#Development


Detect Operating System with JavaScript

Here’s a snip­pet of JS code that might come in handy if you, let’s say, would like to fil­ter out what type of con­tent to dis­play depend­ing on your web­site user’s OS. A real-life exam­ple would be hav­ing a down­load link show up to user’s who have a client that was only pub­lished on Windows.

// This script sets OSName variable as follows:
// "Windows"    for all versions of Windows
// "MacOS"      for all versions of Macintosh OS
// "Linux"      for all versions of Linux
// "UNIX"       for all other UNIX flavors
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

document.write('Your OS: '+OSName);

Note: An alter­nate way can be found via PPK’s quirksmode.org

MacBook/Pro — Disable Wake on Lid Open

It seems like the cur­rent Soft­ware Update nul­li­fied my tweak (YMMV). I think this might be help­ful as most of the results showed only how to “dis­able sleep when the lid is closed” vs. dis­abling wake on lid open.

Any­ways, to do so, do the fol­low­ing in your Ter­mi­nal (Appli­ca­tion > Util­i­ties > Terminal.app):

Check cur­rent state (i.e. “lidwake”):

$ pmset -g

Dis­able it:

$ sudo pmset -a lidwake 0

Or put it back to nor­mal (re-enable):

$ sudo pmset -a lidwake 1

Check the cur­rent state again to ver­ify (i.e. “pmset –g”). You shouldn’t have to restart. I hope that helps. Would’ve saved me a cou­ple of min­utes for sure.

So What’s New In May?

Hey, hey, hey. May 1st has come and gone and those who have promised them­selves to Reboot were either suc­cess­ful, or behind. One of the sites I’m curi­ously await­ing to check out is Bryan Veloso’s new ren­di­tion of Aval­on­Star.

So what the heck am I doing this early in the morn­ing? I can’t damn sleep, and have been try­ing to fig­ure out how to orga­nize my shiznit a bit bet­ter. I have too much stuff going on (as usual), and need to com­plete tasks I have set in my to-do list. But it seems that that list just keeps get­ting big­ger and wider (in terms of those URL-bookmarks).

Any­ways, just wanted to catch-up with this writing-thingy-majig. Maybe some­one out there can help orga­nize things with some cool advise and/or refer­ral gift =)

Speak­ing of which, here’s some cool things that have inter­ested me in the past cou­ple of days:

  • Mac­Book Pro — yeah, I’m a “switch-hitter” now
  • Text­Mate Basic Tuto­ri­als — this will prob­a­bly change my devel­op­ment work­flow for work and on-the-side
  • Com­pil­ing new “points of inspi­ra­tion” from the Reboot-ed sites, new and old
  • … and the list goes on—but it seems that I should be catch­ing some Zs now as I hear some people’s alarm clock going off; at least I think I’m hear­ing it

From my mind to yours, keep learning.