Skip to content

Instantly share code, notes, and snippets.

@tasandberg
tasandberg / Gist.md
Last active May 27, 2021 21:40
ActiveRecord workaround for pg_search and tsvector columns
@tasandberg
tasandberg / README.md
Created April 23, 2021 18:43
Start rails using dynamic ngrok host name
  1. Get ngrok https://ngrok.com/download
  2. Start ngrok ngrok http 3000
  3. In a separate terminal, in your rails directory:
  • copy ngrok-host script above to bin/ directory (drop the .rb, its just there for gist syntax highlighting.
  • make the file executable: chmod +x bin/ngrok-host
  • run: bin/ngrok-host

The script queries the local ngrok instance for available tunnels, grabs the https host name, and starts rails with that hostname configured for url helpers and the like.

@tasandberg
tasandberg / guard_lite.rb
Created October 11, 2018 00:12
Guard Lite (rspec)
# Automatically run tests on file changes. Resolves rails app/ and lib/ files with their corresponding specs,
# following normal rspec directory conventions.
# To use:
# - download this file somewhere (like <app root>/bin/)
# - gem install filewatcher
# - run `bin/guard_lite`
#!/usr/bin/env ruby
require 'filewatcher'
@tasandberg
tasandberg / index.js
Created October 24, 2017 05:34
Remove duplicates from array of Mongo ObjectIDs
/**
* Given many arrays of ObjectIDs, return a unique list
*
* @params objectIDs {Array<ObjectID>}
* @returns
*/
module.exports = function dedupeIDs(objectIDs) {
const ids = {}
objectIDs.forEach(_id => (ids[_id.toString()] = _id))
return Object.values(ids)
@tasandberg
tasandberg / index.js
Last active January 14, 2018 18:02
combineReducers for Immutable.js and Redux
// combineReducers.js
function combineReducers(reducers) {
return function(state, action) {
return Object.entries(reducers).reduce((state, [subtree, reducer]) => {
return state.update(subtree, reducer(action))
}, state)
}
}
// reducers.js
@tasandberg
tasandberg / keybase.md
Created September 21, 2017 17:02
keybase.md

Keybase proof

I hereby claim:

  • I am timmehs on github.
  • I am timmehs (https://keybase.io/timmehs) on keybase.
  • I have a public key ASCx_zvT31T57WPJENDyE5R_qEyiGyfV-Nz30UOIFKoz5Qo

To claim this, I am signing this object:

@tasandberg
tasandberg / gist:ac6c49a4911a971a52f5729c95db8fa1
Created April 23, 2017 22:54
Ruby Firebase Cloud Messaging Post Request with HTTParty
include HTTParty
# The kicker here was I needed to turn the 'body' of the request into a JSON string,
# I had assumed HTTParty would JSONify any PORO passed in. WRONG!
opts = {
headers: {
'Authorization' => "key=#{ENV['FIREBASE_API_KEY'}",
'Content-Type' => 'application/json'
},
body: {