Tuesday, March 21, 2017

C++: Convert Unicode String to ANSI String

I've seen so many examples and questions of how to convert between unicode string and ANSI string using C++. So here is by far the easiest way to do this conversion that I've implemented:

template <typename Facet>
struct TFacet : Facet
    using Facet::Facet;

wstring stringtowstring(string value)
    std::wstring_convert<TFacet<std::codecvt<wchar_t, char, std::mbstate_t>>> conv;
    return conv.from_bytes(value);

string wstringtostring(wstring value)
    std::wstring_convert<TFacet<std::codecvt<wchar_t, char, std::mbstate_t>>> conv;
    return conv.to_bytes(value);


Wednesday, March 1, 2017

Adding a Private Key to macOS Keychain

On macOS, the native SSH client can use the built-in keychain directly which is awesome because you don't have to type in the password every time. To add your private key to the keychain simply use the command:

ssh-add -K /path/of/private/key

For example if your private key's filename is ~/.ssh/id_rsa, you would use the command:

ssh-add -K ~/.ssh/id_rsa

You will then be prompted to enter your password. From now on it's all automatic. Viola!

Update: There appears to be an issue in macOS Sierra where the password is only stored for the currently session. You can follow a thread here. I'll add more information as I run across it.

Monday, January 30, 2017

Make Bootable macOS Sierra USB Install Drive

1. Format drive with the defaults using Disk Utility and name it "Untitled".
2. Download macOS Installer App from Mac App Store (Note: If you use this installer it will not be usable again).
3. Open Terminal and run:

sudo /Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ macOS\ Sierra.app --nointeraction

4. Go do the computer you want to install Sierra on.
5. Plug in the USB drive.
6. Turn the machine on and hold down the Option (ALT) key until you get a list of drives.
7. Choose the installer, and follow the directions.


Friday, January 13, 2017

Blurred Faces in Final Cut Pro X

This is by far the best tutorial on blurred faces or censoring I've come across for Final Cut Pro X. The only thing I'd add is I suggest starting from the beginning, add the keyframe for the position and scale, then use the left and right arrow keys to jog and move the shape to the new position for each frame.

Monday, January 9, 2017

Spam Email Tips

Spammers like to validate that you read your email. They get a lot of satisfaction from this. Also they sell the data. Reading email isn't inherently bad like it was in the past, but there are still some pitfalls such as executing Javascript or loading remote images. Gmail strips Javascript so your'e good there. But they do load remote images by default. From Gmail help:

Choose to show or not show images

  1. Open Gmail.
  2. In the top right, click Settings Settings.
  3. Click Settings.
  4. Scroll down to the "Images" section.
  5. Select Always display external images or Ask before displaying external images. If you chose the "Ask before displaying external images" setting, messages that have images will have a "Display images below" option.
  6. At the bottom of the page, click Save Changes.

Thursday, December 15, 2016

Reduce Hard Drive Size When Running Windows 10 in a VM

If you are running Windows 10 in a VM chance are you could use every bit of hard drive space available. Get a few gigs back by disabling hibernation, which you probably aren't using if you're running in a VM. Here's a link to the Microsoft support article here but the directions are copied below just to make things easier.

  1. Click Start, and then type cmd in the Start Search box.
  2. In the search results list, right-click Command Prompt, and then click Run as Administrator.
  3. When you are prompted by User Account Control, click Continue.
  4. At the command prompt, type powercfg.exe /hibernate off, and then press Enter.
  5. Type exit, and then press Enter to close the Command Prompt window.

Tuesday, December 6, 2016

Bash Script Arugments

I write a lot of bash scripts. It's really out of laziness. Here is a script that allows parsing of specific arguments and passthrough of all other arguments. There are obviously many ways to do this but this is one of the ways that I've found to work best.

# Here is a boolean argument

# Here is an argument with a value

# Argument parsing.
for i in "$@"; do
  if [[ "$i" == ${ARG_NAME_1} ]]; then
  if [[ "$i" == ${ARG_NAME_2}* ]]; then
        ARG_VALUE_2 =${i:${#ARG_NAME_2}}

eval AppToLaunch $(IFS=$' '; echo "${ARGS[*]}")

Thursday, December 1, 2016

CAD for 3D Printing

I've been doing a lot of 3D printing with a Lulzbot Taz 5 lately and I've been working with lots of different CAD programs. I purchased ViaCAD and it's a pretty good program but it crashes once in a while and when it crashes, I loose the entire file, not just my work but the entire file! So I've been looking for an alternative. I run a Mac so I'd prefer to use something native to the platform rather than run a Windows VM. Here's a short list of the paid programs:

  • SolidWorks
  • Inventor
  • Rhino
  • Fusion360
  • Moment of Inspiration
  • SketchUp
  • Metasequoia
SolidWorks is by far the industry standard. If you pickup any product most likely it's been designed with SolidWorks. But it's expensive. Very expensive. Inventor is Auto Desk's version of solid works with about 20% of the market. It's good, but also expensive. Rhino is pretty darn good but they made a huge user interface change in the last few years making it terrible in my opinion. It isn't exactly inexpensive either. Fusion360 is a much less expensive cloud version of Inventor with less features and a monthly fee. Moment of Inspiration is $300. I actually rather like it but it is limited. On Mac it uses Wine which is less than ideal for a $300 piece of software in my opinion. SketchUp is both free and paid, but if you want to generate STL files you need the paid version. SketchUp is really good at architectural drawings but not good to non-geometric stuff. In order to get good prints from SketchUp you have to create your model really big and then scale it down. Even doing this you'll get funny odd jagged edges.

Now for the free stuff:
  • FreeCAD
  • LibreCAD
  • OpenSCAD
  • 123 Design
  • Antimony
  • TinkerCAD
Antimony has an interesting user interface. I'll keep my eye on it but it isn't usable. TinkerCAD is good for kids. LibreCAD and FreeCAD are powerful but extremely difficult to work with in my opinion. As it is I tend to build things in either 123 Design or OpenSCAD. I'll post more about 123 Design or OpenSCAD later.

Wednesday, November 30, 2016

Holloween 2016 - Harry Potter

In Halloween tradition we did another Halloween trick-or-treat garage. I did an mini Maker's Fair showing off the stuff that I build. I 3D Printed over 200 LED candles and suspended them over my driveway. I made a wand that actually did stuff although this video doesn't show it. I have a self stirring spoon, moving pictures, walls that look like stained glass, Dumbledoor's Chair and lots and lots of other small details. Leave a note in the comments if you have any questions or cool Harry Potter projects you want to share or just want to ask how I did something. If I get time I'll post some how to's but let me know if you're interested so I know what to focus on.

Tuesday, October 18, 2016

Review: Dell Ultra HD 4k Monitor P2715Q 27-Inch Screen LED-Lit Monitor

I've been looking for a second monitor for some time now. I currently run an Apple 30" Cinema Display, which is awesome by the way. Between the Missus and myself we have three of them. They are heavy however and not super energy efficient. The Dell P2715Q  came down to $450 on Amazon last December (10 months ago) so I picked one up. You can find other in depth reviews of the monitor around the web, here's one for example P2715q review, because I want to say some bad things about this monitor.

Overall the monitor isn't bad. It is light, it is considerably smaller than 30" monitor, the stand is OK and the monitor holds it's tilt angle better than some monitors. The controls are standard Dell controls. The resolution is amazing! 4K is really nice, if your computer can drive it. Make sure it can drive it because one of my older Mac Books is old and the interpolated resolution leaves a lot to be desired. The Display Port sucks. They have a bad display port chipset in it and it won't wake the Mac at times.

But now I have to get to my scathing review. It died after owning it for 10 months. Honestly, I hardly used it. I believe the power supply went belly up. It is under warranty so I called Dell. I won't bother going into details, but I can say based off my overall experience I suggest looking elsewhere for computer hardware. I will never buy another Dell monitor or computer again. I'm currently on the phone trying to figure out why they sent me an email saying they were going to call me over 2 hours ago and to wait around for that call for 2 hours. They have no idea. It's been over a week now since my initial call and they plan to send me a refurbished unit as a replacement but they have to verify my purchase. Apparently that will be a little while longer. On the plus side the person I spoke with today was very nice. Anyway, I said I wouldn't go into details but I think all that's worthwhile.

So, in summary, I like the monitor, looks great, functions good, it's a good monitor, but don't buy one because it will die and you'll send a week of your life trying to get a replacement.

Monday, August 22, 2016

iOS Looses Your Calendar

I've now seen three devices loose the entire Calendar. All events are gone, all calendars are gone. It doesn't make any sense. You can tell if this is the case by going to Settings | iCloud | Scroll down find find Default Calendar. If it isn't there then you have run into this problem. The only work around that I know of is you sign out of your iCloud account and sign back in. Remember all of your settings. Best to take a screen capture of all the screens so you can recreate what you had.

Tuesday, July 19, 2016

Create a Rounded Cube in OpenSCAD

There are two ways to easily make a rounded cube. The first is to use the hull function:

module RoundedCube(size, radius) {
    width = size[0];
    height = size[1];
    depth = size[2];
    hull() {
        translate([radius, radius, 0]) cylinder(r = radius, h = depth);
        translate([width - radius, radius, 0]) cylinder(r = radius, h = depth);
        translate([radius, height - radius, 0]) cylinder(r = radius, h = depth);
        translate([width - radius, height - radius, 0]) cylinder(r = radius, h = depth);

The second is to use linear_extrude and the offset functions:

module RoundedCube(size, radius) {
    width = size[0];
    height = size[1];
    depth = size[2];

    translate([radius, radius, 0]) linear_extrude(height = depth) offset(r = radius) square([width, height]);

Now they aren't exactly identical. They will produce slightly different rounded cubes, but hopefully this helps someone out there use OpenSCAD.