Skip to content

Instantly share code, notes, and snippets.

@mazuhl
mazuhl / googledocsstrikeoutkeyboardshortcut.user.js
Created February 9, 2010 13:34
Firefox Greasemonkey script to add strikeout keyboard shortcut
// ==UserScript==
// @name Google Docs strikeout keyboard shortcut
// @description Adds a keyboard shortcut for strikeout
// @namespace http://userscripts.org/scripts/review/68438
// @include http*://docs.google.com/*
// ==/UserScript==
(function() {
document.addEventListener('keydown', function(e){
@mazuhl
mazuhl / Webserver one liner
Created April 13, 2010 09:42
Start a Ruby webserver in the pwd
ruby -rwebrick -e"s = WEBrick::HTTPServer.new(:Port => 3000, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"
@mazuhl
mazuhl / gist:387466
Created May 2, 2010 21:29
Bookmarklet for posting images/URLs
/*
* This bookmarklet can be used to post an image/URL
* to a script, just click it. Adds a form and submits it.
*/
javascript:(
function(){
b=document.getElementsByTagName('body')[0];
/* create the form */
@mazuhl
mazuhl / gist:392141
Created May 6, 2010 13:50
Bookmarklet to add stylesheet to web page
javascript: (function () {
var linkNode = document.createElement('link');
linkNode.rel = 'stylesheet';
linkNode.href = 'http://www.website.com/stylesheets/style.css';
document.getElementsByTagName('head')[0].appendChild(linkNode);
})();
@mazuhl
mazuhl / gist:397443
Created May 11, 2010 15:36
Google Notebook bookmarklet - opens new window, adds script tag and loads script
javascript: (function () {
var w = window;
var d = document;
var g = w.open('about:blank', 'gnotesWin', 'location=0,menubar=0,scrollbars=0,status=0,toolbar=0,width=300,height=300,resizable');
var s = d.createElement('script');
s.setAttribute('src', 'http://www.google.com/notebook/bookmarkletPoster?zx=' + (new Date()).valueOf());
d.body.appendChild(s);
w.setTimeout(function () {
w.blur();
g.focus();
@mazuhl
mazuhl / gist:404793
Created May 18, 2010 09:03
Nokogiri example - inserting a node
require 'rubygems'
require 'nokogiri'
html = Nokogiri::HTML(DATA)
html.xpath('//table').each do |htable|
tbody = Nokogiri::XML::Node.new('tbody', html)
htable.children.each do |child|
child.parent = tbody
end
htable.add_child(tbody)
@mazuhl
mazuhl / gist:404806
Created May 18, 2010 09:18
Nokogiri example - using collections and hashes
#!/usr/bin/ruby1.8
require 'nokogiri'
require 'pp'
html = <<-EOS
<table >
<tbody>
<tr> <!-- table header --> </tr>
</tbody>
@mazuhl
mazuhl / gist:404814
Created May 18, 2010 09:27
Bookmarklet to sending page (from Instapaper)
javascript: function wrb() {
var d = document,
z = d.createElement('scr' + 'ipt'),
b = d.body;
try {
if (!b) throw (0);
d.title = '(Saving...) ' + d.title;
z.setAttribute('src', 'http://www.website.com/__UNIQUE__?u=' + encodeURIComponent(d.location.href) + '&t=' + (new Date().getTime()));
b.appendChild(z);
} catch (e) {
@mazuhl
mazuhl / Ruby WIN32OLE methods.rb
Created June 25, 2010 13:26
List of methods returned by WIN32OLE.ole_methods - useful for working with Outlook, Folder, Item, etc. objects.
# list of methods returned by WIN32OLE.ole_methods
Actions
AddBusinessCard
AddRef
AlternateRecipientAllowed
Application
Attachments
AutoForwarded
AutoResolvedWinner
@mazuhl
mazuhl / gist:464291
Created July 5, 2010 12:12
Extract Google search referer
$referer = strtolower($_SERVER['HTTP_REFERER']);
// Test if user comes from google
if (strpos($referer, 'google')) {
// Delete all before &q=
$tmp = substr($referer, strpos($referer, 'q='));
// Remove q=
$tmp = substr($tmp, 2);