Nick's Comp-sci Hints and Tips
Reference Material
I've gathered some interesting information lately, so I thought I'd make it available to the UCR computer science community, and the internet as a whole.
Misc. handy 1-line scripts
- Lower casing all characters in a stream: `tr A-Z a-z < infile > outfile' Reversing the character patterns (eg: a-z A-Z) will capitalize every character in a stream.
- Generating a self-signed SSL cert, all in one command (note that if you need to make your own CA to stuff into browsers, this may not be the best way to go): openssl req -x509 -days 3652 -newkey rsa: -nodes -keyout ssl.key -out ssl.crt
- Inserting code at a specific location in a file using Sed
Quality Foraged Links
Python Code
In the tradition of other code on this page, these are simple examples of problem solving in Python.
- clear-imap-folder.py. Got a huge IMAP folder full of spam (or get Mailbombed) and need to clear it out all quick style? This is the script for you. Can be fully automated via command line switches so as to be run via at/cron, or can be fully interactive. A good example of how to use Python's IMAP client library.
- decloak-youtube.py - Tired of being RickRolled by your "friends"? Pass in the youtube url to this script as the first argument and it will return you the title of the page. That should help. :)!
- mailScrub.py - A utility to clean up a CSV file full of email addresses (and first and last names, in that order, tab delimited). This little file is a good example of using Python's optionparser module, as well as showcasing the DNSPython library, a little bit of socket code, and the CSV handlers. It looks for a file called scrublist.txt (example here) for known domains that are legally protected from spam by the FCC. Address and domain caching implemented. Multi-threaded version to come as soon as I learn how to do it. :D Good times!
- decloak.py - A basic example of using python's httplib module that reads in tinyurl's and decloaks the redirect. This should help cut down the number of accidental goatse.cx (NSFW!) impressions. :P
- fileSlice.py - A simple example of how to slice a chunk out of the middle of a large text file. Originally designed to slice out the page-referrer section of an Awstats data file.
- makenfsrule.py - A simple script to output firewall rules for /etc/sysconfig/iptables for NFS hosts. Check out How-to Fix RPC Server Ports
PHP Code
Pretty much all of this serves as simple examples of how to do certain tasks in PHP.
- http-things.phps - Examples of how to use PHP's libcURL implementation. As well as how to geo-code from Google using their API.
- dirlist.phps - A simple way of defeating a web host who has indexing turned off.
- string-reverse.phps - Reversing a string in PHP without using the built-in string library. Mostly useful as a comparison to the C version of this example.
- pear-smtp.phps - A quick way to use PEAR to send mail via SMTP to a diff' server.
- arabic-translator.php - A funny program inspired by Team America and the Emacs m-x:spook file. Shows how to use stdin/stdout in PHP..
- command.phps - A simle utility to emulate a command line to a web server. Useful if you don't have SSH access to your host. Things to try: whoami, pwd, ls /etc/. :P
- query.phps - Another simple utility to emulate a mysql command line. So there's things like show tables, describe tablename, etc. Useful if you don't have interactive access and say, your phpmyadmin was deleted by a malicious web designer.
- make-lower.phps - A script to emulate tr's behavior of lower-casing every character in a stream. (see 1-liner above.) It should serve as a good example of buffered file IO. (tr took 43 seconds on a 650MB file, and this script took only 56 seconds, not too shabby for only guesstimates of buffer sizes.)
- A quick primer on debugging in PHP
- fputcsv.phps - A simple routine to write out a single dimension array to disk as a text delimited values file.
- smtp-client.phps - Example of using PHP's socket library to send mail via an SMTP server.
C/C++ Code
This segment here will be added to much more slowly than the PHP section, on account of no longer being a developer for a living.. :(
- broacast-proxy.c this was my first foray into UNIX socket programming in C. I wrote this at DefCon 18 for something my team was working on. Hope it helps someone get started! Check the links section above for Beej's guide, that's where I got started that afternoon.
- ipw2100-rndmac.patch This patch will cause the MAC address of your Intel ProWireless 2100 to randomize itself when activated in modprobe.conf with something like this: options ipw2100 rndmac=1 This patch was originally for the Pro Wireless 2200, found here. Since I don't have a 2200 (and the patch looked reasonably easy to port!) I ported it into the 2100 driver during a lunch break at Toorcon 9 This was tested against Kernel 2.6.22.1. Use at your own risk. I recommend setting your modprobe.conf to look something like this: options ipw2100 rndmac=1 associate=0 debug=1 when testing if this works for you.
- string-reverse.c I hadn't written any C in 4+ years, so I had to relearn some things. A simple example then of reversing the bytes in a C string. Note that each call to printf() either has no variables, or has a format string specified. (yep, I put in a format string vulnerability the first version of this code.)
- rotn.c Another byproduct of not writing C in forever: a simple rot(n) cipher tool. Give it an integer to shift by and the string to "encrypt" (I use the term loosely) and it will output the resulting code. I wrote this because I was trying to find a clean algorithm for doing the rotation without having to look at what the ASCII value of the character. I came close. :D
- disable-services.tar.bz2 A small example of using execvp() and getuid() to disable pre-defined list of services on Redhat-style machines. (eg: requires chkconfig and service commands) There's even a bash version thrown in for fun, so you can compare the two.. :) untar, cd, make, profit!
- stl-talk.tar.bz2 Outline and sample code that went along with my boring STL presentation.
Windows users will need WinRAR to decompress this archive. *NIX users: tar -jxf (archivename)
RPM's
Sadly, my old repository on ACMserver has been removed. Why, I couldn't tell you. Good thing xhcm is packaged in Fedora now. One fine afternoon, I'll link it back to my current webhost.
Handy legal download shops for electronic music
Handy meaning, NO DRM! iTunes can eat it (yes, I know they sell non-DRM music now, but try using their store on anything that doesn't run the itunes software.), as can anything associated with "Plays4Sure" (dead format now with the Zune, but yeah..)
- BeatPort One of the few places that offers uncompressed downloads for a marginally higher fee, Flash UI and works in Linux nicely. Addendum, 2009/03/18: Disable AdBlockPlus for BeatPort in Linux+FF3. There's some chicanery WRT Google analytics that I haven't debugged fully. (I still love this site though.)
- Drum & Bass Arena All kinds of killer d'n'b, FLAC/WAV also. Not to mention good use of AJAX (if you ever needed an example of 'doing it right')
- 7digital UK download store (Everything's in GBP) that has a lot of electronic stuff. Everything's DRM free here. 320K mp3 is the norm, newer stuff has FLAC option too.
- AudioJelly Good selections of UK trance
- DanceTunes Ferry Corsten's material is available here more than anywhere else.
- eMusic Lots of older, weird back-catalog type things. One of the few places I've found Fluke stuff for download.
- Bleep Warp Records official online store, most of the Aphex Twin back-catalog is here.
- Nettwork Werkshop Nettwerk Records online store. Includes a lot of BT, Plump DJ's, Sarah McLachlan and the rest of the Nettwerk cast.