Skip to content

Instantly share code, notes, and snippets.

View wolfgangmeyers's full-sized avatar

Wolfgang Meyers wolfgangmeyers

  • AiBrush
  • Washington State, USA
View GitHub Profile
@wolfgangmeyers
wolfgangmeyers / prime sieve
Created August 23, 2013 01:46
prime sieve
import random
sieve_scan_top = 0
sieve = {}
def generate_sieve(top):
global sieve_scan_top
global sieve
if top > sieve_scan_top:
sieve_scan_top = top
@wolfgangmeyers
wolfgangmeyers / gist:e53bd796041fcd48ad3c
Last active August 29, 2015 14:10
python generic segmentation function to break items into sub-groups based on max size
def segment_items(items, max_count_per_segment):
result = []
index = 0
while index < len(items):
segment = []
segment_index = 0
while segment_index < max_count_per_segment and index < len(items):
item = items[index]
segment.append(item)
segment_index += 1
@wolfgangmeyers
wolfgangmeyers / gist:219d176493442581764f
Created December 29, 2014 23:03
Use python to make sure that iTunes is never, ever allowed to run.
#!/usr/bin/python
import psutil
import time
times = 0
while True:
time.sleep(1)
lst = psutil.get_process_list()
for p in lst:
if p.name == "iTunes":
@wolfgangmeyers
wolfgangmeyers / gist:7441fa146030f6929dd0
Last active July 15, 2018 01:11
Run an ansible playbook from the python api
# borrowed from https://groups.google.com/forum/#!topic/ansible-project/V1PoNJcXV_w
import ansible.runner
import ansible.playbook
from ansible import callbacks
from ansible import utils
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
@wolfgangmeyers
wolfgangmeyers / gist:7a113d313371db6e07b9
Last active August 29, 2015 14:15
Format json data on the command line
# pipe any json into the command to the right of the pipe to format any valid json payload
echo '{"foo": "bar"}' | python -c "import sys, json;print json.dumps(json.loads(sys.stdin.read()), indent=4)"
# use the built-in tool to do the exact same thing
echo '{"foo": "bar"}' | python -m json.tool
@wolfgangmeyers
wolfgangmeyers / gist:c641c97e91cb4690cb25
Last active August 29, 2015 14:16
Processing a really long list of things in the background using celery
@celery.task
def process_list_of_things(things):
try:
for i in range(min(20, len(things))):
thing = things.pop()
process_thing(thing)
except SoftTimeLimitExceeded:
things.append(thing)
if things:
process_list_of_things.delay(things)
@wolfgangmeyers
wolfgangmeyers / download
Last active August 29, 2015 14:17
Download script for computercraft
# lua script to download files
args = {...}
url = args[1]
outfile = args[2]
resp, err = http.get(url)
f = io.open(outfile, "w")
f:write(resp.readAll())
f:close()
resp.close()
@wolfgangmeyers
wolfgangmeyers / path
Last active August 29, 2015 14:17
Computercraft turtle script for carving out paths
-- navigate through a path
function digDown()
while not turtle.down() do
turtle.digDown()
end
end
function digUp()
while not turtle.up() do
@wolfgangmeyers
wolfgangmeyers / inventory
Last active August 29, 2015 14:17
Computercraft script for managing turtle inventory
-- gets a list of all items in a turtle's inventory
function listItems()
local result = {}
for i=1,16 do
local item = turtle.getItemDetail(i)
if item then
local itemName = item["name"]
local itemCount = turtle.getItemCount(i)
result[i] = itemCount .. " " .. itemName
end
@wolfgangmeyers
wolfgangmeyers / remote
Last active August 29, 2015 14:17
Computercraft turtle remote control script
-- remote listener
os.loadAPI("inventory")
os.loadAPI("path")
running = true
-- this should be configurable somehow
modem = peripheral.wrap("right")
modem.open(0)
while running do
local event, modemSide, senderChannel,