Skip to content

Instantly share code, notes, and snippets.

View davidfraser's full-sized avatar

David Fraser davidfraser

View GitHub Profile
@davidfraser
davidfraser / reduce_mbsync_journal.py
Last active May 29, 2017 19:58
A simple script to remove superfluous entries from a mbsync internal .journal file
#!/usr/bin/env python
"""This is a script for internal use when doing large mail migrations with mbsync
See http://isync.sourceforge.net/mbsync.html for more information on the product
If IMAP disconnects occur on a large mailbox, the internal .journal file that tracks progress
can grow very large in size, though much of the information is not needed
This script can be used to reduce the file in size
NB: This should be used with caution, and never while mbsync is running
It does not replace the file, but can be used to produce a new journal file,
@davidfraser
davidfraser / hang_coloredlogs.py
Last active May 18, 2017 14:27
Demonstration of hang when coloredlogs in one thread and import in other thread does logging
#!/usr/bin/env python
import logging
import time
import threading
import coloredlogs
# configured notices that will be displayed with styling by coloredlogs
NOTICE = 25
logging.addLevelName(25, 'notice')
@davidfraser
davidfraser / fix-touchpad-bottom-edge.sh
Last active December 1, 2016 21:21
For Linux/X11 systems, adjusting setting on Lenovo Y50 (and possibly others) so that the button area of the touchpad is kept from also being regarded as a mouse movement area, preventing awkward dragging when trying to click.
#!/bin/bash
boundary="`synclient -l | grep RightButtonAreaTop | sed 's/RightButtonAreaTop//' | sed 's/[ =]//g'`"
echo Setting boundary to "$boundary"
synclient AreaBottomEdge="$boundary"
@davidfraser
davidfraser / uninstall-evernote-cleanup
Created December 29, 2014 09:26
Script to cleanup an Evernote installation under Wine, in order to allow reinstallation - see http://www.sgvulcan.com/evernote-under-wine-already-installed-by-another-user/
#!/bin/bash
echo first uninstall evernote using the wine uninstaller
wine uninstaller
echo now searching forregistry entry to remove
cd ~/.wine/drive_c/windows/profiles/$USER/temp
upgrade_code="`grep 'with upgrade code' EvernoteSetup.log | tail -n 1 | sed 's/^.*with upgrade code {\([A-Fa-f0-9-]*\).*$/\1/'`"
reverse_upgrade_code="`python -c "x='${upgrade_code}' ; y = x[:18].split('-') ; x = x.replace('-', '') ; z = [a+b for a, b in zip(x[16::2], x[17::2])] ; print ''.join(''.join(reversed(part)) for part in y+z).upper()"`"
echo please use regedit to navigate to '\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes\' and remove the key "$reverse_upgrade_code"
wine regedit
@davidfraser
davidfraser / android_gnucash_account_link.py
Last active December 26, 2015 04:49
This is a script that will create online_id links for each account in a gnucash file, that correspond to the account ids generated by GnuCash for Android (https://github.com/codinguser/gnucash-android). It will alter the file in-place. After this, imports of OFX files exported by GnuCash for Android should automatically match accounts correctly.…
@davidfraser
davidfraser / scientific-training-in-undergrad-compsci.rst
Created October 11, 2013 15:35
A rationale for teaching source control and testing practice in undergraduate Computer Science

Scientific Training in Undergraduate Computer Science

Background

This document was formed out of the consensus of leaders in software development companies in Cape Town, and proposes some changes to the undergraduate Computer Science curriculum, in order to improve the level of understanding and effectiveness of students, both in order to increase their relevant skills on graduation,

@davidfraser
davidfraser / merge_firefox_history.py
Created June 10, 2013 15:53
This is a (slightly-cleaned-up) script that I used to restore Firefox history when I'd lost it. Basically give it original.sqlite (the original places database you want to modify), backup.sqlite (an old backup with history that needs to be merged into the original database), and it should generate updated.sqlite which will contain the combinatio…
#!/usr/bin/env python
import sqlite3
import logging
import shutil
# copy
shutil.copy2("original.sqlite", "updated.sqlite")
original = sqlite3.connect("original.sqlite")
backup = sqlite3.connect("backup.sqlite")
@davidfraser
davidfraser / OfficeCleaner.py
Created March 19, 2013 08:24
Clean up XHTML by removing extraneous things - in particular those generated by copying and pasting out of Microsoft Office products
import cssutils
from xml.sax import saxutils
from lxml.html import tostring, fromstring, clean
from lxml import etree
import logging
class Cleaner(clean.Cleaner):
def clean_html(self, html):
if not isinstance(html, unicode):
#!/bin/bash
target_displays="$1"
VGA=VGA-0
LVDS=LVDS-0
if [[ "$target_displays" == "auto" || "$target_displays" == "" ]]
then
xrandr_output="`xrandr -q`"
vga_connected=`echo "$xrandr_output" | grep "^$VGA " | cut -d' ' -f2`
@davidfraser
davidfraser / raw_mismatches.py
Created September 15, 2012 06:31
Code to explore android sms corruption by comparing raw and sms tables in mmssms.db
#!/usr/bin/env python
import sqlite3
import pprint
import datetime
import time
# install from https://github.com/pmarti/python-messaging/tarball/master - built against 0.5.12
from messaging import sms
import pprint