Skip to content

Instantly share code, notes, and snippets.

let rec seq n_from n_to =
if n_from <= n_to then
let rec seq_ n acc = match n with
| n when n = n_from-1 -> acc
| _ -> seq_ (n-1) (n::acc)
in seq_ n_to []
else
[]
@siritori
siritori / error
Created July 8, 2012 13:25
http-server.c
http-server-fork.c: In function ‘http_receive_request’:
http-server-fork.c:241: warning: implicit declaration of function ‘strdup’
http-server-fork.c:241: warning: assignment makes pointer from integer without a cast
http-server-fork.c:243: warning: initialization makes pointer from integer without a cast
http-server-fork.c: In function ‘sockaddr_print’:
http-server-fork.c:375: warning: implicit declaration of function ‘getnameinfo’
http-server-fork.c:376: error: ‘NI_NUMERICHOST’ undeclared (first use in this function)
http-server-fork.c:376: error: (Each undeclared identifier is reported only once
http-server-fork.c:376: error: for each function it appears in.)
http-server-fork.c:376: error: ‘NI_NUMERICSERV’ undeclared (first use in this function)
#include <iostream>
#include <boost/regex.hpp>
int main()
{
std::string file_path = "/foo/bar/bunny.obj";
std::string type = "unknown";
boost::regex rx_find_extension("^.*\\.(\\w+)$");
boost::smatch result;
if ( boost::regex_match( file_path, result, rx_find_extension ) )
@siritori
siritori / NK.cpp
Created May 24, 2012 15:24
ほげほげ
#include <iostream>
#include <map>
using namespace std;
typedef enum {
IMPLIES,
AND,
OR,
NOT,
#include <iostream>
using namespace std;
typedef enum {
ATOMIC,
NOT,
AND,
OR,
IMPLIES,
@siritori
siritori / aatree.c
Created May 21, 2012 03:40
AA tree by C
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include "aatree.h"
static aanode* new_aanode(const int key, void *val, aanode *nullnode) {
aanode *n = (aanode*)malloc(sizeof(aanode));
if(n == NULL) return NULL;
n->key = key;
expr : primitive | <'+', expr, expr> | <'-', expr, expr>
primitive : NUMBER
equal(e1:NUMBER, e2:NUMBER) ->
e1 == e2
equal(<'+', e1l, e1r>, <'+', erl, e2r>) ->
equal(e1l, e2l) && equal(e1r, e2r)
equal(<'-', e1l, e1r>, <'-', erl, e2r>) ->
equal(e1l, e2l) && equal(e1r, e2r)
@siritori
siritori / expr_tree.als
Created May 1, 2012 19:52
式木の定義的なアレ
abstract sig Expr {
lhs : lone Expr,
rhs : lone Expr
}
sig True extends Expr {}
sig False extends Expr {}
sig Not extends Expr {}
sig And extends Expr {}
sig Or extends Expr {}
@siritori
siritori / binaty_tree.als
Created February 19, 2012 16:19
二分探索木をAlloyで定義してみた
open util/ordering[Node]
sig Node {
lhs : lone Node,
rhs : lone Node
}
fact {
// 葉をたどればすべての要素が取得できるrootがただひとつ存在する
one root : Node | Node = root.*(lhs+rhs)
// 任意の節において成り立つ
@siritori
siritori / circular_list.c
Created February 6, 2012 06:35
循環リスト
#include <stdio.h>
struct node {
int data;
struct node *next;
};
int main(void) {
struct node a, b, c, d;
a.next = &b;