Skip to content

Instantly share code, notes, and snippets.

View olistik's full-sized avatar

Maurizio De Magnis olistik

View GitHub Profile
@olistik
olistik / gist:11138762
Created April 21, 2014 10:29
Use Union queries with AREL
ForecastPayment.joins(:supplier).where('suppliers.supplierable_type = ?', 'PostalSupplier').joins('INNER JOIN postal_suppliers ON postal_suppliers.id = suppliers.supplierable_id')
class ForecastPayment
def self.postal_suppliers
joins(:supplier).
where('suppliers.supplierable_type = ?', 'PostalSupplier').
joins('INNER JOIN postal_suppliers ON suppliers.supplierable_id = postal_suppliers.id')
end
def self.generic_suppliers

Keybase proof

I hereby claim:

  • I am olistik on github.
  • I am olistik (https://keybase.io/olistik) on keybase.
  • I have a public key whose fingerprint is 7018 3370 51DF 3B8C A755 B950 FFC1 C3BA A255 6331

To claim this, I am signing this object:

@olistik
olistik / mytask.rake
Created February 18, 2014 10:33
Rails.logger is nil when invoking rake tasks [Ruby: 2.1.0p0, Rails: 4.0.2]
task :foo do
if Rails.logger.nil?
puts "WAT"
end
end
@olistik
olistik / license.txt
Last active August 29, 2015 13:56 — forked from xkraty/Superman Art
My BSD 2-Clause License
,,########################################,,
.*##############################################*
,*####*:::*########***::::::::**######:::*###########,
.*####: *#####*. :*###,.#######*,####*.
*####: *#####* .###########* ,####*
.*####: ,#######, ##########* :####*
*####. :#########*, ,,,,,,,,. ,####:
####* ,##############****************:,, .####*
:####*#####################################**, *####.
*#####Copyright (c) 2014, Maurizio De Magnis#*, :####:
@olistik
olistik / rails_middleware_diff
Created January 21, 2014 11:53
see the differences between the Rack stack used in your Rails environments
#!/bin/bash
diff -y --suppress-common-lines <(rake middleware | ruby -e "puts ARGF.read.gsub(/0x[a-z0-9]+/, 'OBJECT_ID')") <(RAILS_ENV=production rake middleware | ruby -e "puts ARGF.read.gsub(/0x[a-z0-9]+/, 'OBJECT_ID')")
@olistik
olistik / gist:8403246
Created January 13, 2014 16:30
REPL Driven Development
$ irb
> class Person
attr_accessor :name
end
> person = Person.new name: 'Alejandro'
> current_session.dump('world.session')
> exit
$ irb
> person.name # => NameError...
@olistik
olistik / gist:7784740
Created December 4, 2013 09:27
It looks like build metadata (as expressed in http://semver.org/spec/v2.0.0.html) are not supported by Rubygems (2.1.11)
ಠ_ಠ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.0]
ಠ_ಠ gem -v
2.1.11
ಠ_ಠ irb
2.0.0p353 :012 > Gem::Version.create '0.1.0'
=> #<Gem::Version "0.1.0">
2.0.0p353 :013 > Gem::Version.create '0.1.0-dev'
@olistik
olistik / gist:7583160
Last active December 28, 2015 23:59
Trying to handle Singleton in a more flexible way
=begin
PRO:
* Configuration is easily testable (you can reset the singleton before each test)
* Configuration keeps Singleton behavior outside of its responabilities
=end
class Configuration
def initialize(path: nil)
puts "#initialize"
@path = path
# rspec greeter_spec.rb
class Answer
def initialize(person)
@person = person
end
end
class RubyAnswer < Answer
def to_s
@olistik
olistik / gist:5028679
Last active December 14, 2015 04:29
GIT prompt
function set_git_ruby_prompt {
local branch
branch=$(git branch --no-color 2> /dev/null | grep '*' | cut -c 3-)
if [ "$branch" ]; then
BGP_GIT_ROOT_DIRECTORY=$(git rev-parse --show-toplevel)
project=`basename ${BGP_GIT_ROOT_DIRECTORY}`
# ruby_interpreter=`rvm info ruby | grep " version" | cut -c 19- | sed -e 's/"//g'`
# rvm_gemset=`rvm info environment | grep gemset | cut -c 19- | sed -e 's/"//g'`
git_info=`git status --porcelain | cut -c -2`