Skip to content

Instantly share code, notes, and snippets.

@alan-mushi
alan-mushi / va_list_ncurses.c
Created July 29, 2014 08:21
Simple wrapping of mvwprintw-like using va_list in ncurses
/*
* This is a simple example of va_list function in ncurses.
* I use it to wrap mvwprintw() and print something in a footer.
*
* How to run:
* gcc -o test va_list_ncurses.c -lncurses
*/
#include <ncurses.h>
#include <stdarg.h>
#include <stdio.h>
@alan-mushi
alan-mushi / method1_prepare.js
Created January 17, 2015 17:25
Files used to benchmark MongoDB random document in a collection.
// Preparation for method 1
use benchmark;
print("Method 1, preparation start.");
db.col.ensureIndex( { random_point: '2d' } );
// This feels ugly...
db.col.find().map(function(u) {
db.col.update(
@alan-mushi
alan-mushi / progressbar.java
Created October 28, 2012 17:11
Barre de progression pour la console en java
public class progressbar {
public static void main( String[] args ) {
System.out.println( "[*] Running ..." ) ;
for ( int i = 1 ; i < 101 ; i++ ) {
System.out.flush() ;
System.out.print( "\r " + ( i == 100 ? "100" : " " + ( i < 10 ? " " + i : i) ) + " % " ) ;
System.out.print( "[" ) ;
for ( int j = 0 ; j < i-1 ; j++ ) { System.out.print( "=" ) ; }
@alan-mushi
alan-mushi / pulseaudio_toggle_mute.sh
Created November 8, 2015 14:11
This simple helper script toggle the mute attribute for a program in pulseaudio.
#!/bin/bash
# This simple helper script toggle the mute attribute for a program in pulseaudio.
PROG="Chromium"
all=$(pacmd list-sink-inputs | egrep -B 15 "client: [0-9]+ <${PROG}>" | sed -n '1p;8p')
index=${all:11:2} # get the index
muted=${all:22:3} # get 'yes' or 'no'
@alan-mushi
alan-mushi / scan.py
Created December 2, 2015 10:40
SRI TP scapy TCP connect dumb scanner
from scapy.all import *
ip_dst = "104.16.34.249"
for i in range(1, 65536):
ans,uns = sr(IP(dst=ip_dst) / TCP(dport=i, flags="S"), timeout=1, retry=-2, verbose=False)
try:
if ans[0][1].getlayer(TCP).flags & 0x12 == 0x12:
print str(i) + " is open"
@alan-mushi
alan-mushi / markdown_with_bootstrap_css.sh
Last active December 19, 2015 17:17
Generate a HTML page from markdown files with Bootstrap CSS
#!/bin/bash
check_args=${@:?You forgot the markdown file(s) as arg}
cat << EOF
<html>
<head>
<title></title>
<!-- Bootstrap css themes -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
@alan-mushi
alan-mushi / easy-graphviz.py
Created December 26, 2015 12:23
Easy graphviz for a simple graph in Python 3
# Install graphviz using pip3 (on archlinux):
# $ sudo pip3 install graphviz
import graphviz as gv
g1 = gv.Graph(format="svg") # "svg" or "dot"
g1.node('A')
g1.node('B')
g1.node('C')
g1.edge('A', 'C')
g1.edge('B', 'C')
@alan-mushi
alan-mushi / installation_workaround.md
Last active December 31, 2015 21:19
My archlinux setup on Dell Vostro 3460

Environnement graphique

Driver vidéo & touchpad

Driver Intel, supprimer les autres si ils ont été ajoutés

# pacman -S xf86-video-intel xf86-input-synaptics
@alan-mushi
alan-mushi / cmd_vim.md
Last active January 28, 2016 19:09
Cheatsheet commandes vim

Commandes vim

Déplacements :

		k
	h		l
		j

w / W : début du mot suivant / "Bigword"

@alan-mushi
alan-mushi / benchmark.log
Last active February 12, 2016 12:51
Simple benchmark on functions using loggers and decorators.
__main__.function_to_benchmark|0:00:00.000172
__main__.function_to_benchmark|0:00:01.001560
__main__.function_to_benchmark|0:00:02.001992