So its way to hard to download an mp3 in Safari. Right click the link and download? Pff, I want to ⌃S and be done with it. Well, this time I decided to avoid the problem all together. I use Skreemr to search for a particular song when it interests me.
In the past I wrote a little bash script, that makes use of curl, to download an mp3 to my desktop unique named so it wouldn’t have conflicts. This shell essentially wraps and drastically improves that to allow for searching, pagination, history, downloading, and opening mp3s off of Skreemr. It gives me just what I need. The functionality that I want without having to use torrents etc. I’m thinking of turning this into a gem.

This script requires the popular “escape.rb” script that gives some nice and safe shell escaping functions. You can download both from my GitHub scripts project.
Of course its available on my ~/bin and there will be another article later on that goes over a few aspects of this simple little script.

I came across a few articles recently that point out how to instantly share a folder on your computer. They basically ride on top of this elegant python script:
python -m SimpleHTTPServer
It works great but I wanted to improve on it in a number of ways:
-
Automatically copy a URI into my clipboard so I can easily paste it to others.
-
Make that URI nicer then just an IP address.
-
Use a non-standard port, for security.
-
Open in a new tab so I can keep working in the directory and yet still monitor the HTTP requests being made.
Here was what I produced. (Its up in my ~/bin.)
es_host=$(curl --silent www.whatismyip.com/automation/n09230945.asp)
es_host=$(nslookup $es_host | awk '/name =/{print substr($4,1,length($4)-1)}')
es_port="8000"
echo "http://$es_host:$es_port"
echo -n "http://$es_host:$es_port" | pbcopy
osascript -e "
Tell application \"Terminal\"
activate
tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down
do script with command \"cd '$(pwd)'\" in selected tab of the front window
do script with command \"clear; echo '$es_host:$es_port/'\" in selected tab of the front window
do script with command \"python -m SimpleHTTPServer $es_port\" in selected tab of the front window
end tell" &> /dev/null
unset es_host
unset es_port
Now that should work on any Mac. And it should give a nicer URL then an ugly IP address. You should see something like this:

As soon as it starts you can paste the URL to anyone you’re chatting with. It couldn’t be simpler!
If you’re experienced enough with DNS servers and you’ve given your computer a Dynamic Name you can customize the script. Paul Berens gave me a great suggestion to determine if I’m on my local network at home. I can check the MAC address of my default gateway (my wireless router). That is a quick check to see if I’m at home. If I’m at home I use my bogojoker.is-a-geek.com URI automatically! Otherwise it defaults to generating the dynamic address generation. Check it out:
if [ -n "$(arp -a | grep 0:1e:2a:76:17:98)" ]; then
es_host="bogojoker.is-a-geek.com"
es_port="8000"
else
es_host=$(curl --silent www.whatismyip.com/automation/n09230945.asp)
es_host=$(nslookup $es_host | awk '/name =/{print substr($4,1,length($4)-1)}')
es_port="8000"
fi
So now when I run easy_share at my house it always throws out bogojoker.is-a-geek.com URIs. Much nicer on the eyes and easy to remember. I’ll write about dynamic names like this another time!
Recently I wrote a Greasemonkey script to add keyboard shortcuts to The Big Picture, to improve on some of their already existing shortcuts. Once I started using some of the shortcuts I made I ended up wanting to use them all over the place at other blogs. This functionality is so tiny, but so useful, that I bundled it into its own script that runs on all web pages!
Grab it here:
(function() {
var x = null;
var y = null;
document.addEventListener("keypress", function(e) {
if(!e) e=window.event;
var key = e.keyCode ? e.keyCode : e.which;
if ( key == 27 ) {
var tempx = x;
var tempy = y;
x = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
y = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
if ( tempx != null ) { window.scrollTo(tempx, tempy);
}
}
}, true);
})();
On any webpage the first time you push the `esc` key position A gets stored. The next time you push `esc` position B gets stored and the browser jumps to position A. The next time you push it, A gets stored and you jump to B. So you always jump back to wherever you pushed `esc` last. Hence the name “back and forth.”
This is useful to me when I jump between comments and the content. When I’m reading a comment and I want to check back to the article, I just just push `esc` to save my position, go back to the article, and when I’m all set I just jump back to my saved position (the comments) with `esc`.
Short, Sweet, Simple: The Back and Forth Greasemonkey Script.
I’ve mentioned before how I’m a big fan of The Big Picture blog. One of the things that makes it so great is that it has keyboard navigation! You can use ‘j’ and ‘k’ to automatically jump between pictures. Its so much nicer then scrolling because it jumps to the exact height to maximize the picture in the browser. Huge usability improvement!
Like before, the problem I had was that users were mentioning pictures in their comments. Jumping back to that picture was hard or annoying. So, I wrote a Greasemonkey script that allows you to type in a number and it will automatically jump to that picture! Click here to get the script!
Oh, and if you’re reading comments and you want to jump back and forth between images and comments that works too. Once you’ve jumped to the image, just hit ‘esc’ and you will be taken back to where you were before. Too cool!
(function() {
var w = ( /a/[-1]=='a') ? unsafeWindow : window;
var x, y;
var keypressnumber = false;
var builtupnumber = '';
var quicknumtimeout = null;
var imgArr = document.getElementsByClassName("bpImage");
document.addEventListener("keypress", function(e) {
if(!e) e=window.event;
var key = e.keyCode ? e.keyCode : e.which;
function storePos() {
x = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
y = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
}
if ( key >= 48 && key <= 57 ) {
if ( e.target.nodeName.match(/TEXTAREA|INPUT/) ) return;
clearTimeout(quicknumtimeout);
keypressnumber = true;
builtupnumber += (key - 0x30);
quicknumtimeout = setTimeout(function() {
w['currImg'] = parseInt(builtupnumber,10)-1;
if (w['currImg'] >= imgArr.length) { w['currImg'] = imgArr.length-1; }
storePos();
window.scrollTo(0,imgArr[ w['currImg'] ].offsetTop+174);
keypressnumber = false;
builtupnumber = '';
quicknumtimeout = null;
}, 300);
}
if ( key == 27 ) {
var tempx = x; var tempy = y; storePos();
window.scrollTo(tempx, tempy);
}
}, true);
})();
All I do is register a new global keyboard listener to catch numeric keys and act accordingly. I tested thoroughly on Firefox and Safari to make sure it works correctly in all cases. It jumps to the correct image, it maintains the “current image” so j/k will still work, it won’t jump if you’re typing in a textfield/input, etc. It even properly handles situations that the current j/k functionality doesn’t. For instance mine allows the user to type in the comment box, click outside the box and reuse the keyboard shortcuts. When you type a j/k or even click inside the search box at the top the j/k functionality is gone. I didn’t feel like correcting that in this Greasemonkey script in case it gets fixed by the developers behind the Big Picture. (Note to those developers: reset isLoaded back to true or take a different approach.)
I’m open to New Ideas. I have some myself but I have to focus on schoolwork in these next few weeks. Let me know if you want anything.
Big Picture Keyboard Commands Greasemonkey Script!
Enjoy.
One thing that really bothers me is when the year changes (2008 to 2009) and I see a ton of websites that sport “© 2008” in their footer. So, I wanted to share my php code to handle this case so that my sites are always “up to date.”
<?php
function footerDate($startYear, $delim='-') {
$currYear = date('Y');
if ( intval($currYear) > intval($startYear) ) {
return $startYear . $delim . $currYear;
} else {
return $startYear;
}
}
?>
<p>© <?php echo footerDate('2009'); ?> Joseph Pecoraro</p>
<p>© <?php echo footerDate('2007'); ?> Joseph Pecoraro</p>
<p>© <?php echo footerDate('2007', ' to '); ?> Joseph Pecoraro</p>
And the ugly 1 liner if you only need a little clip of php:
<?php $c=date('Y');echo '2009'.((intval($c)>2009)?' - '.$c:''); ?>
So please, update your footers now so that you never have to update them again! Thanks.