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
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 |
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
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 |
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/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": |
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
# 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) |
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
# 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 |
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
@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) |
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
# 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() |
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
-- navigate through a path | |
function digDown() | |
while not turtle.down() do | |
turtle.digDown() | |
end | |
end | |
function digUp() | |
while not turtle.up() do |
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
-- 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 |
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
-- 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, |
OlderNewer