Skip to content

Instantly share code, notes, and snippets.

View universal's full-sized avatar

Johannes / universa1 universal

View GitHub Profile
@universal
universal / console.rb
Created April 17, 2015 09:39
ar / arel or
a = Simulation.where(user_id: 1, visibility: 0).where_values.reduce(:and)
a.to_sql
=> "\"simulations\".\"user_id\" = $1 AND \"simulations\".\"visibility\" = $2"
b = Simulation.where(visibility: 1).where_values.reduce(:and)
b.to_sql
=> "\"simulations\".\"visibility\" = $1"
Simulation.where(a.or(b)).to_sql
=> "SELECT \"simulations\".* FROM \"simulations\" WHERE (\"simulations\".\"user_id\" = AND \"simulations\".\"visibility\" = OR \"simulations\".\"visibility\" = )"
list = [128, 110, 60, 126]
list2 = [60, 110, 126]
res = list.each_with_index.each_with_object({}) {|(k,id), res| res[k] = id}
list 3 = list2.sort_by {|a| res[a]}
@universal
universal / error.rb
Last active August 29, 2015 14:19 — forked from valleybay/error.rb
Failures:
1) UserSessionsController#create with correct credentials with device_id and device_type set someone else is logged in with the same devic
e_id adds AddDeviceToken to the queue
Failure/Error: expect{
expected result to have changed by 1, but was changed by 0
# ./spec/controllers/user_sessions_controller_spec.rb:91:in `block (6 levels) in <top (required)>'
Finished in 1.45 seconds (files took 2.33 seconds to load)
13 examples, 1 failure
Schemas
An update_call of the item_classification
Processing ItemClassificationsController#update (for 127.0.0.1 at 2015-03-23 11:15:54) [PUT]
@universal
universal / sample.rb
Last active August 29, 2015 14:16 — forked from selvait90/sample.rb
params = {:id=>"5", :jurisdiction=>{:place_attributes=>{:name=>"Allen County15", :short_name=>"Allen County15", :id=>"5"}}}
@jurisdiction = PlaceEntity.jurisdictions.excluding_unassigned.find(params[:id])
@jurisdiction.place
@jurisdiction.update_attributes(params[:jurisdiction])
@jurisdiction.place.valid?
class AddIndexToLineItems < ActiveRecord::Migration
def change
add_index :line_items, [:user_id, :product_id], unique: true
end
end
@universal
universal / bin_rails
Last active August 29, 2015 14:15
spring / rvm / bundler / git gem issue
#!/usr/bin/env ruby
## modified, working version
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
@universal
universal / bm.rb
Created February 6, 2015 11:57 — forked from workmad3/bm.rb
require 'benchmark'
hsh = {}
1000.times {|i| hsh[i.to_s] = i.succ.to_s}
Benchmark.bm do |x|
x.report("Hash[]") {1000.times{Hash[hsh.values.zip(hsh.keys)]}}
x.report("invert") {1000.times{hsh.invert}}
x.report("each_with_object") {1000.times{hsh.each_with_object({}){|(k,v),h| h[v] = k}}}
end
curl -X POST -H "Content-Type: application/json" -d '[]' http://localhost:3000/manifest.json