Skip to content

Instantly share code, notes, and snippets.

View benpickles's full-sized avatar
🏎️

Ben Pickles benpickles

🏎️
View GitHub Profile
@benpickles
benpickles / action.js
Created March 18, 2016 16:19
Inject an Authorization header into a redux-api-middleware request with a Redux middleware.
import { CALL_API } from 'redux-api-middleware'
export function fetchLocations() {
return {
[CALL_API]: {
endpoint: 'http://api.somesite.com/api/locations',
method: 'GET',
// Don't have to manually add the Authorization header to every request.
headers: { 'Content-Type': 'application/json' },
types: ['REQUEST', 'SUCCESS', 'FAILURE']
@benpickles
benpickles / apiAuthInjector.js
Created March 17, 2016 21:28
Inject an Authorization header into a redux-api-middleware request with a Redux middleware.
import { CALL_API } from 'redux-api-middleware'
export default function({ getState }) {
return function(next) {
return function(action) {
const callApi = action[CALL_API]
if (callApi) {
const { authToken } = getState()
### Keybase proof
I hereby claim:
* I am benpickles on github.
* I am benpickles (https://keybase.io/benpickles) on keybase.
* I have a public key whose fingerprint is D3E2 C490 65FA 7406 95B1 8556 B014 2155 1D63 7BB7
To claim this, I am signing this object:
@benpickles
benpickles / .block
Last active November 20, 2016 16:57
Twitter Analytics-style line chart with Peity
height: 90
@benpickles
benpickles / .railsrc
Created March 31, 2015 14:54
My ~/.railsrc Rails defaults
--database=postgresql
--skip-bundle
--skip-javascript
--skip-keeps
--skip-spring
--skip-test-unit
@benpickles
benpickles / README.md
Last active November 9, 2016 14:52
Freight Train

A train runs along this (randomly generated) track.

@benpickles
benpickles / index.html
Last active November 20, 2016 16:23
Follow SVG <path>
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.path {
fill: transparent;
stroke: #ddd;
stroke-dasharray: 2 4;
stroke-width: 2;
}
@benpickles
benpickles / Makefile
Created April 2, 2014 14:19
Update `~/.vim/bundle`s with the power of make
BUNDLES = $(shell ls bundle)
BUNDLE_TARGETS = $(addprefix update_, $(BUNDLES))
list:
@for BUNDLE in $(BUNDLES); do echo $$BUNDLE; done
update: $(BUNDLE_TARGETS)
update_%:
cd bundle/$(*F) && git pull
@benpickles
benpickles / gsub_sub_bench.rb
Last active October 15, 2019 09:54
When you only want to substitute one thing use `sub` instead of `gsub`.
Rehearsal ----------------------------------------
gsub 0.013451 0.000356 0.013807 ( 0.013817)
sub 0.005154 0.000086 0.005240 ( 0.005302)
------------------------------- total: 0.019047sec
user system total real
gsub 0.011792 0.000351 0.012143 ( 0.012186)
sub 0.003583 0.000001 0.003584 ( 0.003583)
@benpickles
benpickles / dispatch.rb
Created June 19, 2013 12:09
I found this file in one of my very old Rails projects (public/dispatch.rb)
#!/usr/bin/env ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
require "dispatcher"
ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
Dispatcher.dispatch