Skip to content

Instantly share code, notes, and snippets.

View fmerlin's full-sized avatar
👍

François Merlin fmerlin

👍
View GitHub Profile
@fmerlin
fmerlin / cx_oracle_check.py
Last active January 16, 2017 09:37
Check the install for cx_Oracle
import cx_Oracle
"""
Check the install for cx_Oracle
"""
con = cx_Oracle.connect('<LOGIN>/<PASSWORD>@<INSTANCE>')
print con.version
con.close()
@fmerlin
fmerlin / ports_per_processes.py
Last active June 10, 2024 20:10
List all the ports opened by processes on the local machine
#!/usr/bin/python
import psutil
"""
List all the ports opened by processes on the local machine
to run it with sudo: sudo python port_processes.py
"""
connections = {}
for c in psutil.net_connections():
@fmerlin
fmerlin / Tuple.java
Last active January 16, 2017 09:38
Tuple is a utility class to encapsulate an array (redefines hashcode and equals).
import java.util.Arrays;
/**
* Tuple is a utility class to encapsulate an array (redefines hashcode and equals).
*/
public class Tuple {
public final Object[] data;
public Tuple(Object... data) {
this.data = data;
@fmerlin
fmerlin / AutoLock.java
Last active January 16, 2017 09:38
to use a lock in a try catch block
import java.util.concurrent.locks.Lock;
/**
* to use a lock in a try catch block
*/
public class AutoLock implements AutoCloseable {
final Lock ref;
public AutoLock(Lock lock) {
ref = lock;
@fmerlin
fmerlin / InternPool.java
Last active November 15, 2019 16:10
This pool is used to keep only one version of an object when they are equal
import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
/*
* This pool is used to keep only one version of an object when they are equal
* The object is garbage collected when it is no longer used.
* e.g.:
InternPool<Integer> p = new InternPool<>();
Integer a = pool.intern(new Integer(1));
Integer b = pool.intern(new Integer(1));
@fmerlin
fmerlin / memory_timings.c
Last active January 11, 2017 16:15
Memory timings with C code to test
#define buf_size 64*1024*1024
#define step 1
/* Memory Timings
* Compiling the two programs and changing the step from 1 to 16 has little impact on the performance while much more memory is changed
* With step=1 it takes 1.06s (3Ghz processor)
* With step=16 it takes 0.93s
* The two programs have almost the same execution time but the second one does 16 times less multiplications.
* This is due to the fact that the cache line size is 64 bytes and both programs use the same number of cache lines.
* The difference is due to the number of multiplication 1.06s - 0.93s = 0.15s = 15 (more multiplications) * 2 * 64M (times) / 3Ghz / (4 mul per clock)