This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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): | |
""" |