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
# 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): |
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 web | |
urls = ( | |
'/(.*)', 'index' # Regexp matching for URI -> class | |
) | |
class index: | |
def GET(self, name): | |
return '<html><body>Hi!</body></html>' |
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/env python3 | |
# Scan TCP ports in a multithreaded fashion. | |
import multiprocessing | |
import re | |
import socket | |
import sys | |
def checkport(_): | |
global queue |
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/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: |
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 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.') |
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/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): |
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
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); |
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
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) |
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
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) |
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 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 |
OlderNewer