Skip to content

Instantly share code, notes, and snippets.

View troyk's full-sized avatar

Troy Kruthoff troyk

View GitHub Profile
@troyk
troyk / stringer.ex
Created February 5, 2015 10:39
This aint so bad is it??
defmodule Rocket.Stringer do
def sanitize_phone(ph) do
ph = Regex.replace(~r/[^0-9]/,ph,"")
case Regex.run(~r/\d{5,10}$/,ph) do
[phone] -> phone
_ -> nil
end
end
# Install dependencies
#
# * checkinstall: package the .deb
# * libpcre3, libpcre3-dev: required for HTTP rewrite module
# * zlib1g zlib1g-dbg zlib1g-dev: required for HTTP gzip module
apt-get install checkinstall libpcre3 libpcre3-dev zlib1g zlib1g-dbg zlib1g-dev && \
mkdir -p ~/sources/ && \
# Compile against OpenSSL to enable NPN
@troyk
troyk / awesome.sql
Last active August 29, 2015 14:09
Don't try this with MongoDB Folks
with v(dfrom, dto) as (
VALUES('2014-01-01'::date, '2014-11-12'::date)
--VALUES(_from, _to)
), failures as (
select user_id, 'data-entry'::citext as action, count(*) as "count" from ad_histories, v
where action='qc-fail' and created_at>=v.dfrom and created_at<=v.dto
and exists(select 1 from ad_histories subq where ad_id=subq.ad_id and subq.action='data-entry' limit 1) group by user_id
), elapsed as (
select r.user_id,r.action,avg(r.elapsed) as "avg_time" from (
select user_id,action, lead(created_at,1,now()) over w - created_at as elapsed
@troyk
troyk / gist:896c045094ec93c1578b
Created May 29, 2014 17:38
idea to avoid using pointers in go structs just for happy patching
type Repository struct {
Name string `json:"name"`
Description string `json:"description"`
Private bool `json:"private"`
}
// response to blog post https://willnorris.com/2014/05/go-rest-apis-and-pointers
type RepositoryPatch struct {
Repository
@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 / roberto_url_controller.rb
Created June 30, 2013 06:08
quick hack at a doman specific url shortner, decided to go a different route but going to gist it incase I want to come back to it
# A Roberto Url is a tiny url. It depends on the cross-language hashids lib http://www.hashids.org/
class RobertoUrlController < ApplicationController
layout false
# cursory glance at the code, this appears to be threadsafe
HASHER = ::Hashids.new("no offense rob, this is a tribute to your carb intake not your manhood") #change the salt and all urls are invalid!
PREFIX = "#{Rails.configuration.base_url}/l"
# note, extremely important that you do not change the keys of the object map as the
# hashing is tied to the sequence key: So add class maps to the end of the list!
# also, because classes can be models, use the string representation of the class
@troyk
troyk / showsValidation.js
Created June 30, 2013 06:02
Attempt to integrate bootstrap form messages with an angularjs directive. Need to move on, will revisit after clearing some fat from my plate!
// DAMN: THIS NO WORK because it watches the model, some how this also needs to tied
// into form submit for the cases where the model value was left blank
// for now, use this: ng-class || ng-show ="{ error: inviteForm.email.$invalid && inviteForm.email.$dirty }"
// Will toggle the css error class on the .control-group container and create/remove
// the error message. Also assumes data is not invalid in a pristine state
// depends on bootstrap form layout and jQuery; TODO: make work without jQuery
angular.module('blitUi', []).directive('showsValidation', function() {
return {
restrict: 'A',
link:function (scope, element, attrs) {
@troyk
troyk / gist:5384041
Created April 14, 2013 20:17
postgres array manipulation
select (select array(select a.e from unnest(matches) as a(e) where a.e != '%CHAN%')) from sms_keywords;
@troyk
troyk / rocknelephant.sql
Created March 7, 2013 13:19
PostgreSQL, don't leave home without it... MongoDB <giggles>, I guess all the smart kids would know to prejoin their data... MySQL <giggles>, at least it could do half of it...
COPY(
SELECT
p.id as "id",
p.payor_email as "email",
to_char(p.created_at,'YYYYMMDD') as "date",
pgroup.gross*0.01::money as "gross",
pgroup.refunded*0.01::money as "refunded",
f.name as "fund",
pgroup.fee*0.01::money as "fee",
(SELECT 'Paid') as "status",
@troyk
troyk / ablionfix
Created January 22, 2013 01:35
Fix apache bench for mt lion
# download and install pcre
# download and unpack (mine was 2.4.3) latest stable apache
cd httpd-2.4.3
export LTFLAGS='--tag CC'
# might have to symlink this file if you get a toolchain error
# sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain
./configure --silent --prefix=/usr/local/ --disable-debug --disable-dependency-tracking
cd support
make -s ab