Skip to content

Instantly share code, notes, and snippets.

Avatar

Tadas Tamošauskas tadast

View GitHub Profile
@tadast
tadast / arsample.rb
Created Mar 20, 2014
ActiveRecord#sample for postgres
View arsample.rb
class ActiveRecord::Base
def self.sample
order('random()').first
end
end
@tadast
tadast / hash_wat.rb
Last active Aug 29, 2015
ruby **options inconsistency
View hash_wat.rb
def foo(a, *b, **c)
[a, b, c]
end
=> :foo
[16] » foo 10, {d: 40, e: 50}
=> [
[0] 10,
[1] [],
[2] {
@tadast
tadast / quotes_scrum_xp.md
Created May 27, 2014
Quotes from Scrum and XP from the Trenches by Henrik Kniberg
View quotes_scrum_xp.md

Scrum and XP from the Trenches by Henrik Kniberg

Disclaimer: exported by readmill in no particular order :(

If the product owner has a technical background he might add stories such as “Add indexes to the Events table”. Why does he wa nt this? The real underlying goal is probably something like “speed u p the search event form in the back office

The distinction is quite simple. Stories are deliver able stuff that the product owner cares about. Tasks are non-deliverable stuff, or stuff that the product owner doesn’t care about.

Normally the product owner starts the meeting by summarizing his goal for the sprint and the most important stories. Next , the team goes through and time-estimates each story, starting with the most important one. As they do this, they will come up with important scope questions – “does this ‘delete user’ story include going through each pending transaction for that user and canceling it?’” In some cases the answers will be surprising to the team, prompting them to change

@tadast
tadast / activesupport_offsets.rb
Created Jun 17, 2014
ActiveSupport::Timezone offsets
View activesupport_offsets.rb
{
"American Samoa" => -11,
"International Date Line West" => -11,
"Midway Island" => -11,
"Hawaii" => -10,
"Alaska" => -9,
"Pacific Time (US & Canada)" => -8,
"Tijuana" => -8,
"Arizona" => -7,
"Chihuahua" => -7,
View dispatcher.coffee
# As per https://github.com/alphasights/guides/pull/14
# Instead of
$ ->
if $('.js_money_index').length
# all your page-specific logic
# Use a [dispatcher](https://coderwall.com/p/mhvucw) with
# controllers/money_controller.js.coffee
View without_delayed_job.rb
def without_delayed_job &block
@old_behaviour = Delayed::Worker.delay_jobs
Delayed::Worker.delay_jobs = false
yield
Delayed::Worker.delay_jobs = @old_behaviour
end
### Usage
describe 'stuff' do
without_delayed_job do
View thanks_ruby.rb
[94] pry(main)> WHATEVER = {a: [{x: :boom1, z: :boom2}]}.freeze
=> {:a=>[{:x=>:boom1, :z=>:boom2}]}
[95] pry(main)> WHATEVER.clone[:a].first[:x] = :wtf
=> :wtf
[96] pry(main)> WHATEVER[:a].first[:x]
=> :wtf
@tadast
tadast / specialist-publisher-schema-to-rumager.rb
Created Apr 29, 2015
Helper script to convert govuk specialist-publisher schema to rumager document schema
View specialist-publisher-schema-to-rumager.rb
json = File.read("path/to/specialist-publisher/schema")
publisher_schema = JSON.parse(json)
fields = publisher_schema['facets'].map{|x| x['key']}
allowed_values = {}
publisher_schema['facets'].each do |facet|
allowed_values[facet['key']] = facet["allowed_values"]
end
@tadast
tadast / unused_yam_keys.rb
Last active Aug 29, 2015
Unused YAML keys
View unused_yam_keys.rb
def find_keys(hash)
hash.flat_map do |key, value|
if value.is_a?(Hash)
find_keys(value)
else
key
end
end
end
@tadast
tadast / public_pgp_key
Created Jun 1, 2015
My public PGP key
View public_pgp_key
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFVsoucBEACcPaABLP8Hm6b0R5wcZjsLsyTfrgGwC1mKsGSvoFa8Lu4d9moa
xsyWWO1NdIMMB7UNtlB1sbnFI0mkAiZoRVpk+hdYx9UvPup/exfbsKZWMG2srCvJ
cjL36X5jeGbu3X/78zAlPXlKhvJLf1i+8aMgQheO6He+D8Xu5G1QrCqYPaoEWgER
xQrUxu01S25ziwaf/7VvY3C35hKrQL7JG4N1mOL+QjxMRIzrVXe7mL7Igm7rT5Oz
tQtgfeMc4piTKQaztNbP+Yj+6LdoqeIzs3NWlFxfSqYw2qWrDIAqJlfpwMn/MWGN
r/8skOuCjBYPffDgngayAJrNhjeTlY5u++A41Cx84NhnMH93WpZd+Q7ga12QvRPc
U5/F2IBj/8eaSucKrgOL1KREo2JLS+8/Xp8lgJJNDzRkWhfMAqJnz7F8UwJs3DNW
XkLgKBxZobwztoxVWXgLhm78hwQ1vJLQbGlcFM9wbJzuLLRONniK0Rhx4Kuu0Zn2
You can’t perform that action at this time.