Get ready for an onslaught of complex code that will shake you to your core:
javascript:void(location=location+"&as_qdr=w")
Once you drag the following link into your bookmarks, you can click on it to make Google reissue the current search, but limit the results to those updated in the past week. It will show google’s date drop-down so you can opt to change it to the past [d]ay, [w]eek, [m]onth or [y]ear (or remove the date limiter).
If you prefer the default for gWhen to be another time period, just replace the “w” in the link below with the first letter of the period you prefer.
gWhen <- Drag that puppy into your Bookmarks and assign it a keyword
As with all other bookmarklets that I use somewhat regularly, I assign a keyword to so I can just:
command-l
bookmarklet’s keyword [gwhen in this case]
[press enter]
For other great bookmarklets (esp increment and decrement for which I have keywords of inc and dec, respectively), see Jesse’s Bookmarklets
I’m too busy to test it in multiple browsers. If you notice it not working in some (reasonable) browser, let me know and some day I’ll get around to fixing it.
* * *
I am reproducing my recent comment added to a reddHHHHHacker News post. The post was Ask Entrepreneurs: Productivity tips for a chronic procrastinator?.
Note: for the faint of heart not interested in reading my stupidly long post, feel free to scroll to the bottom to see the summary+
One thing that drives me absolute crazy is waiting. I am very impatient. So any time I am performing a programming or administration task that requires waiting for more than 10 seconds or so, I end up looking for ANYTHING to ease my boredom. So when I need to kill 30 seconds while something processes, I end up distracted by reddit, blogs etc. Then, 30 minutes later, I realize I have been off on some tangent instead of working, and have essentially wasted 29 minutes of my work day.
One recent approach I tried was less effective but perhaps still interesting thing I’ve done lately is fill in the gaps by learning my editor during long waits. In my case, this is vim (specifically macvim). You end up sometimes missing the completion of the task, but at least its arguably more productive than getting lulled to reddit sleep. And how else would I know that zomfg, vim has a built in genafyngr gb ebg13 command (“g?”).
But then one day I accidentally stumbled across a very profound idea. If I have something happening in the background that is just interesting enough to prevent me from getting bored, but not interesting enough to consume my attention, then I don’t end up off on tangents every time I have to wait 30 seconds to 5 minutes for something to finish.
Several different approaches work and I’m sure their efficacy varies according to individual habits and taste. I used to put on a movie in a tiny window and turn my attention to it when I get bored for a few minutes. But that takes up screen real estate and can be distracting. You’re also less likely to notice that the task you were waiting for has completed…
So how do I prevent the tangents but still manage to focus on my work? AUDIO BOOKS. Especially audio books that I’ve already read in paper or audio form. If it’s the first time you are listening to it, it’s easy to get distracted by the story since you don’t want to miss it. But if you already know what happens, it’s easy to completely ignore it while its playing in the background. Then, as soon as you click a button and strike a key that fires off a task that is going to take some time to finish, you turn your attention mostly to the audio book, but keep one eye on the task so you know it’s over.
This approach has done wonders for my productivity. Now, I tend to look at reddit, hacker news and google reader as a planned task, or just to kill time when I’m not already coding. Try it my friend. You will love it!!
As an aside, about six months ago I switched from Windows land to Mac land, mostly because: 0) linux has caused me too much pain in my short cruel life 1) I am a languages geek, and it seems like they’re available for mac before Windows 2) as a web developer, I often deploy my products on a linuxy server and macosx is much closer to linuxy then windows is. So until recently, I had a much more difficult time staying on task than I do now. Part of the motivation to change came from a reasonably careful assessment of my days, and how each was spent. I downloaded Slife http://www.slifelabs.com/ and Rescutime http://www.rescuetime.com/ ++, both of which can give you a pretty accurate picture of where your time goes when you are sitting on your computer.
——-
+ Summary: Listen to audio books that you’ve already read while you code.
++ Unfortunately, I don’t feel comfortable recommending one over the other. But I will say that Slife required less time to configure and maintain, but at least felt less flexible. I’d recommend either at least in the short term to help you exorcise your procrastination demons. My macbook was stolen about a month ago and I haven’t (yet?) installed them on my new one. They were definitely instrumental though in inspiring me to become more productive.
——-
Here’s a permalink to my comment: http://news.ycombinator.com/item?id=581337 (my handle at Hacker News—and many places besides—is onceuponapriori.)
Comment [1]
* * *
This one is truly awful. I hate that clicking on the programming.reddit logo on programming.reddit.com pages (especially when paginating across the results) brings you to reddit.com instead of the programming sub-site.
Here’s a horrible user script to fix it. Yes there easier/shorter code, but something just wasn’t working @ 4am when I wrote it. I am releasing it to the public because I saw a reddit thread about it:
Download the programming.reddit.com logo userscript
* * *
Because I hate using my mouse.
I present, Trac_L_ogin
* * *
MC Plus + is not your run of the mill sucka MC. At least take a few minutes to listen to Syntax and Semantics. You won’t be disappointed.
* * *
Sajax is an open source tool to make programming websites using the Ajax framework — also known as XMLHTTPRequest or remote scripting — as easy as possible. Sajax makes it easy to call PHP, Perl or Python functions from your webpages via JavaScript without performing a browser refresh.
Thomas Lackner, of Sajax fame, was gracious enough to accept my JScript-in-ASP version of the Sajax toolkit. Sajax also has versions in Io, Ruby, PHP, Python, Lua, Coldfusion and Perl. The JScript port is still in beta, but I will be ironing out the oddities soon enough.
Essentially, you write server-side methods, choose which among them you’d like to be available from the client, and export them. The client-side code can then call the function and register a callback function. Sajax handles all of the client-server communication rather transparently.
Update (08/09/2006): Unfortunately, due to a misunderstanding, Thomas added my “beta” code into the release. There were some bugs and security issues* that I had not yet addressed and the ASP version was removed from the release. As I’m very busy now, I’d like to know if there is significant demand for the ASP version before I continue. If you would love an ASP Sajax toolkit, leave me a comment here.
Update (08/31/2006): I have completed a new alpha version of Sajax for ASP. If anyone is interested in testing it, please leave a comment here, or email me at jared@protoscript.net . I don’t want to release the files into the wild until I’m reasonably sure that everything is working.
Update (09/17/2006): I forgot to mention something. Sajax for ASP is written in JScript, Microsoft’s (mostly) ECMAScript compliant scripting language. Many people believe that writing ASP pages means writing only in VBScript. So why would I go against the grain and use JScript? That’s easy. It supports true closures; a powerful object model with the ability to use mutliple/dynamic inheritance; a convenient, powerful reflection mechanism; dynamically adding properties and methods to ‘classes’ and instances—at runtime; a nice, self-organizing, auto-growing native array type; a unified syntax for dealing with reference and value types (hence, no “set x = object” vs “x = 0”)—this vastly expands the expressivity derived from it being a dynamically typed language; Function.apply(); a terse, convenient syntax, especially for arrays construciton, regular expressions and, coolest of all, object and function literals… The list goes on and on. I cannot recommend highly enough the switch from vbscript to jscript. Once you get used to the new lanugage, and recognize that it is something alltogether different, you will find yourself far more productive.
Comment [6]
* * *
It’s really exciting to see megacorps taking a vocal interest in dynamic languages. It’s even better to see them put their money where their mouth is.
I recently mentioned Microsoft’s release of Iron Python 1.0. Now, there’s even more exciting news in the dynaming languages world.
First, for those of you who’ve never met her, I’d like to introduce you to JRuby. JRuby is a “100% pure-Java implementation of the Ruby programming language.” The mere existence of this open source project is a boon to the dynamic languages world, as it encourages the adoption of ruby. Particularly, it provides a more direct interface through which ruby can be used as an enterprise integration language for the java platform. If you’re stuck maintaining a steaming, complicated mess (e.g. a J2EE Portal), JRuby can melt off some of the fat. At the very least, you can use JRuby to write your unit tests and to script your builds.
But the real news is that “The JRuby Guys” are joining Sun as paid, fulltime employees! Sun is paying them to continue making JRuby a solid, open source environment for building and deploying ruby applications with full access to the vast multitude of java libraries. On top of that, they’ll be working on JRuby tool support and on helping to transform the Java platform into an even better platform on which to run dynamic languages.
Tim Bray announced the ‘aquisition’ in this post. As a javascript fanatic, I also took a keen interest in his mention of Phobos, about which I’ll post shortly.
UPDATE: Ted Leung blogged about these two events as well.
* * *
Today, Microsoft released IronPython 1.0. Iron Python is the speedy Python implementation written to run atop the CLR. Incredibly, it runs the standard pystone benchmark 1.7 times faster than CPython. Of particular interest, is Microsoft’s decision to release IronPython under an open source BSD-style license.
Jim Hugunin provides a short history of the IronPython project, including this gem:
I wanted to understand how Microsoft could have screwed up so badly that the CLR was a worse platform for dynamic languages than the JVM. My plan was to take a couple of weeks to build a prototype implementation of Python on the CLR and then to use that work to write a short pithy article called, “Why the CLR is a terrible platform for dynamic languages”. My plans quickly changed as I worked on the prototype, because I found that Python could run extremely well on the CLR[...][1]
I’m excited to see Microsoft’s continued commitment to making the CLR a viable platform for dynamic languages. A language-neutral runtime—including a sizable standard library—is a boon to all who develop new programming languages.
[1] IronPython 1.0 released today!
* * *
I’ve now released my second greasemonkey script for del.icio.us. day.licio.us automatically adds a string representing the current date to the “Tags” field.
This helps me find bookmarks by clicking on a tag representing the date that I’m interested in (“What was that ruby site I was looking at on Tuesday?”) to restrict my browsing to bookmarks added on that particular date.
I was manually doing this for a about a week before I wrote day.licio.us. As all good programmers know: Don’t Repeat Yourself.
* * *
Pluvo is a new dynamic language. It appears to be practical, elegant and malleable.
“Pluvo is a functional and imperative programming language intended to be highly practical for scripting and CGIs, interpreted using a just-in-time compiler. Its hybrid dynamic and strict typing is flexible enough to allow duck typing. Its functions are, more specifically, closures, and it allows object orientation using prototypes.[...]important datatype is the Table,[...]All of a program’s code is stored in Tables that may then be manipulated by the program itself. Being a data-structured language it allows self-modification à la Smalltalk and Lisp.” [1]
I’m going to list some of the features that appeal to me:
method function. Even comments are generated by calling one of a series of functions.I’m definitely going to be playing with Pluvo. I hope you will too.
[1] http://inamidst.com/pluvo/
* * *
I created a del.icio.us GreaseMonkey userscript to set focus to the “Tags” textbox when I am tagging a site. I was getting annoyed having to take my hand off of the keyboard (and without pressing tab a ‘bunch’) every time I wanted to tag a site. Now, using the handy-dandy del.icio.us firefox extension, tagging a site is as simple as:
Ah, sweet tagging bliss!
Well, not really. If I could find a tagging service that let me use spaces in my tags and that had a popup tagger, I’d be a happy man. Sadly, Ma.gnolia.com (and some others that allow spaces in tags) redirect me away from the page I am trying to view when I activate the bookmarklet. This drives me insane. Maybe I’ll create a Ma.gnolia.com bookmarklet that allows inline site tagging. Do you know of one?
Install all 6 fabulous lines of def.oc.us!
Update: I made the script a little more robust. It can now be used for any page on the delicious site. If there isn’t a text field with the id “tags”, the del.foc.us will gracefully terminate.
* * *
I haven’t spent a lot of time reviewing C# 3.0, but to say that it has left me pleasantly surprised would be an understatement. A better descriptor might be: “Shock and Awe”.
It looks like C# will some day include:
names.Select( n => n.toUpper() ) new Person { Name="Allen Frances", Age=11, CanCode=false } new { Name="Allen Frances", Age=11, CanCode=false }var s = "inferred as a string". This also allows variables to be set to an inferred anonymous type.Believe me; I am aware that MS often fails to provide promised features in many of their products. Regardless, I am excited that Microsoft has apparently recognized the usefulness of these features. Even if all of these features make it into C# 3.0, it will still be lacking in flexibility and power compared to languages that have been available for decades. But when compared to C# 1.0, these features are truly shocking.
[See The LINQ Project Overview (.DOC format) for more information.]
Comment [3]
* * *
Todd Ditchendorf, of ditchnet.org, shared a technique to extend javascript’s standard Array type. This technique highlights the expressive power that prototype-based languages provide to developers.
Let us assume that we want to add a method, last, to our Array type. In most* class-based languages, one would be forced to subclass the Array class and add the last method to their new class (which is why you sometimes see classes in static languages with names like BetterArray or even ArrayWithLast). The intent of the programmer is to add functionality to the Array type, not to create a new, separate type that happens to provide the two sets of functionality.
In javascript, you can achieve this by adding a property to the prototype property of the type (or object) you are trying to extend:
Array.prototype.last = function()
{
return this[this.length-1];
}
The first line adds the last method as a property of the prototype object of Array. Whenever javascript attempts to access a method meth (or any property, for that matter) of object Obj, the interpreter first checks to see if Obj.meth exists. If the method cannot be found, javascript searches the object’s prototype chain. This chain consists of all of the properties of the object’s prototype, as well as it’s prototype’s prototype, and so on (Fortunately, this chain is finite; Object’s prototype property is set to null). So, to check the prototype chain for the method, the interpreter looks for Obj.prototype.meth, then Obj.prototype.prototype.meth, and so on.**
From this point forward, we can access the {font-family:lucida console}last% method of any array we create. A slightly more subtle effect of this is that all arrays, even those created before this code was executed, can access this new method.
The benefits of using this technique are probably rather clear, but I’ll enumerate just a few of them anyways:
I’d like to proceed to an example, specifically the contains method that Todd added to Array.
First we will need some sample arrays to use for testing purposes:
unlucky = [7,13,99]; num = 1; nums = [new String(num),"2","3","4"];
And here is Todd’s implementation of contains:
Array.prototype.contains = function (element) {
for (var i = 0; i < this.length; i++) {
if (this[i]==element) {
return true;
}
}
return false
};
Now, we can test the membership of an array for a specific element like this:
if(unlucky.contains(13)){document.write("13 is unlucky!")}
Let’s try a—very contrived—example with our other array:
if(nums.contains(new String(num))){document.write("We found "+num)}
If you run this code, you’ll find that, even though you are storing num in the array and passing that same variable to contains, the message never prints! This is due to the strange manner in which javascript handles the comparison of String objects, especially those allocated with the String constructor. I only mention this problem because it has brought me hours of suffering while working on a large project. My colleagues and I were in the habit of new String()-ing things to ensure that we were dealing with the string representation of objects before concatenating to them or comparing them. I’m not sure whether this problem occurs in any other context, but it’s a good idea to reduce the potentiality for error as much as we can.
I realized that the problem vanished if toString was called on either of the objects being compared. It seems like the interpreter is checking the equality of the identities of the objects when both are created with an explicit call to the constructor; otherwise, it tests the value of the objects. My first idea was to change the body of the for loop to this:
if(typeof(element)=="string")
{
if (this[i].toString()==element) {
return true;
}
}
else
{
if (this[i]==element) {
return true;
}
}
But when a string is allocated using the String constructor, passing it to the typeof method returns “object”. So, I decided to check for the String constructor directly:
if (this[i]==element || element.constructor==String &&
this[i]==element.toString() ) {
Finally, we’re getting the results we expect! Fortunately, the factors that cause this odd behavior are only found rarely. It is a small price to pay for the dynamic power that javascript provides!
*Ruby is one exception. I’m still researching, but I often get the impression that, internally, Ruby is closer to a prototype-based language than to a traditional, static, class-based language. Of course, one could employ containment to accomplish a similar effect, but the solution is still an extra step away from the problem domain.
**This is accurate conceptually; under the hood, the details may differ slightly.
NB: I use the word “type” to refer to the concepts behind javascript’s constructor functions. Of course, these “types” are just regular objects with a few special responsibilities, but it’s helpful to be able to differentiate between an instance of Array and Array itself.
UPDATE: The ECMAScript specification states that the proper way to convert a String object to a string value is to call String as a function. Using this technique, the example would look like:
if (this[i]==element || element.constructor==String &&
this[i]==String(element) ) {
Comment [1]
* * *
Lately, I’ve been burned by the size restriction that IE enforces on favelets. I exported a bunch of them to my flash drive, and happily imported them when I got to my home PC. Then, I went back to work and imported them again. Well, IE silently trimmed them down to 259 characters. Since the corrupt versions were imported over both of the locations I keep my favelets, I lost quite a bit of code—some with details that I don’t remember well enough to bother re-writing completely from scratch.
But recently I realized that the size limit need not be a problem. After all, we are talking about a dynamic language! Here is what I came up with:
(function()
{
var s,f;
//put your favelets url here
f="http://www.protoscript.net/favlets/site_search.js";
s=document.createElement("SCRIPT");
s.setAttribute("src",f);
s.setAttribute("type","text/javascript");
document.getElementsByTagName("HEAD")[0].appendChild(s);
})()
The base script, without the URL defined, weighs in at 196 characters. With 63 characters left to define my URL, I shouldn’t need to worry about losing my favelets ever again. If you want the one-line version, email me and I will send it to you.
NB: I know, I know, I should be using firefox. Greasemonkey just might be the proverbial straw. But I have quite an emotional investment in IE, and I need to code specifically for it at work. Soon, perhaps…
* * *
While most of you (you know, all two of my readers) have probably seen these, I wouldn’t want anyone who’s wasting their time looking at my site to miss out on useful Rails content.
So, I present:
You got your Ajax in my Ruby (oh my!)
...and…
Hey, at least your not leaving empty handed today. My apologies for not having written anything in over a week. Moving into a new condo and planning a wedding, while learning ruby and spending extra hours at work each nite, really manages to keep me from my blog for longer than I’d like…
I promise: more content soon!
* * *