Archives for category: Technology

I have been working on an auto-complete web service that searches Amazon’s Product Advertising API.  I built it in Node.js and using the APAC package made it really easy to query the API. The only thing that was extremely impractical was the JSON data returned by APAC.

Since Amazon’s API only returns data as XML, APAC uses xml2json to convert the XML to JSON. Unfortunately the resulting JSON is quite ugly. I wanted to be able to choose the data I needed and copy it to a new, clean JSON format. My solution was to create json2json.

json2json lets you create a template that describes how to transform the original JSON to a new structure. I wrote the Node.js package and example template in CoffeeScript because it has a much cleaner and simpler syntax than JavaScript. However, it is extremely simple to convert to JavaScript (click on “Try CoffeeScript”) and can easily be modified for use in a browser. Check out the (crude) documentation and example files and let me know what you think.

Share

Facebook Open Graph logo

I’ve been working on Rembly using several javascript libraries: Spine.js, Mustache.js, ICanHaz.js, and Facebook’s JavaScript SDK. These have made application development easier, but not always easy enough! I wrote previously about my enhancements to ICanHaz.js for loading Mustache templates. This time around, I wanted to use Facebook’s JavaScript SDK with less “overhead” and a simplified API.

I created FBAPI.js to handle the setup requirements that Facebook’s SDK requires, such as adding a “root” tag to the page before loading the SDK. Now FBAPI.js takes care of all the SDK requirements and lets you use the Graph API without worrying about the overhead. FBAPI.js adds helper methods for event binding and retrieving user data.  However, the best part of FBAPI.js is that you don’t have to wait for the page or javascript dependencies to be loaded before you can start using it! All methods use promises and callbacks. This lets you run your scripts in any order you want!

Check out the Github repository and let me know what you think!

Share

Overloaded

I just answered a Stack Overflow question from a couple years ago titled “Handling optional parameters in javascript“ and figured I’d write about my solution here.

I’ll start by saying that the easiest way to handle optional parameters in javascript is to use an “options” object that allows a function to be called with as many or as few parameters (arguments) as you wish.

function displayOverlay(options) {
  if (options.alert) { 
    alert(options.message); 
  }
}

However, if you need to use individual parameters, i’ve created a utility that acts as a proxy and lets you strongly type values.  It looks like this:

function displayOverlay(/*message, timeout, callback*/) {
  return proxy(arguments, String, Number, Function,
    function(message, timeout, callback) {
      /* ... your code ... */
    });
};

I call my proxy arrangeArgs(). Here’s a clearer explanation of what’s going on:

function displayOverlay(/*message, timeout, callback*/) {
  //arrangeArgs is the proxy
  return arrangeArgs(
           //first pass in the original arguments
           arguments,
           //then pass in the type for each argument
           String,  Number,  Function,
           //lastly, pass in your function and the proxy will do the rest!
           function(message, timeout, callback) {

             //debug output of each argument to verify it's working
             console.log("message", message, "timeout", timeout, "callback", callback);

             /* ... your code ... */

           }
         );
};

I created the arrangeArgs() proxy to handle optional parameters for you.  It works nicely.  The code is in my Sysmo.js utility library on GitHub. Let me know what you think!

Share

Blueprint

I’ve been working on Rembly, which uses Spine.js as the core piece that ties all the functionality together.  I decided to use Mustache.js for my HTML templates.  And finally, I chose ICanHaz.js as a simple and lightweight way of managing my HTML templates.

Although ICanHaz.js is a great start, managing my HTML templates became unwieldy because I started having little templates everywhere.  Each part of a page that is dynamically updated needs to be broken out into its own template.  When you’ve broken a web page into small parts, it’s hard to keep track of what it looks like when put back together.  It also becomes hard to create the correct CSS styles when you lose track of the HTML hierarchy.

This lead me to enhance ICanHaz.js with a ton of new features.  The primary one being nested templates, which allowed me to keep my full HTML page template in tact, while designating specific HTML tags as “sub templates” or partials. You can also specify additional templates to load and replace script “include” tags with the loaded HTML.

Check out my fork on Github for more information about how to use my enhanced version if ICanHaz.js. Make sure to look at the javascript comments for details. And let me know what you think.

Share

I’ve been working with Stratum Security for the past couple of months on ThreatSim (@ThreatSim), which we are happy to announce to the world today!  ThreatSim is a web-based phishing attack simulator to help companies assess how vulnerable their network and internal assets may be to phishing attacks.  Not only does ThreatSim track who is clicking on phishing emails, but we’re also making an exfiltration agent available, which simulates transmitting sensitive data from the local network out to the internet.

Check out the website at www.ThreatSim.com, follow us at @ThreatSim, and check out the conversation on Hacker News.

Share

I think I’m a fan of Google’s Instant Search.  Rather than having to hit “enter” or click the “search” button, the search results automatically refresh as I type.  It’s quirky sometimes, because I’ll see some search results that look accurate as I’v only typed in a couple letters, and if I’m typing too fast, it passes me by and it’s not always easy to back up to to those previous results.  So, for the most part, I like it.

Google just introduced Instant Preview, which displays a screenshot of each search result, while highlighting the relevant part of the page that qualified it as a search result.  Convenient for skimming, and could lead to some interesting hacks that websites implement to generate some catchy screenshots that may or may not look the same when you actually click the link.

Share

Is it silly that Microsoft spends so much time and money chasing the goal of preventing their hardware (and/or software) from being hacked?  If you build it, someone will hack it.  It’s pretty much a fact this day and age.  I think it’s time to embrace it.  As a matter of fact, wouldn’t this HELP push the product?  More people will buy it because you can do much more with it than with the limited functionality that is shipped with the product!

Via Network World.

Share

With all the controversy over voting fraud, it’s great to see that people are consistently trying hard to come up with way to help voting systems become more reliable and trustworthy.  David Bismark gave great (short) talk about a new kind of ballot that seems very logical and useful.  You can walk away with a “receipt” that lets you verify your vote was counted.

Via TED.com

Share

I came across a short clip of Steve Wozniak at Fast Company talking about how intelligent computers are getting and how much they can teach and influence from an early age these days.  But there are still strides to take in getting computers to fully interact with and understand humans and the aspects of our environment and lives that are interpreted through sensory perception and experience in life.

This clip is nothing mind-blowing and doesn’t talk about anything specific.  It just reflects on where the internet and computers have brought us and poses the question of how long will it be before computers can really interact with humans and fully understand its surroundings.

Share