Skip to content

Instantly share code, notes, and snippets.

View ggb's full-sized avatar

Gregor ggb

  • Kiel
View GitHub Profile
defmodule DataMuging do
def processLines [], result, _cols do
result
end
def processLines [head | tail], result, { fst, scd, thd } do
if Regex.match?(%r/^\s*\d+.?\s+/, head) do
s = String.split head
processLines tail, [ { Enum.at(s, fst),
defmodule SleepSort do
def sort(list_of_numbers) do
{:ok, sorted_list} = Agent.start(fn -> [] end)
Enum.map(list_of_numbers, fn number ->
Task.start(fn ->
:timer.sleep(number * 1)
Agent.update(sorted_list, fn l -> [ number | l ] end)
end)
@ggb
ggb / brainfuck.ex
Created November 29, 2014 15:27
Just another brainfuck interpreter...
defmodule Brainfuck do
@moduledoc """
Brainfuck, s. http://en.wikipedia.org/wiki/Brainfuck
"""
@register_size 100
# Function to find the next corresponding closing bracket
defp find_closing_bracket([ 91 | rest ], pos, closing) do
@ggb
ggb / .gitignore
Last active May 18, 2016 19:30
A simple (yet funny!) lunar lander simulator written in Elm. Inspiration: Functional Reactive Programming by Blackheath and Jones (Manning, example from the first chapter). Demo: http://examples.ideen-und-soehne.de/lunarlander/
elm-stuff/
*.html
*.js
@ggb
ggb / data.json
Last active August 29, 2015 14:22
Visualize cooccurrance and centrality with d3.js (inspired by M. Bostocks http://bl.ocks.org/mbostock/4062045). The example shows BetweennessCentrality on the first two paragraphs of Wikipedias "Computer Science"-article. The nodes are CCS (Computer Classification System) entities. Demo (with more data): http://examples.ideen-und-soehne.de/coocc…
{
"links": [
{
"source": 0,
"target": 10,
"value": 1
},
{
"source": 0,
"target": 12,
@ggb
ggb / searchTweets.ex
Last active August 29, 2015 14:23
Paging for Twitters search-end point. Uses: https://github.com/parroty
defmodule SearchTweets do
# number of tweets that are provided with one request
# the twitter api allows maximum 100
@chunk_size 100
defp fetch_next(term, options) do
try do
ExTwitter.search(term, options)
rescue
@ggb
ggb / Slides.elm
Last active October 2, 2015 21:49
Some simple slides using Elm
module Slides where
import Markdown
import Keyboard
import Html exposing (Html)
-- Data
type alias Slide = String
type alias SlideZipper = ( List Slide, List Slide )
@ggb
ggb / PortExample.elm
Last active May 17, 2016 11:23
A minimal example of the usage of ports (aka JS-interop) in Elm, featuring incoming and outgoing ports.
module PortsExample where
import Graphics.Element exposing (show)
type alias MyModel = ( Int, List Int )
initialModel : MyModel
initialModel = ( 0, [] )
@ggb
ggb / MyIntList.elm
Last active May 17, 2016 11:17
Elm list (integer list/generic list) implementation for presentation purposes
module MyIntList exposing (..)
type MyList = Nil | Cons Int MyList
(#) : Int -> MyList -> MyList
(#) ele list =
Cons ele list
@ggb
ggb / RegisterMachine.elm
Last active February 4, 2017 22:09
A Universal Register Machine implemented in Elm and inspired by http://www.thattommyhall.com/clojured/ Copy the following code to http://www.elm-lang.org/try and hit the compile-button.
module RegisterMachine exposing (..)
import Html
import Time exposing (Time, second)
import Array exposing (Array)
import Html exposing (..)
import Html.Attributes exposing (style)
type Msg