Skip to content

Instantly share code, notes, and snippets.

View ElectricCoffee's full-sized avatar

Niko Lepka ElectricCoffee

View GitHub Profile

Keybase proof

I hereby claim:

  • I am electriccoffee on github.
  • I am electriccoffee (https://keybase.io/electriccoffee) on keybase.
  • I have a public key ASDbnWk4-Tm2Q_smSjp-SX48kAlYBVgtoshqMiTDFnOWPwo

To claim this, I am signing this object:

@ElectricCoffee
ElectricCoffee / utils.hs
Last active December 24, 2015 14:07
File I'll be dumping useful functions into when I come across them
module ECUtils where
-- applies a function f to a string
-- the string gets picked apart, modified, then stitched back together
mapWords :: (String -> String) -> String -> String
mapWords f = unwords . map f . words
-- port of Scala's function of the same name,
-- returns the default value 'e' if Nothing
getOrElse :: Maybe a -> a -> a
@ElectricCoffee
ElectricCoffee / .stumpwmrc.lisp
Last active August 29, 2015 14:19
My StumpWM RC file
;;;; stumpwm config file
(load "~/lib/stump-swank-setup.lisp")
(in-package :stumpwm)
(setq window-format "[%s] %t")
;; turn mode-line on for current head
(enable-mode-line (current-screen) (current-head) t
@ElectricCoffee
ElectricCoffee / land-of-lisp-sbcl-chapter-7.lisp
Created April 3, 2015 20:36
The code in Land of Lisp is designed with the CLISP interpreter in mind; this code will work with the SBCL interpreter
(defun dot->png (fname thunk)
(with-open-file
(*standard-output*
fname
:direction :output
:if-exists :supersede)
(funcall thunk))
(sb-ext:run-program "/opt/local/bin/dot" (list "-Tpng" "-O" fname)))
@ElectricCoffee
ElectricCoffee / lazy.lisp
Created April 3, 2015 19:29
Just some simple macros to conveniently define thunks, i.e. call-by-need expressions
(defmacro lazy (&body exprs)
`(lambda () ,@exprs))
(defmacro deflazy (name &body exprs)
`(defvar ,name (lazy ,@exprs)))
@ElectricCoffee
ElectricCoffee / guess-my-number.hs
Last active August 29, 2015 14:14
guess my number game using the StateT monad, even though State isn't technically necessary
import Control.Monad.State
type Bound = (Int, Int) -- left is the lower bound, right is the upper
-- starting values
initial :: Bound
initial = (1, 100)
-- decrement integer
dec :: Int -> Int
void DirectionOnKeypress(System.Func<KeyCode, bool> fn, KeyCode targetCode, Vector3 vector, float multiplier, float cap)
{
var directionalVelocity = Vector3.Dot(rigidbody.velocity, vector);
if (fn(targetCode) && directionalVelocity <= cap)
rigidbody.velocity += vector * multiplier;
}
@ElectricCoffee
ElectricCoffee / Pair.cs
Created January 21, 2015 23:20
make-shift Tuple class for .NET 3.5 which doesn't include it
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Utilities
{
static class Pair
{
public static Pair<T1, T2> Make<T1, T2>(T1 fst, T2 snd)
@ElectricCoffee
ElectricCoffee / list-example.c
Last active August 29, 2015 14:11
Macros for easy generic creation of lists in C
#include <stdlib.h>
#include <stdio.h>
#include "list.h"
DEFINE_LIST(int); /* defines the int_list type */
int main(void) {
int_list *lst = EMPTY;
PUSH(8, &lst, int_list);
PUSH(4, &lst, int_list);
@ElectricCoffee
ElectricCoffee / superliga-eksamen-nikolaj.c
Created December 5, 2014 12:06
my first semester final exam program in imperative programming
/* Navn: Nikolaj Lepka
Email: [email protected]
Gruppe: A425b
Studieretning: Datalogi */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DAYSIZE 4
#define TEAMSIZE 4