Skip to content

Instantly share code, notes, and snippets.

Avatar
👶

Jaime Pillora jpillora

👶
View GitHub Profile
@jpillora
jpillora / express-file-server.js
Last active Oct 10, 2015
Node Static Server using Express
View express-file-server.js
//Node Static Server using Express
var express = require('express'),
app = express();
app.use(express.static(__dirname));
app.listen(9000);
console.log("Listening on 9000");
@jpillora
jpillora / jquery.deferred.serialize.parallelize.js
Last active Oct 11, 2015
jQuery Deferred Serializing Parallelizing Extensions
View jquery.deferred.serialize.parallelize.js
//each accepts an array of functions that return a promise
$.Deferred.serialize = function(fns) {
if(!$.isArray(fns) || fns.length === 0)
return $.Deferred().resolve().promise();
var pipeline = fns[0](), c = 1, l = fns.length;
for(;c < l;c++)
pipeline = pipeline.pipe(fns[c]);
return pipeline;
@jpillora
jpillora / grunt-css2js.js
Last active Dec 10, 2015
Grunt task to convert a CSS file into an equivalent readable JS file
View grunt-css2js.js
// Custom tasks
grunt.registerMultiTask('css2js', 'Convert CSS to JS.', function() {
var name = this.target,
src = grunt.file.expandFiles( this.data.file ),
dest = src + '.js';
grunt.log.writeln("Converting: '" + src + "' to JavaScript");
var css = fs.readFileSync(src).toString();
if(!css) {
@jpillora
jpillora / combinations.js
Last active Sep 7, 2020
Array/String combinations in JavaScript
View combinations.js
//Explaination:
// start with the empty set
// extract the head element
// copy each element in the set with the current head element appended
// recurse
var combinations = function(set) {
return (function acc(xs, set) {
var x = xs[0];
if(typeof x === "undefined")
View hello-world-config.fish
set PATH /usr/local/bin $PATH
function fish_greeting
end
function fish_prompt
set_color cyan
echo -n $USER
echo -n ' '
set_color $fish_color_cwd
@jpillora
jpillora / .travis.yml
Created Mar 24, 2013
Sample Node.js Travis CI config using Phantomjs
View .travis.yml
language: node_js
node_js:
- 0.8
before_script:
- phantomjs --version
script: cake test
@jpillora
jpillora / grunt-includes.coffee
Created Mar 26, 2013
Grunt task to include globs of files into one file using templates
View grunt-includes.coffee
glob = require "glob-manifest"
async = require "async"
_ = require "lodash"
class IncludesRun
#types of buildable files
templates:
js: _.template '<script src="<%= src %>"></script>'
css: _.template '<link rel="stylesheet" href="<%= src %>"/>'
@jpillora
jpillora / guid-node.js
Last active Dec 15, 2015
JavaScript GUID Function
View guid-node.js
require('crypto');
function guid() {
return crypto.randomBytes(6).toString('hex');
}
@jpillora
jpillora / inherit.js
Last active Dec 15, 2015
JavaScript Prototypical Object Inheritance
View inherit.js
//Object create with object extension
function inherit(parent, object) {
function F(){}
F.prototype = parent
return $.extend(new F(), object);
}
@jpillora
jpillora / visit.js
Created Apr 22, 2013
Recursive enumeration of object contents
View visit.js
var visited = [], type, str;
var visit = function(val, path) {
if(!path) path = '';
if(visited.indexOf(val) >= 0) return;
visited.push(val);
type = typeof val;
str = type !== 'function' ? val : '*';