Skip to content

Instantly share code, notes, and snippets.

@exviva
exviva / query_rates.rb
Created January 25, 2017 02:12
Shameless querying
rates = Rate.where(hotel_id: 1,
room_type: '1 bed',
check_in_date: Date.today)
@exviva
exviva / write_rate.rb
Created January 25, 2017 02:11
Shameless writing
# All index fields are required,
# the rest is the schemaless content
rate = Rate.put(hotel_id: 1,
room_type: '1 bed',
check_in_date: Date.today,
discount_type: 'geo',
net_price: 120.0) # potentially ~20 fields
rate[:hotel_id] # => 1
rate[:net_price] # => 120.0
@exviva
exviva / create_tables.rb
Created January 25, 2017 02:10
Shameless create tables
RateStore.create_tables!
@exviva
exviva / rate.rb
Created January 25, 2017 02:10
Shameless model
# app/models/rate.rb
class Rate
RateStore.attach(self)
index do
integer :hotel_id
string :room_type
string :check_in_date
@exviva
exviva / rate_store.rb
Created January 25, 2017 02:08
Shameless initializer
# config/initializers/rate_store.rb
RateStore = Shameless::Store.new(:rate_store) do |c|
c.partition_urls = [
ENV['RATE_STORE_DATABASE_URL_0'],
ENV['RATE_STORE_DATABASE_URL_1']
]
# total number of shards across all partitions
c.shards_count = 512
end
@exviva
exviva / Gemfile
Created January 25, 2017 02:07
Shameless Gemfile
gem ‘shameless’
@exviva
exviva / Shameless
Last active January 25, 2017 02:04
Shameless usage
Shameless usage
@exviva
exviva / gist:5696879
Created June 3, 2013 08:34
js.pusher.com
$ dig js.pusher.com
; <<>> DiG 9.9.2-P1 <<>> js.pusher.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63691
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
unless ENV.include?('CI')
ENV['DISPLAY'] = ':99'
pid = Process.spawn('Xvfb :99 -ac', out: '/dev/null', err: '/dev/null')
at_exit { Process.kill(:SIGINT, pid) }
end
<?php
class Admin_ContentTranslationsControllerTest extends Our_Test_ControllerTestCase
{
function testEditFindTranslationByIdTheOldWay()
{
$this->table->insert(array('key' => 'foo'));
$this->get('edit', array('id' => '1'));
$this->assertEquals(1, $this->assigns->translation->id);
}