When it’s worth it to destroy something
Posted in Photography on October 1st, 2009 by bemasherLook no further than this photo.
Look no further than this photo.
So I was sitting in my discrete structures analysis class today when a student asked a question about the homework. It went a little like this:
Student: How should we format pseudo-code in the homework?
Professor: Ah see pseudo-code is in that grey area. It’s somewhere in between code and english.
Professor: You see me do it one way in class, the book does it another way and the homework assignment does it an even different way.
Professor: Think of it this way, pseudo-code is a lot like pornography: you’ll know it when you see it.
Professor: So I’m not very worried about how you do your pseudo-code as long as I understand it.
The other cool thing that happened today was that I found out the owner of my favorite coffee shop is a pro-gun person. Apparently some of his relatives own a gun shop and he’s done some shooting competitions. All very cool. It definitely explains why none of the employees ever freak out about me carrying my 1911 which looks giant on my hip compared to others. I’m a tall skinny guy if you didn’t already know.
Bored again which seems to be the usual for the summer I sat down with one purpose in mind: To write another plugin. Didn’t really matter to me if it was useful or not I just wanted to write another one. I decided to ask my friend Pete who snarkily replied “Write one that randomly inserts horse pr0n1 in your blog.” to which I immediately replied “not horse pr0n, ASCII pr0n!” which probably made him choke on his drink and immediately remember rule 34. But this made me think to myself: Why not a random plugin?
So I did just that, I wrote a random plugin. One so useless that I don’t think I’m even going to activate it on my blog save for days like April Fools Day. The plugin chooses at random a word from each post using the the_content hook and censors it out with <censored>. Funny huh? This will ignore html tags so it won’t break links and things like that. The code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <? /* Plugin Name: Random Censor Plugin URI: http://www.bemasher.net/ Description: Picks a common word at random from posts at display and replaces with <censor>. Ignores urls and other semi-important things. Version: 0.01 Author: BeMasher Author URI: http://www.bemasher.net/ */ function random_censor($content) { $oldcontent = $content; $content = preg_replace("/<[^<]+?>/", "", $content); preg_match_all("/\b\w+\b/", $content, $words); $word = $words[0][rand(0, sizeof($words[0]))]; $oldcontent = preg_replace("/\b$word\b/i", " <censored> ", $oldcontent); return $oldcontent; } add_filter("the_content", "random_censor"); ?> |
I’ve been meaning to do this for a while, I’m writing a plugin for wordpress to automatically capitalize the right letter in the words I’m generally lazy about typing. Things like I, I’m, I’ve and the like1.
Took me a little while but I did finally find some documentation on all the different hooks wordpress has for filters. I found one in particular that does what I want called content_save_pre which applies a particular filter to the content of a post any time I save or edit it. So for things like drafts and actual posting and updating posts it would fire the function I registered as a filter.
The first problem I ran into is that for some strange reason it didn’t seem to want to replace contractions with the single quote character. I later found out that when displaying the single-quote it converts it to the html entity ’ which shows up as an apostrophe. So I tried working around that but that dIdn’t seem to work either. Eventually I just setup a small test post and modified the function to email me the plain-text contents of the post that the filter would receIve, I noticed that it escaped single quotes probably through the use of the php function mysql_escape_string2. So anything with an single-quote would show up with a backslash just before the single-quote. This of course broke the regular expression I was using and I couldn’t seem to figure out how to get it to check for that character so I gave up and just used the negated word-character class \W.
Anyway after fiddling around with it a little more and adding a few new cases to the regex I arrived at this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php /* Plugin Name: Lazy Errors Plugin URI: http://www.bemasher.net/ Description: Replaces errors from lazy typing, things like: I, I'd, I've, I'm will be replaced with proper case. Version: 0.02 Author: BeMasher Author URI: http://www.bemasher.net/ */ function lazy_errors($content) { return preg_replace("/I(?(?=\W')(\W')(ve|m|d|)|(\b))/", "I$1$2$3", $content); } add_filter("content_save_pre", "lazy_errors"); ?> |
The regular expression reads like so: If there’s an I followed by any non-word character and a single-quote then make sure it’s got a proper contraction following the single-quote. Else make sure there’s a space, period, comma, colon or semI-colon following the I. Then replace with capitalized I and the matching group from the conditional.
I should probably work out some code to make it ignore sections of text I don’t want it to filter. A prime example of this would be in the comments of the plugin and especially in any code as code examples copied from my site would then be broken if the regex I wrote matched anything in the code.
Summer is usually a bad thing for my hardware and projects. Once I’ve gone through all the trouble of getting them setup and working the way I like I get bored and wonder what else I could do to//with1 them.
My next project for my server2 was to install pfSense3. I wasted most of my time on this project trying to do it the ways that were either not recommended or not documented.
Things like using unetbootin4 to run the LiveCD5 image since I have this strange hatred for optical media, it seems too wasteful to me, not to mention I rarely have the specific kind of media I need for the right project. That failed miserably of course since FreeBSD based LiveCD’s never seem to like the extraction and customization process unetbootin does to linux based iso’s.
After trying and failing to run the LiveCD from a thumb drive I did what I usually do to install OS’s that require optical media for installation: I use my IDE-USB adapter6 to chain it to the USB KVM7 I use so I don’t have to take my optical drive out to do installs. Lo and behold pfSense just happens to not support USB optical drives, it boots to the point where it would normally mount the iso96608 formatted volume it expects to be at /dev/acd0 which isn’t because FreeBSD 7.0 doesn’t seem to have support for USB optical drives.
Anyway next in line was to use the embedded image. If you didn’t already know the main storage for my server is a SYBA SD-CF-2IDE-U adapter9 or simpler: a Compact Flash to IDE adapter. I figured this would be simple enough as I used to do the same thing for running FreeNAS on my server. I’d just pop the CF card into the multi-reader on my desktop and use dd10 to dump the embedded image that pfSense provides to it. My first instinct after getting the image downloaded was to decompress it since it was packaged as a GNU Zip file. Booting from this produced only a pipe character with a blinking cursor immediately beneath it. Reading through instructions further I discovered that the embedded version doesn’t have keyboard or video support, only serial which I don’t have on any of my systems anymore never mind that for once I have the proper cable for that. Also apparently I’m supposed to dump the compressed image to the card which produces no pipe character at all let alone a bootable card.
Clearly I was off to a good start11. I finally gave up on the whole idea of doing it any other way than what was tried and true. This lead to me dismantling my desktop to use the only working optical drive I’ve got left and plug it into my server to install from the LiveCD. Also took me a good long time to find the manual for the IDE-CF adapter to figure out which jumper12 needed to be changed so it would act as a slave. Once that was all said and done and the system booted to the LiveCD I ran the install to harddisk option. After formatting the disk, partitioning it and setting up appropriate slices it started the install. I wasn’t done yet with my troubles since it decided it was going to hang at 43%. Upon further investigation I noticed the light on the optical drive I was using wasn’t on or indicating any accessing at all. Found out that power had somehow disappeared from the drive, either through mechanical error13 or something else entirely. Rebooted and restarted the install once more, ended up disconnecting power and reconnecting it whilst installing. That seemed to do the trick as the install finished without further hitch excluding the fact that it wouldn’t install GRUB citing an error return code of 1 so ditched that idea and just used their default setting.
You’d think I would have been done with installing and general mucking about at the low-level end of this whole thing and you’d be wrong. After putting the optical drive back in my desktop and rebooting the server I notice it did the same thing it did when I tried to boot it from the optical drive plugged in through USB, it couldn’t find//mount the volume it thought the system was on. This is due to the CF adapter being a slave during the install and a master during boot after removing the optical drive. Instead of mucking around with the KVM switch and switching monitor display ports anymore14 I popped the CF card out of my server and into the CF port on the multi-reader in my desktop. Instead of using the USB filtering that VirtualBox has since it rarely ever works//tends to break anything I touch with it, I fired up a command prompt and created a vmdk that points to the physical disk. Mind you the command prompt must be run as administrator if you’re doing this in Windows 7 like I am. It will fail with a VERR_ACCESS_DENIED exception if you don’t.
1 | VBoxManage.exe internalcommands createrawvmdk -filename CF.vmdk -rawdisk \\.\PhysicalDrive3 |
After creating CF.vmdk I made a new virtual machine for it to go into along with mounting the pfSense LiveCD. Starting a command prompt with option 8 I mounted /dev/ad0s1a to /mnt and edited /mnt/etc/fstab to change ad1s1a and ad0s1b to ad0s1a and ad0s1b respectively.
1 2 | mount ufs:/dev/ad0s1a /mnt vI /mnt/etc/fstab |
Reboot and it is finished! After all that is simple web-interface based configuration that didn’t take very much time at all. Actually as I write this I am posting it through my new pfSense router.
Every couple of days I stop and take a look through the stats on my blog to see how things are progressing, and I notice plenty of times where people have used certain search terms to come to my blog. Sometimes the terms are very specific, sometimes they are very vague, but I always wonder the same thing: did they find what they were looking for?
I often times wish I could some how contact the person that made a certain query to ask them if they found what they wanted to find. I wonder if they took the time to read through the post i wrote that relates to their query and found their answer. I know how I read blogs and it’s often not very thorough, I figure that a majority of the time I don’t find what i’m looking for specifically because I just skim over it. I do admit though that I’m probably not making it very easy for the readers to find very specific information, there’s often a lot of fluff and cruft surrounding the important bits of information in my posts.
Google can you help me? I want to be able to answer the questions posed by your users’ queries. Yes I already know you’re going to tell me that that’s what comments are for but sadly not enough people use comments. I also already know you’ve implemented what you call a SearchWiki1 and that seems to have failed miserably, but I like the idea, just wish I could contribute my own results and findings to other’s SearchWiki’s.
One of the only things that kept me from installing Windows 7 permanently during the school year was that the few times I tried, I had never gotten MikTeX1 to work. This of course was a major problem since nearly all of my assignments are done with MikTeX now. When installing MikTeX I always ran into a BSOD that I ignored because I figured that it was only because Windows 7 was only an RC2.
I’ve had Windows 7 on my desktop now for about 2 weeks and up until this point I’ve been making due with the MikTeX Portable Edition which is pretty buggy to say the least. More than half of the time it would hang on compiling a document to pdf at something due to it not thinking initexmf.exe was an operable program. And of course upon googling this problem, nothing of use could be found.
Well tonight I decided I’d give the install another go to see if either Windows 7 had been patched to fix this issue, or if MikTeX had fixed the problem. On my first try, it did exactly as it had always done before BSOD’d. Since I had never set windows to not automatically restart upon catastrophic system failure3 it would just instantly restart without giving me enough time to read the type of error. I fixed this and ran the installer once more. The BSOD was a PAGE_FAULT_IN_NON_PAGED_AREA error, which was pretty vague as usual but I figured it had to do with system paging, so I disabled the Virtual Memory restarted and ran the installer once more. This time it worked exactly as it should.
On another interesting note, I discovered that pdflatex is significantly faster than texify. I found this out when I was trying different methods of compiling my TeX documents into pdf’s using the MikTeX Portable Edition which was giving me fits with my old method.
I used to use the following in NotePad++’s NppExec plugin to compile a pdf and view in Adobe Reader:
1 2 | C:\Program Files\MiKTeX 2.7\miktex\bin\texify.exe -c -p "$(FULL_CURRENT_PATH)" "$(NAME_PART).pdf" C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe "$(CURRENT_DIRECTORY)\$(NAME_PART).pdf" |
Now I use pdflatex:
1 2 | C:\Program Files\MiKTeX 2.7\miktex\bin\pdflatex.exe "$(FULL_CURRENT_PATH)" C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe "$(CURRENT_DIRECTORY)\$(NAME_PART).pdf" |
I’d have to say that my favorite style of photography is good black and white infrared photography, occasionally false-color infrared photography is good but black and white is by far my favorite.
I finally got a chance this summer to take some decent IR photos on my parent’s ranch in Wyoming. I did all of the photos with my Nikon E-Series 28mm f/2.8, which on my Nikon D50 is a bit closer to a 42.7mm lens than a 28mm lens. How did I figure that you ask?
Given that I can find the angle of view of the camera using the equation1:
Where alpha is the angle of view, f is the focal length of the lens and d is the diagonal length of the sensor of the camera in question. Given that my camera’s sensor is 24.7mm x 15.5mm2, we can substitute this in for d as well as the focal length of my lens, 28mm and solve for alpha:
Now that we’ve found the angle of view that my camera sees through the 28mm lens we can solve for the focal length f in lets say Nikon’s D3X which happens to have a full-frame sensor. The Nikon D3X’s sensor is 35.9mm x 24mm3.
Substituting in the diagonal length of the D3X’s sensor and the angle of view my D50 has we can find what focal length of lens the D3X would need to have to have the same angle of view as my D50.
And now we can figure out how much cropping (magnification if you will) my camera’s sensor causes when using a lens meant for a 35mm//full-frame camera.
This happens to be pretty close to the ratio that most people give for calculating the focal length of a lens meant for a 35mm//full-frame camera on Nikon DX format cameras. The general rule given is that you should just multiply the focal length by 1.5 which… as you can see is ever-so-slightly off. I’m just a little OCD about that sort of thing and it seemed too simple to be completely correct so I figured I’d just calculate it myself.
Anyway I suppose I should have warned you at the beginning of the post that this would have more to do with photography math than infrared photos but it probably didn’t hurt you to learn something new.
Also I almost forgot to mention what filter I used. I used a Hoya R72 Infrared bandpass filter. This particular filter passes light wavelengths 720nm and greater. Since my camera was designed with visible light photography in mind it has a low pass filter installed over the sensor that blocks out a good deal of infrared and ultraviolet light so even in broad daylight I still have to do long exposures to get infrared photos exposed properly.
The photos in that album were all done at f/16 since I found that using extremely long exposures at smaller f-numbers just blows out the photo and I’m not sure why just yet. However it helps to use a smaller aperture anyway since infrared light also focus’ at a different point than visible light does, my 28mm lens has an infrared focusing mark on it for correcting but, it’s not perfect and I can’t compose or focus the shots while the filter is on the camera since being human my eyes are only sensitive to light of wavelengths between about 380nm and 750nm4. As well as making the photos not-blown-out with the aperture so small it also aids in any focusing deficiency since the depth of field is much deeper. Most of the photos were between 2 and 5 second exposures depending on the cloud-cover. You can see detailed shooting info by looking at the EXIF data Picasa shows in the More Info section of each photo, the aperture is erroneous there so ignore it, my Nikon E-Series 28mm is a non-cpu lens so it can’t tell the camera what it’s current aperture is.
I’m kind of pathetic, I still have access to my workstation even when I’m on vacation and I needed to do a little bit of work while I was here. So I fired up Logmein only to discover it didn’t like any of the credentials I had tried to give it.
A quick google later and I found that Windows 7 RC requires the computer’s name be prefixed as the domain of the login credentials like so:
Lets suppose your username is bob and your computer’s name is bobs-computer. In order to login you would have to use bobs-computer\bob in for the username field then simply bob’s password for that username.
So I did manage to remote into my workstation to do some work and all is well.
If you’ve read back far enough here you’ll remember I was in the process of building my own NAS for media storage and backup. I was recently reading through the RSS feed from engadget and came across the Acer easyStore. While this is a lot more polished in the end than my home-brew NAS box it ended up being a little more expensive as well. The parts I used are as follows:
Ignoring extraneous things like shipping and sales tax the grand total is $547.39. If you take out the hard drives it was only $319. While the Acer Altos easyStore will be $400 (with one preinstalled 1TB drive). Granted Acer’s looks much prettier than mine and depending on the internals it might even have hardware raid where mine doesn’t. Though considering it’s got Windows Home Server installed i’m doubting very much that it has hardware raid.
When I first started building my NAS box atom processors had only just started to come out let alone be available in mini-itx packages like the one I bought. I could just as easily upgrade the motherboard in mine for somewhere between $80 and $120 which might bring new life to my system, but for what it does now and it’s general duties the Via C7 it’s got is good enough for me.
I think if I ever decided to get one of the Acer Altos easyStore NAS’s I’d just stick an IDE-CF adapter inside (assuming it’s got PATA) and load freeNAS onto that and use all 4 bays for storage instead of OS + Storage on the 4th drive.