Skip to content

Instantly share code, notes, and snippets.

View jakcharlton's full-sized avatar

Jak Charlton jakcharlton

View GitHub Profile
@jakcharlton
jakcharlton / contato_mailer.rb
Created June 5, 2018 04:20 — forked from andrerpbts/contato_mailer.rb
IMAP Mail Receive Ruby
#encoding: utf-8
class ContatoMailer < ActionMailer::Base
def receive(message)
p message
end
end
@jakcharlton
jakcharlton / SlowMongoQueries.md
Created September 11, 2016 23:50 — forked from rantav/README.md
Find slow queries in mongo DB

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 March 18, 2016 02:16 — forked from janko/01-activerecord.rb
PostgreSQL JSON querying in Sequel (my presentation from our local Ruby meetup)
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 August 29, 2015 14:05
Wufoo form embed code
<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 August 29, 2015 14:05
Get the LeadMachine ID from the query string
<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 September 18, 2015 21:07 — forked from davemo/README.md
Pre commit git hook to stop dumb checkins

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
// 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 December 23, 2013 01:45
RethinkDB query/update
r.table("foo").get("idValue").update( function(doc) { return r.branch( doc.eq(A), B, {} ) })
@jakcharlton
jakcharlton / join.js
Created December 23, 2013 00:46
RethinkDB join against nested ID
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 December 31, 2015 14:29
Rethink concepts

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