Skip to content

Instantly share code, notes, and snippets.

Avatar

Alvin Liang aliang

  • Burlingame, CA
View GitHub Profile
@aliang
aliang / expr.py
Created Jan 10, 2011
expr template tag for evaluating arbitrary python in django templates
View expr.py
# app/common/templatetags/expr.py
from django import template
from django.utils.translation import gettext_lazy as _
from django.conf import settings
import re
register = template.Library()
class ExprNode(template.Node):
@aliang
aliang / application_controller.rb
Created Feb 1, 2011
Force SSL on Devise routes only, then redirect back
View application_controller.rb
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
@aliang
aliang / font-face.css
Created Mar 11, 2011
bulletproof font-face
View font-face.css
/* 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 / example.haml
Created Mar 31, 2011
returning after omniauth
View example.haml
# 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 / optimize-legibility.html
Created Apr 2, 2011 — forked from kolber/optimize-legibility.html
kerning/ligatures using text-rendering:optimizeLegibility CSS
View optimize-legibility.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cross-browser kerning-pairs & ligatures</title>
<style>
body { font-family: sans-serif; background: #f4f3f3; color: rgba(40, 30, 0, 1); width: 500px; margin: 80px auto; padding: 0px; }
a { color: rgba(15, 10, 0, 0.8); text-decoration: none; border-bottom: 1px solid; padding: 1px 1px 0px; -webkit-transition: background 1s ease; }
a:hover { background: rgba(0, 220, 220, 0.2); }
p, li { line-height: 1.5; padding: 0em 1em 0em 0em; margin: 0em 0em 0.5em; }
@aliang
aliang / fakeout.rake
Created Apr 3, 2011 — forked from matthutchinson/fakeout.rake
fill your database with crap using faker
View fakeout.rake
# a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# NOTE: requires the faker or ffaker gem
# sudo gem install faker - http://faker.rubyforge.org
# OR
# sudo gem install ffaker - http://github.com/EmmanuelOga/ffaker
require 'faker'
class Fakeout
@aliang
aliang / watir.rb
Created May 26, 2011
watir basics that I always forget
View watir.rb
require 'rubygems'
require 'watir'
#start the browser up
Watir::Browser.default = "firefox"
browser = Watir::Browser.start "http://www.weather.com/"
browser.text_field(:id, "whatwhereForm2").set("san diego, ca")
browser.button(:src,"http://i.imwx.com/web/common/searchbutton.gif").click
@aliang
aliang / migrate_s3.rake
Created Jun 6, 2011 — forked from felixalias/migrate_s3.rake
rake task to migrate paperclip attachments to Amazon S3
View migrate_s3.rake
namespace :attachments do
task :migrate_to_s3 => :environment do
require 'aws/s3'
# Load credentials
s3_options = YAML.load_file(File.join(Rails.root, 'config/s3.yml')).symbolize_keys
bucket = s3_options[:bucket_name]
# Establish S3 connection
@aliang
aliang / routes.rb
Created Jun 6, 2011
Force SSL on routes, version 2, doesn't use Devise
View routes.rb
YourApplication::Application.routes.draw do
class SSL
def self.matches?(request)
# This way you don't need SSL for your development server
return true unless Rails.env.production?
request.ssl?
end
end
# Reusable Proc for redirection. Will redirect with 301 (on Rails 3.0, at least)
@aliang
aliang / omniauth.rb
Created Jun 7, 2011 — forked from dira/omniauth.rb
OmniAuth strategy for a custom provider
View omniauth.rb
module OmniAuth
module Strategies
# tell OmniAuth to load our strategy
autoload :Pixelation, 'lib/pixelation_authorization'
end
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "app_name", "secret"
provider :facebook, "app_name", "secret", :scope => ''