Skip to content

Instantly share code, notes, and snippets.

View romainhuet's full-sized avatar

Romain Huet romainhuet

View GitHub Profile
# 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
@rallat
rallat / gist:849a68520ca10d913aeb
Created October 23, 2014 07:41
Digits with custom button
final AuthCallback authCallback = new AuthCallback() {
@Override
public void success(DigitsSession digitsSession, String s) {
//Success !!
}
@Override
public void failure(DigitsException e) {
//sad :(
}
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);
@dshaw
dshaw / levelup.md
Last active November 17, 2022 14:52
Leveling-up on Node

Core Principals

  • 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.
#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.
}
@domenic
domenic / interop.md
Last active July 7, 2022 19:47
`module.exports =` and ES6 Module Interop in Node.js

module.exports = and ES6 Module Interop in Node.js

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 do require("function-module")()?
  • How can consumers of function-modules use ES6 import syntax, while not demanding that the module author rewrites his code to ES6 export?

@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.

@adamcooke
adamcooke / cloudapp-export.rb
Created January 11, 2013 15:45
Export all your drops from CloudApp using this quick Ruby script
#!/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
#
@max-mapper
max-mapper / helloworld.js
Created November 27, 2012 06:55
droneduino
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)
})
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
@juliocesar
juliocesar / awesome_router.coffee
Created May 21, 2012 17:00
AwesomeRouter: a cool Backbone.js router class
# 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