Skip to content

Instantly share code, notes, and snippets.

# jsminlib.rb 2007-12-29
# Author: David Troy <dave@popvox.com>
# Based directly on jsmin.rb by Uladzislau Latynski
# Converted to use the JSMin class and the minimize method rathert han
# stdin/stdout
#
# This work is a translation from C to Ruby of jsmin.c published by
# Douglas Crockford. Permission is hereby granted to use the Ruby
# version under the same conditions as the jsmin.c on which it is
# based.
function smiley() {
if [ $? = 0 ]; then
printf $1
else
printf $2
fi
return $?
}
# Show lots of info in the __git_ps1 output.
@ryanb
ryanb / application.html.erb
Created January 19, 2011 19:31
Example of very simple password authentication.
<!-- layout file -->
<% if current_user %>
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %>
<% else %>
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>.
<% end %>
@moro
moro / gist:1024620
Created June 14, 2011 10:05
Kaminari and pushState
(function($){
$('.pagination a[data-remote=true]').live('ajax:success', function(e){ window.history.pushState('', '', $(e.target).attr('href')) })
$(window).bind('popstate', function(){ $.ajax({url:window.location, dataType:'script'}) ; return true });
})(jQuery);
@gnunicorn
gnunicorn / modernizr-snippet.js
Created January 2, 2012 13:54
Nachbarschaftsauto Photo stack Animation
var photo_stack_speed = 7500;
Modernizr.load([
{
load: '//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
complete: function() {
if (!window.jQuery) {
Modernizr.load('/js/libs/jquery-1.5.2.min.js');
}
}
},
@coreyhaines
coreyhaines / .rspec
Last active April 11, 2024 00:19
Active Record Spec Helper - Loading just active record
--colour
-I app
@mdigital
mdigital / tarsnap-install.sh
Created April 18, 2012 02:40
Debian / Ubuntu Tarsnap installation
#!/bin/sh
# Installs tarsnap client on Debian and Ubuntu
#
# You'll need to setup an account at
# http://www.tarsnap.com
# and load it with some funds
#
# Make sure you run this as root
#
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

class Handlers
constructor: ->
@handlers = {}
register: (handler, registered_class) ->
@handlers[handler] = registered_class
instantiate: (handlers, element) ->
handlers = handlers.replace(/\s/g, '').split(',')
element.handlers = []