Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthijs Langenberg mlangenberg

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am mlangenberg on github.
  • I am mlangenberg (https://keybase.io/mlangenberg) on keybase.
  • I have a public key ASBSM_mFEEKzuEStpCjGoji06WQKj-NDqz5OIZ40c21BDgo

To claim this, I am signing this object:

View json.rb
gem 'json', '1.8.1'
require 'json'
class FooBar
def as_json(options = nil)
{ foo: 'bar' }
end
end
puts JSON.generate(FooBar.new, quirks_mode: true)
View test_helper.rb
def pending name, bt = caller
result = yield
ensure
puts "FIXED in #{bt.first}" if result
skip name
end
View actual.json
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
View gist:9eebec165a0482e22de9
bundle exec irb
2.0.0-p451 :001 > require 'active_record'
=> true
2.0.0-p451 :002 > ActiveRecord::RecordNotFound
=> ActiveRecord::RecordNotFound
2.0.0-p451 :003 > ActiveRecord::RecordInvalid
NameError: uninitialized constant ActiveRecord::RecordInvalid
from (irb):3
from ~/.rvm/rubies/ruby-2.0.0-p451/bin/irb:12:in `<main>'
@mlangenberg
mlangenberg / ams_cache.rb
Last active Aug 29, 2015
One approach to cache ActiveModelSerializer representations with ActiveRecord objects
View ams_cache.rb
class User < ActiveRecord::Base; end;
class Post < ActiveRecord::Base; end;
class Comment < ActiveRecord::Base; end;
class AuthorSerializer < ActiveModel::Serializer
attributes :id, :name :created_at, :updated_at
end
class PostSerializer < ActiveModel::Serializer
attributes :id, :body :created_at, :updated_at
View gist:7474892
$.each @items, (index, item) =>
listItem.click do (index) =>
=>
alert @items[index]
View gist:6940231
SELECT `messages`.* FROM `messages`
INNER JOIN `message_recipients` ON `messages`.id = `message_recipients`.message_id
WHERE `message_recipients`.recipient_id = X
ORDER BY messages.created_at DESC LIMIT 10
View rack-ok.rb
# When doing Cross Origin request from Internet Explor 8 & 9
# the XDomainRequest object must be used. This object does not
# give access to the response status code and *discards* the
# responseText for responses with status code other than 2xx.
#
# This Rack Middleware wraps the original response body and
# status code in a JSON object and always returns a 200 OK.
class Rack::Ok
def initialize(app)
@app = app
View gist:4716459
sudo dd if=/dev/zero bs=2M | pv -s 200G | sudo dd of=/dev/sdb bs=2M
^C
0+1076858 records in
0+1076858 records out
141145931776 bytes (141 GB) copied, 5594.01 s, 25.2 MB/s