This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cx_Oracle | |
""" | |
Check the install for cx_Oracle | |
""" | |
con = cx_Oracle.connect('<LOGIN>/<PASSWORD>@<INSTANCE>') | |
print con.version | |
con.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |