Skip to content

Instantly share code, notes, and snippets.

View phette23's full-sized avatar
🌹
"you're right, no human being would stack books like this"

Eric Phetteplace phette23

🌹
"you're right, no human being would stack books like this"
View GitHub Profile
@phette23
phette23 / footnote-at-bottom.sublime-snippet
Created April 18, 2013 22:11
Sublime Text Snippets for Footnotes in Markdown
<snippet>
<content><![CDATA[<span id="fn$1">[$1]</span><a href="#note$1">^</a> $2
$0]]></content>
<tabTrigger>fn</tabTrigger>
<scope>text.html.markdown.multimarkdown, text.html.markdown</scope>
<description>Footnote at Bottom</description>
</snippet>
@phette23
phette23 / count-edits.js
Last active December 17, 2015 07:49
Count number of edits & bytes changed on Wikipedia user's Contributions page
(function(){
// Wikipedia ships with jQuery v1.8.3 as of 5/14/13
// will only count edits on the page
// if editor has >50 edits need to up the display limit
var numEdits = $( 'ul' ).eq( 0 ).find( 'li' ).length,
bytesChanged = 0;
$( '.mw-plusminus-pos, .mw-plusminus-neg' ).each( function ( el, index ) {
// text looks like (+###) where # of digits is variable
// e.g. (+3), (-45), (+1,479)
// so remove any commas, first 2 chars, last char, & parse as int
(function ( $ ) {
// run after document is loaded so ga.js is available
$( document ).ready( setTracking );
function setTracking () {
// class is specific to databases subject list
$( '.view-clone-of-databases-subject-list a' ).click( databaseTracking );
}
function databaseTracking ( event ) {
@phette23
phette23 / unending-rainbow.py
Created June 29, 2013 14:17
Never-ending rainbow effect in Boston Python Workshop's ColorWall project https://openhatch.org/wiki/Boston_Python_Workshop_7/Friday/OSX_project_dependencies
def RainbowTest(wall):
print "RainbowTest"
rainbowColors = [ colors["red"], colors["orange"], colors["yellow"], colors["green"], colors["baby blue"], colors["blue"], colors["purple"] ]
i = 0
for y in range( wall.height ):
color = rainbowColors[ i ]
i += 1
if i == 7:
i = 0
@phette23
phette23 / doaj.php
Last active February 9, 2023 17:32
Web Scraping Examples in a Few Languages
<?php
// need to download simple_html_dom.php from SourceForge
// http://sourceforge.net/projects/simplehtmldom/files/
// and place it in the same directory as this script
require_once( 'simple_html_dom.php' );
// http://simplehtmldom.sourceforge.net/manual_api.htm
$base = 'http://www.doaj.org/doaj?func=search&template=&uiLanguage=en&query=';
$query = urlencode( 'librarianship' );
@phette23
phette23 / update-repos.fish
Last active March 22, 2024 04:34
Shell script to run `git pull` inside all subdirectories which are git repositories. I keep a number of projects in a folder & this helps me avoid manually updating each.
#!/usr/bin/env fish
# similar script in Fish
# still under construction, need to quiet `git status` more effectively
function update -d 'Update git repo'
git stash --quiet
git pull
git stash apply --quiet
end
// stupid Node.js tricks
// accepts JS object literal of commands & their args
// executes each in series, pipes child process output to parent
// e.g. `node hellspawn.js '{"ls": "-al", "pwd": null, "echo": "Hello world!"}'`
var spawn = require('child_process').spawn
, cmds = JSON.parse(process.argv[2])
, cmd
, key
, val;
@phette23
phette23 / one-liners.js
Last active April 24, 2021 15:33
A few JavaScript One-Liners
// taken from https://medium.com/html5-css3/7c80a4b731f8
// and expanded, unreadable one-liners are kind of pointless
//pad zeroes
function pad(num) {
return ('0' + num).split('').reverse().splice(0,2).reverse().join('')
}
// get page query params
var qp = document.location.search.replace(/(^\?)/,'')
@phette23
phette23 / clip.js
Created June 18, 2014 23:55
Pipe to Clipboard in Node.js (Mac OS X only)
var clipboard = require('child_process').spawn('pbcopy')
, data = 'put whatever data here';
clipboard.stdin.write(data);
clipboard.stdin.end();
@phette23
phette23 / csv2patron-marc.py
Last active August 7, 2022 01:18
Converting CSV into Patron Records for III Millennium
#!/usr/bin/env python
# note final, more robust version at https://github.com/cca/millennium_patron_import
import sys
import csv # https://docs.python.org/2/library/csv.html
# PCODE mappings, etc.
from mapping import *
import datetime
import re