Skip to content

Instantly share code, notes, and snippets.

View robhurring's full-sized avatar
🍻
cheers

Rob Hurring robhurring

🍻
cheers
View GitHub Profile
# Search term parser from https://gist.github.com/1477730
# Modified to allow periods (and other non-letter chars) in unquoted field values
# and field names.
#
# Helper class to help parse out more advanced saerch terms
# from a form query
#
# Note: all hash keys are downcased, so ID:10 == {'id' => 10}
# you can also access all keys with methods e.g.: terms.id = terms['id'] = 10
# this doesn't work with query as thats reserved for the left-over pieces
@robhurring
robhurring / Rakefile
Created December 7, 2010 20:09
Delayed Job with Sinatra -- without sinatra specific gems, etc.
task :environment do
require './dj-sinatra'
end
namespace :jobs do
desc "Clear the delayed_job queue."
task :clear => :environment do
Delayed::Job.delete_all
end
@robhurring
robhurring / geolookup.js
Created October 8, 2014 21:40
Geolocation zip code lookup using google maps and angular. (Demo: http://jsfiddle.net/robhurring/kL50yeek/)
(function(angular) {
'use strict';
var app = angular.module('MyApp', []);
app.factory('GeolocationSvc', [
'$q', '$window',
function($q, $window) {
return function() {
var deferred = $q.defer();
@robhurring
robhurring / any.html.erb
Created March 24, 2009 15:19
object debugging with syntax highlight
<!-- using -->
<%= syntax_debug @object %>
@robhurring
robhurring / ghetto_thread_pooling.rb
Created November 22, 2010 20:24
Simple way to do multi-threaded chunking in Ruby : http://proccli.com/super-simple-thread-pooling-ruby
require 'thread'
# Stupid simple "multi-threading" - it doesn't use mutex or queues but
# it does have access to local variables, which is convenient. This will
# break a data set into equal slices and process them, but it is not
# perfect in that it will not start the next set until the first is
# completely processed -- so, if you have 1 slow item it loses benefit
# NOTE: this is not thread-safe!
class ThreadPool
def self.process!(data, size = 2, &block)
@robhurring
robhurring / bash_aliases.sh
Created November 22, 2010 19:48
Fun with OpenSSL encryption
# Put this somehwere in .bashrc/aliases/etc.
# OpenSSL must be installed -- these are just aliases.
alias enc='openssl enc -e -aes-256-cbc -salt '
alias dec='openssl enc -d -aes-256-cbc '
@robhurring
robhurring / README.md
Last active January 30, 2020 19:00
Override devise's TokenAuthenticatable strategy to use Authorization headers

This will allow you to use devise's TokenAuthenticatable strategy while passing your :auth_token in using HTTP Authorization headers instead of params.

You can check it out using

curl -H "Authorization: Token token=XXXXXX, option=1" -vv http://railsapp.dev/api/v1/endpoint.json

It should properly authenticate using the token as well as set request.env['token.options'] to {"options" => "1"}.

@robhurring
robhurring / shBrushRuby.js
Created July 17, 2009 01:04
GitHub style syntax highlighter theme
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/wiki/SyntaxHighlighter:Donate
*
* @version
* 2.0.320 (May 03 2009)
*
@robhurring
robhurring / fb-token-refresh
Created June 15, 2016 17:45
long lived facebook access token
#!/usr/bin/env sh
# Turn a short-lived access token into a long(er) lived access token.
# To use this you must first generate a short-lived access token using the
# graph API (https://developers.facebook.com/tools/explorer/)
#
# NOTE: make sure you select your app under the "Application" dropdown. if you
# don't you will see an error from this saying something about your app and
# not having permission/access
#
@robhurring
robhurring / app.rb
Created November 23, 2010 17:03
ActiveRecord query caching with Sinatra
# ActiveRecord refuses to enable query caching _unless_ you have the following setup
# 1) you _must_ use ActiveRecord::Base.configurations to store your auth details
# 2) you _must_ include the ActiveRecord::QueryCache middleware
# 3) you _must_ inherit from the _Base_ connection -- abstract models don't
# cache without a bit of hacking, it only query caches anything from AR::Base
require 'sinatra'
require 'active_record'
# query caching requires that you use AR::Base.configurations to store your