Skip to content

Instantly share code, notes, and snippets.

@jarosan
jarosan / elasticsearch.rake
Created July 16, 2012 20:37
Elasticsearch reindex task
# Run with: rake environment elasticsearch:reindex
namespace :elasticsearch do
desc "re-index elasticsearch"
task :reindex => :environment do
klass = Place
ENV['CLASS'] = klass.name
ENV['INDEX'] = new_index = klass.tire.index.name << '_' << Time.now.strftime('%Y%m%d%H%M%S')
@gorenje
gorenje / Gemfile
Created June 8, 2012 11:05 — forked from fairchild/Gemfile
An example sinatra omniauth client app
source :rubygems
gem 'sinatra'
gem 'json'
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'omniauth-github'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
# gem 'omniauth-att', :path => File.expand_path("./../../omniauth-att", __FILE__)
@bentonporter
bentonporter / gist:2891463
Created June 7, 2012 20:51
Ruby - HMAC-SHA256 example
require 'openssl'
require 'Base64'
key = "secret-key"
data = "some data to be signed"
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), key, data)).strip()
@sishen
sishen / Usage:
Created June 4, 2012 05:44
Dirty plugin for SpineJS.
So the model object can bind the event "change:#{field} to trigger event when the field value is changed.
By default it's off and if need this feature, the model should extend Spine.Model.Dirty.
A sample case.
class User extends Spine.Model
@extend Spine.Model.Dirty
end
@rylanb
rylanb / Description.text
Created May 22, 2012 01:21
Facebook IFrame Canvas Flash Issue in Internet Explorer
In Internet Explorer there was an issue where the iframe/canvas embed for a Facebook App would cause flashing as the app redirected to itself over and over as it was blocking any sort of cookies set from an external url...
Source of final AHA:
http://duanesbrain.blogspot.com/2007/11/facebook-ie-and-iframes.html
View the Page's Privacy Policy in Internet Explorer and you should see external cookies blocked for your app that is hosted elsewhere.
Solution:
Set the headers properly! (Or check if you aren't loading a file properly like Duane's solution).
@poshboytl
poshboytl / jquery.tinypubsub.coffee
Created May 11, 2012 15:52 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.(coffee)
$.subscribe = (event, handle) ->
if not o[event]
o[event] = []
o[event].push handle
true
$.unsubscribe = (event) ->
if o[event]
delete o[event]
@sishen
sishen / Usage:
Created May 10, 2012 03:19
Controller Observer: It's very similar like Sweeper but the observer should be manually added into config/application.rb. The benefit is that the observe still can be callable in the non-request environment such as console or rake.
# In Controller such as comments_controller.rb
observer :comment_observer, only: [:create, :destroy]
@sj26
sj26 / 0-readme.md
Created May 5, 2012 05:39 — forked from burke/0-readme.md
ruby-1.9.3-p194 cumulative performance patch.

Patched ruby 1.9.3-p194 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p194 with patches for boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Huge thanks to funny-falcon for the performance patches.

@iain
iain / 1_faraday.rb
Created April 22, 2012 12:23
A small sample of Faraday using Etags for caching
require 'logger'
$logger = Logger.new(STDOUT)
require 'active_support/cache'
$cache = ActiveSupport::Cache.lookup_store(:memory_store)
$cache.logger = $logger
$cache.clear
class EtagMiddleware
@sishen
sishen / clean_eco_template.rb
Created April 11, 2012 17:36 — forked from doitian/clean_eco_template.rb
CleanEcoTemplate for Sprockets in Rails app
# Put this file in lib/
require 'sprockets/eco_template'
class CleanEcoTemplate < Sprockets::EcoTemplate
FROM = " (function() {"
TO = "}).call(__obj);"
def evaluate(scope, locals, &block)
content = Eco.compile(data)