Skip to content

Instantly share code, notes, and snippets.

View AtnNn's full-sized avatar
:shipit:

Etienne Laurin AtnNn

:shipit:
View GitHub Profile
@AtnNn
AtnNn / persistent-graph.hs
Created September 14, 2011 06:49
Visualize Persistent Schemas Using Graphviz
{-# LANGUAGE UnicodeSyntax, ViewPatterns #-}
-- usage:
-- persistent-graph < config/models > schema.dot
-- neato schema.dot -Tpdf > schema.pdfimport Database.Persist.Base (EntityDef(..), ColumnDef(..))
import Database.Persist.Quasi (parse)
import Data.List (intersperse)
main = do
@AtnNn
AtnNn / Log.hs
Created October 11, 2011 15:23
Simple WAI logging
{-# LANGUAGE UnicodeSyntax #-}
module Log where
import Network.Wai
import Network.HTTP.Types
import System.Log.Logger
import qualified Data.ByteString.Char8 as C
import Control.Monad.Trans
@AtnNn
AtnNn / GenRawSql.hs
Created March 12, 2012 03:52
Generate calls to rawSql
import Database.Persist.Store
import Database.Persist.EntityDef
import qualified Database.Persist.GenericSql as GenSql
import Language.Haskell.TH
import Language.Haskell.TH.Quote
import Language.Haskell.Meta
import qualified Data.Text as T
-- example:
-- (fmap unSingle . listToMaybe → mcssid) ← runDB $
@AtnNn
AtnNn / exemple.c
Created May 15, 2012 04:19
foo(BAR, 42); foo(QUX, "hallo")
#include <stdio.h>
union zig {
int num;
char *str;
};
enum pop { BAR, QUX };
void foo_ (enum pop p, union zig z){
struct t{struct t*l,*r;int x;};
extern puts();
int main(){
struct t tree1 = { 0, 0, 1 };
struct t tree3 = { 0, 0, 3 };
struct t tree2 = { &tree1, &tree3, 2 };
struct t tree5 = { 0, 0, 5 };
struct t tree7 = { 0, 0, 7 };
@AtnNn
AtnNn / utils.sh
Last active December 23, 2015 11:49
Mostly posix shell scripting tricks: assoc list, logging, classes, methods, inheritance, ...
set -e
set -u
main () {
init
# ...
}
# contains <haystack> <needle>
# Test if the space-separated list haystack contains needle
@AtnNn
AtnNn / code_with_types.hs
Created October 7, 2013 17:26
Code generation with types For GHC HEAD (7.7.20131005)
-- Code generation with types
-- For GHC HEAD (7.7.20131005)
{-# LANGUAGE
KindSignatures, DataKinds, PolyKinds, UnicodeSyntax,
TypeFamilies, UndecidableInstances, TypeOperators,
ScopedTypeVariables, ConstraintKinds, FlexibleInstances,
MultiParamTypeClasses, FunctionalDependencies,
FlexibleContexts, RankNTypes, ImpredicativeTypes,
diff --git a/src/clustering/administration/cli/admin_command_parser.cc b/src/clustering/administration/cli/admin_command_parser.cc
index 453eb0d..4d0d260 100644
--- a/src/clustering/administration/cli/admin_command_parser.cc
+++ b/src/clustering/administration/cli/admin_command_parser.cc
@@ -344,7 +344,8 @@ admin_command_parser_t::admin_term_cap_t::admin_term_cap_t(fd_t fd) {
}
// Command to disable all formatting
- char *normal_cstr = tgetstr("me", NULL);
+ char end_modes[] = "me";
@AtnNn
AtnNn / bench.py
Last active December 27, 2015 15:18
#!/usr/bin/env python
import rethinkdb as r
import rethinkdb.ast
import rethinkdb.net
import sys
import types
import json
import ujson
@AtnNn
AtnNn / test query
Last active December 29, 2015 07:18
r.table('lexi2').insert([
{net:{lo:{tx:1, rx:2}, eth0:{tx:2, rx:4}}},
{net:{lo:{tx:4, rx:6}, wl0ps4:{tx:7, rx:1}}},
{net:{lo:{tx:14, rx:8}, eth0:{tx:1, rx:5}}}])
r.table('lexi2').reduce(
function(left, right){
return { net:
left('net').keys().setUnion(right('net').keys()).map(
function(iface){