Skip to content

Instantly share code, notes, and snippets.

View mondalaci's full-sized avatar

László Monda mondalaci

View GitHub Profile
@mondalaci
mondalaci / hostname-konsole-tab-ssh-wrapper.sh
Last active December 15, 2015 18:49
SSH wrapper script to make Konsole tab names always reflect the hostname of the current host
#!/bin/bash
# This script makes Konsole tab names always reflect the hostname of the current host.
#
# You're supposed to rename this script as "ssh" and put it into a
# directory that precedes /usr/bin in your $PATH, like /usr/local/bin
if [ "x$KONSOLE_DCOP_SESSION" = "x" ]; then
exec ssh $*
fi
@mondalaci
mondalaci / supervise-host.sh
Created April 11, 2013 14:40
Ping HOSTNAME and if it's down then WOL it and send a notification mail to the admin.
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: $0 HOSTNAME NOTIFICATION-SCRIPT-URL"
echo "Ping HOSTNAME and if it's down then WOL it and send a notification mail to the admin."
echo "NOTIFICATION-SCRIPT-URL?host=HOSTNAME will be fetched to send the actual mail."
echo "Example: $0 mybox http://mydomain.com/notifyme.php"
exit
fi
@mondalaci
mondalaci / detect-primary-language.php
Last active December 16, 2015 02:39
Detect primary language by HTTP Accept-Language.
<?php
$accepted_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$primary_language = $accepted_languages[0];
if ($pos=strpos($primary_language, ';') !== false) {
$primary_language = substr($primary_language, 0, $pos+1); // Throw away quality value.
}
if ($pos=strpos($primary_language, '-') !== false) {
$primary_language = substr($primary_language, 0, $pos+1); // Throw away dialect.
}
@mondalaci
mondalaci / stickfile.py
Created April 11, 2013 14:51
Automatically overwrite destination file with source file whenever the destination file gets overwritten by an external process.
#!/usr/bin/env python
import os
from sys import argv, exit
from shutil import copyfile
from pyinotify import *
def add_watch():
global watch_manager, watch_descriptor, file_to_stick
watches = watch_manager.add_watch(file_to_stick, IN_MODIFY | IN_DELETE_SELF)
@mondalaci
mondalaci / stickfile.sh
Created April 11, 2013 14:54
Automatically overwrite destination file with source file whenever the destination file gets overwritten by an external process. This script was written by Zachary Hobbs.
while true; do
inotifywait -q -q -e modify -e delete $2
cp $1 $2
done
@mondalaci
mondalaci / overclock.net-html-to-feed.php
Last active December 16, 2015 02:39
Convert the HTML of the Mechanical Keyboard Guide forum thread of OverClock.net to Atom feed.
<?php
// It's a webscraper that converts the most recent posts of the
// Mechanical Keyboard Guide forum thread of Overclock.net to RSS.
//
// This piece of code used to work but not anymore because the site has changed its
// layout but it's expected - chasing a moving target is the nature of webscraping.
//
// MySQL table schema:
// CREATE TABLE IF NOT EXISTS `mechanical_keyboard_guide` (
@mondalaci
mondalaci / fix-wordpress-comment-counter.php
Created April 11, 2013 15:23
Fix the comment counters of WordPress that are stored in MySQL.
<?php
if (!file_exists('../wp-config.php')) {
die('There doesn\'t seem to be a wp-config.php file. Double check ' .
'that you updated wp-config-sample.php with the proper database ' .
'connection information and renamed it to wp-config.php.');
}
require('../wp-config.php');
@mondalaci
mondalaci / x-that-image.py
Last active December 16, 2015 02:39
Draw a red X on top of the supplied image.
#!/usr/bin/env python
# This is a simple command line image manipulation utility that draws a red X to the image.
import sys
import gtk
if len(sys.argv) != 3:
print 'usage: x-this-image source-image destination-image'
sys.exit()
@mondalaci
mondalaci / print-pascal-procedure-and-function-names.prolog
Last active December 16, 2015 02:39
Parse and print procedure and function names of the supplied Pascal program.
% Simple Pascal parser written in Prolog that prints the names and
% line numbers of the procedures and functions found in input.pas
% I put together this mess for the programming languages course of the university in 2005.
printIden(L) :-
get_char(C),
print(C),
C == ';' ->
print(' '),
print(L),
@mondalaci
mondalaci / mono.ps
Created April 30, 2013 00:11
Mono advertisement postscript graphics that I created for the computer graphics course of the university in 2004.
% This is a Mono advertisement postscript graphics that I created
% for the computer graphics course of the university in 2004.
/draw-monkey { % fg-color bg-color scale
dup
scale
newpath
0 0 moveto
0 0.95 lineto