Skip to content

Instantly share code, notes, and snippets.

View ggb's full-sized avatar

Gregor ggb

  • Kiel
View GitHub Profile
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 / 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 )
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),
@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 / 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 / .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
module Particle exposing (..)
import Array
import Task
import Html.App as App
import Window exposing (Size, resizes)
import Color exposing (Color, black, white, rgba)
import Element exposing (Element, toHtml)
import Collage exposing (Form, collage, move, rect, filled, circle)
import AnimationFrame exposing (times)