-
djbouche42
I don't know if this has already been done, and no idea how useful this really is in practice, but I thought I'd give it a crack!
I wrote a real simple module for handling callbacks which allow you to decorate commands in a script as 'callback handlers' (basically, decorated Python functions taking any number of arguments), along with a URL generator for creating the callback URL to call the command in the current script or optionally in another script which also implements the callback handling.
The module is available here: https://gist.github.com/djbouche/5079561
Appreciate any feedback or suggestions!
Example (uses TweetBot module from https://gist.github.com/djbouche/5079739):
<pre>
import TweetBot
import callback
import syshandler = callback.InfoHandler(sys.argv)
@handler.cmd("process_next")
def process_next(tweets):
if len(tweets):
t = tweets.pop() #process next tweet on the list
#tweet, and send the list of remaining tweets down
TweetBot.tweet(t,callback.url('process_next',tweets=tweets))
else: #no more tweets
print 'Finished processing tweets!'if name == "main" and not handler.handle():
#first entry point
f = open("tweets.txt","r") #read tweets from a file called 'tweets.txt'
a = f.read()
f.close()
tweets = a.splitlines() #one line per tweet
tweets.reverse() #so we can pop them off
process_next(tweets) #start processing!
</pre> -
-
djbouche42
Any chance we could get a way to have an audio callback? I have no idea what the performance would be like on an iOS device, but it could be useful for playing around with real time audio synthesis :)
I'm imagining something like the below as a light wrapper around Core Audio / AudioQueue:
def audio_callback(buffer): #len(buffer) would be the number of interleaved frames
for i,v in enumerate(buffer):
buffer[i] = 0 #silence
return True # return True if this frame is not silentau = Audio.audio(audio_callback,sample_rate=44100,channels=2,format=float)
au.start() #non-blocking, of course(edit: after looking around I found this.. not sure if it is helpful to you or not: http://wiki.python.org/moin/MacPython/CoreAudio )
-
djbouche42
Would be great if we could play a specific sound file by it's path.. and also the wave module. http://docs.python.org/2/library/wave.html
-
djbouche42
I made a really quick and dirty script for grabbing files from Gist..
https://gist.github.com/djbouche/5019580
When you run it, it will prompt you to enter a Gist URL (or you can just enter the ID of the Gist). It will automatically populate the prompt with the current clipboard contents.
Very simple, no fancy error checking or anything, but thought I would share it!