Skip to content

Instantly share code, notes, and snippets.

View kristjan's full-sized avatar

Kristján Pétursson kristjan

View GitHub Profile
79271
104677
107019
174413
201911
198794
209420
208774
62819
181205
# Data looks like:
# {
# #"old": new,
# "7583": 201343,
# "7614": 280397,
# "8381": 285146,
# "9197": 285727,
# "9356": 220591,
# }
$ ruby proctest.rb
1
proctest.rb:2:in `block in <main>': wrong number of arguments (2 for 1) (ArgumentError)
from proctest.rb:5:in `call'
from proctest.rb:5:in `<main>'
alert('hi!')
module RequireImplementation
def require_implementation(method_name)
define_method method_name do
raise NotImplementedError, "#{self.class.name} must implement #{method_name}"
end
end
end
class TestClass
@kristjan
kristjan / keybase.md
Created September 23, 2014 17:46
Keybase proof

Keybase proof

I hereby claim:

  • I am kristjan on github.
  • I am kristjan (https://keybase.io/kristjan) on keybase.
  • I have a public key whose fingerprint is 90B8 10A8 031E E111 893B 49B4 9455 B368 7480 A7AA

To claim this, I am signing this object:

@kristjan
kristjan / promises.md
Created October 15, 2014 03:06
Promises in Angular

Disclaimer: None of this code was actually run!

What's a Promise

A way to handle something that happens asynchronously. Instead of getting your result back, you get a promise back that you can handle in a success way and a failure way. At some point in the future, the promise resolves to one of those cases, passing your success/failure functions the applicable data.

Why use promises?

@kristjan
kristjan / all_colors
Last active August 29, 2015 14:21
DB color distribution
# All colors on all applications
$ for app in `heroku apps | tail -n +2`; do heroku config --app $app | cut -d':' -f1 | grep HEROKU_POSTGRESQL | cut -d_ -f3; done | sort | uniq -c | sort -rn
4 WHITE
3 CHARCOAL
2 YELLOW
2 ORANGE
2 ONYX
2 CRIMSON
2 COBALT
2 BRONZE
@kristjan
kristjan / rails_console.rb
Last active August 29, 2015 14:21
ActiveRecord log silencing example
$ rails c
Loading development environment (Rails 4.1.2)
[1] pry(main)> Specialist.find(15)
Specialist Load (0.9ms) SELECT "specialists".* FROM "specialists" WHERE "specialists"."id" = $1 LIMIT 1 [["id", 15]]
=> #<Specialist id: 15, ...>
[2] pry(main)> ActiveRecord::Base.logger.silence(Logger::FATAL) { Specialist.find(16) }
=> #<Specialist id: 16, ...>
@kristjan
kristjan / tags.rb
Created June 7, 2015 19:07
Demo bug using Array#product to build a hash
tags = %w[tag1 tag2 tag3]
h = tags.product([[]]).to_h
#=> {"tag1"=>[], "tag2"=>[], "tag3"=>[]}
h['tag1'] << 1
#=> [1]
h
#=> {"tag1"=>[1], "tag2"=>[1], "tag3"=>[1]}