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 / 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: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,
@wolfgangmeyers
wolfgangmeyers / client
Last active August 29, 2015 14:17
Computercraft script - client to control turtle
running = true
modem = peripheral.wrap("back")
modem.open(1)
while true do
io.write(">")
command = io.read()
modem.transmit(0, 1, command)
local event, modemSide, senderChannel,
@wolfgangmeyers
wolfgangmeyers / minetest.lua
Created April 2, 2015 03:36
test strip mine script
-- test strip mine script
os.loadAPI("path")
local DEFAULT_HEIGHT = 5
function isOverBedrock()
if turtle.detectDown() then
local itemName = turtle.inspectDown()
local i = string.find(itemName, ":")
itemName = string.sub(itemName, i + 1, string.len(itemName))