Skip to content

Instantly share code, notes, and snippets.

@k0001
k0001 / gist:833226
Created February 18, 2011 03:50
Some *sh file redirection
k@del 0 /tmp % { echo "a" > /dev/stdout; echo "b" > /dev/stderr } 1> >(tee -a out) 2> >(tee -a err >&2)
b
a
k@del 0 /tmp % cat out
a
k@del 0 /tmp % cat err
b
@k0001
k0001 / microformats.py
Created May 4, 2011 11:48 — forked from scoffey/microformats.py
Python microformats parser that supports hCard, hCalendar, hResume and rel-tag and provides an extensible model for other microformats.
# -*- coding: utf-8 -*-
#!/usr/bin/env python
"""
Model for microformat properties and parsers. A microformat parser can
parse an HTML element into a dictionary of properties, whose keys are
strings and whose values are strings or other dictionary of properties.
As an example, the main program of this script parses an hResume from
given URL.
@k0001
k0001 / crawler.py
Created August 15, 2011 00:52 — forked from jmoiron/crawler.py
Simple gevent/httplib2 web crawler.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple async crawler/callback queue based on gevent."""
import traceback
import logging
import httplib2
import gevent
@k0001
k0001 / peuler.hs
Created December 31, 2011 16:09
Project Euler solutions in Haskell
import Control.Applicative
--
-- Utils
--
-- Ordered List: difference
minus :: (Ord a) => [a] -> [a] -> [a]
minus (x:xs) (y:ys) = case (compare x y) of
LT -> x : minus xs (y:ys)
--- PKGBUILD 2011-12-17 19:24:25.000000000 -0300
+++ PKGBUILD.new 2012-01-01 14:33:41.501639783 -0300
@@ -22,3 +22,3 @@
source=("http://us.download.nvidia.com/XFree86/Linux-${_arch}/${pkgver}/${_pkg}.run")
- md5sums=('29e47c0ba2d755a0807661a988af0773')
+ md5sums=('5a80b13f0e92e33367d49866f6377dc1')
fi
@k0001
k0001 / groupBy.hs
Created January 2, 2012 09:21
My (untested) implementation of Data.List.groupBy
-- My (untested) implementation of Data.List.groupBy
groupBy' :: (a -> a -> Bool) -> [a] -> [[a]]
groupBy' f xs = foldr step [] xs
where step x acc@(yy@(y:ys):yys)
| f x y = (x:yy):yys
| otherwise = [x]:acc
step x [] = [[x]]
ghci> "Hello World" =~ "W.rld" :: Bool
True
ghci> "Hello World" =~ "W.rld" :: Int
1
ghci> "Hello World" =~ "W.rld" :: String
"World"
ghci> "Hello World" =~ "W.rld" :: (Int, Int)
(6,5)
module Tony20 (
Fluffy,
furry,
EitherLeft(..),
EitherRight(..),
Misty,
banana,
unicorn,
jellybean,
apple
@k0001
k0001 / constcheatshit.c
Created April 19, 2012 16:53
C const rules cheat shit
typedef struct {
int a;
const int b;
} thing_t;
int main(int argc, char *argv[])
{
thing_t t1 = { .a = 1, .b = 2 };
t1.a = 90;
// t1.b = 90; // NO!
- switch (state) {
+ switch (state) { /** Finit tillståndsmaskinen från helvete **/