Skip to content

Instantly share code, notes, and snippets.

View NilsHaldenwang's full-sized avatar

Nils Haldenwang NilsHaldenwang

View GitHub Profile
#!/usr/bin/env ruby
# -*- encoding: UTF-8 -*-
changed_files = insertions = deletions = 0
cmd = nil
default_log_cmd = 'git log --since="00:00:01am" --stat -- .'
complete_log_cmd = 'git log --pretty=medium --stat -- .'
unless ARGV[0]
\chapter*{Erklärung}
\thispagestyle{empty}
Ich versichere, dass ich die eingereichte Bachelor-Arbeit selbstständig und ohne
unerlaubte Hilfe verfasst habe. Anderer als der von mir angegebenen Hilfsmittel und
Schriften habe ich mich nicht bedient. Alle wörtlich oder sinngemäß den Schriften
anderer Autoren entnommenen Stellen habe ich kenntlich gemacht.
\bigskip\bigskip
LectureInstanceParticipation::ROLES.keys.each do |role|
define_method(role.pluralize) do
participants_with_role(role.to_sym)
end
end
@NilsHaldenwang
NilsHaldenwang / cucumber backtrace
Created September 16, 2011 17:52
Problem with cucumber steps from factory girl
Lecture(#56834100) expected, got Lecture(#30902240) (ActiveRecord::AssociationTypeMismatch)
/home/nils/.rvm/gems/ruby-1.9.2-p290-patched@ba/gems/activerecord-3.1.0/lib/active_record/associations/association.rb:205:in `raise_on_type_mismatch'
/home/nils/.rvm/gems/ruby-1.9.2-p290-patched@ba/gems/activerecord-3.1.0/lib/active_record/associations/belongs_to_association.rb:6:in `replace'
/home/nils/.rvm/gems/ruby-1.9.2-p290-patched@ba/gems/activerecord-3.1.0/lib/active_record/associations/singular_association.rb:17:in `writer'
/home/nils/.rvm/gems/ruby-1.9.2-p290-patched@ba/gems/activerecord-3.1.0/lib/active_record/associations/builder/association.rb:49:in `block in define_writers'
/home/nils/.rvm/gems/ruby-1.9.2-p290-patched@ba/gems/factory_girl-2.1.0/lib/factory_girl/proxy/build.rb:21:in `set'
/home/nils/.rvm/gems/ruby-1.9.2-p290-patched@ba/gems/factory_girl-2.1.0/lib/factory_girl/factory.rb:112:in `block (2 levels) in run'
/home/nils/.rvm/gems/ruby-1.9.2-p290-patched@ba
Rehearsal -------------------------------------------
sort 12.040000 0.030000 12.070000 ( 12.116498)
sort_by 0.440000 0.000000 0.440000 ( 0.438764)
--------------------------------- total: 12.510000sec
user system total real
sort 10.020000 0.030000 10.050000 ( 10.054058)
sort_by 0.410000 0.000000 0.410000 ( 0.416572)
@NilsHaldenwang
NilsHaldenwang / todays_git_stats
Created September 3, 2011 15:11
This script outputs the sum of the git changes you made today.
#!/usr/bin/env ruby
changed_files = insertions = deletions = 0
lines = `git log --since="0am" --stat`
lines.each_line do |line|
if line =~ /(\d+) files changed, (\d+) insertions\(\+\), (\d+) deletions\(-\)/
changed_files += $1.to_i
insertions += $2.to_i
deletions += $3.to_i
m = Matrix.new([[1,2], [3,4]])
NameError: no constructor with arguments matching [class org.jruby.RubyArray] on object #<Java::OrgApacheCommonsMathLinear::Array2DRowRealMatrix:0x0>
from (irb):28:in `evaluate'
from org/jruby/RubyKernel.java:1088:in `eval'
from /home/nils/.rvm/rubies/jruby-1.6.1/lib/ruby/1.8/irb.rb:158:in `eval_input'
from /home/nils/.rvm/rubies/jruby-1.6.1/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /home/nils/.rvm/rubies/jruby-1.6.1/lib/ruby/1.8/irb.rb:270:in `signal_status'
from /home/nils/.rvm/rubies/jruby-1.6.1/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1418:in `loop'
@NilsHaldenwang
NilsHaldenwang / brute_force.rb
Created May 14, 2011 12:08
Genetic Algorithm vs. 0-1-KNAPSACK
# taken from http://rosettacode.org/wiki/Knapsack_problem/0-1#Brute_force
class Array
# do something for each element of the array's power set
def power_set
yield [] if block_given?
self.inject([[]]) do |ps, elem|
r = []
ps.each do |i|
r << i
new_subset = i + [elem]
class Test
def some_method
puts "hello world"
end
def some_other_method
puts "something else"
end
end
This is another gist-test.