Skip to content

Instantly share code, notes, and snippets.

View lakim's full-sized avatar

Louis KIM lakim

View GitHub Profile
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
@wrs
wrs / DeviseJsonAdapter.rb
Created December 8, 2010 18:02
JSON-encoded error and redirect results for Devise controllers
# JSON-encoded error and redirect results for Devise controllers.
# This overrides an internal method of Devise, so be careful when updating Devise!
#
# Usage:
#
# class Users::RegistrationsController < Devise::RegistrationsController
# include DeviseJsonAdapter
# end
#
# devise_for :users, :controllers => { :registrations => "users/registrations" }
@jujudellago
jujudellago / devise.fr.yml
Created March 15, 2011 17:20
I18n French translation for Devise - Update for devise-1.1.2
#########################################################################################################
# I18n French translation for Devise (http://github.com/plataformatec/devise)
# I18n traduction française pour Devise
#
# Mise à jour par Yabo-concept http://www.yabo-concept.ch pour refléter les dernières clés utilisées par devise
# dans la branche "translated-views"
# basé sur https://github.com/davidw/devise/blob/translated-views/config/locales/en.yml
# 15.3.2011
#########################################################################################################
@ryanmarshall
ryanmarshall / gist:989900
Created May 24, 2011 22:29
Quick Ruby Signed Request Parser for Facebook
module Facebook
#
# Facebook request tools
#
class Request
class << self
def parse_signed_request(signed_request, secret, max_age=3600)
encoded_sig, encoded_envelope = signed_request.split('.', 2)
envelope = JSON.parse(base64_url_decode(encoded_envelope))
algorithm = envelope['algorithm']
@ramontayag
ramontayag / tutorial.md
Created June 24, 2011 16:21
Rails 3.1: How to embed a dummy Rails app in a gem for Cucumber testing purposes

Intro

Problem: I learned how to run RSpec to test classes and modules in my gem. But, if I wanted to test my gem as if it were already included in a Rails app, I couldn't find much info about it online.

I usually do unit tests with RSpec, and I test the whole stack with Cucumber. So here we will just setup Cucumber to run the Rails app that you embed in your gem.

Before we begin:

  • This tutorial is for people who already know how to make gems, and who have used RSpec and Cucumber before in a Rails app.
  • MyGem and my_gem below refer to the name of the gem we are creating. Replace this with your own name.
@btoone
btoone / gist:1151748
Created August 17, 2011 15:17
Ubuntu Packages for Rails Hosting

One command to rule them all

sudo aptitude install apache2 apache2-prefork-dev autoconf bison build-essential \
clang curl dnsutils git-core imagemagick libc6-dev libcurl4-openssl-dev libffi-dev \
libmagickwand-dev libmysqlclient16 libmysqlclient16-dev libreadline6-dev libsqlite3-0 \
libsqlite3-dev libssl-dev libxml2 libxml2-dev libxslt-dev libxslt1.1 libxslt1-dev \
libyaml-dev mysql-client mysql-server openssl sqlite3 wget zlib1g zlib1g-dev 
@madhums
madhums / Procfile.development
Created August 22, 2011 07:15
foreman and thinking sphinx
sphinx: bundle exec rake thinking_sphinx:run_in_foreground RAILS_ENV=development --trace
@btoone
btoone / ubuntu-lucid-setup-rails.md
Created November 17, 2011 14:06
Ubuntu Lucid Setup Guide for Rails

This note will walk you though setting up and securing a Ubuntu 10.04 LTS then deploying a Rails application with mulit-stage deployment.

TODO:

  • Add section for NGINX setup

Server Setup

@kazu69
kazu69 / pjax.rb
Created March 13, 2012 16:34
Pjax(pushState + Ajax) with Sinatra and BackboneJs
#encoding: UTF-8
require 'rubygems'
require 'sinatra'
require 'erb'
require 'pp'
class Sinatra::Request
def pjax?
env['HTTP_X_PJAX'] || self['_pjax']
@jonathanmoore
jonathanmoore / gist:2640302
Created May 8, 2012 23:17
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter