Skip to content

Instantly share code, notes, and snippets.

View kenmazaika's full-sized avatar

ken mazaika kenmazaika

View GitHub Profile
@kenmazaika
kenmazaika / client_validated_fields.rb
Created February 12, 2011 04:17
Add Client-Side validation to ActiveResource
class User << ActiveResource
class ClientValidatedFields
attr_accessor :phone
include ActiveModel::Validations
validates :phone, :presence => true, :length => { :maximum => 10, :minimum => 10 }, :numericality => true
def initialize(*args)
(args.first.first || {}).each_pair do |k, v|
send("#{k}=".to_sym, v) if self.respond_to?("#{k}=".to_sym)
end
https://github.com/myronmarston/vcr/blob/master/lib/vcr.rb
require 'rubygems'
require 'activemerchant'
LOGIN_ID = '************'
TRANSACTION_KEY = '**********'
ActiveMerchant::Billing::Base.mode = :test
ActiveMerchant::Billing::CreditCard.require_verification_value = false
gateway = ActiveMerchant::Billing::AuthorizeNetCimGateway.new(:login => LOGIN_ID, :password => TRANSACTION_KEY)
@kenmazaika
kenmazaika / sources.list
Created June 12, 2011 22:07
ubuntu chef server
deb http://apt.opscode.com/ lucid-0.10 main
@kenmazaika
kenmazaika / gist:1022055
Created June 12, 2011 22:17
haproxy.cfg
global
maxconn 4096
daemon
nbproc 1
defaults
mode http
clitimeout 60000
srvtimeout 30000
contimeout 4000
option httpclose
@kenmazaika
kenmazaika / gist:1081459
Created July 13, 2011 22:17
install_im.sh
#!/bin/bash
# Install ImageMagick on Snow Leopard (10.6)
# Reported to work also on Leopard (10.5)
#
# Created by Claudio Poli (http://www.icoretech.org)
# Configuration.
# Set the sourceforge.net's mirror to use.
SF_MIRROR="heanet"
# ImageMagick configure arguments.
@kenmazaika
kenmazaika / Console Output
Created February 20, 2012 18:45
Start and Stop tasks for resque workers, with capistrano deploy hook, killing correct processes (without God)
** [out :: ec2-174-129-60-95.compute-1.amazonaws.com] $ kill -s QUIT 12689 12692 12696 12686
** [out :: ec2-174-129-60-95.compute-1.amazonaws.com]
** [out :: ec2-174-129-60-95.compute-1.amazonaws.com] Starting 1 worker(s) with QUEUE: *
** [out :: ec2-174-129-60-95.compute-1.amazonaws.com]
** [out :: ec2-174-129-60-95.compute-1.amazonaws.com] Starting 3 worker(s) with QUEUE: OMG
** [out :: ec2-174-129-60-95.compute-1.amazonaws.com]
@kenmazaika
kenmazaika / post.html
Created February 21, 2012 11:18
Embed Gist In Tumblr, File By File
<div class="gist">
<a href=
"https://gist.github.com/1870642.js?file=resque.rake">https://gist.github.com/1870642.js?file=resque.rake</a>
</div>
@kenmazaika
kenmazaika / turn.rb
Created February 22, 2012 14:49
Optionally using Turn with Bundler
# config/initializers/turn.rb
# this file is ignored by the gitignore file
if(Rails.env.test? || Rails.env.integration?)
files = [
'/Users/kmazaika/.rvm/gems/ruby-1.9.3-p0@gem_set_name/gems/minitest-2.8.1/lib/minitest/autorun.rb',
'/Users/kmazaika/.rvm/gems/ruby-1.9.3-p0@gem_set_name/gems/turn-0.9.3.ken/lib/turn.rb'
]
files.each do |file|
$:.unshift File.dirname(file)
@kenmazaika
kenmazaika / max_out_join_query.sql
Created March 1, 2012 16:51
Tyler's Max 'B' For Every 'A' Query
Here's an example -- this returns the max "b" record for every "a".
Tyler
mysql> create table x (a int, b int);
Query OK, 0 rows affected (0.18 sec)
mysql> insert x values (1, 1), (1, 2), (1, 3), (2, 5), (2, 8), (3, 10);
Query OK, 6 rows affected (0.04 sec)
Records: 6 Duplicates: 0 Warnings: 0