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 / 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...

@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 / wufoo-embed.js
Last active Aug 29, 2015
Wufoo form embed code
View wufoo-embed.js
<script type="text/javascript">var m7x3w7;(function(d, t) { var s = d.createElement(t), options = { 'userName':'username', 'formHash':'m7x3w7', 'autoResize':true, 'height':'234',
// NOTE: This is the line we are adding to the default snippet.
'defaultValues':'field13=' + lead_id,
'async':true,
'header':'show'};
s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'wufoo.com/scripts/embed/form.js';
s.onload = s.onreadystatechange = function() { var rs = this.readyState; if (rs) if (rs != 'complete') if (rs !=
@jakcharlton
jakcharlton / getParameterByName
Last active Aug 29, 2015
Get the LeadMachine ID from the query string
View getParameterByName
<script type="text/javascript">
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var lead_id = getParameterByName('lead_id');
</script>
@jakcharlton
jakcharlton / README.md
Last active Sep 18, 2015 — forked from davemo/README.md
Pre commit git hook to stop dumb checkins
View README.md

Git pre-commit Hooks

The pre-commit file listed here is setup to scan files for invalid keywords prior to commit to avoid debug or logging information making its way into production files.

Setup to scan .js, .coffee, .rb, .erb files for 'debugger' or 'binding.pry'

Installing the Hook

  • cp pre-commit .git/hooks/
  • chmod +x .git/hooks/pre-commit
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