Skip to content

Instantly share code, notes, and snippets.

Richard Bishop rbishop

Block or report user

Report or block rbishop

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
rbishop / after.ex
Created Aug 18, 2015
Replacing imperative if/else with lazy, infinite Stream. I had to remove some of the specifics for security purposes but hopefully this shows the general idea.
View after.ex
def loop(model, models) do
task_sup = Process.whereis(:worker_supervisor)
fn -> {model, 0} end,
fn(_) -> :ok end
|> Stream.chunk(20)
|> -> Task.Supervisor.async(task_sup, Worker, :sanitize, [model, ids]) end)
rbishop / flatten.ex
Created Jun 5, 2015
TCO and append-less List.flatten
View flatten.ex
defmodule ListOp do
def flatten([head | tail]), do: flatten(tail, [head])
def flatten([], acc), do: Enum.reverse(acc)
def flatten([ [head | []] | tail], acc), do: flatten(tail, [head | acc])
def flatten([ [head | rest] | tail], acc), do: flatten(flatten([rest | tail], [head | acc]))
def flatten([head | tail], acc), do: flatten(tail, [head | acc])
rbishop /
Last active Jan 21, 2020
A super simple Elixir server for sending Server Sent Events to the browser.

Generate a new Elixir project using mix and add cowboy and plug as dependencies in mix.exs:

  defp deps do
      {:cowboy, "~> 1.0.0"},
      {:plug, "~> 0.8.1"}
rbishop / quicksort.ex
Created Sep 26, 2014
Quicksort in Elixir
View quicksort.ex
# Not tail recursive and uses ++ :(
defmodule Quicksort do
def sort([]), do: []
def sort([head | rest]) do
{before, after} = Enum.partition(rest, &(&1 < head))
sort(before) ++ [head] ++ sort(after)
rbishop / ecto.ex
Last active Aug 29, 2015
Based on an unknown list size, I want to create an inner join and where clause for each item in the list. I don't know how to dynamically change the binding in the where, though.
View ecto.ex
def by_path(ancestry) do
Enum.reduce(ancestry, App.Node, fn (ancestor, query) ->
|> join(:inner, [n], n1 in App.Node, == n.parent_id)
|> where([n], n.key == ^ancestor) # This is where I'm stuck, all the where's are n0."key", see line 14
# Here is the resulting SQL:
SELECT n0."id", n0."key", n0."project_id", n0."type", n0."parent_id"
rbishop / centinel.rb
Last active Aug 29, 2015
Cardinal Centinel Gateway Example
View centinel.rb
credit_card =, cc_info_hash)
gateway =
ProcessorId: '123',
MerchantId: '456',
TransactionPwd: 'p4ssw0rd'
lookup_response = gateway.authorize(amount, credit_card)
if lookup_response.enrolled?
rbishop / austin_beer
Last active Aug 29, 2015
Craft breweries and beers to order in Austin
View austin_beer
- Jester King
- Black Metal Farmhouse Imperial Stout
- Whatever Farmhouse and Wild Ales they have out
- Anything else you see from them, apparently
- Austin Beerworks
- Fire Eagle IPA
- Heavy Machinery Double IPA
- Peacemaker Pale Ale
- Blackthunder Schwarzbier
rbishop / private.rb
Created Jul 15, 2014
Inheritance and private vs protected
View private.rb
class Parent
def initialize(name)
@name = name
attr_accessor :name
rbishop / unique_pairs.ex
Last active Aug 29, 2015
Find all the unique pairs of numbers that add to 100 in a list
View unique_pairs.ex
defmodule UniquePairs do
def hundreds(numbers) do
|> combinations
|> is_hundred
|> sort_pairs
|> Enum.uniq
View rainforest.rb
require 'httparty'
fetch = -> (url) {
HTTParty.get(url, headers: { "Accept" => "application/json"})
response = fetch.("")
next_url = response["follow"]
You can’t perform that action at this time.