Planet
The SOPA/PIPA Protest
The following is a list (woefully incomplete) of sites that took action against SOPA/PIPA:
Google (blacked out their logo)
Slashdot (blacked out their logo)
XKCD (Protest Comic)
WBAI Radio (CSS switch: Content blocks in reverse video)
I Can Has Cheezburger? and the Cheezburger Network (Banner)
TV Tropes (Banner)
EFF (Banner & CSS Switch)
The Tor Project (Censor bar across site)
Craigslist (Main page blacked out. Banner on regional pages)
Ars Technica (CSS Switch & Banner)
Not Always Right (CSS Switch & Banner)
Reddit (12-hour outage, 8AM-8PM Eastern -- US Workday)
Questionable Content web comic (Special Comic)
The Mozilla Project (12 hour outage, 8AM-8PM Eastern ; Firefox start page made black)
English Wikipedia (Offline)
2600 (and various local 2600 groups) (Offline)
The Oatmeal (Offline & Funny Picture)
SMBC Comic (Comic blacked out)
Explosm (Site blacked out)
Wasted Talent (Site blacked out)
Wordpress (Main site blacked out)
Nyan Cat (Site blacked out. No Nyan Cat.)
…and of course bsd-box.net, which was offline.
Continue reading "The SOPA/PIPA Protest"
Using PowerShell to represent Base 26 as the uppercase English Alphabet
Today I was asked to do something that seemed simple, until I actually had to do it. A coworker had a database with two fields he wanted renamed in a specific way. For our example, lets call them ProductNumber and ProductName. He wanted ProductNumber to be sequential (1, 2, 3 . . .) and the ProductName fields to be called “Product A”, “Product B” . . . “Product Z”, “Product AA” etc. So this suddenly became a non-trivial problem if you had more than 26 rows, which of course I did.
So I rolled up my sleeve, got a fresh cup of coffee, and got to work. Populating ProductNumber was easy enough using a Common Table Expression (CTE) with a ROW_NUMBER(). Then I realized I could think of the English alphabet as symbols for a base 26 number system, with AA following Z and so on. The only problem was I couldn’t express that in a set based way for a clean T-SQL implementation. No problem, I’d just generate the T-SQL to make a giant mapping table in PowerShell!
I am ashamed to admit I had to look up the algorithim for converting from base 10 to another number. I was also surprised to discover that the first result google returned me was this tripod page.
The algorithm is as follows.
- Start with an empty string which becomes the return value
- While the value is greater than the base get the remainder of the value divided by the base. Convert that to its letter and prepend that to the return value
- Repeat step 2 with the quotient of the value over the base.
- When the quotient is less than the base, prepend that to the string instead.
It seemed simple enough, but there were some headaches.
The first thing I discovered was that when you divide integers in PowerShell, you get a float as a result. Also casting it back to an int rounds instead of truncating the results. I was expecting the opposite in both cases, because that is how C# behaves. I ended up using the unwieldy combination of Math.Floor() and a cast in the form [int][math]::Floor($currVal / 26) to resolve this. The MSDN technet has an article that recommends the more unwieldy [Math]::floor([int] $currVal / [int] 26), but I proved that my terser method gives the same results.
Then I had problems with how to display powers of 26. The way it was supposed to work was that 1 = A, 24 = X, 25 = Y, 26 = Z and 27 = AA. However, depending on how I did it I ended up with 26 = AZ or 27 = BA. I could not account for this edge case, nor compensate for it with special conditions.
Then it dawned on me, A needed to be equal to zero not one. A base 10 system deals with the digits 0-9. Base 2 deals with 0 and 1. Base 16 deals with 0-F and F is 15. Once I rewrote my script to work that way, edge cases disappeared, and things just worked.
The script function Convert-ToLetters ([parameter(Mandatory=$true,ValueFromPipeline=$true)][int] $value) { $currVal = $value; $returnVal = ''; while ($currVal -ge 26) { $returnVal = [char](($currVal) % 26 + 65) + $returnVal; $currVal = [int][math]::Floor($currVal / 26) } $returnVal = [char](($currVal) + 64) + $returnVal; return $returnVal }If its not clear how I generated upper case letters, the ASCII codes for A through Z are 65 through 90, and casting an integer to a char converts it to its ASCII code. Ergo, the expression [char]65 evaluates to “A”.
So now here’s the function in action:
1 .. 100 | ForEach-Object { $_ | Convert-ToLetters }Happy Scripting!
Making an RDP connection to a server you just rebooted with powershell
It’s an all to familiar story. You need to reboot a server, and then you need to start a remote desktop connection into it. So what do you do? You open up a command prompt, type ping -t <HOSTNAME> and wait until the server responds to pings. When that happens, you keep trying to connect via remote desktop, until it works. There’s got to be an easier way. You should write a PowerShell script to automate the process. However, its one of those things that not quite annoying enough to get you to actually take action and write the script. Luckily, thanks to the power of twitter, I reached a tipping point this week, and wrote the script. It all started out with some innocent whining:
.ditto155068373691150337{background: #C0DEED url(http://a0.twimg.com/images/themes/theme1/bg.png) no-repeat;padding: 20px;} .ditto155068373691150337 a { color: #0084B4;} p.dittoTweet{background: #fff;padding: 10px 12px 10px 50px;margin: 0;min-height: 48px;color: #000;font-size: 18px !important;line-height: 22px;-moz-border-radius: 5px;-webkit-border-radius: 5px;} p.dittoTweet span.metadata {display: block;width: 100%;clear: both;margin-top: 8px;padding-top: 12px;height: 65px;} p.dittoTweet span.metadata span.author {line-height: 22px;color: #666;font-family: Arial, Helvetica, sans-serif;} .mainlink {font-family: Arial, Helvetica, sans-serif;font-size: 26px;color: #1F98C7;text-decoration: none;} .mainlink: hover {color: #1F98C7;text-decoration: underline;} .tweet {font-size: 24px;} p.dittoTweet span.metadata span.author img {float: left; margin: 0px 7px 0px 0px;} p.dittoTweet a:hover {text-decoration: underline;} p.dittoTweet span.timestamp {font-size: 12px;display: block;color: #999;} p.dittoTweet span.timestamp a {color: #999;text-decoration: none;}@zippy1981
Justin DearingYou know what I need in an RDP client. I need an “”I just rebooted so ping it for me and autoreconnect”. 2 days ago via web · powered by @socialditto
Then d0tk0m and Yanni Robel retweeted my whining. They say necessity is the mother of invention. In this case the commiseration off two tweeps was the father. So I spent a Saturday with PowerGUI, and came up with a script to solve the problem.
Planing stageI wanted my script to automate what I already did. From the perspective a system administrator that wants to reboot a server and then remote desktop into it, the following happens.
- All the processes, including the remote desktop service (termsrv.dll) are shut down. When that happens the remote desktop port (default 3389) no longer has anything listening on it.
- Eventually the network adapter is shutdown and it will stop responding to ICMP echo requests, or pings.
- The server will finish shutting down, the BIOS will POST, and Windows will begin booting
- Eventually the network adapter will come up and start responding to pings.
- The remote desktop service will start and bind to the remote desktop port.
Therefore, I made my script to do the following.
- Ping the server until it answered five successive ping requests. Yes this might be naive and optimistic in many cases. However, it worked in my use case. I used the Send() method of the .NET System.Net.NetworkInformation.Ping class to do this.
- Once I was sure the host was up, I’d try to connect to it on port 3389, or another port if I passed a different port as a parameter. To do this I used the System.Net.Sockets.TcpClient class.
- After this it was simply a matter of passing the right parameters to the remote desktop client, mstsc.exe. I initially attempted to use the simple & mstsc <Arguments>. However, that didn’t work to well so I ended up resorting to Invoke-Expression.
Below is the current version of the script, hosted on poshcode.org. The current version is stored in gist repository. While you are free to post changes to poshcode.org (or anywhere), in accordance with the license, I’d prefer if you notified me of any changes so that they may be placed in the gist git repo.
What #SQLFamily means to me.
Warning folks, this is a non-technical post.
Recently, a post on the official SQL Server blog stated that for each of the first 400 “what #SQLFamily means to me” stories submitted to sqlfamilysubmission@live.com, $50 would be donated to The Pragmatic Works Foundation to train veterans in IT skills. I just submitted my entry, which I have reproduced below.
My name is Justin Dearing, and I have worked in various capacities in the IT industry since December 2002. This is my #SQLFamily story. it is a story of learning my manners and receiving forgiveness.
Paul Randal and Kimberly Tripp recently decided to increase the community marketing of their SQLSkills consulting company. They offered to send anyone a SQLSkills sticker that sent them a mailing address. I decided to sign up for this. I was a bit surprised there was no automated form, and that I had to send this request in prose via email. Note that there is now a web form for this.. Well I did not say please or thank you, or generally acknowledge that a fellow homo sapien would be receiving the request at the end. Well, a very unique and talented homo sapien that I respect very much (Paul Randal himself) did indeed read my response, and sent the following twitter message: Amazing number of people that sign up for our mailing list and ask for sticker without please or thank you at all. Internet = no manners I hung my head in shame for about a week while fretting over what to do because I knew right away I was the offender. Eventually I decided to simply send an email to Paul saying I realized I was the one that offended him and apologizing. He accepted the apology and sent me the sticker. Like a functional family, when forgiveness was sought it was quickly given, the incident was forgotten, and I’d like to think I’ve been a little more polite and considerate both on and off the internet as a result.Nested If’s the root of all evil
Ok so the title is an over exaggeration but I need a simple way to express how much I HATE when I see code with dozens of closing brackets because the developer was trying to fix the Unexpected $end error. Simple control structures not only help to keep code readable, it will also help in performance because you can escape code blocks with ease. To illustrate, below is an example of a function I have seen in my adventures in programming:
- function isAuthorized($resource)
- {
- $allowed = false;
- if ($_SESSION['loggedin'] == 1) {
- $user = $_SESSION['username'];
- if (!empty($user)) {
- $result = mysql_query('SELECT * FROM user_roles WHERE user = "' . $user . "'");
- if ($result) {
- while ($resArray = mysql_fetch_array($result)) {
- if ($resource == $resArray['role']) {
- $allowed = true;
- }
- }
- } else {
- throw new Exception('No valid results');
- }
- } else {
- throw new Exception('User name is invalid');
- }
- }
- return $allowed;
- }
Lets just ignore the security hole and performance issues with the MySql query, just look at the structure starting with the while loop. What if that user had 100 roles assigned and the role we wanted is the 1st record? We set $allowed to true on the 1st iteration then spend 99 iterations doing nothing. We can either break the loop or just add the $allowed to the condition. I suggest adding the $allowed to the loop which will clearly state that we are looking for $allowed.
- while (($resArray = mysql_fetch_array($result)) && !$allowed) {
- if ($resource == $resArray['role']) {
- $allowed = true;
- }
- }
Ok a little better we now have a chance of breaking the loop if we find the resource early. We can still optimize this function but returning true or false based off our conditionals:
- function isAuthorized($resource)
- {
- if (!$_SESSION['loggedin'] == 1) {
- return false;
- }
- $user = $_SESSION['username'];
- if (empty($user)) {
- throw new Exception('User name is invalid');
- }
- $result = mysql_query('SELECT * FROM user_roles WHERE user = "' . $user . "'");
- if (!$result) {
- throw new Exception('No valid results');
- }
- while ($resArray = mysql_fetch_array($result)) {
- if ($resource == $resArray['role']) {
- return true;
- }
- }
- return false;
- }
We gain a many advantages here. First PHP will not have to allocate memory for the $allowed and $user variables since they will not get called if the user is clearly not logged in. We also gain greater op-code usage by not having the parse read in else statements. The big advantage to this is how easy it is to read and make a change. Lets say we wanted to add a check for if the users session expired, by following the 1st example we would have to add a whole new block as follows:
- function isAuthorized($resource)
- {
- $allowed = false;
- if ($_SESSION['loggedin'] == 1) {
- if (date_add($_SESSION['loggedin'], '+30 min') < new DateTime("now")) {
- $user = $_SESSION['username'];
- if (!empty($user)) {
- $result = mysql_query('SELECT * FROM user_roles WHERE user = "' . $user . "'");
- if ($result) {
- while ($resArray = mysql_fetch_array($result)) {
- if ($resource == $resArray['role']) {
- $allowed = true;
- }
- }
- } else {
- throw new Exception('No valid results');
- }
- } else {
- throw new Exception('User name is invalid');
- }
- } else {
- throw new Exception('Session has expired');
- }
- }
- return $allowed;
- }
With our cleaned up structure we just add the following lines like so:
- function isAuthorized($resource)
- {
- if (!$_SESSION['loggedin'] == 1) {
- return false;
- }
- $user = $_SESSION['username'];
- if (empty($user)) {
- throw new Exception('User name is invalid');
- }
- if (date_add($_SESSION['loggedin'], '+30 min') < new DateTime("now")) {
- throw new Exception('Session has expired');
- }
- $result = mysql_query('SELECT * FROM user_roles WHERE user = "' . $user . "'");
- if (!$result) {
- throw new Exception('No valid results');
- }
- while ($resArray = mysql_fetch_array($result)) {
- if ($resource == $resArray['role']) {
- return true;
- }
- }
- return false;
- }
As we can see keeping the code structured helps us understand what a function is supposed to be doing, improves our opcode performance, and helps keep making changes to a function that much easier
Bye Bye GoDaddy
As I write this all of my domains are in the process of being transferred from GoDaddy (who I've used since they first hit the scene years ago) to NameCheap (I considered going with Gandi, but wanted to avoid pricing in Euros because my credit card company sucks so hard they blow).
Most of you know that I've been generally dissatisfied with GoDaddy from an image standpoint, but have generally let the inertia of "I don't want to go through the domain transfer process" carry me along. That all changed today -- I can overlook their shitty business practices. I can excuse their slut-tacular commercials as "sex sells (even domain names)", but I draw the line at supporting the Stop Online Piracy Act (SOPA, H.R. 3621) - This is an absolute piece of shit legislation that threatens the most fundamental principles of free speech by stripping away even the minimal end-user and content-provider protections of the DMCA. Further in chosing its technological weaponry SOPA also manages to jeopardize the DNS system, one of the most basic technical underpinnings of the internet as we know it.
That anyone can support this legislative disaster in the making baffles me. That a technology company can do so is unfathomable. Mr. Parsons has literally gone to congress, pointed an elephant gun at his testicles, and said "Go on, pull the trigger. I like the pain."
I am not usually a fan of Reddit, but they have a nice thread about GoDaddy supporting SOPA, and the ensuing mass exodus of even folks like me who were sticking with GD because of inertia. I have also reproduced GoDaddy/Mr. Parsons' statement supporting SOPA in its entirety below the break. They also mention the BYEBYEGD NameCheap coupon that inspired the title of this post.
Continue reading "Bye Bye GoDaddy"
New Look
Well as you can see, MANCHUCK has a new look. I switched over to Word Press because really, it takes a long time to build your own blog from scratch (which is what I was hoping to do with the old site). It took about a day to install and configure the new look. Hope you all enjoy
Shout out to Themetation for creating this theme. Thanks for helping save me some time with messing around with CSS
Dear ImageMagick: FUCK YOU.
Dear FAA/Aeronav...
Holy Hairballs - A Blog update! Dayum it's been a while!
So, what the hell do I want to talk about? Well, I want to expound for a bit on the FAA/AeroNav proposal to start charging for digital chart data. And, because this is my blog, I can!
Really everything I want to say can be said by an appropriate LOLCat:
Continue reading "Dear FAA/Aeronav..."
I Am A Former Radiation Patient
In 2006, my mom noticed a strange lump on the side of my neck. I went to see an ENT (an ear, nose, and throat doctor — but they call themselves otolaryngologists, because they went to a lot of school), and he took MRIs and CAT scans and whatever else, and the machines told him I had a cyst. He removed it in February, and upon performing a biopsy, he discovered that rather than a cyst, he had actually removed a benign tumor, called a pleomorphic adenoma. It was harmless, and it was removed, and life went on.
Until it came back. I went back to the ENT every six months for a checkup, to make sure the tumor didn’t come back. Well, this Spring, he was concerned that it had come back, and so he sent me to see a colleague. The new ENT confirmed that the tumor had, in fact, come back, and would need to be removed again. So, on July 18th, I had a second surgery to remove this tumor.
It is apparently very rare for this kind of tumor to come back; something like 1 in 20 do. The theory is that since the first doctor didn’t remove the tumor the way you’d normally remove a tumor (since he thought it was a cyst), some of the cells spilled and replanted. The second doctor, even though he was happy with how the tumor came out, was concerned about the same thing, since apparently you never really know what happened at a microscopic level, and maybe a couple of cells spilled out that he couldn’t see. In addition, the tumor grew in such a way that it wrapped around an important facial nerve. The second doctor was quite worried that this nerve might have been compromised during the surgery, and actually prepared me for that possibility. Thankfully, he’s talented enough — or I’m young and healthy enough — that there were no such side effects.
Still, the possibility existed that this tumor might regrow, and the doctor was very concerned about having to go in a third time. He essentially guaranteed that the facial nerve would be damaged if he had to operate again. So, he strongly recommended radiation, and sent me to see his colleague.
To make a long story short, after talking with both ENTs, the radiation oncologist, and my dentist, there was no way to choose not to have the radiation. The oncologist told me that the chances of the tumor coming back without radiation were 90%, but it’s more like 50% if I have the radiation.
So, on October 17th, I had my first radiation treatment. I felt virtually nothing for the first two weeks, except that around the end of the second week, Jack brought a cold home from day care. But I wasn’t better by Sunday night, so Carrie talked me into staying home that Monday to get better. The thing about radiation treatments, though, is that the body has a lot of work to do to recover from them, and what seemed like “just a cold” wound up keeping me out of school for a week because I was too sick and too weak to work. The cold actually got worse toward the end of the week, which is something I had never experienced before.
Monday of the fourth week, I went back to work, but by now the effects of the radiation had really started to take their toll. I was unable to make it through an entire hour and fifteen minutes of class. Thankfully that Tuesday was a day off, so I only had to make it through two more days, but that was enough, and I had to tell my chair that I needed some time off to recuperate.
It sounds like a dream to sit around at home for a few weeks while classes are going on, but I didn’t really get any time to enjoy it. Mostly, I slept or got nauseous. It became more difficult for me to eat or even to drink water, because I was sick so often. What I didn’t realize is that I had become dehydrated, and that Friday (of week 4) I wound up in the emergency room to get rehydrated.
I’ve been doing a little better lately, especially since I now appreciate the need to eat and drink. But today was my best day. Radiation lasts for 30 sessions, which works out to six weeks. The last session would have been this past Friday, except that the department was closed for Thanksgiving. So, #30 should have been yesterday, except that the machine was down. But, finally, this morning, I became a former radiation patient after treatment #30.
Among the paperwork the hospital sent me before starting treatment was this document, entitled “The Striking of the Gong”:
The completion of your radiation therapy treatments marks a milestone in your survivorship journey. The staff of the Department of Radiation Medicine believes that this accomplishment should be acknowledged: One way is through the ceremonial playing of a gong. On your last day of radiation treatment, you are welcome to strike the gong… Traditionally, the touching of a gong is thought to bring strength and good fortune.
I would hear the gong being struck a couple times a week during my treatment visits, and it became something to look forward to. Well, finally, today was gong day:
I still feel like crap, and it’ll be a while before I’m fully recovered. One of the worst side effects, besides all the sleeping and nausea, is the change to my taste buds. Many of my favorite foods taste wrong or bad because of the radiation. I haven’t been able to eat any bread products or tomato products. Ice cream tastes weird, as does anything with chocolate in it. I recently tried pineapple, and it was almost completely devoid of taste. They say that it will take about three weeks for taste to finally come back. Until then, I have become a huge fan of the Food Network, planning what sort of wonderful things I’m going to eat when I’m able to.
Soon enough, I’ll be back to work, back to drinking coffee and beer, back to being awake 18 hours a day instead of sleeping 15 hours a day, back to playing on the floor with Jack — back to normal. It’ll take some time, but I know that the recovery process started today. I invite you to ask me anything you need to ask me about radiation, especially if you or a loved one needs to go through it. It ends, and it gets better, and that’s the most important thing to understand.
Edited to add: The treatments would not have gone nearly as well as they did if not for all the dedicated staff at LIJ who worked so hard to make me comfortable. Special thanks go out to all the radiation techs (and of course I identified the musicians and the volunteer firefighter right away), to Nurse Diana, and to PA Jonathan. No one in his right mind would classify radiation therapy as “easy”, but these professionals made it as easy a process as anyone could wish for. Thanks.
One more edit: While writing this post, I was so careful to get all the technical stuff right, like timelines and whatnot, that I forgot what was really important. My wife Carrie and my mom both made huge sacrifices during these six weeks, to make sure I was eating and drinking, to make sure Jack got to day care and back, and to make sure I was comfortable. They worked harder, and took better care of me, than I ever expected to need. They were so awesome during this that their awesomeness became commonplace and expected, and I started to take it for granted. Well, let me say here, publicly, that I truly would not have gotten through all this without their love and hard work. I hope never to have to repay this debt.

