Things in Jars

Simon Madine (thingsinjars)

@thingsinjarsFollow me on Twitter

Hi, I’m Simon Madine and I make digital toys and write guides on web development.

I'm a senior web dev and evangelist for Nokia Maps in Berlin.

  • Twitter
  • Flickr
  • GitHub
  • Forrst
  • Shelvist
  • Last.FM
  • RSS
  • ImpressJS Tools

    Written 16 Jan 2012

    Development,Design,Javascript

    While putting together last week's promo video for Museum140 (a vote'd be awsm, btw), I knocked up a few tools to make my life easier. As I always say, if you find something you like, make a plugin for it. Seriously, I always say that. That might even be how I proposed to my wife, I'll have to check.

    Anyway.

    Play

    This is a simple timing helper. It just provides a little array you can push slide durations into and at the end, you call 'play'. I can't see many uses for this other than in creating videos.

    ImpressJS.play(3000);  //Set the first slide duration for 3 seconds
    ImpressJS.play(1000);  //Set the second slide duration for 1 second
    ImpressJS.play(); //Play from the start
    

    Edit

    This is much more useful.

    If this script is included in the page (after the impress.js script), you can drag your slides around, rotate and scale them into exactly the position you want. Once you're happy, you can get the current HTML output onto the console for pasting back into your original slideshow file. I could have snuck in a drag-n-drop file handler but that would make it Chrome only.

    Disclaimer

    These tools rely on ImpressJS having a public API which it currently doesn't have. It's obviously high on the author's priority list (given the amount of discussion it's raised) but, as too many pull requests spoil the broth, I've made a little fork of my own, added the public functions the tools require and I'll update them once the main repository's settled down a bit.

    Download

    These are available in the tools folder of this fork of impress.js. Each one contains an example. Hopefully, these will be updated to use the public API as soon as it's available.

    Comments

  • Create a draggable file on-the-fly with JS

    Written 8 Dec 2011

    Guides,Javascript,Development,Geek

    Here's a useful little code snippet if you're building a web application. It's a simple way of making the boundary between web-browser and platform a bit smaller. It allows you to create a file (text, html, whatever) in in your page which the user can drag onto their desktop (if their browser supports the dragstart event and dataTransfer methods).

    document.getElementById('downloadElement').addEventListener("dragstart", function (e) {
      e.dataTransfer.setData("DownloadURL", "text/html:filename.html:data:image/png;base64," + btoa(fileContent));
    });
    

    A description of the code:

    • attach an event listener to the draggable element you specify (downloadElement)
    • when you start to drag it (dragstart),
    • it creates a dataTransfer object (with the type DownloadURL)
    • and sets the content of that to be whatever you pass it (fileContent)
    • It uses btoa() to encode the string data as a base64-encoded string.
    • When you combine this with the MIME-type (text/html),
    • you can create a file with the specified name (filename.html) when the user releases the drag in their local file system.
    • The fake MIME-type (image/png) is there as part of the object data to convince the browser this is a binary file (which it is, even though it's not an image).

    Note: The element this is attached to (downloadElement above) should either be draggable by default (image, link or text selection) or have the draggable attribute set otherwise this'll do nothing.

    Credit goes to Paul Kinlan for using this in Appmator which is where I first saw this done this way. He actually uses it alongside some extremely clever JS zip-file creation stuff, too, it's definitely worth digging through the source there.

    You can find out more about the drag events on the MDN.

    Comments

  • Copy-paste coding

    Written 31 Oct 2011

    Development,Development,Toys,Guides

    This weekend, I had a spare couple of hours on Saturday night (as often happens when you have a kid) so I decided to pass the time with a bit of copy-paste coding.

    I grabbed a bit of example code for a top-down racing game built using Box2d and GameJs. I then grabbed a Google Maps demo and a Nokia Maps demo and smooshed them together. I've seen a few racing games before so I know there's nothing innovative here, it's just a bit of silliness.

    The results

    • Driving on Nokia Maps
    • Driving on Google Maps

    Copy-Paste: Not a bad thing

    There are many developers who will tell you that blindly copy-pasting is a terrible way to code. They make the valid points that you don't understand something if you don't read it properly and that you'll end up stuck down an algorithmic cul-de-sac with no way to three-point-turn your way out (although they may phrase it differently). These are valid points but...

    If I'd sat down on Saturday night and thought "I want to build something in Box2D" then gone to the site, downloaded the library, read the docs and loaded the examples, by the time I had understood what I was doing, Sunday morning would have come round and I'd still have GameJS to read up on. There's absolutely no harm in blindly catapulting yourself a long way down the development track then looking round to see where you are. Sure, you'll end up somewhere unfamiliar and you may end up with absolutely no clue what the code around you does but at least you have something to look at while you figure it out. At least a few times, you'll find something almost works and a quick search of the docs later, you've figured it out and know what it's doing.

    Basically, copy-pasting together a simple little demo and making it work is a lot more interesting than taking baby-steps through example code and beginner tutorials. Don't be too careful about trying to build something complicated.

    An Idea

    If you're in the mood for copy-paste coding, try taking the two demos above (Google and Nokia), grab the node.js server from the multi-user page experiment and figure out how to have multiple racers on the same map (by transmitting angle and geo-coords).

    Comments

  • Copy-paste coding

    Written 31 Oct 2011

    Development,Development,Toys,Guides

    This weekend, I had a spare couple of hours on Saturday night (as often happens when you have a kid) so I decided to pass the time with a bit of copy-paste coding.

    I grabbed a bit of example code for a top-down racing game built using Box2d and GameJs. I then grabbed a Google Maps demo and a Nokia Maps demo and smooshed them together. I've seen a few racing games before so I know there's nothing innovative here, it's just a bit of silliness.

    The results

    • Driving on Nokia Maps
    • Driving on Google Maps

    Copy-Paste: Not a bad thing

    There are many developers who will tell you that blindly copy-pasting is a terrible way to code. They make the valid points that you don't understand something if you don't read it properly and that you'll end up stuck down an algorithmic cul-de-sac with no way to three-point-turn your way out (although they may phrase it differently). These are valid points but...

    If I'd sat down on Saturday night and thought "I want to build something in Box2D" then gone to the site, downloaded the library, read the docs and loaded the examples, by the time I had understood what I was doing, Sunday morning would have come round and I'd still have GameJS to read up on. There's absolutely no harm in blindly catapulting yourself a long way down the development track then looking round to see where you are. Sure, you'll end up somewhere unfamiliar and you may end up with absolutely no clue what the code around you does but at least you have something to look at while you figure it out. At least a few times, you'll find something almost works and a quick search of the docs later, you've figured it out and know what it's doing.

    Basically, copy-pasting together a simple little demo and making it work is a lot more interesting than taking baby-steps through example code and beginner tutorials. Don't be too careful about trying to build something complicated.

    An Idea

    If you're in the mood for copy-paste coding, try taking the two demos above (Google and Nokia), grab the node.js server from the multi-user page experiment and figure out how to have multiple racers on the same map (by transmitting angle and geo-coords).

    Comments

  • older posts

Browse articles by category:

Toys, Guides, Opinion, Geek, Non-geek, Development, Design, CSS, JS, Open-source Ideas, Cartoons, Photos

Recent side-projects

  • Insta-Art
  • 8-Bit Alpha
  • Shelvi.st
  • The Elementals
  • Harmonious

Toys

Find my digital toys at thelab.thingsinjars.com.

Contact

Send me a message via Twitter.

Adopt-a-Museum

@thingsinjars:

    © 2012 Simon Madine