Skip to content

Instantly share code, notes, and snippets.

// Index of maximum: j
int j = 0;
for (int i = 1; i < array.length; i++) {
if (array[i] > array[j]) j = i;
}
@hmaurer
hmaurer / intput.txt
Created February 24, 2014 00:10 — forked from bemasher/intput.txt
// This is the structure of the binary nbt file
TAG_Compound('Level') {
TAG_Compound('nested compound test') {
TAG_Compound('egg') {
TAG_String('name'): 'Eggbert'
TAG_Float('value'): 0.5
}
TAG_Compound('ham') {
TAG_String('name'): 'Hampus'
TAG_Float('value'): 0.75
sumUpTo :: Int -> [(Int, Int)]
sumUpTo n = map (\x -> (x, n - x)) [0..n]
mult xs ys = do
cs <- map sumUpTo [0..maxCoef]
return (sum $ map g $ filter f cs)
where
maxCoef = length xs + length ys - 2
f (x, y) = x < length xs && y < length ys
g (x, y) = (xs !! x) * (ys !! y)
apply :: (t -> a) -> (t -> b) -> (a, b)
apply f g x = (f x, g x)

Useful Scalac Flags

So, there have been some discussions and angry tweets recently about irritating Scala "features" (like value discarding and auto-tupling) that can actually be turned off by selecting the right compiler flag in conjunction with -Xfatal-warnings. I highly recommend a set of options something like those below.

scalacOptions ++= Seq(
  "-deprecation",           
  "-encoding", "UTF-8",       // yes, this is 2 args
  "-feature",                
 "-language:existentials",
... = begin
suc (a + suc b)
==< cong suc (lemma2 a b) >
suc (suc (a + b))
==< cong (suc.suc) (comm a b) >
suc (suc (b + a))
==< cong suc (sym (lemma2 b a)) >
suc (b + suc a)
[]
suc (a + suc b) == suc (b + suc a)
^
|
|
suc (suc (a + b)) == suc (b + suc a)
^
|
|
suc (suc (a + b)) == suc (suc (b + a))
^
module Printf
%default total
data Format = FInt Format -- %d
| FString Format -- %s
| FOther Char Format -- [a-zA-Z0-9]
| FEnd --
format : List Char -> Format

This is my recommended path for learning Haskell.

Something to keep in mind: don't sweat the stuff you don't understand immediately. Just keep moving.

Primary course

Installing Haskell

Ubuntu PPA

require 'tire'
require 'nobrainer'
NoBrainer.connect 'rethinkdb://server/company'
class Employee
include NoBrainer::Document
field :name
field :title