Skip to content

Instantly share code, notes, and snippets.

View hayesr's full-sized avatar

Eric Hayes hayesr

View GitHub Profile
tracks_with_date = [
["6GZeeRql1kto2a7koIve9i", "2018-11-13 05:02:50 UTC"],
["6pXJV9kSdjyAcDsM32ftLK", "2018-11-13 05:02:50 UTC"],
["5x9jMerOQr7oTF1GO4STRY", "2018-11-13 05:02:50 UTC"],
["2hLTFcVb0k2xpHXZblhu7Y", "2018-11-13 05:02:50 UTC"],
["77L5jfCpmpkDma5lXjG6oX", "2018-11-13 05:02:50 UTC"],
["6rux2bYOCSr2woxnQsoUE3", "2018-11-13 05:02:50 UTC"],
["0gjknY5vRTKbzMos2hhfN7", "2018-11-13 05:02:50 UTC"],
["0ZHn1GiKfyLgpvEks2wBcn", "2018-11-13 05:02:50 UTC"],
["25EmPX0QaVUOzi2sG3fZEp", "2018-11-13 05:02:50 UTC"],
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@hayesr
hayesr / rails-jsonb-queries.rb
Last active December 13, 2018 15:12 — forked from mankind/rails-jsonb-queries
Rails-5 Postgres 9.6+ JSONB queries
# http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
# http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
# payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
# data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@hayesr
hayesr / mongoid version diff
Created June 23, 2012 18:21 — forked from beanieboi/mongoid version diff
shows the diff between two versions when you use Mongoid::Versioning
def compare_to(version)
reject_fields = ["_id", "updated_at", "version"]
diff_array = self.versions[version-1].attributes.to_hash.to_a - self.attributes.to_hash.to_a
diff_array.delete_if {|f| reject_fields.include?(f.first) }
Hash[diff_array]
end
// Provides a device_scale class on iOS devices for scaling user
// interface elements relative to the current zoom factor.
//
// http://37signals.com/svn/posts/2407-device-scale-user-interface-elements-in-ios-mobile-safari
// Copyright (c) 2010 37signals.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# Monitor HTTP requests being made from your machine with a one-liner..
# Replace "en1" below with your network interface's name (usually en0 or en1)
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
# OR.. to be able to use as "httpdump" from anywhere, drop this into ~/.bash_profile:
# (again replace "en1" with correct network interface name)
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*""
# All the above tested only on OS X.