Skip to content

Instantly share code, notes, and snippets.

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:

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)
def pending name, bt = caller
result = yield
ensure
puts "FIXED in #{bt.first}" if result
skip name
end
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
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 August 29, 2015 13:58
One approach to cache ActiveModelSerializer representations with ActiveRecord objects
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
$.each @items, (index, item) =>
listItem.click do (index) =>
=>
alert @items[index]
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
# 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
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