Skip to content

Instantly share code, notes, and snippets.

Avatar

Jak Charlton jakcharlton

View GitHub Profile
View contato_mailer.rb
#encoding: utf-8
class ContatoMailer < ActionMailer::Base
def receive(message)
p message
end
end
@jakcharlton
jakcharlton / README
Created Jun 20, 2011
Pros and Cos of TFS and Git
View README
TFS
Pros
• Familiar to current team
• Has a UI tool within Visual Studio
• Close tie in to Work Items
Cons
• Slow to pull, check in and branch
• Merge conflicts are frequent
• Encourages infrequent check in due to merge conflicts and slow performance
• Branching frequently leads to time consuming conflicts
@jakcharlton
jakcharlton / 01-activerecord.rb
Created Mar 18, 2016 — forked from janko/01-activerecord.rb
PostgreSQL JSON querying in Sequel (my presentation from our local Ruby meetup)
View 01-activerecord.rb
require "active_record"
ActiveRecord::Base.establish_connection('postgres:///testing')
ActiveRecord::Migration.verbose = false
ActiveRecord::Migration.class_eval do
create_table :played_quizzes, force: true do |t|
t.integer :player_ids, array: true
t.json :quiz_snapshot
end
@jakcharlton
jakcharlton / 1.9.3.md
Created Feb 18, 2012
Ruby 1.9.3 and Rails 3.2 on Heroku
View 1.9.3.md

http://railsapps.github.com/rails-heroku-tutorial.html

Ruby 1.9.3 and Rails 3.2 on Heroku Heroku’s newest stack, “Celadon Cedar,” supports Rails 3.2 but installs Ruby 1.9.2 by default. Ruby 1.9.3 is recommended for Rails 3.2.

You can configure the Heroku environment to use Ruby 1.9.3.

Note: Heroku makes it clear that Ruby 1.9.3 on Heroku is experimental, which means “no support, the ruby_version will change in the future, and this feature may change or be removed without warning.” In response to an inquiry on January 31, 2012, Heroku said, “there is no timeline yet” to fully support Ruby 1.9.3.

Install the heroku-labs plugin:

@jakcharlton
jakcharlton / SlowMongoQueries.md
Created Sep 11, 2016 — forked from rantav/README.md
Find slow queries in mongo DB
View SlowMongoQueries.md

A few show tricks to find slow queries in mongodb

Enable profiling

First, you have to enable profiling

> db.setProfilingLevel(1)

Now let it run for a while. It collects the slow queries ( > 100ms) into a capped collections, so queries go in and if it's full, old queries go out, so don't be surprised that it's a moving target...

View gist:8363967
// Retrieve all the documents where val == 1
// If no document is returned, insert {newVal: 2}
// Else update all the documents with {newVal: 2}
//
// Note: This query is not atomic
r.table("test").filter({val: 1}).count().do(function(numResults) {
return r.branch(
numResults.eq(0),
r.table("test").insert({newVal: 2}),
@jakcharlton
jakcharlton / queryupdate.js
Created Dec 23, 2013
RethinkDB query/update
View queryupdate.js
r.table("foo").get("idValue").update( function(doc) { return r.branch( doc.eq(A), B, {} ) })
@jakcharlton
jakcharlton / join.js
Created Dec 23, 2013
RethinkDB join against nested ID
View join.js
r.db('master').table("machines").eqJoin(function(machine) { return machine("machine_memberships")("user_id") }, r.db('master').table("users")).zip()
@jakcharlton
jakcharlton / gist:8000864
Last active Dec 31, 2015
Rethink concepts
View gist:8000864

A Datacentre is a group of Servers

Servers can be grouped in a Datacentre

A Server (Instance) is a single Rethink process

A Database is a logical grouping for Tables - Tables may sit on different Servers

A Shard is a partition of a Table

@jakcharlton
jakcharlton / gist:7937470
Created Dec 12, 2013
eqJoin with missing key in RethinkDB
View gist:7937470
r.db("user1").table("others").filter(function(user) {
return user.hasFields('contact_id')
}).eqJoin("contact_id", r.db("user1").table("contacts"))