Skip to content

Instantly share code, notes, and snippets.

View benjamingeiger's full-sized avatar

Benjamin Geiger benjamingeiger

View GitHub Profile
@benjamingeiger
benjamingeiger / cpu.py
Created December 23, 2015 05:27
Day 23 Solution
#!/usr/bin/python
#
# Copyright (c) 2015 Benjamin Geiger <github@bgeiger.net>
"""
Module-specific doc string.
"""
from __future__ import absolute_import
from __future__ import division
@benjamingeiger
benjamingeiger / skel.py
Created July 24, 2015 19:32
Python skeleton file.
#!/usr/bin/python
#
# Copyright (c) 2015 Benjamin Geiger <email.redacted>
"""
Module-specific doc string.
"""
from __future__ import absolute_import
from __future__ import division
@benjamingeiger
benjamingeiger / cherylsbirthday.py
Last active August 29, 2015 14:19
Solution to the "Cheryl's Birthday" problem in Python.
#!/usr/bin/python
#
# Copyright (c) 2015 Benjamin Geiger <begeiger@mail.usf.edu>
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function
from collections import defaultdict
def max(seq, key=lambda x: x):
return reduce(lambda x, y: y if key(y) > key(x) else x, seq[1:], seq[0])
@benjamingeiger
benjamingeiger / gist:11340007
Created April 27, 2014 07:53
Python subprocess emulating a filter.
infile = open(inputfilename, "r")
outfile = open(outputfilename, "w")
filter1 = subprocess.Popen(commandline1, stdin=infile, stdout=subprocess.PIPE, stderr=None)
filter2 = subprocess.Popen(commandline2, stdin=filter1.stdout, stdout=outfile, stderr=None)
filter1.stdout.close() # required so filter2 can get SIGPIPE, apparently
filter1.wait()
filter2.wait()
@benjamingeiger
benjamingeiger / Intervalometer.ino
Created August 26, 2013 01:42
Intervalometer code that started breaking.
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#include <EEPROM.h>
/*
** Hardware configuration.
*/
@benjamingeiger
benjamingeiger / gist:6082446
Created July 25, 2013 18:31
Aliasing bug in Python.
foo = [[0] * 10] * 10
print(foo)
foo[3][5] = 1
print(foo)
@benjamingeiger
benjamingeiger / gist:6081268
Created July 25, 2013 16:10
Are lists passed by reference?
In [1]: foo = [1, 2, 3, 4, 5]
In [2]: def bar(lst):
...: lst.append(6)
...:
In [3]: bar(foo)
In [4]: foo
Out[4]: [1, 2, 3, 4, 5, 6]
import re
# Get a list of all stories. (This will have to be written at some point.)
stories = get_stories()
for story in stories:
summary = story.get_summary()
body = story.get_body()
if (not summary) or len(summary.trim()) == 0:
[bgeiger@Maximus][~]$ ls -l /Library/Internet\ Plug-Ins/
total 12
drwxrwxr-x 3 root wheel 102 Oct 31 09:08 AdobeExManDetect.plugin
lrwxr-xr-x 1 root wheel 91 Oct 17 09:56 AmazonMP3DownloaderPlugin1017287.plugin -> /Applications/Amazon MP3 Downloader.app/Contents/Resources/AmazonMP3DownloaderPlugin.plugin
drwxrwxr-x 3 root wheel 102 Jan 9 15:10 Flash Player.plugin
drwxr-xr-x 3 root wheel 102 Aug 24 17:33 Flip4Mac WMV Plugin.plugin
lrwxr-xr-x 1 root wheel 86 Jan 9 17:03 JavaAppletPlugin.plugin -> /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin
drwxr-xr-x 3 root wheel 102 Jun 20 2012 Quartz Composer.webplugin
drwxr-xr-x 3 root wheel 102 Jun 20 2012 QuickTime Plugin.plugin
drwxrwxr-x 3 root wheel 102 Apr 2 2012 SharePointBrowserPlugin.plugin