Skip to content

Instantly share code, notes, and snippets.

View jakcharlton's full-sized avatar

Jak Charlton jakcharlton

View GitHub Profile
@jakcharlton
jakcharlton / Gemfile
Created March 13, 2012 07:51
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@jakcharlton
jakcharlton / _media-queries.scss
Created September 18, 2012 23:32 — forked from anthonyshort/_media-queries.scss
Media Queries in Sass
// Media Queries in Sass 3.2
//
// These mixins make media queries a breeze with Sass.
// The media queries from mobile up until desktop all
// trigger at different points along the way
//
// And important point to remember is that and width
// over the portrait width is considered to be part of the
// landscape width. This allows us to capture widths of devices
// that might not fit the dimensions exactly. This means the break
@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

#!/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
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)
// 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 / 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
@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 / 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 / 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