Skip to content

Instantly share code, notes, and snippets.

View singpolyma's full-sized avatar

Stephen Paul Weber singpolyma

View GitHub Profile
/* Expanded form of a bookmarklet for extracting rev=canonical OR tinyurling a page */
(function(){
var url=document.location;
var links=document.getElementsByTagName('link');
var found=0;
for(var i = 0, l; l = links[i]; i++) {
if (l.getAttribute('rev') == 'canonical' || (/alternate short/).exec(l.getAttribute('rel'))) {
found=l.getAttribute('href');
break;
}
#!/bin/sh
# Implementation of http://tantek.pbworks.com/NewBase60
# License: http://creativecommons.org/licenses/by-sa/3.0/
n="$1"
s=''
m='0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz'
if [ -z "$n" ] || [ "$n" -eq "0" ]; then
echo 0
@singpolyma
singpolyma / epub2html.rb
Created December 6, 2010 21:37
Convert ePub files to XHTML
#!/usr/bin/ruby
# Usage ./epub2html.rb thing.epub thing.html
#
# ePub files are just XHTML with a ton of (often useless) stuff layered on top
# This script extracts the XHTML content and sticks it together
# It tries to preserve common metadata
# It tries to preserve images
# It converts Google Books' crap .gtxt_heading to <h1>
@singpolyma
singpolyma / Gemfile
Last active April 8, 2020 00:37
Add cell numbers from a set of vcards to your XMPP roster (through Cheogram)
source "https://rubygems.org"
gem "blather"
gem "vcard"
@singpolyma
singpolyma / Cache.hs
Created July 18, 2013 14:34
Simple in-process key/value cache for Haskell
-- | Simple in-process key/value cache
--
-- Of course, for really simple stuff you could probably use unsafeInterleaveIO
module Cache (Cache, newCache, fromCache) where
import Control.Monad (void)
-- Could also use STM instead
import Control.Concurrent (forkIO, Chan, newChan, readChan, writeChan, MVar, newEmptyMVar, putMVar, takeMVar)
diff -r 7a3ac037e57f mod_onions/mod_onions.lua
--- a/mod_onions/mod_onions.lua Fri Jun 08 21:59:42 2018 +0200
+++ b/mod_onions/mod_onions.lua Mon Dec 03 01:28:59 2018 +0000
@@ -148,12 +148,16 @@
end
function socks5listener.onconnect(conn)
+ if not sessions[conn].socks5_handler == socks5_handshake_sent then
+
module:log("debug", "Connected to SOCKS5 proxy, sending SOCKS5 handshake.");
@singpolyma
singpolyma / enc.sh
Created December 14, 2011 04:23
Convert WAV and TOC to FLAC
#!/bin/sh
# Copyright 2011, Stephen Paul Weber <singpolyma.net>
# You may use this code under the terms of an ISC License
# This script assumes a cdrdao TOC file with CD-TEXT in it named cd.toc
# It also assumes the front cover art is called cover.jpg
# It assumes track{TRACKNUMBER}.cdda.wav files (as generated by cdparanoia)
# The WAV files are encoded to FLAC with the TITLE, ARTIST, ALBUM, TRACKNUMBER, and ISRC set
# based on the CD-TEXT and ISRCs found on disc, and with front cover art set.
@singpolyma
singpolyma / prompt.sh
Created November 14, 2008 16:47
Awesome git prompt
# Determine if the current directory is a GIT repo
# and print out '*' if there are changes to be committed
iz_git_dirty() {
#IZ_GIT=`git status 2>/dev/null`
IZ_DIRTY=`git status 2>/dev/null | grep 'nothing to commit (working directory clean)'`
#if [ "." != "$IZ_GIT." ]; then
if [ "." == "$IZ_DIRTY." ]; then
echo '*'
fi
@singpolyma
singpolyma / CollectLeft.hs
Created September 8, 2012 21:50
Alternative Applicative instance for Either that collects multiple Left values
import Data.Monoid
import Control.Applicative
newtype CollectLeft es a = CollectLeft (Either es a)
deriving (Show, Eq)
-- Alternative applicative instance for Either with a Monoid on the Left
-- If everything is Right, then it acts like the normal instance
-- Instead of resulting in the first Left, the values inside all Left are
-- concatenated (any Monoid)
@singpolyma
singpolyma / gist:1002978
Created June 1, 2011 18:43
Convert ISBN10 to ISBN13
def isbn10_to_isbn13(isbn10)
i = 30
s = '978' + isbn10.to_s[0..8]
4.step(12, 2) do |j|
i += s[j-2, 1].to_i + (3 * s[j-1, 1].to_i)
end
s + ((10 - (i % 10)) % 10).to_s
end