Skip to content

Instantly share code, notes, and snippets.

@fleinfelder
fleinfelder / gitPullAll.sh
Created July 14, 2016 09:41
git pull for all subdirectories
find . -type d -name .git -exec sh -c "cd \"{}\"/../ && pwd && git pull" \;
@fleinfelder
fleinfelder / gist:8580725
Created January 23, 2014 15:40
Killing Multithreaded Python Programs With Ctrl-C
#!/usr/bin/python
import os, sys, threading, time
class Worker(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
# A flag to notify the thread that it should finish up and exit
self.kill_received = False
@fleinfelder
fleinfelder / twistedClient.py
Created March 19, 2013 22:39
This is a simple JSON-RPC Web Client using the Twisted engine.
import json
import sys
from twisted.web.client import Agent
from twisted.web.http_headers import Headers
from twisted.web.iweb import IBodyProducer
from twisted.internet import reactor
from twisted.internet.defer import Deferred, succeed
from twisted.internet.protocol import Protocol
from zope.interface import implements
@fleinfelder
fleinfelder / twistedServer.py
Created March 19, 2013 22:35
This provides a simple Web Server with a JSON-RPC using the Twisted engine.
import json
from twisted.internet import reactor
from twisted.web import server
from twisted.web.resource import Resource
class method(Resource):
isLeaf = True
def __init__(self, version):
Resource.__init__(self)
@fleinfelder
fleinfelder / checkAirportEnabled.py
Created March 14, 2013 11:36
Check whether AirPort is enabled in Mac OS X using Python
from subprocess import Popen, PIPE
airportPath = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
def checkAirportEnabled():
arguments = [airportPath, "--getinfo"]
execute = Popen(arguments, stdout=PIPE)
out, err = execute.communicate()
if (out.strip() == "AirPort: Off"):
print "AirPort is disabled!"
@fleinfelder
fleinfelder / getAirportScan.py
Last active December 14, 2015 21:40
List all nearby available Access Points on Mac OS X using Python
from subprocess import Popen, PIPE
from plistlib import readPlist
from xml.parsers.expat import ExpatError
airportPath = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
def getAirportScan():
arguments = [airportPath, "-s", "-x"]
execute = Popen(arguments, stdout=PIPE)
try:
@fleinfelder
fleinfelder / saveAirportScanAsPList.py
Last active December 14, 2015 21:39
Save a PreferenceList (.plist) containing all nearby available Access Points on Mac OS X using Python
from subprocess import check_output
airportPath = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport'
def saveAirportScanAsPList(filename):
arguments = [airportPath, "-s", "-x"]
output = check_output(arguments)
with open(filename, 'w') as outf:
outf.write(output)