Skip to content

Instantly share code, notes, and snippets.

View TMaYaD's full-sized avatar

Subhash Chandra TMaYaD

View GitHub Profile
@TMaYaD
TMaYaD / gist:835223
Created February 19, 2011 17:57
nested attributes with validate parent
#app/models/parent.rb
class Parent < ActiveRecord::Base
accepts_nested_attributes_for :children
validate :children_are_less_than_two
private
def children_are_less_than_two
errors.add(:base,
"shouldn't have more than two children"
) if children.count > 2
I18n.extend Module.new {
def translate(*args)
print args.to_yaml
super
end
}
module Tester
def Tester.hello
print 'hello'
end
extend Module.new {
def world
print 'world'
end
}
@TMaYaD
TMaYaD / remove_merged_branches.sh
Created March 21, 2012 12:57
Remove merged branches
function rmb {
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ]; then
echo "WARNING: You are on branch $current_branch, NOT master."
fi
echo "Fetching merged branches..."
git remote prune origin
remote_branches=$(git branch -r --merged | grep -v '/master$' | grep -v "/$current_branch$")
local_branches=$(git branch --merged | grep -v 'master$' | grep -v "$current_branch$")
if [ -z "$remote_branches" ] && [ -z "$local_branches" ]; then
@TMaYaD
TMaYaD / prep_optware
Created April 18, 2012 18:17
prep_optware
#!/bin/sh
# Script for installing optware on DD-WRT
# Written by frater
#
export PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
SCRIPTVER="Fri Apr 22 17:08:38 CEST 2011"
export SITES='http://ipkg.nslu2-linux.org http://ftp-osl.osuosl.org/pub/nslu2'
export dom=wd.mirmana.com
@TMaYaD
TMaYaD / node.json
Created April 30, 2012 08:17
chef attributes for test role
{ "run_list": "role[data_provider]" }
101 def parse_and_update(file_name)$
102 Rails.logger.info "============================== Parsing: #{file_name} Begin =============================="$
103 piper, pipew = IO.pipe$
104 Thread.new do$
105 begin$
106 @remote_archive.get(file_name) do |chunk|$
107 puts chunk$
108 pipew << chunk$
109 end$
110 rescue Exception => e$
#!/bin/bash
# node.js using PPA (for statsd)
sudo apt-get install python-software-properties -y
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm -y
# Install git to get statsd
sudo apt-get install git -y
@TMaYaD
TMaYaD / base.rb
Created November 16, 2012 07:12
ActiveModel like interface for redis
# lib/redis_record/base.rb
module RedisRecord::Base
extend ActiveSupport::Concern
def save
run_callbacks :save do
success = REDIS.multi do
REDIS.mapped_hmset(key, attributes)
sorted_indices.each do |attr|
Fion.deleteItem = function (contentName) {
var asin = contentName.substring(11); // asin extracted from the argument
var itemData = itemCache.getDataByASIN(asin); // the item in the library list
// create vars to be sent in the ajax request to fiona-delete
var lendingId = '';
var lendingType = '';
var lendingStatus = '';
var loanId = '';
// assign the above vars where appropriate
if (itemData.loanId) {