Skip to content

Instantly share code, notes, and snippets.

View fsodogandji's full-sized avatar

Fabrice Sodogandji fsodogandji

View GitHub Profile

Python Number Conversion Chart

From To Expression
@fsodogandji
fsodogandji / x_times_per_second.py
Created April 26, 2013 12:09
Monitor the CPU Temperature with sched module and linux command sensors from lm_sensors software
import sched, time
from time import strftime, localtime
import sys
from subprocess import check_output
import re
scheduler = sched.scheduler(time.time, time.sleep)
def sched_call(calls_per_second, callback, *args, **kw):
period = 1.0 / calls_per_second
import networkx as nx
import pprint
from operator import itemgetter
G = nx.read_graphml('metro.graphml')
print "graph has %d nodes with %d edges"\
% (nx.number_of_nodes(G), nx.number_of_edges(G))
@fsodogandji
fsodogandji / skeleton.py
Created May 29, 2013 12:10
Template file for python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4 nu
from __future__ import (unicode_literals, absolute_import,
division, print_function)
"""
package.module
~~~~~~~~~~~~~
@fsodogandji
fsodogandji / id_generator.py
Created July 3, 2013 09:07
random string generator
def id_generator(size=8, chars=string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for x in range(size))
import time
import datetime
print "Time in seconds since the epoch: %s" %time.time()
print "Current date and time: " , datetime.datetime.now()
print "Or like this: " ,datetime.datetime.now().strftime("%y-%m-%d-%H-%M")
print "Current year: ", datetime.date.today().strftime("%Y")
print "Month of year: ", datetime.date.today().strftime("%B")
@fsodogandji
fsodogandji / profile_decorator.py
Created July 5, 2013 15:22
A simple profiling decorator
def profileit(func):
def wrapper(*args, **kwargs):
datafn = func.__name__ + ".profile"
prof = cProfile.Profile()
retval = prof.runcall(func, *args, **kwargs)
prof.dump_stats(datafn)
return retval
return wrapper
@fsodogandji
fsodogandji / install_oracle_JDK_ubuntu.sh
Last active December 19, 2015 15:19
Install Oracle JDK with ubuntu
#!/bin/sh
# remove openJDK
sudo apt-get purge openjdk-\*
# Install Oracle JDK
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java6-installer
@fsodogandji
fsodogandji / .bashrc_MacOS
Last active December 20, 2015 03:09
OS x setup
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
# tell grep to highlight matches
export GREP_OPTIONS='--color=auto'
# alias
alias ls='ls -FGal'
@fsodogandji
fsodogandji / git-tips
Created July 24, 2013 23:04
git tip & tricks
#Enabling colors in git command-line interface
git config color.ui true