Skip to content

Instantly share code, notes, and snippets.

@micktwomey
micktwomey / export_gists_to_markdown.py
Last active March 10, 2024 20:55
Python script to export your gists (public or private) to a single Markdown file. This is useful for backing up or exporting. Doesn't preserve full revision history.
"""Noddy to dump out all your gists to Markdown
https://developer.github.com/v3/gists/
Requires the requests library.
"""
import argparse
import hashlib
@micktwomey
micktwomey / client.py
Created October 1, 2010 13:03
python multiprocessing socket server example
import socket
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 9000))
data = "some data"
sock.sendall(data)
result = sock.recv(1024)
print result
sock.close()
@micktwomey
micktwomey / mttpstats.py
Created October 2, 2010 14:32
redis profiling
"""Class for printing reports on profiled python code."""
# Modified by mtt to support loading of stats without creating file objects
# Class for printing reports on profiled python code. rev 1.0 4/1/94
#
# Based on prior profile module by Sjoerd Mullender...
# which was hacked somewhat by: Guido van Rossum
#
# see profile.doc and profile.py for more info.
@micktwomey
micktwomey / Makefile
Last active June 25, 2018 17:32
Overcomplicated Raspberry Pi + Sense Hat + Firehose + Lambda + Hosted Graphite Thermometer
ZIPFILE=lambda_process_s3_records.zip
SOURCES=iso8601.py lambda_process_s3_record.py
all: $(ZIPFILE)
$(ZIPFILE): $(SOURCES)
rm -f $@
zip $@ $^
.PHONY: upload
@micktwomey
micktwomey / HelloWorld.elm
Created October 20, 2016 22:45
ELMO-8 HelloWorld.elm
{-| PICO-8's Hello.lua redone in ELMO-8
-}
import Elmo8.Console as Console
type alias Model = {
t : Int
}
@micktwomey
micktwomey / Hello.elm
Last active October 19, 2016 23:23
ELMO-8 Hello World.
import Elmo8.Console as Console
import Elmo8.Palettes.Pico8 as Palette
type alias Model = {}
draw : Console.Console Model -> Model -> List Console.Command
draw console model =
[ Console.sprite 2 60 30
]
@micktwomey
micktwomey / Main.elm
Last active May 17, 2016 10:04
Reproduces TypeError seen in Elm 0.17
{- Simple wrapper to WebSocketExample -}
module Main exposing (..)
import Html exposing (..)
import Html.App as App
import WebSocketExample
@micktwomey
micktwomey / redis.conf.diff
Created October 25, 2012 15:46
Difference between default redis 2.4 and 2.6 configs
--- /dev/fd/63 2012-10-25 16:46:38.000000000 +0100
+++ /dev/fd/62 2012-10-25 16:46:38.000000000 +0100
@@ -1,6 +1,6 @@
# Redis configuration file example
-# Note on units: when memory size is needed, it is possible to specifiy
+# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
@micktwomey
micktwomey / utf8bmp.py
Created October 16, 2012 11:01
WSGI middleware to replace non-BMP characters in JSON with unknown character. Works around poor UTF-8 support in certain dbs.
"""WSGI middleware and test code to munge utf-8
To work around narrow builds you need to do this:
re.sub(r'\\U[0-9a-f]{8}', '\\ufffd', s.encode("unicode_escape")).decode("unicode_escape")
(Use the representation)
"""
@micktwomey
micktwomey / forgive.py
Created August 9, 2012 11:22
Better to ask for forgiveness...
import contextlib
import functools
@contextlib.contextmanager
def forgiveness(exceptions):
"""Seek forgiveness
"""
try:
yield