Search:

eriksmartt.com/blog

 

Topics:

  • arduino (3)
  • art (2)
  • austin (39)
  • automotive (15)
  • blogging (25)
  • books (14)
  • business (5)
  • code (15)
  • design (10)
  • diy (3)
  • django (9)
  • experience (17)
  • family (2)
  • film (4)
  • food (1)
  • for:optaros (2)
  • gadgets (11)
  • games (11)
  • garden (3)
  • green (5)
  • hack (13)
  • hardware (11)
  • hci (9)
  • life (13)
  • lifehack (11)
  • links (71)
  • linux (8)
  • living (3)
  • make (3)
  • media (7)
  • mobile (98)
  • music (2)
  • news (17)
  • osx (29)
  • outdoors (4)
  • privacy (2)
  • product-management (1)
  • python (75)
  • quote (3)
  • security (10)
  • society (21)
  • software (38)
  • spam (2)
  • syndication (5)
  • technical (31)
  • technolust (5)
  • transportation (12)
  • travel (25)
  • ubuntu (7)
  • web (67)
  •  

    Django “lorem ipsum” generator (and a new contrib.webdesign module)

    Filed under: code, django, python, technical, web — March 30, 2007

    Django “lorem ipsum” generator (and a new contrib.webdesign module)

    The Django Web Framework project just added a new contrib.webdesign module with an amazingly simple, but incredibly handy first feature: a lorem ipsum generator. The idea is that a project’s base templates can include generated lorem ipsum for testing layout and page flow, but inheriting templates can override the generated text once real content is available.

    The lorem tag is used like this (via the contrib.webdesign docs):

    • {% lorem %} will output the common “lorem ipsum” paragraph.
    • {% lorem 3 p %} will output the common “lorem ipsum” paragraph and two random paragraphs each wrapped in HTML <p> tags.
    • {% lorem 2 w random %} will output two random Latin words.

    In practice, you might do this:

    templates/template.html:

    
    <html>
      <head>
        <title>{% block article_title %}{% lorem 5 w %}{% endblock %}</title>
      </head>
      <body>
        <div class="article">
          <div class="article_title">{% block article_title %}{% lorem 5 w %}{% endblock %}</div>
          <div class="article_body">{% block article_body %}{% lorem 4 p %}{% endblock %}</div>
        </div>
      </body>
    </html>
    

    And then inherit when you’re ready:

    templates/article.html:

    
    {% extends "template.html" %}
    
    {% if article %}
      {% block article_title %}{{ article.title }}{% endblock %}
      {% block article_body %}{{ article.body }}{% endblock %}
    {% endif %}
    

    Previously, I used to just paste lorem ipsum text directly into the main template (wrapped in block tags for overridding), but this new tag will let you skip the copy/paste routine. Very nice!


    Post Comment »


    Web typography presentation worth reading… (from SXSW 2007)

    Filed under: links, web — March 22, 2007

    Web Typography Sucks“, the SXSWi 2007 presentation (w/notes.) Also see: http://webtypography.net/sxsw2007/.


    Post Comment »


    Triggering a browser’s “Save As…” dialog using a custom Content-Type header

    Filed under: code, django, technical, web — February 16, 2007

    My previous post, “Passing JSON via the X-JSON HTTP header with Django and Prototype“, contained an example on writing custom HTTP headers from a Django-based web application. Continuing with that theme, here’s another header trick that I use in one of my apps to force the browser’s “Save As…” dialog box when viewing a particular URL.

    The feature that I wanted was the ability to generate an XML file based on an HTTP GET request, but to have the browser open a “Save As…” dialog instead of attempting to render it (as would normally happen with XML in a modern browser.) The solution is to exploit the web browser behavior of not handling unknown mime types. A sample implementation (written in Python for the Django Web Framework) follows:

    def save_as_xml(request):
        import datetime
    
        current_time = datetime.now()
    
        response = HttpResponse('PUT THE XML HERE')
        response['Content-Type'] = 'application/x-generated-xml-backup'
        response['Content-disposition'] = 'Attachment; filename=export.%s.xml' % (current_time.strftime("%Y-%m-%d"))
    
        return response
    

    Setting the Content-Type header to a made-up type ensures that the browser will not attempt to render the file. The Content-disposition header provides the mechanism for suggesting the filename of the content to be saved on the viewer’s system. In this case, I’m using the standard `datetime` module to insert the date into the suggested filename.


    1 Comment »


    Passing JSON via the X-JSON HTTP header with Django and Prototype

    Filed under: code, django, technical, web

    One of the demo sites I was working on this week needed to pass a small amount of JSON back with it’s page results. There are a few ways to do this (and I’d suggest this post, “Loading Content with JSON” as a starting point if you’re looking for ideas), but for simplicity, I decided to take advantage of the automatic X-JSON HTTP Header parsing feature in Prototype 1.5.0. (The Ajax.Request docs address this capability.)

    The sample code below demonstrates the use of the X-JSON header with an simple “sticky notes” web app. On the client-side, the JavaScript is quite simple. The second variable in the onSuccess callback handler will be automatically initialized using the data in the X-JSON header:

    function display_note(id) {
        new Ajax.Request('/api/note/' + id + '/', {
            method: 'get',
            onSuccess: function(transport, results) {
                alert("Note(" + results['id'] + ") `" + results['title'] + "`: " + results['body']);
            },
            }
        );
    }
    

    To handle this request, I’m using Django on the server with the following URL pattern:

    (r'^api/note/(?P\d+)/$', 'views.get_note')
    

    The `get_note` method implementation looks like this: [NOTE: For production use, you'll want some exception handling, but I removed the error handling to simplify the example.]

    def get_note(request, id):
        # Fetch the Note from the DB:
        note = Note.objects.get(pk=id)
        # Create the response object (with some dummy text for now):
        response = HttpResponse('Check the X-JSON header.')
        # Manually set the X-JSON header using the JSON generated from the Note record:
        response['X-JSON'] = cjson.encode(note.__dict__)
        # Return the response object:
        return response
    

    If you’d like to use this technique on your own sites, there are couple points to remember:

    1. You can’t return an empty HTTP Response regardless of there being an X-JSON header. If the response is empty, the browser will hang waiting for content to arrive.
    2. The X-JSON header should only be used for small payloads. Don’t stuff more then 8kb in your headers. If you’re sending more then that, move the JSON to the body of the response.
    3. The cjson and simplejson encoders don’t handle Django DateTime fields. For objects with DateTime fields, write an alternate method for converting the object into a dictionary before passing it to the json encoder.


    Post Comment »


    Yahoo! Pipes — an Automator for the web

    Filed under: web — February 7, 2007

    Yahoo! just launched a new mashup tool called Yahoo! Pipes. The tool allows geek-savvy web users to wire together content filters without writing code. On quick glance, the system reminds me of the way that Apple’s Automator empowers non-programmers (and lazy programmers) to create scripts without writing any AppleScript — only this tool is for wiring together web content. It’s certainly an idea who’s time has come. Even if it doesn’t attract mass usage, it will be successful if it inspires a new level of user control over content, or perhaps a new generation of web tools.

    There’s enough detail on the Pipes’ site to get a feel for it, but you might also check out the O’Reilly Radar post, “Pipes and Filters for the Internet” for more.


    Post Comment »


    Video: “Web 2.0… The Machine is Us/ing Us”

    Filed under: art, media, web

    Here’s a great video on the evolution of the Web:

    [Direct link, for the feed readers.]

    (Via Gizmodo.)


    Post Comment »


    ColorZilla conflict causes FireBug 1.0 to not display on FF 2.x on Ubuntu (update: getting better)

    Filed under: linux, software, web — February 6, 2007

    Just wanted to share this find: After the 1.0 update of FireBug last month, the extension stopped working for me on Firefox 2.0.x on Ubuntu. Thanks to a quick Google search, I found that FireBug conflicts with ColorZilla. After disabling ColorZilla, FireBug now works again.

    (Via the comments in: Firebug 1.0: Public Beta, Still Free, and a Lite version for other browsers.)


    Update 2007-02-08: The author of ColorZilla contacted me, and while we still haven’t isolated the problem, we did find that my ColorZilla extension was at version 0.8.x, and wasn’t finding the 1.0 update. After un-installing and re-installing ColorZilla, it is now somewhat more compatible with FireBug. Both extensions load, and everything except the ColorZilla Eyedropper works.

    Update: It’s broken again… And once again, disabling ColorZilla got my FireBug working again. I don’t know which extension is causing the problem, but there seems to be a conflict.


    9 Comments »


    Tips for ASP’s

    Filed under: business, web — February 5, 2007

    I’ve been doing a lot of work lately focused on researching content and Web-service providers, and it’s amazing how differently companies respond to inquiry. As a result, I’ve pulled together a few tips for the budding Web-services entrepreneur’s out there:

    1. Make it easy to contact whomever is responsible for business development. Auto-responders aren’t necessary, but be sure to get back to the person inquiring promptly. A business development manager is the first-line of exposure into a company, and the experience interacting with this person goes a long way in setting the tone for future relations.
    2. If your service costs thousands per month, have some marketing materials. This should include a presentation on your product/service, it’s features, and your approach to pricing. It should be a non-issue to email this to anyone who inquires about your service. (If you don’t have materials on your offering, that sends a message that you haven’t really thought about selling it.)
    3. If your service is used via Web API’s, have some samples and documentation on-hand to send to anyone evaluating the service. Remember, the person on the other end is trying to figure out how hard it will be to integrate with your service. The easier you can make this person’s job, the better.
    4. Follow through. This is a general good-practice, but when you say you’re going to delver a document about your service, follow through. If you can’t follow through up-front, you’re sending a message that things are going to be very difficult in the future if there’s ever a problem. (Sometimes the right business decision is to stay away from a vendor that looks shaky, no matter how good the service sounds.)
    5. Know who your competition is and don’t be afraid to acknowledge them. A potential customer researching your service has probably talked to your competitors too, and you should have some ideas on how your product/service differentiates itself from theirs. Note that this includes not just the people you’d like to be compared to, but also the companies that show up in the same paragraph as you on TechCrunch.
    6. Don’t introduce NDA’s too early. Remember, it’s your execution that’s valuable, not the ideas.
    7. Learn from the experience. Don’t be afraid to follow-up with someone even if your company was not selected as the final service provider. Doing a little win/loss analysis will help you prepare for next time — and maintaining a good relationship may pay off down the line.
    8. Don’t forget that the person asking about your service may have done their homework, and you can use that information. They very well may have researched your leadership team, read their blogs, looked at their LinkedIn profiles, talked to your VC’s, and searched for mailing list posts from your engineers. They may know a great deal about how your company looks from the outside, and there’s no reason not to ask their opinion.


    Post Comment »


     

    A few books I'm reading now:

    A few books I'd recommend: