Skip to content

Instantly share code, notes, and snippets.

View JEG2's full-sized avatar

James Edward Gray II JEG2

View GitHub Profile
@JEG2
JEG2 / training.md
Created August 18, 2016 01:29
Please help me prepare my ElixirConf training.

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.

@JEG2
JEG2 / ARandomNumberASecond.elm
Last active July 20, 2016 13:48
The full program for streaming a new random number each second.
module ARandomNumberASecond exposing (main)
import Html exposing (..)
import Html.App
import Time exposing (Time, second)
import Random
type alias Flags = {randSeed : Int}
@JEG2
JEG2 / pub_sub.exs
Created February 22, 2016 15:49
An example pub/sub server in Elixir.
defmodule PubSubServer do
def start(subscriber_callback \\ nil) do
spawn(__MODULE__, :run, [[ ], subscriber_callback])
end
def subscribe(server, handler) do
send(server, {:subscribe, self})
listen(handler)
end
@JEG2
JEG2 / concurrency.rb
Created January 22, 2016 16:33
Ruby's concurrency, an example.
require "open-uri"
require "json"
require "benchmark"
REPO_URL = "https://api.github.com/users/JEG2/repos"
def github_api(url)
open(url) { |response| JSON.parse(response.read) }
end
@JEG2
JEG2 / late_binding.rb
Created January 11, 2016 13:46
You can call methods higher than their definitions, as long as it's executed before said call.
>> class Magic
>> def initialize
>> self.var = 42
>> puts var
>> end
>> attr_accessor :var
>> end
=> nil
>> Magic.new
42
@JEG2
JEG2 / example.rb
Created May 29, 2015 19:37
A manual `gsub!()`?
>> s = "active_model/errors"
=> "active_model/errors"
>> i = 0
=> 0
>> while (md = s.match(/(?:_|(\/))([a-z\d]*)/i, i)); s[md.begin(0)...md.end(0)] = "#{md[1]}#{md[2].capitalize}"; i = md.end(0) - 1 end
=> nil
>> s
=> "activeModel/Errors"
@JEG2
JEG2 / retry.rb
Created February 24, 2015 17:37
Minitest stubbing is weird
require "minitest/autorun"
class Something
def dont_do_it
:oops
end
end
class RetryTest < Minitest::Test
def test_different_return_values
@JEG2
JEG2 / surprise.rb
Created February 19, 2015 15:28
Is this a bug in Ruby or just a poor method definition on my part?
class HashLike
def to_hash
{a: 1, b: 2}
end
end
def surprise(*args, keyword: nil)
p args
end
@JEG2
JEG2 / pathfinder.rs
Created August 29, 2014 14:47
Exploring capturing strings in a Rust task.
use std::collections::HashMap;
fn main() {
let mut services = HashMap::new();
services.insert("S1", vec!["A", "C"]);
for (name, stops) in services.iter() {
spawn( proc() {
println!("{}", name);
} );
@JEG2
JEG2 / iterators.rs
Created August 28, 2014 14:34
A type question abou Rust.
// The uncommented version of increment_all() works. What I'm trying to
// understand is why I can't handle the return type as shown in the commented
// out version, which does not compile.
// fn increment_all<I: Iterator<int>>(numbers: I) -> I /* or Iterator<int> */ {
fn increment_all<'r, I: Iterator<int>>(numbers: I) -> std::iter::Map<'r, int, int, I> {
numbers.map(|n| n + 1)
}
fn main() {