Friday, February 20, 2009

Subway Rumble - Part 1

Alright so, let me tell you about this fight I got in on the subway the 2nd week I was here. It’s nuts. Me and one of my roommates Nick went to a bar to watch the UFC fight. We went to this bar right next to Fenway, where the red sox play. The bar is right behind the “Green Monster”, the big wall in left field. Anyway, we watched the fight and I drank some beers but I was pretty straight (That’s another great thing about the subway, you can be totally blasted and still have a ride home, just make sure you take a piss before you leave… you may even wanna take two pisses).


Nick doesn’t drink, so he was sober the whole night and we headed back to the subway station about 12:30 at night. We watched some dude take a piss on the floor in the station, and get arrested… (Obviously he did not take two pisses before he left) Then the train came and we hopped on it to get home.




Let me kind of describe the trains, the Green Line (A,B,C,D are all Green Lines) is where I live, I live at the end of the C line (Called Cleveland Circle) but you can also take the B Line to Reservoir and there’s a little side dip that will get you home… or raped… it’s 50/50. The trains on the green line are more like trolley cars, but enclosed. The C line runs in the middle of this long road called Beacon that runs right into downtown. C Line trains have to stop at stop lights and shit, but they are riding on rails, the rails just run in the middle of the street, kind of like where the median would be. So, there is usually two cars to a train, and there is like a little middle part that is like an accordion so it can flex between the cars when the train goes through a curve.


When me and Nick got on the train the only spots left to sit were on the middle part and there was a kinda hot girl and this bald Butter Bean looking dude kinda dressed up. He had like a tweed sport coat and tie on with some dress pants and dress shoes. This guy was wasted, and he was trying to holler at this girl. Asking people for a pen on the train and being all obnoxious. So me and Nick were trying to kind of diffuse the situation, because we could tell this girl was uncomfortable and she was all by herself.




So anyway, we were just talking to this guy, asking where he came from, how much did he drink tonight and kinda laughing at him. The girl started to chirp in with little comments and he probably thought we were making fun of him. So this goes on for about 15 minutes and the ride home from the bar is about 25 minutes. All of a sudden this guy is just stone cold quiet for like 4 stops on the train, it was a good 5 minutes. I look over and this guy is like super-duper mean mugging Nick who is sitting across the aisle from me in a separate seat by the girl. Nick notices it too and so he starts smiling and is like “Hey man, you’re being awful quiet over there”, but this dude is still just super mean mugging him so eventually Nick is like “Alright man, you win the staring contest” and he looks back at me across the aisle. I smiled a little bit and started to change the subject, I asked if any of the other stops on that line were faster than just going all the way down to the end of the C-Line like I always did.


So all of a sudden while we are talking this big Butter Bean dude gets up and is like “fuck you fuckin boston college kids,” and starts walking toward Nick and leans back and throws the slowest haymaker I have ever seen in my life. It was like slow motion it went so slow. Nick just kind of moved out of the way and the guy hit the window and fell on top of him so I got up and somehow put this guy in some kinda 1/8th Nelson and grabbed onto the pole.


I was holding on for dear life...

Now Playing - Kanye West - Stronger

Thursday, October 30, 2008

JTemplates template file cached workaround

I've been using a lot of JQuery and JTemplates after reading a couple really helpful JQuery and MVC posts at Encosia.com. One problem I ran into while doing some development on a new .Net MVC Project that was using JQuery extensively was that my template files were being cached by my browser. I tried clearing the cache but that wasn't helping, so here's a workaround I came up with.


If you take a look at how JQuery's $.ajax(...) function handles the caching problem you can see that they append a random query string parameter to each request.




So that is what I basically did to workaround the caching problem with the template files. I created a function called cacheBust() that just returned the current times milliseconds value and used that to generate my random query string. Here's some sample code:





function cacheBust() {return new Date().getMilliseconds().toString();}

function GetTimeEntries(day) {
// Show the loady
showLoady();

$.ajax({
type: "GET",
cache: false,
url: "/TimeEntry/" + day.replace(/\//g, "-"),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// This method loads the HTML template and
// prepares the container div to accept data.
$('#TimeWrapper').setTemplateURL('/scripts/timeentry.vw?_=' + cacheBust());

// This method applies the JSON array to the
// container's template and renders it.
$('#TimeWrapper').processTemplate(msg);

// Hide the loady.
hideLoady();
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
// typically only one of textStatus or errorThrown
// will have info, I'm not using either.
hideLoady();
$('#TimeWrapper').empty();
$('#TimeWrapper').append("<p class='errord'>There was a problem loading the data from the server. Sorry I got nothing else.</p>");

}

});
}


And now we get the most up to the second versions of our templates. Once I'm done with development it will be beneficial to have the templates be cached. I figure once that happens I'll change my cacheBust() function to return a constant (something like, "ItCompilesSoShipIt").



Now Playing: Snow Patrol - Open Your Eyes

Monday, October 6, 2008

Powershell Count Files By Regex Match on Content

Being a Powershell Winter Scripting Games Top Scorer for both the 2007 and 2008 Scripting Games I have to keep my skills fresh. Never know when you need to whip out an extra dirty little script to count how many T's are in a text file.

Scripting languages always give me a dirty feeling when I get done and look at my code. I'm a fan of what Code Complete describes as the Primary Imperative of Software Engineering; Managing Complexity. Solving something with a scripting language always makes we want to write something using the least amount of characters possible. Comments, descriptive variable names and consistent formatting usually go right out the window along with the ability to come back a month later and figure out what is going on in the script, let alone try and tell a co-worker what is going on.

That being said, here is a tiny powershell script to count files based on a Regex match of their content. Don't worry, I took the time to comment it a little bit and even have some pretty descriptive variable names. It originally was just one line for the specific task I needed to get done. I was looking for the number of xml files with a specific value in a set of directories.


# Create Parameters for our script.
# TODO: Make a helpful usage reply when no parameters supplied.
Param( [String]$path="./",
[String]$filter="*.txt",
[String]$match=$(throw "Regex Pattern required."),
[switch]$searchSubs)

$reg = [regex]$match;

if ( $searchSubs )
{ # Get the files matching the passed in path/filter
dir -path $path -filter $filter -recurse
# Loop through each and look for a match of the Regex.
% {
$in = gc $_.FullName; $reg.Match($in).Groups[1].Value
} group #Group the Values.
}
else
{ dir -path $path -filter $filter
% {
$in = gc $_.FullName; $reg.Match($in).Groups[1].Value
} group
}

Here is some sample usage:

./FileMatch.ps1 -path c:\somewebsite\fileUpload -filter *.xml -match 'field value="(.*?)" name="blah' -searchSubs

You can even mix up the parameters if you want. Powershell Rocks!

Now Playing: Jason Mraz - Curbside Prophet