<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>Jacob Wright</title><link>https://www.jacwright.com/</link><description>JavaScript, user interfaces, and building software products.</description><language>en-us</language><item><title>Dabble Week Three</title><link>https://www.jacwright.com/773/dabble-week-three/</link><guid isPermaLink="true">https://www.jacwright.com/773/dabble-week-three/</guid><pubDate>Mon, 24 Aug 2015 13:44:21 GMT</pubDate><description><![CDATA[<p><a href="https://www.jacwright.com/752/second-week-on-dabble/">Last week</a> I said I was going to focus on product design. And I did. For at least a few days.</p>
<h3>Monday</h3>
<p>I explored ways to work with plots and subplots. Many writers use 3&#215;5&#8243; note cards to help craft and organize their plots. Many writing products give you note card features to mimic this. Note cards work great. They really help to organize the main plot of a story.</p>
<p>Note cards aren&#8217;t as great at organizing and tracking subplots as they relate to the main plot. J.K. Rowling <a href="http://www.openculture.com/2014/07/j-k-rowling-plotted-harry-potter-with-a-hand-drawn-spreadsheet.html" target="_blank" rel="noopener">used a hand-drawn grid to help her track subplots</a> for at least one of the Harry Potter books. So I spent time thinking through how Dabble might help you track multiple plot lines throughout a story.</p>
<p>I worked out what it might look like if I were to arrange note cards into a grid.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/plotsketch1.png"><img class="aligncenter wp-image-776" src="https://www.jacwright.com/wp-content/uploads/2015/08/plotsketch1.png" alt="plotsketch1" width="500" height="375" /></a></p>
<p>I didn&#8217;t like it. This would require a lot of scrolling, up and down, left and right. It might be fine for a MacBook with that nice trackpad, but not for many other laptops. I continued to mull over the problem.</p>
<h3>Tuesday</h3>
<p>I considered the different hats we wear as writers. Plotting, writing, and editing are the three main hats you wear when creating you work of art. After the creation is publishing and marketing, but I don&#8217;t know if I&#8217;ll touch those hats. Dabble will help you focus on the role you are in, without distracting you with the other roles. For example, when plotting, Dabble will focus you on the architecture of your story. When writing, Dabble will focus you on the words. You will be in scene with your characters. When editing Dabble will focus you on eliminating adverbs, or polishing dialog.</p>
<p>Next, I thought through several interface design problems. I considered a tabbed interface (like the browser) to work with multiple documents at once. I thought through how to store the text (as HTML, markdown, plain text). I thought through how undo/redo should work (per document, across the whole manuscript, how it should work in a product where documents can be looked at from scene, chapter, or the book level). I made some good decisions.</p>
<p>Ideally, none of this work will be apparent to you in the end. Dabble should make it easy to do what you need and just work the way you would expect. My job is to make the tool disappear leaving only your novel.</p>
<h3>Wednesday</h3>
<p>I had a nice brainstorm session with my twin <a href="https://twitter.com/xtyler" target="_blank" rel="noopener">Tyler</a>. A huge shout out to him (thanks Tyler!) because I ended up with some great stuff. We discussed a lot about how <em>he</em> would like Dabble to work. I got some great ideas on how you might work with the manuscript and how you could deal with subplots. I also had affirmation on the direction I was going overall. I will share about what we came up with as the features are implemented.</p>
<h3>Thursday</h3>
<p>I went back to coding. I should have continued with product design, but hey, I&#8217;m a programmer. I added the concept of placeholder text to the navigation. You can name each book, chapter, and scene. But before you  name things you should get helpful placeholder names. This is one from Tyler.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot-2015-08-19-at-11.30.28-AM.png"><img class="aligncenter size-full wp-image-777" src="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot-2015-08-19-at-11.30.28-AM.png" alt="Screen Shot 2015-08-19 at 11.30.28 AM" width="395" height="341" /></a></p>
<p>Your scenes will show the first few words which can help identify a scene before naming it. You may never decide to name scenes if this works good enough.</p>
<p>I also added the ability to edit your scene text. Up until Thursday you couldn&#8217;t actually write your book (and have it save). I added a stop-gap implementation for writing the words. It doesn&#8217;t support undo/redo the way Dabble will, but it works for now. I typed up the beginning of a popular book and things worked out fine.</p>
<p><img class="aligncenter wp-image-778" src="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot-2015-08-20-at-10.48.20-AM.png" alt="Screen Shot 2015-08-20 at 10.48.20 AM" width="500" height="344" /></p>
<h3>Friday</h3>
<p>I added filtering to the navigation. Perhaps this was a bit premature, since there are more important features waiting to be done. But I had the itch to do it, so I did.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot-2015-08-24-at-11.14.11-AM.png"><img class="aligncenter size-full wp-image-779" src="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot-2015-08-24-at-11.14.11-AM.png" alt="Screen Shot 2015-08-24 at 11.14.11 AM" width="314" height="282" /></a></p>
<p>You can find scenes that mention a particular person or thing.</p>
<p>Perhaps this week I&#8217;ll prioritize my backlog so I can work on the most important pieces first.</p>
<h3>Saturday</h3>
<p>I added support for creating new scenes and chapters in-line! When you write, you don&#8217;t want to take your hands off the keyboard, even to create a new scene or chapter.</p>
<p>When you hit Cmd+Enter on Mac or Ctrl+Enter on Windows (the standard shortcut for a page break) you will get a new scene. If you hit Cmd+Enter twice you will get a new chapter, as show below. Hopefully the video is the right format for your browser.</p>
<div style="width: 640px;" class="wp-video">
<video class="wp-video-shortcode" id="video-773-1" width="640" height="444" preload="metadata" controls="controls"><source type="video/mp4" src="https://www.jacwright.com/wp-content/uploads/2015/08/scene-creation.m4v" /><a href="https://www.jacwright.com/wp-content/uploads/2015/08/scene-creation.m4v">/wp-content/uploads/2015/08/scene-creation.m4v</a></video></div>
<h3>Summary</h3>
<p>Great progress this week in terms of product design (most of which I have not disclosed) and some features. I may continue doing a bit of both each week.</p>
<p>&nbsp;</p>
]]></description></item><item><title>Second Week on Dabble</title><link>https://www.jacwright.com/752/second-week-on-dabble/</link><guid isPermaLink="true">https://www.jacwright.com/752/second-week-on-dabble/</guid><pubDate>Tue, 18 Aug 2015 14:51:37 GMT</pubDate><description><![CDATA[<p>Apparently one post is a precedence (according to <a href="https://twitter.com/rtyer" target="_blank">Ryan Tyer</a>). Now I must write another. You can catch up with my <a href="https://www.jacwright.com/740/first-week-on-dabble/" target="_blank">first week with Dabble</a>.</p>
<p>This week there was less visibly done. But nonetheless important stuff.</p>
<h3>Monday</h3>
<p>As a writer, you&#8217;ll likely have many projects, completed, in the works, or just placeholders for an idea you have. You don&#8217;t want to scroll to the bottom of an alphabetical list to work on your &#8220;Zenocide&#8221; smash hit. Nor do you want to write down manuscript ideas on paper just because adding them to Dabble ordered by creation date will push your current novel to the bottom.</p>
<p>So Dabble now sorts by last opened date in the manuscripts view. The projects you haven&#8217;t touched in forever will be nicely collecting dust at the bottom (I have yet to add the dust effects) and your fresh new novels will sparkle and gleam at the top (yet to add sparkle and gleam effects). A screenshot you may imagine is sorted in order of last opened.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot.png"><img class="aligncenter  wp-image-748" src="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot.png" alt="Screen Shot" width="500" height="554" /></a></p>
<h3>Tuesday</h3>
<p>Nothing. I slacked. I let you down. I failed!</p>
<p>But!</p>
<p>I got to sleep in.</p>
<h3>Wednesday</h3>
<p>Navigation day. I prettied up the navigation. I wanted the fonts to match in order to make it easier to find what you&#8217;re looking for. The book nav is now the same font as the book title. The chapter nav is the same font as chapter headings. Scenes are now the same font as your manuscript.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/navigation.png"><img class="aligncenter size-full wp-image-755" src="https://www.jacwright.com/wp-content/uploads/2015/08/navigation.png" alt="navigation" width="237" height="181" /></a></p>
<p>I made the nav less &#8220;deep&#8221;, meaning, your scene is now indented a quarter of the way from the left edge instead of half way, giving you more room to have a meaningful title.</p>
<p>You can also now open and close the sections, because hey, who doesn&#8217;t like opening and closing things?</p>
<p>I cleaned up code and added CDN support. That means the files are hosted on a fast server instead of a slow one. Yay!</p>
<p><strong>BY THE WAY!</strong> Did I tell you I&#8217;ve been building this for and testing this in the browser? Well, I have been. I glossed over it pretty quick last week, but Dabble will have a desktop app for working from the comfort of your own lappy, AND it will have a browser version (pretty much identical) that will allow you to continue writing during your lunch break. Huh-mazing, I know, right? This feature will be part of the paid plans which include cloud storage and syncing between devices.</p>
<h3>Thursday</h3>
<p>Thursday, the day I put in book-title/author/chapter-title editing. Since these portions didn&#8217;t need any great programming genius (in contrast to the scene editing) I was able to get them in easy enough. It was good to be able to rename my book. No more Untitled by Unknown (might be an interesting name for a book, but not for <em>every</em> book).</p>
<h3><a href="https://www.jacwright.com/wp-content/uploads/2015/08/doc-edit.png"><img class="aligncenter  wp-image-757" src="https://www.jacwright.com/wp-content/uploads/2015/08/doc-edit.png" alt="doc-edit" width="500" height="367" /></a>Friday</h3>
<p>I did a bunch of code and visual cleanup that my week of coding left behind. Gotta keep up on those things or you find yourself going slower and slower as time goes on (and you make more bugs, and you hate your work, and life sucks, and it&#8217;s just better to keep up some basic house keeping).</p>
<h3>Saturday</h3>
<p>A special day. The day I added navigation between documents. Up until this day when you opened a manuscript you would get the full book and when you clicked on the navigational pieces on the left, it would scroll to that location in your book. This <em>is</em> better than Word where you have to scroll and scroll and scroll. And scroll. But I want to focus solely on one chapter. Or even one scene. So now, when you click on a navigation item it opens that one item up solo. All by itself. You can look at the whole book, a complete chapter, or a single scene. You have the choice now. I may add a toggle setting to switch between scroll and select, but I don&#8217;t think it will make the cut. Focus is much better this way. Focus is essential to a writer.</p>
<p>I also made the folder arrows hide unless you hover over the nav item. Cleans up the nav IMO. The screenshot below didn&#8217;t capture the mouse, but I was hovering over &#8220;Characters&#8221;. I may change my mind and decide it is nicer to know at a glance what is open/closed. But for now, I like having less visual clutter.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/arrows.png"><img class="aligncenter size-full wp-image-758" src="https://www.jacwright.com/wp-content/uploads/2015/08/arrows.png" alt="arrows" width="500" height="395" /></a></p>
<h3>Summary</h3>
<p>The first week was some initial design and getting screens up. The second week was more under-the-hood programming and making stuff work.</p>
<p>This week, I am putting off tackling the hard problem of the text editor (procrastination is one of my best skills), and hitting product design. I find that when wearing my programming hat, I have a hard time keeping the vision of Dabble at the forefront. So I&#8217;m getting it planned out and written down. This week I&#8217;m wearing my product design hat.</p>
<p>As writers we have several hats. Hats for plotting, writing, and editing. This concept informs my product design and plays a big role in how Dabble will work for you. You generally only where one hat at a time. Whether you are a plotter <em>or</em> a <a href="https://www.google.com/search?q=pantser" target="_blank">pantser</a>. And Dabble will help you focus on the role you are playing at a given moment. More on this later.</p>
]]></description></item><item><title>First Week on Dabble</title><link>https://www.jacwright.com/740/first-week-on-dabble/</link><guid isPermaLink="true">https://www.jacwright.com/740/first-week-on-dabble/</guid><pubDate>Mon, 10 Aug 2015 09:18:44 GMT</pubDate><description><![CDATA[<p>Last week I began work in earnest on Dabble, a writing app for novelists. This is my week at a glance.</p>
<h3>Monday</h3>
<p>I started creating a logo, because hey, it&#8217;s got to look gooood. I want to this product to be fun to use, to have personality. I&#8217;m taking inspiration from <a href="https://slack.com/" target="_blank">Slack</a>.</p>
<p>I looked through a bunch of fonts on Google Fonts typing in &#8220;Dabble&#8221; to the preview and picked my 3 favorites. Then after consulting with my lovely assistant/wife, Brittany, I chose Comfortaa.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/dabble-comfortaa.png"><img class="aligncenter size-full wp-image-741" src="https://www.jacwright.com/wp-content/uploads/2015/08/dabble-comfortaa.png" alt="dabble-comfortaa" width="237" height="57" /></a></p>
<p>I didn&#8217;t like the ligature on the L so rounded that off, tilted the E because I thought it looked nice, and gave it some coloring that makes it more fun, less utilitarian. Between the font, the color, and the E, I thought this conveyed a good sense of mischief.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/dabble-logo1.png"><img class="aligncenter size-full wp-image-742" src="https://www.jacwright.com/wp-content/uploads/2015/08/dabble-logo1.png" alt="dabble-logo1" width="262" height="65" /></a></p>
<p>I also threw up some files into an Amazon S3 bucket for a website, <a href="http://www.dabblewriter.com/" target="_blank">www.dabblewriter.com</a>, so I could show off my logo to Tyler, the twin. And I posted to my friends and family on Facebook about the new company and product. I&#8217;m <em>that</em> excited about it.</p>
<h3>Tuesday</h3>
<p>Unfortunately I discovered my subconscious must have been working hard on Monday. Because when double checking I wasn&#8217;t stepping on any copyright toes for writing tools with the name Dabble, I saw I very well may be stepping on toes with my logo design. Hello <a href="http://dabble.co/" target="_blank">dabble.co</a>! I must have seen you earlier when vetting the name.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/dabble-co-logo.png"><img class="aligncenter size-full wp-image-743" src="https://www.jacwright.com/wp-content/uploads/2015/08/dabble-co-logo.png" alt="dabble-co-logo" width="156" height="115" /></a></p>
<p>The fonts were too similar, and even the E was slanted. Back to the drawing board. The runner up fonts were Baumans and Megrim. I ended up with the latter because Brittany liked the A and Baumans was still similar-ish to Comfortaa. I present you the Dabble logo.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/dabble-logo21.png"><img class="aligncenter wp-image-745 size-full" src="https://www.jacwright.com/wp-content/uploads/2015/08/dabble-logo21.png" alt="" width="322" height="65" /></a></p>
<p>I also put together a quick attempt at marketing and an email capture so people could sign up for updates. Facebook friends were interested in the progress, and I wanted to be sure to get emails for those who want to be part of a beta.</p>
<h3>Wednesday</h3>
<p>I spent some time doing product design.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/FullSizeRender.jpg"><img class="aligncenter size-full wp-image-747" src="https://www.jacwright.com/wp-content/uploads/2015/08/FullSizeRender.jpg" alt="FullSizeRender" width="500" height="375" /></a></p>
<h3>Thursday</h3>
<p>I made the Project List view, which I changed names to Manuscripts view. These are not just projects after all, they are manuscripts.</p>
<p>I started off wanting to make a single novel look like a book and with series looking like a boxed set. I followed <a href="http://srobbin.com/blog/3d-css-book-covers/" target="_blank">http://srobbin.com/blog/3d-css-book-covers/</a> and had something ok looking, but it didn&#8217;t feel right.</p>
<p>I ditched the book idea and went with a simple pile-of-papers approach, since these are unfinished/unpublished works. I think it turned out nicely.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot.png"><img class="aligncenter size-full wp-image-748" src="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot.png" alt="Screen Shot" width="685" height="759" /></a></p>
<p>The piles of paper are different from each other, and when you mouse over them they straighten out a bit and raise off the page, like you&#8217;re picking it up. I love making little UI interactions delightful. This was very fulfilling.</p>
<h3>Friday</h3>
<p>The day I made it a web app instead of just HTML. I brought in <a href="https://github.com/chip-js/chip" target="_blank">Chip</a> for keeping the HTML in-sync with the data and <a href="http://pouchdb.com/" target="_blank">PouchDB</a> to store the database in the browser (also supports syncing with a server when online). This was just beginning work.</p>
<p>I also added loading messages, again inspired from Slack. Unlike Slack, I leave the message up long enough to read it, allowing a click anywhere to close it immediately. I always want to read those slack messages but too often they disappear before I can. Thank you <a href="http://www.writersdigest.com/writing-quotes" target="_blank">Writer&#8217;s Digest for a compilation of quotes from famous authors</a>.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot2.png"><img class="aligncenter size-full wp-image-749" src="https://www.jacwright.com/wp-content/uploads/2015/08/Screen-Shot2.png" alt="Screen Shot2" width="625" height="299" /></a></p>
<h3>Saturday</h3>
<p>I set up my base model classes and the loading/saving mechanisms so when a manuscript (actually all manuscripts currently) gets loaded all the objects get linked together by id, and when an object is saved those links turn into ids. Because I want to save sort-order in my manuscripts, I&#8217;m storing the data like this:</p>
<pre>{
  "_id": "abc",
  "type": "book",
  "title": "Escape from Waterfall",
  "chapters": [
    { "_id": "def" },
    { "_id": "ghi" }
  ]
}
</pre>
<p>I got Manuscript creation/deleting working. I added saving of lastOpened date so old manuscripts naturally sort to the bottom (useful if you have a lot of manuscripts).</p>
<p>I also hooked up my manuscript editor page (the one thing I had coming into this week) to display manuscript data.</p>
<p>I imported a 10k word script into the tool to test out a bunch of chapters. Then I did the same 99 more times to test load. It took 8 seconds for the page to load all that data in (in the future I&#8217;ll only load the manuscripts when they&#8217;re opened) and it still worked like a charm. Page scroll was fast. Everything was snappy.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/08/Google-Chrome.png"><img class="aligncenter wp-image-750" src="https://www.jacwright.com/wp-content/uploads/2015/08/Google-Chrome.png" alt="Google Chrome" width="667" height="500" /></a>I&#8217;m not including a shot of the full script I imported since I haven&#8217;t had permission from the author to do so.</p>
<p>Lastly I added scrolling to the book/chapter/scene you click on so you can jump to that place in your script.</p>
<h3>Summary</h3>
<p>I feel really good about what I was able to do in just one week. I&#8217;ve only been spending a few hours a day on this outside of my day job. Today I wasted my few hours writing this blog post (ok ok, you&#8217;re not a waste), but I&#8217;m too excited about this project and my progress to keep it to myself. I feel really good about the product I have envisioned and the direction I&#8217;m going.</p>
<p>If you&#8217;re interested in beta-testing Dabble, or just want to keep up on its progress, sign up for the newsletter on <a href="http://www.dabblewriter.com/#subForm" target="_blank">dabblewriter.com</a>. I have much more on its way.</p>
]]></description></item><item><title>Starting at Riot Games</title><link>https://www.jacwright.com/711/starting-at-riot-games/</link><guid isPermaLink="true">https://www.jacwright.com/711/starting-at-riot-games/</guid><pubDate>Thu, 29 Jan 2015 14:41:15 GMT</pubDate><description><![CDATA[<p>I am excited to announce that I will be starting work at <a href="http://www.riotgames.com/">Riot Games</a> on Monday. I just got my laptop so I suppose it is really happening. Good thing too, because I&#8217;ve already given leave at <a title="Careers at TeamSnap" href="https://www.teamsnap.com/about/careers">TeamSnap</a>.</p>
<p>First I want to say that TeamSnap has been the best company I&#8217;ve ever worked for. The team is fun, talented, and just great people. The management knows how to guide without micro-managing. Every employee&#8217;s voice is heard. There are no office politics. The dev team is all remote, so working through github while lounging on my couch is awesome. The tech is interesting. The leadership is solid. I am very sad to be leaving.</p>
<p>I am very excited, however, to be joining Riot Games. Their flagship product, League of Legends, is said to be the most played game in the world. If you haven&#8217;t heard of Riot or League of Legends, don&#8217;t be surprised. They&#8217;ve spread through word of mouth and it just hasn&#8217;t reached you yet. It&#8217;s a very fun team-based game with plenty of strategy and room to grow and enjoy the game for a long time. Riot puts a lot of effort into the game itself, as well as other creatives like music videos (such as one of my favorites below).</p>
<p><span class="embed-youtube" style="text-align:center; display: block;"><iframe class='youtube-player' type='text/html' width='640' height='360' src='https://www.youtube.com/embed/0nlJuwO0GDs?version=3&#038;rel=1&#038;fs=1&#038;autohide=2&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' allowfullscreen='true' style='border:0;'></iframe></span></p>
<p>And my twin brother works at Riot, so I&#8217;ll get to work with <a href="http://xtyler.com/">Tyler</a> again! That will be a lot of fun.</p>
]]></description></item><item><title>Scrollable Calendar Widget</title><link>https://www.jacwright.com/699/scrollable-calendar-widget/</link><guid isPermaLink="true">https://www.jacwright.com/699/scrollable-calendar-widget/</guid><pubDate>Thu, 15 Jan 2015 10:37:50 GMT</pubDate><description><![CDATA[<p><img class="aligncenter size-full wp-image-703" src="https://www.jacwright.com/wp-content/uploads/2015/01/Screen-Shot-2015-01-15-at-9.28.47-AM.png" alt="Scrolling Calendar" width="227" height="271" /></p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2015/01/calendar.html">See the Demo</a>.</p>
<p><strong>Update: I built and tested this on Chrome using my macbook&#8217;s trackpad. It scrolls very smoothly, however I&#8217;ve heard reports that a scroll wheel jumps from month to month, but can cut off dates half-way. Needs to be updated for scroll wheels. Also touch events for mobile.</strong></p>
<p>I haven&#8217;t been on <a title="Dribble" href="https://dribbble.com/" target="_blank">Dribbble</a> in awhile, but last night I was poking around and found a bit of inspiration. A little <a href="https://dribbble.com/shots/1882470-Schedule-Gift-Delivery" target="_blank">calendar widget design</a> by Dribbble user <a href="https://dribbble.com/imcatnoone" target="_blank">Cat Noone</a> caught my eye, but what really sparked my interest was the fisrt comment below it:</p>
<blockquote><p>Really love this widget! Quick question how do you change the month? Or is the intention that you can only pick a day during a specific month?</p></blockquote>
<p>I started thinking how the calendar might work if you used scrolling to change the month. From Cat&#8217;s design it seems there is a window of delivery, so she may not need to change months. But most apps I&#8217;ve used do.</p>
<p>Several hours later I ended up with my own <a href="https://www.jacwright.com/wp-content/uploads/2015/01/calendar.html">Scrolling Calendar</a> widget. It is just a prototype and could use work to make it more robust, but it will give you a feel for the scrolling interaction.</p>
<h3>Building the Scrolling Calendar</h3>
<p>I started building the calendar by setting up the HTML I thought I would use and styling it (borrowing from Cat&#8217;s color scheme). The initial HTML looked something like:</p>
<pre class="prettyprint html">&lt;div class="date-picker"&gt;
  &lt;header&gt;December 2014&lt;/header&gt;
  &lt;table class="calendar"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Su&lt;/th&gt;
        &lt;th&gt;Mo&lt;/th&gt;
        &lt;th&gt;Tu&lt;/th&gt;
        &lt;th&gt;We&lt;/th&gt;
        &lt;th&gt;Th&lt;/th&gt;
        &lt;th&gt;Fr&lt;/th&gt;
        &lt;th&gt;Sa&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td class="disabled"&gt;30&lt;/td&gt;
        &lt;td&gt;1&lt;/td&gt;
        &lt;td&gt;2&lt;/td&gt;
        &lt;td&gt;3&lt;/td&gt;
        &lt;td&gt;4&lt;/td&gt;
        &lt;td&gt;5&lt;/td&gt;
        &lt;td&gt;6&lt;/td&gt;
      &lt;/tr&gt;
      &lt;!-- etc. --&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;section class="controls"&gt;
    &lt;button&gt;Select Date&lt;/button&gt;
  &lt;/section&gt;
&lt;/div&gt;</pre>
<p>Many calendar components use tables to display, with each week being a row in the table. The dates which are not part of the current month but show because they are on the current week, they get a &#8220;disabled&#8221; look.</p>
<p>I wanted my scrolling calendar to show the current month&#8217;s dates in the highlighted blue color, and the other dates with the disabled look, but I didn&#8217;t feel like iterating over each date cell to add and remove classes was my favorite method. Couldn&#8217;t I use CSS to toggle whole months at a time instead? (It seems like Cat&#8217;s company, Liberio, actually has specific date ranges, in which case doing it by day makes the most sense.)</p>
<p>So I threw out the table. That always gives me a good feeling when I get rid of a table—I don&#8217;t know why. And instead of using spans and divs, I thought I&#8217;d get all HTML5ey and use custom elements. So <code>&lt;week&gt;</code>, <code>&lt;day&gt;</code>, <code>&lt;month&gt;</code>, and <code>&lt;date&gt;</code> were created.</p>
<p><img class="aligncenter size-full wp-image-702" src="https://www.jacwright.com/wp-content/uploads/2015/01/Screen-Shot-2015-01-15-at-8.18.59-AM.png" alt="Custom elements" width="479" height="292" /></p>
<p>This screenshot didn&#8217;t include it, but inside <code>&lt;week&gt;</code> would be <code>&lt;day&gt;Su&lt;/day&gt;</code>, <code>&lt;day&gt;Mo&lt;/day&gt;</code>, etc. The day and date elements became inline-blocks with a set width and height, and their containers got a set width so they would automatically wrap every 7th item.</p>
<p>Once I had the HTML and styles I wanted, I started to code it. I pulled in the trusted <a title="I've used this quite a bit in the past year and it's been great." href="http://momentjs.com/" target="_blank">moment.js</a> library to populate the dates, and since I was using a date library I auto-generated the weekdays with Moment as well (that&#8217;s why the screenshot above is missing the weekdays). The calendar will support multiple locales now!</p>
<p>When I was using the table-based HTML my thought was as the user scrolled up or down, rows would be added at the top or bottom of the table as needed. Now I would be creating months at a time. So the initial population of the calendar contains 3+ months. The current month, the previous month, and the next month. The &#8220;+&#8221; comes in because I need the &#8220;filler&#8221; dates from the month before the previous (e.g. January 2015 would show 28, 29, 30, and 31 from December). I can&#8217;t just leave these out because I am no longer using a row-based layout, so they are needed to make sure the dates are in the correct place.</p>
<p>At first I tried the &#8220;scroll&#8221; event, but it was the &#8220;wheel&#8221; event that I needed. You can&#8217;t get the wheel event&#8217;s delta change, and you can prevent it&#8217;s default action. When the user scrolls over the calendar, I use the delta to know where the screen should be, add a month to the front or back of the calendar if needed, and set the current month if needed. Scrolling up and down will change months very quickly. <a href="https://www.jacwright.com/wp-content/uploads/2015/01/calendar.html">Try it out</a>.</p>
<p>I played around with the &#8220;break point&#8221; in the middle of the calendar to determine when to switch the active month. It turned out that directly in the middle wasn&#8217;t quite right. It always looked like the break point was too low, because of the amount of visible text above and below. Also, the breakpoint couldn&#8217;t be a line, but a margin, otherwise you could get jitter when scrolling slowly between two months.</p>
<p>The final touch was the date selection. Handling the click on a date wasn&#8217;t difficult, but I ran into a usability issue when clicking on one of those &#8220;disabled&#8221; dates. I wanted to allow it so you didn&#8217;t have to scroll all the way when you saw the date you needed, but I also didn&#8217;t want the top of the calendar showing &#8220;January 2015&#8221; when you just clicked on the December 28, 2014 date.</p>
<p>To fix this, I selected the month for the date when you click on it. This highlights those dates in blue and shows the correct month in the title bar. You can still scroll after that, but when you click you get confirmation of the date you selected.</p>
<p>Because I&#8217;m using moment.js with locales the calendar should work correctly for you, with Sunday being the first day of the week in the US and Monday in many other countries.</p>
<h3>Things to Improve</h3>
<p>This isn&#8217;t ready for prime time as it is just a proof of concept. If you wanted to go the distance you would want to add &lt; and &gt; buttons on the month line. Just because a user <em>can</em> scroll through the months, doesn&#8217;t mean that they will <em>know they can</em>. You&#8217;ll have to give them the training wheels and let them discover the scroll feature for themselves.</p>
<p>Currently I only create one month in front or back when scrolling past the break point. Using my track pad it is pretty smooth until I try to flick it very fast. It halts the flow. In my prototype you can still get years down the road very quickly, so I didn&#8217;t fix this, but to make it a smooth experience you would want to use the delta to add/remove several months when needed instead of just the one at a time.</p>
<p>You could add other features, such as selecting a range of dates, adding time selectors like Cat&#8217;s original design, providing maximum and minimum dates available, giving some sort of visual indication that scrolling is possible (without an ugly scrollbar hopefully), and packing it up for reuse of course.</p>
<p>What do you think, would this be useful and intuitive?</p>
]]></description></item><item><title>A Better jQuery by Extending the DOM</title><link>https://www.jacwright.com/694/a-better-jquery-by-extending-the-dom/</link><guid isPermaLink="true">https://www.jacwright.com/694/a-better-jquery-by-extending-the-dom/</guid><pubDate>Fri, 29 Aug 2014 10:53:32 GMT</pubDate><description><![CDATA[<p>Not very long ago creating your own custom HTML was considered A Bad Thing™. If you deviate from standards you&#8217;re just as bad as table-based layouts and the &lt;blink&gt; tag. Now we have <a href="http://www.w3.org/TR/custom-elements/" target="_blank">Custom Elements</a>, <a href="https://angularjs.org" target="_blank">Angular.js</a> and <a href="http://emberjs.com" target="_blank">Ember.js</a> and <a href="http://www.polymer-project.org" target="_blank">Polymer</a>. It&#8217;s alright now because it&#8217;s a standard. But before it was a standard I was trying to hack support for custom elements in <a href="https://github.com/jacwright/simpli5" target="_blank">Simpli5</a> with the __proto__ element. IE didn&#8217;t support __proto__ so it came to a halt. <em>Note: Polymer&#8217;s Custom Element polyfill relies on the __proto__ property, and IE11 supports it now, even though it is non-standard. Oh, and we can look forward to using <a title="The Object.setPrototype() method sets the prototype (i.e., the internal [[Prototype]] property ) of a specified object to another object or null." href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf">Object.setPrototypeOf</a>.</em></p>
<p>What about extending the DOM? jQuery makes things really nice, but it must wrap everything to accomplish this, adding memory and slowing down (not significantly, so this may be a lame argument) access. Why can&#8217;t we just extend the DOM to add all the useful functionality we need? <a href="http://prototypejs.org" target="_blank">Prototype.js</a> does it. Here are a bunch of easy wins, along with suggestions for some of the more in-depth ones. <em>This won&#8217;t work with really old browsers such as IE8.</em></p>
<h3>How to Extend</h3>
<p>Before we get started, here&#8217;s a quick note on how you ought to extend the DOM. Make sure you use <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty" target="_blank">Object.defineProperty</a></code> or <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties" target="_blank"><code>Object.defineProperties</code></a> on the prototypes of the DOM elements. This allows you to define getters and setters if needed, but it you can also leave the <code>enumerable</code> setting at its default of false so that for-i-in loops don&#8217;t see your methods. Otherwise you can mess up other libraries. To match the other methods, set <code>configurable</code> and <code>writable</code> to true. I&#8217;ll be using <code>Element.prototype.method = xxx</code> in my examples for brevity, but know that it really means</p>
<pre>Object.defineProperty(Element.prototype, 'method', {
  configurable: true,
  writable: true,
  value: xxx
})</pre>
<p>Also, remember to always return <code>this</code> from your methods if you&#8217;re not returning a value. That way they can be chainable like jQuery.</p>
<h3>Finding Elements</h3>
<p><code>document.querySelector(selector)</code> and <code>document.querySelectorAll(selector)</code> return an element or all elements respectively, using the CSS selector provided. You don&#8217;t need jQuery to do this anymore, and you don&#8217;t even need to extend anything to have this. These same methods exist on every element, searching their children for the selector provided. And if you want to shorten the call, set <code>Document.prototype.find = Document.prototype.querySelectorAll</code> and <code>Element.prototype.find = Element.prototype.querySelectorAll</code>.</p>
<p>You&#8217;ve already got the built-in <code>element.nextElementSibling</code>, but if you really want it to be shorter, you can make a getter on <code>Element.prototype.next</code> to return <code>this.nextElementSibling</code>.</p>
<p>We can make sure the built-in <code>element.matches</code> exists without prefix by using a pollyfill:</p>
<pre>if (!Element.prototype.matches) {
  Element.prototype.matches = Element.prototype.webkitMatchesSelector ||
  Element.prototype.mozMatchesSelector ||
  Element.prototype.msMatchesSelector ||
  Element.prototype.oMatchesSelector
}</pre>
<p>which allows an <code>element.closest</code> method to match jQuery&#8217;s method of the same name.</p>
<h3>Events</h3>
<p>Why not add <code>Element.prototype.on = Element.prototype.addEventListener</code> and <code>Element.prototype.off = Element.prototype.removeEventListener</code> (and the same to <code>Document</code> and <code>Window</code>) to shorten our event listening? Or to really shine we make the <code>on</code> method accept a <code>selector</code> and use <code>event.target.matches</code> to optionally call the listener, like jQuery, but built in.</p>
<p>You can add a <code>trigger</code> method if you don&#8217;t like <code>dispatchEvent</code>. It can take a string and make a MouseEvent, KeyboardEvent, CustomEvent, etc. for you.</p>
<h3>Lists of Things</h3>
<p>jQuery is nice because you can do one action to a whole list of elements at a time. What about extending <code>NodeList</code>? You know, that non-array you get back from calls like <code>element.children</code>, and <code>document.querySelectorAll</code>. We could add a bunch of methods to <code>NodeList.prototype</code> that have the same name as methods we add to <code>Element.prototype</code> except that the <code>NodeList</code> versions iterate over their elements and call the element method of the same name. This would allow <code>element.children.on('click', onClick)</code> or <code>document.find('.tag').removeClass('tag')</code>.</p>
<h3>Dealing with Nulls</h3>
<p>One things jQuery does nicely is it handles nicely when the thing you&#8217;re looking for doesn&#8217;t exist. $(&#8216;dummy-element&#8217;).on(&#8216;event&#8217;, function(){}) won&#8217;t break, even though there is no dummy-element. When we&#8217;re getting back NodeLists it&#8217;s not a big deal because iterating over 0 elements won&#8217;t cause any errors. But you may want to create a dummy element class to return from calls to <code>next()</code> or <code>prev()</code> which only return one element, so that you can continue to chain without breaking. I&#8217;ll let you figure out how this could best be done, but one idea is you might think of returning an empty <code>NodeList</code> from <code>document.createElement('div').children</code> or something.</p>
<h3>More Complex Settings</h3>
<p>Creating elements from strings of HTML is one thing that takes a little more doing. Fortunately, jQuery has already done the work for us and we can just add the method to <code>Document.prototype.create</code> or something. If you don&#8217;t want to go looking through the jQuery source, <a title="How to properly convert HTML string to a DOM element" href="http://krasimirtsonev.com/blog/article/Revealing-the-magic-how-to-properly-convert-HTML-string-to-a-DOM-element" target="_blank">Krasimir has already done the work for you</a>.</p>
<p>Another heavier item is setting a bunch of CSS properties at once, taking into account browser prefixes. Here is one solution that I&#8217;ve come up with which extends the style property of your elements.</p>
<pre>// Allows setting a lot of CSS styles at once, doing translations for vendor-
// prefixed styles.
// E.g. element.style.set({ color: red, transform: 'rotate(7deg)' })
var prefixes = ['webkit', 'moz', 'ms', 'o']
Object.defineProperty(CSSStyleDeclaration.prototype, 'set', {
  configurable: true,
  value: function(properties) {
    var style = this
    Object.keys(properties).forEach(function(property) {
      var value = properties[property]
      if (typeof style[property] == 'string') {
        style[property] = value
      } else {
        var capitalized = property.charAt(0).toUpperCase() + property.slice(1)
        for (var i = 0; i &lt; prefixes.length; i++) {
          property = prefixes[i] + capitalized
          if (typeof style[property] == 'string') {
            style[property] = value
            break
          }
        }
      }
    })
  }
})</pre>
<h3>The Rest</h3>
<p>Now that you&#8217;ve got the hang of it, you can see how you might easily add <code>append()</code>, <code>prepend()</code>, <code>addClass()</code>, and any number of things that you need from jQuery. Even if you only use the library for pet projects, it will be a good exercise in learning the DOM methods and build your understanding of how jQuery works internally as well.</p>
<p>Extending the DOM is a lot of fun and it can be quite enjoyable to work with native objects everywhere, sprinkled with your own helper methods. I don&#8217;t know if something like this will ever become mainstream, but you shouldn&#8217;t have any issues doing it with your own applications.</p>
<p>Because of potential conflicts (the main reason for <em>not</em> going this route), it is best to avoid extending the DOM in libraries that you want to load on other websites. Imagine if Facebook used a library like this in their Facebook Like button, and Google did the same in their Google Plus button. One of them would likely break the other, and they are so often on the same page that it would always be broken.</p>
<h3>MyStickies Uses it Minimally</h3>
<p>I use element prototype extension for MyStickies, but only to pollyfill missing functionality such as <code>element.remove</code>, <code>element.matches</code>, and <code>element.classList</code>. This way I won&#8217;t conflict with any other libraries (the MyStickies script is loaded on every page you browse when you install the extension), but I can still rely on the useful functionality that is standardized, but not implemented yet in every browser I support.</p>
<p>What say you? Is extending the DOM the epitome of all evil? Or would you do it for your own applications?</p>
]]></description></item><item><title>Use array-view Instead of Angular’s Filters</title><link>https://www.jacwright.com/692/use-array-view-instead-of-angulars-filters/</link><guid isPermaLink="true">https://www.jacwright.com/692/use-array-view-instead-of-angulars-filters/</guid><pubDate>Tue, 01 Jul 2014 12:25:07 GMT</pubDate><description><![CDATA[<p>AngularJS uses dirty checking to discover when changes have occurred to the data it is displaying on-screen. This simplifies your code. It speeds up development. And it allows you to use whatever-the-heck you want for your data and models, instead of forcing you to use their model classes (as Ember and Backbone require).</p>
<p>Dirty checking also re-runs filters. <a href="http://www.bennadel.com/blog/2489-how-often-do-filters-execute-in-angularjs.htm">A lot</a>.</p>
<p>Checking whether 32 has changed to 33 isn&#8217;t a big deal. Checking whether an array that, using Angular&#8217;s filters, is sorted and filtered by re-sorting and re-filtering the original is slightly more expensive. Doing that on every $digest (e.g. every key-stroke in an input field), especially on large arrays, could kill performance on slower machines and <em>mobile</em>.</p>
<h3>array-view</h3>
<p>Introducing <a href="https://github.com/jacwright/array-view">array-view</a>. array-view is a library that provides a <strong>sorted</strong>, <strong>filtered</strong>, even <strong>paginated</strong> view onto your original array. The view is an actual array that stays in sync with your original, so any push/pop/shift/etc will affect both arrays. And the best part, the view syncs only when required, not whenever $digest is run.</p>
<p>You can even use array-view to simply keep an array sorted automatically whenever you add new objects to it. It&#8217;s simple and easy to use.</p>
<p>And the best part: it&#8217;s still an array. Any library expecting arrays can use it. You can use it in your JavaScript SDK you provide for customers.</p>
]]></description></item><item><title>Inline HTML Editing Sneak Peek</title><link>https://www.jacwright.com/669/inline-html-editing-sneak-peek/</link><guid isPermaLink="true">https://www.jacwright.com/669/inline-html-editing-sneak-peek/</guid><pubDate>Fri, 29 Mar 2013 08:00:17 GMT</pubDate><description><![CDATA[<p>You are building a website, CMS, blog platform, ecommerce site, or web app. You need the user to edit their webpages, product info, or posts. You have an idea for how it will work, how your product will make this easier than any other. But after hours of searching for something you can use you are emotionally exhausted. The only things out there that aren&#8217;t ugly hobby projects are over-engineered replace-your-textarea solutions. You can&#8217;t have your vision. You can only have someone else&#8217;s complete package. Or you can start your own hobby project and stop because of time, releasing it among the crowds of other partially started WYSIWYGs.</p>
<p>I have felt keenly the pain of existing WYSIWYG solutions through the years. I&#8217;ve been meaning to take the time to build one from scratch that kept the core separate from the toolbar/interface. One that other&#8217;s could build custom solutions with. I finally made some time. It&#8217;s still not finished, but it&#8217;s in a usable state. I wanted to provide a sneak peak.</p>
<h3>Inline WYSIWYG Sneak Peak</h3>
<p>To make portions of an HTML page editable you can add a <code>data-editable="simple"</code> attribute to the element or call <code>editable.enable(element, 'simple')</code>. The following screenshot is the HTML for the page being edited in the video. We&#8217;ll be open sourcing it soon.</p>
<p><a href="https://www.jacwright.com/wp-content/uploads/2013/03/Screen-Shot-2013-03-26-at-2.46.png"><img class="aligncenter size-full wp-image-670" alt="Screen Shot 2013-03-26 at 2.46" src="https://www.jacwright.com/wp-content/uploads/2013/03/Screen-Shot-2013-03-26-at-2.46.png" width="560" /></a></p>
<p><iframe src="https://www.youtube.com/embed/ytIac-8ELAc" height="315" width="560" allowfullscreen="" frameborder="0"></iframe></p>
]]></description></item><item><title>I am an Original</title><link>https://www.jacwright.com/673/i-am-an-original/</link><guid isPermaLink="true">https://www.jacwright.com/673/i-am-an-original/</guid><pubDate>Tue, 26 Mar 2013 16:48:48 GMT</pubDate><description><![CDATA[<p>I&#8217;ve been quietly working for Original the last month. I&#8217;ve worked with startups before, but this is my first real startup experience. We have a remote team of six really great people. The hiring process was amazing. There was no resume submitted, just my <a href="https://github.com/jacwright/">Github profile</a> and a few Skype interviews. We are using <a href="https://hall.com/">hall.com</a> to keep in sync, <a href="https://www.pivotaltracker.com/">Pivotal Tracker</a> to organize the work, and <a href="https://github.com/">Github</a> branches and pull-requests for features and issue tracking for bugs. We are using <a href="http://nodejs.org/">Node.js</a> and <a href="http://angularjs.org/">Angular</a> and <a href="http://www.mongodb.org/">MongoDB</a> for our product. We&#8217;ve been able to build quickly and are excited to start getting feedback from an early alpha. We really are remote, the six of us being scattered from the West coast to the East, all working from home, coffee shops, colocation, or wherever we feel like. No skimping on benefits either in the name of cash flow. I feel well taken care of. Basically, this is my dream job. Minus an office <a href="http://ardrone2.parrot.com/">AR Drone</a>. I&#8217;ll keep you posted.</p>
]]></description></item><item><title>restdb: A NoSQL JavaScript Database</title><link>https://www.jacwright.com/662/restdb-a-nosql-javascript-database/</link><guid isPermaLink="true">https://www.jacwright.com/662/restdb-a-nosql-javascript-database/</guid><pubDate>Fri, 09 Nov 2012 16:51:43 GMT</pubDate><description><![CDATA[<p>I&#8217;ve <a title="My previous thoughts on how cool building a JavaScript database would be" href="https://www.jacwright.com/617/my-dream-javascript-database/" target="_blank">thought for awhile</a> how much fun it would be to make and/or hack on a JavaScript database. After seeing the implementation of an append-only B+ tree in JavaScript for a <a title="Chesterfield" href="https://github.com/Vertexio/chesterfield/wiki/Design-Proposal" target="_blank">CouchDB clone</a> I thought, what the heck, why not? So for <a title="Best place to work!" href="http://www.jivesoftware.com/" target="_blank">my company&#8217;s</a> hackday I thought it would be a great way for me to expand my knowledge and grow in new ways.</p>
<h3>The Why and What</h3>
<p>The real bottlenecks in distributed databases are network and storage, not the speed of the language. As long as the database is architected well, handles concurrency well, and is able to scale, then it should be perfectly fine to write it in any language. JavaScript and Node.js seem suited particularly well because of its ability to deal well with concurrency, IO, and many connections.</p>
<p>Using a dynamo-styled setup that can expand a ring of gossip-protocol-linked nodes should work well with node. Allowing socket-based connections as well as RESTful interfaces would work easily. Providing real-time websocket updates to web apps would allow for both a great web-interface into the health and load of the database as well as direct and instant updates to web apps relying on the data.</p>
<p>The format of this database is key-value. It stores JSON documents, but handles any other types of document too, from HTML to binary and images. They key for each document is a URI. This allows the organization of documents and related types (e.g. /tweets/1234 and /users/123/comments/1234). The database needs to be able to create custom indexes to sort documents in custom ways. And a mechanism needs to be in place to create and update those indexes and access them via a defined URI. Being inspired by CouchDB&#8217;s design documents, the indexes and other possible custom data handling (think document validation, triggers or callbacks, and refined ACLs/permissions) could be taken care of by creating special JSON documents called &#8220;apps&#8221;. These will be prefixed with an underscore to differentiate them from other documents.</p>
<h3>The Parts</h3>
<p>Rather than using a node B-tree I opted to use Google&#8217;s already stable <a title="Cool sorted key-value store written in C" href="http://code.google.com/p/leveldb/" target="_blank">leveldb</a>. Node.js has a module with bindings for leveldb, so this provides a great start but it doesn&#8217;t support streams. This is a negative because the whole document is loaded into memory by the leveldb module. If it supported streams we could send the data along as we received it from the file system and keep memory low, especially relavent when storing large files such as pictures and video.</p>
<p>I&#8217;m using <a title="The defacto standard for node.js http apps" href="http://expressjs.com/" target="_blank">express</a> for the REST server. This may be more than I need for this very specific use-case, but I know it well and can drop down to node&#8217;s HTTP stack sans-express if needed.</p>
<p>There is a <a title="Allows nodes to keep in sync and know about each other efficiently, even in extremely large clusters" href="https://github.com/bpot/node-gossip" target="_blank">gossip protocol</a> module which is a start for our dynamo style ring, but there is a lot more work to be done on coordinating where on the ring documents are stored. I&#8217;m thinking it can work like Riak where you specify a number of vhosts for the ring and each vhost would be a separate database and separate node process. Leveldb only allows one process to be connected at a time, to prevent contention. Map-reduce queries would be spread around to each vhost. And the vhosts would be spread around the cluster/ring as it is grown. I&#8217;ve also included an <a title="Allows for broadcasting your services (like a printer on a network)" href="https://github.com/agnat/node_mdns" target="_blank">mdns</a> module, or more commonly known as zero-conf or bonjour, so that the nodes on a network can automatically detect each other and auto-join a ring possibly, depending on a configuration value.</p>
<p>I&#8217;ll use the <a title="Like JSON, but smaller and faster" href="https://github.com/pgriess/node-msgpack" target="_blank">msgpack</a> module to serialize and store the JSON to leveldb. This will make it faster to pull the data off disk and into memory for indexing and map-reduce, and keeps the database smaller. The REST interface could support JSON and msgpack and then we could use the msgpack protocol in addition to the REST interface, allowing for connecting clients the choice to work in the smaller/faster binary format of msgpack.</p>
<h3>The Result: restdb</h3>
<p>I created and called this project <a title="A NoSQL JavaScript Database!" href="https://github.com/jacwright/restdb" target="_blank">restdb</a>, since it is a database very much based on the REST protocol. I was only able to get the initial parts working today. This was mostly because I forgot to use &#8211;data-binary with curl for testing and spent a long time figuring out why my image wasn&#8217;t displaying in the browser. But you may install and run the database if you&#8217;ve got node.js installed by following the instructions in the readme.</p>
<p>You can do PUTs, GETs, and DELETEs. And it works well. The next steps would be to handle JSON correctly with msgpack. And to give support for the specialized app documents.</p>
<p>Each index created will be a separate database that stores the index field as the key and the document id as the value. This might cause problems as each vhost would need to have an additional database to its own for each index created. CouchDB deals with similar problems as it has a b-tree file for each database and for each index (view) in each database. It recommends increasing the ulimit on your machine. ElasticSearch has similar requirements. So I figure we&#8217;re not in too poor of company.</p>
<h3>Future of restdb</h3>
<p>It was a lot of fun to think about how I would build a database. It turned out to be able to be an application server as well as a database since using the app documents you could host complete web apps from the database. This is like the CouchApp, but I feel it supports it from the ground up rather than a bolt-on or pivot afterwards.</p>
<p>I don&#8217;t feel confident in my ability to write a production-ready, mature, or stable database. So I will continue to work on this whenever I get the itch to have some fun hacking, but it is not something I will commit any large amount of time to. However, if you are also interested in hacking JavaScript and want something meatier than a webapp to sink your teeth into, please <a title="MIT licensed, come on and help out" href="https://github.com/jacwright/restdb" target="_blank">fork and contribute to restdb</a>. It has some great potential.</p>
]]></description></item><item><title>Caching data with localStorage and LZW compression</title><link>https://www.jacwright.com/611/caching-data-with-localstorage-and-lzw-compression/</link><guid isPermaLink="true">https://www.jacwright.com/611/caching-data-with-localstorage-and-lzw-compression/</guid><pubDate>Fri, 21 Sep 2012 14:10:09 GMT</pubDate><description><![CDATA[<p>Storing JSON strings to the browser&#8217;s localStorage allows you to show data quicker on page loads, both for desktop and mobile applications. Using localStorage allows you to even create simple apps without any server (no syncing or collaboration, like a TODO app could do).</p>
<p>But like anyone, you want to pre-optimize for the massive amounts of data you&#8217;re sure you will be storing to localStorage. You don&#8217;t want your users to run out of room. So you grab an easy compression algorithm and use the worker API so your UI doesn&#8217;t freeze up and you&#8217;re ready to go!</p>
<p>There is a storage vs performance tradeoff. But who needs that in today&#8217;s world of&#8230; oh yeah, mobile, nvmd.</p>
<p>You can see what this might look like here:</p>
<p><a href="https://www.jacwright.com/contacts/">/contacts/</a></p>
<p>&nbsp;</p>
]]></description></item><item><title>Culture is Everything</title><link>https://www.jacwright.com/654/culture-is-everything/</link><guid isPermaLink="true">https://www.jacwright.com/654/culture-is-everything/</guid><pubDate>Thu, 26 Jul 2012 13:03:32 GMT</pubDate><description><![CDATA[<p><em>Rewritten and reposted from a previous post on my personal company blog.</em></p>
<p>As developers we need to live in many worlds to write effective code. We need to understand multiple languages. And we need to be multi-cultural.</p>
<p>I&#8217;ve recently been working in Java. It&#8217;s been over 6 years since I dabbled in it, and I didn&#8217;t have a good mentor. I learned OOP with PHP (I know, I know, believe me, I know). And the closest I came to cultural Java is ActionScript 3. When coding Flash apps we used annotations, enums, dependency injection, many small classes to increase code-reuse and help with refactoring. I&#8217;ve been reminded of AS3 as I work with Java. But I still don&#8217;t feel I could write good Java without a template to go off of, without copying someone else&#8217;s style. That comes with time.</p>
<p>The past two years I have been working with JavaScript. At first, culture shock. I missed AS3, packages, solid class structure, working with hundreds of classes and files easily. You can&#8217;t do that in JavaScript. How are you supposed to organize large amounts of code?? It took me a year before I finally &#8220;got it&#8221;, fully. <em>Modules</em> are the way to organize related functionality, handle dependencies, and work with large code bases. Each file shouldn&#8217;t necessarily represent a class. You don&#8217;t write a class for every piece of functionality. Functional programming (to me, like the old days of PHP) is better than OOP in many cases. Lambda functions and callbacks are useful and readable. Function closures are an excellent way to encapsulate data and functions, similar to how classes do for Java. You still use classes, but not like with Java.</p>
<p>You can reduce your JavaScript overhead (size <em>and</em> complexity) by immersing yourself into the JavaScript culture.</p>
<p>Sometimes companies write JavaScript like they do their Java, in the <em>Java</em> culture. With long variable and method names, many classes (for everything), and even sometimes utilities that help provide private, protected, and public variables! They steer clear of closures. They don&#8217;t use modules.</p>
<p>When we write JavaScript we should strive to engender a JavaScript culture for our code. And though developers may feel out of place writing this kind of JavaScript, as I did, and as I have recently felt out of place writing Java, with time we will all learn to be multi-cultural.</p>
]]></description></item><item><title>My experience with Node.js</title><link>https://www.jacwright.com/637/my-experience-with-node-js/</link><guid isPermaLink="true">https://www.jacwright.com/637/my-experience-with-node-js/</guid><pubDate>Mon, 10 Oct 2011 11:44:12 GMT</pubDate><description><![CDATA[<p>I love <a href="http://nodejs.org/">node.js</a>, but I didn&#8217;t always. </p>
<h3>Initial Impression</h3>
<p> When I first read about node.js I thought, &#8220;you&#8217;ve got to be kidding me. Javascript is slow and user-interface-oriented. The only reason you&#8217;d use it on the server is because you don&#8217;t know any other languages.&#8221; And I moved on. </p>
<h3>Recommendation from a Friend</h3>
<p> The next time I heard about it, my friend Derek Andriesian said he was using node for some of his applications. I knew Derek had experience in PHP, Ruby, and other languages, so I asked a little more why he would go with Javascript. Apparently Derek liked the event model it used. He said it was pretty cool controlling the flow of the request as it came in and went through the system. He also said to use express.js, an HTTP server for node. I still didn&#8217;t touch it. </p>
<h3>Javascript Inundation</h3>
<p> At my day job I started doing Javascript, client side, a lot. It became my daily grind. But I had been working in ActionScript for so long, not having proper class syntax (my opinion), packages, and imports was a major stumbling block. I had managed to get a very large jquery file, and even after breaking it apart into multiple files organized by app section, it was very hard to make changes to anything, and to share data across the sections. I needed more organization. I separated out much of the data code and more of the jquery code, but then I had a problem of having more than 20 Javascript files to deal with, then 30, then more, and ensuring they were in the correct order, and updating my build script whenever I added on, and tweaking the script when I got the new file in the wrong location. Dependency management would be really nice at this point. I found CommonJS, a standards body for dealing with more complex Javascript. They had a standard around &#8220;modules&#8221; for Javascript. I implemented it and built a build script that traversed the require statements and pulled everything into one script. Things were much better. </p>
<h3>&#8220;Getting&#8221; Node.js</h3>
<p> After that, I looked into node more. I knew how modules worked from my client-side journey. And I &#8220;got&#8221; what node.js is all about. Node is about handling many connections at once, without dealing with threads. Node is about simplicity for simple servers, and flexibility for complex ones. In node, I can return the results of a web request to the client and then continue to run some code (such as sending an email or logging information that isn&#8217;t important to the result). I can use function closures to hold data for connections when using websockets or regular sockets. Node isn&#8217;t just Javascript on the server for people who don&#8217;t know other languages. It&#8217;s a different paradigm for programming server-side applications. And it&#8217;s actually pretty fast, for Javascript, because it uses some of the most advanced run-time technology around with Google&#8217;s V8 engine. </p>
<h3>It&#8217;s Just Fun</h3>
<p> It&#8217;s just been fun to develop in node. There are a ton of libraries available and more coming all the time. Creating REST APIs is a breeze with express.js. There is a lot of excitement and activity around node (some may call it hype, but whatever it is, it&#8217;s furthering the platform). There are some who are vehemently against node, but I haven&#8217;t read anything from anyone that was accurate and a good reason for not using node. If you&#8217;re a poor programmer, you&#8217;ll write poor programs in node same as in PHP. It isn&#8217;t a magic bullet. But if you can write code, node is a lot of fun. I also feel my code is easier to change and read, but I&#8217;ve also been writing heavy Javascript for 2 years now, so take it with a grain. <span class="Apple-style-span" style="color: rgba(134, 34, 35, 0.398438); font-family: 'Rock Salt', arial, sans-serif; font-size: 15px; font-weight: bold; line-height: 19px; word-spacing: 0px;">Getting Started</span> There are <a href="http://www.google.com/search?q=nodejs+getting+started">plenty of guides</a> and tutorials on getting started. Be sure to check out <a href="http://npmjs.org/">npm</a> too if you don&#8217;t manage to come across it in the basic guides, the node module package manager (like ruby&#8217;s gems). After than you can check out <a href="http://expressjs.com/">express.js</a> a great web server for building apps and REST APIs, node.js <a href="http://learnboost.github.com/cluster/">cluster</a> which launches several processes for each processor core to maximize performance, <a href="http://socket.io/">Socket.io</a> that gives you websockets (or alternatives for browsers that don&#8217;t support) for realtime data streaming, <a href="http://redis.io/">Redis</a> a key-value store which node devs seem to like a lot, and <a href="http://www.mongodb.org/">mongodb</a> a document database which also seems to be very popular for node.js users. <a href="http://couchdb.apache.org/">CouchDB</a> and <a href="http://wiki.basho.com/Riak.html">Riak</a> are also two databases that work well with node because of their Javascript orientation. And <a href="http://www.elasticsearch.org/">elasticsearch</a> is a nice search service that works well via a REST API.</p>
]]></description></item><item><title>My Dream Javascript Database</title><link>https://www.jacwright.com/617/my-dream-javascript-database/</link><guid isPermaLink="true">https://www.jacwright.com/617/my-dream-javascript-database/</guid><pubDate>Sat, 06 Aug 2011 17:40:22 GMT</pubDate><description><![CDATA[<h3>I have a dream</h3>
<p>A dream that one day I will be able to use a NoSQL database solution built on NodeJS. A dream that people won&#8217;t laugh at my desire to build such a database. A dream that it will work well, and that it will bring together all the best features from my favorite NoSQL databases into one product. A dream that someday I will have the time to spend on something like this, and to learn about Amazon Dynamo/map-reduce/file-journaling/etc hands on in a language I enjoy.</p>
<h3>Seriously guys, a Javascript Database would be cool</h3>
<p>I&#8217;m actually completely serious. For some this dream might be a nightmare (the Java-heads I work with at my day job think I&#8217;m insane). But I think it would be completely awesome. And what&#8217;s more, I think there will be a lot of other people who think the same.</p>
<p>It seems everything Javascript is all the rage these days, especially NodeJS (node). Some evidences: <a href="https://www.dotcloud.com/">DotCloud</a> said their most popular stack by far was node. I wrote a VoltDB driver for node which in just a few weeks became the most popular driver. And <a href="http://couchdb.apache.org/">CouchDB</a> is quite popular. Its interface is only REST and its map/reduce you write in Javascript (though it is implemented in Erlang). Also Riak uses Javascript for its map/reduce.</p>
<h3>My Wishlist</h3>
<p>I&#8217;ve written an extensive list of features I&#8217;d like for this so that if I ever get time to work on it I can remember what I wanted. Features come from <a href="http://www.basho.com/products_riak_overview.php">Riak</a>, <a href="http://couchdb.apache.org/">CouchDB</a>, <a href="http://www.mongodb.org/">MongoDB</a>, and my own imagination. Here are the highlights:</p>
<ul>
<li><span class="Apple-style-span" style="line-height: 20px;">It should be written <strong>amazon dynamo-style</strong> so that adding/removing servers is simple when growing/shrinking the cluster, maintenance is easier</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;">Should be <strong>written for nodejs</strong>. I&#8217;m guessing that could bring high-performance since there will be no [insert language here]-to-javascript bridge, and since network and disk IO (which node excels at) are a major part of dynamo. We&#8217;ll see</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;"><strong>Map/reduce using Javascript</strong>, allowing multiple phases and links/link-walking like Riak</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;">(Don&#8217;t roast me) Allowing <strong>in-place updates</strong> both on an individual document as well as at the end of a map/reduce query. These updates would be Javascript functions that alter the object in-memory to be written back to disk. The object could be updated thousands of times/second while it was in memory and persisted to disk every few hundred milliseconds or so. Speed like <a href="http://www.mongodb.org/">MongoDB</a>&#8216;s in-place updates, simplicity by using Javascript to alter the document, and brining the update/code to the document rather than moving the document to the client and back again for the same code to be run. Faster. Especially great for updates over many documents (can be parellelized). Allows only certain fields to be changed instead of the whole document to be overwritten, so safer transformations for the developer (than say Riak or CouchDB). E.g. if I just want to increment a field, I don&#8217;t have to worry about whether someone is changing the firstName of the document at the same time and that I might overwrite it with my complete document PUT. [Whew, that was long]</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;"><strong>RESTful interface</strong>, probably bucket/database then key (e.g. /db-name/doc-key)</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;">Ability to have map, reduce, and update <strong>functions stored as documents</strong> in the database and referred to by name (bucket/key) in map/reduce/update queries. Also ability to store complete queries as documents in the database.</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;">Pre/post <strong>commit hooks</strong> on documents allowing validation as well as other-domain side-effects such as sending an email when a document is stored, full nodejs abilities</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;"><strong>Index creation</strong> (like CouchDB views?), but allow sorting</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;">Robust <strong>URL rewriting</strong> so that one might write a self-hosted application</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;"><strong>User authentication</strong> and permissions, pluggable authentication mechanisms</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;"><strong>Pluggable storage</strong> system, in-memory, disk, S3(?)</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;"><strong>Replicatable</strong> like CouchDB so you can have replicates across data-centers, or even partial data on your local machine, maybe even mobile someday</span></li>
<li><span class="Apple-style-span" style="line-height: 20px;">Admin <strong>GUI</strong> for managing the cluster, and email notifications that can be sent out</span></li>
</ul>
<h3><span class="Apple-style-span" style="line-height: 20px;">Reasons for a Javascript Database</span></h3>
<p>Here are my reasons. Node is great at IO, which distributed databases deal a lot with. Node is fast thanks to V8. Many of these databases use Javascript anyway for querying, why not use it for the database? I don&#8217;t know Erlang, and I know I wouldn&#8217;t be able to sufficiently alter the feature sets of the existing solutions into my ideal database, so why not write my own, everyone else is. :) I like the idea of the database hosting the application, thus replicating it out to multiple nodes along with the data, <a href="http://couchapp.org/">CouchApp</a>-style. But I want to do more than what CouchDB allows, so I can have real applications completely hosted. And I want links like in Riak. And I want in-place updates like in MongoDB. The only other thing I would want that I wouldn&#8217;t actually tackle would be lucene indexing. So maybe I can provide a <a href="http://www.elasticsearch.org/guide/reference/river/index.html">river</a> for <a href="http://www.elasticsearch.org/">elasticsearch</a>. :)</p>
<div>And the biggest reason is I think it would be so fun to write and so much to learn along the way. Even if nobody ever uses the thing. Actually, that might be safest for everybody.</div>
]]></description></item><item><title>Sharing my Class class.</title><link>https://www.jacwright.com/562/sharing-my-class-class/</link><guid isPermaLink="true">https://www.jacwright.com/562/sharing-my-class-class/</guid><pubDate>Sun, 03 Apr 2011 15:10:05 GMT</pubDate><description><![CDATA[<p>I&#8217;ve been using a little class utility to create classes for awhile and thought I&#8217;d share it and discuss what I did and why. First the goals, then code, then examples and discussion.</p>
<h3>Goals</h3>
<p>When I created this I basically wanted something that looked like a class instead of a function I was extending (I know, non-javascripty, but ecmascripty in laster versions), but that was still 100% native Javascript inheritance.</p>
<ul>
<li>Looks like a class from other more OO languages</li>
<li>Uses native JS prototype inheritance so &#8220;myobj instanceof MyClass&#8221; still works.</li>
<li>Small, uncomplicated, don&#8217;t want tons of hacks and work-arounds.</li>
</ul>
<h3>Code</h3>
<p>The most updated code can be found on github and requires the compat.js file in the same repository needs to be included for cross-browser compatibility if using in the browser: <a href="https://github.com/jacwright/jslib/blob/master/class.js">https://github.com/jacwright/jslib/blob/master/class.js</a></p>
<h3>Examples and Discussion</h3>
<p>To create a new class you new up an instance of Class like this:</p>
<pre>var Person = new Class({
    constructor: function(name) {
        this.setName(name);
    },
    setName: function(value) {
        this.name = value || 'unknown';
    }
});
console.log(Person);</pre>
<p>When you output the Person class you&#8217;ll see that it is actually just the constructor function. If you were to create this same Person class with regular Javascript you would get the exact same end result.</p>
<pre>var Employee = new Class({
    extend: Person,
    constructor: function(name, title) {
        Person.call(this, name); // call the super-class constructor
        this.title = title;
    },
    setName: function(value) {
        if (!value) throw new Error('Employees must have a name.');
        Person.prototype.setName.call(this, value); // call super setName
    }
});
var jacob = new Employee('Jacob Wright', 'UI Guy');
console.log('Is employee?', jacob instanceof Employee);
console.log('Is person?', jacob instanceof Person);</pre>
<p>Creating a sub-class is really easy. You use the word &#8220;extend&#8221; (not &#8220;extends&#8221; because that is a keyword in javscript/ecmascript) and assign it the class you&#8217;re extending. It uses javascript prototype extension under the hood. You end up with the exact same thing you would not using the Class class. You see I still call the super class constructor and methods the same as I would in normal Javascript. If you have the class in its own closure you could define a property &#8220;var parent = Person.prototype;&#8221; before the class and then change your calls to the super class to &#8220;parent.setName.call(this, value)&#8221; if you are so inclined.</p>
<p>You can also pass in &#8220;implement&#8221; and the methods on that class (or classes as you can also give it an array of classes) will get copied over to the prototype of this one. It is not actual inheritance so &#8220;instanceof&#8221; will not return true, and I don&#8217;t have any methods to ask if a class implements another, though that might be useful.</p>
<p>Statics are easy as well.</p>
<pre>var Developer = new Class({
    extend: Employee
}, { // 2nd parameter is the static definition
    devs: {},
    factory: function(name) {
        if (this.devs.hasOwnProperty(name)) return this.devs[name];
        return this.devs[name] = new Developer(name, 'Developer');
    }
});
var jacob = Developer.factory('Jacob Wright');</pre>
<h3>Working Parts</h3>
<p>Things I like about how it is implemented:<br />
I thought it was stupidly clever to actually call the constructor &#8220;constructor&#8221; instead of &#8220;init&#8221; or &#8220;initialize&#8221; or whatever else other class helpers do. I don&#8217;t even have to remove it from the prototype since native prototypes define the constructor on them anyway. I only remove extend and implement from the prototype (though maybe I don&#8217;t even need to do that).</p>
<p>The empty constructor. You&#8217;ll see in the code there is an EmptyClass function. I use this in the prototype inheritance by assigning the prototype of the extended class to that of EmptyClass. Then I can create &#8220;new EmptyClass()&#8221; for the prototype chain and accomplish the same thing without running constructor code on the prototype object. This keeps the constructor of the parent class from getting called until you actually create a new instance of the class.<br />
UPDATE: Using Object.create() does the same thing as using the empty constructor trick and I use that now to stick to standards.</p>
<p>Returning from a constructor. When a function returns a value and you attempt to create an object with the &#8220;new&#8221; operator, you actuall get back the returned value instead of a new class instance. If I were to return the number 42 from the Class function then &#8220;var num = new Class()&#8221; would give me 42 for num. You can see from the code that the Class constructor returns the impl.constructor. This is an interesting feature of Javascript and allows me to give back the constructor passed in the impl object (i.e. the prototype object) to the caller after I&#8217;ve set up its extend and implement parts.</p>
<h3>Credits</h3>
<p>Whether this is something useful or not I hope it is an interesting approach to the problem of OO and has helped you learn something new. I picked up the &#8220;empty constructor&#8221; trick from Prototype, the general idea of using &#8220;new Class&#8221; from MooTools, some of the implementation from ExtJS and the others, and then just simplified down as much as possible.</p>
]]></description></item><item><title>Client-side-only Javascript Amazon S3 CMS</title><link>https://www.jacwright.com/556/client-side-only-javascript-amazon-s3-cms/</link><guid isPermaLink="true">https://www.jacwright.com/556/client-side-only-javascript-amazon-s3-cms/</guid><pubDate>Mon, 07 Mar 2011 07:00:00 GMT</pubDate><description><![CDATA[<p>Amazon S3 just released a feature that allows you to host a <a href="http://aws.amazon.com/about-aws/whats-new/2011/02/17/Amazon-S3-Website-Features/">website on S3</a>. I&#8217;ve been wanting this feature for years and now that it&#8217;s here I can&#8217;t keep my mind off of building a CMS on top of it. There&#8217;s just so many interesting challenges to figure out and technical coolness.</p>
<h2>Javascript Client</h2>
<p>The idea is to build a CMS that is 100% HTML and Javascript, hosted from S3 itself. You would upload the initial files for the admin, set an appropriate bucket policy, and set up the website features on your bucket (or more likely when I&#8217;m further along put your Amazon creds into an online upload form and allow a little web service to do it for you). Then you would navigate to https://yourbucket.s3.amazonaws.com/admin/index.html and login to your hosted javascript admin. Logging would keep the key and secret in memory and you&#8217;d be able to add, delete, update, and otherwise work with your website on S3, from S3.</p>
<h3>Benefits of Client-side Javascript and S3</h3>
<p>There are some really cool aspects to a 100% client-side Javascript application and hosting on S3.</p>
<p>The biggest IMO probably being pluginability. Most people can write Javascript and many know jQuery, so writing plugins that utilized both to extend the interface, respond to actions, and otherwise modify the system would be easy and allow for very customized web admins and sites. You also have a built-in REST API that you can store anything to. If you want to add TODOs to the cms, you can store them in /api/todos/ immediately without having to create a new database table and worry about setup. You can also update your TODO plugin later to include priority without needing to update tables.</p>
<p>There is also the draw of high-traffic websites not hitting any servers you have to worry about. Let Amazon deal with the hosting and meet their &#8220;99.99% availability&#8221;. You can handle massive load. And it&#8217;s cost-effective. And stable/redundant, you don&#8217;t need backups. And you can front the whole thing with CloudFront to deliver your pages at the closest locations possible (you&#8217;ll have to invalidate pages that get updated though).</p>
<h3>Drawbacks</h3>
<p>It&#8217;s hard to have dynamic websites without server-side logic. You can&#8217;t accept comments on your posts. You can&#8217;t resize images on the fly or even at upload time (well, with canvas, but that&#8217;s something to research more on viability). You can&#8217;t send out emails. And you can&#8217;t utilize cross-site resources or APIs (such as CloudFront or Akismet). However, if this cms turns out well and people use it, I can create a service that will allow all of these things for registered users.</p>
<h3>Previous Work</h3>
<p>When looking around for an S3 Javascript client I found that back as far as 2006 <a href="http://decafbad.com/2006/04/03/javascript-apps-with-readwrite-access-to-s3">people</a> were thinking about building <a href="http://ajaxian.com/archives/s3-javascript-bindings">Javascript applications hosted from S3</a>. It didn&#8217;t really seem to take off, but there&#8217;s a lot more work that&#8217;s been done on S3 since then. It might be more interesting now. Especially if some general hurdles are figured out so that your site isn&#8217;t hacked, spammed, and ruined.</p>
<h2>Security</h2>
<p>My first and biggest concern for something like this is handling security. How does one have an all client-side application and still allow secure login and user management? The first thing that comes to mind is the obvious: why not have the user enter their Amazon key and secret to login? That&#8217;s a good idea. At least, it will work. Using a the bucket policy file we can specify an area of the site that is private for reads and writes which can store website data (all of it will be private for writes). But if this is going to be something I use, I don&#8217;t want to go look up my amazon key and secret every time I need to log in. So I brainstormed other solutions.</p>
<h3>AES</h3>
<p>I need 2-way encryption that will allow me to store the amazon key and secret in a public location. Public because you can&#8217;t access it before you&#8217;re logged in now can you. The most secure 2-way encryption I found was <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES</a> which is used in government and many other places. It is quite secure and wonderfully <a href="http://www.movable-type.co.uk/">Movable Type</a> has implementations of <a href="http://www.movable-type.co.uk/scripts/aes.html">AES</a> and <a href="http://www.movable-type.co.uk/scripts/sha1.html">SHA1</a> and lots of other stuff in Javascript.</p>
<p>A user will register with a username (or email), password, amazon key, and amazon secret. The password will be used to encrypt a string of &#8220;username:key:secret&#8221; and saved to a public file by the sha1 of the username under the private folder api/auth/. Having the folder private will prevent people from seeing what is in it. You&#8217;d have to guess the sha1 to even get the file, and then you&#8217;d have to know the password to decrypt it. After registering, a user can login with their username and password. The username will be sha1&#8217;ed and the user file will be loaded (if it exists). Then the password will be used for deciphering the contained hash and the key and secret put safely away inside a Javascript closure in memory.</p>
<p>This seems quite secure. For one, the username and password never even go over the wire, so even if we weren&#8217;t going to use SSL (which we are) the only thing a man-in-the-middle would see is the encrypted AES hash. If anyone has better ideas or sees holes in this I&#8217;d love to fix it up more securely.</p>
<h2>Features</h2>
<p>My other main concern is whether one could really support many features of a common web cms with only client-side logic. I&#8217;ve been quite surprised at how many features I&#8217;ve thought could work with simple Javascript. Here is a list of those I&#8217;ve thought of so far:</p>
<p><strong>Templates</strong>: pages, content, templates, etc. could be stored in the api and whenever you update a page, jQuery can put the content into the template and save the whole file out to its location. Templating would be similar to other systems except that when you change the theme or update the template it will have to re-process each file that uses the template individually.</p>
<p><strong>Plugins</strong>: plugins would work by attaching onto hooks or listeners throughout the system or adding new editable-field types. They could add HTML to the admin to include new buttons or menus. And their javascript could be concatenated and minified into one plugin file that gets loaded at runtime whenever you activate a new plugin, then you have one small file to load when you log in.</p>
<p><strong>File upload</strong>: it turns out you can sign a form a certain way in order to upload files to S3. This is great since you can&#8217;t load (in all browsers) files into Javascript first and then sign them and put them to S3. So lage images, video files, etc. can be done without passing through Javascript.</p>
<p><strong>Blog support</strong>: you can easily do a blog by recompiling the home-page template whenever you publish a new post. You could even recompile an RSS feed client-side and put that to S3 at the same time.</p>
<p><strong>Shared content</strong>: menus, footer content, and other shared content could work, just like when editing a template. Any page that piece of content is shown on will need to be recompiled, however this could easily happen in the background with a little progress indicator while you continue editing or modifying your website. If you try and close up shop before it is finished the admin can warn you that leaving the page will leave your site partially undone.</p>
<p><strong>Additional users</strong>: you could either 1. give access to another user&#8217;s amazon account to edit your site and let them register using their amazon key/secret, or 2. you could add more users with username/password using your amazon key/secret which will create their &#8220;auth file&#8221; using those creds. They would never need to touch your key/secret, although they could find it out, so don&#8217;t use this method with people you don&#8217;t trust.</p>
<p><strong>Remember me</strong>: you could store username/password in a cookie for &#8220;remember me&#8221; functionality. If you do this then maybe using the sha1 of the password to encrypt the AES cypher and storing the sha1 password in the cookie would be a better idea. Keep that thing as safe as possible. Though unsafe plugins could take either version out of the cookie and use it to obtain your key/secret. Maybe use a separate path for login since cookies can restrict on path? Something to think through more.</p>
<p><strong>Code highlighting</strong>: code or syntax highlighting can be done at save-time using the Google Code Prettifier project or another Javascript-based project of similar sort. It would just be a plugin.</p>
<p><strong>Content</strong>: you can have all the same content other CMSes allow: html, js, css, flash, images, galleries, xml, etc. E.g. use a Javascript plugin to create the XML that your Flash photo gallery needs to run.</p>
<p><strong>Versioning</strong>: you can use S3&#8217;s built-in versioning to keep every version of an object saved to the bucket and revert back to an old version if desired, or undo a delete.</p>
<h2>Open Source</h2>
<p>This is something crying out for open source. It has been really fun to start and should be really fun to continue working on. I&#8217;ve put the beginnings up on github calling it <a href="https://github.com/jacwright/StaticSite">Static Site</a>, since it is hosted on S3. Should I call it S2? :) I also have <a href="http://staticsite.org/">staticsite.org</a> hosted from my own S3 bucket which will be using the CMS as it comes along. I hope to steal a moment here and there from my busy work schedule when I need a break in the evenings to keep working on it.</p>
<p>What do you think? Would you use it?</p>
]]></description></item><item><title>Into the swing of Javascript</title><link>https://www.jacwright.com/501/into-the-swing-of-javascript/</link><guid isPermaLink="true">https://www.jacwright.com/501/into-the-swing-of-javascript/</guid><pubDate>Mon, 14 Feb 2011 08:00:49 GMT</pubDate><description><![CDATA[<p>My last post was a long time ago. I&#8217;ve been busy. Unfortunately rather than being some interesting article occupying the top spot on my site it has been a short bemoan of missing Flash. I still miss ActionScript 3 from time to time, but I&#8217;ve really been enjoying Javascript development, both in the client and on the server. There have been a couple things that have made it more manageable to me. I want to share.</p>
<h2>Multiple Files</h2>
<p>One of the hardest parts of heavy Javascript starting out was fitting everything into a few files. Being used to a-class-per-file with ActionScript has made cramming a whole application into two or three files quite unorganized, no matter how commented the code. I know combining Javascript files isn&#8217;t a big deal, but what really made it work for me is when I integrated it into my IDE workflow (I use <a href="http://www.jetbrains.com/idea/">IntellJ</a> which has the best Javascript intelligence I&#8217;ve found in any IDE—<a href="http://www.jetbrains.com/webstorm/">WebStorm</a> would be the same, without as much bloat). I have a maven script that uses <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a> (could use Ant easily as well) and it is set up to my Cmd+S key-binding so whenever I save a Javascript file it saves the file and recombines the rest into one file. A downside is that I have to be cognizant of what order (dependency-wise) the files go in and to be sure to add them to my maven script as I add new files. I&#8217;d like to look at Google&#8217;s Closure compiler which allows the use of a require() method to include scripts and figures out dependency for you when putting them together. This would be nice.</p>
<h2>Realistic Classes</h2>
<p>Getting a simple Class utility put together that makes creating classes more readable but still uses does it &#8220;the native way&#8221; under the hood has made class structures enjoyable. I use a modification of my <a href="https://github.com/jacwright/simpli5/blob/master/src/class.js">simpli5 class utility</a> (I don&#8217;t use the rest of simpli5 much however since we&#8217;re still not completely HTML5 yet). Consider the difference between the following:</p>
<pre>
function MyClass(state) {
    this.state = state;
}
MyClass.prototype.doSomething = function() {
    this.state = this.state + 42;
};
// versus
var MyClass = new Class({
    constructor: function(state) {
        this.state = state;
    },
    doSomething: function() {
        this.state = this.state + 42;
    }
});
</pre>
<p>I think it is much more readable.</p>
<h2>Packages</h2>
<p>I also use a form of package management, and I wrap all my files in function closures so I don&#8217;t clutter the global scope. But I hate always referencing Classes or package-level object and methods with their full package name, so I use imports&#8230;sorta.</p>
<pre>
(function() {
    // imports
    var Class = mypackage.Class,
        OtherNeededClassOrObject = mypackage.somepackage.ClassOrObject,
        subpackage = mypackage.subpackage,
        MySuperClass =subpackage.MySuperClass;

    subpackage.MyClass = new Class({
        extend: MySuperClass,
        constructor: function() {
            MySuperClass.call(this); // super(); in Flash
        }
    }, {
        /*statics*/
    });
})();
</pre>
<p>I&#8217;m quite happy with the setup I&#8217;ve established, using separate files, classes, and package management. It keeps it close to how Javascript works without any &#8220;magic&#8221; or hacks, and it makes my code much more readable and manageable to me. I&#8217;ve also borrowed a few ideas from <a href="http://documentcloud.github.com/backbone/">backbone.js</a> for a base Model class that will load data from my APIs. I didn&#8217;t need the rest of backbone for this project so just used their ideas, but in future projects I would consider it.</p>
<p>Happy coding!</p>
]]></description></item><item><title>I miss Flash</title><link>https://www.jacwright.com/495/i-miss-flash/</link><guid isPermaLink="true">https://www.jacwright.com/495/i-miss-flash/</guid><pubDate>Fri, 24 Sep 2010 21:46:32 GMT</pubDate><description><![CDATA[<p>Javascript can be fun, but I miss Flash. I miss having packages. I miss having private, protected, and public variables. I miss having getters and setters. I miss the organization of a Flash project. Javascript is so messy, even when it&#8217;s done well.</p>
<p>Mostly, I miss the Flash community.</p>
<p>Don&#8217;t worry duders, I&#8217;ll be back.</p>
]]></description></item><item><title>In-memory Javascript Database</title><link>https://www.jacwright.com/489/in-memory-javascript-database/</link><guid isPermaLink="true">https://www.jacwright.com/489/in-memory-javascript-database/</guid><pubDate>Fri, 24 Sep 2010 08:00:51 GMT</pubDate><description><![CDATA[<p>I wrote an in-memory Javascript database for a project at work. &#8220;<em>What?!&#8221;</em> you say? You heard me. In-memory&#8230;Javascript&#8230;database. Yes, there is a use-case for it. So our current HTML5 project has moved back its target coverage to IE8. Darn. No CSS3, standard event model, or implicit getters/setters (meaning no data-binding). But it still has localStorage and sessionStorage, the ~5MB data store that an HTML5 app can use. So I wrote a JS database which is really just an array of objects with some easy API for filtering, sorting, limiting, and finding the object you need. Now I can store a bunch of data in memory, getting only the newest content when I poll the server, and much more quickly sort, filter, etc. the data for the user without round-trips to the server. And then when they close the app, I can JSONify the data in the localStorage and load their app much more quickly when the come back. They&#8217;ll immediately see where they left off, then when the first server poll finishes they&#8217;ll see they&#8217;ve got unread items that they can scroll up to view. I found taffydb.com already existed, but I sure hate unreadable code, and I thought how I could make it faster using the built-in Array filter() method. So I built my own. I also added a full-text search index that can be used for finding based off of keyword matching. I&#8217;m working on refactoring for a different query API that supports ORs and sub-expressions–or expressions within parenthesis (e.g. name == &#8220;Jacob&#8221; and (age == null or age &gt; 10) and cool == true). Follow the <a title="JaDE - Javascript Database Engine" href="https://github.com/jacwright/JaDE">progress of JaDE</a> (Javascript Database Engine) on github.</p>
]]></description></item><item><title>Reintroducing – Flight Stealth!</title><link>https://www.jacwright.com/484/reintroducing-flight-stealth/</link><guid isPermaLink="true">https://www.jacwright.com/484/reintroducing-flight-stealth/</guid><pubDate>Thu, 23 Sep 2010 07:00:40 GMT</pubDate><description><![CDATA[<p>Flight Stealth was a Flash component framework a year ago. It went away as the creators of Stealth and OpenFlux combined to create Reflex last year. But Stealth is back! Reflex is forked.</p>
<p>There has been some disappointment that Reflex has forked. Many people have ignorantly but understandably attributed the split to Tyler, the project lead over Flight Stealth. However, Ben Stucki was the one who wanted to fork. After deciding to fork and leave Reflex he asked Tyler if he could keep the Reflex name. Tyler graciously consented, deciding to use the old Stealth name, but since the only difference in a new fork is the projects&#8217; names, he&#8217;s gotten the short end of the stick, losing mind share, and for those who were against the fork, getting the blame.</p>
<p>I believe both projects will move forward as a result of this fork. Their project leads each have a vision and direction in mind, and I&#8217;m seeing the difference in goals will lead to different products and needs addressed by the projects. Although as Flash developers who currently only have one robust component set in our tool belts, it is hard to imagine the need for more than one alternative. However I believe we will find that one-size-fits-all is not an ideal goal and a specialized framework will always win out over a generic one in its own problem domain.</p>
<p>Good luck to both projects and make us proud.</p>
<p>As an aside, I designed the <a title="Flight eXperience Design" href="http://flightxd.com/">flightxd.com</a> website where Flight Stealth will be hosted. I am quite proud of what I did, not being a designer.</p>
<p>Please join the <a title="Stealth Google group" href="http://groups.google.com/group/flight-stealth">Stealth mailing list</a> and find out how you can help. We have a website to put together, user docs that need to be written, components that need to be written, and much much more.</p>
]]></description></item></channel></rss>