Skip to content

Instantly share code, notes, and snippets.

View judy2k's full-sized avatar

Mark Smith judy2k

View GitHub Profile
#!/usr/bin/env python
#
# Copyright 2009 Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
anonymous
anonymous / gist:4433900
Created January 2, 2013 11:17
A function returning the first matched item in a sequence, or None.
def first_match(seq, pred=None, default=None):
"""
Obtain the first item in `seq` where `pred` returns True, otherwise return
`default`.
If no `pred` is supplied, then the first value in seq will be returned. If
no `default` is supplied and no matching value is found in `seq`, then
`None` will be returned instead.
:param seq: A sequence or iterable to obtain an item from.
@pandemicsyn
pandemicsyn / something.sh
Last active December 21, 2015 13:28
Reverse all the prompts!
in a file called ~/.reverseit.py:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from sys import stdin, stdout
pchars = u"abcdefghijklmnopqrstuvwxyz,.?!'()[]{}"
fchars = u"ɐqɔpǝɟƃɥıɾʞlɯuodbɹsʇnʌʍxʎz'˙¿¡,)(][}{"
flipper = dict(zip(pchars, fchars))
@judy2k
judy2k / unicode.md
Last active December 31, 2015 02:09
These are some notes for a potential short talk on Python & Unicode.

Python & Unicode

text = open('a_unicode_file.txt', 'r').read()
print text
print 'type:', type(text)       # str is a container for binary data
print 'bytes:', len(text)       # The number of bytes, not characters!
print ' '.join(repr(b) for b in text)
print 'first byte:', text[:1] # Prints an invalid character!
@vampjaz
vampjaz / jasper-setup.sh
Created April 13, 2014 14:50
Automatic setup and install of Jasper (http://jasperproject.github.io/)
#!/bin/bash
# Jasper install script (http://jasperproject.github.io/)
# Must be run as root (i.e. sudo setup.sh)
apt-get update
apt-get upgrade --yes
apt-get install vim git-core espeak python-dev python-pip bison libasound2-dev libportaudio-dev python-pyaudio subversion autoconf libtool automake gfortran --yes
sed "s/options snd-usb-audio index=-2/options snd-usb-audio index=0" /etc/modprobe.d/alsa-base.conf>/etc/modprobe.d/alsa-base.conf
void backlight_effect_solid_reactive(void)
{
// Relies on hue being 8-bit and wrapping
for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
{
uint16_t offset2 = g_key_hit[i]<<2;
// stabilizer LEDs use spacebar hits
if ( i == 42 || // LC6, LD13