Skip to content

Instantly share code, notes, and snippets.

View canadaduane's full-sized avatar

Duane Johnson canadaduane

View GitHub Profile
@canadaduane
canadaduane / download-files.js
Created February 12, 2009 07:46
Downloads files matching the regular expression pattern to a folder.
/*
Ubiquity Command: download-files [regexp pattern] to [folder]
Author: Duane Johnson
Email: duane.johnson@gmail.com
Description: Downloads files matching the regular expression pattern to a folder.
2009-08-29: Updated for Ubiquity 0.5.x
See: http://github.com/canadaduane/ubiquity-download-files
*/
CmdUtils.CreateCommand({
name: "search-domain-name",
icon: "http://instantdomainsearch.com/favicon.ico",
author: {name: "Pratham Kumar", email: "pratham@pratham.name"},
description: "Checks availabilty of the domain name with com/net/org TLDs.",
homepage: "http://pratham.name/",
takes: {"example.com": noun_arb_text},
preview: function (html, q) {
var params = {name: q.text};
CmdUtils.CreateCommand({
names: ["eyes like lightning"],
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'input'} ],
author: {name: "Duane Johnson", email: "duane.johnson@gmail.com"},
license: "GPL",
description: "Opens a speed-reading window above the currently selected text.",
help: "Select some text, and then use the eyes like lightning command to start reading it.",
preview: function(pblock, args) {
require 'json'
$log_filename ||= File.expand_path(File.join("..", "ruby.log.json"), File.dirname(__FILE__))
begin
if !File.exist?($log_filename)
File.open($log_filename, "w") do |f|
f.write "["
end
end
@canadaduane
canadaduane / gist:660747
Created November 3, 2010 02:53
Feature Guessing Game
class FeatureSet
include Enumerable
def initialize(*features)
@features = features
end
def randomly_choose_one
@features[rand(@features.size)]
end
@canadaduane
canadaduane / jquery.textselect.js
Created February 12, 2011 05:29
jQuery Text Selection method and events
/* jQuery plugin textselect
* version: 1.0
* tested on jQuery 1.3.2, 1.5
* author: josef.moravec@gmail.com, duane.johnson@gmail.com
*
* usage:
* $(function() {
* $(document).bind('textselect', function(e) {
* Do stuff with e.text
* });
@canadaduane
canadaduane / app_path.rb
Created October 26, 2011 21:50
Sinatra app_path, similar to uri/url/to but with optional params
def app_path(path, params={})
if params.size == 0
uri(path)
else
query_string = ""
params.each_pair do |key, value|
query_string += key.to_s + '=' + escape(value.to_s)
end
uri(path) + '?' + query_string
end
@canadaduane
canadaduane / gist:3173840
Created July 25, 2012 01:27
Trouble with netrap on a Mac
$ make
gcc -c -std=gnu99 -O2 -fdata-sections -ffunction-sections -Wall -o netrap-controller.o netrap-controller.c
netrap-controller.c: In function ‘sockport’:
netrap-controller.c:151: warning: unused variable ‘port’
netrap-controller.c: In function ‘new_listen_socket’:
netrap-controller.c:410: error: ‘buf’ undeclared (first use in this function)
netrap-controller.c:410: error: (Each undeclared identifier is reported only once
netrap-controller.c:410: error: for each function it appears in.)
netrap-controller.c:414: error: ‘listen_socket’ has no member named ‘protocol’
netrap-controller.c: In function ‘new_http_socket’:
@canadaduane
canadaduane / gist:4219039
Created December 5, 2012 20:08
Make an Iterator
# Here's my method that loops over a collection and yields a block
def tardies_for_student(student_id, now=Time.zone.now)
submissions_by_student_id[student_id].each do |submission|
assignment = @assignments_by_id[submission.assignment_id]
yield build_tardy(assignment, submission, now)
end
end
# now I know I can do this...
@canadaduane
canadaduane / mount_ext3_volume.sh
Created January 4, 2013 03:24
Mounts an external drive via SSHFS+OSXFuse, using a Linux Virtual Machine to read/write to an Ext3 filesystem.
UBUNTU_IP=172.16.232.100
GUEST_DIR=/media/duane
MOUNTPOINT=/tmp/archive
if [ ! -d "$MOUNTPOINT" ]; then
echo "Mount point $MOUNTPOINT does not exist, creating..."
mkdir -p $MOUNTPOINT
fi
FIRSTDIR=`ls -1 $MOUNTPOINT`