Skip to content

Instantly share code, notes, and snippets.

@johanlaidlaw
johanlaidlaw / log_to_csv.py
Created September 20, 2012 20:04
Log file to CSV file
# It turns a very specific logfile :) into a csv file
# Take all events within a minute and calcute avg and max
# Returns csv file with same name as argument log file
import sys
popper_file = sys.argv[1]
output_file = popper_file[:-3]+"csv"
fi = open(popper_file,"r")
fo = open(output_file, "w+b")
@johanlaidlaw
johanlaidlaw / plotter.py
Created September 20, 2012 19:56
Plot graph from csv file
# python plotter.py test.csv => will produce test.png
# Give it a csv file as argument and it will produce a png image with the same name as the csv file
# It expects the CSV file to be of format '2012-09-20 20:32,1.3,2.1'
# NOTE: This code will show the graph so you need a gui builder. It will fail on a server
# TO make it run on a server use 'Agg'
# import matplotlib
# matplotlib.use('Agg')
# and don't use the show() method
@johanlaidlaw
johanlaidlaw / linux_commands
Created September 19, 2012 19:39
Useful linux commands that I never can remember
#Create ssh keys
ssh-keygen -t rsa -C "[email protected]" -f id_rsa.MyService
#Empty a file (owned by you)
> file.log
#Empty a file owned by root
#Copy a file from server over ssh
@johanlaidlaw
johanlaidlaw / gist:1596626
Created January 11, 2012 20:35
Scraper for transfermarkt
<?php
include_once('../simple_html_dom.php');
function scraping($url) {
// create HTML DOM
$html = file_get_html($url);
// Find the table that has class="tabelle_spieler" in the source code
// There are two of these tables and we want the second one therefor 1 (index start by 0)