Skip to content

Instantly share code, notes, and snippets.

@meeuw
meeuw / print_container.py
Created June 5, 2013 14:50
list files in cloudfiles container
import cloudfiles
import sys
conn = cloudfiles.get_connection(
'username',
'apikey',
authurl=cloudfiles.uk_authurl
)
container = conn.get_container(sys.argv[1])
marker = None
limit = 5000
@meeuw
meeuw / rmfrom_container.py
Created June 5, 2013 14:51
remove files from cloudfiles container
import cloudfiles
import sys
conn = cloudfiles.get_connection(
'username',
'apikey',
authurl=cloudfiles.uk_authurl
)
container = conn.create_container(sys.argv[1])
for obj in sys.argv[2:]:
print 'delete_object', obj
@meeuw
meeuw / removesorted.py
Created June 5, 2013 14:53
called like: python removesorted.py haystack needles, only works on sorted files, remove needles from haystack.
import sys
haystack = open(sys.argv[1])
needles = open(sys.argv[2])
needle = needles.readline()[:-1]
counter = 0
while 1:
hay = haystack.readline()[:-1]
if not hay: break
if hay == needle:
needle = needles.readline()[:-1]
@meeuw
meeuw / adhoc.py
Last active September 13, 2018 20:30
Python script to create, using dbus, an adhoc wifi connection
import dbus
bus = dbus.SystemBus()
wpas_obj = bus.get_object("fi.w1.wpa_supplicant1",
"/fi/w1/wpa_supplicant1")
wpas = dbus.Interface(wpas_obj, "fi.w1.wpa_supplicant1")
path = wpas.CreateInterface({'Ifname':"wlan0"})
if_obj = bus.get_object("fi.w1.wpa_supplicant1", path)
path = if_obj.AddNetwork({
<?php
// create table error_log(lastseen varchar(50), message text, count integer, unique (message), unique (lastseen,message));
$month_translation = array("Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12);
$error_log_format = "/\[(?<weekday>Mon|Tue|Wed|Thu|Fri|Sat|Sun) ".
"(?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ".
"(?<monthday>\d\d) ".
"(?<hour>\d\d):".
"(?<minutes>\d\d):".
"(?<seconds>\d\d).".
"(?<milliseconds>\d+) ".
@meeuw
meeuw / rpmdb2dot
Last active December 19, 2015 03:38
List and resolve local rpm database to an almost graphviz dot file format
rpm -qa --queryformat '%{NAME} [--whatprovides %{REQUIRES} ]\n'|while read NAME REQUIRES ; do rpm -q --queryformat '%{NAME}\n' $REQUIRES|grep -v 'no package provides'|sed "s/\(.*\)/\"$NAME\" -> \"\1\"/" ; done|sort -u > /tmp/deps.dot
@meeuw
meeuw / icalexport.py
Created July 17, 2013 06:07
Python script to export CSV from Google calendar
from icalendar import Calendar
from icalendar.cal import Event
import datetime
import urllib2
import csv
import sys
for url, label in (
(
urllib2.urlopen('https://www.google.com/calendar/ical/11111111111111111111111111%40group.calendar.google.com/private-11111111111111111111111111111111/basic.ics'),
@meeuw
meeuw / sudouser.sh
Created November 12, 2013 08:57
sudo to a certain user and show export / xauth commands to use your X session as the specified user
#!/bin/bash
echo export DISPLAY=$DISPLAY
echo export XAUTHORITY=$(grep ^$1: /etc/passwd|cut -d: -f6|head -n1)/.Xauthority
echo xauth add $(xauth list|grep ^$(uname -n))
sudo -i -u ${1}
@meeuw
meeuw / dnsmasq.sh
Created November 28, 2013 19:48 — forked from anonymous/dnsmasq.sh
Hookscript for dhclient (place in /etc/dhcp/dhclient.d) to configure dnsmasq (using dbus) with the supplied nameserver. Add enable-dbus to dnsmasq
#!/bin/bash
function inet_aton () {
local count=3
local int=0
for num in $(echo $1 | sed -e 's/\./ /g'); do
let "int+=$num*256**$count"
let "count-=1"
done
echo $int
}
@meeuw
meeuw / depclean.sh
Created December 17, 2013 14:59
Use this script to find all "leaves" you've installed on your yum/rpm system. Add these "leaves" to PACKAGES="" and remove what you aren't using anymore. Then re-run the script until all unwanted packages are removed.
#!/bin/bash
PACKAGES=""
LEAVES="$(package-cleanup --leaves --all --qf='%{NAME}')"
ERASE=$(grep -vxf <(echo "$PACKAGES") <(echo "$LEAVES"))
if [ "$ERASE" ]; then
yum erase $ERASE
else
diff -udr <(echo "$LEAVES") <(echo "$PACKAGES")
fi