Skip to content

Instantly share code, notes, and snippets.

View Alexis-D's full-sized avatar

Alexis Daboville Alexis-D

View GitHub Profile
@Alexis-D
Alexis-D / primes.cpp
Created June 29, 2011 21:06
Compute primes upto n
/* really fast & efficient, if you need to increase speed replace std::vector by std::list */
#include <cmath>
#include <list>
#include <vector>
#include <iostream>
using namespace std;
vector<int> getPrimes(int n) {
vector<bool> crible(n + 1, true);
@Alexis-D
Alexis-D / objects.py
Created July 8, 2011 17:59
Abusing iterator to get objects without class keyword
#!/usr/bin/env python
#-*- coding: utf-8 -*-
def Person(name, life=100):
_name = name
_life = life
def _init_():
cmd = yield
#include "malloc.h"
/*
* nchunks
* Représente le nombre de chunk "disponible" pour ce chunk.
* Il y a donc nchunks - 1 chunks disponibles pour l'utilisateur.
* next
* Pointe vers le prochain chunk de la liste.
*/
typedef struct chunk {
/*
* Alexis Daboville - 2011
*/
#include <fcntl.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
@Alexis-D
Alexis-D / badwords.py
Created October 6, 2011 15:39
Distributed Systems - Tutorial 1
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import socket
import threading
class BadWordsServer:
"""Represent a server which is designed to filter "bad words"
from data which is send to the network, and then resend
the cleaned data to the client."""
@Alexis-D
Alexis-D / primes.py
Created November 6, 2011 11:51
Eratosthene sieve
#!/usr/bin/env pypy
#-*- coding: utf-8 -*-
def get_primes(n=10**6):
if n < 2:
return []
sieve = [True] * (n + 1)
sieve[:2] = [False, False]
#primes = [2]
@Alexis-D
Alexis-D / oauth2.html
Created November 17, 2011 19:35
Distributed Systems - Tutorial 3 (Facebook/Oauth2)
<!doctype html>
<html>
<!-- Alexis Daboville - 11110651 1 -->
<head>
<meta charset="utf-8" />
<title>OAuth 2 - Facebook</title>
</head>
<body>
<!-- placeholder for the name of the user -->
<div id="greetings"></div>
@Alexis-D
Alexis-D / merged.csv
Created January 13, 2012 18:27
merged.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 10 columns, instead of 6 in line 9.
Date, #words, #positive, #negative, domain, pos freq, neg freq, domain freq, volume, close
2004-01-01, 30964, 775, 371, 107, 0.025029066012143133, 0.011981656116780778, 0.0034556258881281486, ,
2004-01-02, 81655, 2768, 873, 760, 0.03389872022533831, 0.01069132325026024, 0.009307452084991733, 0, 3596.8
2004-01-03, 44283, 1176, 556, 125, 0.026556466364067475, 0.012555608246957072, 0.0028227536526432267, ,
2004-01-05, 148177, 5142, 1773, 1445, 0.03470174183577748, 0.011965419734506705, 0.009751850827051432, 0, 3608.29
2004-01-06, 100011, 3371, 1156, 854, 0.033706292307846136, 0.011558728539860615, 0.008539060703322634, 0, 3595.82
2004-01-07, 123872, 4310, 1350, 1072, 0.034793980883492635, 0.010898346680444329, 0.00865409454921209, 0, 3563.51
2004-01-08, 112720, 3668, 1309, 985, 0.03254080908445706, 0.011612845990063875, 0.00873846699787083, 0, 3592.73
2004-01-09, 139877, 4584, 1556, 1254, 0.03277164937766752, 0.01112405899468819, 0.008965019266927372, 0, 3574.8
2004-01-10, 62778, 1663, 762, 303, 0.026490171716
dabovila@macneill:~/concurrent$ cat sample3.run
1 thread(s): 524.11s
2 thread(s): 275.00s
3 thread(s): 192.64s
4 thread(s): 150.11s
5 thread(s): 122.52s
6 thread(s): 104.51s
7 thread(s): 97.71s
8 thread(s): 88.17s
9 thread(s): 75.76s
@Alexis-D
Alexis-D / consumer.c
Created February 11, 2012 15:51
Producer / Consumer / Conditions variables / pthreads
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define BUF_SIZE 5
// the buffer works like a stack for
// the sake of simplicity, if needed
// we may implement a queue