Skip to content

Instantly share code, notes, and snippets.

View eberle1080's full-sized avatar

Chris Eberle eberle1080

View GitHub Profile
@eberle1080
eberle1080 / PyUnicode_AsASCIIString.cpp
Created October 22, 2013 15:54
An example of how to use PyUnicode_AsASCIIString
// Assumption: you have a variable named "pyobj" which is
// a pointer to an instance of PyUnicodeObject.
PyObject* temp = PyUnicode_AsASCIIString(pyobj);
if (NULL == temp) {
// Means the string can't be converted to ASCII, the codec failed
printf("Oh noes\n");
return;
}
@eberle1080
eberle1080 / kwallet.py
Created October 21, 2011 21:05
Python KWallet sample usage (command line)
# I just wanted to find a simple way to store credentials in KWallet, and fetch it from
# a command line application. Here's how (assumes the credentials are already set):
def getCredentials():
from PyKDE4.kdeui import KWallet
from PyQt4 import QtGui
from PyQt4 import QtCore
app = QtGui.QApplication([])
wallet = KWallet.Wallet.openWallet(KWallet.Wallet.LocalWallet(), 0)
@eberle1080
eberle1080 / dirwatcher.scala
Created September 26, 2011 00:43
Recursive directory watcher in Scala
/**
* dirwatcher.scala
*
* Uses the Java 7 WatchEvent filesystem API from within Scala.
* Adapted from:
* http://download.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java
*
* @author Chris Eberle <eberle1080@gmail.com>
* @version 0.1
*/
@eberle1080
eberle1080 / dirwatcher.scala
Created September 25, 2011 22:45
Uses the Java 7 WatchEvent filesystem API from within Scala
/**
* watcher.scala
*
* Uses the Java 7 WatchEvent filesystem API from within Scala.
* Based on http://markusjais.com/file-system-events-with-java-7/
*
* @author Chris Eberle <eberle1080@gmail.com>
* @version 0.1
*/
@eberle1080
eberle1080 / leds.py
Created June 28, 2011 17:24
Schoolbus LED script
#!/usr/bin/env python
# Randomly change LED lights on schoolbus
import sys, random, time
def main():
while True:
fh = open('/dev/led', 'w')
fh.write(random.choice(('shutdown', 'fault on', 'fault off', 'ready on')) + '\n')
fh.close()
@eberle1080
eberle1080 / module_watcher.py
Created June 7, 2011 20:50
Automatically reload python module / package on file change
#!/usr/bin/env python
# Author: Chris Eberle <eberle1080@gmail.com>
# Watch for any changes in a module or package, and reload it automatically
import pyinotify
import imp
import os
class ModuleWatcher(pyinotify.ProcessEvent):
"""