Skip to content

Instantly share code, notes, and snippets.

View fspot's full-sized avatar

Frédéric Matigot fspot

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fspot
fspot / jwt.md
Last active December 6, 2018 14:28

How to craft authenticated tokens ?

Say you want to create a token with limited rights, for example with only access to a specific small app "myapp", and with a limited view on the data, like if you had a group "mygroup" assigned (this mechanism requires to setup permissions).

And say you want this token to expire in 10 hours, for security reasons.

The python code for crafting the token (using pyjwt library) would be:

import jwt
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Usage: python upn.py list
python upn.py add|delete <port> tcp|udp"""
import miniupnpc
import sys
try:
@fspot
fspot / worker_manager.coffee
Created November 28, 2013 23:55
Simple way of making a worker manager with node.js, so you can limit concurrent tasks (cpu bound).
EventEmitter = require('events').EventEmitter
print = console.log
class MyManager extends EventEmitter
constructor: (@max_w) ->
@nb_w = 0
@queue = []
@on 'died_worker', (arg) ->
@on_died_worker(arg)
@fspot
fspot / pdc2.md
Last active December 25, 2015 13:19
PDC 2

Gestion des ressources

Voilà le fruit d'une recherche de solutions au niveau du thème "gestion des ressources", pour les besoins de la DSI.

Précision : "ressources", dans ce contexte, désigne les PC des salles de TP (puisqu'on parle de la plateforme d'enseignement), mais peut également désigner les serveurs (hébergeant moodle, le webmail, les VMs, etc).

Objectif

@fspot
fspot / saltshell.py
Created October 10, 2013 00:58
Usage : "saltshell.py" to get the list of minions (+ os and ip), "saltshell.py foo" to virtually ssh into foo minion. A lot of restrictions. May not work if your salt master is properly configured.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import os
from os.path import join
if len(sys.argv) == 1:
print "\n### Wanna see the list of connected minions, and their respective OS ? k."
print "### Wait a little... like 10s...\n"
#!/bin/bash
set -e
echo "> Downloading virtualenv.py..."
wget -q https://raw.github.com/pypa/virtualenv/develop/virtualenv.py # -O virtualenv.py
# or curl -s https://raw.github.com/pypa/virtualenv/develop/virtualenv.py > virtualenv.py
echo "> Creating and activating new virtualenv <venv>..."
python virtualenv.py venv > out.log
@fspot
fspot / l.sh
Created July 9, 2013 08:45
alias l="l.sh" => use simply l instead of ls or less
#!/bin/bash
LSCMD="ls --color=auto -lahF"
LESSCMD="less"
if [ $# -eq 0 ]; then
$LSCMD
exit 0;
fi
@fspot
fspot / multiprocessqueue.py
Created June 7, 2013 08:24
Example script using several process in order to consume messages put in a message queue.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Example script using several process in order to consume
messages put in a message queue.
"""
from multiprocessing import Process, Queue, cpu_count