Skip to content

Instantly share code, notes, and snippets.

View kesla's full-sized avatar

David Björklund kesla

  • Stockholm, Sweden
View GitHub Profile
@kesla
kesla / gist:3378547
Created August 17, 2012 12:52
.map(parseInt) fails
['1', '2'].map(parseInt)
// output [1, NaN]
['1', '2'].map(Number)
// output [1, 2]
Why?
var levelup = require('levelup');
var db = levelup('levelup-leak-db');
db.put('foo', 'bar');
function read() {
db.readStream().once('end', read);
}
read();

examplebuild status

An example module to show how to autogenerate a README.md-file. The code implements addition.

Installation

npm install example
@kesla
kesla / stream2-falsy-objects-test.js
Last active December 19, 2015 07:19
Weird behaviour with streams and falsy objects
var Transform = require('stream').Transform
var assert = require('assert')
var stream = new Transform({objectMode: true})
var read = function(stream, callback) {
var actual = []
var data
function onReadable () {
while((data = stream.read()) !== null) {
node-snappy|merged⚡ ⇒ gdb --args node failure.js
GNU gdb 6.3.50-20050815 (Apple version gdb-1824) (Wed Feb 6 22:51:23 UTC 2013)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ........ done
(gdb) run
function fullName (firstName, secondName) {
return firstName + ' ' + secondName;
}
function fullName2(obj) {
return obj.firstName + ' ' + obj.secondName;
}
console.log(beepboop(fullName2, ['firstName', 'secondName'])('David', 'Hipsterson'));
console.log(fullName('David', 'Hipsterson'));
import toArticleJson from ‘html-to-article-json’;
const embed1 = toArticleJson(‘<iframe src="https://www.youtube.com/embed/pDVmldTurqk"></iframe>’
const embed2 = toArticleJson(‘<iframe src="//cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2F3rS6mZUo3fg%3Ffeature%3Doembed"></iframe>’)
@kesla
kesla / example.js
Last active February 9, 2016 22:48
import toArticleJson from ‘html-to-article-json’;
const embed1 = toArticleJson(
'<iframe src=”https://www.youtube.com/embed/pDVmldTurqk"></iframe>'
);
const embed2 = toArticleJson(
'<iframe src=”//cdn.embedly.com/widgets/media.html?src=http%3A%2F%2Fwww.youtube.com%2Fembed%2F3rS6mZUo3fg%3Ffeature%3Doembed"></iframe>'
);
import toAmp from ‘article-json-to-amp’;
const amp = toAmp(articleJson);