Skip to content

Instantly share code, notes, and snippets.

View ane's full-sized avatar

Antoine Kalmbach ane

View GitHub Profile
import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
}
}
@ane
ane / pdu.hs
Created October 26, 2013 19:34
parallel version of du
-- Parallelized version of the unix "du" command that shows only the size of current *subdirectories.
-- pdu launches a new thread for each subdirectory, using the neat independence of subfolders.
-- (c) ane <ane@iki.fi>
-- license: BSDv3
module Main where
import System
import System.IO
import System.Directory
userRights = self.conn.search("member="+username)
apps = [app for app in userRights if 'groupOfNames' in
app['objectClass'] and
(app['cn'][0].startswith(prefix))]
@ane
ane / Ehrlich.cs
Created September 26, 2011 12:55
Permutation by Ehrlich swaps in C#
static IEnumerable<IEnumerable<T>> Permute<T>(IEnumerable<T> collection)
{
// Initialize
int length = collection.Count();
int[] b = Enumerable.Range(0, length).ToArray();
// Set all in c to zero.
int[] c = Enumerable.Range(0, length + 1).Select(x => 0).ToArray();
// Create a temporary copy.
List<T> set = collection.Select(x => x).ToList();
while (true)
@ane
ane / Permutation.cs
Created June 19, 2011 19:51
Permutations by Ehrlich swaps
static IEnumerable<IEnumerable<T>> Permute<T>(IEnumerable<T> collection)
{
// Initialize
int length = collection.Count();
int[] b = Enumerable.Range(0, length).ToArray();
// Set all in c to zero.
int[] c = Enumerable.Range(0, length + 1).Select(x => 0).ToArray();
// Create a temporary copy.
List<T> set = collection.Select(x => x).ToList();
while (true)
// Geneerisiä C++-toteutuksia Haskellin (2-)tuplafunktioista, ks.
// http://hackage.haskell.org/packages/archive/base/4.1.0.0/doc/html/Prelude.html#19
// uuden C++ 2011 -standardin ominaisuuksista osaa käyttäen.
//
// Kääntyy GCC 4.5.1 vivulla -std=c++0x
// ja VS2010 sellaisenaan.
//
// (c) ane 2011 <ane@iki.fi> (lisenssi: bsd v3)
#include <iostream>
// Geneerisiä toteutuksia Haskellin (2-)tuplafunktioista, ks.
// http://hackage.haskell.org/packages/archive/base/4.1.0.0/doc/html/Prelude.html#19
//
// KÄä
//
// (c) ane 2011 <ane@iki.fi> (lisenssi: bsd v3)
#include <iostream>
#include <vector>
#include <iterator>
ane@hyperion:~$ tracert helsinki.fi
Tracing route to helsinki.fi [128.214.222.4]
over a maximum of 30 hops:
1 <1 ms 1 ms <1 ms 192.168.100.1
2 1 ms 1 ms 1 ms ananas-gw-alue1.kortex.jyu.fi [130.234.176.2]
3 1 ms 1 ms 1 ms 130.234.253.161
4 1 ms <1 ms 1 ms jyu-funet.core.jyu.fi [130.234.254.92]
5 4 ms 4 ms 4 ms csc6-rtr.core.jyu.fi [130.234.254.6]
module Main where
import Data.List
magic :: Int -> Int -> Int
magic end c = foldr1 (+) (counted [1 .. end])
where
counted list = map findN list
findN x = length . filter (\l -> length l == c) . group . sort . filter (/= 0) . map (\z -> z `mod` 10) . take 5 . iterate (\y -> y `div` 10) $ x
-- in Stats.hs
processMessages :: Log -> [(S.ByteString, Int, Int)]
processMessages log = map fmt $ M.toList $ mapReduce rwhnf (foldl' update M.empty)
rwhnf (M.unionsWith (+)) ([msgs log])
where
-- Increments the user (word count discardedfor now) line count by 1.
update map (Message _ nick _) = M.insertWith (+) nick 1 map
msgs = filter isMessage
-- FIXME: adds a word count of 1 to the (Nick, LineCount) pairs from M.toList
-- add wordcount!