Skip to content

Instantly share code, notes, and snippets.

View MSch's full-sized avatar

Martin Schürrer MSch

View GitHub Profile
@MSch
MSch / fix_model_name.rb
Created June 21, 2013 18:23
If you prefer to keep your models namespaced then ActiveModel::Naming really makes that harder for you than it would have to be.
module MyApp::ModelNameFix
def model_name
@_model_name ||= ActiveModel::Name.new(self, nil, self.name.sub(/^#{self.parent.name}::/, ''))
end
def namespaced_model_name
@_namespaced_model_name ||= ActiveModel::Name.new(self)
end
# Work with Draper
self.collectionView = ({
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds
collectionViewLayout:flowLayout];
collectionView.delegate = self;
collectionView.dataSource = self;
collectionView;
% brew --config :(
HOMEBREW_VERSION: 0.9.4
ORIGIN: https://github.com/mxcl/homebrew.git
HEAD: ba09af5da322ce5506be593629a20835702c5d26
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit arrandale
OS X: 10.8.4-x86_64
Xcode: 5.0 => /Applications/Xcode5-DP5.app/Contents/Developer
CLT: 5.0.0.0.1.1372877146
@MSch
MSch / azet.rb
Created September 27, 2013 14:38
$state = 0
def lol(x, y)
$state += 1
puts "Incrementing state it's now #{$state}"
[:bla, $state]
end
a, e = lol(:screw, :this) until e == 3
puts "a=#{a} e=#{e}"
@MSch
MSch / azet.rb
Created September 27, 2013 14:38
$state = 0
def lol(x, y)
$state += 1
puts "Incrementing state it's now #{$state}"
[:bla, $state]
end
a, e = lol(:screw, :this) until e == 3
puts "a=#{a} e=#{e}"
@MSch
MSch / thread.rb
Last active January 2, 2016 09:09
module ActiveRecord
class Connection
def connect
Thread.current.thread_variable_set(:connection_id, 123)
end
end
end
module Sequel
class Connection

Keybase proof

I hereby claim:

  • I am msch on github.
  • I am msch (https://keybase.io/msch) on keybase.
  • I have a public key whose fingerprint is 6A3B C7D2 D3B2 D5CE 4C46 F279 E851 70D1 DB52 D668

To claim this, I am signing this object:

defmodule Mix.TasksServer do
@moduledoc false
use GenServer.Behaviour
def start_link() do
:gen_server.start_link({ :local, __MODULE__ }, __MODULE__, :ok, [])
end
def clear_tasks() do
call :clear_tasks
@MSch
MSch / stem.ex
Last active August 29, 2015 14:02 — forked from avgerin0s/stem.ex
defmodule Stemmer do
def stem(word) do
IO.puts "stemming #{word}"
case Regex.run(~r/^(.+?)(ASD|QWE)$/u, word) do
[pattern_matching, like, "ASD"] -> IO.inspect like
[pattern_matching, like, "QWE"] -> IO.puts "whatever"
end
end
end
@MSch
MSch / dup_bench.exs
Last active August 29, 2015 14:04 — forked from alco/dup_bench.exs
Benchfella.start duration: 1.0#, format: :machine
defmodule StringDuplicateBench do
use Benchfella
@iterations [100, 1000, 10000, 100000]
Enum.each(@iterations, fn n ->
@str "1234567890"
@n n