Tumblr
Moved to tumblr: http://urlencode.tumblr.com/
Blog of Titus Stone; Part programmer, part... wait... what?
Moved to tumblr: http://urlencode.tumblr.com/
Posted by titus at 7:08 PM 0 comments
Labels: moved
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 to the tag (in jQuery as so)....
$('#myDivTag').click(function() { // your code here });
<style type="text/css"> #myDivWrapper { display: block; } #myDiv { } </style> <a id="myDivWrapper"> <div id="myDiv"> ... content ... </div> </a>
<style type="text/css"> #myDiv { position: relative; } a.clickable-overlay { position: absolute; top: 0; left: 0; height: 100%; width: 100%; z-index: 1; display: block; background-color: transparent; } </style> <div id="myDiv"> ... content ... <a class="clickable-overlay" href="#wherever"></a> </div>
Posted by titus at 6:44 AM 2 comments
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
Posted by titus at 5:27 PM 0 comments
Labels: random
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...
Posted by titus at 8:20 PM 0 comments
Labels: template, web-frameworks
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 theme, then share it on the site. Other people can download it or Vote/"Like" it. Most-liked themes bubble to the top. I'm thinking of a simple architecture using Google App Engine (python) + Tornado. We'll see.
In the mean time I sure did waste like 2 hours of what should have been productive programming time putting together a bunch of themes for Komodo Edit. Here are some previews of them...
Posted by titus at 7:34 PM 3 comments
Labels: komodo-edit, komodo-themes
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 "formatSourceLine" I felt was getting close to the concept, using recursion, immutable values, and always returning a value (avoiding the side effect of printing from within the function).
The actual output from this script is:
D:\Development\Scala>scala file.scala file.scala 1 | import scala.io.Source 2 | 3 | if (args.length > 0) { 4 | 5 | def formatSourcePrefix(line: Int, suffix: String, max: Int = 5): 6 | var prefix: String = "" 7 | for (i <- 1 to (max - line.toString.length)) 8 | prefix += " " 9 | prefix + line.toString + suffix 10 | } 11 | 12 | def formatSourceLine(lines: List[String], line: Int = 1, 13 | val out = output + formatSourcePrefix(line, " | ") 14 | if (lines.length > 1) 15 | formatSourceLine(lines.tail, line + 1, out) 16 | else 17 | out 18 | } 19 | 20 | // Read file from disk 21 | val lines = Source.fromPath(args(0)).getLines().toList 22 | 23 | // Print results to screen 24 | println 25 | print(formatSourceLine(lines)) 26 | 27 | } 28 | else { 29 | // Print out proper syntax 30 | Console.err.println 31 | Console.err.println("scala file.scala [filename]") 32 | }
Posted by titus at 11:58 PM 1 comments
Labels: functional-programming, scala
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
scala> 4.+(1) res20: Double = 5.0 scala> 4 .+(1) res21: Int = 5
Posted by titus at 11:05 AM 1 comments
Labels: 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 Chapter 2 of the book.
Starting with an abstract class, we can declare an abstract type. In this case, type "In" on our class "BulkReader" is abstract. It's there, but it does not have a concrete type associated with it. Yet, our value "Source" is typed as type "In". How can this be?
abstract class BulkReader { type In val source: In def read: String }The magic comes when we declare a concrete version of "BulkReader" and can assign a concrete type to "In":
class StringBulkReader(val source: String) extends BulkReader { type In = String def read = source } class FileBulkReader(val source: File) extends BulkReader { type In = File def read = { val in = new BufferedInputStream(new FileInputStream(source)) val numBytes = in.available() val bytes = new Array[Byte](numBytes) in.read(bytes, 0, numBytes) new String(bytes) } }Very cool! In our two concrete instances of "BulkReader" we assigned two different types to our abstract type "In". Note that the value typed as In, "source" is actually part of the concrete class's constructor which is, at this point for me, completely mind bending in terms of flexibility towards class design.
Posted by titus at 9:07 AM 0 comments
Labels: 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 before I attempt to tackle it again.
So in the mean time I wanted to take on something more transitional. I had considered F#. It seems like a great choice, especially since I already know C# and am familiar with the .NET platform. But it's a Microsoft language and I was hoping for something more portable (actually, I'm harboring a secret desire to use a functional programming language to one day code for Lego Mindstorms NXT with).
I happened to stumble upon Lift again yesterday. I had heard about it before when I was looking at other web frameworks after watching a keynote from the author of Seaside at Djangocon.
However, I realized something important about Lift and Scala which I had never caught before: Scala compiles to java bytecode. Java can be run on Google App Engine. I can use Scala/Lift to write for App Engine.
Suddenly I'm hooked. Oh, awesome, and the book "Programming Scala" is available freely online. Mmmm... looks like I have my reading for my traveling this summer.
Posted by titus at 8:40 AM 0 comments
Labels: functional-programming, haskell, scala
Getting a job doesn't seem like a fun activity to many people. I'm in the thick of it right now. The problem is when you have a skill set that you really like and that you feel confident with that no company wants. I feel like I'm in that place with Python/Django.
Sure, I've worked on the "corporaty" systems, ASP.NET, MVC, C#, etc., but what I'd really prefer to work on is python/Django on the web. It doesn't seem like there are any companies hiring for that in Denver (or maybe I need to come up with a better way to find them?). So I end up in an odd place where I wonder if it would be worth a.) going back to the corporaty things that get jobs (MSSQL, ASP, etc.) or b.) learning a newer but similar technology (RoR), and gamble that someone will hire me because I have previous experience in Django.
No one in Colorado needs Django work done?
Posted by titus at 4:05 PM 0 comments
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 (compared to $26.50 online). It's a pretty nice looking laptop bag with built-in padding and tons of pockets/storage. It has an interesting feature in that it comes with multiple straps so you can keep the green one out for a young/hip look, or put the dark one one for a more serious professional look.
Posted by titus at 12:57 PM 1 comments
Labels: laptop
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 also need to store specific details about each. Using model inheritance we can do something as follows.
class Product(models.Model):In a real use-case scenario you'd most likely have more than 1 field per, but for this example I wanted to keep things simple.
name = models.CharField(max_length=75)
product_id = models.SmallIntegerField()
price = models.DecimalField()
class BoardGame(Product):
num_of_players = models.SmallIntegerField()
game_type = models.CharField(max_length=50)
class VideoGame(Product):
PLATFORM_CHOICES = (
('wii', 'Wii),
('xb3', 'Xbox 360'),
('ps3', 'Playstation 3'),
)
platform = models.CharField(max_length=3, choices=PLATFORM_CHOICES)
b = BoardGame.objects.all()[1]Another thing that's cool is child instances have a parent instance record. Using the "Djangopoloy" game from above, which is technically type BoardGame, one could still query Product and retrieve it.
print b.name
>>> 'Djangopoly'
p = Product.objects.get(name='Djangopoly')This is really useful, but sometimes you need to go the opposite direction, and this is where Django's implementation stops. The link can't go from a Product model instance to a BoardGame. It can't retrieve state as if it was of type BoardGame.
print p.platformBecause the need for this seems to be arising more often than not lately for me, I put together a re-usbale bit of code to overcome this limitation. I'll post the code below (a GitHub gist), but using it is actually quite simple.
>>> CAN'T DO THAT!
from inheritance.models import ChildAwareModelThen, an inner class "Inheritance" is supplied to describe children of the model.
class Product(ChildAwareModel):
...
pass
class Product(ChildAwareModel):Only children that need to be reversed to should be set. Once that is configured, a method "get_child_model()" will become available, and can be used like so:
...
class Inheritance:
children = (
'myapp.models.BoardGame',
'myapp.mdoels.VideoGame',
)
p = Product.objects.get(name='Djangopoly')I'm finding this particularly useful when I've created an aggregate type page -- that is a page that shows a summary of all the generic types (Product) -- but need to on user-click show them some type of product-specific detail.
b = p.get_child_model()
print b.num_of_players
>>> 4
Posted by titus at 3:15 PM 3 comments
Labels: django, django-models, inheritance
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....
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?
Posted by titus at 11:55 PM 0 comments
Labels: haskell, ipod, javascript, kindle, RWH
© Blogger template 'Minimalist G' by Ourblogtemplates.com 2008
Back to TOP