Wednesday, December 12, 2012

Messing up with command-line arguments in Bash: $*, $@, "$*", "$@",…

Figured out a stupid issue that plagued a bit of code I had for quite a while.  Didn't care about it enough to google it till recently tho.

Quoting the source:
It’s stupid, but it took me a good hour to figure this out, so maybe I’m not the only one…
I’ve recently had a problem with command-line arguments in my Java program. The problem was that command line arguments containing spaces were parsed incorrectly, i.e. chopped into individual arguments. My initial suspect was gnu.Getopt package I use for parsing arguments, but as it turned out I was wrong.
The real culprit was a shell wrapper script I used to wrap my java code. The code was the following:

java -some parameters- -programm .class- $@
 
See the problem? I didn’t. You need quotes around "$@" in which case the parameter gets expanded to: "$1" "$2" "$3"... With no quotes the shell expands it to $1 $2 $3, hence all parameters containing spaces get chopped (also globbing takes place in this case).
BTW: There’s also "$*" which is used to combine all parameters into a single one, i.e, "$*" expands to "$1c$2c$3c..., where c is $IFS (or space). Here it’s also important to have it enclosed in quotes.

Monday, October 1, 2012

Removing 'Ubuntu Desktop' from unity's Panel Bar for Ubuntu 12.04

In any editor that can edit binary data (emacs/vi), open

/usr/lib/unity-2d/plugins/panel/libpanelplugin-appname.so

then search for 'Ubuntu Desktop' and replace the characters with spaces.

Wednesday, August 8, 2012

QA Notes

Testing

  • Who is our largest QA audience?  Our users.  There's no escaping the fact that our users will find more bugs than our QA team.  Therefor it is in our best interest to capture what they are doing with logging and sane error messages.  There needs to be logging servers which handle the logs coming in from various environments (QA/Prod/Various different versions of prod) that allow us to grep back through and find out exactly what it was that the user was doing when he got the error. We can then replicate what he was doing in QA with debugging on, but if we are logging all error messages, this might not even be necessary.  Better exception handling is also a must.

Tests

  • Unit tests - Tests developers write to make sure code isn't broken, no syntax errors, handles all edge cases etc.
  • Acceptance Tests - Supposed to be written by Product Team (yes, they're supposed to be developers, they are supposed to have the good idea's for the product and understand how the features are going to work into the current code base), ensure that the code that the developer wrote is what the actually wanted in the feature
  • Integration Tests - Test that the code works correctly in the entire stack, a replica as close as possible to production

More on Assertive Programming

(from The Pragmatic Programmer: From Journeyman to Master by Andy Hunt and David Thomas)

There is a common misunderstanding about assertions, promulgated by the people who write compilers and language environments. It goes something like this:

Assertions odd some overhead to code. Because they check for things that should never happen, they'll get triggered only by a bug in the code. Once the code has been tested and shipped, they are no longer needed, and should be turned off to make the code run faster. Assertions are a debugging facility.  
There are two patently wrong assumptions here. First, they assume that testing finds all the bugs. In reality, for any complex program you are unlikely to test even a miniscule percentage of the permutations your code will be put through (see Ruthless Testing). Second, the optimists are forgetting that your program runs in a dangerous world. During testing, rats probably won't gnaw through a communications cable, someone playing a game won't exhaust memory, and log files won't fill the hard drive. These things might happen when your program runs in a production environment. Your first line of defense is checking for any possible error, and your second is using assertions to try to detect those you've missed. Turning off assertions when you deliver a program to production is like crossing a high wire without a net because you once made it across in practice. There's dramatic value, but it's hard to get life insurance.

Python Utils

http://wiki.python.org/moin/PythonTestingToolsTaxonomy

Copy Pasta

You cannot escape discovery. The world is full of idle people reading books, and they are only too glad to act as detectives; they please their miserable vanity by showing their alertness, and are proud to hear witness against you in the court of parallel columns. You have no safety in the obscurity of the author from whom you take your own; there is always that most terrible reader, the reader of one book, who knows that very author, and will the more indecently hasten to bring you to the bar because he knows no other, and wishes to display his erudition.

Monday, May 14, 2012

Blazing Saddles scenes

20:35 - Harumph scene
46:25 - Mongo punches horse scene

Thursday, March 29, 2012

Make Firefox work with dark themes in Gnome/GTK/Unity

Google and stackoverflow like to fuck with the colors for their search boxes.. after fighting with greasemonkey for the whole day I finally gave up and installed Stylish then added this as a global stylesheet:

input, textarea {
    background: #000000 ! important;
    color: #FFFFFF ! important;
}

In conkeror, simply changed everything with a stylesheet in the .conkerorrc file (or folder).
in .conkerorrc/main.js


let (sheet = get_home_directory()) {
    sheet.appendRelativePath(".conkerorrc/stylesheets/input_color_fix-user.css");
    register_user_stylesheet(make_uri(sheet));
}

in .conkerorrc/stylesheet/input_color_fix-user.css


input, textarea {
    background: #000000 ! important;
    color: #FFFFFF ! important;
} 
 

Tuesday, March 27, 2012

Ubuntu, Unity, Xmonad and the missing appmenu

Finally figured out how to remove the global appmenu in unity that causes the text based menu at the top of my apps to disappear in xmonad.  Have to remove indicator-appmenu.

sudo apt-get remove indicator-appmenu

Monday, March 26, 2012

Changing theme colors in Unity for Ubuntu without installing gnome-tweak-tool

gnome-tweak-tool seems to want to install all of gnome for it to work.  Instead just edit these files:

/usr/share/themes/[theme]/gtk-3.0/settings.ini
 
/usr/share/themes/[theme]/gtk-3.0/gtk.css 
 
/usr/share/themes/[theme]/gtk-2.0/gtkrc 
 
source

Sunday, March 4, 2012

Geben CheatSheet

istep into
ostep over
rstep out
bset breakpoint at current line
uunset breakpoint at current line
Bbreakpoint menu
(set conditional break points, call breakpoints, etc)..
investigate later
grun
qquit
eevaluate php
crun to current line (run to cursor)
C-c fopen file in geben, useful for setting
breakpoints in files further down the call stack
(use after geben has started with a call to
http://yoururl/?XDEBUG_SESSION_START)