Skip to content

Instantly share code, notes, and snippets.

View ElectricCoffee's full-sized avatar

Niko Lepka ElectricCoffee

View GitHub Profile
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 / 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
@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 / 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 / .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 / 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

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 / lex.scala
Last active February 3, 2016 10:48
Primitive tokenizer in Scala
package eu.wausoft.lex
import java.lang.{String => JString} // renames the built-in string to JString to avoid token clashing
trait Token
case class String(value: JString) extends Token
case class Number(value: JString) extends Token
case class Atom(value: JString) extends Token
case class Keyword(value: JString) extends Token
case object Unknown extends Token
@ElectricCoffee
ElectricCoffee / CityNameGenerator.scala
Last active March 9, 2016 11:51
A simple idea for a city name generator I came up with based on Ben "Yahtzee" Croshaw's idea in The Consuming Shadow. The basic premise is that it takes common city prefixes and suffixes and mashes them together at random, causing generic sounding city names. The fun bit is when you start mixing cities from different countries together!
package eu.wausoft.city.gen
import scala.util.Random
import java.io._
/**
* Created by coffee on 3/8/16.
*/
object Generator {
val prefixes = Vector (
"Alt", "Alten", "Olden", "Groß", "Großen", "Hoh", "Hohen",
@ElectricCoffee
ElectricCoffee / touch-cpp.sh
Last active October 6, 2016 06:08
I had to make a bunch of C++ files, and couldn't be bothered to make all the cpp/hpp pairs, so instead I wrote a script that does it for me! It also makes sure not to overwrite any files that already exist
function touch-cpp {
for file in "$@"
do
cpp="$file.cpp"
hpp="$file.hpp"
# only actually attempt to write the files if they don't exist.
if [ -f $cpp -o -f $hpp ]
then
echo ">> Either $cpp or $hpp already exist, no action taken."