Monday, July 27, 2015

OSX Web Server Folders

Something that I always forget because I don't run a web server on my Mac very often is when I go to localhost I see something different than what I expect. localhost is located here:

/Library/WebServer/Documents

While if you are editing ~/Sites then you want:

http://localhost/~yourusername

Wednesday, July 22, 2015

iOS 8.4 iPad Air 2 rotational & wake delay issue work-arounds

There are two iPad Air 2 issues with iOS 8.4 that I personally find pretty annoying and apparently so do others as you can see from this discussion on the Apple message boards.

1. Screen rotation does not work
When running on the iPad, if I rotate the screen before unlocking then screen rotation does not work. The best work around is to disable Reduce Motion:

Settings | General | Accessibility | turn off Reduce Motion.

The screen will now rotate correctly. I really don't like Reduced Motion but not rotating is even worse. Unfortunately battery life suffers.

2. Long wake delay
The only current work-around for the wake delay is to use a Smart Cover/ Smart Case (magnetic wake). I don't use a smart cover so I hope Apple fixes this soon.


There is some additional information in the message on the Apple message boards.



Monday, July 20, 2015

Small Changes in Windows 10 not for the better

There are quite a few changes in Windows 10 and I have hardly uncovered half of them. Many are for the better and many are well less than idea which is cause the majority of the people a bit of a difficult time. I thought Microsoft would have learned from their mistakes before.

Here is the right click menu on the Recycle Bin.


Notice that the "Empty Recycle Bin" is the third item down, when in all previous versions of Windows (I'm not counting Windows 8 because I don't think many people count that as a version) it was the second item.

Many years back Microsoft tested a great idea to reorganize menu items based off use. And by great I mean it was a really bad idea. Research ended up finding that people tend to remember location more than reading the words. Think of it as muscle memory.

There are many other such subtle menu items that have changed location for no apparent reason other than a new feature. A few of them I'm find with, but if Microsoft hopes to get everyone on board with Windows 10, and I think they have a really good chance of success, they need to not change the user interface very much between iterations of Windows.

Wednesday, June 24, 2015

Disable Skype Auto Start

Skype starts automatically and it is pretty trivial how to disable it but you have to know how and that's the key which is why I'm writing this. It doesn't show up in the Registry under Software | Windows | CurrentVersion | RunOnce.

So here is how to disable it:

Launch Skype and login. This is the key step because if you don't login the options are different. Go to the Tools menu and choose Options, under General Settings you'll see the checkbox for start Skype when I start Windows. Uncheck that and you're good!

If you don't have a Skype account, then I think you're out of luck because I've used ProcessMonitor to monitor the registry access and haven't been able to find a manual way to disable this.

Monday, June 22, 2015

Enums in Bash

I find that I use a lot of bash scripts. Using cygwin on Windows, Mac and Linux they are cross platform (for the most part). One feature lacking in bash is enums, but you can simulate them. I ran across this StackOverflow post and there is a nice comment about enums in bash, but it isn't complete.

#!/bin/bash

STATES=(INITIAL DEFAULT_CS_SETUP CREATED_CS CHECKED_OUT_DIR MKELEMENT_FILE CREATED_BRANCH CHECKED_IN_DIR COMPLETE)
tam=${#STATES[@]}
for ((i=0; i < $tam; i++)); do
    name=${STATES[i]}
    declare -r ${name}=$i
done

echo get the INITIAL state
echo ${STATES[$INITIAL]}

echo get the next state from CREATED_CS
echo ${STATES[$CREATED_CS+1]}

echo list elements from CREATED_CS to the end
for ((i=$CREATED_CS; i < $tam; i++)); do
    echo ${STATES[$i]}
done

echo list elements from CREATED_CS to CREATED_BRANCH
for ((i=$CREATED_CS; i <= $CREATED_BRANCH; i++)); do
    echo ${STATES[$i]}
done

Often times I want to create an empty enum and add items to it. So here is my example of creating an enum type, OPTION_STATES, defining the enum values and adding an item to it and checking for it later.

#!/bin/bash

# Define enum type.
OPTION_STATES=(OPTION_ONE OPTION_TWO OPTION_THREE)

count=${#OPTION_STATES[@]}
for ((i=0; $i < $count; i++)); do
    name=${OPTION_STATES[$i]}
    declare -r ${name}=$i
    
    if [[ $DEBUG == true ]]; then
      echo $name $i
    fi
done

# Create instance of enum type, yes this is a hash table.
OPTIONS=()

# Put an element into the instance.
OPTIONS[$OPTION_ONE]=$OPTION_ONE

# Check if that element is in the instance.
if [[ ${OPTIONS[$OPTION_ONE]} == $OPTION_ONE ]]; then
  echo "woo hoo"
fi

Tuesday, June 16, 2015

Desk Ergonomics - Every Diagram on the internet is wrong!

I ran across the following image recently from the article here.


The image is courtesy of Ergotron but I never found it on their website or I would have provided a link other than that one. On a side note, I have tried to use an Ergotron, but it didn't work for me. I'm too tall for one, two it didn't stay clamped to the desk, three the springs were too weak for my monitor, four it bounced when I typed. For someone else it might work out though. I know other people that like them. I think they are shorter and use a smaller monitor.

Anyway, back to my point. I honestly can't stand diagrams like this that have been floating around as long as I've used a computer for the correct ergonomic positioning. There are so many things wrong with this from a movement and ergonomic perspective it isn't even funny. Anyway, I'm going to start writing about this in future articles, but I wanted to point out a couple major issues with this diagram for "ergonomic perfection".

1. The legs are parallel to the floor. Not good. You want your thighs slightly sloped toward the knee. Same goes for the elbow. However sloped forearms makes using a mouse difficult, but I have a solution for this that I will post about in the future. The correct angle for legs and arms is 120 degrees. This isn't always achievable but that is as close to neutral as one can get without standing with their arms at their side and palms facing their legs.

2. The height of the monitor is incorrect. Monitor placement is an extremely complicated subject. It depends on your size and the size of the monitor, and most importantly, where on the monitor you look the most. Like I said, it's complicated. Your eye muscles are very strong in holding your eye up so you can look down, but are much weaker when looking up, so you certainly don't want to be looking up too much. I will write a future post about monitor placement because this is so important.

Monday, June 15, 2015

Rasperry Pi - How can I fix broken sudo - sudo: parse error in /etc/sudoers near line 29?

I recently got a Rasperry Pi and I've googled for many little oddities so I figured I'd write them up here on this blog to save anyone else out there some time.

I decided to create a new account it administrative privileges. So I create a new account for myself and enable sudo for it.

sudo adduser chris

Then add a line to the /etc/sudoers like so.

sudo visudo

This will open the /etc/sudoers file in nano, add a line just like the one already there for the pi user.

chris ALL=(ALL) NOPASSWD: ALL

However, I spelled PASSWD correctly. And consequently get:

sudo: parse error in /etc/sudoers near line 29
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

Can't shutdown, can't edit /etc/sudoers. So I thought I was stuck. Looking online if you have Linux you can put the SD card in your card reader, and mount the file that is rasparian image and edit to your hearts content. On Mac you can sorta do it with Fuse-ext2. Here is the best set of directions for that http://pi.gbaman.info/?p=328. But, I decided to try something I hadn't seen before:

logout

Then I logged in with "root"! Now I could edit /etc/sudoers all I wanted.

Friday, June 12, 2015

Windows 10

I just installed the Windows 10 preview in a VM on my Mac. So far so good! I think this is going to be a pretty good release of Windows.


Thursday, June 11, 2015

iOS Privacy Settings

Here are a couple privacy settings that I like to make changes to and I'm documenting here so I can point friends and family to this post.

1. Settings, Privacy, scroll down to Advertising, turn "Limit Ad Tracking"

2. Settings, Privacy, Location Services, scroll down to System Services, Frequent Locations, turn it off.

Thursday, May 28, 2015

Unit Testing JavaScript

Recently I was working on some JavaScript that really needed unit tests. I was making a substantial change that could not introduce any regression bugs and is very difficult to black box test. After all, this JavaScript was live! After digging into it a bit, reading the JavaScript spec since I'm more familiar with other languages like C/C++, Java and C#, I came to the conclusion it was going to be difficult so set off on a journey to see how others did it so I could save myself some time reinventing the wheel. My Google search of "unit testing private methods javascript" resulted in coming across the blog post How to Unit Test Private Functions in JavaScript.

The solution provided by Philip Walton was pretty good, but has a couple caveats. First let me explain what his solution is so you don't have to go read his entire post before continuing. He concludes that there are two camps of testing private JavaScript methods:

1. Don't
2. Everything is public

Obviously that isn't so good so he came up with a new option:

3. Export the private methods so they are public but do it in such a way that a code stripper removes them before going live.

The code stripper option isn't much of a stretch because most JavaScript goes through a compression process anyway removing white space and comments. I like his option but for me it wasn't an option to be able to modify the code stripper. We use YUI Compressor and aren't going to modify it. We could add a preprocessor but that isn't an option at this point. Plus there is potential for bugs because the code that is live isn't the same as the code you are testing. Our stripper has been around for a long time so we have confidence in it. So I came up with a new option:

4. If a global variable has been introduced and the .js file is loaded from a specific URL then initialize the global variable with a closure class containing only the private methods you want to test. For example if the URL is contains "http://localhost" or "file://", then initialize the closure. Any URL could be added here, including an internal test URL. However I can see how publishing a private URL is undesirable no matter how difficult it is to read.

For example:

var myclass = function() {
    // Private
    function someInternalMethod(arguments) {
    }

    function anotherInternalMethod(arguments) {
    }

    function initialize() {
      if ((typeof __myclassTestHook__ !== 'undefined') &&
           (__myclassTestHook__ == null) &&
           ((window.location.href.indexOf('http://localhost') == 0) ||
           (window.location.href.indexOf('file://') == 0))
           ) {
           __myclassTestHook__ = {
            someInternalMethod: someInternalMethod,
            anotherInternalMethod: someInternalMethod,
         };
        }
    }

    // Public
    function publicMethod(arguments) {
    }

    function anotherPublicMethod(arguments) {
    }

    initialize();

    return {
        publicMethod: somePublicMethod,
        anotherPublicMethod, anotherPublicMethod
    };
}();

Now:

<script>
var __myclassTestHook__ = null;
</script>

<script type="text/javascript" src="testexample.js"></script>


then use it like this:

<script>

    var stuff = __myclassTestHook__.someInternalMethod();
</script>


Is this perfect? No, but it comes pretty close in my opinion. What are your thoughts? The biggest concern is introducing security vulnerabilities.

Monday, May 4, 2015

Mountain Unicycling

Mountain Unicycling is the best sport I have every done. By far the most energy expended for the amount of time spent ratio. Check out this video if you are at all interested and want a challenge!


Thursday, April 30, 2015

Homeland Security wants less Encryption

The full text of the speech given by the Remarks by Secretary of Homeland Security Jeh Johnson at the RSA Conference 2015 can be found here. I think it is very telling where Homeland Security is from this small except:

"Now, finally, I have an ask: for your indulgence and your understanding on the subject of encryption. 
The Department of Homeland Security has both the cybersecurity mission and a law enforcement/counterterrorism mission for the American people. We have feet in both camps. I therefore believe I have a good perspective on this issue. 
The current course we are on, toward deeper and deeper encryption in response to the demands of the marketplace, is one that presents real challenges for those in law enforcement and national security.
Let me be clear: I understand the importance of what encryption brings to privacy. But, imagine the problems if, well after the advent of the telephone, the warrant authority of the government to investigate crime had extended only to the U.S. mail.
Our inability to access encrypted information poses public safety challenges. 
In fact, encryption is making it harder for your government to find criminal activity, and potential terrorist activity. 
We in government know that a solution to this dilemma must take full account of the privacy rights and expectations of the American public, the state of the technology, and the cybersecurity of American businesses."
First of all, uh, no. Second, are you kidding? The government has mountains of information in the form of metadata that they need absolutly no warrant for. They want back doors which make the encryption pointless. Maybe it's time some smart Silicon Valley engineers work for them rather than just VPs and Execs getting cushy jobs. Just sayin'. If other industries can do it like Monsonto with the FDA why not us?