Skip to content

Instantly share code, notes, and snippets.

View ggb's full-sized avatar

Gregor ggb

  • Kiel
View GitHub Profile
@ggb
ggb / Types.elm
Last active October 5, 2016 10:00
import Html exposing (text)
type alias T = {name: String}
type alias R b = {b | name: String, age: Float}
type alias S a = {a | name: String}
type alias Q = {age: Float}
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)
@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
@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 / 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 / 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 / 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 / .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 / 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