Skip to content

Instantly share code, notes, and snippets.

View mbklein's full-sized avatar

Michael B. Klein mbklein

  • Northwestern University
  • Evanston, IL
View GitHub Profile
require 'httparty'
require 'open-uri'
class Oasis
include HTTParty
base_uri 'availability.library.oregonstate.edu'
headers 'accept' => 'application/json'
class << self
def availability(*ids)
select 'flag:' || lower(sc.code) || ':' || sc.name,
d.downloads, (d.downloads/t.total)*100
from (select country_code,sum(relative_value) as downloads from stats.download_country_month
where year=?
group by country_code) as d,
stats.country sc,
(select sum(relative_value::real) as total from stats.download_month
where year=?) as t
where d.country_code = sc.code
order by d.downloads desc;
kleinm-apim24:Desktop KleinM$ irb
>> require 'open-uri'
=> true
>> raw = open('https://catalog.library.jhu.edu/mods/?format=marc&bib=1144347') { |io| io.read }
=> "\nLDR:\302\24001341nam 2200301 a 450 \n005: 19971120234400.0\n008: 890316s1988 caua b 101 0 eng \n010: \302\240\302\240$a 86025055\n020: \302\240\302\240$a0520055756 (alk. paper)\n035: \302\240\302\240$a1144347\n035: \302\240\302\240$aADR9480EI\n035: \302\240\302\240$a(CStRLIN)MDJGADR9480-B\n040: \302\240\302\240$dMdBJ\n043: \302\240\302\240$aaz-----\n049: \302\24000\302\240$aJHE\n050: \302\24000\302\240$aBP63.A4$bS646 1988\n082: \302\24000\302\240$a297/.14/0954$219\n245: \302\24000\302\240$aShari\314\204\312\273at and ambiguity in South Asian Islam /$cedited by Katherine P. Ewing.\n260: \302\24000\302\240$aBerkeley :$bUniversity of California Press,$cc1988.\n300: \302\24000\302\240$axiii, 321 p. :$bill. ;$c24 cm.\n500: \302\24000\302\240$aPapers from the conference entitled \"South Asian Islam: moral principles in tension\" held at
class MyHTTP < Net::HTTP
def initialize(*args)
super(*args)
read_timeout = 120
end
end
MyHTTP.get_response(...)
require 'formula'
require 'fileutils'
SOLR_START_SCRIPT = <<-end_script
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $ solr path/to/config/dir"
else
cd %s/example && java -Dsolr.solr.home=$1 -jar start.jar
fi
require 'formula'
class ApacheAnt <Formula
url 'ftp://ftp.osuosl.org/pub/apache/ant/binaries/apache-ant-1.8.1-bin.tar.gz'
homepage 'http://ant.apache.org/'
md5 'dc9cc5ede14729f87fe0a4fe428b9185'
def install
prefix.install %w[bin lib etc docs]
end
def chucksort(z):
while not sorted(z): roundhousekick(z)
return z
function calcRoute() {
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {

I've been noticing some interesting behavior with my iPad+Bluetooth Keyboard in vBulletin's WYSISYG editor. When I have caps lock on, the B, U, and I keys create vBulletin bold, underline, and italic tags, respectively. They insert both the opening and closing tag, and leave the cursor in the middle. Holding down shift and typing the same letter obviously doesn't do the same, and the vBulletin editor doesn't respond to any Ctrl or ⌘ key combinations. I can't get the on-screen keyboard to emulate the behavior either, even with double-tap caps lock on.

That got me curious about what effect Caps Lock has on Mobile Safari's keypress events, so I did some experimenting. What I found was a rabbit's warren of browser-specific implementation discrepancies as to how keypress events are constructed by different browsers. I originally tracked all three keyboard events (keydown, keypress, keyup), but got so confused that I turned off the keydown and keyup handlers to focus on keypress.

Interesting findi

@mbklein
mbklein / sayit.rb
Created January 19, 2011 01:18
Sinatra web service for OS X to speak (via the "say" command) whatever is posted
#!/usr/bin/env ruby
require 'rubygems'
require 'haml'
require 'sinatra'
require 'rack/conneg'
use(Rack::Conneg) { |conneg|
conneg.set :accept_all_extensions, false
conneg.set :fallback, :html