⌘ ⌥ ⎋

dotcom

Archive

RSS

Theme
  1. In Place Quick Sort (in JavaScript)

    Everyone loves quicksort. Everyone loves writing quicksort using new arrays for partitioning because it’s super easy. Just splice out your pivot, compare and push. In contrast the in-place version with keeping track of the pointers, incrementing, swapping things, can be lead to an almost-working sort and subsequent hours of debugging.

    There weren’t too many examples of quick sort written up in JavaScript, so here’s a quick and simple version for you all. Not much to say, n log n if all is good.

      // lb, rb - left bound, right bound
    function quickSortInPlace(unsorted, lb, rb) {
      if(typeof lb === 'undefined') { lb = 0; }
      if(typeof rb === 'undefined') { rb = unsorted.length-1; }
    
      if(lb < rb) {
        var pivot = unsorted[Math.floor((lb+rb)/2)];    // or use Math.random()
        var l = lb, r = rb;         // indicies that will be moving from either end
        var tmpSwap;
    
        while(l < r) {
          while(unsorted[l] < pivot) { l++; }
          while(pivot < unsorted[r]) { r--; }
          if(l <= r) {
            tmpSwap = unsorted[l];
            unsorted[l] = unsorted[r];
            unsorted[r] = tmpSwap;
            l++;
            r--;
          }
        }
    
        quickSortInPlace(unsorted, lb, r);
        quickSortInPlace(unsorted, l, rb);
      }
    }

    Check it out as a Gist.

  2. Easy guide to making your own [githubname].github.io page.

    GitHub is awesome. It’s so awesome that they even provide you with super basic web hosting for static pages, so you can re-up your old GeoCities site. However, their documentation isn’t that stellar, so I wrote up this quick little guide…

    1) Make a new repo on GitHub with the following name: [username].github.io

    image

    The name before github.io needs to be your exact GitHub handle. So if you’re xSk8oRDiEx on GitHub, it’ll be xsk8ordiex.github.io, sorry.

    2) Once the repo is created, go to the settings (last item in the menu on the right):

    image

    3) Click on the Automatic Page Generator (you can skip writing in content on the following page):

    image

    4) Select a template and click publish!

    image

    Great! Within 15 minutes, you should be able to visit yourname.github.io (or in my case, cmdoptesc.github.io). And to edit the site, clone down the repo and edit it like any other static site. If you want to run Node.js, you’ll have to look to paid hosting, or get a trial at Heroku, or Nodejitsu.

    Hope this helps!

     

    Follow-ups:

    • If you own a domain and would like to direct it to yourname.github.io, check out GitHub’s help page. In short, it’s a two-step process of (1) modifying information on your registrar (e.g. NameCheap or Gandi) like this:

      image

      And (2) adding a CNAME file to the root of the repo. CNAME should have no extensions, and should contain one simple line: yourdomain.com

    • Individual repos (aka projects) on your account can have their own pages, which will take the form of yourname.github.io/[repo name], or yourdomain.com/[repo name]. You can do this manually, or again with the automatic page generator. The basics here is creating a branch named gh-pages in the individual repo.
  3. Best practices for real-world computer security? I don’t think that was ever even a FOOTNOTE in any of my C.S. courses.

    element-o.p. via /.

    I took a senior-level computer security class while working on my C.S. degree in college, and it was largely a waste of time. We spent half the semester working our way through various historical encryption algorithms trying to get *to* asymmetrical encryption (you know, Caesar’s belt, various ROT-x ciphers, etc. — i.e., stuff that should have been covered in the first week, maybe). We spent most of the rest of the semester dissecting DSA and RSA, and maybe two weeks talking about covert channels. We spent next to no time talking about one-way hashes, and salts were a completely foreign concept to me when I discovered them two or three years later when I started using Linux. As far as best practices for real-world computer security? I don’t think that was ever even a FOOTNOTE in any of my C.S. courses. 

    Maybe I just went to a crappy school, but IMHO, my college education was woefully inadequate for the real world. Pretty much everything I use on a day-to-day basis was learned on my own, outside of college.

  4. Restify XMLHttpRequest cannot load localhost.. not allowed by Access-Control-Allow-Origin

    Having issues with cross-origin resource-sharing not working with Restify? Have you copied and pasted a dozen StackOverflow snippets, looked through the Restify newsgroup, and scoured the Git issue tracker without any avail? We did, and came up with a relatively painless fix in three easy steps:

    1. Go to your project folder in the command-line and type: npm install express
    2. Replace var restify = require('restify') and var server = restify.createServer() with var express = require('express') and var server = express()
    3. Delete any of the Restify header settings you tried, and replace them with this following block of code:
      var allowCrossDomain = function(req, res, next) {
        res.header('Access-Control-Allow-Origin', '*');
        res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
        res.header('Access-Control-Allow-Headers', 'X-Requested-With, Accept, Origin, Referer, User-Agent, Content-Type, Authorization');
      
        // intercept OPTIONS method
        if (req.method === 'OPTIONS') {
          res.send(200);
        }
        else {
          next();
        }
      };
      
      server.configure(function() {
          server.use(allowCrossDomain);     // make sure this is called before server.route
          server.use(server.router);
      });
      

    For our group project “Hatch" we needed to build a RESTful API server to support our mobile app. Since the server only needed to handle API calls and didn’t need to serve up any pages, Restify seemed like a good framework to experiment with. However, we ran into cross-origin issues when simulating our mobile app from a laptop. Given Restify’s sparse documentation, we burned 2-3 hours trying to solve the issue without any luck. Eventually, we decided to switch over to Express midway through development since this was going to hold up mobile development. Within 20 minutes of making that call, we got our server running on Express and resolved all our cross-origin restrictions.

    Mark Cavage has done an impressive job with Restify, but if you don’t require “absolute control over interactions with HTTP and full observability into the latency and characteristics” of your app, you’re probably better off with Express. Personally, considering how minimal Express is, I don’t see a need for a lighter-weight solution. If anything, I’d go in the opposite direction and check out ActionHero.

  5. What the smartest people do on the weekend is what everyone else will do during the week in ten years

    Chris Dixon:

    Many breakthrough technologies were hatched by hobbyists in garages and dorm rooms. Prominent examples include the PC, the web, blogs, and most open source software.

    The fact that flip-flop wearing hobbyists spawn large industries is commonly viewed as an amusing eccentricity of the technology industry. But there is a reason why hobbies are so important.

    Business people vote with their dollars, and are mostly trying to create near-term financial returns. Engineers vote with their time, and are mostly trying to invent interesting new things. Hobbies are what the smartest people spend their time on when they aren’t constrained by near-term financial goals.

    Today, the tech hobbies with momentum include: math-based currencies like Bitcoin, new software development tools like NoSQL databases, the internet of things, 3D printing, touch-free human/computer interfaces, and “artisanal” hardware like the kind you find on Kickstarter.

    It’s a good bet these present-day hobbies will seed future industries. What the smartest people do on the weekends is what everyone else will do during the week in ten years.

  6. Yishang Wong on performance reviews and career ladders

    The CEO of Reddit, Yishang Wong, has some great views on the performance review process that feel really pertinent given my company’s upcoming roundtable discussions:

    No one is interested in feedback (if they really wanted feedback, they could get it any time they wanted by asking their manager how they were doing), they just come under the belief that a performance review process will somehow magically uncover the fact that they are the true superstar.

    […]

    Instead, hundreds of management hours will be sunk into creating a “fair” and “consistent” performance review process, it will be executed, everyone will have to write some painful and awkward self-evaluations, everyone will have to write a bunch of painful and awkward peer evaluations, and then managers will (at best) discover what they already knew about everyone’s performance and – possibly this is the only good thing that comes out of the entire process – the people who suck will awkwardly get told that they suck. Typically this last thing does not even happen.

    […]

    As a bonus, you might have also acquired a “career ladder.” In technology startups, these things are a joke.  They come about because people in Class 2 and Class 3, after seeing their Class 1 peers get promoted and given raises, ask their managers, “What’s my career path here?”  This is a euphemism for “How do I get a raise and promotion too?”  (The Class 4 people, at least the ones who know they’re Class 4, are again just happy they haven’t been fired)

    […]

    In Silicon Valley, there is no career ladder within a single company. […] The “career ladder” concept is a holdover from the 1950s manufacturing era, where you might work at a company for 30 years and slowly work your way up, where you had a career at a single company. In the Valley, the median tenure for an employee at a startup is 4.5 years. That’s not a career.

    […]

    Your real “promotion” is what happens when you leave the company and are recognized as having become better (through working and improving your skills) than you were 4-5 years ago and are thus offered a better job at your next startup.

  7. All science is becoming data science.

    When the Wikileaks material came out, you’re not going to pour yourself a pot of coffee and pour over those materials, print them all out, and go through them one-by-one. You’re going to write algorithms that do this kind of [data] analysis; word-use analysis, look for e-mail chains and dialogues; these sort of computational methods in order to analyse that material. Journalism itself is a computational enterprise, it’s a data science problem, or it’s amenable to data science technique. As a data scientist, the world is your oyster.

    - Bill Howe, Intro to Data Science on Coursera

  8. Ben Pieratt, Blog: In Praise of Quitting Your Job

    Why do I hate this job so much? What is wrong with me that I’m so entitled? People the world over have jobs they don’t like, why am I unable to stick this out?

    I could wax on this for a while (and I did, but then deleted all the paragraphs), but I think it comes down to the fact that, for some people, work is personal. Personal in the same way that singing or playing the piano or painting is personal.

    As a creative person, you’ve been given the ability to build things from nothing by way of hard work over long periods of time. Creation is a deeply personal and rewarding activity, which means that your Work should also be deeply personal and rewarding. If it’s not, then something is amiss.

    Creation is entirely dependent on ownership.

    Ownership not as a percentage of equity, but as a measure of your ability to change things for the better. To build and grow and fail and learn. This is no small thing. Creativity is the manifestation of lateral thinking, and without tangible results, it becomes stunted. We have to see the fruits of our labors, good or bad, or there’s no motivation to proceed, nothing to learn from to inform the next decision.