Skip to content

Instantly share code, notes, and snippets.

defmodule SomeTest do
use ExUnit.Case
def some_function(%{arg1: "thing", arg3: _}) do
:two
end
def some_function(%{arg1: "thing", arg2: _}) do
:one
end
def some_function(_) do
@Ball
Ball / something.html
Created April 2, 2015 13:56
Deletion Prompt for Jon
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="application/javascript">
$(document).ready(function(e){
$("button.delete").click(function(){
var org_name = $(this).parents("tr")
.children("td:first-child").html();
alert(org_name);
});
@Ball
Ball / padding-names.clj
Created January 24, 2014 02:43
some prefixing logic for some files I'm downloading in a personal project.
(defn zero-pad [n number-string]
(->>
(concat (reverse number-string) (repeat \0))
(take n)
reverse
(apply str)))
(defn prefix [file-name]
(str "ns" (clojure.string/replace file-name #"^\d+" #(pad 3 %))))
@Ball
Ball / MainWindow.cs
Created August 16, 2013 13:39
Cross-Threading binding updates with WPF for RPH. I have no idea if this is best practice, but it seems to work.
namespace MyApplication {
public partial class MainWindow
{
private readonly ViewModel _vm;
private bool _close;
public MainWindow()
{
InitializeComponent();
@Ball
Ball / TypeDrivenBowlingKata.fs
Created November 21, 2012 13:55
Type Driven Bowling Kata
type Frame = StandardFrame of int * int
| SpareFrame of int * int
| StrikeFrame
type Game = Frame list
let score game =
let nextRoll frames =
match frames with
| [] -> 0
| StandardFrame(a,_)::_ -> a
@Ball
Ball / fizzbuzz.fs
Created November 20, 2012 19:53
FizzBuzz in types
type Fizzable = Plain of int
| Fizzy
| Buzzy
| FizzyBuzzy
let toFizzable n :Fizzable =
match n with
| _ when (n % 3) = 0 && n % 5 = 0 -> FizzyBuzzy
| _ when n % 3 = 0 -> Fizzy
| _ when 0 = n % 5 -> Buzzy
@Ball
Ball / stack_monad.fs
Created November 19, 2012 20:58
Learning Monads - Stack from the javascript example
// Adapted from http://igstan.ro/posts/2011-05-02-understanding-monads-with-javascript.html
type StackResult = {value: int; stack: int list}
let push element stack =
{value= element; stack = element :: stack}
let pop stack =
{value= (List.head stack); stack = (List.tail stack)}
let bind operation continuation stack =
let r = operation stack
@Ball
Ball / gist:3986836
Created October 31, 2012 12:40
Defer / disposable in ruby
def using(object, message, *args)
begin
yield if block_given?
ensure
object.send(message, *args)
end
obj = SomthingToClose.connect
@Ball
Ball / network_sockets.hs
Created October 5, 2011 14:00
A networked based socket server
-- Socket based network library
-- http://www.haskell.org/ghc/docs/6.10.4/html/libraries/network/Network-Socket.html
import Network.Socket
-- System io calls. Posix based
-- http://lambda.haskell.org/hp-tmp/docs/2011.2.0.0/ghc-doc/libraries/haskell2010-1.0.0.0/System-IO.html
import System.IO