This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'raven' | |
require 'rake/task' | |
if Rails.env.production? | |
Raven.configure do |config| | |
config.dsn = 'http://xxx:xxx@app.getsentry.com/xxxxx' | |
end | |
module Rake | |
class Task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thinking_sphinx/middlewares' | |
module ThinkingSphinx | |
module Middlewares | |
class IdentityCacheMiddleware < ActiveRecordTranslator | |
def call(contexts) | |
contexts.each do |context| | |
Inner.new(context).call | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I benchmarked identity_cache with memcached vs. default active_record against mysql. | |
Setup is running on AWS, same availability zone. I used RDS (Multi AZ setup) for MySql and ElastiCache for memcached. The test server is on EC2. Instance types are m3.large for MySql, m3.xlarge for EC2 and r3.large for memcached. | |
The database is a copy of our production db. The products table holds about 1.4M entries. | |
The cache has been pre-heated with all 1.4M entries prior to the test. | |
During the test, I ran 10000 fetches: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var listId = $(this).parents().filter(function() { return $(this).data("list-id"); }).eq(0).data("list-id"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install dependencies manually | |
apt-get install odbcinst1debian2 libodbc1 unixodbc libpq5 | |
# Fetch deb package | |
mkdir -p /usr/local/build ; cd /usr/local/build && [-f sphinxsearch_2.1.4-release-0ubuntu11~precise_amd64.deb ] || wget http://sphinxsearch.com/files/sphinxsearch_2.1.4-release-0ubuntu11~precise_amd64.deb | |
# Install package | |
dpkg --install /usr/local/build/sphinxsearch_2.1.4-release-0ubuntu11~precise_amd64.deb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
layout :conditionally_select_layout | |
# Like `layout`, but allows conditional overriding in app controller | |
def self.preferred_layout(value = nil) | |
@preferred_layout = value unless value.nil? | |
@preferred_layout | |
end | |
private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires ImageMagick | |
# Converting the source from JPEG to PNG - if necessary | |
convert my_src_image.jpg my_src_image.png | |
# Option A | |
# - Requires a temporary intermediate file | |
# - Drill more than 10 might result in poor results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dashing.js is located in the dashing framework | |
# It includes jquery & batman for you. | |
#= require dashing.js | |
#= require_directory . | |
#= require_tree ../../widgets | |
console.log("Yeah! The dashboard has started!") | |
Dashing.on 'ready', -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- app/views/devise/omniauth/link_user.html.erb --> | |
<h2>Link your account</h2> | |
<%= form_for(@user, :url => user_omniauth_link_url, :html => { :method => :put }) do |f| %> | |
<p>You already have an account, that was created with email and password. To link your Facebook account, please enter your password. If you can't remember your password, you can recover it by clicking the link below.</p> | |
<%= render "devise/shared/error_messages" %> | |
<div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# C implementation of Levenshtein text distance algorithm, uses RubyInline to call from within Ruby | |
# Wildly faster than the Text gem's Text::Levenshtein | |
# Example: | |
# l = Levenshtein.new | |
# l.distance 'hello', ' hello' | |
# => 1 | |
# Taken from http://www.benallfree.com/2008/10/05/finding-duplicate-text-with-ruby/ |