Skip to content

Instantly share code, notes, and snippets.

View MonkeyIsNull's full-sized avatar

Adam Guyot MonkeyIsNull

View GitHub Profile
@MonkeyIsNull
MonkeyIsNull / war.factor
Created June 29, 2014 20:51
Simple Battle System
USING: kernel random math accessors sequences prettyprint io ;
USING: io.encodings.binary io.files serialize math.parser ;
IN: examples.war
TUPLE: player name hitpoints acc ;
! We're starting w/ Two sample players on the stack
! The rule is to always keep them there
"Urg" 20 70 player boa
"Conan" 25 65 player boa
! "Gwent" 18 95 player boa
@MonkeyIsNull
MonkeyIsNull / lispwar.clj
Last active August 29, 2015 14:04
Simple Battle System
;; Die Roll stuff
(defn die-roll [numSides]
(int (+ 1 (rand numSides))))
(defn d4 []
(die-roll 4))
(defn d6 []
(die-roll 6))
@MonkeyIsNull
MonkeyIsNull / war.exs
Last active August 29, 2015 14:10
War - Battle System
defmodule Die do
def init(), do: :random.seed(:erlang.now)
def d6(), do: :random.uniform(6)
def d100(), do: :random.uniform(100)
end
defmodule War do
def create_player(name, skill, hp) do
[ name: name, skill: skill, hp: hp ]
end
@MonkeyIsNull
MonkeyIsNull / Preso.exs
Created February 11, 2015 01:43
Presenter
defmodule Preso do
# shows what was passed in and then evals it and shoves the
# lhs back into the current context
defmacro show(stuff) do
{op, _, [{lhs,_, _}, rhs]} = stuff
IO.write "#{IO.ANSI.blue}#{IO.ANSI.bright}"
IO.write "#{lhs} #{op} "
IO.inspect rhs
IO.puts "#{IO.ANSI.reset}"
quote do
@MonkeyIsNull
MonkeyIsNull / gist:865814c4f92783025d9a
Last active August 29, 2015 14:17
Nginx redirect to local
server {
listen 80;
server_name www.demoit.io;
underscores_in_headers on;
listen 443 ssl;
client_max_body_size 500M;
ssl_certificate /etc/nginx/ssl/api_demoit_io.crt;
ssl_certificate_key /etc/nginx/ssl/api_demoit_io.key;
defmodule FileripperTest do
use ExUnit.Case, async: true
@test_files_path "fixtures/test"
setup_all do
File.mkdir_p(@test_files_path)
on_exit fn ->
IO.puts "At the very end"
defmodule FileripperTest do
use ExUnit.Case, async: true
@test_files_path "fixtures/test"
setup do
File.mkdir_p(@test_files_path)
on_exit fn ->
IO.puts "End of test case"
defmodule Taskrun do
def run(num) do
IO.puts "running sleep task: #{num}"
:timer.sleep(num)
num
end
def launch(num) do
Task.async(Taskrun, :run, [num])
@MonkeyIsNull
MonkeyIsNull / catstore.ex
Last active November 4, 2015 02:20
Catstore
defmodule Catstore do
def start() do
{:ok, store} = Agent.start(fn -> ["Biggles"] end)
store
end
def pr_cats(cats) do
Enum.each(cats, fn cat -> IO.puts cat end)
end
@MonkeyIsNull
MonkeyIsNull / catstore.ex
Created May 29, 2015 02:51
OTP CatStore
defmodule Catstore.Server do
use GenServer
## really simple API
def new_store(cats) do
{:ok, store} = GenServer.start_link(Catstore.Server, cats)
store
end
def add(store, cat) do