Skip to content

Instantly share code, notes, and snippets.

@ToJans
ToJans / ewmath.ex
Last active December 20, 2015 17:59
My functional coding blurb
defmodule EWMath.Guidance do
@moduledoc """
This is the general guidance document for the module EwMath
"""
defmodule :'Getting started' do
@moduledoc """
This is a guidance that will walk you through blahaba
"""
@ToJans
ToJans / example.ex
Last active December 21, 2015 07:08
An attempt for a more succint event handler in elixir
defmodule Listen.NewFSM do
use OtpDsl.Genfsm, register: {:local, :listen_fsm},
initial_state: :start,
init_params: []
@timeout 3*1000
defrecord CallInfo, from: "", to: "", suspicious_segments: 0
@ToJans
ToJans / meetup.exs
Created August 26, 2013 22:22
Freakenstein code
defmodule Meetup do
defmacrop dayname_parts, do: %W(mon tues wednes thurs fri satur sun)
defmacrop dayname(range_id, dayname_part) do
if (range_id == :teenth) do
dayname_part <> "teenth"
else
bin = atom_to_binary(range_id)
bin <> "_" <> dayname_part <> "day"
@ToJans
ToJans / cargo_tests.erl
Last active December 22, 2015 19:59
Porting the DDD app or not?
-module(cargo_tests).
-include_lib("eunit/include/eunit.hrl").
-compile([export_all]).
cargo_construction_test() ->
Cargo = start_a_cargo(),
?assertEqual(not_routed, cargo_delivery:routing_status(Cargo)),
?assertEqual(not_received, cargo_delivery:transport_status(Cargo)),
@ToJans
ToJans / 0.without_pipe.erl
Last active December 22, 2015 21:49
We REALLY need a pipe operator in Erlang
Cargo = start_a_cargo(),
Cargo_1 = cargo:specify_new_route(Cargo_1, a_route_specification()),
Cargo_99 = cargo:assign_to_route(Cargo_2, an_itenerary_that_does_not_match_the_route_specification())
?assertEqual(misrouted, cargo_delivery:routing_status(Cargo_99)),
stop_a_cargo(Cargo_99).
using System;
using System.Collections.Generic;
using System.Linq;
using AggregateSource;
namespace TheStuff
{
class Program
{
static void Main()
@ToJans
ToJans / blah.cs
Created September 26, 2013 12:08
New spike for property based testing
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Propern.Specs
{
[TestClass]
public class Math_operations
{
static Func<int> an_integer = Spec.Given(R => R.Next());
@ToJans
ToJans / gist:6755089
Created September 29, 2013 18:18
Just a test for @ptomasroos
Did you get the msg?
@ToJans
ToJans / histogram.exs
Last active May 8, 2019 11:51
To run, > elixir histogram.exs
defmodule Lab05 do
@doc """
My take on [the histogram exercise]
(http://computing.southern.edu/halterman/Courses/Fall2013/124/Labs/lab05_F13.html)
mentioned in [this newsgroup post]
(https://groups.google.com/d/msg/elixir-lang-talk/TTSjV0iy9yA/hpiGDZOk6DkJ)
"""
def main(), do: parse_pars(System.argv, nil)
defp parse_pars([],nil), do: histogram()
@ToJans
ToJans / no_if.erl
Last active December 25, 2015 17:09
What I love about Erlang: no "if" statements
%% @doc Register a new identity.
-spec register_identity(identifier()) -> succeeded().
%% @end
register_identity(Id) ->
F = fun () ->
Identity = get_identity(Id),
{_, true} = {already_registered, Identity =/= not_found},
identity_registered(Id)
end,
transact(F).