Skip to content

Instantly share code, notes, and snippets.

View yetanothernguyen's full-sized avatar

Nguyen Vu Nguyen yetanothernguyen

View GitHub Profile
def failed(job)
begin
if job.payload_object.respond_to? :on_permanent_failure
say "Running on_permanent_failure hook"
job.payload_object.on_permanent_failure
end
rescue DeserializationError
# do nothing
end
def failed(job)
begin
if job.payload_object.respond_to? :on_permanent_failure
say "Running on_permanent_failure hook"
job.payload_object.on_permanent_failure
end
rescue DeserializationError
# do nothing
end
@yetanothernguyen
yetanothernguyen / youtube
Created June 28, 2011 04:29
Youtube wrapper class
require 'youtube_it'
module Says
class Youtube
attr_accessor :video, :vid, :client
def initialize(url=nil, username=nil, password=nil, dev_key=nil)
@url = url
@username = username
@password = password
@dev_key = dev_key
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
//= require underscore
//= require backbone
// TODO: move this out
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
@yetanothernguyen
yetanothernguyen / gist:1196486
Created September 6, 2011 03:08
unicorn config
# Sample verbose configuration file for Unicorn (not Rack)
#
# This configuration file documents many features of Unicorn
# that may not be needed for some applications. See
# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
# for a much simpler configuration file.
#
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.
@yetanothernguyen
yetanothernguyen / gist:1196492
Created September 6, 2011 03:11
unicorn init script
#!/bin/bash
### BEGIN INIT INFO
# Provides: says-dot-com-production
# Required-Start: $all
# Required-Stop: $network $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the says-dot-com-production unicorns at boot
# Description: Enable says-dot-com-staging at boot time.
### END INIT INFO
@yetanothernguyen
yetanothernguyen / gist:1246989
Created September 28, 2011 04:29
erly.com image tag
<div class="post card laidout" data-postid="2416174" id="post_2416174" style="top: 0px; left: 261px; width: 250px; height: 192px; "> <div class="photo" style="width: 250px; height: 162px; ">
<img class="needs-center-letterbox lazy-loaded center-letterboxed" data-lazy-src="https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/314433_10150264072250981_567335980_8068159_6857977_n.jpg" src="https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/314433_10150264072250981_567335980_8068159_6857977_n.jpg" alt="" data-height="540" data-width="720" style="height: auto; width: 250px; margin-left: 0px; margin-top: -9px; opacity: 1; ">
<div class="enlarge-overlay overlay fade-in" style="width: 250px; height: 162px; display: none; "></div>
</div>
</div>
@yetanothernguyen
yetanothernguyen / config.bluepill
Created October 7, 2011 09:35
bluepill config for delayed_job
Bluepill.application("says", :log_file => "/var/www/says-dot-com-staging/current/log/bluepill.log") do |app|
app.process("delayed_job") do |process|
process.working_dir = "/var/www/says-dot-com-staging/current"
process.stdout = process.stderr = "/var/www/says-dot-com-staging/current/log/delayed_job.log"
process.start_grace_time = 60.seconds
process.stop_grace_time = 60.seconds
process.restart_grace_time = 60.seconds
process.start_command = "/usr/bin/env RAILS_ENV=staging bundle exec script/delayed_job start --db=us --pid-dir=/var/www/says-dot-com-staging/shared/pids --prefix staging"
Loading development environment (Rails 3.1.1)
:001 > user = User.create(:name => "user1")
(0.5ms) BEGIN
SQL (9.7ms) INSERT INTO `users` (`created_at`, `name`, `updated_at`) VALUES ('2011-11-01 05:35:51', 'user1', '2011-11-01 05:35:51')
(0.5ms) COMMIT
=> #<User id: 2, name: "user1", created_at: "2011-11-01 05:35:51", updated_at: "2011-11-01 05:35:51">
:002 > story1 = Story.create(:title => "title1")
=> #<Story _id: BSON::ObjectId('4eaf85562ab0f56c6e000001'), title: "title1">
:003 > story2 = Story.create(:title => "title2", :featured => true)
=> #<Story _id: BSON::ObjectId('4eaf85762ab0f56c6e000003'), featured: true, title: "title2">
rake, version 0.9.2.2