Skip to content

Instantly share code, notes, and snippets.

View aliang's full-sized avatar

Alvin Liang aliang

View GitHub Profile
@aliang
aliang / example.haml
Created March 31, 2011 09:19
returning after omniauth
# Link to /sign-in/:provider?return_to=current_page in your view. This example shows auth using Twitter in a HAML view
%a{ :href => "/sign-in/twitter?return_to=" + request.env['PATH_INFO'] }
@aliang
aliang / font-face.css
Created March 11, 2011 11:29
bulletproof font-face
/* replace filenames and other stuff as needed
* the main point is to have the four formats available
* see also fontsquirrel.com, this is where I got it
*/
@font-face {
font-family: 'ChunkFiveRegular';
src: url('Chunkfive-webfont.eot');
src: url('Chunkfive-webfont.eot?iefix') format('eot'),
url('Chunkfive-webfont.woff') format('woff'),
@aliang
aliang / application_controller.rb
Created February 1, 2011 23:53
Force SSL on Devise routes only, then redirect back
class ApplicationController < ActionController::Base
# Tell Devise to redirect after sign_in
def after_sign_in_path_for(resource_or_scope)
some_url(:protocol => 'http')
end
# Tell Devise to redirect after sign_out
def after_sign_out_path_for(resource_or_scope)
some_url(:protocol => 'http')
end
db/*.sqlite3
log/*.log
tmp/**/*
bin/*
vendor/gems/ruby/1.8/*
!vendor/gems/ruby/1.8/cache/
require 'fileutils'
dirs = Dir['path_to_your_root_music_directory/**/*.*']
begin
file = dirs[rand(dirs.size)]
end until File.file?(file)
# could check to make sure your dropbox folder is mounted/exists here
# remove all files from this dropbox folder
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
@aliang
aliang / prototype-within-viewport.js
Created August 1, 2010 08:23
methods for seeing if something is in the viewport. see also http://github.com/xing/prototype-within-viewport
Element.Methods.centerIsWithinViewport = function(element) {
var dim = document.viewport.getDimensions();
var so = document.viewport.getScrollOffsets();
var co = element.cumulativeOffset();
var edim = element.getDimensions();
// x and y measured from upper left
var center = {
x: co.left + (edim.width / 2),
y: co.top + (edim.height / 2)
}
# List of environments and their heroku git remotes
ENVIRONMENTS = {
:staging => 'myapp-staging',
:production => 'myapp-production'
}
namespace :deploy do
ENVIRONMENTS.keys.each do |env|
desc "Deploy to #{env}"
task env do
(function(){
function delegateHandler(e){
var element = e.element(), elements = element.ancestors ? element.ancestors().concat([element]) : [element];
((Element.retrieve(this, 'prototype_delegates') || $H()).get(e.eventName || e.type) || []).each(function(pair){
if (element = Selector.matchElements(elements, pair.key)[0])
pair.value.invoke('call', element, e);
});
}
function delegate(element, selector, event, handler){
@aliang
aliang / gist:263863
Created December 26, 2009 06:20 — forked from retr0h/gist:98308
content type handling for sinatra
CONTENT_TYPES = {:html => 'text/html', :css => 'text/css', :js => 'application/javascript'}
before do
# instead of using case here, metaprogram it
request_uri = case request.env['REQUEST_URI']
when /\.css$/ : :css
when /\.js$/ : :js
else :html
end
content_type CONTENT_TYPES[request_uri], :charset => 'utf-8'