Skip to content

Instantly share code, notes, and snippets.

View lazywithclass's full-sized avatar

Alberto Zaccagni lazywithclass

View GitHub Profile
@lazywithclass
lazywithclass / version bump with prompt offered
Created January 29, 2014 16:19
Version bump compliant with semver with prompt to the dev
bump: {
options: {},
files: ['package.json']
},
prompt: {
bump: {
options: {
questions: [{
config: 'bump.options.level',
type: 'list',
@lazywithclass
lazywithclass / ?. in JavaScript
Created February 3, 2014 23:00
First version of CoffeeScript's ?. in JavaScript thanks to sweet.js
macro ?. {
rule infix {
$lhs:expr | $rhs:expr
} => {
$lhs && $lhs.$rhs
}
}
// obj?.possiblyNullProperty
@lazywithclass
lazywithclass / Describing Y Combinator
Last active August 29, 2015 14:03
My take in explaining to myself the Y Combinator
// the original Y Combinator is here: https://leanpub.com/javascript-allonge/read#y
// have a look at that soup of function and return
// I refactored it down to the below version
// I hope is correct, too tired now.
// used like this
var factorial = Y(
// next
function(fac) {
return function(n) {
{ [Error: SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[2sj2k_hAQWKeObWgAzBZhw][events][0]:
SearchParseException[[events][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"filtered":{"filter":{"geo_distance":{"distance":"1km",
"geopoint":{"lat":48.507351,"lon":-0.127758}}}}}]]]; nested: SearchParseException[[events][0]: from[-1],size[-1]: Parse Failure [No parser for elemen
t [filtered]]]; }]]
status: '400',
message: 'SearchPhaseExecutionException[Failed to execute phase [query_fetch], all shards failed; shardFailures {[2sj2k_hAQWKeObWgAzBZhw][events][0
]: SearchParseException[[events][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"filtered":{"filter":{"geo_distance":{"distance":"1km
","geopoint":{"lat":48.507351,"lon":-0.127758}}}}}]]]; nested: SearchParseException[[events][0]: from[-1],size[-1]: Parse Failure [No parser for elem
ent [filtered]]]; }]' }
@lazywithclass
lazywithclass / remove-as-read.js
Last active September 24, 2015 19:13
Marking comments as read on HN, the hacky way
// these are to be pasted into the console
// remove by clicking on the up arrow
// the useful thing is that you remove comments and add the removed id to
// an array, so next time you know exactly what you've considered
// (use case might be monthly "Who is hiring?")
function remove(id) {
document.getElementById(id).parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.remove();
}
[].forEach.call(
@lazywithclass
lazywithclass / challenge.js
Last active September 24, 2015 22:36
Traversing a graph whose elements you get from API calls, using a token that expires after 10 calls. Leaves contain a secret message.
var async = require('async'),
request = require('request');
function traverse(start, token) {
var queue = [];
queue.unshift(start);
async.forever(function(next) {
if (queue.length === 0) next('no more items');
var item = queue.pop();
getAdjacents(item, token, function(err, adjacents) {
@lazywithclass
lazywithclass / c for copy
Created July 24, 2011 19:26
Append c to a command and see its output copyed in the clipboard (xclip needed)
command_not_found_handle() {
if [ $(echo $1 | cut -d' ' -f1 | grep ".*c$") ]; then
echo "copying $(echo $1 | sed 's/^\([a-z][a-z]*\)c.*/\1/') results in your clipboard..."
exec $(echo $1 | sed 's/^\([a-z][a-z]*\)c.*/\1/') | copy
#just pasted the body of the system-wide function to handle c-n-f
#if the command-not-found package is installed, use it
elif [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found ]; then
# check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/bin/python /usr/lib/command-not-found -- $1
@lazywithclass
lazywithclass / partial
Created August 22, 2011 09:24
Partial function application
function partial(func /*, 0..n args */) {
var args = Array.prototype.slice.call(arguments, 1);
return function() {
var allArguments = args.concat(Array.prototype.slice.call(arguments));
return func.apply(this, allArguments);
};
}
@lazywithclass
lazywithclass / about.md
Created October 19, 2011 10:32 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@lazywithclass
lazywithclass / gist:1372959
Created November 17, 2011 11:34
Version control aware ps1
. /etc/bash_completion.d/git
function customW {
echo $PWD | sed 's|.*/\([a-Z0-9][a-Z0-9]*/[a-Z0-9][a-Z0-9]*\)|\1|'
}
function hasToPush {
git diff-index --quiet --cached HEAD &>/dev/null &&
(git svn dcommit --dry-run 2>/dev/null | grep -q "diff-tree" && echo "↑")
}
function hasToPull {
git diff-index --quiet --cached HEAD &>/dev/null && (