Skip to content

Instantly share code, notes, and snippets.

View jonwolski's full-sized avatar

Jon Wolski jonwolski

View GitHub Profile
def server(form_response, test_response)
Proc.new {|env|
if env["REQUEST_METHOD"] == "POST"
[303, {"content-type" => "application/json", "location" => "http://localhost:8080/test" }, []]
elsif env["REQUEST_PATH"] == "/test"
[200, {"content-type" => "text/html"}, [test_response]]
else
[200, {"content-type" => "text/html"}, [form_response]]
end
}
@jonwolski
jonwolski / bash.sh
Last active April 17, 2020 17:01 — forked from antony/bash.sh
Auth0 SSR Compatible Integration with Sapper
npm install --save express express-openid-connect
@jonwolski
jonwolski / mut.hs
Last active October 29, 2018 21:49
simulating a C-style `for` loop in haskell
-- TODO: Use a Map instead of a hard-coded Env
-- TODO: Lexical scoping for the `for` loop variables: Use a separate, but
-- chained Map for the loop counter (`i`) and mutate `k` from the 'global'
-- env
-- TODO: move `for` to a module
-- TODO: find a cleaner syntax than lambda & record (`\env -> i env`)
import System.Environment (getArgs)
import Data.Maybe (listToMaybe)
@jonwolski
jonwolski / keybase.md
Created June 26, 2018 17:05
keybase.md

Keybase proof

I hereby claim:

  • I am jonwolski on github.
  • I am jonwolski (https://keybase.io/jonwolski) on keybase.
  • I have a public key ASCptrwRuYFbPFz906nlT9A1N-OW0mZHUfWR9rdKKIKIuAo

To claim this, I am signing this object:

@jonwolski
jonwolski / config.ru
Created October 5, 2016 16:18
Generate a 401 with JSON-API response
errors = '{ "errors": [{"detail": "no can haz" }]}'
run Proc.new {|env| [401, {"content-type" => "application/json"}, [errors]]}
@jonwolski
jonwolski / example.rb
Created September 29, 2016 21:30
holidays gem fun
require 'holidays'
easter_of_year = -> year {
Holidays.between(
Date.civil(year, 1, 1),
Date.civil(year+1, 1, 1),
:us, :informal)
.select {|h| h[:name] == "Easter Sunday"}
}
easter_of_year[2030] # [{:date=>#<Date: 2030-04-21 ((2462613j,0s,0n),+0s,2299161j)>, :name=>"Easter Sunday", :regions=>[:us]}]
@jonwolski
jonwolski / server.go
Created July 23, 2016 20:32
Comparing Rust (Iron) with Go cf. http://pastebin.com/qSzBFz91
package main
import (
"io"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello World!")
}
@jonwolski
jonwolski / how-to-set-up-stress-free-ssl-on-os-x.md
Created February 27, 2016 15:05 — forked from jed/how-to-set-up-stress-free-ssl-on-os-x.md
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@jonwolski
jonwolski / sum_alternating_harmonic_series.rb
Last active January 6, 2016 03:51
Sum alternating harmonic series
(2..100).reduce(0) {|acc, i| (i.even? ? -1.0 : 1.0)/i + acc }
{
"baz": 1,
"foo": {
"bar": [
"zero",
"one",
{
"a": 1,
"b": [
"red",