Skip to content

Instantly share code, notes, and snippets.

@jsomers
jsomers / menke.rb
Last active December 11, 2015 00:59
Solves the path-of-primes puzzle at http://www.sporcle.com/games/smenks13/path-of-primes.
#!/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!
@jsomers
jsomers / dice.py
Created October 11, 2013 03:11
A better method of generating Yahtzee-ish dice possibilities in Python
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
@jsomers
jsomers / pe-215.rb
Created July 13, 2011 22:17
Solution to Project Euler problem #215
=begin
Most of the work here is in generating a sort of matrix of mutually
compatible "p-bricksets," or single-row arrangements of bricks. There are
something like 3,300 of these total.
Once you have that matrix - what in the code I call the "compatimap" - all you
do is exhaustively "expand" each p-brickset ten times (for the ten rows).
It helps to imagine the space of possible walls as a tree in which nodes are
@jsomers
jsomers / drive_google_doc.rb
Last active October 17, 2017 23:22
DocWriter code
# 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 / traffic.ipynb
Created October 7, 2018 15:18
NYC traffic collision data
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jsomers
jsomers / college-squash.ipynb
Last active March 20, 2019 13:43
College Squash ratings analysis
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jsomers
jsomers / websters-chrome.md
Created November 10, 2014 14:20
Adding Webster's as a Chrome search engine

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 / websockets.md
Created September 27, 2018 12:50
Using websockets to easily build GUIs for Python programs

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.")

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

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.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.