Skip to content

Instantly share code, notes, and snippets.

View jakcharlton's full-sized avatar

Jak Charlton jakcharlton

View GitHub Profile
@jakcharlton
jakcharlton / gist:7937470
Created December 12, 2013 23:29
eqJoin with missing key in RethinkDB
r.db("user1").table("others").filter(function(user) {
return user.hasFields('contact_id')
}).eqJoin("contact_id", r.db("user1").table("contacts"))
@jakcharlton
jakcharlton / gist:7937379
Created December 12, 2013 23:21
Left/Right field renaming in RethinkDB
:20] <jakcharlton> Is there a simple way of renaming that doesnt need to iterate data (inefficiently) ?
[10:20] <@neumino> You can chain your eqJoin/innerJoin/outerJoin with
[10:20] <@neumino> map( r.row.merge({ contact: r.row("left"), organisation: r.row("right") }).without("left", "right") )
[10:20] <@neumino> And that should do the trick
[10:20] <@neumino> There is not a sugar syntax for renaming field yet
class Product < ActiveRecord::Base
# our hstore column, make sure gem 'activerecord-postgres-hstore' is in your Gemfile
# and you've run: rails g hstore:setup
serialize :data, ActiveRecord::Coders::Hstore
# name is a string col
attr_accessible :data, :name
def self.search(query)
@jakcharlton
jakcharlton / gist:6401563
Created September 1, 2013 00:35
Mandrill
def perform(email_job_id, recipient_ids)
job = EmailJob.find(email_job_id)
recipients = Person.where("email IS NOT NULL and email <> ''").where(id: recipient_ids)
to = []
substitues = []
sub_fields = ["title", "first_name", "last_name", "email", "telephone_number", "website"]
recipients.each do |r|
recipient = {}
recipient["_rcpt"] = "[#{r.full_name}](mailto:#{r.email})"
Hi Jak,
Not a problem, you do raise some good points. First off, I would like to point out that uniqueness of credit cards is determined across your entire gateway account, since credit cards are not linked to specific merchant accounts in the gateway. Once stored, a credit card can be used on any merchant account in the gateway, but attempting to store that card again, if you’re doing duplicate card checking, wouldn’t be possible.
Regarding the use cases you’ve brought up, they do bring some of the inherent limitations of doing duplicate checking to light. If merchants are looking to ensure that duplicate cards are kept out of their vault, they’ll have to find some way to allow for joint credit cards. One way I can think to manage this would be to find a way to allow people to link their account to someone else’s account in your application, then give them access to the other user’s payment methods. Of course, there is potential for malicious users to take advantage of this, so you would have to be extreme
@jakcharlton
jakcharlton / backbone_view.js
Last active December 16, 2015 00:49
Assigning "this" for use inside a closure ... which reads/scans better
// using self - this seems the most obvious, esp coming from Rails
var self = this;
this.create({
myModel: {
email: $('#email').val()
}
},
{
wait: true,
@jakcharlton
jakcharlton / log.sh
Last active December 14, 2015 06:49
Pretty git log
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
[alias]
hist = log --pretty=format:\"%h | %ad | %s%Cred%d%Creset %Cgreen[%an]%Creset\" --graph --date=short
@jakcharlton
jakcharlton / deploy.rb
Created January 20, 2013 11:25
Basic cap script
require 'net/https'
require 'json'
set :stages, %w(production staging)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
default_run_options[:pty] = true
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
@jakcharlton
jakcharlton / launch_sublime_from_terminal.markdown
Created September 24, 2012 03:46 — forked from artero/launch_sublime_from_terminal.markdown
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation