Skip to content

Instantly share code, notes, and snippets.

@ryands
ryands / module.js
Created June 19, 2014 17:49
JS Module pattern - quick example
/* Module pattern in javascript
* Not using RequireJS/ES6/Node/...
*/
var MyModule = (function () {
function SubClass() {
// constructor
}
SubClass.prototype.someMethod = function() {
@ryands
ryands / gist:193251a517599d82ed75
Created June 16, 2014 21:47
Lodash vs. Underscore (benchmarks)
Chrome 36.0.1985.67 on OS X 10.9.3
Sit back and relax, this may take a while.
`_(...)` with a number:
lodash.min x 148,659,845 ops/sec ±1.16% (83 runs sampled)
underscore-min x 21,250,737 ops/sec ±0.71% (89 runs sampled)
lodash.min is 596% faster.
`_(...)` with an array:

Keybase proof

I hereby claim:

  • I am ryands on github.
  • I am ryands (https://keybase.io/ryands) on keybase.
  • I have a public key whose fingerprint is D0CA AAC9 FC0A 7B41 829B 31B0 3369 F0BD BB2C E1EB

To claim this, I am signing this object:

@Override
protected void onResume() {
super.onResume();
loadImageWhenReady(imageView, mPayload);
}
private static void loadImageWhenReady(final ImageView v, final String url) {
v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
@ryands
ryands / callback.js
Created March 28, 2014 22:07
throwaway gist
var addition = function(a, b, callback) {
var result = a + b;
if (callback != null) {
callback(result);
}
};
addition(2, 3, function(result) {
alert("The sum is " + result + "!");
});
@ryands
ryands / Builder.java
Last active August 29, 2015 13:56
Lunch Tech Talk - 2/6/2014 - Builder pattern - Sample code. Gist broke my formatting/indentation
public class Builder {
public static void main(String... args) {
DogeBuilder builder = new DogeBuilder();
builder.setSo("design")
.setSuch("pattern")
.setVery("software engineering");
System.out.println(builder.build());
}
@ryands
ryands / gist:7922304
Created December 12, 2013 02:24
Monkey patch for Hash fun.
class Hash
# This will favor :symbol keys over string keys
def method_missing (method, *args)
if has_key? method.to_sym
self[method.to_sym]
elsif has_key? method.to_s
self[method.to_s]
else
super
end
@ryands
ryands / SplashActivity.java
Last active December 23, 2015 09:49
A proper splash screen implementation for android.
package org.ryands.android;
import android.app.Activity;
import android.os.Bundle;
/**
* A proper splash screen for android.
*/
public class SplashActivity extends Activity {
@Override
@ryands
ryands / logconcat.py
Created May 31, 2013 23:14
IRSSI log concatenation, sort by date from multiple input files.
#!/usr/bin/env python
# usage: ./logconcat.py output.log [list, of, input, files]
# Eventually I'll put all log entries in a db for more fun.
from datetime import datetime
class LogEntry():
def __init__(self, date, entry):
@ryands
ryands / attr2style.pl
Created October 26, 2012 22:29
attributes to style xml
#!/usr/bin/env perl -w
use strict;
print "<style name=\"" . shift . "\">\n";
while (<>) {
print " <item name=\"$1\">$2</item>\n" if ($_ =~ /\s*([^=]+)=\"([^\"]+)\"/i);
}
print "</style>\n";