Skip to content

Instantly share code, notes, and snippets.

View drench's full-sized avatar

Daniel Rench drench

View GitHub Profile
@drench
drench / Search & Replace
Created August 20, 2009 19:07
Add search-and-replace to textareas
(function(){
var D=document;
var CI=function() { return D.createElement('input') };
var SaR=function(ta) {
var f=ta.parentNode;
var s=CI();var r=CI();var b=CI();
b.value='replace';
s.type=r.type='text';
b.type='button';
@drench
drench / osx cleanup
Created November 3, 2009 17:17
Free some disk space on OS X
sudo port -f -v uninstall inactive
@drench
drench / I back up my eee pc like this
Created November 21, 2009 19:03
How I back up my eee pc
sudo dd if=/dev/sda1 | gzip -c | ssh doak 'cat > /opt/backup/eee/sda1.gz'
sudo dd if=/dev/sda2 | gzip -c | ssh doak 'cat > /opt/backup/eee/sda2.gz'
@drench
drench / bookmarklets
Created January 25, 2010 18:41
Wrap text/plain bookmarklet
<a href="javascript:(function(){%28function%28%29{var%20d%3ddocument%3bvar%20t%3dd.body.textContent.replace%28/%26/g%2c%27%26amp%3b%27%29.replace%28/%3c/g%2c%27%26lt%3b%27%29.replace%28/%3e/g%2c%27%26gt%3b%27%29.replace%28/\n/g%2c%27%3cbr/%3e\n%27%29%3bd.open%28%29%3bd.writeln%28%27%3ctt%3e%27%2bt%2b%27%3c/tt%3e%27%29%3bd.close%28%29%3b}%29%28%29%3b})()">text/plain word wrap</a>
#!/bin/sh
# Tweaked from http://jeetworks.org/node/68 to remove bashisms.
# Drop this in your libexec/git-core/ to use it as "git targz"
if [ -z "$1" ]
then
echo "Usage: git-targz [rev] path"
echo
echo "Creates gzipped-compressed tarball archive of the current or specified branch."
var timethis = function (f, n) {
var start = new Date();
for (var i=n; i > 0; --i) f();
var end = new Date();
var delta = end.getTime() - start.getTime();
print(n + ' iterations took ' + delta + 'ms');
};
var switchcase = function (tag) {
#!/usr/bin/env php
<?php
function counter ($n) {
error_log("starting counter at $n");
return function () use (&$n) {
return ++$n;
};
}
@drench
drench / soderberg-new-windows
Created September 14, 2010 20:42
soderbergs target=_blank code
/* one way: */
for (var i=0,L; L=document.links[i]; ++i) {
if (L.title.match(/\b(Join\s+Our\s+Mailing\s+List|Shop\s+Online)\b/i)) {
L.setAttribute('target', '_blank');
}
}
/* another way, maybe a bit more readable: */
@drench
drench / wp-ssl-rewrite
Created November 11, 2010 02:06
Wordpress: https for login, admin, shopping; http for everything else
# Did the user hit a page that should be https that should be http?
# Yes: redirect to https:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(wp-admin|wp-login|wp-register|products-page)/.*$ https://wordpress.example.com/$1 [R=301,L]
# Did the user hit a page that should not be https, under https?
# Yes: redirect to http:
RewriteCond %{HTTPS} on
#!/bin/sh
proxyhost=localhost
read method file http
if [ "$method" != "GET" ]; then
printf "HTTP/1.0 405 Method Not Allowed\r\n"
printf "Content-type: text/plain\r\n"
printf "Connection: close\r\n\r\nMethod Not Allowed\r\n"