Skip to content

Instantly share code, notes, and snippets.

View terrettaz's full-sized avatar

Pierrick Terrettaz terrettaz

View GitHub Profile
@terrettaz
terrettaz / MasterMind.java
Last active March 15, 2023 21:54
Easy version of MasterMind developed with my sister
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class MasterMind {
@terrettaz
terrettaz / setJDK
Last active December 4, 2021 22:41
Set JDK
#!/usr/bin/env python3
import glob
import pathlib
import sys
jdks = {}
jdks.update(dict([(x.name, x) for x in pathlib.Path('/usr/local/opt').glob('openjdk@*')]))
jdks.update(dict([(x.parent.parent.name, x) for x in pathlib.Path('/Library/Java/JavaVirtualMachines').glob('*/Contents/Home')]))
#!/usr/bin/env python2.7
import sys
import os
import popen2
import re
import shutil
import pytz
import imghdr
from datetime import datetime
@terrettaz
terrettaz / pi__install_python.sh
Last active January 27, 2019 13:47
Rasberry Pi Python installation
#!/bin/bash
VERSION=3.7.0
sudo apt-get update -y
sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y
wget https://www.python.org/ftp/python/$VERSION/Python-$VERSION.tar.xz
tar xf Python-$VERSION.tar.xz
cd Python-$VERSION
./configure
make -j 2
sudo make altinstall
@terrettaz
terrettaz / pic_remove_orphans.py
Last active March 18, 2018 16:07
Find orphan files based on the extension and move them into directory, typically used for removing raw picture where jpeg have been removed
#!/usr/bin/env python
import os, os.path
import argparse
parser = argparse.ArgumentParser(description='Find orphan files based on the extension and move them into directory')
parser.add_argument('--dir', nargs='?', default=os.getcwd(), help='Directory to process (default CWD)')
parser.add_argument('--dest', nargs='?', default='orphans', help='Destination directory (default orphans)')
parser.add_argument('--delete', action='store_true', default=False, help='Delete files instead of backing them up')
parser.add_argument('--sensitive', action='store_true', default=False, help='Case sensitive for extensions')
@terrettaz
terrettaz / .bash_PS1
Created November 9, 2017 10:16
Gist than display fast Mercurial info
# Version 1.1
__get_hg_dir() {
local d=`readlink -f "$1"`
if [ -d "$d/.hg" ]; then
echo "$d/.hg"
return 0
elif [ "$d" == "/" ]; then
echo ""
return 1
@terrettaz
terrettaz / LambdaBenchmark.java
Last active February 24, 2017 16:34
Java Benchmarks of lambdas
/*
* Benchmarks of Java 8
*/
package benchmarks;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.openjdk.jmh.annotations.BenchmarkMode;
@terrettaz
terrettaz / jpeg-keywords.py
Last active December 8, 2019 20:15
JPEG Keywords
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
__version__ = "$Revision: 0.1 $"
__author__ = "Pierrick Terrettaz"
__date__ = "2007-08-15"
import argparse, subprocess
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='JPEG Keywords')
@terrettaz
terrettaz / vigenere.py
Last active September 1, 2016 15:47
Vigenere Cipher tool
#!/usr/bin/env python
import sys, argparse, random
start = ord('.')
end = ord('Z')
modulo = (end - start) + 1
def alphabet():
return reduce(lambda a, b: '%s%s' % (a,b), map(lambda x: chr(x), range(start, end+1)))
@terrettaz
terrettaz / sqs-admin.py
Last active August 29, 2015 14:14
sqs-admin
#!/usr/bin/python
import csv, sys
from math import sin
from collections import Counter
class Player:
def __init__(self, name):
self.name = name
self.points = 0