Skip to content

Instantly share code, notes, and snippets.

View stoft's full-sized avatar

Rasmus stoft

  • 06:02 (UTC +02:00)
View GitHub Profile
@stoft
stoft / recursivehtml2text.py
Last active January 3, 2016 16:39
Short python script to recursively process html files with mark2text.py (https://github.com/aaronsw/html2text) thus converting them to MD docs instead (e.g. a Tomboy notes extracted collection). Written for OSX, YMMV.
import os
import subprocess
import sys
import string
import re
for dir, subdir, files in os.walk( sys.argv[1] ):
for filename in files:
# ignore OSX fs file
if( filename != ".DS_Store"):
@stoft
stoft / logstash.conf
Created March 24, 2014 05:39
Logstash configuration for TCP input, JSON filter and ElasticSearch output
input {
tcp{
port => 5000
}
}
filter {
# Only process messages that have the keywords Audit or System.
if ([message] =~ "Audit|System" ) {
json {
@stoft
stoft / point_mutations_perf_text.exs
Last active August 29, 2015 14:10
Exercism exercise "point mutations" performance test.
if System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("example.exs")
else
Code.load_file("point_mutations.exs")
end
ExUnit.start
defmodule DNATest do
use ExUnit.Case, async: true
@stoft
stoft / orient_connector.ex
Last active December 10, 2015 15:48
Basic OrientDB HTTP/REST backend to Phoenix web framework
defmodule Phtest.OrientConnector do
use Jazz
@base_url "http://localhost:2480/"
@database "Phtest"
@user "admin"
@password "admin"
@basic_auth [basic_auth: {@user, @password}]
def get(document_id, type) do
OrientConnector.get_document(document_id)
@stoft
stoft / gist:ae1e1dce95d96f3a1772
Created June 20, 2015 12:02
bitstring/byte play
list = for i <- 1..4, do: <<255>>
my_int = :crypto.bytes_to_integer(:erlang.list_to_binary list)
iex> Enum.reduce(1..255, [], fn(x, acc) -> [x|acc] end) |> IO.iodata_to_binary |> byte_size
255
iex(7)> :crypto.bytes_to_integer(:erlang.list_to_binary list)
16777215
iex(96)> <<a::1, rest::bitstring>> = :erlang.integer_to_binary 0b00000001
@stoft
stoft / gist:43572de1f8b387e62721
Created July 13, 2015 21:06
Ecto touchpoints in Phoenix
# These are most of the Ecto touchpoints within Phoenix.
# I may have missed a few though.
# /
## mix.exs
:postgrex, :phoenix_ecto
# web/
## web.ex
* controller & channel
@stoft
stoft / assert_more.ex
Last active August 29, 2015 14:26
More assert functions
defmodule AssertMore do
@moduledoc """
More assert functions.
"""
import ExUnit.Assertions, only: [assert: 1, assert: 2]
@doc """
Asserts that two data structures are equal, except certain keys.
The data structures can be nested, such as maps with lists with maps.
@stoft
stoft / ElixirFizzBuzzGolf.ex
Last active November 15, 2015 08:41
Attempts at short FizzBuzz
for i<-1..100,r=&(rem(&1, &2)==0 && &3),x=(r.(i,15,"FizzBuzz")||r.(i,5,"Buzz")||r.(i,3,"Fizz")||i),do: IO.write "#{x} "
@stoft
stoft / ElmFizzBuzz.elm
Last active November 15, 2015 20:49
FizzBuzz in Elm
import Graphics.Element exposing (show)
main = show (iterate 100)
fizzbuzz : Int -> String
fizzbuzz n =
if | mod n 15 -> "FizzBuzz"
| mod n 5 -> "Buzz"
| mod n 3 -> "Fizz"
| otherwise -> toString n
@stoft
stoft / DiscoBoxen.elm
Last active November 30, 2015 22:10
Displays 10 boxes, one of them randomly switching off every cycle (200ms).
module DiscoBoxen where
import Array exposing (fromList, get)
import Color exposing (Color, black, white, green, red, blue, yellow, brown, purple, orange)
import Graphics.Element exposing (Element, spacer, color, flow, right, show)
import List exposing (foldr, (::))
import Random exposing (generate, initialSeed)
import Time exposing (every, millisecond, second)
drawSquare : Int -> Int -> Color -> Element