Skip to content

Instantly share code, notes, and snippets.

View danstn's full-sized avatar
🚀
Binding. Lifting. Zipping.

Daniel Stankevich danstn

🚀
Binding. Lifting. Zipping.
View GitHub Profile
@danstn
danstn / watch.hs
Last active August 29, 2015 14:27
Very simple Haskell watcher
#!/usr/bin/env runhaskell
{-# LANGUAGE OverloadedStrings #-}
import Turtle
main :: IO ()
main = do
stdout (runWatch $ findSrc)
@danstn
danstn / chjava
Last active August 29, 2015 14:23
chjava bash function
function chjava() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
@danstn
danstn / opt_type.scala
Last active August 29, 2015 14:20
My Opt type implementation
sealed trait Opt[+A] {
def flatMap[T](f: A => Opt[T]): Opt[T] =
fold[Opt[T]](Nothing)(f)
def map[T](f: A => T): Opt[T] =
fold[Opt[T]](Nothing)(a => Something(f(a)))
def fold[B](g: => B)(f: A => B): B =
this match {
case Something(a) => f(a)
# An equilibrium index of a sequence is an index into the sequence
# such that the sum of elements at lower indices is equal to the
# sum of elements at higher indices.
def eq_indices(arr)
left, right = 0, arr.inject(0, :+)
result = []
arr.each_with_index do |el, i|
right -= el
result << i if right == left