01 Apr 2015
Japanese text can be thought of a mixture of Chinese characters known as Kanji, and the two phonetic alphabets of Hiragana and Katakana. Japanese text has no white spaces between words and one Kanji character can stand in for a whole word. This makes it difficult calculate how to fairly change clients for Japanese to English translation work. In Japan, the loosely agreed procedure is to charge by the letter, but when charging for every single letter, there are some characters that must be removed before calculating the total per letter fee. Some examples are English letters, numbers, white spaces, carriage returns, periods and other symbols in both Japanese and English. Removing these characters changes the text below from 135 characters
to 72 characters.
A significant difference when the translation work is priced by letters.
So how exactly do you remove all the cruft for the calculation? You could combing through the text yourself and manually delete letters one by one but Ain't Nobody Got Time for That! So regex to the rescue. If the text is in Unicode the following regex will match any characters, including symbols, that are not Kanji, Katakana, or Hiragana.
Use it in a text editor that has a regex friendly find and replace, like TextMate and done.
14 Mar 2015
In Japan is customary for women to give men chocolates on Valentine's Day, and men to return the favour with white chocolate on March 14, White Day. It's easy enough to pop down to the store and buy a few boxes of chocolate, but it displays a certain lack of imagination. This year, all the women I will be giving chocolates to this year are Harry Potter fans and so I figured that some appropriately shaped chocolates would be in order. Luckily Anna Kaziunas France from the FabLab network has a great instructable on molding white chocolate skulls and I came across some great house crest models on (where else) Thingiverse that fit the bill.
The first step is to create and print the box and positive model that will be cast in food safe silicone. I downloaded the crest models and modified Anna's original OpenSCAD file to work with the models. I spent quite a bit of time modifying the program to be able to dynamically change the sizes of the box, the desired output size, and evenly distribute the maximum the number of crests in the box. Unfortunately, due the to properties of the original crest models, OpenSCAD was unable to render and produce a final stl file with the crests.
Instead, I imported the box model into Rhino from OpenScad, placed the crests models in the box, and generated the stl for printing.
The print came out well, but due to the reduced sizes of each crest some of the fine detail was lost, especially around the lettering. Less detailed models will not only print better, but produce silicone mold that is easier to use. Eventually, the box will need to be destroyed to remove the cured mold, so do not make the printed box so thick or strong that you can't easily tear it apart. A wall thickness of 1.3mm produced a mold maker with no significant leaks that was easy to tear apart.
I purchased 1kg of very easy to use food safe silicon from Amazon. This silicon reacts badly to water or pollutants on the print, environmental contaminants such as tobacco smoke, and will not set properly in low temperature environments. A temperature controlled room, a careful cleaning with alcohol, and a complete drying is recommended.
To calculate the required amount of silicon for the mold, subtract the volume of each crest from the the volume of the box. Next I measured out half the volume of both the A and B materials into 2 paper cups, poured them into a 3rd larger cup, and gently mixed them together. Care must be taken to make sure the two materials are throughly blended together while not introducing air bubbles into the final mixture. The silicon I used has a working time of about 30 minutes and I spent that time tapping the box from all sides and the bottom to remove air bubbles. The details of the design trapped a surprising amount of air and the final mold has a couple small bubbles that were trapped in the crevasses of the design. The temperature needs to be controlled as the silicon cures over the next 8 hours. I left the heat in the room and while it was cooler in the room than recommended, there where no problems. The next morning I was able to remove the cured silicon mold from the printed box by tearing apart the box with my hands and a needle-nose pliers.
On to the chocolate!
I next melted bars of white chocolate using a glass measuring cup and a water bath, being very careful not to get any water in the chocolate or drip water into the mold. It will save you time and trouble if you can get chocolate that doesn't require tempering. Unfortunately, my chocolate did. To temper the chocolate, I first heated the chocolate up to about 46 C monitoring the temperature is an IR thermometer. Next, while gently stirring I cooled it down to below 27 C. Again care must be taken to not introduce air bubbles into the chocolate while stirring especially as it thickens. Finally, I reheated the chocolate to about 32 C and gently poured it into the mold while tapping to help it spread evenly and minimise bubbles. The chocolate sets up quickly so a smooth but relatively fast pour is recommended, but be careful not to trap excessive air in the mold.
Due to the detailed faces of the crests, the chocolates stuck quite firmly in the mold but the thinness of the design made them very easy to break. It's not good for the chocolate, but I had to completely freeze the mold in order to successfully remove the chocolates. Even so, frozen chocolate is very brittle and I ended up breaking quite a few of the Gryffindor and Slytherin crests, probably due to the large variations in thicknesses from lettering to the underlying animal motifs. I susspect that a design with a more consistent thickness would be considerably easier to demold successfully. Fortunately, broken chocolates can be melted and reuse to try-try-again.
The final results came out better than I had expected, even if the lettering is not very distinct.
For the finishing touch, I laser cut some of my Valentine's Day gift boxes which are the perfect size for a set of four chocolates.
14 Feb 2015
Being empty handed on Valentine's Day is never a good idea, so with that in mind I whipped up a quick little gift box out of paper.
With a little work in Illustrator, quick job on the laser cutter, fold it up, attach ribbon and done. The best part is that by switching out the hearts for a message and changing the paper colour this design can be tweaked and reused again for other small gifts etc. Adding a custom sticker on the top lid to seal the box would be a nice professional touch too.
Download the original files on Thingiverse
13 Dec 2014
Recently an app I develop needed to keep the map center while zooming in/out to show all markers dropped on the map. It's not a particularly difficult thing to do, but it took a moments thought. The example is for Android, but it works the same way on iOS etc.
09 Dec 2014
I've been dying to try out the new time lapse photography on my 6+, but I haven't had a great way to attach the larger iPhone to a camera stand. I could order up one from Amazon or something, but this is something that just screams for 3d printing.
I whipped up a quick clamp design that would fit the large phone and subtracted a hex hole for the mounting nut. One printout, some hot glue, and a few rubber bands later I had a camera mount.
The first version is fine for my purposes but the tolerances on the slider should be tighter, the edges in the band groves should be rounded to prevent band wear, and the whole thing could be slimmed down a bit to use less materiel.
03 Dec 2014
Now that my Shapeoko has a nice t-slot aluminum bed, I needed some work holding clamps. The great thing about CNC machines and 3d printers is that you can often make parts to improve your machines with the machines themselves.
For any CNC work, it is a must to keep the workpiece held firmly while milling. There are many ways to do this with bolts, tape, metal clamps etc. The slots in the t-slot bed can be positioned inconviently for a particular piece and tape can come undone partway through milling not to mention the occasional tape residue left on the bed. Premade clamps are availaible or printable out of plastic, but I wanted to make at least part of something for the machine with the machine itself.
Inventables has created a cam tool specifically for use with the Shapeoko called Easel that's simple to use. Upload a SVG file, set up the materiel, arrange the parts layout, connect and mill. The CAM functionality of Easel is minimal, no tab support etc, but it works well for more simple jobs and has very easy to follow instructions. Files can be shared with links or published to Inventables.
Creating the cut file was a simple matter of taking a very nice existing clamp design from thingiverse, cleaning up the 2d data, and modifying the design and material settings to match the 9mm MDF I had at hand.
For some reason, Easel marked several areas in red that might be problematic, but after checking the tool paths and the design this was a false warning and I milled the pieces anyway. Milling the clamps (link) was a smooth and trouble-free process. The only quibble I had about Easel besides the lack of tab support was that the tool paths were not optimised very well and resulted in significant wasted movement. Some of that could possible be improved by altering the design, but still the milling took much longer than otherwise necessary.
After cutting, glue the halves together, clamp and let them dry. Next, drill a hole and cut off a short piece (roughly 18mm) of 20mm dowelling. When the glue has dried, add a bolt, washers, a wing nut, and an insertion nut for the t-slots and the clamps will be ready to go. Wooden clamps are great if you happen to make a mistake and run the tool through one, destroying the clamp but saving the end mill (hopefully).
29 Nov 2014
Paul Kaplan from Inventables made this great snowflake generator tool that outputs SVG. I figured this would be an easy project for newcomers to my weekly FabFriday events at Fablab Oita. It's quite easy if you are familiar with Illustrator (or similar vector tools), but if not then you may need a little help.
First go to Paul's great snowflake generator tool and design a snowflake. At this stage it's ok to have narrow points within reason but very small details may become lost. After you are satisfied with the design, download the SVG snowflake file
Next open the SVG in Illustrator or a similar vector image editing program. I'm still getting by with and old Japanese version of CS3 that amazingly still runs on Yosemite. The first step is to select the object and increase the line width. Some detail will end up getting lost, so only do this if you have narrow weak points in the design and increase the line width as little as possible and still maintain structural integrity. Next in the line window, round off the corners and edges. Select the snowflake again, and outline the object paths to fix the new thicker object outlines. Finally, select the snowflake and use the pathfinder merge tool to clean up all of the interior lines. From here, you can add a hole to hang the snowflake or cut out the design as is.
The whole process is quick, easy, and fun to watch. Adding a colourful ribbon and a little white makes a nice ornament.
26 Nov 2014
So, this summer I purchased and assembled a Shapeoko2 because CNC machines are really cool. From the perspective of a professional, the whole kit is full of compromises like the delrin wheels, the fake Dremel hand tool, and the Arduino controller. Most of these compromises are fine for an entry level desktop CNC that machine that is not in heavy use and used with only lighter materials. After my first project, it was pretty obvious that the worst compromise was the stock MDF bed (followed closely by the fake Dremel). The MDF bed may be cheap, easy, and relatively light but the two panels of the bed flexed under the slightest pressure and were nowhere near strong or stiff enough to provide a stable cutting platform. One post in the Shapeoko forums showed a particularly nice aluminium bed with extrusions (HFSQN4-15250-500) from Misumi that happened to be sized perfectly to fit the stock Shapeoko. Luckily, Misumi is a Japanese company and I quickly placed an order for the extrusions and corresponding nuts for the T-slots.
After installing the extrusions buckled upwards ever so slightly. To eliminate the buckling I made two brackets out of aluminium, tapped holes into the extrusions, and bolted them down to the existing t-slot crosspieces. It's not a permanent solution but for now it's amazing how much the extrusions stiffened up the whole machine and greatly increased the overall precision.
Next on the list, some nice work holding clamps to go with the T-slot extrusions.
15 Sep 2014
There are no settings available in a UITextField to make the placeholder font different (color, smaller, fontface etc) from the font or textColor. You would think that it would be possible with UITextField attributedPlaceholder, but you would be wrong. The way to get around this is to sublclass UITextField and override drawPlaceholderInRect. Occasionally, this will cause placeholder text to be pinned to the top of the UITextField, which can be fixed by vertically centering the draw rect.
27 Aug 2014
One project that I'm working on right now shares it's assets across several platforms and development teams. The client maintains all of the string data in Excel and generates several simple JSON files from a worksheet. These sheets are then used by other teams for building the web interfaces and by myself for making the iOS and Android apps. Using the raw JSON files on iOS is not a problem because I use a custom cache backed localized string manager and not the Interface Builder localisation tooling or the default NSLocalizedString macro.
In Android, string handling and localisation are highly integrated into the tools making custom solutions more difficult. Additionally, strings in Android projects are defined in a strings.xml file residing in the read-only res folder and thus are not writeable from within the app itself. The only way then to use the standard IDE etc and still use common set of JSON files for localised strings, is to generate a proper strings.xml file from the various JSON files as part of the build process. Since I am developing in Android Studio, this meant fiddling around with embedded build tool, Gradle. Being relatively unfamiliar with both Gradle and Groovy, the language used in the build.gradle file, it took me a bit of fiddling around but I was finally able to generate a proper strings.xml as part of the build.
The localised JSON string file is just a simple map of keys and strings similar to below:
The additions to build.gradle file are as follows:
In the new generateStrings task, the JSON file containing the localised string data is read in and a new xml MarkupBuilder is created to receive the new string data. Next we iterate over the JSON map and add the keys and values as string elements to the xml MarkupBuilder, writing the new strings.xml file when finished.
The trick to get this to be run on build, is to insert the new generateStrings task into the build process. This is done by adding the generateStrings task as a dependency to the preBuild task, ensuring that the strings.xml file is recreated before every build.
- The strings.xml file is recreated on every build and as such slows down the build process. There should be a way to only regenerate the strings file when the JSON has been altered
- It may be desirable to not overwrite the file, but read in the current xml file and only add in the changes from the JSON assets. Could lead to a bloated strings file though.