Skip to content

Instantly share code, notes, and snippets.

View mklabs's full-sized avatar

Mickael Daniel mklabs

View GitHub Profile
@mklabs
mklabs / .gitignore
Created October 9, 2011 15:17
datauri / mhtml script experiment
node_modules
# folders used for testing
css
img
images
test
@mklabs
mklabs / base64
Created October 3, 2011 20:56
data URIs for web content quick and easy
#!/usr/bin/env node
//
// small program/library to make creation of data URIs for web content quick and easy
//
// ./base64 ../path/to/some/file.png | pbcopy
//
// may ends up in a tool to embed data URIs in HTML/CSS files.
//
// inspired by https://github.com/nzakas/cssembed
@mklabs
mklabs / stuff.js
Created September 30, 2011 14:22
recursive deep object getter
var assert = require('assert');
var o = {a: {b: 'c'}, d: {e: {f: 'GG'}}};
assert.equal(get(o, 'a'), o.a);
assert.equal(get(o, 'd'), o.d);
assert.equal(get(o, 'd.e'), o.d.e);
assert.equal(get(o, 'd.e.f'), 'GG');
assert.equal(get(o, 'foobar'), undefined);
assert.equal(get(o, 'foobar.is.not'), undefined);
@mklabs
mklabs / pre-commit
Created September 28, 2011 01:25
npm test as git/hg hooks
#!/usr/bin/env node
var npm = nrequire('npm');
if (npm) return npm.load(function(e, n) {
this.commands.test(function(e) {
process.exit(e ? 1 : 0);
});
});
@mklabs
mklabs / test.js
Created September 26, 2011 14:44
easily compose log statements with colors and style, a la markdown (kinda)
var colors = require('colors');
// I've got an idea.. (it happens..) What if I could log colors and style,
// like I would do with some markdown content...
//
// so here's the idea, a function wrapper around colors.js to escape some markers
// and easily compose log statement. kinda fun
//
// idea is to automatically escape some custom markers, and apply
// according colors style. Enable easy output, without having to rely,
@mklabs
mklabs / gists-clone.js
Created September 17, 2011 22:19
script to clone a list of gists, only those with markdown files and a package.json
// script to clone a list of gists, only those with markdown files
var child = require('child_process'),
colors = require('colors'),
path = require('path'),
fs = require('fs');
// set up your credentials
@mklabs
mklabs / spawn.js
Created September 12, 2011 19:39
spawn and pipe
var spawn = function spawn(cmd, args, callback) {
var stderr = [], stdout = [],
ch = child.spawn(cmd, args);
ch.stdout.pipe(process.stdout, {end: false});
ch.stderr.pipe(process.stderr);
ch.stdout.on('data', function(data) { stdout[stdout.length] = data; });
ch.stderr.on('data', function(data) { stderr[stderr.length] = data; });
ch.on('exit', (callback || function (code) {
console.log('done', arguments);
@mklabs
mklabs / hookio-xml2json.js
Created August 2, 2011 21:22
A simple Hook, requests feed xml, emits json data
//
// requires hookio-request spawned
// requires https://github.com/Leonidas-from-XIV/node-xml2js installed
// npm install xml2js
var Hook = require('hook.io').Hook,
util = require('util'),
xml2js = require('xml2js');
@mklabs
mklabs / cdnjs.js
Created July 28, 2011 20:26
little jsonp helper, github api v3 + cdnjs example
(function(exports, document) {
// ## cdnsjs
//
// example: get the list of cdnjs hosted scripts (http://developer.github.com/v3/git/trees/)
// GET /repos/:user/:repo/git/trees/:sha
//
// usage:
// cdnjs(function(err, data) { if(err) {return console.error(err);} console.log(data); });
//
@mklabs
mklabs / whitespace-cleanr.js
Created July 23, 2011 12:57
svg to raphael helper, get an array of path object {path, attr} from an svg file
// <script type="text/someunknowntype" id="logo-svg"><svg>...</svg></script>
var svg = $('#logo-svg')[0].innerHTML
// >< whitespace cleanr ><
.replace(/>[\s]+</g, '><')
.replace(/[\s]+/g, ' ')
// get an array of path hash object, with path/attr property
.match(/<(path[^\/]+)\/>/g)
.map(function(el) {
var m = el.match(/<path d="([^"]+).+style="([^"]+).+/),
attr = {},