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
#!/bin/env ruby | |
# Quick and dirty script to merge N small mp3 files in the current directory into files with duration ~30 minutes | |
# The power of Unix + the power of Ruby :) | |
# Question: how to reduce the number of used tools (mplayer, sox, and lame) ? | |
i = 1 | |
threshold = 60 * 30 |
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
$ cat in.txt | |
1000,1030 | |
1000,1040 | |
1040,1000 | |
3000,3010 | |
3010,3000 | |
# with ruby | |
cat in.txt | ruby -n -e 'BEGIN{@a = {}}; x,y = $_.chomp.split(","); if y && x && ! y.empty? then @a[x] = y; puts $_ ; end ; END{@a.keys.each{|k| puts k + "," + k}}' |
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
# export PS1="\u:\w$ " | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/' | |
# git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | |
} | |
# no highlight | |
# export PS1="\u:\w \$(parse_git_branch)$ " | |
# git branch in bold |
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
real_time1 = Benchmark.measure { # Written by consultants | |
# Perform a query for every zone getting companies in that zone, | |
# initialize all active records, merge results into one list, remove duplicates | |
@advertisers = @zones.map{ |z| z.companies.available }.flatten.uniq | |
}.real | |
real_time2 = Benchmark.measure { # Written by me | |
@_advertisers = Company.available.find(:all, :include => :zones, :conditions => ['zones.id in (?)', @zones]) | |
}.real |
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
def create | |
Order.transaction do | |
ArticlePurchase.transaction do | |
@order = create_order # can go wrong due to programmers' mistakes | |
@order.purchase # can go wrong due to programmers' mistakes | |
flash[:notice] = :order_successfully_created.l | |
end | |
end | |
redirect_to account_root_path | |
rescue # Intercepting ALL errors, so the user is |
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
elsif @advertiser=Company.find(params[:filter][:advertiser_id]) | |
@point_transactions = current_user.point_transactions_as_target.find_all_by_keyword("AD_REDEEMING") + | |
current_user.point_transactions_as_source.find_all_by_keyword("ARTICLE_PURCHASE") + | |
current_user.point_transactions_as_target.find_all_by_keyword("WHITE_TRANSACTION") + | |
current_user.point_transactions_as_source.find_all_by_keyword("WHITE_TRANSACTION") + | |
current_user.point_transactions_as_target.find_all_by_keyword("CARD_INFO") + | |
current_user.point_transactions_as_source.find_all_by_keyword("CARD_INFO") + | |
current_user.point_transactions_as_target.find_all_by_keyword("CARD_POSITIVE") + | |
current_user.point_transactions_as_source.find_all_by_keyword("CARD_POSITIVE") |
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
desc 'generate add_index declarations for all foreign key fields' | |
task :indexes => :environment do | |
files = nil | |
Dir.chdir(File.join(RAILS_ROOT, "app/models" )) do | |
files = Dir["*.rb"] | |
end | |
models = [] | |
files.each do |m| |
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 'rubygems' | |
require 'activesupport' | |
class Contract | |
attr_reader :start_date, :renew_date | |
def initialize(start_date, renew_date) | |
@start_date, @renew_date = start_date, renew_date | |
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
class HashWithIndifferentAccess | |
def get_to(*keys) | |
subhash = self | |
keys.each do |k| | |
subhash = subhash.try(:[], k) | |
return nil if subhash.nil? | |
end | |
if block_given? && subhash.any? | |
yield subhash | |
else |
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
function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all_records, | |
link_for_export, parameter_name_for_query_loading, parameter_name_for_focus, environment){ | |
this.checkIfJsFrameworkIsLoaded = function(){ | |
if (! jQuery){ | |
alert("jQuery not loaded, WiceGrid cannot proceed!") | |
} | |
} | |
this.checkIfJsFrameworkIsLoaded(); |
OlderNewer