Friday, July 6, 2012

PHP: The Language You Love And Hate

tl;dr

I use PHP and find that it works well for most jobs, but for others, not that great. Use the language that best fits the job!

PHP in the critic spotlight lately

Quite a few "PHP is good" and "PHP is bad" posts lately; even from people who, like me, use PHP, love it, and also hate it, have come out to say a thing or two

Well, if you read veekun's post, he's got something going there that I really want to point out, even though it really wasn't meant for the way I'm thinking about it; it's the toolbox. As engineers, it is our responsibility to build things. You can hammer in a nail with a wrench (haven't we all done that once before?), but obviously you should have used a hammer. Heck, you can even use a nail gun if it does the job better.

Languages Are Engineers' Tools In Their Toolbox

No, really. The more you know, the more knowledgeable and versatile you will be. And obviously if you have that knowledge, you'll know what "tool" is the right one. Steve Yegge's post on interview phone screens tells a wonderful tale of this. 
"Many C/C++/Java candidates, even some with 10+ years of experience, would happily spend a week writing a 2,500-line program to do something you could do in 30 seconds with a simple Unix command."
I'll let you read the article for the complete story, but it essentially explains that you can do a search and replace in many ways, but if you don't know how to use grep or python or even php you would be wasting lots of time on a quick job.

Now, I'm not saying to go and learn all the languages out there. I'm just saying that maybe knowing a little bit of a compiled language, scripting language, and a frontend language would help you understand better the full stack of whatever you are working on.

Wednesday, April 18, 2012

FezBook Update: Added a Java Library

FezBook Java Library

I shouldn't need to say anything more than the title right? Well anyhow, my little FezBook Library that I've been using is also now available in java. Exciting! You can check it out on my github FezBook repository.

Why?

Well, why not? Hehe :) Honestly, I've been working on a backend service and java seemed like a nice fit. I haven't had the chance to drop a javadoc anywhere, so be patient. I may just end up adding the phpdocs and javadocs in the repository itself.

ymmv

Well, just try it and see. Same thing with the PHP version, you'll need to do your own OAuth or already have your access token. Enjoy!

Wednesday, February 29, 2012

Grepping for Control Characters

"\t Will Not Work"

Plain and simple, send a ^v before the control character you want. ;)

What happened there?

Say for example you want to grep for lines in a file that have tabs. You've tried grep '\t' yourfile to all avail and it's just not working. Well, you're close, you actually want to send a tab. To do so, use ^v (control + v) and then send an actual tab:
grep '^v[tab button]' yourfile

This seems to be a common question from people and a coworker just dropped in to ask, so here ya go! Cheers!

Thursday, December 8, 2011

Python CSV Parsing

If you haven't realized already, I live and breathe in a command-line world. That's not even just talking about my work-related things; even when helping out helping out someone who is running Windows I will do majority of the things I need to do in the cmd prompt. Anyhow, I'm starting to ramble...

I also sporadically get some data sent to me in csv (or I will convert it to csv format). Now, if you have done this enough times, you'll obviously want to have some sort of csv parser. And what do you know, voila! I've got a simple one here for all of my command-line junkies out there!

csvreader.py is short enough to be available as a short gist on github. --My first activity on github by the way!

I'm sure you'll all find a nice way to use that. If you were curious what I ended up doing, well here's a generic code snippet: for f in `python csvreader.py tmp/b.20111208_1042.csv 0`; do echo $f; php postInfo.php /mnt/$f; done;

Cheers!

Sunday, October 2, 2011

Decoding the "Ghost in the Wires": Chapter 01

Quick Intro

I recently just finished Kevin Mitnick's Ghost in the Wires. Excellent read! I highly recommend! The cryptic text got my attention and I decided I wanted to give a crack at them. Let's see how far I can get before I give up.

01 Yjcv ku vjg pcog qh vjg uauvgo wugf da jco qrgtcvqtu vq ocmg htgg rjqpg ecnnu?

I wrote a simple Caesar cipher C program, called rotn that I can pipe in some text.

for n in {1..26}; do cat ~/tmp/ghost01 | rotn $n; done
Zkdw lv wkh qdph ri wkh vbvwhp xvhg eb kdp rshudwruv wr pdnh iuhh skrqh fdoov?
Alex mw xli reqi sj xli wcwxiq ywih fc leq stivexsvw xs qeoi jvii tlsri geppw?
Bmfy nx ymj sfrj tk ymj xdxyjr zxji gd mfr tujwfytwx yt rfpj kwjj umtsj hfqqx?
Cngz oy znk tgsk ul znk yeyzks aykj he ngs uvkxgzuxy zu sgqk lxkk vnutk igrry?
Doha pz aol uhtl vm aol zfzalt bzlk if oht vwlyhavyz av thrl myll wovul jhssz?
Epib qa bpm vium wn bpm agabmu caml jg piu wxmzibwza bw uism nzmm xpwvm kitta?
Fqjc rb cqn wjvn xo cqn bhbcnv dbnm kh qjv xynajcxab cx vjtn oann yqxwn ljuub?
Grkd sc dro xkwo yp dro cicdow econ li rkw yzobkdybc dy wkuo pboo zryxo mkvvc?
Hsle td esp ylxp zq esp djdepx fdpo mj slx zapclezcd ez xlvp qcpp aszyp nlwwd?
Itmf ue ftq zmyq ar ftq ekefqy geqp nk tmy abqdmfade fa ymwq rdqq btazq omxxe?
Jung vf gur anzr bs gur flfgrz hfrq ol unz bcrengbef gb znxr serr cubar pnyyf?
Kvoh wg hvs boas ct hvs gmghsa igsr pm voa cdsfohcfg hc aoys tfss dvcbs qozzg?
Lwpi xh iwt cpbt du iwt hnhitb jhts qn wpb detgpidgh id bpzt ugtt ewdct rpaah?
Mxqj yi jxu dqcu ev jxu ioijuc kiut ro xqc efuhqjehi je cqau vhuu fxedu sqbbi?
Nyrk zj kyv erdv fw kyv jpjkvd ljvu sp yrd fgvirkfij kf drbv wivv gyfev trccj?
Ozsl ak lzw fsew gx lzw kqklwe mkwv tq zse ghwjslgjk lg escw xjww hzgfw usddk?
Patm bl max gtfx hy max lrlmxf nlxw ur atf hixktmhkl mh ftdx ykxx iahgx vteel?
Qbun cm nby hugy iz nby msmnyg omyx vs bug ijylunilm ni guey zlyy jbihy wuffm?
Rcvo dn ocz ivhz ja ocz ntnozh pnzy wt cvh jkzmvojmn oj hvfz amzz kcjiz xvggn?
Sdwp eo pda jwia kb pda ouopai qoaz xu dwi klanwpkno pk iwga bnaa ldkja ywhho?
Texq fp qeb kxjb lc qeb pvpqbj rpba yv exj lmboxqlop ql jxhb cobb melkb zxiip?
Ufyr gq rfc lykc md rfc qwqrck sqcb zw fyk mncpyrmpq rm kyic dpcc nfmlc ayjjq?
Vgzs hr sgd mzld ne sgd rxrsdl trdc ax gzl nodqzsnqr sn lzjd eqdd ognmd bzkkr?
What is the name of the system used by ham operators to make free phone calls?
Xibu jt uif obnf pg uif tztufn vtfe cz ibn pqfsbupst up nblf gsff qipof dbmmt?
Yjcv ku vjg pcog qh vjg uauvgo wugf da jco qrgtcvqtu vq ocmg htgg rjqpg ecnnu?

Did you see the decrypted text? These should be fun. Let's see how long it will take for me to crack the next chapter. 8)

Oh, and yes I will publish the code for my Caesar cipher program for those curious. Just give me some time, I've been fighting to not open a github account, but I think that's a decent option as of now.

Sunday, September 18, 2011

Pyweek Post Mortem

Pyweek Was Brutal

Pyweek: a week long contest to develop a game in python. Sounds fun right? I thought it did. I'll tell you right now, that it was brutal; but ultimately, even though I didn't even submit my code for review, I think I accomplished a lot.

Pyweek Objectives

You have one week to develop a game in python. The contest's theme is voted on one week before the contest starts. This keeps things fair so there is nobody working on their projects before the contest starts. You are allowed to use any libraries specified on pyweek's rules page. All graphics and music must be created by you for the contest. That's about it in a nutshell, there's a lot more detail on the pyweek site.

My Objectives

  • Learn a python game library.
    Yes, that's right, I entered a contest to learn. I like challenges and feel like I needed something like this to push me to learn.
  • Survive.

You really need to use the entire week

One week. That's all you get. From 00:00 UTC September 11 until 23:59 UTC September 17 is all the time you will get. Now, to paint a picture of my week, here was what my schedule looked like:
Sunday: housework all day, ~10pm EST start some pyweek work write up some game ideas
Monday: work -- start getting sick, though a little bit of pygame learning
Tuesday: work -- still sick
Wednesday: work --still sick
Thursday: work --still sick, but able to do a little bit of pygame tutorials to keep learning
Friday: work - pyweek work
Saturday: pyweek work
Fighting a cold for time is seriously an uphill struggle. If you're sick, stay in bed to rest up.

A Failure at Pyweek, A Success At Learning

So as I stated earlier, I never even submitted my code for review. I was not able to get as far as I would have liked to, though for my objectives, I think I did well. The theme for Pyweek was "mutate"; I had a basic idea and I tried to keep things simple, but apparently not simple enough. Well, not simple for someone who is just learning the pygame library.
I learned a lot in this short time and I am ultimately happy that I at least have something a little bit playable. Crappy, yes. But hey, I made it and I made every piece of it; from code to background music, to little character gifs, I made them all. And for that reason, if someone ever asks me if I've ever created a game, "why yes! yes, I did!" You can checkout my Pyweek diaries here and check out all of the entries here. There are some really awesome games out there, go check them out! Congrats to all Pyweek contestants!

Wednesday, August 3, 2011

Python: Reading and Running Commands From A File

So I recently came across a broken process that needed some manual re-running. I was able to search through the log files and then see what part needed to be re-run. I ended up with a new data file (that I modified) to be a list of each command that failed for each iteration. So, the file looked something like this:
/path/to/program -option x -site a
/path/to/program -option x -site b
...
/path/to/program -option x -site z



Using a bash for line in `cat command.file`; do $line; done would not work since I would end up with a
-bash: -option: command not found
-bash: x: command not found
-bash: -site: command not found
error. So, here's some quick Python that can get the job done:

import os

f = open('/tmp/tmp-fix.commands')
for line in f:
    print line.rstrip()
    os.system(line.rstrip())


Yay for saving me some time! Cheers!