- Read lots of code.
- Write lots of code.
- Don’t be afraid to throw it away.
- Don’t be afraid to share it.
- Find your happy place writing tests.
- You’ll probably spend more time writing tests and debugging than writing code. Embrace this. Make it a key part of your workflow.
- Tests are one of the first things I read in a module. That and the example(s). Probably before API docs.
- Don’t know where to start. Write some tests for a module you like. This benefits everyone.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert a live action video to gif | |
# Works best for videos with high color palettes like videos from your phone | |
# | |
# @param $1 - video file name like `video.mp4` | |
# @param @optional $2 - width size like `720` | |
# | |
# Example: ffmpegtogif video.mp4 720 | |
# Requirements: ffmpeg. Can be downloaded via homebrew | |
# | |
# http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final AuthCallback authCallback = new AuthCallback() { | |
@Override | |
public void success(DigitsSession digitsSession, String s) { | |
//Success !! | |
} | |
@Override | |
public void failure(DigitsException e) { | |
//sad :( | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.highlight = function(text, sample) { | |
var escapedSample = sample.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); | |
var reSample = new RegExp(escapedSample, 'g'); | |
var args = ['']; | |
var highlightedText = text.replace(reSample, function(match) { | |
args.push('background-color: #ffc', 'background-color: none'); | |
return '%c' + match + '%c'; | |
}); | |
args[0] = highlightedText; | |
console.log.apply(console, args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "js_api.h" | |
// Sometimes you want to access the js "this" value in a function | |
// function Point(x, y) { this.x = x; this.y = y; } | |
bool point_constructor(js_context* C) { | |
js_set(C, 0, "x", 1); // this.x = arguments[0] | |
js_set(C, 0, "y", 2); // this.y = arguments[1] | |
return true; // js returns undefined, but C returns true meaning no error. | |
} |
The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:
- How can authors of function-modules convert to ES6
export
syntax, without breaking consumers that dorequire("function-module")()
? - How can consumers of function-modules use ES6
import
syntax, while not demanding that the module author rewrites his code to ES6export
?
@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.
This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# A quick script to download all your files from CloudApp. | |
# To run this just run the script passing your e-mail & password | |
# to the script, for example: | |
# | |
# gem install cloudapp_api | |
# ruby cloudapp-export.rb adam@atechmedia.com mypassword | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var serialport = require('node-serialport') | |
var sp = new serialport.SerialPort("/dev/ttyO3", { | |
parser: serialport.parsers.raw, | |
baud: 9600 | |
}) | |
sp.on('data', function(chunk) { | |
console.log(chunk.toString('hex'), chunk.toString(), chunk) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export AR=arm-unknown-linux-gnueabi-ar | |
export CC=arm-unknown-linux-gnueabi-gcc | |
export CXX=arm-unknown-linux-gnueabi-g++ | |
export LINK=arm-unknown-linux-gnueabi-g++ | |
node-gyp --target=v0.8.11 --arch=arm configure build --nodedir=/path/to/node/checkout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AwesomeRouter: A class that I've been using throughout a few Backbone.js apps I've built. | |
# | |
# It adds 2 features: an event that gets fired when one calls `navigate` (aptly named | |
# "navigate"), so you can bind things to when a URL gets triggered. And a "before filter" | |
# method `before`, which you can use to run things before every a route gets triggered. | |
# | |
# This could easily be extended to have after filters too, or to only trigger a route | |
# upon @before returning something that's not false. | |
class AwesomeRouter extends Backbone.Router |
NewerOlder