Skip to content

Instantly share code, notes, and snippets.

View stianeikeland's full-sized avatar

Stian Eikeland stianeikeland

View GitHub Profile
@ctford
ctford / isort.idr
Created July 2, 2014 18:47
A length-safe insertion sort.
insert : Ord a => a -> Vect n a -> Vect (1 + n) a
insert x [] = [x]
insert x (y::ys) with (x <= y)
| True = x::y::ys
| False = y::insert x ys
isort : Ord a => Vect n a -> Vect n a
isort [] = []
isort (x::xs) = insert x (isort xs)
#lang racket
(require (only-in racket
(+ old+)))
(define (dechurch n)
(n (λ (i) (old+ i 1)) 0))
(define (zero f x)
x)
@stianeikeland
stianeikeland / coffeetimer-msp430.c
Created March 20, 2011 15:06
MSP430 Coffeetimer
/*
* Coffetimer (safetytimer)
*
* Activated when button (pin 4) is grounded.
* Connected to a RF - remote control on pin 5 and 6
* via a couple of transistors, controling the
* coffemakers power outlet.
*
* */
@tormaroe
tormaroe / README.md
Created December 20, 2013 23:36
XMASLANG, a small programming language I created for my xmas calendar competition 2013.

To run this you need node and the PEG.js module installed.

To create the parser.js file, run:

pegjs grammar.peg parser.js

Now to compile the xmaslang source, run:

node parser.js program.xmas > programm.js
-++/|+(5)++(3)(1)(1)<x+(2)x>$->#(2)<x(1)>s(1)<i+si>+||#(5)<x->x<y+$xz(100)<k-zk>y>><x$xa(0)<b+ab>>|-$->#(10)<x#x>x(0)<y+x$yz(0)<y+yz>>$->->#(30)<x+x(1)><x%$->#(10)<a*a$=?->#<F?=F*(2)(4)<B*+FBB>[-(20)(15)](100000)>[|->#||(1)<x+(1)x><x+(1)x><x|(1)<x+(1)x>><r$rp(0)<q+pq>>]<i+(100)i><x>x(100)>A(0)<I+AI>>M(1)<b+Mb>x>C(0)<m+mC><x*(113)x>|||*|||(1)<x(1)><x+|(1)<x(1)>x><x*||(1)<x(1)><x+|(1)<x(1)>x>x>|||(1)<x(1)><x+|(1)<x(1)>x><x+||(1)<x(1)><x+||(1)<x(1)><x+|(1)<x(1)>x>x>x><x+|||(1)<x(1)><x+|(1)<x(1)>x><x+||(1)<x(1)><x+||(1)<x(1)><x+|(1)<x(1)>x>x>x>x><x+|*|||(1)<x(1)><x+|(1)<x(1)>x><x*||(1)<x(1)><x+|(1)<x(1)>x>x>|||(1)<x(1)><x+|(1)<x(1)>x><x+||(1)<x(1)><x+||(1)<x(1)><x+|(1)<x(1)>x>x>x><x+|||(1)<x(1)><x+|(1)<x(1)>x><x+||(1)<x(1)><x+||(1)<x(1)><x+|(1)<x(1)>x>x>x>x>x><x+||*|||(1)<x(1)><x+|(1)<x(1)>x><x*||(1)<x(1)><x+|(1)<x(1)>x>x>|||(1)<x(1)><x+|(1)<x(1)>x><x+||(1)<x(1)><x+||(1)<x(1)><x+|(1)<x(1)>x>x>x><x+|||(1)<x(1)><x+|(1)<x(1)>x><x+||(1)<x(1)><x+||(1)<x(1)><x+|(1)<x(1)>x>x>x>x><x+|*|||(1)<x(1)><x+|(1)<x(1)>x><x*||(1)<
@ctford
ctford / lenses.clj
Created July 12, 2014 20:40
A Clojure lens implementation based on focus and fmap.
(ns shades.lenses)
; We only need three fns that know the structure of a lens.
(defn lens [focus fmap] {:focus focus :fmap fmap})
(defn view [x {:keys [focus]}] (focus x))
(defn update [x {:keys [fmap]} f] (fmap f x))
; The identity lens.
(defn fapply [f x] (f x))
(def id (lens identity fapply))

These instructions work for the Raspberry Pi running Raspbian (hard float) and create a hardware optimized version of NodeJS for the Raspberry PI, (and include a working install and NPM!!!):

  1. Install Raspbian - http://www.raspberrypi.org/downloads

  2. Install the necessary dependecies:

sudo apt-get install git-core build-essential

(If you just installed git then you need to administer your git identity first, else adding the patches below will fail!!!)

# MAC manipulators
alias random_mac='sudo ifconfig en0 ether `openssl rand -hex 6 | sed "s/\(..\)/\1:/g; s/.$//"`'
alias restore_mac='sudo ifconfig en0 ether YOUR_ORIGINAL_MAC_ADDRESS_GOES_HERE'
@avafloww
avafloww / PhpJava.java
Last active October 16, 2022 18:50
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
@AvnerCohen
AvnerCohen / npm-cheat-sheet.md
Last active July 9, 2023 09:14
Node.js - npm Cheat Sheet

Node.js - npm Cheat Sheet

(Full description and list of commands at - https://npmjs.org/doc/index.html)

List of less common (however useful) NPM commands

Prepand ./bin to your $PATH

Make sure to export your local $PATH and prepand relative ./node_modules/.bin/: