Skip to content

Instantly share code, notes, and snippets.

Avatar

Alberto Zaccagni lazywithclass

View GitHub Profile
@lazywithclass
lazywithclass / gist:1378190
Created Nov 19, 2011
Invert a string (the inefficient way)
View gist:1378190
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();
}
View gist:1388891
[SeatDefaults]
greeter-session=lightdm-gtk-greeter
user-session=xubuntu
View gist:1411161
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 Dec 21, 2011
Quick each (took from here https://gist.github.com/500145 without spaces)
View gist:1506587
// 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(){
View gist:1506629
jQuery.fn.quickEach = (function() {
var jq = jQuery([1]);
return function(c) {
var i = -1, el, len = this.length;
try {
while (++i < len && (el = jq[0] = this[i]) && c.call(jq, i, el) !== false);
} catch (e) {
delete jq[0];
throw e;
}
@lazywithclass
lazywithclass / gist:1511267
Created Dec 22, 2011
Builder pattern with compile time check
View gist:1511267
public class Complex {
private Complex() {}
public static void main(String[] args) {
new ComplexBuilder()
.setFirst("first")
.setSecond("second")
.setThird( "third" )
.build();
@lazywithclass
lazywithclass / gist:1582626
Created Jan 9, 2012
TDD functions for emacs
View gist:1582626
(global-set-key (kbd "C-c C-r") 'run-mocha)
(defun run-mocha()
"Runs all the tests in the current buffer"
(interactive)
(let* (command result exit-value)
(setq command (concat "mocha -r should " (buffer-name)))
(setq exit-value (shell-command command))
(color-modeline exit-value)))
View gist:1713723
request({
method: "POST",
uri: "http://example.com/action",
json: {
foo: "foo",
bar: "bar"
}
}, function (error, response, body) {
if(response.statusCode === 201){
console.log("posted");
View gist:1748552
//I've launched my app as so: NODE_ENV=development nodemon server.js
var Log = new require("log"),
log = new Log(process.env.NODE_ENV === "production" &&
"error" || "debug");
@lazywithclass
lazywithclass / gist:1790981
Created Feb 10, 2012
TDD functions revised (added chance to run a single test)
View gist:1790981
(defun mocha-run(test-file)
"Runs all the tests in the passed file"
(interactive "b")
(let* (command result exit-value)
(setq command (concat "mocha -r should --globals i --timeout 10000 " test-file))
(setq exit-value (shell-command command))
(color-modeline test-file)))
(defun color-modeline(test-file)
"Colors the modeline, green success red failure"
(interactive)