Skip to content

Instantly share code, notes, and snippets.

View timjb's full-sized avatar

Tim Baumann timjb

View GitHub Profile
@timjb
timjb / NineDigitProblem.hs
Created July 26, 2011 22:24
NineDigitProblem
-- http://csokavar.hu/blog/2010/04/20/problem-of-the-week-9-digit-problem/
import Data.List (delete)
main :: IO ()
main = print $ solve 0 1 [1..9]
solve :: Integral a => a -> a -> [a] -> [a]
solve curr _ [] = [curr]
solve curr divisor possibilities = concatMap solveFor possibilities
@timjb
timjb / about.md
Created August 10, 2011 18:51 — forked from robotlolita/about.md
Programming Achievements: How to Level Up as a Developer
@timjb
timjb / Cat.hs
Created August 18, 2011 11:23
Cat.hs
{-
- This is a simple type-safe concatenative (stack-based) language
- implemented as an embedded DSL in Haskell. It's based on the ideas presented in
-
- http://www.codecommit.com/blog/cat/the-joy-of-concatenative-languages-part-1
- -"- 2
- -"- 3
-
- MIT License, Tim Baumann
-}
@timjb
timjb / proper-test.html
Created September 8, 2011 20:20
Rich-Text-Editing with YUI3
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Proper with YUI &ndash; Test</title>
</head>
<body>
<p id="buttons">
@timjb
timjb / sanitize.js
Created September 24, 2011 10:53
HTML Sanitizer for JavaScript
// I'm developing this now as a part of substance (https://github.com/michael/substance)
@timjb
timjb / gist:1239228
Created September 24, 2011 11:43 — forked from michael/gist:1239217
sanitizeConfig.json
{
"a":{
href: function(href) {
// accepts only absolute http, https and ftp URLs and email-addresses
return /^(mailto:|(https?|ftp):\/\/)/.test(href);
}
},
"strong": {},
"em": {},
"b": {},
@timjb
timjb / index.html
Created October 22, 2011 16:45
HTML-Kurs
<!doctype html>
<html>
<head>
<title>Erstes Beispiel</title>
<style>
body {
background: rgb(200, 200, 0);
font-size: 100px;
font-family: sans-serif;
}
@timjb
timjb / LinearRegression.hs
Created October 28, 2011 17:39
AI class: Linear Regression
-- https://www.ai-class.com/course/video/quizquestion/127
module LinearRegression where
computeLR :: [(Double, Double)] -> (Double, Double)
computeLR vs = (w0, w1)
where w1 = enum / denom
enum = m * (sum $ zipWith (*) xs ys) - (sum xs) * (sum ys)
denom = m * (sum . map (^2) $ xs) - (sum xs)^2
w0 = (sum ys - w1 * sum xs) / m
@timjb
timjb / Euclid.hs
Created November 1, 2011 22:49
Extended Euclidean algorithm
-- Extended Euclidean algorithm
-- Preconditions: gcd(a, b) = 1, a > b
-- Postcondition: (fst result) * a + (snd result) * b = 1
euc :: (Integral a) => a -> a -> (a, a)
euc a b = case b of
1 -> (0, 1)
_ -> let (e, f) = euc b d
in (f, e - c*f)
where c = a `div` b
@timjb
timjb / SimpleMotionModel.hs
Created December 7, 2011 23:56
AI class: Simple Motion Model
-- https://www.ai-class.com/course/video/quizquestion/285
data State = S { x :: Double
, y :: Double
, theta :: Double
, v :: Double
, omega :: Double
, dt :: Double
} deriving (Show)