Skip to content. | Skip to navigation

Personal tools
Log in
You are here: Home - Blog

Start a promise chain in Bluebird Q-style

Posted by admin |

You can start a promise chain in the javascript library Q with a data item, like so:

Q([foo:'bar}).then( ...

How do you do that in the Bluebird javascript library?

One way is like this:

Promise.resolve([foo:'bar}).then( ...
One of the simplest is calling Promise.resolve() on nothing:

Read more: Link - javascript - Define empty Bluebird promise like in Q - Stack Overflow

Oct 03, 2015 04:12

Testing for an empty array in javascript

Posted by admin |


if (myEmptyArray.length === 0) {} // true

Do not do:

if (myEmptyArray === []) {} // false


if (myEmptyArray == []) {} // false


if (!myEmptyArray) {}  // false
Oct 01, 2015 12:34

Random text string in Javascript

Posted by admin |

This worked fine:


for(var c = ''; c.length < 32;) c += Math.random().toString(36).substr(2, 1)


Which reminded me of this uuid one:

Sep 28, 2015 09:40

Instructions for use of the TempScan GT-302A Thermometer

Posted by admin |

Instructions for use of the TempScan GT-302A Thermometer

(Unofficial instructions, use at your own risk)

I just figured out how to use mine again, lost the instructions a decade ago or so. Here goes:

Switching it on
Switch it on by pressing the on/MEM button. This will set the device in memory recall mode, indicated by the “M” symbol to the left in the display. The SCAN button will cycle between the 10 most recent temperature takings, taking #1 being the most recent.

Go to temperature taking mode
Press the on button again to put the device in stand-by mode for temperature monitoring. Over a bit less than 10 seconds, a progress report will appear near the top of the display showing 3 progressively thicker bars and finally a pictogram of an ear, accompanied by a beep.

Take the temperature
When the ear pictogram has appeared, the device is ready for temperature monitoring. Position the tip of the device in ear (with appropriate protection) and depress the SCAN button. Release the SCAN button when the device has beeped. The temperature may now be read from the display and will be stored in memory as reading #1.

Switching off the device
Depress the on/MEM button and wait for the device to switch off the display. Release button.


Shorter version:

Switch it on by pressing the on/MEM button. Press “on” again & wait 10 secs for small ear to appear in display. Take the temp by pressing SCAN until beep.

Sep 19, 2015 06:50

Avoiding grey-screen in tightvnc under Ubuntu 14.04

Posted by admin |

This is on the right path although windows are not controllable for me:






gnome-panel &

gnome-settings-daemon &

metacity &

nautilus &

gnome-terminal &

This and similar just greyscreened:

xrdb $HOME/.Xresources
xsetroot -solid grey
echo starting gnome
gnome-session --session=ubuntu-2d &


xrdb $HOME/.Xresources
xsetroot -solid grey
echo starting gnome

Read more: Link - Ubuntu VNC Grey Screen | onkea eLearning

Sep 14, 2015 12:55

Nouveau stopped my Acer V5-537G from crashing

Posted by admin |

Switching from Ubuntu 32-bit to 64-bit (14.04 and 15.04) I got problems with my Acer V5-537G freezing irrevocably, and only a hard restart would get it back to life again.

However by selecting the open source Nouveau driver for my Nvidia Geforce GT750M graphics card, the deep-freezes stopped. Now there are just temporary freeze-ups.


BinaryDriverHowto/Nvidia - Community Help Wiki

Sep 14, 2015 12:30

ECMAScript 6 tutorial shows similarities to python

Posted by admin |

Use ECMAScript 6 Today - Tuts+ Code Article is a tutorial that is readable, about ECMAScript (Javascript) 6. It is from 2013 so more features may be available directly in the browsers and in Node.js as of today.

As a python developer, the things that stand out as similar to python in ECMAScript 6 are:

  • for x of - Seems to do what pythons for x in does. Javascript has for x in since long but it returns more primitive things.
  • Maps - allows any object and not only strings to be the key, as in python dictionaries.
  • rest and spread - Seems to be like splat (star) in python, that is * although python also has ** for dictionaries (a.ka. maps in ECMAScript 6) which ECMAScript 6 does not have,
  • Default function parameters -seems to work as in python
  • Destructuring - Works as in python, but better. In python you can only return tuples, but in ECMAScript 6 you can also unpack things from objects
  • Array comprehensions - Just like list comprehensions in python, but using of instead of in syntax-wise as noted above.


In this article, we'll explore ten new features, with a significant focus on tools, browsers and transpilers.

Read more: Link - Use ECMAScript 6 Today - Tuts+ Code Article

Sep 09, 2015 11:09

Fast mass inserts into PostgreSQL

Posted by admin |

The fastest way seems to be with a special tool:


Other than that, one can use COPY which is almost as fast and it means you have a data file that postgres can suck in: PostgreSQL: Documentation: 9.4: Populating a Database

This guy has tested it all and concludes that if for whatever reason you cannot use COPY you can make multirow INSERTS: select * from depesz; » Blog Archive » how to insert data to database – as fast as possible

Here is an example of how a multirow insert looks like in PostgreSQL

INSERT INTO films (code, title, did, date_prod, kind) VALUES
    ('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'),
    ('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy');


There is an alternative to using COPY, which is the multirow values syntax that Postgres supports. From the documentation:

Read more: Link - postgresql - Whats the fastest way to do a bulk insert into Postgres? - Stack Overflow

Sep 04, 2015 03:32

Python dictionaries are pretty fast

Posted by admin |

Yesterday I found myself looking at Google dense hash maps in C++. Googling around about them, I found a page from benchmarking different hashes in C++.

The author, on a lark he writes, decided to include dictionaries from Python and the corresponding data structure from Ruby. It turns out that python dictionaries aren't slow at all. Here two diagrams from the post:


They are fast, but take up a fair bit of memory. More diagrams and te text in the original post:




I've put together a set of benchmarks of what I consider to be the most prominent C and C++ hash table implementations. I've made the code available at Github. If you have any critiques or corrections, please post a comment below, email me, or fork the code and send me a pull request on Github.


Read more: Link - Hash Table Benchmarks

Sep 04, 2015 01:50