We’ve all come across the time where we’ve needed to pull data from a database and dump it to a CSV file for backup or reporting purposes. There are many challenges in doing so: escaping commas, escaping double strings, adding newlines, etc… It seems like I solve this problem many times on my own by using a different delimeter such as a semicolon or tab. However, after using Excel on a Mac for awhile, I began to realize that using an alternate delimeter for a csv file requires a few extra steps to make the data display correctly in Excel.

Then I came across two PHP functions: fputcsv and fgetcsv.

fputcsv will store an array of strings to a file and automatically handle any additional escaping and newlines.
fgetcsv will do the opposite and GET an array of strings from one line of a csv file.

In my case, I only wanted to output a string to the browser with an attachment header so that it would prompt a download of a csv file. I actually learned a new trick as well:

1

$output=fopen('php://output','w');

I can fake a file-pointer by specifying a file location of php://output.

Ever since being introduced to Nicole Sullivan’s OOCSS, I’ve changed the way I develop CSS code. While I do not believe in everything that OOCSS offers, the main takeaway from me is introducing more structure and reason into my code.

Strictly speaking…there’s nothing wrong with that code. But the one thing that should stand out is its lack of re-usability. It’s pretty easy to write code specifically to accomplish a task on a page or closely-match a page comp, but OOCSS forces you to think about scalability. That is its greatest strength.

Here is how I might re-write that code in OOCSS

1

2

3

4

5

6

h2{font-size:110%;}

.headerWithBorder{border-bottom:1pxdashed#000;}

.mod{padding:10px;}

.size1of2{width:50%;}

.unit{float:left;}

.lastUnit{float:none;width:auto;display:inline-block;}

1

And the HTML code:

1

2

3

4

5

6

7

8

9

&lt;div class="mod"&gt;

&lt;h2 class="headerWithBorder"&gt;Title of webpage&lt;/h2&gt;

&lt;div class="unit size1of2"&gt;

&lt;p&gt;Content!&lt;/p&gt;

&lt;/div&gt;

&lt;div class="unit size1of2 lastUnit"&gt;

&lt;p&gt;Content!&lt;/p&gt;

&lt;div&gt;

&lt;/div&gt;

OOCSS gives you the concept of gridding for free. A grid can consist of one or more elements that are floated and fit next to one another in defined fragments. For example, I’ve implemented a grid of .size1of2, which allows me to put two elements side-by-side in a reusable fashion site-wide. Pretty cool huh?

I’ll go into more detail about OOCSS in future blog posts and share some tips and tricks I’ve learned along the way. Stay tuned!

Election Day: the end of months of political banter, negative ads, and social media politicians. I am actually building a house made entirely of political flyers I’ve received in the mail this election year. I counted well over 200. TWO-HUNDRED pieces of mail, lobbying for MY vote. In Michigan, we are fighting over whether renewable energy should be enforced, yet we are wasting trees, ink, and the environment to print out crap that very few read.

The only thing worse than 200 flyers is 200 friends on social media crop-dusting my news feed with LOLz and Internet memes, expressing political interests. Has “Free Speech” gotten out of hand? Why do people get so passionate about this stuff for only four months every four years? Don’t get me wrong, I’m not promoting that they go out and constantly talk politics– that’ll land them square in the “fuck if I care what you say” list of friends—but rather, do something about it or shut up. Look, if you’re in favor of abortion now, odds are you’re not going to change that. Therefore, you know you’re voting democrat no matter what. Do it and shut up.

Instead, many people find it necessary to post links and pictures that relate to their beliefs, while ignorantly believing that no one will respond against it. Here is how most of those conversations on FB go:

Amy: OMG Romney says he is a business man, but he will ruin this country. He’s MORMON!

Joe: Dude, do you even know what Mormanism is? You act like he’s Jewish or something.

Ezikiel: What’s wrong with being Jewish?

Joe: No hard feelings, Zeke. Just proving a point.

Amy: Mormanism = moronism LOL

Joe: Fuck this country, we’re fucked.

Amy: Not if Obama is in office. Obama cares about me PERSONALLY!

Ezikiel: That’s because you shhticked him last night

Joe: Romney FTW!

….

Fun isn’t it? We get it, you love your political candidate so much, you’d lose a few FB “friends” over it. Why not go back to how it used to be and put your bumper sticker on your car and a sign on your lawn? People will know where you stand, but you don’t have to shove it in everyone’s faces. If you love your candidate as much as you lead the social media to believe, you better be watching CSPAN and every speech/game show/talk show/Saturday Night Live/ESPN game the president is a part of. If not, keep it all to yourself. Thanks.

The secret to a successful productive life is routine. It sounds simple enough, but we as humans despise routine. It’s incredibly difficult to form one and even more difficult to maintain it–yet, we need it. We are creatures of habit and can function more efficiently when we know what is coming next.

I am discovering that the most difficult routine to follow is a workout regimen. It is next to impossible for me to workout in the evenings, so I am attempting to workout in the morning before work. I know once my alarm goes off in the morning (an hour before it normally does, now that I’m working out) I’m going to do everything in my power to find an excuse to fall back asleep.

The secret to productivity is routine. The secret to weight loss is a healthy lifestyle, including a balanced diet and exercise. 6AM…here I come! Wish me luck.

New features are not always better features. I admire what Microsoft is doing and hope that these new changes bring about a better user interface overall. My instinct tells me that the new interface does more harm than good, but I’ll withdraw my comments until I can actually experience it.

What a battle it will be this year. I think MSU and UM are the top two teams in The Big 10…it just sucks that they’re in the same division. Love or hate UM and State, they both have great teams and fatal flaws. The battle will be very entertaining in years to come!

I came across an issue while developing a responsive website for JSTOR this past week. It appears that if you use a long text string in an input box, Mobile Safari and Blackberry will overflow the text below the input box and beyond to display the full search string. I’m not sure if this is a bug or intentional, but here’s what I did to fix it:

1

2

3

4

5

6

7

8

&lt;script type="text/javascript"&gt;

$(document).ready(function(){

if($('#idOfInputBox').length){

$('#idOfInputBox').wrap('&lt;div id="idOfInputBoxWrapper"&gt;');

$('#idOfInputBoxWrapper').css({'overflow':'hidden'});

}

});

&lt;/script&gt;

Now you can obviously do this with HTML/CSS by itself, but in my case I added this code conditionally only for mobile viewports/touch screen devices since that’s really where the issue was. If you’re following suit, just wrap the code inside of $(document).ready() with:

1

if(window.innerWidth&lt;=1023){}

. This is just a simple way of *assuming* the users is on a non-desktop environment. There are obviously other ways of detecting it for certain, but I won’t get into that here.