Skip to content

Instantly share code, notes, and snippets.

View highfestiva's full-sized avatar

highfestiva highfestiva

View GitHub Profile
@highfestiva
highfestiva / quickcraft.py
Last active August 28, 2015 12:13
22 LoC Minecraft prototype. Written for Trabant game prototyping IDE, pixeldoctrine.com/trabant.html.
# A minimal 22 LoC Minecraft imitation for the Trabant API (pixeldoctrine.com/trabant.html).
# Note that this is made for computers and no touch controls are included.
from trabant import *
# draw all shapes filled
fg(outline=False)
# floor
for y in range(5):
import web
urls = (
'/(.*)', 'index' # Regexp matching for URI -> class
)
class index:
def GET(self, name):
return '<html><body>Hi!</body></html>'
@highfestiva
highfestiva / tcpscan.py
Last active August 29, 2015 14:00
Parallel tcp port scan
#!/usr/bin/env python3
# Scan TCP ports in a multithreaded fashion.
import multiprocessing
import re
import socket
import sys
def checkport(_):
global queue
@highfestiva
highfestiva / natural_sort.py
Created May 2, 2014 14:18
Sort input from pipe or files on command line
#!/usr/bin/env python3
import re, sys
def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
return [int(text) if text.isdigit() else text.lower()
for text in re.split(_nsre, s)]
fs = [sys.stdin] if not sys.stdin.isatty() else [open(fn) for fn in sys.argv[1:]]
for f in fs:
@highfestiva
highfestiva / example_alarm.py
Created May 12, 2014 22:40
Generator state machine home alarm snippet
def alarm_main():
print('Alarm not turned on.')
while not alarm_active():
yield # yield resumes in the next timeslice.
print('Alarm turned on, waiting for burglar.')
while alarm_active():
if alarm_sensor_detecting_something():
print('FAT BEEP! (Waiting 10 seconds to wake the neighbours up.)')
for _ in range(10): yield
print('Siren turned off. Resetting alarm.')
@highfestiva
highfestiva / fuzzy_path.py
Last active August 29, 2015 14:02
Fuzzy finding a path given a directory, say 'Deploy/31337 Application/SETTINGS.INI' would find 'deployment/application_12/settings.xml'. Now includes support for partial wildcards in a glob-like method.
#!/usr/bin/env python3
from glob import glob as doglob
import difflib
import os
def _match_ratio(s1,s2):
return difflib.SequenceMatcher(None,s1.lower(),s2.lower()).ratio()
def find(basepath, fuzzypath, thresold=0.7):
void setup() {
Serial.begin(9600);
while (!Serial)
;
pinMode(OPIN_LED_STATE, OUTPUT);
pinMode(OPIN_SIREN_ON, OUTPUT);
pinMode(IPIN_SWITCH, INPUT_PULLUP);
pinMode(IPIN_SENSOR1, INPUT);
pinMode(IPIN_SENSOR2, INPUT);
digitalWrite(OPIN_SIREN_ON, LOW);
active = device.active
inactive = lambda: not active()
while inactive():
yield
active_init_blip(device)
statewait(inactive, timeout=initiation_timeout)
if inactive():
inactive_blip(device)
return
active_running_blip(device)
@highfestiva
highfestiva / sendsms.py
Created June 19, 2014 22:06
Twilio sending SMS.
from twilio.rest import TwilioRestClient
msg = 'My message from Österbotten'
phones = ('+46-123-456789', '+35-2-23 45 67')
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
for phone in phones:
client = TwilioRestClient(account_sid, token)
client.messages.create(to=phone,
from_="+46zzzzzzzzz",
body=msg)
import Graphics.Gloss
main = animate (InWindow "Tree" (500, 650) (20, 20))
black (picture 4)
picture :: Int -> Float -> Picture
picture degree time
= Translate 0 (-300)
$ tree degree time (dim $ dim brown)
stump :: Color -> Picture
stump color
= Color color