Skip to content

Instantly share code, notes, and snippets.

View bjarkevad's full-sized avatar

Bjarke Vad Andersen bjarkevad

View GitHub Profile
@bjarkevad
bjarkevad / National Geographic Picture-Of-The-Day Wallpaper Script
Last active December 24, 2015 20:29 — forked from JoshSchreuder/National Geographic Picture-Of-The-Day Wallpaper Script
Updated National Geographic Picture-Of-The-Day Wallpaper Script for Gnome 3.*
#!/bin/bash
# Copyright (c) 2011 Josh Schreuder
# http://www.postteenageliving.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@bjarkevad
bjarkevad / sqrt.scala
Last active December 25, 2015 12:59
Scala stuff
import scala.annotation.tailrec
import math.abs
//Fixed point algorithm
object fpalgorithm {
val tolerance = 0.0001
def fixedPoint(f: Double => Double)(firstGuess: Double) = {
def isCloseEnough(x: Double, y: Double) =
@bjarkevad
bjarkevad / classes.scala
Last active December 25, 2015 14:19
Rational number
class Rational(n: Int, d: Int) {
require(d != 0, "Denominator must be nonzero")
def this(n: Int) = this(n, 1)
private def gcd(a: Int, b: Int): Int =
if (b == 0) a else gcd(b, a % b)
private val g = gcd(n, d)
val numer = n / g
@bjarkevad
bjarkevad / List.scala
Last active December 25, 2015 14:39
Linked List
import java.util.NoSuchElementException
trait List[T] {
def isEmpty: Boolean
def head: T
def tail: List[T]
def length: Int
def atIndex(i: Int): T
def add(i: T): List[T]
}
@bjarkevad
bjarkevad / mergesort.scala
Created October 25, 2013 20:47
mergesort in scala
object mergesort {
def msort[T](xs: List[T])(implicit ord: Ordering[T]): List[T] = {
val n = xs.length / 2
if (n == 0) xs
else {
def merge(xs: List[T], ys: List[T]): List[T] = (xs, ys) match {
case (Nil, ys) => ys
case (xs, Nil) => xs
case (x :: xs1, y :: ys1) =>
if (ord.lt(x, y)) x :: merge(xs1, ys)
"Vundle
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'altercation/vim-colors-solarized'
Bundle 'Valloric/YouCompleteMe'
Bundle 'gerw/vim-latex-suite'
Bundle 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}
Bundle 'scrooloose/nerdtree'
@bjarkevad
bjarkevad / package.scala
Created December 3, 2013 17:00
continueWith
def continueWith[S](cont: Future[T] => S): Future[S] = {
val p: Promise[S] = Promise()
f.onComplete {
case Failure(f) => p.complete(Failure(f))
case Success(v) => p.completeWith(Future(cont(f)))
}
return p.future
%Datamatrix D:
D = [ -6.5 -6.5 -6.5 -6.5 -2.5 -2.5 -.75 -.75 3.25 3.25 4.5 4.5 6.5 6.5 6.5 6.5; ...
-2 -2 .5 .5 .5 .5 2 2 2 2 .5 .5 .5 .5 -2 -2; ...
-2.5 2.5 2.5 -2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 2.5 -2.5; ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;...
];
%Adjency matrix
A =[0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1;...

This is my recommended path for learning Haskell.

Something to keep in mind: don't sweat the stuff you don't understand immediately. Just keep moving.

Primary course

Getting started (do you have a compiler installed yet?)

Ubuntu users -> PPA

import Data.Binary.Put
import GHC.Word
data HeartBeat = HeartBeat {
typet :: Word8,
autopilot :: Word8,
basemode :: Word8,
custommode :: Word32,
systemstatus :: Word8,
version :: Word8