Posts

utf 8 - Read file with UTF-8 in Haskell as IO String -

i have following code works fine unless file has utf-8 characteres : module main import ref main = text <- getline theinput <- readfile text writefile ("a"++text) (unlist . proc . lines $ theinput) with utf-8 characteres this: hgetcontents: invalid argument (invalid byte sequence) since file i'm working has utf-8 characters, handle exception in order reuse functions imported ref if possible. is there way read utf-8 file io string can reuse ref 's functions?. modifications should make code?. in advance. i attach functions declarations ref module: unlist :: [string] -> string proc :: [string] -> [string] from prelude: lines :: string -> [string] this can done ghc's basic (but extended standard) system.io module, although you'll have use more functions: module main import ref import system.io main = text <- getline inputhandle <- openfile text readmode hsetencoding inputhandle u...

node.js - npm install express-generator not installing express -

i'm following mean stack tutorial requires me have express installed: i run this: npm install -g express-generator and results: username@username-inspiron-3521:~$ npm install -g express-generator /home/username/npm/bin/express -> /home/username/npm/lib/node_modules/express-generator/bin/express express-generator@4.13.1 /home/username/npm/lib/node_modules/express-generator ├── sorted-object@1.0.0 ├── mkdirp@0.5.1 (minimist@0.0.8) └── commander@2.7.1 (graceful-readlink@1.0.1) but when do express --ejs flapper-news the program 'express' not installed. can install typing: sudo apt-get install node-express what doing wrong? thanks time. edit when npm install username@username-inspiron-3521:~/documents/mean/flapper_news$ npm install npm err! install couldn't read dependencies npm err! linux 3.16.0-51-generic npm err! argv "/home/username/local/bin/node" "/home/username/local/bin/npm" "install" npm err! node v4.2.1 n...

json - Using filter with each on lodash -

i have json string [ { uri : '/someuri/one', title : 'title 1', displaylocation : 'action_menu', masterdata : 'location', iconclass : 'icon-class-1' }, { uri : '/someuri/two', title : 'title 2', displaylocation : 'action_menu', masterdata : 'location', iconclass : 'icon-class-2' }, { uri : '/someuri/three', title : 'title 3', displaylocation : 'action_menu', masterdata : 'job', iconclass : 'icon-class-3' }, { uri : '/someuri/four', title : 'title 4', displaylocation : 'summary', masterdata : 'location', iconclass : 'icon-class-4' } ] i converting to [ { iconclass : 'icon-class-1', id : 'anythingunique', text : 'title 1' }, { iconclass : 'icon-class-2', id : 'any...

javascript - Wait for asyn call to finish - too late -

i have dialog button. once clicked button calls async method returns true or false depending on whether posted data valid or not. click event calls method below. now, problem closedialog called before callback function executed!! how can make work? thanks close: function (srccmd) { var closeresult = true; asyncthing(function(result) { if (result) closeresult = true; else closeresult = false; }); if (closeresult !== false) { this.closedialog(); } }, the function withing asyncthing called when(whenever might be) asynchronous call finished. not interpreted line-by-line. move latter if question callback function , fine. close: function (srccmd) { var closeresult = true; asyncthing(function(result) { if (result) closeresult = true; else closeresult = false; if (closeresult !== false) { this.closedialog(); } }); },

JavaScript Promises - reject vs. throw -

i have read several articles on subject, still not clear me if there difference between promise.reject vs. throwing error. example, using promise.reject return asyncispermitted() .then(function(result) { if (result === true) { return true; } else { return promise.reject(new permissiondenied()); } }); using throw return asyncispermitted() .then(function(result) { if (result === true) { return true; } else { throw new permissiondenied(); } }); my preference use throw because shorter, wondering if there advantage of 1 on other. there no advantage of using 1 vs other, but, there specific case throw won't work. however, cases can fixed. any time inside of promise callback, can use throw . however, if you're in other asynchronous callback, must use reject . for example, new promise(function() { settimeout(function() { ...

microcontroller - UART in LPC1778 not working -

i trying send byte using uart1 in lpc1778 (i'm using keil simulator). however i'm not able send byte; after detailed debugging, came conclusion data not getting written in uart1->thr register. this code snipped transmission: void uart1_tra(uint8_t x) { lpc_uart1->thr=x; //after line ,irrespective of value of x, uart1->thr remains @ value equal 0 while(1) { if(lpc_uart1->lsr&(1<<5)) { break; } } } initialization code: void uar1_init(void) { lpc_sc->pconp|=1u<<4; lpc_sc->pclksel|=1u; lpc_uart1->lcr|=1u<<7; lpc_uart1->dll|=0x05; //set baud rate lpc_uart1->fdr|= 0x21; //end of baud rate calculations lpc_uart1->lcr&=~(1u<<7);//disable dlab lpc_uart1->lcr|=3u;//8-bitcharacter length lpc_uart1->fcr|=1u; //enable fifo reg lpc_uart1->fcr|=(0x03<<1);//reset rxbuffers //lpc_uart...

view - mysql subtract row by row -

i have 2 mysql (5.6) views. 1 view contains 1 value in 1 row on column. let's column , in single row have value 5000. i have second view 3 columns: item (varchar), date (obviously containing dates) , value (decimal). second view has 4 rows looks this: item date value 'lectii de pian', '2015-11-09', '101.88' 'microsoft office','2015-11-11', '7.00' 'belasting', '2015-11-15', '524.00' 'netflix', '2015-11-18', '8.99' what want create in view column let's call "b" , subtract first value in column value value in view , result subtract next value , on looks this item date value b 'lectii de pian', '2015-11-09', '101.88' '4898.12' 'microsoft office','2015-11-11', '7.00' '4891.12' 'belasting...