Skip to content

Instantly share code, notes, and snippets.

@emilbayes
emilbayes / coverElement.js
Created February 16, 2014 10:36
Make one element cover another proportionately
(function($) {
$.fn.extend({
coverElement: function(options) {
var settings = $.extend(true, {
container: 'html' //Default is fit the viewport
}, options);
var $elements = this,
$container = this.first().closest(settings.container);
@emilbayes
emilbayes / Docs.md
Created June 19, 2014 13:59
Convert images to video slideshow

Folder structure

|-/input #Still images
|-/frames #Converted and resized frames
|-/output

|- video.mp4

@emilbayes
emilbayes / index.css
Created August 26, 2014 12:05
Semantic CSS Arrow
body {
width: 360px;
}
.box {
width: 100%;
}
.box header {
background: #ddd;
@emilbayes
emilbayes / readme.md
Last active August 29, 2015 14:06
intro to kick-off-koa

Koa is based on generators which are a new feature in ES6. The syntax for a generator is function* fnName() {} where fnName is optional, just as with normal functions. What generators allow one to do is effectively to suspend execution and hand over the execution flow to the calling function, which can then inject data into the generator. This is exploited to make async calls seem sync. Example:

function *() {
   var data = yield db.find(); //yield suspends execution and hands over the control flow

   data.map(someMapper);
}

As you can see we can pretend the async function db.find is sync, because the caller takes care of executing the function for us and can inject the response into the variable data. That's the high level overview of generators. How they actually work is another story but nothing you need to worry about at first. ES6 (also known as Harmony) features are not enabled by default so when running node, use the harmony flag: node --harmony index.js

@emilbayes
emilbayes / client.sh
Last active August 29, 2015 14:08
Netcat Speed Test
#Copy 2.1GB
DATASIZE=$(echo '2^31' | bc)
dd if=/dev/zero bs=$DATASIZE count=1 | nc [HOST] 2222
@emilbayes
emilbayes / index.js
Last active August 29, 2015 14:10
requirebin sketch
var KMeans = require('kmeans-js');
var getPixels = require('canvas-pixels');
var document = require('global/document');
var img = require('img');
var canvas = document.createElement('canvas'),
context = canvas.getContext('2d');
img('https://www.npmjs.org/static/img/npm.png', function(err, el) {
canvas.width = el.width;
@emilbayes
emilbayes / .editorconfig
Last active August 29, 2015 14:11
Project .files
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 2
@emilbayes
emilbayes / example.js
Last active August 29, 2015 14:16
Stream Example
var stream = require('stream');
var messageStream = require('./message-stream');
var jsonify = new stream.Transform({
writableObjectMode: true,
transform: function(chunk, enc, cb) {
this.push(JSON.stringify(chunk, null, 2) + '\n');
cb();
}
});
@emilbayes
emilbayes / package.json
Created March 12, 2015 10:17
Minimal password protected server
{
"name": "minimal-protected-server",
"version": "0.0.0",
"description": "Minimal password protected server",
"main": "server.js",
"dependencies": {
"basic": "0.0.3",
"st": "^0.5.3"
}
}
@emilbayes
emilbayes / attempted-solution.js
Created March 16, 2015 09:42
I need callbacks on _read
var stream = require('stream');
var outer = 0, inner = 0;
var collectorStream = stream.Readable({
highWaterMark: 1,
objectMode: true,
read: function() {
var self = this;
var id1 = outer++;