Skip to content

Instantly share code, notes, and snippets.

config.action_controller.asset_host = Proc.new do |source, request|
non_ssl_host = "http://asset#{source.hash % 4}.backpackit.com"
ssl_host = "https://asset1.backpackit.com"
if request.ssl?
case
when source =~ /\.js$/
ssl_host
when request.headers["USER_AGENT"] =~ /(Safari)/
non_ssl_host
var DateHelper = {
// Takes the format of "Jan 15, 2007 15:45:00 GMT" and converts it to a relative time
// Ruby strftime: %b %d, %Y %H:%M:%S GMT
time_ago_in_words_with_parsing: function(from) {
var date = new Date;
date.setTime(Date.parse(from));
return this.time_ago_in_words(date);
},
time_ago_in_words: function(from) {
require 'yaml'
class Hash
def filter(*keys)
self.inject({}){|h,v| h[v.first] = v.last if keys.include?(v.first); h}
end
end
test_hash = {'one' => 1, 'two' => 2, 'three' => 3}
puts test_hash.to_yaml
require 'yaml'
class Hash
def filter(*keys)
self.inject({}) {|h,(k,v)| h[k] = v if keys.include?(k); h}
end
end
test_hash = {'one' => 1, 'two' => 2, 'three' => 3}
puts test_hash.to_yaml
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@r38y
r38y / gist:366080
Created April 14, 2010 17:23
MongoDB init.d script for Ubuntu 8.04 LTS
# since there is no deb package for Ubuntu 8.04 LTS, this is what I had to do
# download latest stable version of mongodb and move to /usr/local/mongodb
# add "export PATH=$PATH:/usr/local/mongodb/bin" to /etc/profile
# make directories for the data /db/mongodb/master and /db/mongodb/slave
# chown those directories to the user you want
# move this script to /etc/init.d/mongodb
# chmod +x /etc/init.d/mongodb
# update-rc.d mongodb defaults
RETVAL=0
module Paperclip
class Geometry
def self.from_file file
parse("100x100")
end
end
class Thumbnail
def make
src = Test::FileHelper.fixture_file('white_pixel.jpg')
dst = Tempfile.new([@basename, @format].compact.join("."))
# checkout: http://github.com/igrigorik/async-rails/
From bb2a78858cffa7c6937642986e9aca1a4f862c0d Mon Sep 17 00:00:00 2001
From: Ilya Grigorik <ilya@igvita.com>
Date: Thu, 10 Jun 2010 00:46:48 -0400
Subject: [PATCH] async rails3
---
Gemfile | 6 ++++++
app/controllers/widgets_controller.rb | 6 ++++++
@kdwinter
kdwinter / authenticable.rb
Created June 14, 2010 21:52
Authlogic with Mongoid (in spirit of http://pastie.org/503478)
module Authenticable
def self.included(model)
model.class_eval do
extend ClassMethods
include InstanceMethods
field :username
field :email
field :crypted_password
field :password_salt
@kdwinter
kdwinter / authenticable.rb
Last active September 5, 2015 05:45
Authlogic plugin for MongoMapper
module Authenticable
extend ActiveSupport::Concern
included do
key :username, String
key :email, String
key :crypted_password, String
key :password_salt, String
key :persistence_token, String
key :login_count, Integer, :default => 0