February 2012
7 posts
3 tags
Immutable Arrays in Javascript
Most instance methods of javascript’s array perform mutations on the array. Because objects are assigned by reference, this creates some odd situations…
var a = [1, 2, 3]; var b = a; b.push(4); // a == [1, 2, 3, 4];
When taking on functional programming practices, one of the first things is dealing with the mutation-based implementation of array methods. Fortunately it’s...
2 tags
Programming Puzzle: String Length
Determine the length of a string without using any built-in “.length” or length getting functions.
Typical to true-engineering form, my first idea was overly complicated. I had reasoned that I could write a recursive loop to progressively build up a 2nd string, then compare them to see if the lengths matched. The problem there of course is that in order to do the comparison I have...
2 tags
FizzBuzz in F#
If you’re not familiar with what FizzBuzz is, check out this blog post by Jeff Atwood (Coding Horror). FizzBuzz is sort of that bare-minimum-entry-level-bar that when you can clear you know you’ve at least understood the basic grammar of a language. Typically I find in learning languages what takes the most time is really learning the standard library and built in functions.
F# has...
2 tags
Appending to a List in F#
One thing about functional languages which sounds somewhat simple at first but turns out to be more complex is immutable values. Variables (or “values” as they’re called in F#) can’t be changed once they’ve been initialized.
let x = 2 // This isn’t allowed: x = x + 3
Values in F# can be thought of as an equivalent to C#’s readonly accessor.
int...
2 tags
F# is a Trip (or What is Function Currying)
For developers that have been living in javaland, javascriptland, or C#land for any lengthy period of time, the first encounter with a very functional language, it’s definitely weird. F# is Microsoft’s latest language addition to their .NET kingdom. It’s a functional/object oriented hybrid language which leans more towards the functional side and finds it’s roots in...
3 tags
LINQ is List Comprehensions in Disguise
I had a stunning realization last night. LINQ is nothing more than Microsoft’s implementation of Haskell list comprehensions (a language I greatly admire). It’s not obvious this is what LINQ is, because Microsoft chose to change the keywords to be more SQL-like.
In Python or ECMAScript 6, a list comprehension can be written like so:
[x for x in set (if condition)]
Say for...
3 tags
Using a Custom Fork on Github with...
I just learned a really neat trick. Have you ever had this situation come up:
You forked a public repo on github of an npm module and made some fixes or changes, but now you want to be able to use your fork in another project, perhaps even on Heroku?
Here’s how it’s done…
In the package.json file, replace the version of the npm module with the HTTP address of it’s...
November 2010
6 posts
In Defense of Vendor-Specific CSS Prefixes
Sitepoint.com has been asking recently, “Should CSS vendor prefixes be abolished?” The poll has been running on their front page for the past few days and as of the writing of this post 51% of respondents have said “Yes” versus 22% “No”.
I’m kind of surprised actually. Likely the majority of respondents are web developers who would rather have the...
Converting PNG Images into HTML
A while back I wrote a short python script to take any PNG image file and convert it into pure HTML. Yes, pure HTML.
This actually started as an office joke with the query of how do we put the company logo into emails for people who don’t have images enabled. It was a natural downward progression of jokes that eventually lead to converting the image into HTML. Aaaaaand as any dynamic...
Non-Intrusive Javascript Hovers by Convention
As I’ve been learning Rails lately, the value of convention-over-configuration has been becoming more apparent to me. Here’s a quick example of how you can use this principle to speed up common tasks in web development.
For demonstration, let’s use a really common task: Making mouse over hover effects. I’ll be using jQuery but you can use the JS framework of your...
Why Writing a Webapp Reminds me of Playing a RPG
I’m sure you’ve played an RPG of some sort… Diablo, Torchlight, Titan’s Quest, City of Heroes, World of Warcraft, Pirates of the Burning Sea, Aion, Eve Online, Dark Age of Camelot, Age of Conan, etc. These all invariably involve the same pattern of gameplay.
You design a character — it’s gender, appearance, skin tone, and of course role/class. You enter the...
Blekko & Google: A Quick Study in Color Contrast
Blekko recently launched with much fanfare. There hasn’t been much change in the search engine world recently so I imagine a flood of early adopters will give them a steady flow of traffic for sometime. Being a techy and web developer myself I of course wanted to hop on the bandwagon early on.
However within just the first day I began to feel like Blekko was “harder” to use....
Is the Golden Age of Django Over? [Opinion]
To me Django was revolutionary. Sure there were many more frameworks who came before it, but for those of us who didn’t care for the scaffolding-command-line-driven style Ruby On Rails offered, Django was a breath of fresh air to the otherwise tedious task of web development. Django had so much going for it…
Tons of features
Built on python
A positive and helpful community
Good...
October 2010
1 post
4 tags
Why Using the AJAX Spinny Wheel Is Bad [Opinion]
Alright that was a tricky title just to get you to read the first line.
Twelves years ago when I made my first website on AOL’s “MyPlace” I copied some javascript I found out there on the internet somewhere to try and make a hover effect for my “personal webpage”.
Why? Because it looked cool.
A few years later I was implementing DHTML page transitions.
Why?...
September 2010
3 posts
2 tags
3 Cool Jquery Tricks I've Been Using Lately
Everyone loves jQuery. Ok maybe not everyone, but at least a huge portion of the internet. It’s likely because jQuery implements the DOM very similar to how it should have been implemented in the first place (but we won’t beat that dead LiveScript horse anymore).
Anyways, here are some cool tricks that I’ve learned, used, or been using lately…
1. Use .live for binding...
2 tags
Bookmarks Are Dead
At least to me. I noticed the other day that I almost never use bookmarks anymore. A year or two ago I was a bookmark junky, having 500+ easily. So what changed? In reflecting upon it, I think there are a few reasons for this…
I switched to using Chrome whenever I’m not doing web development (Firebug is just too awesome to give up). The way Chrome is designed the bookmarks...
4 tags
5 Reasons to Consider Tornado for AppEngine...
As I’ve begun to become better acquainted with Google’s AppEngine platform, I’ve hit a few points where the python-based “webapp” framework is less than desirable.
While I have a background in Django, I didn’t feel as if it was a fit for AppEngine due to it’s heavy data layer ties. On the flip side, Tornado (IMHO) is a lightweight alternative and prime...
August 2010
3 posts
3 tags
Restoring Browser Functions to Clickable DIVs...
Occasionally the situation comes up in web development where you have a highly styled tag such as <div> or <li> that you want to make clickable. This often happens when you have a list of items in which you want to make the entire item clickble instead of just the title for example. The standard fare for doing so is to set { cursor: pointer; } with CSS then to bind the .click event...
1 tag
Top 10 Programming T-Shirts That Don't Make Sense
mind.location = unknown http://www.zazzle.com/javascript_mind_tshirt-235892961444457742 I wonder what the value of the variable unknown is? import_soul http://www.zazzle.com/import_soul_tshirt-235715645595867505 What is import_soul? It’s written as a keyword. If it were a function it should be import_soul(), however the keywords for this shirt include “python” which makes me...
2 tags
Python Templating For the Web (Random Ideas)
Well it’s past midnight and I’m musing about web templating in Python for Tornado or AppEngine. The thing about most Python templating engines that I notice is… There’s kind of an obsession with being agnostic about everything. You can render JSON and XML and whatever else you want with our engine! When is someone just going to make a really awesome templating engine...
July 2010
1 post
2 tags
Komodo Edit
I like Komodo Edit. It’s simple but at the same time functional enough to be useful. It also does code completion, supports Python, and is cross-platform. (Side note: If only it supported Scala, then it would be like the **aaaaahhh** perfect editor). I’ve had this idea kicking around for a while of starting a Komodo color themes/schemes website. The idea is simple. You create a...
June 2010
1 post
2 tags
Formatting Console Output in Scala
So it’s midnight and I’m programming Scala (heh). I’m actually starting to be able to write little scripts in Scala. Here’s a quick one that I put together, inspired by Chapter 3 of “Programming Scala” which reads a source code file and formats the file to the screen with line numbers. I tried to be as functional as possible. The...
May 2010
4 posts
1 tag
The Difference a Space Can Make
How can you print the string value of a floating point value of 5 in Scala? scala> 5.toString // Wrong! res16: java.lang.String = 5 scala> 5. toString res17: java.lang.String = 5.0 In the first line scala counts the “.” as syntax for “toString method of Integer 5”. The second line uses the “toString” method in infix notation, applying the toString...
1 tag
Abstract Types in Scala
Whenever I learn new programming languages, there is invariably features of the language that will surprise me. One of those in Scala (one of many actually) is abstract types. When I first read the textual description of an abstract type, I wondered what use it would ever entail. However, the authors of Programming Scala gave a very clear example of proper use. This code snippet comes from...
3 tags
Language of the Summer: Scala?
I’ve been quite fascinated with Haskell as a language. It’s purely functional, ridiculously strict typing, and algebraic syntax were completely foreign to me before I began learning about it. I wouldn’t say that I learned Haskell, but I did learn about it. I learned enough to know that it’s a bit over my head at this point and that I need a better theoretical foundation...
1 tag
I Bought It at Ross!
I was waiting on the wife at Ross Dress for Less the other day, when I happened to notice something: They sell laptop bags! Since when did Ross start carrying those? Surprisingly they had a selection of name brands at, you guessed it, discount prices. I ended up buying a Targus Messenger Fusion in dark gray/green for the Toshiba 13.3” I got a few months ago. It was marked down to $18.99...
January 2010
3 posts
3 tags
Accessing Inherited Models from the Parent in...
One of the neat features of Django’s ORM is Model inheritance (table-level). It allows several neat data design patterns to occur. Here’s an example. Let’s say we’re developing a website for a game company. The company sells two types of products: board games and video games. All of the products will share some data in common, name and product_id for example, but we...
4 tags
Version Control Commit Messages
Soooooo… I think I’m going to put in a proposal at work. All commit messages for our Mercurial DVCS need to be in 16-year-old girl language…. “Like, the JSON api is totally updated” “fixed the buggies kk thx bai “this import module is sooooo cuties!!!!!11`1”
5 tags
Meh @reading (but Yay to reading on the iPod)
I can’t be the only programmer who finds reading a chore? And what about those 5-billion page programming tomes? Am I the only one who never finishes those? It happens to be that I just found something about reading that totally rocks: Reading on the iPhone/iPod Touch is totally different (better different). HA! I bet you didn’t know I was going to say that (well if you read the...
December 2009
8 posts
4 tags
Where Have All The Good DatePickers Gone?
Is it just me, or is it hard to find a good jQuery-based date picker? Or maybe I’m just picky. The widget needs to support selecting a date range (there goes most of them). And it needs to be able to support configuring a starting and ending time. And it has to support Themeroller (there goes whatever few remained). So as it seems is starting to become a norm for me, I’m working on...
3 tags
Using Google's jQuery CDN with Django when not in...
I wanted to transition the Django site I work with primarily to use Google’s jQuery CDN. However, when developing locally, it’s often faster to just use a local copy. What I wanted was a way to toggle which copy of jQuery was being used based on the environment. Environment Detection Before we can toggle the jQuery location, we need to have a way to detect which environment...
3 tags
How can I create a page that regularly updates...
It seems this question has been coming up a lot on Stack Overflow, and I wrote a pretty lengthy response which I’ll include here. The original question is #1883266. Q: I’m building a web application that needs to have content on the page updated in real time without a page refresh (like a chat or messaging application). How do I do this with Django? In other words, how do I use AJAX...
2 tags
Efficiently View Apache Log Files on Windows
One of the annoying things about using multiple platforms is when one platform has a useful utility (no matter how small) and the other platform doesn’t. Have you ever needed to regularly check an Apache log file on your Windows development machine? The shell user inside me says “just tail it”… but this is Windows. However, I just found a really amazing tool called...
2 tags
Time for Python Neenjah!
I happened upon an administrative assistant today who was renaming files using Windows Explorer. She had a folder with about 50 or so sub-folders, many of which contained sub-folders of their own. Every file needed to be renamed with the company name prefixing it. So for example, the file “january-charts.pdf” needed to be renamed to “Company - january-charts.pdf”....
3 tags
MarkEdit in Django
Being primarily a Django developer, it was only a matter of time until MarkEdit came with Django integration. I added to the GitHub repo today a simple app which provides a widget that renders MarkEdit through Django. It’s probably a bit more difficult to use than the jQuery plugin because it makes some assumptions about your Django configuration and usage (as do many Django apps). In any...
2 tags
MarkEdit Moved to GitHub
I have relocated the MarkEdit repository to GitHub to give it more community accessibility. The GitHub repo now also includes an improved wiki. MarkEdit now has it’s own project page, also hosted by GitHub: http://tstone.github.com/jquery-markedit/ The project page finally puts a working demo online (along with 4 other advanced demos, showing some of MarkEdit’s flexibility).
2 tags
IE TextRanges, Selections, and Carriage Returns
I spent several hours this week trying to track down a bug with programmatically selecting text via javascript. if (textarea.setSelectionRange) { // Set selection for Mozilla-ish browsers textarea.setSelectionRange(start, end); } else { // Set selection for IE var range = textarea.createTextRange(); range.collapse(true); range.moveEnd('character', start); range.moveStart('character',...
November 2009
12 posts
1 tag
MarkEdit Documentation
For those interested, I finished the preliminary documentation and sample code for MarkEdit. It can be viewed via the Bitbucket Wiki. The documentation includes… Installation Sample code Complete API reference Complete configuration option reference
Developer Blog Entries
I haven’t done any development in the past few days thanks to this holiday weekend, however I did have a chance to catch up on my blog subscriptions (which were really beginning to pile up). My wife just peeked over my should and said I was also spending quality time with her. Ryan Tomayko on Unicorn (ruby), “because it’s Unix.” A neat post on using some of the unixy...
3 tags
WMD Editor & jQuery
I’ve been using Dana Robinson’s WMD Editor fork for a couple of months now. It was a great place to start. The problem is, it’s becoming a real pain to customize. Small things were taking huge amounts of time to accomplish so I had a tough decision to make: Continue to use WMD Editor and have to spend hours for customization that should only take a minute or two -OR- re-write...
2 tags
Using jQuery's Dialog Function to Get User Input
The jQuery UI library provides a really useful method: dialog. It allows any tag to be rendered as a fake “window” in the browser in either a modal or non-modal way. It’s easily a natural choice for any time we need a dialog to fetch input from a user. What makes it somewhat difficult for some programmers to use is that it’s an asynchronous function. It opens the dialog...
4 tags
A Truly Modular Web Framework
Web development is weird. It’s weird because the rendering of the UI (in HTML) feels so incredibly disconnected from the logic and objects that are represented by the UI. It’s weird because the UI is usually rendered by a server-side template facility, but is occasionally rendered by cilent-side javascript. Here’s an example. I find the decorator pattern really cool. ...
3 tags
Django South Fork
I really like South (the database migration app for Django). I even wrote about it a little bit on Stack Overflow (#1590944). In short, South lets you create python-based migrations to change the database schema. The translation is that you can have a Django model, make a change to it, and then have south change the database schema for you. It’s generally awesome. But there’s this...
2 tags
Komodo Edit Theme: Candybar Ver 1
Well what’s the fun of a new editor without a new color scheme to go along with it? Here’s my latest Komodo Edit color scheme. The colors were inspired by Mozilla Bespin, but I’ve certainly taken things in my own direction. Python HTML Instead of uploading the file somewhere (which would create a broken link a year from now), I’m going to insert the text right here. To...
1 tag
Komodo Edit
I’ve been using Netbeans for Python for several releases now. Don’t get me wrong, it’s not a bad editor. The problem is that I’ve used Visual Studio which includes Intellisense. In Episode 50 of the Stack Overflow podcast Joel refereed to Intellisense as “crack” — once developers try it they’re hooked. After coding in Visual Basic, VB.NET, and...
3 tags
Mercurial hgwebdir under Apache using WSGI
The doc for setting up HgWebDirStepByStep sure make it seem harder than it really is. Maybe it is hard. Maybe it’s just that I spent so much time trying to understand the doc, that when I actually just tried it myself it wasn’t that bad. I’ve been thinking of moving over from SVN to Mercurial (hg) but wasn’t sure if it was worth the fuss. I moved. It seems nice. ...
2 tags
Javascript: The Good Parts (the Video)
Kudos to Google and MIT for uploading such great quality stuff to YouTube (if you’ve been scared off by the drones of webcam-yourself-complaining-about-current-events then give it another try). I stumbled upon Doug Crockford at google speaking on “Javascript: The Good Parts”. He has a book by the same title as well. In his presentation he also mentions JSLint, a tool he wrote...
2 tags
FizzBuzz Ruby
Well since I was in the mood writing FizzBuzz and since I’ve been working on learning Ruby, I figured, why not do recursive fizzbuzz in ruby? Ruby is quite an expressive language. It feels like it comes with more built-in keywords and default methods than python, so I’m sensing it is a bit more complex to learn. However, it has some neat stuff. I’m thinking of writing...
Toshiba T135-1309 13.3" Laptop Review
It’s funny how times changes. 9 years ago I purchased a Toshiba laptop for college. It set me back $1800 and came “loaded” with a Pentium 3 @ 600Mhz and 64MB RAM. I promptly maxed out the RAM to 192MB. I ended up hating it and vowed never to buy a laptop again. Fast forward now a decade into the future. Things have changed. I’m married, have a full time job, and...
October 2009
2 posts
3 tags
Structure and Interpretation, LISP and Python
I’m a “city boy” when it comes to programming languages. 90% of my experience in programming is in ridiculously high level languages like VB.NET, C#, and Python. I haven’t “roughed it out” much in the wilderness of some low level language. I had heard talk about MIT’s Open Courseware, but wasn’t sure what the hoopla was all about. Based on a...