Skip to content

Instantly share code, notes, and snippets.

View derekpeterson's full-sized avatar

Derek Peterson derekpeterson

  • Seattle, WA
View GitHub Profile
if ( 'function' !== typeof window.addEventListener ) {
(function ( win, doc ) {
function docHijack( p ) {
var old = doc[p];
doc[ p ] = function ( v ) {
return addListen( old( v ) );
};
}
@derekpeterson
derekpeterson / RegexTest.java
Last active August 29, 2015 14:10
Comparison of Regular Expressions
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Pattern STATE_REGEX = Pattern.compile( "\\b(?<stateCode>[a-zA-Z]{2})$" );
Matcher matcher = STATE_REGEX.matcher( input );
List<ZipCode> zipCodeList = new ArrayList<>();
if ( matcher.find() ) {
String city = input.substring( 0, matcher.start() - 1 );
@derekpeterson
derekpeterson / CityReviews.py
Last active December 14, 2015 04:49
Simple MRjob script to count words from a TSV with data in the form "category\t[item1,item2,item3]".
#!/usr/bin/env python
from mrjob.job import MRJob
import json
import re
class CityReviews(MRJob):
def mapper(self, _, line):
line = re.sub(r'\[|\]| ', '', line)
@derekpeterson
derekpeterson / amazon-fresh.js
Last active December 21, 2015 14:48
Amazon Fresh demonstrating how not to do it
function updateAddAllToCartButton(event) {
var validList = "";
var invalidList = "";
jQuery(".listItem").each(function(index) {
var item = jQuery(this);
var conflictInput = item.find("input[name='conflictWithSlot']");
if (item.find(".itemUnavailableText").size() > 0 || item.find(".discontinued").size() > 0) {
// Ignore unavailable and discontinued items
} else if (conflictInput.size() == 0 || conflictInput.val() == "false") { // skip invalid items
// konami code - up up down down left right left right b a
var code1 = String.fromCharCode(38, 38, 40, 40, 37, 39, 37, 39, 66, 65);
var code2 = String.fromCharCode(38, 38, 40, 40, 37, 39, 37, 39, 65, 66);
var codeBuffer = "";
$(document).keyup(function (e) {
codeBuffer += String.fromCharCode(e.which);
if (code1.substring(0, codeBuffer.length) == codeBuffer) {
if (code1.length == codeBuffer.length) {
toggle1();
codeBuffer = String.fromCharCode(38, 38, 40, 40, 37, 39, 37, 39, 66);
@derekpeterson
derekpeterson / adult.cat.finder.js
Created August 28, 2013 23:11
The JavaScript for Adult Cat Finder
var i=0;
var dataRef = new Firebase("https://adultcatfinder.firebaseio.com/rooms");
var myRoomRef = dataRef.push();
window.setInterval(function(){
var chat=document.getElementById("chat");
if (i==0){chat.innerHTML +="<p style='color:blue'>Local Cat: meow meow <i>meow</i>?</p>";}
else if (i==1){chat.innerHTML +="<p style='color:blue'>Local Cat: moew meow meow meow!!</p>";}
// Save the raw JSON paste to file.json
// Then start up a Node REPL and do this
var data = require('./file.json');
var fs = require('fs');
fs.writeFileSync('./formatted-file.json', JSON.stringify(data, null, 2));

Keybase proof

I hereby claim:

  • I am derekpeterson on github.
  • I am okayderek (https://keybase.io/okayderek) on keybase.
  • I have a public key ASA7RUlnv10juehdIw0hFJBCJypjTmlHDPhHbmghXpYhZgo

To claim this, I am signing this object:

@derekpeterson
derekpeterson / hacker-news-contrast-fix.js
Created November 1, 2016 21:04
GreaseMonkey script to undo HN's contrast effects
// ==UserScript==
// @name HN font-color
// @namespace hackerNewsFix
// @include https://news.ycombinator.com
// @include https://news.ycombinator.com/*
// @version 1
// @grant none
// ==/UserScript==
var comments = Array.from(document.querySelectorAll('span[class^=c]:not(.comhead)'));