Testing for an empty array in javascript
Do:
if (myEmptyArray.length === 0) {} // true
Do not do:
if (myEmptyArray === []) {} // false
nor:
if (myEmptyArray == []) {} // false
nor:
if (!myEmptyArray) {} // false
Do:
if (myEmptyArray.length === 0) {} // true
Do not do:
if (myEmptyArray === []) {} // false
nor:
if (myEmptyArray == []) {} // false
nor:
if (!myEmptyArray) {} // false
This worked fine:
for(var c = ''; c.length < 32;) c += Math.random().toString(36).substr(2, 1)
Which reminded me of this uuid one:
"00000000-0000-4000-8000-000000000000".replace(/0/g,function(){return(0|Math.random()*16).toString(16)})
(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.
This is on the right path although windows are not controllable for me:
#!/bin/sh def export XKL_XMODMAP_DISABLE=1 unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS gnome-panel & gnome-settings-daemon & metacity & nautilus & gnome-terminal &
This and similar just greyscreened:
#!/bin/sh xrdb $HOME/.Xresources xsetroot -solid grey export XKL_XMODMAP_DISABLE=1 echo starting gnome gnome-session --session=ubuntu-2d &
#!/bin/sh xrdb $HOME/.Xresources xsetroot -solid grey export XKL_XMODMAP_DISABLE=1 echo starting gnome gnome-session
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.
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.*
although python also has **
for dictionaries (a.ka. maps in ECMAScript 6) which ECMAScript 6 does not have,
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
Mainly in python:
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
Yesterday I found myself looking at Google dense hash maps in C++. Googling around about them, I found a page from incise.org 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
I introduced logging to a a python application that is multi threaded, and it started to segfault. I switched to ConcurrentLogHandler but it still segfaulted. I then switched to log over http with restapi-logging-handler, and in that way introduced a bit of complexity, but eventually decided to take another sweep at pypi to see if there wasn't a simpler solution and found this:
multiprocessing-logging 0.2.1 : Python Package Index
It seems to work like a charm in initial tests. I use it like this (abbreviated code):
import multiprocessing_logging log_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logs', 'app.log') mhandler = multiprocessing_logging.MultiProcessingHandler('worker-logger', sub_handler= logging.handlers.RotatingFileHandler( log_file, maxBytes=20000000, backupCount=0))
Well, it isn't actually stealing your icons but when interacting with Spotify on Ubuntu 14.04 Linux, it has a tendency to make your icons for applications and other stuff disappear. It seems to do this by switching themes somehow or some sorts. However there is a way of preventing that.
AppArmor is a program that can control what other programs can and cannot do, with regards to file access. It is mainly used for security reasons to make sure that programs, especially binary-only ones whose code you cannot scrutinize (such as Spotify), are not secretly veering off stealing data from your hard disk or mucking about in other ways.
AppArmor can be configured to prevent Spotify from doing this icon-disappearing thingy. In your AppArmor profile for Spotify, add these two lines (tested by me):
# block sni-qt deny /usr/lib/i386-linux-gnu/qt4/plugins/systemtrayicon/libsni-qt.so r, deny /usr/lib/x86_64-linux-gnu/qt4/plugins/systemtrayicon/libsni-qt.so r,
Or use the entire profile here https://raw.githubusercontent.com/ozcanesen/spotify-indicator/master/spotify (not tested by me)
Untested by me. My need is to carry over just the changes in one file to the same file in another branch in the same git repository.
A simple command already solved the problem for me if I assume that all changes are committed in both branches A and B:
git checkout A
git checkout --patch B f
Read more: Link - git - How do I merge changes to a single file, rather than merging commits? - Stack Overflow
In GNOME desktop, you can use gnome-desktop-item-edit to configure a desktop shortcut easily.
$ gnome-desktop-item-edit ~/.local/share/applications --create-new
In this example, gnome-desktop-item-edit will automatically create a desktop launcher file in ~/.local/share/applications.
If gnome-desktop-item-edit is not available (e.g., on Ubuntu), you can install it as follows.
$ sudo apt-get install --no-install-recommends gnome-panel
Read more: Link - How to create desktop shortcut or launcher on Linux - Xmodulo
Tested by me.
You specify the path to the file where the tests are residing. After the path you add a string that specifies the place of the test inside that file, in dotted format:
python <path_to_file> <class_name>.<test_method_name>
python testMyCase.py MyCase.testItIsHot
Read more: Link - python - Running single test from unittest.TestCase via command line - Stack Overflow
Don't point pkill at anything you do not have the intention to kill.
Use
pgrep -f pattern
first, so you know what you are killing.
Use pkill -f, which matches the pattern for any part of the command line
pkill -f my_pattern
Read more: Link - linux - How to kill all processes with a given partial name? - Stack Overflow
Update 2014-08-02, see also these links:
Which take a Haskell/FP perspective on improvements
Understanding the code in a javascript application can be hard work. There are at least two reasons for that:
There's more than one way to do it, a term I believe originally coined by Perl creator Larry Wall. C++ and Scala are also often said to suffer from different coding styles, while python does not. Javascript is by many felt as lacking a lot of features, but can be cajoled to emulate these features.
Different people have different preferences and decide to go about "fixing" these things in different ways. The result of this is that there are different ways of importing functionality, tracking dependencies, emulating a class base OO language and so on and so forth. All these extensions still rely on javascript syntax which makes them contrived in source code.
Even such a common solution as the object literal demands a lot of knowledge of the coder about anonymous functions, closures and so on to figure out what's going on. Also other ways of going about things become syntax-heavy:
(function() { this.Example || (this.Example = {}); this.Example.Models = { Product: employee }; this.Example.Collections = { Products: employees } }).call(this);
On top of that there is a plethora of frameworks each one if their own idiosyncratic view of the world.
"Callback hell" is a term often used for the default way of handling asynchronicity in javascript. It makes it hard to follow the program execution by reading the source code. There are other ways of handling asynchronicity in javascript, but then we are back to reason number 1 above: a plethora of solutions. Another aspect, put forth by my friend Mikael, is that javascript has exceptions, which doesn't sit very well with the structure of the language. I guess because it becomes quite unclear through what an exception is supposed to bubble up.
What can one do in order to write javascript that is readable and understandable by another coder?
Or at least I cannot find any. Jetbrains has acquired spy.js but that one is not open source. The node-inspector people seem less enthusiastic Enhancement: Full trace of program execution · Issue #366 · node-inspector/node-inspector
There is something close to tracing though for node.js (and I have tested it):
I'm trying to figure out how to make the source code of a system readable, readable meaning that you can understand the system on a high level, and also its constituent parts, from the source code.
It seems to me, and I am just starting thinking about this, that there things (patterns, frameworks, data schemas) that are invariant, that is they don't change over time as the system runs. I'm sure the word invariant has other definitions, but for this text that was invariant means. These invariant things are the things you can communicate to the developer/maintainer.
So it would seem that you should be upfront with your invariant stuff. Like in a central file or as imports to it. And if you have stuff that is changing and amorphous, can it be abstracted into, or at least abstractly described, as something invariant? Then do that.
It seems to me that the more of these invariant stuff you can get into your system and systems description, the easier it the system will be to understand.
However the invariants, such as e.g. a framework's modus operandi, should not lead to convoluted solutions.
So the rule might be:
Use as many invariants as you can in your system, but not to the point of convoluted constructs.
Could be a two step process: Find and describe the invariants you already have, and see if you can refactor code into invariants.
The invariants can work on many levels: Using a language that discourages TIMTOWDI, using frameworks (iff they fit the problem) and taking time to create well defined abstractions for as many parts of the code as possible. Abstractions here means in the direction of readability and understandability.
Another question then arises, what abstractions are easy to undertstand? In user interface design one measure of the complexity of a GUI is the number of objects on the screen and how many alignment lines there are. Fewer objects and aligned objects lead to lower complexity. I wonder how could one measure the complexity of abstractions in source code? Metrics could include
Abstractions already familiar to the developer are easier for him to use, and re-using known abstractions with some magical twist may work too. it also means it may be a good idea to have a toolbox of powerful abstractios that covers most of the things needed to be done.
Sometimes there is a like precipice when interactions between even simple components get too complex to understand. In which case the sub system needs to be "black-boxed" and not leak into the environment.
Update 2015-08-31: Something is on its way: 'virtualization support' - MARC
While searching I noticed there was not much activity in the field of using OpenBSD as a host operating system, with some solutions such as VirtualBox and Vmware not supported at all.
Theo de Raadt, BDFL of OpenBSD, has said the following about x86 virtualization:
x86 virtualization is about basically placing another nearly full kernel, full of new bugs, on top of a nasty x86 architecture which barely has correct page protection
So the support for x86 virtualization in OpenBSD is less than enthusiastic.
Read more: Link - 'Re: About Xen: maybe a reiterative question but ..' - MARC
Some info is available though:
Install and Run Windows Within QEMU Virtualization on OpenBSD or Linux
Disclaimer: I have no idea of what I am doing.
I have a WD My Cloud with an ARM processor running on 4.x of WD's OS, which is a Debian with large page sizes. From my 32-bit i386 normal page sized Linux I just tried this:
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 go build -ldflags "-R 65536" hello.go
And that runs on the WD device. Not sure if it just dumb luck, maybe it won'y work for bigger programs.
Update: I have now tried to compile a much bigger program and it seems it worked fine, but I got
fatal error: runtime: cannot map pages in arena address space
Which if I undertand golang correctly, is an out of memory error. I never thought of how much RAM my little NAS has. It turns out it has 277MB of which 45MB is free. That is a bit on the low side for the rather huge project I was trying to run. I had to drop the CGO_ENABLED flag but I think that is only needed if there is C code in the project. I have an idea of putting a USB stick into the USB3 port of the NAS and use that as swap to increase the memory available.
I got the flags and switches from here, but I think that guy also built a special golang compiler:
panic on arm cross compile - Google Groups
Cross compilation just got a whole lot better in Go 1.5 | Dave Cheney
Untested by me, but looks promising. I wonder how many people use it?
Obnam can also access the live data over SFTP, instead of via the local filesystem. This means you can run Obnam on, say, your desktop machine to backup your server, or on your laptop to backup your phone (assuming you can get an SSH server installed on your phone). Sometimes it is not possible to install Obnam on the machine where the live data resides, and then it is useful to do a pull backup instead: you run Obnam on a different machine, and read the live data over the SFTP protocol.
Read more: Link - Backups with Obnam