Skip to content

Instantly share code, notes, and snippets.

---
- name: Update APT
action: apt update-cache=yes
tags:
- install
ignore_errors: True
@arunthampi
arunthampi / macdeb.sh
Created May 16, 2012 00:36
Ruby formula for Macdeb
# This creates a deb package called macdeb-ruby-1.9.3-p125_x86_64.deb
#
# You can then install it (including dependencies) using gdebi
# `sudo gdebi macdeb-ruby-1.9.3-p125_x86_64.deb`
#
# To install gdebi, run `sudo aptitude install gdebi-core`
macdeb create --formula ruby --namespace macdeb --pkgname ruby --pkgver 1.9.3-p125
@arunthampi
arunthampi / global_leaderboard.rb
Created January 19, 2012 06:00
Voting and ranking used in GitHeroes
def self.leaderboard
Hero.select("id, login, name, location, votes_received, avatar_url, html_url, rank() over(order by votes_received DESC)").limit(20)
end
@arunthampi
arunthampi / set_asset_fingerprint.rb
Created January 3, 2012 08:33
Set Asset Fingerprint as part of the deployment workflow
def set_asset_fingerprint!
# -- First see if the files have changed
puts "-----> Calculating Asset Fingerprint"
fingerprint_method = "find public -type f -exec md5 {} + | awk '{print $0}' | sort | md5"
current_fingerprint = %x{#{fingerprint_method}}
fingerprint_file = Rails.root.join('assets.fingerprint')
if !File.exists?(fingerprint_file) || current_fingerprint != File.read(fingerprint_file)
execute("#{fingerprint_method} > #{fingerprint_file}")
# -- Add it to production
@arunthampi
arunthampi / application.rb
Created January 3, 2012 08:32
GetDenso Rails Application Config
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module GetDenso
class Application < Rails::Application
@arunthampi
arunthampi / desc_order_index.sql
Created December 6, 2011 06:25
Descending order indexes leads to 10x improvement in response time
CREATE INDEX desc_created_citems_idx on channel_items(created_at DESC NULLS LAST);
@arunthampi
arunthampi / transaction.rb
Created September 23, 2011 00:16
Transactions for nested creation of objects in a controller
Channel.transaction do
@channel.save
rss_bot = @channel.build_youtube_rss_bot(:username => youtube_username)
if rss_bot.valid?
rss_bot.save
Delayed::Job.enqueue(SocialFeed::YoutubeRssScraper.new(rss_bot))
else
@channel.errors.add(:youtube_username, rss_bot.errors[:username])
@arunthampi
arunthampi / no_end.haml
Created July 20, 2011 03:27
No 'end's in HAML
%ul
- @feed_stories.each do |story|
%li= render :partial => 'feed_item', :locals => { :s => story }
= will_paginate @feed_stories
@arunthampi
arunthampi / pusher_jasmine.js
Created February 3, 2011 16:23
Testing Web Sockets (Pusher) with Jasmine
describe('pusher', function() {
describe('message event', function() {
it("should append the message to the timeline", function() {
spyOn(room, 'appendMessage');
spec.loadFixture('room-show');
room.pusher.send_local_event('message', messageStub('abc-def-ced'), room.room_id);
expect(room.appendMessage).toHaveBeenCalled();
});
});
});
@arunthampi
arunthampi / apache_bench.sh
Created January 18, 2011 14:05
Unscientific Node vs Cramp
ab -n 1000 -c 1000 http://0.0.0.0:3000/