Skip to content

Instantly share code, notes, and snippets.

James Somers jsomers

Block or report user

Report or block jsomers

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jsomers
jsomers / college-squash.ipynb
Last active Mar 20, 2019
College Squash ratings analysis
View college-squash.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jsomers
jsomers / traffic.ipynb
Created Oct 7, 2018
NYC traffic collision data
View traffic.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jsomers
jsomers / websockets.md
Created Sep 27, 2018
Using websockets to easily build GUIs for Python programs
View websockets.md

Using websockets to easily build GUIs for Python programs

I recently built a small agent-based model using Python and wanted to visualize the model in action. But as much as Python is an ideal tool for scientific computation (numpy, scipy, matplotlib), it's not as good for dynamic visualization (pygame?).

You know what's a very mature and flexible tool for drawing graphics? The DOM! For simple graphics you can use HTML and CSS; for more complicated stuff you can use Canvas, SVG, or WebGL. There are countless frameworks, libraries, and tutorials to help you draw exactly what you need. In my case, this was the animation I wanted:

high-priority

(Each row represents a "worker" in my model, and each rectangle represents a "task.")

View drive_google_doc.rb
# Dependencies: ruby-full, watir, xvfb, iceweasel, geckodriver
# Run `Xvfb :10 -ac &` before running this script
require 'watir'
NEW_DOC_URL = "https://docs.google.com/document/create"
EMAIL_ADDRESS = ENV['DOCWRITER_EMAIL']
PASSWORD = ENV['DOCWRITER_PASSWORD']
SHARE_WITH_EMAIL = ENV['DOCWRITER_SHARETO']
@jsomers
jsomers / a-wotd-custom-word-list.md
Last active Aug 26, 2019
How to use a custom word list with OS X's "Word of the Day" screensaver
View a-wotd-custom-word-list.md

OS X's "Word of the Day" screensaver is a great way to passively learn words:

But I've always thought that its word list kind of stunk—it was full of obscure words that I could never really see myself using. I'd prefer something like Norman Schur's 1000 Most Important Words. What if you could plug your own word list into the screensaver?

On a rather obscure comment thread, someone explained where you might find the word list that Apple uses to power the screensaver. It is at /System/Library/Graphics/Quartz\ Composer\ Plug-Ins/WOTD.plugin/Contents/Resources/NOAD_wotd_list.txt. The file looks like this:

m_en_us1282510	quinsy
@jsomers
jsomers / websters-chrome.md
Created Nov 10, 2014
Adding Webster's as a Chrome search engine
View websters-chrome.md

Instructions courtesy of @chancelionheart:

  1. Access the Settings menu by clicking the Options icon in the upper-right corner of the browser window. It is the icon with three horizontal lines stacked on top of each other. Click on “Settings” near the bottom of the Options menu.

  2. Under the “Search” heading in the Settings menu, click the "Manage search engines" button.

  3. At the bottom of the Search Engines window that comes up, enter the following: Name: Use whatever you like (I used "Webster's Revised 1913+1928 Dictionary") Keyword: Also whatever you like, I just use 'd' for easy access. Url: http://machaut.uchicago.edu/?resource=Webster%27s&word=%s&use1913=on&use1828=on (replaces the search term with %s, what google chrome uses for the query)

@jsomers
jsomers / android-websters.md
Last active Nov 19, 2019
Instructions for using Webster's 1913 on Android
View android-websters.md

To use Webster's 1913 dictionary on Android, install Colordict 3, an app that accepts this StarDict format. https://play.google.com/store/apps/details?id=com.socialnmobile.colordict

Next download James's S3 archive. https://s3.amazonaws.com/jsomers/dictionary.zip

You will need to extract the .dict file from inside three containers - .dz, .tar, .bz2 from innermost to outermost. 7zip handles all of these formats.

Place the .dict, .idx and .ifo files in the dictdata directory on your sdcard or local storage root. This is where colordict looks for dictionaries.

When the files are in the right place, you can run Colordict and tap the folder icon in the top right to see the dictionaries installed and set the dictionary priority. I put the 1913 dictionary above the defaults "Wordnet" and "Wikipedia." When you look up a word, ColorDict shows the definition, if available, from these multiple sources.

@jsomers
jsomers / websters-kindle.mdown
Created May 19, 2014
How to make the Webster's 1913 your default Kindle dictionary
View websters-kindle.mdown

How to make the Webster's 1913 your default Kindle dictionary

  1. Download a Kindle-compatible version of the dictionary here. Unzip the .rar archive.

  2. Get the "Send to Kindle" program on your computer. Here's the link for the Mac.

  3. Right-click your recently downloaded (unzipped) dictionary file, and click the "Send to Kindle" menu item. It will arrive on your Kindle shortly.

  4. Once the dictionary has arrived, go to your settings -- on my newish paperwhite, it's at Home > Settings > Device Options > Language and Dictionaries > Dictionaries > English. Choose the Webster's 1913.

@jsomers
jsomers / dice.py
Created Oct 11, 2013
A better method of generating Yahtzee-ish dice possibilities in Python
View dice.py
from itertools import product
def iterate_dice_simple(diceNums, diceToHold):
roles = list(product(range(1, 7), repeat=len(diceNums)))
return [r for r in roles if has_held_dice(r, diceNums, diceToHold)]
def has_held_dice(r, diceNums, diceToHold):
for i in range(len(diceToHold)):
if diceToHold[i] == 0: continue
if r[i] != diceNums[i]: return False
View menke.rb
#!/Users/jsomers/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
require 'prime'
class Menke
def initialize(numbers)
@numbers = numbers
@grid = make_grid
end
def solve!
You can’t perform that action at this time.