Skip to content

Instantly share code, notes, and snippets.

@vothane
vothane / command.exs
Created October 11, 2015 20:55
replacing command pattern with functions in Elixir
defmodule CashRegister do
def new do
Agent.start_link(fn -> 0 end)
end
def add(pid, amount) do
Agent.update(pid, fn(register) -> register + amount end)
end
def reset(pid) do
@vothane
vothane / template.exs
Created October 11, 2015 20:52
replacing template pattern with functions in Elixir
ExUnit.start
defmodule Grader do
def grade(grade) do
cond do
grade <= 5.0 and grade > 4.0 -> "A"
grade <= 4.0 and grade > 3.0 -> "B"
grade <= 3.0 and grade > 2.0 -> "C"
grade <= 2.0 and grade > 0 -> "D"
grade == 0 -> "F"
@vothane
vothane / clojure9IDE.md
Last active January 26, 2022 13:33
How to install Leiningen and Clojure in Cloud9 IDE.

Should have a Leiningen Clojure project in workspace.

Go up one directory

cd ..

then go to bin directory since this is already in the $PATH

cd bin

@vothane
vothane / _test.rb
Created November 9, 2012 09:07 — forked from jcoglan/_test.rb
$VERBOSE = nil
require File.expand_path('../rooby', __FILE__)
Person = Rooby::Class.new 'Person' do
define :initialize do |name|
@name = name
end
define :name do
@vothane
vothane / YARIM.rb
Created March 7, 2012 01:11
YET ANOTHER RUBY IMPLEMENTATION for MEMOIZATION based on James Edward Gray II blog (blog.grayproductions.net/articles/caching_and_memoization), however turned to be more problematic than a solution.
require 'digest/sha2'
require 'base64'
class HashClod < Hash
def [](key)
r = super(key)
puts r
if r == nil
puts "set cache"
else