Skip to content

Instantly share code, notes, and snippets.

View jcelliott's full-sized avatar

Joshua C Elliott jcelliott

View GitHub Profile
@jcelliott
jcelliott / railway.ex
Last active August 18, 2023 14:32
Small Elixir implementation of Railway Oriented Programming
defmodule Railway do
@moduledoc """
Railway implements the ideas from this blog post: https://zohaib.me/railway-programming-pattern-in-elixir/
It is essentially an implementation of the 'Either' monad constrained to the Elixir :ok/:error
result tuple convention. It can replace many straightforward uses of a 'with' statement.
Use it like this:
```
import Railway
value

Keybase proof

I hereby claim:

  • I am jcelliott on github.
  • I am jelliott (https://keybase.io/jelliott) on keybase.
  • I have a public key ASBLWJywrax6mgI8RZlPvHnBaJ97YJdvRAFOFq1tv0Fcogo

To claim this, I am signing this object:

@jcelliott
jcelliott / flatten.exs
Last active August 26, 2021 16:21
Recursively flatten a list in Elixir
defmodule Flatten do
@doc """
Flattens a list by recursively flattening the head and tail of the list
"""
def flatten([head | tail]), do: flatten(head) ++ flatten(tail)
def flatten([]), do: []
def flatten(element), do: [element]
end
@jcelliott
jcelliott / deps.info.ex
Last active August 19, 2024 14:36
Mix task to list information about all dependencies
defmodule Mix.Tasks.Deps.Info do
use Mix.Task
@moduledoc """
Prints information for every dependency from Hex
"""
def run(_args) do
Mix.Project.get!
Mix.Dep.loaded([env: :prod])
@jcelliott
jcelliott / duration_fmt.go
Created August 25, 2014 19:47
A small binary to print a duration in milliseconds in a human-friendly format
package main
import (
"fmt"
"os"
"strconv"
)
const (
MIN = 60
def authorized_for(user, op):
if user[1] == 'admin':
return True
else:
return False
def forbidden():
print('forbidden!')
def check_authorized(operation):
@jcelliott
jcelliott / proxy.go
Last active September 6, 2017 06:58
Reverse proxy using Go
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
@jcelliott
jcelliott / launch_requestbin.py
Created January 23, 2014 00:03 — forked from glenbot/launch_requestbin.py
Bootstrap file to run Requestbin locally
import os
from requestbin import app
from requestbin.storage.memory import MemoryStorage
app.config['bind_address'] = ('0.0.0.0', int(os.environ.get("PORT", 5000)))
app.config['ignore_headers'] = """
X-Varnish
X-Forwarded-For
X-Heroku-Dynos-In-Use
X-Request-Start
import argparse
import fileinput
def find_alliteration(line, smallest_seq):
# print("examining line: "+line)
seq = 1
words = line.split()
letter = words[0][0]
# print("looking for: "+letter)
for word in words[1:]:
package main
func work(id int, done chan int) {
println("processing top secret document:", id)
done <- id
}
func main() {
done := make(chan int, 5)
for i := 0; i < 5; i++ {