Skip to content

Instantly share code, notes, and snippets.


Chamnap Chhorn chamnap

View GitHub Profile
Mic92 / index.html
Last active Dec 15, 2015
Zeroclipboard css styling for twitter bootstrap
View index.html
<button id="copy" class="btn">Copy</button>
ryanb / episode_search.rb
Created Feb 18, 2013
Class that handles the PostgreSQL full text search for
View episode_search.rb
class EpisodeSearch
attr_reader :ability, :options
delegate :sanitize, to: Episode
def initialize(ability, options = {})
@ability = ability
@options = options.dup
def tag
ryanb /
Created Nov 29, 2012
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base
marcusmalmberg /
Last active Jun 14, 2021
Guide to setup CarrierWave which will upload a file to Amazon S3 in production environment and use local storage in development and test

CarrierWave home

This example will create an uploader that will upload a file stored in a model Model. The file will be stored locally in development and test environment and will use Amazon S3 in production.

CarrierWave installation

First add the gems.

ryanb / tasks_controller_refactoring.rb
Created Nov 9, 2012
Variation of RubyTapas episode "021 Domain Model Events" without using callbacks
View tasks_controller_refactoring.rb
class TasksController < ApplicationController
def update
tracker =
if @task.update_attributes(params[:task]), socket_id).push_changes, current_user).deliver_email
# success response
# failure respond
ryanb / abilities.rb
Created Sep 15, 2012
How you can break up large Ability class in CanCan
View abilities.rb
module Abilities
def self.ability_for(user)
if user.admin?
else user
greypants / README.markdown
Last active Jan 31, 2019 — forked from reagent/nav_link.rb
RAILS 3: nav_link helper for adding 'selected' class to navigation elements
View README.markdown
jshaw / FacebookPageTabResizeiFrame.html
Created Jul 26, 2012
Resize the Facebook iFrame Tab Page with resizing content and different page heights on page loads.
View FacebookPageTabResizeiFrame.html
<!DOCTYPE html>
<html lang="en" style="overflow: hidden">
<body style="overflow:hidden">
<!-- You need to include jquery & FBSDK-->
<div id="fb-root"></div>
window.fbAsyncInit = function() {
mperham / after.rb
Created Jul 4, 2012
Thread-friendly shared connection
View after.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || => 1) { retrieve_connection }
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
jonathanmoore / gist:2640302
Created May 8, 2012
Get the share counts from various APIs
View gist:2640302

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.