Skip to content

Instantly share code, notes, and snippets.

View jpillora's full-sized avatar
👶

Jaime Pillora jpillora

👶
View GitHub Profile
@jpillora
jpillora / express-file-server.js
Last active October 10, 2015 21:28
Node Static Server using Express
//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 October 11, 2015 12:07
jQuery Deferred Serializing Parallelizing Extensions
//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 December 10, 2015 00:18
Grunt task to convert a CSS file into an equivalent readable JS file
// 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 September 7, 2020 15:52
Array/String combinations in JavaScript
//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")
@jpillora
jpillora / hello-world-config.fish
Last active July 10, 2017 03:41
a fish config
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 March 24, 2013 03:55
Sample Node.js Travis CI config using Phantomjs
language: node_js
node_js:
- 0.8
before_script:
- phantomjs --version
script: cake test
@jpillora
jpillora / grunt-includes.coffee
Created March 26, 2013 00:25
Grunt task to include globs of files into one file using templates
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 December 15, 2015 23:49
JavaScript GUID Function
require('crypto');
function guid() {
return crypto.randomBytes(6).toString('hex');
}
@jpillora
jpillora / inherit.js
Last active December 15, 2015 23:48
JavaScript Prototypical Object Inheritance
//Object create with object extension
function inherit(parent, object) {
function F(){}
F.prototype = parent
return $.extend(new F(), object);
}
@jpillora
jpillora / visit.js
Created April 22, 2013 06:17
Recursive enumeration of object contents
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 : '*';