Lack of updates, link aggregation

So first off I apologize for a lack of blogging. It always seems to fall to the side when life gets busy. My main priority right now is working on (and eventually) finishing going through Florida pictures, but everything seems to get in the way including taking more pics to add to the queue.

One thing I’ve wanted to do for awhile though is have a way to manage my interesting links. I read a lot of tech and science news in the morning and like to share said articles with family and friends. So I generally share them with Facebook, or Twitter (which in turn *usually* trickles back to Facebook unless their plugin is broken), but neither is really a trust worthy place to put any information you care about. I really like the way Justin does it, but also wanted to tie a quick push to Twitter (and thus Facebook) in.  So I figured I might as well write a little social bookmarking thing.

The entire hack took about 30 minutes, including the time to register a cheap (i.e. not taken) and very short (3.2) domain name (k4v.ca) for my built in URL shortener as using kavassalis.com?blah seemed a touch long. I have yet to display my links in the blog layout, but I will probably whip up a widget tomorrow morning to appear on the right side of all the pages with the last N links. Anyway the code is pretty ugly and basic but here it is:

The actual link forwarder: (l.php)

if (sizeof($_GET)!=1) { header("Location: http://kavassalis.com/"); }
$code = key($_GET);

$dbUser = "abc";
$dbPass = "xyz";
$dbName = "nick_blog";
$dbHost = "127.0.0.1";

@mysql_connect($dbHost, $dbUser, $dbPass) or header("Location: http://kavassalis.com/");
@mysql_select_db($dbName) or header("Location: http://kavassalis.com/");

$result = mysql_query("SELECT link FROM links where code='$code'");
$rows = mysql_num_rows($result) ;

if ($rows == 1) {
$link = mysql_result($result,0,"link");
header("Location: $link");
} else { header("Location: http://kavassalis.com/"); }

(The obvious flaw is that it doesn’t give an error to the user if the database is down, but I didn’t feel like doing that so…)

and here is the link creator: (bookmark.php)

function mkCookie()
{
$pool = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
for ($i = 0; $i < 3; $i++)
{ $result .= $pool{rand(0, 61)}; }
return $result;
}

if (!isset($_GET['link']) || !isset($_GET['blurb'])) {
*** FORM HTML WOULD APPEAR HERE, THANKS WORDPRESS ***
} else {

$blurb = $_GET['blurb'];
$link = $_GET['link'];

$dbUser = "abc";
$dbPass = "xyz";
$dbName = "nick_blog";
$dbHost = "127.0.0.1";

@mysql_connect($dbHost, $dbUser, $dbPass) or die("Bah, cannot connect to my DB...");
@mysql_select_db($dbName) or die("Bah, cannot select my database...");

// make sure we dont dupe codes, even though the code space is huge (62*62*62)
while (1) {
$code = mkCookie();
$result = mysql_query("SELECT id FROM links where code='$code'");
$rows = mysql_num_rows($result) ;
if ($rows < 1) break;
}

$result = mysql_query("INSERT INTO links (code,link,blurb) VALUES('$code','$link','$blurb')");
$url = "http://k4v.ca/l?$code";
header("Location: http://twitter.com/home?status=$blurb> $url");
}
?>

Amusingly the WordPress < code > block really seems to detest HTML, i.e. WordPress renders it even though its inside the block, that just makes no sense… Too lazy to figure out how to do it for a 4 line form. So yea, thats the code. No URL tracking/stats, but thats not really what I was going after. I just wanted an easy one click way to share URLs everywhere at once, and store them somewhere safe.

Things have been generally busy work wise, home wise. I am going to try and blog more again. Today being May 5th means that Mucho Burrito has $5 12″ burritos and I’m going to go and see if I can’t manage to consume two between now and dinner. Toodles!

Comments: 5 Comments

5 Responses to “Lack of updates, link aggregation”

  1. Justin says:

    First off, for embedding white-space preserving code blocks in WP, wrap them like so (this is assuming you’re using the html editor, and not the visual editor):

    <pre><code>code blah blah here</code></pre>

    And you also have to html encode the less-than signs if you’re planning on displaying HTML source. PHP’s htmlspecialchars() is handy here.

    Can I ask one thing? Why do you need a URL shortener? Why can’t you just store the link of what you’re linking to?

  2. Nick says:

    Ahhh thanks! I had totally not thought of using the proper tags first.

    The URL shortener is for twitter’ification, it only saves like 8 characters but I figured it was worth implementing + the $10/year for the domain. Many times the cursed 140 characters leaves me a few short of being able to express my angry-rant-de-jeur… I could have used an existing URL shortener but this was easier (IMO) + theres always the fear your shortener of choice will one day up and vanish.

  3. Nick says:

    Actually here was a good example:
    @nkavassalis Apparently you can simply chop your standard GSM SIM with a butchers knife and use it in your iPad/iPhone 4G prototype > http://k4v.ca/l?NTS

    I literally had 0 characters to spare, thankfully I didn’t have to reword my blurb or make it sound like SMS speak as I often need to by removing adverbs and such…

    Eventually the comp-sci student in me will rework the hash/cookie creating algorithm to not brute force until it finds one taken. I realize there will likely never be collisions and even when there are, very few, but it’s just so ugly…

  4. [...] This post was mentioned on Twitter by Nick Kavassalis. Nick Kavassalis said: Lack of updates, link aggregation >> http://is.gd/bViUa [...]

  5. Justin says:

    Yeah, I just can’t get over Twitter’s 140 char limit or the expressiveness of HTML I’ve grown so accustomed to. In my case, I have a special category set up in WordPress for my “neatlinks” and I’ve hacked WP core a bit to generate a title from the content. Which allows me, when necessary, to link to TWO! things, e.g.

    http://justinsomnia.org/2010/05/worth-reading-interview-with-shawn-brauch-of-pen/

    I suppose I could pump all my neatlinks into Twitter with a link back to my blog, but that just seems not what Twitter was intended for.

Leave a Reply

Recent Photos

Post archives

Red List’s Species of the Day