Skip to content

Instantly share code, notes, and snippets.

View troyk's full-sized avatar

Troy Kruthoff troyk

View GitHub Profile
@troyk
troyk / db.go
Created November 12, 2015 23:17
golang sql query abstraction
package db
import (
"database/sql"
"log"
"strings"
"sync"
_ "github.com/lib/pq" // required for database/sql
"golang.org/x/net/context"
@troyk
troyk / just_use_fkeys.sql
Created April 10, 2019 23:33
Polymorphic relationships with triggers in postgresql
-- saving here for later reference incase I decide to complicate things, decided to just use foreign keys
create table user_groups {
id bigint PRIMARY KEY default id_generator(),
account_id bigint not null references accounts(id) on delete cascade on update cascade,
updated_at timestamptz,
name citext not null
}
CREATE TYPE notification_level AS ENUM ('change', 'complete', 'digest', 'all');
@troyk
troyk / contacts.js
Created February 23, 2012 12:38
Mongoose multiple schemas in single collection
// Don't care much about inheritance at this point, but I'll probably attempt it at
// some point via cloning ancestor schema's
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var Contact = new Schema({
_type: String,
name: String
});
@troyk
troyk / jwt.go
Created April 7, 2016 04:21
golang jwt example
package cmd
import (
"encoding/json"
"flag"
"fmt"
"os"
"regexp"
"strings"
@troyk
troyk / pg_stat_statements
Created January 5, 2013 18:18
enable postgres pg_stat_statements
1) see re: increasing shmmax http://stackoverflow.com/a/10629164/1283020
2) add to postgresql.conf:
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
136 pg_stat_statements.max = 1000
137 pg_stat_statements.track = all
3) restart postgres
4) check it out in psql
@troyk
troyk / hubcode.zsh
Created February 10, 2021 18:53
zsh must haves
hubcode () {
local repo=$1
[[ ! $repo =~ "https://*" ]] && repo="https://github.com/${repo}"
local temp="$(mktemp -d)"
git clone --depth 1 "${repo}" "${temp}"
code --wait -n "${temp}"
rm -rf "${temp}"
}
@troyk
troyk / hnjobsfilter.js
Last active August 1, 2019 17:34
filter HN who's hiring to golang, elixir and ruby
var gojobs = 0, elixirjobs = 0, rubyjobs = 0;
document.querySelectorAll('.athing.comtr').forEach(function(el){
var text = el.innerText.toLowerCase();
var show = false;
if (text.indexOf('golang')>0 || text.indexOf(', go ')>0 || text.indexOf(' go,')>0) {
gojobs++; show=true;
}
if (text.indexOf('elixir')>0) {
elixirjobs++; show=true;
}
@troyk
troyk / rubypoop.rb
Created October 11, 2013 02:04
ruby rants
deliver {reset_code: user.password_reset_code_deliver!}
#SyntaxError (/Users/troy/Projects/church/app/controllers/api/users_controller.rb:126: syntax error, unexpected ':', expecting '}'
# deliver {reset_code: user.password_reset_code_deliver!}
# ^):
deliver({reset_code: user.password_reset_code_deliver!})
# umm, ok ruby so parens are optional when?
@troyk
troyk / desc.txt
Last active January 26, 2018 17:48
300 char entry for HR startup of the year
Next generation background screening technology disrupting the industry with mobile first candidate experience, automated compliance, single-sign-on integrations and fastest delivery (98% of reports, less than 27 hours)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>