Skip to content

Instantly share code, notes, and snippets.

View nicolargo's full-sized avatar

Nicolas Hennion nicolargo

View GitHub Profile
onename
import asyncore
import socket
class PortScanner(asyncore.dispatcher):
def __init__(self, host, port):
self.host = host
self.port = port
asyncore.dispatcher.__init__(self)
@nicolargo
nicolargo / compress-value.py
Last active October 26, 2021 06:43
Compress list of float (precision 0.01)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Timestamp compression test bed
#
#
import sys
import array
@nicolargo
nicolargo / tips.py
Last active May 5, 2020 08:37
Python tips for optimization
#############################################################################
# Apply a function to a list
#############################################################################
# Instead of...
newlist = []
for word in oldlist:
newlist.append(word.upper())
# ... use map
@nicolargo
nicolargo / dockerstatsbench.py
Last active August 29, 2015 14:27
Docker stats getter in a thread
import threading
import docker
import time
class ThreadStats(threading.Thread):
def __init__(self, client, container):
super(ThreadStats, self).__init__()
self._stop = threading.Event()
self.container = container
@nicolargo
nicolargo / gist:22662eb26ca590bea198
Created January 11, 2015 13:24
Stress script for Glances
NBCORE=`nproc`
FREEMEM=`free -th | grep "buffers/cache" | awk '{print $4}'`
TIME=30
echo "START CPU stress"
echo "$NBCORE logical core"
echo
echo "Stress CPU user - $TIME seconds"
stress --cpu $NBCORE -t $TIME
# echo
@nicolargo
nicolargo / 0_reuse_code.js
Created November 27, 2013 20:41
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@nicolargo
nicolargo / firewall.sh
Last active December 29, 2016 10:07
My firewall startup script
#!/bin/sh
#
# Simple Firewall configuration.
#
# Author: Nicolargo
#
# chkconfig: 2345 9 91
# description: Activates/Deactivates the firewall at boot time
#
### BEGIN INIT INFO
@nicolargo
nicolargo / gist:4647457
Created January 27, 2013 08:54
Glances 1.6 default configuration file
[cpu]
# Limits values for CPU user in %
# Defaults values if not defined: 50/70/90
user_careful=50
user_warning=70
user_critical=90
# Limits values for CPU system in %
# Defaults values if not defined: 50/70/90
system_careful=50
system_warning=70
@nicolargo
nicolargo / wansimul.sh
Created June 20, 2012 12:46
A WAN simulator script for Linux box
#!/bin/bash
#
# simulwan-bridge.sh
# Nicolargo - 2012
#
##############################################################################
# Nom des interfaces ou l'on doit faire les simulations
# eth0 cote LAN local