Skip to content

Instantly share code, notes, and snippets.

View mavc's full-sized avatar

maverick mavc

  • Vancouver, BC
View GitHub Profile
@mavc
mavc / pdict.py
Created October 10, 2011 23:30
Priority Queue
'''
Created on 2011-10-09
Modified Python Recipe: http://code.activestate.com/recipes/522995/
@author: mavc
'''
from heapq import heapify, heappop, heappush
__all__ = ['PriorityDict']
@mavc
mavc / boyermoore.py
Created November 1, 2011 03:32
Boyer-Moore string search
'''
Boyer-Moore exact string search, implemented from the description
given in:
http://www.inf.fh-flensburg.de/lang/algorithmen/pattern/bmen.htm
'''
def _bad_character_shift(pat):
''' Calculates the bad character shift as the distance of the
@mavc
mavc / jsonparser.py
Created September 29, 2012 05:00
pyparsing demonstration
"""
Sample JSON decoder for demonstrating how to use pyparsing.
"""
import pyparsing as pp
# JSON types are number, string, boolean, object, array, and null.
# A boolean is either the literal 'true' or the literal 'false'. Set a
# parsing action that just replaces it with the Python equivalent.
boolean = (
@mavc
mavc / json_parser.py
Created October 1, 2012 18:46
pyparsing and ply demonstration
import re
from ply import lex, yacc
from ply.lex import TOKEN
import pyparsing as pp
# First, let's define a pyparsing parser for JSON.
class JSONPyParsing(object):
# pylint: disable-msg=W0104,E0213
import java.util.Comparator;
import java.util.List;
public class SlowSort {
public static <T extends Comparable<? super T>> void slowSort(T[] array) {
slowSort(array, 0, array.length);
}
public static <T> void slowSort(T[] array, Comparator<? super T> comparator) {
// ==UserScript==
// @name Kasi-Time Select
// @namespace github.com/mavc
// @include http://www.kasi-time.com/*
// @version 1.0
// @grant unsafeWindow
// ==/UserScript==
(function() {
/*
@mavc
mavc / th.rafo.user.js
Created August 30, 2016 04:22
Add < Prev and Next > Navigation for RAFO threads.
// ==UserScript==
// @name Thread.And.Find.Out
// @namespace mavc
// @description Add < Prev and Next > Navigation for RAFO threads.
// @match http://*.readandfindout.com/*
// @version 1.0.0
// ==/UserScript==
function getNext(t) {
// get first child, next sibling, or getNext() of parent.
// ==UserScript==
// @name twimg-icon
// @namespace github.com/mavc
// @description Download source images on Twitter.
// @include https://twitter.com/*
// @exclude https://twitter.com/i/*
// @version 1.1.1
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
// @grant none
// ==/UserScript==
from __future__ import print_function
import os
from os import path
from PIL import Image
import shutil
from sys import argv
EXTENSIONS = ('.jpg', '.png')
WALLPAPER_RATIO_MIN = 1.25
@mavc
mavc / close-tab-focus-left.gesture.js
Last active September 28, 2017 03:24
Foxy Gestures: Close Tab and Focus Left
executeInBackground(async () => {
const tabs = await browser.tabs.query({currentWindow: true});
const activeTab = tabs.find((t) => t.active);
if (activeTab.index > 0) {
// Set the current tab to the tab on the left.
let nextTab = tabs.find((t) => t.index == activeTab.index - 1);
await browser.tabs.update(nextTab.id, {active: true});
}
// Close the current tab.
await browser.tabs.remove(activeTab.id);