You are currently browsing the tag archive for the 'Ruby' tag.
When updating to 2.3.4 I noticed that touch is
no longer a simple ‘update :updated_at’, but a save!,
which caused some code to break
(e.g. touch`ing in after_save == loop)
Usage
User.first.touch_without_callbacks User.touch_without_callbacks([User.first.id, User.last.id])
Install
Paste somewhere…
# Provide .touch as it was in 2.3.2, simply update the :updated_at field.
class ActiveRecord::Base
def touch_without_callbacks
now = Time.now.utc
self.class.touch(id, now)
self.updated_at = now
end
def self.touch_without_callbacks(ids, time=Time.now.utc)
update_all({:updated_at=>time}, :id=>ids)
end
end
Also available as Gist
Ever wondered how much who adds/removes, its time to find out ![]()
(those are real stats, I just obfuscated the names
)
Results
Git scores (in LOC): mr-add : +482273 -9466 justu : +286250 -159905 grosser : +152384 -323344 another : +121257 -82116 naames : +104577 -13591 justfor : +68716 -72446 example : +7795 -4987 andeven : +5100 -1730 morenow : +4225 -2764 finish : +17 -19
Install
Copy init git_stats.rb and ruby git_stats.rb
(you can add the names of people who commit with different users into the ’same’ array)
# please add enhancements to http://gist.github.com/234560
#!/usr/bin/env ruby
t = Time.now
same = [['name-a','name-b'],['mr fred','fred']]
pipe = open("|git log --shortstat")
author = "unknown"
stats = {}
loop do
line = pipe.readline rescue break
author = $1 if line =~ /Author\: ([a-z]+) </
found = same.detect{|a| a.include?(author)}
author = found.first if found
if line =~ /files changed, (\d+) insertions\(\+\), (\d+) deletions/
stats[author] ||= Hash.new(0)
stats[author]['+']+=$1.to_i
stats[author]['-']+=$2.to_i
print '.'
end
end
puts "\nGit scores (in LOC):"
puts stats.sort_by{|a,d| -d['+'] }.map{|author, data| "#{author.ljust(20)}: +#{data['+'].to_s.ljust(10)} -#{data['-'].to_s.ljust(10)} " } * "\n"
A new version of the old pass/block hack, but this time they also work as expected on HashWithIndifferentAccess (params/session…)
When attr_protected or attr_accessible are just to complicated, a simple user.attributes = params[:user].pass(:name, :email) just works.
Or user.attributes = params[:user].block(:admin) for the opposite…
Again I read an article about background processing that generates many different jobs which all do the same: call method a on b with parameter z. At the moment we are using one GenericJob to handle all those cases.
It serializes ActiveRecord objects to a string representation, so that they do not get submittet as instance(often too large or deserialisation problems), if you do not need this feature, :send_later could be a good option for starting with generic jobs.
Usage
Install
Since my old Ubuntu lived a long live and saw numerous hacks, I chose to reinstall from scratch, here are the steps I took:
- install dotfiles
- Skype
- Multi-clipboard: sudo apt-get install glipper
- Application laucher: sudo apt-get install gnome-do + enable skype plugin
- Ruby enterprise
- Rubymine + Desktop icon+ Meta key for Rubymine
- Mysql: sudo apt-get install mysql-server mysql-client libmysql-ruby
- Apache: sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
- Passenger
- SSL for apache/passenger
- gem sources -a http://gems.github.com
- gems…
- Java: sudo apt-get install sun-java6-jre
- Git: sudo apt-get install git-core
No more hacks, everything works, very fast startup (~10s), faster graphics (for intel chips)

