Skip to content

Instantly share code, notes, and snippets.

James Edward Gray II JEG2

View GitHub Profile
View tic_tac_toe.exs
defmodule TicTacToe do
def play do
move(" ", " ", " ", " ", " ", " ", " ", " ", " ", "X")
end
def draw_grid(a1, b1, c1, a2, b2, c2, a3, b3, c3) do
IO.puts "\n a b c "
IO.puts "1 #{a1} | #{b1} | #{c1} "
IO.puts " ---+---+---"
IO.puts "2 #{a2} | #{b2} | #{c2} "
View tic_tac_toe.exs
defmodule TicTacToe do
def play do
move(" ", " ", " ", " ", " ", " ", " ", " ", " ", "X")
end
def draw_grid(a1, b1, c1, a2, b2, c2, a3, b3, c3) do
IO.puts "\n a b c "
IO.puts "1 #{a1} | #{b1} | #{c1} "
IO.puts " ---+---+---"
IO.puts "2 #{a2} | #{b2} | #{c2} "
View sql_test.exs
defmodule SQLTest do
use ExUnit.Case, async: false
alias Replicator.{Config, Database, Connection, TestHelper}
defmodule Examples do
use Replicator.SQL
none(:prepare, "CREATE TABLE examples (id SERIAL, name TEXT)")
none(:insert, "INSERT INTO examples (name) VALUES ($name)")
@JEG2
JEG2 / Sync Work.scpt
Created Feb 4, 2018
My OmniFocus <-> Pivotal Tracker integration.
View Sync Work.scpt
tell application "OmniFocus"
tell default document
set work_project to first flattened project whose name is "Close PivotalTracker Stories"
set work_tasks to flattened tasks of work_project
set tasks_string to ""
repeat with the_task in work_tasks
set task_name to the name of the_task
if completed of the_task then
set task_status to "delivered"
else
View prime_server.exs
defmodule Fermat do
require Integer
def mpow(n, 1, _m), do: n
def mpow(n, k, m) when Integer.is_even(k) do
x = mpow(n, div(k, 2), m)
rem((x * x), m)
end
def mpow(n, k, m) when Integer.is_odd(k) do
x = mpow(n, k - 1, m)
View gunfight.exs
defmodule Gunfight do
defstruct shooters: %{ }, kills: ""
@result_limit :math.pow(10, 9) |> Kernel.+(9) |> round
def new, do: %__MODULE__{ }
def point(%__MODULE__{shooters: shooters} = gunfight, pointer, "0") do
%__MODULE__{gunfight | shooters: Map.delete(shooters, pointer)}
end
@JEG2
JEG2 / playbook.yml
Created Feb 1, 2017
Install Erlang and Elixir.
View playbook.yml
---
- hosts: builders
tasks:
- name: Fetch Erlang Solutions repository
get_url:
url: https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
dest: /tmp/erlang-solutions_1.0_all.deb
- name: Add Erlang Solutions repository
become: true
apt:
@JEG2
JEG2 / counter.rb
Created Jan 25, 2017
A wannabe GenServer.
View counter.rb
class Counter
def initialize(initial_count = 0)
@mailbox = Queue.new
@replies = Queue.new
@state = initial_count
@server = process_messages
end
def increment
mailbox.push([:handle_increment, 1])
@JEG2
JEG2 / runtime_types.exs
Created Oct 19, 2016
How to get typespec information from Elixir at runtime.
View runtime_types.exs
defmodule TypeSpecs do
def for_module(module) do
{:ok, {^module, [{:abstract_code, {:raw_abstract_v1, attributes}}]}} =
module |> :code.which |> :beam_lib.chunks([:abstract_code])
attributes
|> Enum.filter_map(fn
{:attribute, _, :spec, _function_and_types} -> true
_attribute -> false
end, fn {:attribute, _, :spec, function_and_types} ->
function_and_types
@JEG2
JEG2 / training.md
Created Aug 18, 2016
Please help me prepare my ElixirConf training.
View training.md

ElixirConf Training Sneak Peek

I've done a practice run of one fourth of my ElixirConf training. It was very helpful to me and I would like a little more practice.

I plan to run sessons for one half of my training next week. The sessions will be:

  • Tuesday at 7:00 PM Central Time: Process Basics
  • Wednesday at 7:00 PM Central Time: "Special Processes"

Each session is planned to last about an hour and a half.

You can’t perform that action at this time.