Skip to content

Instantly share code, notes, and snippets.

View octopuscabbage's full-sized avatar
🔱

Chris Denniston octopuscabbage

🔱
  • University of Southern California
  • Los Angeles
  • 19:33 (UTC -07:00)
View GitHub Profile
Configuring copilot-core-2.1.2...
Building copilot-core-2.1.2...
Preprocessing library copilot-core-2.1.2...
[ 1 of 23] Compiling Copilot.Core.Type.Equality ( src/Copilot/Core/Type/Equality.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Copilot/Core/Type/Equality.o )
[ 2 of 23] Compiling Copilot.Core.Random.Weights ( src/Copilot/Core/Random/Weights.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Copilot/Core/Random/Weights.o )
[ 3 of 23] Compiling Copilot.Core.Type.Dynamic ( src/Copilot/Core/Type/Dynamic.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Copilot/Core/Type/Dynamic.o )
[ 4 of 23] Compiling Copilot.Core.Type ( src/Copilot/Core/Type.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Copilot/Core/Type.o )
[ 5 of 23] Compiling Copilot.Core.Type.Uninitialized ( src/Copilot/Core/Type/Uninitialized.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/Copilot/Core/Type/Uninitialized.o )
[ 6 of 23] Compiling Copilot.Core.Type.Show ( src/Copilo
f:: Maybe a -> Maybe b
f (Just a) = Just a
g:: Maybe a → Maybe b
g (Just a) = Just a
c = f . g
@octopuscabbage
octopuscabbage / test.js
Created August 2, 2015 00:50
Heterogenous reduce sum.
function heterogenous_sum_fold(prev, cur, I, a){
if( Object.prototype.toString.call( someVar ) === '[object Array]') { //if it's an array
return prev +cur.reduce(heterogeneous_sum_fold);
//apply this function recursively.
}
return prev + cur; // probably everything else. Might error.
}
Array.reduce(heterogeneous_sum_fold); //how to invoke
import Text.ParserCombinators.Parsec
main = (getLine >>= \line -> putStrLn . either show show $ ((parse (many digit >>= \d1 -> oneOf ['+','-','/','*'] >>= \f -> many digit >>= \d2 -> return (read d1, (if (f == '+') then (+) else if (f=='-') then (-) else if (f == '*') then (*) else if (f == '/') then (/) else undefined), read d2)) "golf parser"line) >>= \(d1,f,d2)->return (f d1 d2)))
@octopuscabbage
octopuscabbage / gist:a5d0296143c0010b54e8
Last active August 29, 2015 14:15
1-5 to 1-7 generator
import System.Random
import Control.Monad
main = do
let trials = 100000
vals ← collect trials $ zip [1‥7] $ cycle [0]
let percents = map (λ(value,amount) → (value,amount / trials)) vals
print percents
--collect:: Int -> [(Int, Int)] -> IO [(Int, Int)]
@octopuscabbage
octopuscabbage / gist:0d884829e8349c74f0b8
Created July 3, 2014 02:18
i'm the best mayne i deeeeeeeeeeeeeeeeed it
matrix_list = [[1,2,3],[4,5,6],[7,8,9]]
def lrange(seq):
'''returns a generator for the range of a length of a matrix'''
return range(len(seq))
def rotateMatrix(matrix_list):
'''rotates a matrix'''
#Constructs matrix of same size as supplied matrix
#The function f should return true iff is supplied the key you want to remove
def cloneExcluding(f, seq):
return filter(f, seq)
@octopuscabbage
octopuscabbage / gist:ccff498b41c7f4ac9830
Last active August 29, 2015 14:02
S A D B O Y S python interpreter and command line
import sys
def sadify(string):
string = str(string)
out = ""
for char in string:
out += char.upper() + " "
return out+'B O Y S'
if(len(sys.argv)>=2):
@octopuscabbage
octopuscabbage / gist:0aba7550d5522cbd86d6
Last active August 29, 2015 14:01
functional parenthesis balancer
def balance(chars):
def testchar(chars, open, closed)
if (open < closed):
return False
if not chars: #chars is empty
return (open == closed)
if (chars.head == '('):
testchar(chars.tail, open+1, closed)
elif (chars.head == ')'):
testchar(chars.tail, open, closed+1)
@octopuscabbage
octopuscabbage / spotify_control.py
Created April 15, 2014 21:40
control spotify from the command line
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument("-p",action="store_true",dest="playpause",default=False)
parser.add_argument("-n",action="store_true",dest="next",default=False)
parser.add_argument("-l",action="store_true",dest="previous",default=False)
results = parser.parse_args()