Skip to content

Instantly share code, notes, and snippets.

View duncanbeevers's full-sized avatar
🔊


Duncan Beevers duncanbeevers

🔊

View GitHub Profile
module SessionsHelper
def sign_in(user)
cookies.permanent.signed[:remember_token] = [user.id, user.salt]
self.current_user = user
end
def current_user=(user)
@current_user = user
end
!!!
%html
%head
= csrf_meta_tags
= stylesheet_link_tag "application"
%body
= yield
= javascript_include_tag "application"
= render_inline_javascript_controller_action_asset
@duncanbeevers
duncanbeevers / rename_rails_migrations.rb
Created June 15, 2011 17:29
Rename Rails 1 style migration names to timestamp filenames
require 'fileutils'
Dir['./db/migrate/*.rb'].each do |from|
to = File.join(File.dirname(from),
"%014d%s" % File.basename(from).match(/^(\d+)(_.*)$/)[1..-1].map.with_index do |f, i|
0 == i ? f.to_i : f
end)
FileUtils.mv(from, to) if from != to
end
@duncanbeevers
duncanbeevers / throttle.js
Created May 11, 2011 21:56
throttle a given function
function throttle(millis, fn) {
var sched;
return function() {
if (!sched)
sched = setTimeout(function executeAndClear() { fn(); sched = false; }, millis);
};
}
@duncanbeevers
duncanbeevers / Readme.md
Created April 8, 2011 11:00
Create a jQuery Template tag method out of a template

Expose jQuery templates as helper methods

Example: <script type="text/x-jquery-tmpl" id="timeTagTemplate"> ${$data} </script> <script type="text/x-jquery-tmpl" id="commentTemplate">

${username} {{time commented_at}}

package {
import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.graphics.Graphiclist;
import net.flashpunk.graphics.Text;
public class HUD extends Entity {
[Embed(source = "assets/fonts/pf_tempesta_seven.TTF", embedAsCFF=false, fontFamily = "what")]
public var myvar:String;
function AsynchDispatcher() {
var listeners = [],
m = 'message',
w = window;
function receiveMessage(index) {
index = parseInt(index.data || index);
setTimeout(listeners[index], 10);
if (index) {
Factory.sequence :luhn do |n|
def luhn?(n)
odd = false
0 == n.to_s.scan(/\d/).inject(0) { |a, d|
i = d.to_i * (odd = !odd ? 2 : 1)
a + (i > 9 ? i - 9 : i)
} % 10
end
require 'stringio'
class Capistrano::Logger
class StringIOProxy < StringIO
def initialize(proxy_target)
@proxy_target = proxy_target
super('')
end
def write(*args)
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
var Base64 = (function() {
// Private methods for UTF-8 encoding and decoding