Skip to content

Instantly share code, notes, and snippets.

@bamthomas
bamthomas / ChiffreRomain.java
Created October 17, 2012 22:12
Chiffre Romain TDD
package bam;
import static bam.ChiffreRomain.Chiffre.*;
import static java.lang.Math.abs;
import static java.util.Arrays.asList;
public class ChiffreRomain {
public final String chiffreRomain;
enum Chiffre {
@bamthomas
bamthomas / blocage.java
Created October 18, 2012 07:36
Bascule
private int calculepalier(StringBuffer buffer, int chiffre, Chiffre chiffreCourant, Chiffre precedent) {
int nombrePalier = chiffre / chiffreCourant.chiffreArabe;
for (int i = 0; i < nombrePalier; i++) {
if (chiffre >= chiffreCourant.chiffreArabe) {
buffer.append(chiffreCourant.name());
chiffre -= chiffreCourant.chiffreArabe;
}
}
if (chiffre == chiffreCourant.chiffreArabe - precedent.chiffreArabe) {
buffer.append(precedent.name());
@bamthomas
bamthomas / pub_sub_redis.py
Created November 28, 2012 22:16
Pub/Sub redis python
from multiprocessing.process import Process
import time
import redis
def pub(myredis):
for n in range(10):
myredis.publish('channel','blah %d' % n)
time.sleep(5)
def sub(myredis, name):
@bamthomas
bamthomas / gist:7168175
Last active December 26, 2015 14:49
Get subdir of git repository
git archive --remote=<url_repo> <branche> [<chemin>] | tar xvf
@bamthomas
bamthomas / app.js
Last active December 28, 2015 17:29
Atelier emberjs - 2e épisode
// pour memoire
App = Ember.Application.create();
var marks = [
{id: '1', title: 'barreverte', url: "http://barreverte.fr"},
{id: '2', title: 'leanagilecamp', url: "http://leanagilecamp.fr"},
{id: '3', title: 'ansamb', url: 'http://www.ansamb.com'}
];
App.Router.map(function () {
@bamthomas
bamthomas / myzip.py
Last active December 29, 2015 00:49
in memory zip with python
from zipfile import ZipFile
def append_file(memory_stream, file_name, file_content):
with ZipFile(memory_stream, 'a') as zf:
zf.writestr(file_name, file_content)
@bamthomas
bamthomas / gist:7970938
Last active December 31, 2015 10:09
OpenSCAD mug
$fn = 200;
tasse(160, 120);
rotate([90, 0, 0])
translate([65, 80, 0])
anse_ronde();
module tasse(hauteur, diametre) {
difference() {
@bamthomas
bamthomas / gist:8210776
Last active January 1, 2016 22:29
chroot with peudo-devices
sudo mount /dev/sda1 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
@bamthomas
bamthomas / test_docker.sh
Last active August 29, 2015 13:56
Playing with docker
# install with ubuntu 13.10 64 bits - warning with 32bits apt wont find the package
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install lxc-docker
# check install ok
sudo docker ps -a
# lets play with containers
@bamthomas
bamthomas / chroot.sh
Last active August 29, 2015 14:00
mounting host chroot pseudo filesystem
bindir=$(dirname $0)
root_dir=$bindir/root_dir
montePointsPourChroot() {
sudo echo -ne « mounting pseudo filesystems: »
for pseudo in dev proc sys
do
sudo mount –bind /$pseudo $root_dir/$pseudo
echo -ne » $pseudo »
done