Skip to main content

Posts

Showing posts from August, 2018

Strcpy Segmentation Fault C

I am learning some new things and get stuck on a simple strcpy operation. I don't understand why first time when I print works but second time it doesn't. #include #include #include int main() { char *name; char *altname; name=(char *)malloc(60*sizeof(char)); name="Hello World!"; altname=name; printf("%s \n", altname); altname=NULL; strcpy(altname,name); printf("%s \n", altname); return 1; } Solved You need to allocate memory for altname : #include #include #include int main() { char *name; char *altname; name=(char *)malloc(60*sizeof(char)); name="Hello World!"; altname=name; printf("%s \n", altname); altname=NULL; // allocate memory, so strcpy has space to write on ;) altname=(char *)malloc(60*sizeof(char)); strcpy(altname,name); printf("%s \n", altname); return 1; } The problems star...

Unexpected token import Using React Jasmine Babel Webpack

Trying to write some Jasmine tests for my React App, and getting this error: import HomePage from '../../src/components/home/HomePage'; ^^^^^^SyntaxError: Unexpected token import at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.jasmine.executeSpecsInFolder (C:\Users\JasmineTest\node_modules\jasmine-node\lib\jasmine-node\index.js:160:9) at Object. (C:\Users\JasmineTest\node_modules\jasmine-node\lib\jasmine-node\cli.js:248:9) Using React, Babel-loader, webpack. Only gives error if i try to import component, or if i use required('component') and in component i use Import. Solved Here is my webpack file import webpack from 'webpack'; import path from 'path';...

How to select an item programmatically in vega?

The following works, but it doesn't seem right (see live demo) : vg.parse.spec(spec, function(chart) { var view = chart({ el: "#graph" }); view.update(); view.update({ props: "hover", items: view._model._scene.items[0].items[0].items[1] // What's the right way of doing this? Solved Vega is making good progress and this is one of the features they've talked about in their forum. However, right now, what you're doing is the only way to get to a scene item. For proof, see advice from jheer (main author of vega): https://groups.google.com/forum/#!topic/vega-js/r4aUahV-RwI (last post there shows an example of traversing the scene the same way you do). One small difference is you can use view.model().scene() instead of view._model._scene . But right now those do the same thing, it's just you don't have to use variables that are actively telling you not to use them :)