Skip to content

Instantly share code, notes, and snippets.

@stim371
stim371 / broken-500.php
Last active August 29, 2015 14:18
Different content types cause the message body to split
<?php
$url = 'http://api.app.dev:3000/messages';
$data = array(
'data' =>
json_encode(array(
'test' => 'hello & more details',
'fail' => 'asdf;sadfsfa='
))
);
@stim371
stim371 / gitto.bash
Created June 12, 2014 21:10
console function to tell you how many commits you need to roll back to get to a branch
function gitto() {
git diff $1 --name-status | grep -c "^[AM].*migrate"
COMPREPLY=($(git branch))
}
@stim371
stim371 / devise_oauth.rb
Last active December 22, 2015 13:39
adding error logging to the devise_oauth2_providable gem
require 'devise/strategies/base'
# in order to diagnose issues with the iphone app, we needed
# to monkeypatch the error code to put the error explanation in the logs
module Devise
module Strategies
class Oauth2GrantTypeStrategy < Authenticatable
# return custom error response in accordance with the oauth spec
# see http://tools.ietf.org/html/draft-ietf-oauth-v2-16#section-4.3
@stim371
stim371 / split_bm.rb
Last active December 17, 2015 08:29
benchmarking different options for splitting a string
require 'benchmark'
str = "1234 Ocean Drive #PH 2"
n = 50000
def split_arr(str)
str.split('#')[0]
end
def slice_index(str)
<p class='sub'>
Showing <%= size == 0 ? 0 : start + 1 %> to <%= (start + per_page) > size ? size : start + per_page %> of <b><%= size %></b> jobs
</p>
@stim371
stim371 / git prompt.bash
Created February 11, 2013 00:52
Not sure if this works.
#!/bin/bash
git_prompt ()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
@stim371
stim371 / datetime_update_trigger_1.sql
Last active December 11, 2015 16:39
two different pseudo-code examples to try to better explain what I was trying to achieve.
UPDATE c SET
CreateDate = CASE WHEN UPDATE ([CreateDateUTC]) THEN dbo.ConvertUTCTimeToPacific(i.CreateDateUTC)
ELSE CreateDate
END,
CreateDateUTC = CASE WHEN UPDATE ([CreateDate]) THEN dbo.ConvertPacificTimeToUTC(i.CreateDate)
ELSE CreateDateUTC
END
FROM dbo.Calls AS c
JOIN INSERTED AS i
ON i.CallId = c.CallId;
@stim371
stim371 / rails3_dep.md
Created November 30, 2012 22:23
fixing deprecations from Rails 2 to Rails 3

This is a catalog of the various deprecation notices that I worked through during my upgrade to Rails 3.

Rails Constants for env and root

###Details These constants have been phased out in favor of attributes on the Rails module

# Rails 2
if RAILS_ENV = 2.3
# OR
RAILS_ROOT
@stim371
stim371 / bbjs_model_test.coffee
Created October 4, 2012 20:57
example model test for question
describe 'Statement', ->
createStatement = (callback)->
domtest (window)->
Statement = window.require 'models/statement'
model = new Statement()
callback(model)
it 'can be initialized', (done)->
createStatement (model)->
@stim371
stim371 / gist:3382640
Created August 17, 2012 21:03
optify install
# command line
gem install optify
# with bundler
gem 'optify'