Skip to content

Instantly share code, notes, and snippets.

View jsimpson's full-sized avatar

Jonathan Simpson jsimpson

View GitHub Profile
@jsimpson
jsimpson / Gemfile
Created June 14, 2018 05:43 — forked from timothypage/Gemfile
Quick hack to passthrough sinatra to webpack-dev-server for awesome client hot reloading plus live api endpoints
source "https://rubygems.org"
gem "rack-proxy"
gem "sidekiq"
gem "sinatra"
gem "sinatra-contrib"
gem "py"
@jsimpson
jsimpson / event_sourcing_intro.rb
Created May 14, 2018 02:33 — forked from mottalrd/event_sourcing_intro.rb
An introduction to event sourcing, London Ruby User Group, 9th May 2018
module Commands
module Meeting
AcceptSchema = Dry::Validation.Schema do
required(:user_id).filled
required(:status).value(eql?: :scheduled)
end
class Accept < Command
def call
return validate if validate.failure?
#!/usr/bin/env ruby
## disconnect
# ./disconnect.rb -u yourusername [-o /your/path] [-p yourhttpproxyserver]
#
# This is a command-line utility for the bulk-downloading of run data from
# the connect.garmin.com web application, which has lackluster export
# capabilities.
#
# application.rb:

config.exceptions_app = lambda do |env|
  exception   = env['action_dispatch.exception']
  params      = env['action_dispatch.request.parameters']
  request     = Rack::Request.new(env)
  status_code = ActionDispatch::ExceptionWrapper.new(env, exception).status_code
  
 Rails.logger.info [
@jsimpson
jsimpson / problem.cpp
Created April 1, 2017 14:41 — forked from depp/problem.cpp
A Faster Solution
// Faster solution for:
// http://www.boyter.org/2017/03/golang-solution-faster-equivalent-java-solution/
// With threading.
// g++ -std=c++11 -Wall -Wextra -O3 -pthread
// On my computer (i5-6600K 3.50 GHz 4 cores), takes about ~160 ms after the CPU
// has warmed up, or ~80 ms if the CPU is cold (due to Turbo Boost).
// How it works: Start by generating a list of losing states -- states where the
// game can end in one turn. Generate a new list of states by running the game
@jsimpson
jsimpson / Xdefaults.jellybeans
Created March 22, 2017 23:03 — forked from pablox-cl/Xdefaults.jellybeans
Jellybeans color palette for rxvt and xfce4-terminal
# Adjust Rxvt to suit your terminal emulator
# Created with
# ITERM_COLOR_MULTIPLIER=2.5 ./itermcolors2Xdefaults.rb Jellybeans.itermcolors
# https://github.com/richo/jellybeans.vim/blob/c7ff7e9555881a5671fcc8753b381ba142b5ea82/Xdefaults/jellybeans.Xdefaults
Rxvt*color0: #393939
Rxvt*color1: #ca674a
Rxvt*color2: #96a967
Rxvt*color3: #d3a94a
Rxvt*color4: #5778c1
Rxvt*color5: #9c35ac

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would

@jsimpson
jsimpson / authentication_with_bcrypt_in_rails_4.md
Created November 18, 2016 02:07 — forked from thebucknerlife/authentication_with_bcrypt_in_rails_4.md
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@jsimpson
jsimpson / .rubocop.yml
Created November 16, 2016 23:41 — forked from jhass/.rubocop.yml
My preferred Rubocop config
AllCops:
RunRailsCops: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
@jsimpson
jsimpson / gist:0e78c489881b15000a9a38a591d01eba
Created June 21, 2016 18:33 — forked from mebens/gist:4218802
Simple glow/bloom GLSL shader for Love2D
// adapted from http://www.youtube.com/watch?v=qNM0k522R7o
extern vec2 size;
extern int samples = 5; // pixels per axis; higher = bigger glow, worse performance
extern float quality = 2.5; // lower = smaller glow, better quality
vec4 effect(vec4 colour, Image tex, vec2 tc, vec2 sc)
{
vec4 source = Texel(tex, tc);
vec4 sum = vec4(0);