maximise your spare cycles
applet= bookmarklet
javascript:(function () { /* do stuff */ })();
javascript:void(location.pathname = (location.pathname + '').replace(/([^/]+\/?)$/, ''))
javascript:(function () { var newHost; if (location.host.match(/(^|\.)example\.local$/)) { window.name = location.host; newHost = 'www.example.com'; } else { newHost = window.name.match(/(^|\.)example\.local$/) ? window.name : 'example.local'; } location = location.href.replace(location.host, newHost); })()
javascript:Array.prototype.slice.call(document.querySelectorAll('form:not([target="_blank"])')).forEach( function (f) { f.method = 'GET'; f.target = '_blank'; } );
window.getSelection()
:
javascript:alert((getSelection() + '').length);
javascript:location = 'http://www.merriam-webster.com/wdictionary/' + encodeURIComponent(prompt('Word:'));
frmblank
of mw
%s
gebruikt in de URL van je bookmarklet, wordt die vervangen door hetgeen je achter je woord typthttp://www.merriam-webster.com/dictionary/%s
levert http://www.merriam-webster.com/dictionary/test opjavascript:alert('%s'.length);
met len
als keywordjavascript:alert(%s.length);
en len 'hello, world!'? Omslachtig!var x = <foo bar="baz">quux</foo>
is geldige JavaScript-codevar x = <><![CDATA[It's time!]]></>
is geldige JavaScript-code<><![CDATA[%s]]></>
javascript:(function () { var s = (<><![CDATA[%s]]></> + '') || getSelection() + '' || prompt('Text:'); prompt('The length of "' + s + '" is:', s.length); })();
html
javascript:(function () { var s = (<><![CDATA[%s]]></> + '') || getSelection() + '' || prompt('HTML:'); location = 'data:text/html;charset=UTF-8,' + encodeURIComponent(s); })();
Mogelijke gebruikswijzen:
data:text/plain;charset=UTF-8
voor platte tekst; eventueel zonder encodeURIComponent
om URL-encoding te ontcijferencheck
javascript:(function () { var s = (<><![CDATA[%s]]></> + '') || getSelection() + '' || location; location = 'http://validator.w3.org/check?verbose=1;ss=1;outline=1;uri=' + encodeURIComponent(s); /* location = 'http://validator.nu/?doc=' + encodeURIComponent(s); */ })();
refer
javascript:(function () { var s = (<><![CDATA[%s]]></> + '') || getSelection() + '' || location; location = s; })();Bijvoorbeeld anti-hotlinkers: refer vanaf een toegelaten site en het lukt wel
keyword.URL
op http://www.google.com/search?btnI=&ie=utf-8&q= in about:config
wget
downloadtgrep
doorzoektsort
sorteertDownloads
in je gebruikersmap (~
is je home directory)
test.txt
foo
in test.txt
templates
en al haar submappen
ack
in huis: ack --html --php 'href="[^"]*login' templates/x
in op bla bla bla
x
x
in op de uitvoer van het commando foo
x
in op de eerste drie karakters van de variabele USER
(bv. janmoesen
geeft jan
)x
in op de variabele x
met alle a
's vervangen door o
's (bv. faal
geeft fool
)x
in op de variabele SUDO_USER
, en als die niet bestaat, op de variabele USER
switch … case
)0wn3d.php
?foo
als de invoer van bar
bar
uit als foo
gelukt is
0
$?
bar
uit als foo
mislukt isfoo
uit in de achtergrondfoo
, bar
en baz
tegelijkertijd uit wacht tot alles gedaan is./modules/animations/js/banner.js ./modules/animations/js/detail.js ./modules/channels/js/buy.js ./core/js/jquery/jquery.js ./core/js/utils.js ./cache/navigation/tinymce_link_list_en.js
nascom-bseen.be
nog niet bestaat, bevat de uitvoer van whois
de tekst Status: FREE
grep
zal dan die tekst vinden en lukken, dus exit status 0
gevengrep
gelukt is, zal de echo
uitgevoerd wordenwget
mijn site niet kan downloaden, waarschuwt mijn computer mefoo.zip
en laat me ondertussen verder werkenprod1
, prod2
en prod3
en zeg het als het klaar isx.txt
als invoer (STDIN
) voor foo
STDOUT
) van foo
naar x.log
STDERR
) van foo
foo
naar x.log
x
als invoer voor foo
ls -alF
als invoer voor foo
— vergelijkbaar met ls -alF | foo
publish.txt
als een script voor het FTP-programma:
ls type binary put latest-news.html put archive.html quitWat
ftp
betreft, heb je dat zelf "live" getypt.
my-cron.php
voor en na een svn update
r
(d.w.z. exit nodes)mysqldump
uit op de productieserver via SSHsed
om bv. de Google Analytics-ID te veranderenmysql
~/.my.cnf
:
[client] host=localhost user=janmoesen password=supers3kr1t database=example
~/.ssh/config
:
Host prod1 HostName example.be User janmoesen IdentityFile ~/.ssh/example.be-id_rsa
ssh-agent
of OS X's Keychain) die wachtwoorden onthoudttput
kan je onder andere kleuren verkrijgengrep
: !grep
foo
door bar
: ^foo^bar:
for x in *.avi; do echo mv -vi "$x" "films/$(tr '[:upper:]' '[:lower:]' <<< "$x")"; done # Uitvoer: # mv -vi FooBarBaz.avi foobarbaz.avi # mv -vi PHL CANDID CAMERA MUST SEE!.avi phl candid camera must see!.avi ^ echo # Uitvoer: # for x in *.avi; do mv -vi "$x" "films/$(tr '[:upper:]' '[:lower:]' <<< "$x")"; done # FooBarBaz.avi -> films/foobarbaz.avi # PHL CANDID CAMERA MUST SEE!.avi -> films/phl candid camera must see!.avi
ls -alF frontend/core/css/screen.css minify !$ # hergebruik het laatste argument
export HISTSIZE=4096 export HISTCONTROL=erasedups
nano
: export EDITOR=nano~/.bash_profile
PS1
) niet zo nuttig
janbookpro:tmp janmoesen$ echo "$PS1" \h:\W \u\$ janbookpro:tmp janmoesen$
PS1
bevat voor mij tijd, opdrachtnummer, succes van vorige opdracht, gebruiker, server, huidige map en huidige branch:
-----[ 17:23:22 ] (!505) [ :-) ] janmoesen@janbookpro ~/Sites/forkcms (protect-against-xss) $ echo "$PS1" \033]0;${PROMPT_TITLE}\W \a-----[ \t ] (!\!) [ ${PROMPT_ERR_ICON} ] \u@\h \w $(git_branch)\033[m\n$ -----[ 17:23:28 ] (!501) [ :-) ] janmoesen@janbookpro ~/Sites/forkcms (protect-against-xss) $
#!/bin/bash latest_remote="$(curl --silent http://build.chromium.org/f/chromium/snapshots/chromium-rel-mac/LATEST)" || exit $?; current_local="$(/usr/libexec/PlistBuddy -c 'print SVNRevision' /Applications/Chromium.app/Contents/Info.plist)" || exit $?; if [ "$latest_remote" -gt "$current_local" ]; then src="http://build.chromium.org/f/chromium/snapshots/chromium-rel-mac/$latest_remote/chrome-mac.zip"; dst="/Applications/Chromium.app"; bak="/Applications/Chromium-$current_local.app"; tmp="$(mktemp -d -t "$(basename "$src").XXX")"; cd "$tmp" && \ curl --silent --output chromium.zip "$src" && \ unzip -qq chromium.zip && \ mv "$dst" "$bak" && \ mv chrome-mac/Chromium.app /Applications && \ rm -rf "$tmp" "$bak"; fi;
backup () {( # Configuration. local backup_dir="$HOME/backups"; local date_format='%Y-%m-%d-%H-%M-%S'; local i=0; for x in "$@"; do # Determine the name for the current backup. local curr_date="$(date +"$date_format")"; local full_path="$(php -r 'echo realpath($_SERVER["argv"][1]);' "$x")"; local curr_backup="$backup_dir/$curr_date$full_path"; local curr_backup_dir="$(dirname "$curr_backup")"; # Check for previous backups. local prev_backup=''; shopt -s nullglob; for prev_backup in "$backup_dir/"*"$full_path"; do : done; # Back up using rsync, hard-linking unchanged files to the previous backup, if any. mkdir -p "$curr_backup_dir"; echo "Now backing up: $(basename "$full_path")"; echo "Backing up to: $curr_backup"; if [ -z "$prev_backup" ]; then echo 'Previous backup: (none)'; echo; rsync --itemize-changes --archive "$full_path" "$curr_backup_dir"; else echo "Previous backup: $prev_backup"; echo; rsync --itemize-changes --archive --link-dest="$(dirname "$prev_backup")" "$full_path" "$curr_backup_dir"; fi; let i++; [ $i -eq $# ] || echo; done; )}
kak.be/phl (→ http://jan.moesen.nu/presentaties/klik-hier-niet-fronteers-2011/)