Skip to content

Instantly share code, notes, and snippets.

@rob-brown
rob-brown / RBSimpleSingleton.h
Created July 31, 2011 02:28
A singleton that can be safely subclassed to reduce code duplication.
//
// RBSimpleSingleton.h
//
// Copyright (c) 2011 Robert Brown
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@rob-brown
rob-brown / RBNetworkActivityIndicatorManager.h
Created July 31, 2011 05:51
A threadsafe network activity indicator manager.
//
// RBNetworkActivityIndicatorManager.h
//
// Copyright (c) 2011 Robert Brown
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@rob-brown
rob-brown / ExecuteSigil.ex
Last active April 11, 2023 08:18
An Elixir sigil for executing terminal commands similar to Ruby.
defmodule ExecuteSigil do
@doc """
Handles the sigil %x. Takes the given command line string, unescapes the necessary
characters and replaces interpolations, executes it, and returns the
results as a string.
## Examples
iex> %x"echo Hello \x45\x6c\x69\x78\x69\x72\x21"
@rob-brown
rob-brown / ElixirConf2014.md
Last active December 4, 2020 05:38
Notes from ElixirConf 2014

ElixirConf 2014

Dave Thomas—Opening Keynote

Twitter | Slides

Think different(ly)

Get out of your rut and learn new ways to think.

You can now send me #bitcoin here: https://onename.io/robert_brown
Verifying that +robert_brown is my Bitcoin username
@rob-brown
rob-brown / simulator.exs
Last active August 29, 2015 14:07
Simulator/App Finder
defmodule Simulator do
defstruct name: "", version: "", directory: ""
# Uses the home directory to find the devices directory.
case :init.get_argument(:home) do
{:ok, [[dir]]} ->
@simulator_dir :filename.join [dir, "Library", "Developer", "CoreSimulator", "Devices"]
_ ->
IO.puts "Unable to find the home directory."
@rob-brown
rob-brown / mastermind.ex
Last active August 15, 2022 08:43
A Mastermind game implemented in Elixir.
defmodule Mastermind do
defstruct rounds: 10, choices: 6, answer: nil, guesses: []
def start, do: game_loop %Mastermind{}
defp game_loop(game = %Mastermind{answer: nil}) do
game
|> start_computer_mastermind
|> game_loop
@rob-brown
rob-brown / life.ex
Last active August 29, 2015 14:09
Conway's Game of Life
defmodule Life do
# Defaults to B3/S23
defstruct cells: [[]], born: [3], stays: [2, 3], width: 10, height: 10, step: 0
def run(file) do
file |> read_file |> loop
end
def loop(life) do
@rob-brown
rob-brown / ObjectsFromFunctions.swift
Last active June 8, 2017 05:16
Use Church Encoding to create objects using only functions
//: Playground - noun: a place where people can play
import UIKit
// ----------------------------
// Create the "object".
// Basically it's a dispatch table.
typealias Person = (String) -> Any
var PersonInit: ((String, String) -> Person)!
@rob-brown
rob-brown / stage_inspector.ex
Last active August 18, 2016 07:06
Inspect the data passed between GenStages.
defmodule StageInspector do
alias Experimental.{GenStage}
use GenStage
def init(type) when type in [:consumer, :producer_consumer] do
{type, type}
end
def handle_events(events, _from, state = :consumer) do
Enum.each events, &inspect_event/1