:: Hack: Interactive Gentoo config integration ::
Gentoo preserves locally-tailored configuration files -- through the onslaught of ubiquitous package updates -- by placing new, dot-permuted copies proximal to their production brothers (e.g. /etc/._cfg0001_fstab). This is both safe and simple. Nonetheless, clusters of interrelated (often superfluous) package revisions quickly make the post-emerge stitching a bother.
dispatch-conf interactively steps through open configs, providing a diff and performing one of several actions: edit the existing config & reference diff, delete the new config or replace the existing config with the new one.
For each extant file, it provides a display like the following.
>>> 1 of 2 >>>>>> diff /etc/make.conf /etc/._cfg0000_make.conf --- /etc/make.conf 2002-12-15 10:25:08.000000000 -0500 +++ /etc/._cfg0000_make.conf 2002-12-15 13:16:20.000000000 -0500 @@ -50,7 +50,6 @@ # #CFLAGS="-mcpu=athlon-xp -O3 -pipe" #CFLAGS="-march=pentium3 -O3 -pipe" -CFLAGS='-march=pentium4 -mcpu=pentium4 -O3 -pipe' # If you set a CFLAGS above, then this line will set your default C++ flags to # the same settings. If you don't set CFLAGS above, then comment this line out. >> /etc/make.conf >> q quit, n skip, e edit current, k kill new, s supercede w/new
Update: Brandon Low (lostlogic at gentoo.org) asked me to update dispatch-conf to the point it can replace etc-update -- an existing shell-based utility for same.
:: Hack: Keyboard shortcuts ::
This is a simple one, but shaving every last keystroke from repetitive operations is a pet peeve. After seeing Google's keyboard shortcuts, I'd thought I'd use keyed features on my link page (which replaces bookmarks and serves as a home page.)
I have a set of input fields at the top,
<form name=one method=post action=home-search.cgi>
<center>
<u>g</u>oogle <input name=google type=text>
<u>p</u>aper <input name=paper type=text>
<u>w</u>ebster's <input name=websters type=text>
<u>i</u>mdb <input name=imdb type=text>
<input value=sub type=submit>
</center>
</form>
None of them has focus on page load. If one of our four keys is pressed, it gets focus.
<script>
function resetkeys() // for onload
{
nokeys = false;
}
function getkey(e)
{
if (nokeys) return true;
if (e == null) { // ie
kcode = event.keyCode;
} else { // mozilla
if (e.altKey || e.ctrlKey) return true;
kcode = e.which;
}
key = String.fromCharCode(kcode).toLowerCase();
switch (key) {
case "g": document.one.google.focus(); nokeys = true; return false;
case "p": document.one.paper.focus(); nokeys = true; return false;
case "w": document.one.websters.focus(); nokeys = true; return false;
case "i": document.one.imdb.focus(); nokeys = true; return false;
}
return true;
}
document.onkeypress = getkey;
</script>
And a script processes the results on [enter]...
#!/usr/local/bin/python
import cgi, urllib
form = cgi.FieldStorage ();
services = { "google" : "http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF8&q=",
"paper" : "http://my paper document database?query=",
"websters" : "http://www.m-w.com/cgi-bin/dictionary?va=",
"imdb" : "http://www.imdb.com/Find?for="
}
for k, v in services.items ():
if form.has_key (k):
print "Location: %s%s\n" % (v, urllib.quote_plus (form [k].value))
break
I have hotkey Ctrl-Numpad-Minus to launch a new browser window. One more keypress gets me the engines.
:: Hack: Ad Blocking with djbdns ::
A cohort has published his collection of evil, ad-generating domains, for easy blocking. If you have control of local DNS and web servers, redirecting them all to a local page is straightforward. For instance, I send them to a local fakenet web page like this. (Grab Synj's file here.)
Now, our friend's domain list is in Win2K registry format, but I'm using djbdns on a Linux router. I've written adservers-conf to read his file and generate domains in dnscache's servers/ dir for local resolve, and an appendage to your tinydns data file. The script expects adblocker.reg in the local directory. Optional files append and remove, with domains one per line, will modify that input. Each run of adservers-conf cleans its dnscache files, i.e. changes don't accumulate cruft.
The script assumes the following setup on your network. A dnscache resolving addresses for all internal hosts. A tinydns serving (perhaps) local reverse and hostnames. A web server that can support a new ad-blocking IP.
Steps:
- Grab adservers-conf and adblocker.reg.
- Ready a IP alias (e.g. in a fakenet, 10.0.0.250) and VirtualHost (if Apache).
- Execute adservers-conf on your dnscache system. It writes tinydns data lines to the console, so you must trap them. It's arguments look like,
- Append tinydns results and make.
- Setup your VirtualHost to respond to any URL it receives. I do this with an ErrorDocument directive.
- Reset dnscache (e.g. svc -t /etc/dnscache).
adservers-conf dnscache-path tinydns-ip web-ip
e.g.
adservers-conf /etc/dnscache 10.0.0.250 10.0.0.250 > tinydns.append
ErrorDocument 404 http://ad.web.server/index.html
Update: Use regdump to list adblocker.reg domains.
:: Further reading on this article ::