Skip to content

Instantly share code, notes, and snippets.

Avatar

Derek Peterson derekpeterson

  • Seattle, WA
View GitHub Profile
@derekpeterson
derekpeterson / hacker-news-contrast-fix.js
Created Nov 1, 2016
GreaseMonkey script to undo HN's contrast effects
View hacker-news-contrast-fix.js
// ==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)'));
View reading-list.md
View keybase.md

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:

View easy-json-format.js
// 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));
@derekpeterson
derekpeterson / RegexTest.java
Last active Aug 29, 2015
Comparison of Regular Expressions
View RegexTest.java
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 );
View addEventListener.polyfill.js
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 / adult.cat.finder.js
Created Aug 28, 2013
The JavaScript for Adult Cat Finder
View adult.cat.finder.js
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>";}
View vogue.raptor.easter.js
// 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 / amazon-fresh.js
Last active Dec 21, 2015
Amazon Fresh demonstrating how not to do it
View amazon-fresh.js
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
@derekpeterson
derekpeterson / gist:5358722
Last active Sep 19, 2020
A little print-ready resume template in HTML and CSS
View gist:5358722
<!DOCTYPE html>
<head>
<title>Name</title>
<style type="text/css">
html {
background: white;
color: black;
font: 14px 'Helvetica Neue', Arial, sans-serif;