How to break out of an exit popup in Firefox

Ever gone to a site and tried to close the window/tab and instead of closing, you get a popup? “Wait! Don’t go yet! Come back and sign up to my email (legit spam) list!”.

It looks something like this:

A Typical Exit Popup
A Typical Exit Popup (Very Annoying)

And keep trying to get your ass outta there, and each time it gets more & more frustrating, because the site won’t let you close the damn window.

On Firefox, just go to preferences (Mac = Command + comma), Content tab, and uncheck “Enable Javascript”. A-like so:

Then close the window. Then you can re-enable javascript by re-checking the box.

I don’t know about other browsers because I really don’t use any others.

Why you should NOT use short tags in PHP

Where’s My Damn Emulator?

So I was trying to find a good SNES emulator for Mac. I read somewhere that Snes9x works for OSX, so I went to the site and then the downloads page to find one to… well, to download. The page started out “Here is a list of all the known available mirrors for Snes9x…”, but then it was an empty list.

I thought of two possibilities. Either the list contains exactly zero available mirrors, or something is wrong with the page. It struck me as rather odd that the site would put up an empty list of download mirrors for its own product, so I did some investigative research to check out possibility #2.

Note that the site is built in PHP. Here’s the non-hyperlinked URL for the downloads page: http://www.snes9x.com/downloads.php

Here’s a snippet from the page source:

Here is a list of all the known available mirrors for Snes9x. If a mirror is
not listed on this page, it either does not exist or the web peon doesn't know it exists.



Notice the foreach loop and the stuff? That’s the culprit.

PHP – A Short Word on Tags

PHP “tags” are opening and closing bits of code that let the machine know when text should be evaluated as PHP code, and when it’s not code (e.g. just “normal” text).

This is a standard opening PHP tag:

...and this is a closing tag:
?>

The idea is that everything in between the opening & closing tags is evaluated as PHP code & executed (in this case by the web server).

Also, note that when viewing a site built on PHP, you will never be able to see the PHP code! The web server will execute that code, then spit out the results to your screen. The results are what you see, only after the code is executed. Enter short tags...

Short Tags Suck Ass and Should Die

Remember the standard opening tag in PHP? Well, one day some genius came along and decided that he could save a whole 3 fucking keystrokes by just removing the letters "php", so the optional "short tag" was invented. Now, "<?php" could be shortened to just "<?". Absolute genius.

Then he decided to improve upon that and add the "echo shortcut", which is just the short opening tag followed by an equals sign. It's used like the echo function.

Here's the standard opening PHP tag, echo statement, and closing tag:

... and for comparison, the echo shortcut:

The problem is, not all servers support PHP short tags. So code that's working fine on one server might break when moved or copied to another server. Or maybe the sysadmin decides to disable short tags for whatever reason. Or a new version of PHP is installed.

Then crap like the above happens, and Nathan doesn't get his list of download mirrors for Snes9x, and the world is a bit worse of a place in general. Don't be an asshole. Don't use short tags.

Also, I've written a script (in Perl) called php_fixxer.pl. If you have PHP code with short tags, please backup your code, then download this & run it on all your code. It's called "fixxer" because if it has short tags, then it's as good as broken.

Oh, by the way: I'm not responsible for anything you screw up with this script. I told you to back up your code anyway. I do, however, accept full responsibility for any and all productive enhancements made possible by use of it.

Meanwhile...

Oh yeah, back to the above site... the page pretty much works, just one part of it is broken. Unfortunately, it's the part that's the reason for the existence of the page. Since this is the only PHP code that I am able to see from my browser {see note above if that doesn't make sense}, that probably means:

1) The whole file doesn't make use of short tags, just some of it.
and
2) If they convert these to standard PHP tags (no shortcuts), then this page should start working again, and I will be able to see my download mirror URLs.

Greasemonkey script to remove ‘Who to follow’ box on twitter.

Note: It’s now April 2015. This is really old & probably won’t work anymore. But I don’t like removing old content, so I’ll keep this post up anyway

Here’s a Greasemonkey script to remove the “Who to follow” (aka “recommended users”) box on twitter.com.

It’s annoying as hell and way too facebookish.

 


// ==UserScript==
// @name No Recommended Twitter Users
// @namespace http://ngmarley.com/
// @description Remove 'who-to-follow' box on twitter.com.
// @include http://twitter.com/*
// ==/UserScript==

function disable() {
location.href="javascript:(function(){ $('#recommended_users').remove(); })()";
}
disable();
window.addEventListener("hashchange", disable, false);

Or just get it here.

If it doesn’t work, let me know & I’ll try & fix it or something.

photo credit

Mac OS X – madplay mp3 player

This was originally posted on my old blog, ngmarleyDOTnet, on May 8, 2009 @ 11:20 CST. That blog is now defunct and the content is slowly being absorbed into this one. I pretty much do use iTunes exclusively on my Macbook now, but wanted to preserve this for posterity.

I’m not a huge fan of iTunes. On my Linux systems, I use a command-line MP3 player. I simply type the names of the files I want to play as arguments.

By contrast, I have to click around about 17 different times to play the songs I want in iTunes, including clicking around in the “open file/folder” dialog box (because Apple apparently believes the average Mac user too stupid to be able to type the absolute path to the file(s) on disk, so they don’t offer that as an option). The UI is, to me, insufferable. All I want to do is play a few songs, quickly. Seriously, it should take less than 2 seconds to do this.

More stuff I hate about iTunes:

  • the iTunes store. Which can’t be disabled or hidden (not very well, anyway)
  • the Genius Sidebar (which can be hidden, but is nevertheless annoying)
  • I’m sure there’s more, but I’m getting irritated just thinking about iTunes

I attempted to compile the current source release of madplay, and was able to do so after patching audio_carbon.c, but didn’t get any audio output.

Finally I was able to install this using fink, but then received this error:


[root@lorien ~]# madplay
dyld: Library not loaded: /sw/lib/libintl.1.dylib
Referenced from: /sw/bin/madplay
Reason: image not found
Trace/BPT trap

At first glance it appears as though I need to install libintl, but I went poking around in the fink lib directory /sw/lib. Apparently I already had a couple of versions of libintl installed (both static and dynamic), but none to match the version above. Of course this was easily fixed with a symbolic link:


[root@lorien lib]# ln -s libintl.dylib libintl.1.dylib
[root@lorien lib]# logout
[ngmarle@lorien Mana]$ madplay
Usage: madplay [OPTIONS] FILE [...]
Try `madplay --help' for more information.

Now I have all the functionality of my favorite cmd-line mp3 player on my Macbook.

*note: I was able to compile/install mpg123 from source, but the pause function put on a 1-second infinite loop instead of actually pausing. I also had to modify the mpg123 source to be able to exit the player without having to kill the process from an external terminal window.

The below is other debugging I was using: “otool -L” is like “ldd” on Linux. This will list the dynamic dependencies (shared libraries on which an executable is dependent) for an executable.


[root@lorien ~]# otool -L /sw/bin/madplay
/sw/bin/madplay:
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 136.0.0)
/sw/lib/libintl.1.dylib (compatibility version 2.0.0, current version 2.1.0)
/sw/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/sw/lib/libmad.0.dylib (compatibility version 3.0.0, current version 3.1.0)
/sw/lib/libid3tag.0.dylib (compatibility version 4.0.0, current version 4.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.1)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 32.0.0)

check gmail from command-line on Mac OS X

This was originally posted on my old blog, ngmarleyDOTnet, on Apr 19, 2009 @ 18:47 CST. That blog is now defunct and the content is slowly being absorbed into this one. I’ve rewritten this one just a bit to make it better.

I bought a new Macbook last week (several weeks ago, when this post was originally written) for my anticipated travels. I wanted something both lightweight and stable. For several reasons, I like to check my gmail using the mutt email client (command-line based).

  1. I don’t like the web interface.
  2. Command-line is faster.

Ok, maybe only 2 reasons.

I was able to compile mutt with imap, smtp, and SSL support and with header caching (had to install gdbm library as a prerequisite for header caching). Here’s the configure line I used:

./configure --enable-imap --enable-pop --with-gss --with-ssl --with-sasl --with-regex --enable-hcache --enable-smtp

The gmail connection info needs to be added to the ~/.muttrc config file:

set move = no
set quit = yes
set copy = no
set recall = no

set imap_user = "my_email.address@gmail.com"
set imap_pass = "Sup3rS33krit"
set smtp_url = "smtp://my_email.address@smtp.gmail.com:587/"
set smtp_pass = "Sup3rS33krit"
set from = "my_email.address@gmail.com"
set realname = "Nathan Marley"

set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed = "+[Gmail]/Drafts"
set record = "+[Gmail]/Sent Mail"

set header_cache = ~/.mutt/cache/headers
set message_cachedir = ~/.mutt/cache/bodies
set certificate_file = ~/.mutt/certificates

set sort = 'threads'
set sort_aux = 'last-date-received'

hdr_order Date From To CC

Now I can just open terminal, type ‘mutt’, and I’m checking my email. What’s better — I have a script (written in Python) that I use to check whether or not I have any new messages, and if I do, list the sender and how many messages from each sender. So I don’t even have to spend the 2 extra seconds to fire up mutt if I don’t need to.

make a universal binary on OSX 10.6 – Snow Leopard

125244997_6af3d42e86_z

This post describes how to create a “fat binary” on Mac OS X. If you’re using Snow Leopard, I don’t know why you’d want to make one of these, except maybe to compile for distribution to an older OS version (Leopard) or something. In fact, I can’t even remember why I wrote this, but I wrote it some time last fall or winter and thought I’d go ahead and post it now since I’d already spent some time working on it.

It’s not hard to create a universal binary on Mac OS X – these instructions are for Snow Leopard, but probably work on Leopard too.

First, the code must be compiled for each architecture (i386, ppc and x86_64). Each compilation will result in a separate executable (binary) file.

Then use lipo to merge them into a universal binary.

Here’s a sample makefile that will do all of that at once for a command-line utility I wrote in C called “whead”.

CC=gcc
CFLAGS=
LDFLAGS=

all: i386 ppc x86_64 univ

i386:
$(CC) -o whead_$@ whead.c $(CFLAGS) $(LDFLAGS) -arch i386

ppc:
$(CC) -o whead_$@ whead.c $(CFLAGS) $(LDFLAGS) -arch ppc

x86_64:
$(CC) -o whead_$@ whead.c $(CFLAGS) $(LDFLAGS) -arch x86_64

univ: i386 ppc x86_64
lipo -create whead_i386 whead_ppc whead_x86_64 -output whead

clean:
rm whead_ppc whead_i386 whead_x86_64 whead

Just run the makefile:

[ngmarle@lorien whead.univeral]$ make
gcc -o whead_i386 whead.c -arch i386
gcc -o whead_ppc whead.c -arch ppc
gcc -o whead_x86_64 whead.c -arch x86_64
lipo -create whead_i386 whead_ppc whead_x86_64 -output whead

And ensure that the resulting binary is compatible with all architectures previously specified:


[ngmarle@lorien whead.univeral]$ file ./whead
./whead: Mach-O universal binary with 3 architectures
./whead (for architecture i386): Mach-O executable i386
./whead (for architecture ppc7400): Mach-O executable ppc
./whead (for architecture x86_64): Mach-O 64-bit executable x86_64
[ngmarle@lorien whead.univeral]$ ./whead
usage: ./whead hostname [port]

That’s it.

photo credit

basic Perl log function

I believe any good Perl utility should have a log to which pertinent information should be written. I’m not even going to go over the merits of having a log file, but all good scripts should have one.

Setup – Define the Function and Log Filename

Here’s the log function which I use in my Perl scripts. This could easily be exported to a log module. Yes, I realize there are probably a lot of good logging modules out there already, I’m just offering this for the lazy sods who don’t currently log anything in their Perl scripts, but realize that it’s a good idea to start.

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon  += 1; $wday += 1; $year += 1900;
my @months = qw { Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec };
unshift @months , '';


my $date = sprintf "%04d%03s%02d" , $year , $months[$mon] , $mday ;
my $logfile = "/tmp/$progname.$date.log";

open( LOGFILE , ">> $logfile" )
    or die "Can't open file '$logfile'. $!\n";
select((select(LOGFILE), $| = 1)[0]); # autoflush LOGFILE

sub logh() {
    my $msg = shift(@_);
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    $mon  += 1; $wday += 1; $year += 1900;

    my @months = qw { Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec };
    my $dts;
    $dts = sprintf("%04d%3s%02d %02d:%02d:%02d",
                   $year,$months[$mon],$mday,$hour,$min,$sec);
    my $pid = $$;
    printf LOGFILE ("$dts:$pid: $msg\n" , @_);
}

I’ve actually included a bit more than just the log function – a few more lines to show how I set up the log filename. I like to create a daily log and assume the script I’m writing will eventually be run from a cron job or something.

Logging Strings – Calls to the logh() subroutine

This is the reason for all the setup — the actual log strings. Because of the way the arguments to the logh() function are utilized,
printf-style strings & arguments can be sent to the function. Here are some example calls to the logh function (pulled directly from a live production script):

I generally start out with the first line in the examples below (I always have a script global called “$progname”).

&logh("$progname started");
&logh("site '$store_nbr' not found in DB. adding site.");
&logh("all data matches for site '$store_nbr': nothing to do.");
&logh("adding site $store_nbr to db");
&logh("updating '$k' to '$v' for store $store_nbr in db");

Close It Out

Though it’s not really necessary these days, it’s good practice to actually close the file at the end of your script. I like to include the block below to close out the log file.

&logh("$progname ended");
my $line = '='x72;
&logh("$line");
close( LOGFILE );

Linux shared library error

Note: this was originally written on Apr 23, 2010, so that’s why the dates are from about a week and a half ago. Because I’m a lazy sod, I didn’t get around to publishing this until now.

After installing ntp on my Arch Linux server via pacman, I received this error message while trying to update my system time with ntpdate:


[root@ngmar01 ~]# ntpdate
ntpdate: error while loading shared libraries: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory

At first I thought the error indicated that I was missing libcrypto, but then I checked and indeed I did have libcrypto installed on my system.

So then I checked the ntpdate executable itself. The ‘ldd’ utility lists dynamic dependencies of an executable (or, to put it another way, it lists the shared libraries on which the program is dependent).

[root@ngmar01 ~]# ldd $( which ntpdate )
linux-vdso.so.1 => (0x00007fffdcae6000)
libcrypto.so.1.0.0 => not found
librt.so.1 => /lib/librt.so.1 (0x00007fa1fef84000)
libcap.so.2 => /lib/libcap.so.2 (0x00007fa1fed80000)
libc.so.6 => /lib/libc.so.6 (0x00007fa1fea2a000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fa1fe80e000)
libattr.so.1 => /lib/libattr.so.1 (0x00007fa1fe60a000)
/lib/ld-linux-x86-64.so.2 (0x00007fa1ff18c000)

So we found the culprit. It’s obviously trying to link to “libcrypto.so.1.0.0”, which can’t be found anywhere in my shared lib path. Generally the error above is just a version problem and can be easily fixed with a symbolic link to the system version. A-like so:

[root@ngmar01 ~]# cd /usr/lib/
[root@ngmar01 lib]# ln -s libcrypto.so libcrypto.so.1.0.0

Now we no longer get a “not found” message when running ldd on the binary.
[root@ngmar01 lib]# ldd $( which ntpdate )
linux-vdso.so.1 => (0x00007fff88fff000)
libcrypto.so.1.0.0 => /usr/lib/libcrypto.so.1.0.0 (0x00007f85f8ce2000)
librt.so.1 => /lib/librt.so.1 (0x00007f85f8ada000)
libcap.so.2 => /lib/libcap.so.2 (0x00007f85f88d6000)
libc.so.6 => /lib/libc.so.6 (0x00007f85f8580000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f85f837c000)
libz.so.1 => /usr/lib/libz.so.1 (0x00007f85f8164000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f85f7f48000)
libattr.so.1 => /lib/libattr.so.1 (0x00007f85f7d44000)
/lib/ld-linux-x86-64.so.2 (0x00007f85f9072000)

And now, to test that it’s working:

[root@ngmar01 lib]# ntpdate
23 Apr 22:48:24 ntpdate[20587]: no servers can be used, exiting

Note: the error above indicates that the binary is working, but I didn’t provide any command-line arguments. It’s beyond the scope of this post, but “ntpdate pool.ntp.org” should work.

my personal daily caloric intake tracker

Update {2010 Ago 10}: I am no longer updating the DCI Tracker. At the time, it was a good thing for me to do, it fit in with my life/lifestyle and it was also a great start with CakePHP. I still eat healthy, but don’t have time to update it. I also don’t feel the need to update it anymore. My life is taking on a new direction with me getting involved in Internet Marketing and also traveling to New Zealand. Those pursuits are now taking up most of my time. I will keep the tracker up for posterity’s sake.

About 6 days ago I started tracking every thing I eat and the number of calories contained within said food items.

I initially just put everything in a text file, but that got old quickly for 2 reasons:

1. I wanted to update my DCI from work, but couldn’t b/c the text file was on my laptop at home, and
2. I got tired of calculating {in my head} the total # of calories I consumed each day.

So I decided to write a web app to track it all and display nice, neat summaries for me. Incidentally, I learned a bit about CakePHP in the process.

Without further ado, here is the link to the mydci app:
http://ngmarley.com/mydci/

It’s quite basic, with little more functionality than a text file, but it makes my day a bit easier. This will only show my own caloric intake, I haven’t expanded the functionality to include tracking multiple users, etc.

I’ve added some basic authentication so that the world can’t go mucking up my data.