Skip to content

Instantly share code, notes, and snippets.

View paulsturgess's full-sized avatar

Paul Sturgess paulsturgess

View GitHub Profile
@paulsturgess
paulsturgess / remote_mysql.rb
Created February 2, 2012 16:55
Run a MySQL command on a remote server (via SSH) using Ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'mysql'
require 'net/ssh/gateway'
HOST = ''
SSH_USER = ''
SSH_PASS = ''
DB_HOST = "127.0.0.1"
DB_USER = ""
@paulsturgess
paulsturgess / Old rubies on OS X Mountain Lion.md
Created January 19, 2013 22:29
Install old rubies on OS X Mountain Lion
@paulsturgess
paulsturgess / Ruby read from file.md
Created February 27, 2013 19:34
Ruby read from file
$ cat somefile.txt | ruby version*.rb

Version 1:

input = $stdin.read
input.each_line do |line|
  ...
end

Version 2:

@paulsturgess
paulsturgess / reset_primary_key.md
Created February 27, 2013 19:49
Reset postgres primary key index using Rails
$ ActiveRecord::Base.connection.reset_pk_sequence!('table_name')

If you need the table names:

$ ActiveRecord::Base.connection.tables

=> ["accounts", "assets", ...]

@paulsturgess
paulsturgess / resque_retry.rb
Created February 27, 2013 19:55
Retry Resque jobs. Note this is sudo code, something like this should work...
index = 0
loop do
failure = Resque::Failure.all(index)
break if failure.nil?
if failure["queue"] == "queue_name"
Resque::Failure.requeue(index)
Resque::Failure.remove(index)
@paulsturgess
paulsturgess / password_regex.rb
Last active December 14, 2015 20:09
Password Regex Must include one number, one upper and lower case letter and be between 8 and 40 characters.
/^(?=.*\d)(?=.*?[a-z])(?=.*?[A-Z]).{8,40}$/
@paulsturgess
paulsturgess / capybara.md
Last active December 14, 2015 20:28
Useful capybara checks

Check a download

page.response_headers['Content-Type'].should == "text/csv"
page.response_headers['Content-Disposition'].should == "attachment; filename=\"some_file.csv\""

Check link href

find("a.some_link")["href"].should == "http://google.com"

Manually set the value of a field (even if it is a hidden field) with the following:

@paulsturgess
paulsturgess / sublime_text.js
Last active December 15, 2015 04:59 — forked from twosixcode/gist:1988097
Make smart paste the default in Sublime Text 2. Put this in: Preferences > Key Bindings - User
// swap the keybindings for paste and paste_and_indent
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" }
@paulsturgess
paulsturgess / app_controller.rb
Last active December 15, 2015 11:59
Idea for a standard approach to setting up the basics of a RubyMotion app
class AppController < UIViewController
def loadView
self.view = AppView.alloc.init
end
def viewDidLoad
super
view.viewDidLoad
end
@paulsturgess
paulsturgess / rubymotion bundler.md
Created April 6, 2013 12:36
Setup rvm and bundler for RubyMotion apps

Create rvmrc file:

$ rvm use 1.9.3@yourgemsetname --create --rvmrc

Add bundler to your Rakefile

$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require 'bundler'

Bundler.require