Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string operator "" _rev(char const *p, size_t sz)
{
string rev(p, sz);
reverse(rev.begin(), rev.end());
diff --git a/bench/db-bench.c b/bench/db-bench.c
index bf6dbfc..6207b42 100644
--- a/bench/db-bench.c
+++ b/bench/db-bench.c
@@ -20,6 +20,7 @@
#include <time.h>
#include <sys/time.h>
#include <string.h>
+#include <signal.h>
#include "../engine/util.h"
time_in_sec total_inserted inserts_per_sec
0 0 0
1 170000 170000
2 330000 160000
3 440000 110000
4 590000 150000
5 730000 140000
6 870000 140000
7 1010000 140000
8 1150000 140000
@nicolasff
nicolasff / grp.hs
Created April 13, 2011 17:48
Grouping numbers together in Haskell
-- Group blocks together.
import Data.List (intersperse)
grp :: [Int] -> [(Int,Int)]
grp [] = []
grp (x:xs) = pair x x xs where
pair lo hi (x:xs) | x == hi + 1 = pair lo x xs
pair lo hi xs | otherwise = (lo,hi): grp xs
[
{
"disabled": ["*"]
},
{
"enabled": ["GET", "SET", "INCR"]
}
]
@nicolasff
nicolasff / gist:773056
Created January 10, 2011 17:04
Allowed elements in a set.
-module(test).
-export([allowed/1]).
% null case
allowed([]) ->
[];
% single element case
allowed([E]) ->
[[E]];
*4\r\n
$4\r\n
ZADD\r\n
$4\r\n
key1\r\n
$3\r\n
123\r\n
$6\r\n
query1\r\n
fileCopyNoComment infile outfile = do
contents <- readFile infile
let out = map (fst . break (== '%')) $ lines contents
writeFile outfile $ unlines out
module Main where
import System.Environment
import Control.Concurrent
import Control.Monad
process i inbox outbox = do
msg <- takeMVar inbox -- read message from inbox
when (i /= 0 || msg == 0) (putMVar outbox $! msg) -- all except the last node forward their message
when (msg /= 0) (process i inbox outbox) -- when not at the last message, recur.
module Main where
data Bst a = Nil | Node {
elt :: a,
l :: Bst a,
r :: Bst a} deriving Show
insert_ntr Nil x = Node x Nil Nil
insert_ntr n x | x < elt n = n {l = insert_ntr (l n) x}
| x > elt n = n {r = insert_ntr (r n) x}