ES6 Variable Swap Explained

The following ES6 code swaps the values of two variables:

var x = 1;
var y = 2;
[x, y] = [y, x];

It works by using a Destructuring assignment on the array [y, x]. Destructuring is used to extract values from an array or an object. You are able to do this for example:

var [month, year] = [5, 1990]

The example above creates two local variables called “month” and “year” with the respective values 5 and 1990. In the swap example we are omitting the “var” keyword and end up with two simple assignment calls (most ES6 transpilers end up creating the following code):

var x = 1;
var y = 2;
var temp = [x, y];
x = temp[1];
y = temp[0];

How to Get the MAC Address From a Local IP Address

Command

ping -c 1 192.168.1.1 > /dev/null && arp -a | grep 192.168.1.1

This returns something like this:

? (192.168.1.1) at 61:02:6a:40:34:A3 on en0 ifscope [ethernet]

How does this work?

The command pings the IP address once to make sure that your machine and the target machine communicated at least once. Because we don’t need the output of the ping command, we can simply pipe it into /dev/null. It then continues and loads all entries from ARP (Address Resolution Protocol) and “greps” the line which matches with the provided IP address.

Careful with IPv6!

ARP is IPv4 only. For IPv6 you need to use NDP (Neighbor Discovery Protocol). Simply replace “arp -a” with “ndp -a” above.

NVIDIA Web Driver Broken After OS X Update

NVIDIAs alternate drivers for OS X usually break after a minor system update. You can fix this most of the time by modifying the following file:

/System/Library/Extensions/NVDAStartup.kext/Contents/Info.plist

Change the NVDIARequiredOS to your current system version which can be found in the app System Information. The version number should look something like this:

14F1021

Write it into the file and save it (sudo access is needed).

Bildschirmfoto 2015-10-23 um 07.54.24 Kopie

You should now rebuild your kext cache:

sudo kextcache -system-prelinked-kernel
sudo kextcache -system-caches

Reboot. Select the NVIDIA web drivers in your system settings and reboot once more. Done.

Building a Hackintosh in 2015

So today I have installed OS X 10.10.4 on my computer that I did not buy from Apple, which essentially means that I have built myself a Hackintosh. Here is what I learnt during that process.

Update October 15: Updating to 10.10.5 was no problem at all through the Mac Appstore.

  1. Buy hardware that TonyMacx86 advises you to buy.
  2. Read the complete guide on how to install it on that page too.
  3. If you plan on installing multiple operating systems, get a separate hard drive for each. You are going to save yourself so much time.
  4. Unplug your card reader if you encounter any issues during the installation.
  5. At some time during the installation you will probably need bootflags. Here is what helped me install OS X with my GTX 960 G1 Gaming:
    nv_disable=1 GraphicsEnabler=No maxmem=4096
  6. If you have a GTX graphics card, see if you can install the Web Drivers provided by Nvidia.
  7. Do not screw around and select Mac Pro 6,1 in Multibeast. You will not get any benefits and your Nvidia Web Drivers will stop working. Use the nv_disable=1 bootflag if that has happened to you.

multibeast-customize

After quite some time and furiously purchasing another SSD since I couldn’t get OS X to install on my partitioned Windows SSD, here is what I achieved:

Screen Shot 2015-07-31 at 23.12.58

 

Complete list of working parts:

  • Intel Core i5 4690K (LGA 1150, 3.50GHz, Unlocked)
  • ASUS MAXIMUS VII RANGER (LGA 1150, Z97, ATX)
  • HyperX Fury Black (2x, 8GB, DDR3-1866, DIMM 240)
  • Gigabyte GTX 960 G1 Gaming (GM206, 2GB)
  • Corsair Builder Series CX600 V3 (600W)
  • TP-LINK TL-WDN4800, Wireless N Dualband (PCI-E x1, 450Mbit/s)
  • Cooler Master Silencio 550 Matt (Midi Tower, Black)
  • be quiet! Dark Rock 3 (16cm)
  • AOC u3477Pqu (34”, 300cd/m², 3440 x 1440 Pixel, Black)
  • Samsung 850 EVO Basic (250GB, 2.5″)
  • HyperX Fury (120GB, 2.5”)

Mongoose: Cannot read property ‘paths’ of undefined

When working with Mongoose, make sure you never ever name a property “type”, since it’s reserved for declaring datatypes on fields. Take a look at this:

permissions: {
  type: String,   // this will throw an error
  userGroups: [
    {
      group: { type: mongoose.Schema.Types.ObjectId, ref: 'UserGroups' },   // correct use of "type"
      permission: String
    }
  ]
}

This will throw an uncaught exception. I’m writing this post so I can save you 20 minutes of debugging. Here’s the correct approach:

permissions: {
  permissionType: String,   // correct usage
  userGroups: [
    {
      group: { type: mongoose.Schema.Types.ObjectId, ref: 'UserGroups' },
      permission: String 
    }
  ]
}