Skip to content

Instantly share code, notes, and snippets.

View lazywithclass's full-sized avatar

Alberto Zaccagni lazywithclass

View GitHub Profile
@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 && (
@lazywithclass
lazywithclass / gist:1378190
Created November 19, 2011 00:26
Invert a string (the inefficient way)
public static String invert(String invertMe) {
StringBuilder output = new StringBuilder();
for (int i=invertMe.length(); i>0; i--) {
output.append(invertMe.charAt(i-1));
}
return output.toString();
}
@lazywithclass
lazywithclass / gist:1388891
Created November 23, 2011 14:59
xfce settings
[SeatDefaults]
greeter-session=lightdm-gtk-greeter
user-session=xubuntu
@lazywithclass
lazywithclass / gist:1402417
Created November 28, 2011 22:39
Fibonacci tail recursion in Scheme
(define (fib n)
(define (iter a b count)
(if (<= count 0)
a
(iter b (+ a b) (- count 1))))
(iter 0 1 n))
@lazywithclass
lazywithclass / gist:1402456
Created November 28, 2011 22:49
Fibonacci tail recursion in Java
public static long tailRecursive(long n) {
if (n <= 2) {
return 1;
}
return tailRecursiveAux(0, 1, n);
}
private static long tailRecursiveAux(long a, long b, long count) {
if(count <= 0) {
return a;
@lazywithclass
lazywithclass / gist:1411161
Created November 30, 2011 21:56
Array covariance
public class Test {
class Parent {}
class Child extends Parent {}
public void accept(Parent[] parent) {
System.out.println("accepted");
}
public static void main(String[] args) {
@lazywithclass
lazywithclass / gist:1506587
Created December 21, 2011 16:14
Quick each (took from here https://gist.github.com/500145 without spaces)
// The `quickEach` method will pass a non-unique jQuery instance
// to the callback meaning that there will be no need to instantiate
// a fresh jQuery instance on each iteration. Most of the slow-down
// inherent in jQuery's native iterator method (`each`) is the constant
// need to have access to jQuery's methods, and so most developers
// see constructing multiple instances as no issue... E.g.
// $(...).each(function(){ $(this)... $(this)... $(this)... });
// A better approach would be `quickEach`.
jQuery.fn.quickEach = (function(){