Skip to content

Instantly share code, notes, and snippets.

View zakgrant's full-sized avatar
🎯
Focusing

Zak Grant zakgrant

🎯
Focusing
View GitHub Profile
@semipermeable
semipermeable / data_migration_and_test.rb
Created July 14, 2011 19:18
Rails3 Data Migration and RSpec Test
# db/migrate/20110714024435_split_author.rb
class SplitAuthor < ActiveRecord::Migration
def self.up
Post.where(:author=>nil).each do |p|
author = Author.create!(:name => p.author_name,
:account_id => p.account_id)
p.author = author
p.save!
end
end
@rodrigo-galba
rodrigo-galba / gist:4058942
Created November 12, 2012 11:52
Rest assured with cucumber step definitions
public class TransformationStepdefs {
private RequestSpecification spec = RestAssured.with();
@Given("^I have a single \"([^\"]*)\" file$")
public void I_have_a_single_file(String format) throws Throwable {
spec.given().
multiPart("requestData", objectAsJson()).
header("Version", 1);
}
@sstephenson
sstephenson / super.bash
Last active January 30, 2017 01:40
`super` in Bash
#!/usr/bin/env bash
source super.bash
foo() {
echo hello
}
super_function foo
foo() {
@Couto
Couto / raspberrypi_archlinux.md
Last active August 27, 2017 17:06
Raspberry Pi with ArchLinux
@shakyShane
shakyShane / example.js
Created October 24, 2014 14:12
Reloader plugin
var browserSync = require("browser-sync");
browserSync.use({
plugin: function () { /* noop */},
hooks: {
'client:js': require("fs").readFileSync("./reloader.js", "utf-8") // Link to your file
}
});
browserSync({
@brundage
brundage / database.yml
Created November 16, 2012 22:05
Use sqlite in-memory database for rspec testing
test:
adapter: sqlite3
encoding: utf8
pool: 5
timeout: 5000
database: ":memory:"
verbosity: quiet
@vlado
vlado / gist:1877457
Last active April 3, 2018 08:36
Postgres on macos or OSX - Fix
# ** ERROR 1 **
# FATAL: lock file "postmaster.pid" already exists
# HINT: Is another postmaster (PID 4646) running in data directory "/usr/local/var/postgres"?
#
# ** ERROR 2 **
# Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
#
# To fix one of this errors:
cat /usr/local/var/postgres/postmaster.pid # pid is the number on first line
@NickLaMuro
NickLaMuro / check_and_change_dns
Last active June 28, 2018 10:56
Dealing with Dynamic IP's with a home server and DNSimple
#!/bin/bash
EMAIL="your_email@example.com"
API_TOKEN="API_TOKEN"
DOMAIN_ID="your_domain.com"
RECORDS=(123456 234567 345678) # Replace with the Record ID
IP="`curl -s -S http://v4.ident.me`"
STORED_IP_ADDRESS_FILENAME="$HOME/.current_external_ip_address"
# Loop through each record id in the array
@mperham
mperham / after.rb
Created July 4, 2012 19:30
Thread-friendly shared connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@cobyism
cobyism / cask-finder.rb
Last active December 14, 2019 09:19
Search /Applications for apps that can be installed with `brew cask` (see http://caskroom.io)
#!/usr/bin/env ruby
exact_matches = {}
partial_matches = {}
no_matches = []
puts "Searching /Applications for things that exist in cask…"
Dir.glob('/Applications/*.app').each do |app|
app_name = File.basename(app)
search_term = File.basename(app, ".*").downcase.split(/\s/)[0]