Scott Hanselman

Announcing: Running Ruby on Rails on IIS8 (or anything else, really) with the new HttpPlatformHandler

February 9, '15 Comments [20] Posted in IIS | Ruby
Sponsored By

For years there's been numerous hacks and ways to get Ruby on Rails to run on IIS. There's also ways to get Java via Tomcat or Jetty, Go, and other languages and environments to run as well. There's ways to get Node.JS running on IIS using iisnode but that's been node-specific. The blog posts you do find say things like "get Rails to run on IIS in 10 steps" and I'm like JUST TEN?!? Why not 13? Others say "You can deploy Rails under IIS, it's just very difficult and there's not a lot of documentation. You'll need a special Fast-CGI implementation...WELCOME TO HELL."

No longer.

Azure Websites has supported node AND Java (again, Tomcat or Jetty) for a while now, in production and it's very nice and it runs under IIS. How? They've now brought that support to Windows running IIS 8+ with the release of the HttpPlatformHandler. Here's their example on how to get IIS 8+ running Java, easily.

Let's see if this works well with Ruby on Rails as well!

Why is HttpPlatformHandler interesting? Check this from the docs...it means IIS can host anything that runs on Windows now, easily. These things were possible before, but with all kinds of hacks and FastCGI this and that. What's great about HttpPlatformHandler is that it isn't about Rails. It's about any process that's listening on a port. You get all the value of IIS *and* total control of your self-hosting scenario.

The HttpPlatformHandler is an IIS Module, for IIS 8+, which does the following two things:

  1. Process management of http listeners - this could be any process that can listen on a port for http requests.  For example - Tomcat, Jetty, Node.exe, Ruby etc;
  2. Proxy requests to the process that it manages.

To be clear, you can work with Ruby on Rails on Windows and have it host itself with WEBrick locally, but if you're going to go production on Windows you'll want to have IIS and more likely, jRuby in a Tomcat container, similar to using Nginx on linux. What value does IIS provide in a scenario like this? Static file hosting, Reverse Proxy, complex auth that can span multiple apps, languages and frameworks, it monitors and manages your process looking at memory and CPU, crashes, etc.

Running Ruby on Rails on IIS 8 with the HttpPlatformHandler

First make sure you have Ruby on Rails. If you do, skip forward.

I use the http://railsinstaller.org for Windows and go. You'll get Ruby, Rails, Bundler, Sqlite, and TinyTDS. Even SQL Server support. Very kind of them. Another good Rails on Windows on is RailsFTW.

I go to Turn Windows Features On and Off to make sure I have IIS installed as well.

Turn on IIS in Windows Features

Then get the HttpPlatformHandler. You can get it with the Web Platform Installer, or just install it from here: x86/x64

I make a folder for the app I'm going to make. I put it in c:\inetpub\wwwroot\rails but you can move it around if you like.

Make sure your Rails app is an application in IIS

I right-click my folder in IIS Manager and "Convert to Application."

My Rails application in IIS

I run "gem install rails" to make sure I have Rails in the first place. ;) You will if you installed with the RailsInstaller. If you installed with the RubyInstaller, then this will get you Rails.

NOTE: If you have issues with SSL running gem on Windows, you'll need manually to update gem to 2.2.3 as of the time of this writing. I'm not sure why this isn't already done by the installer. The symptom I saw was weird errors on 'bundle install' that was fixed by this.

Installing Rails

Then, from inside c:\inetpub\wwwroot\rails, I ran "rails new helloworld." I ended up moving this folder up. I should have just made the app first, then converted the folder to an app in IIS. Order of operations and all that, eh?

OK, now I'll "rails server" from within c:\inetpub\wwwroot\rails, just to make sure Rails can run under the local WEBrick server. And it does:

Rails on Windows

Now, let's do it under IIS.

I need to make sure there's a web.config file in the same root folder as my Rails app. WHAT?!? Web.config is for ASP.NET, right? Well, no. It's config for any IIS application. You'll need this for Go, Java, PHP, Rails, node, ASP.NET, whatever. IIS can host basically anything.

Lemme add a hello world controller and edit its view. I'll "rails generate controller welcome index" then edit app\views\welcome\index.html.erb for good measure.

I put my Rails app under http://localhost/rails rather than at the root http://localhost so I did need to tell Rails 4 about the fact it's running in a subdirectory with a change to /config.ru, otherwise my routes wouldn't line up.

Rails.application.config.relative_url_root = '/rails'

map Rails.application.config.relative_url_root || "/" do
  run Rails.application
end

Make special note of the paths below AND the encoded " there in the arguments. That's important, because it's a quoted argument passed into the ruby.exe process that IIS will kick off. Note also the %HTTP_PLATFORM_PORT% environment variable reference. That is passed in by IIS and will be a localhost-bound high port.

I also put in foo and bar for theoretical environment variables you might want your Rails app to know about. For example, I might add:

<environmentVariable name="RAILS_ENV" value="production"/>

...when it's time. I put in some standard debug logging there with the "stdout" but you can remove that if you don't want the clutter. Make sure your IISR_ users have write access to the folders if you want to see any logs.

WARNING/DISCLAIMER: This first example is just showing you what's possible. You DON'T want to go to production with the little built-in Ruby WEBrick web server. As Fabio Akita very kindly points out in the comments, and I'll pull his comment out here:

"One thing to be careful with the example using Rails. When running Ruby for Windows, when you run "rails server" it's going to spawn a single process that's mono-threaded, meaning that it can only respond to 1 request at a time. If IIS starts receiving too many requests simultaneously and each request is slow, it's going to generate a long queue until they start timing out.
In Linux we put NGINX to reverse-proxy HTTP requests to Unicorn, or Puma, or Rainbows, or Passenger. They all coordinate multiple Ruby processes (which in Unix, is very cheap as each process reuses memory from it's parent process upon forking - copy-on-write memory). So we can handle simultaneous requests."

You'd want to use JRuby and Tomcat with Puma under IIS for production on Windows.

KEEP SCROLLING FOR EXAMPLES USING JRuby, Trinidad/Tomcat, and Puma! They are farther down the page.

Also, on slower machines when running in development, you might need to up your startupTimeLimit if you are seeing IIS stop your Ruby processes that take to long to startup.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform stdoutLogEnabled="true" stdoutLogFile="rails.log" startupTimeLimit="20" processPath="c:\RailsInstaller\Ruby2.1.0\bin\ruby.exe"
arguments="&quot;C:\RailsInstaller\Ruby2.1.0\bin\rails&quot; server -p %HTTP_PLATFORM_PORT% -b 127.0.0.1">
<environmentVariables>
<environmentVariable name="foo" value="bar"/>
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>

Here's a screenshot of Ruby within the SysInternals Process Explorer application. I wanted to show you this so you could see the Process Tree and see who started which process. You can see w3wp (that's IIS) which is a Service, and it's hosting Ruby, running Rails. Make note of the command line arguments as well.

image

And here it is. Ruby on Rails 4 running under IIS8 on my Windows 8 machine.

Ruby on Rails on IIS on Windows

Big thanks to Ranjith Ramachandra (@ranjithtweets) and Andrew Westgarth (@apwestgarth) at Microsoft for the help with the web.config values!

TL;DR

So, basically, to give you the TL;DR version, except at the end. When you have IIS, install HttpPlatformHandler and add a web.config as appropriate and you're all set. Run what you like, passing in the port that IIS will proxy to.

UPDATE: Puma and Trinidad (with Tomcat) on IIS

As pointed out in the comments, it's silly to use WEBrick in Production. Don't'.

I'm told JRuby is the way to go for prod. I was able to install JRuby and both Trinidad (with Tomcat) and Puma and get my HelloWorld running under IIS in an hour.

Here's Trinidad (I'm told Trinidad is out of vogue, however). I did a "JRuby -S gem install trinidad" and was on my way.

Note the JAVA_HOME environment variable setting. I also had to update some security policy files due to a "Illegal key size" error which was a Javaism. Otherwise, it just worked once the paths lined up. If you see problem, it'll be path related or you'll be loading the wrong Java version. Also, experiment but you don't really need to mess with processesPerApplications. If you create a lot of individual processes, Java can take up a lot of memory (300megs or so) per process and you can thrash your system.y

You'll get 10x the perf when running under production, so note I'm explicitly running in the prod environment.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform stdoutLogEnabled="false" processesPerApplication="1" stdoutLogFile="rails.log" startupTimeLimit="20" processPath="C:\jruby-1.7.19\bin\jruby.exe"
arguments="-S trinidad --context /jRubyonRails --env production --dir C:\inetpub\wwwroot\jRubyonRails -p %HTTP_PLATFORM_PORT% ">
<environmentVariables>
<environmentVariable name="JAVA_HOME" value="C:\Program Files\Java\jre1.8.0_31"/>
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>

And it works. I was easily able to get 1600+ req/sec on my laptop with minimal effort. I'm sure I could do better with some tuning and a better machine.

JRuby on Rails using Trinidad behind IIS8 with the HttpPlatformHandler

OK, let's swap out Trindad/Tomcat for Puma. I put Puma in the Gemfile and did "bundle exec puma" to test. That worked. Now I need to hook it into IIS. I also had to add gem 'jruby-openssl', :require => false to  my Gemfile to avoid some weird errors.

Basically it was the same thing, as IIS is the reverse proxy and process manager in this case.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform stdoutLogEnabled="false" processesPerApplication="1" stdoutLogFile="rails.log" startupTimeLimit="20" processPath="C:\jruby-1.7.19\bin\jruby.exe"
arguments="-S puma --env production --dir C:\inetpub\wwwroot\jRubyonRails -p %HTTP_PLATFORM_PORT% ">
<environmentVariables>
<environmentVariable name="JAVA_HOME" value="C:\Program Files\Java\jre1.8.0_31"/>
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>

I'm using just 1 processPerApplication and I'm getting 1500 req/s easily. I don't know anything about Puma or JRuby but I assume it can do better if I knew how to tune it.

Load testing JRuby on Windows under IIS

I tested without IIS against Puma itself and saw essentially the same results. IIS has minimal overhead that I can't measure in this case and you get its process management and other benefits. If you're having issues with perf doing this kind of stuff, it's unlikely it will be IIS.

JRuby on Rails using Puma with the HttpPlatformHandler

All in all, the HttpPlatformHandler just maybe the reverse proxy you've always wanted for Windows!

Related Links


Sponsor: Big thanks to Infragistics for sponsoring the feed this week! Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls.  Get super-charged performance with the world’s fastest HTML5 Grid – Download for free now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

3D Printer Shootout - $600 Printrbot vs. $20,000 uPrint SE Plus

February 6, '15 Comments [34] Posted in 3D Printing
Sponsored By

First, let's level set with a disclaimer. I am a smart enough person but a total beginner at 3D printing. I've been 3D printing for about two weeks using a Printrbot Simple Metal from Amazon that I got for US$599. Other than Amazon affiliate links (buy from my links and you buy me tacos!) I don't have ANY relationship with Printrbot or anyone in the 3D Printing space. I'm unaffiliated. This "shootout" is an interesting experience. I'm sure I did something wrong, or perhaps my partner in crime on this experiment, Brandon Potter, missed a step. Who knows? But this is how it went down.

Brandon saw that I was doing some 3D printing and mentioned they had a <$22,000 3D printer at his work and what did I think about doing a comparison? I had been having trouble printing with success, ruining at least 2 out of 3 prints, but recently got my Printrbot dialed in nicely. '

Here's my investment so far both in time and money.

So I'm into it for $722 and my time. I did NOT use a Heated Bed for my Printrbot Simple Metal but I am told it's a great upgrade.

Here's Brandon's company's outlay in his words:

  • uPrint SE Pro Printer and Dissolving Bath – about $22,000
  • 1 Spool of Model Material (Black) – $205.00 (produces 42 cubic inches of printing)
  • 1 Spool of Support Material – $200.00 (42 cubic inches worth)
  • Box of Build Plates – $125.00 for 24 (you need one for each print, so it costs about $5.20/each)
  • Soluble Concentrate – $149.00 for 12 bottles (dissolves support material, aka fancy drain-O)
  • Warranty Support – $2,000/year – because it does break from time to time.
  • Brandon says - Add a little bit of shipping, and for a mere $25K you’re ready to print your very own coffee cup.

We decided to print a coffee cup. I don't plan on drinking from it because who knows if the plastic will leech off, but it seemed like an interesting and common object. As a 3D model it has some nice curves, the handle overhang is a small challenge and it's something we can easily compare.

I printed one on my Printrbot and Brandon printed one on their Stratasys uPrint SE Pro. Then Brandon mailed me his cup and I'm sitting here holding them both in my hands.

Here is a timelapse video of my cup printing. My 0.2mm print took about 7 hours and this video is 90 seconds. I used Octoprint and the Raspberry Pi to create the video.

I downloaded the Coffee Cup model from Thingiverse as an STL 3D model. I ran the STL model through the Microsoft 3D Printing NetFabb online service to make sure the model was watertight. Then I loaded the result directly into Repetier and used Cura to slice the model into individual instructions for the printer. I made one adjustment to the slicing settings, telling it to make a "support structure" when it sees an overhang over 30 degrees. I was concerned about the cup's handle. Other than that one settings change which resulted in the support being added (which is easily pulled off after the print) it was a "printing as is." Brandon's model also used a support structure to print the cup and keep the handle stable so we decided this was pretty typical. He also printed on his pro printer with no changes.

My 3D model with support

Here is a picture of my setup. There's my printer on the right with some stuff I've made and my box of tools/crap on the left. You can see the spool, the printer (the red lipstick looking thing is where the hot plastic comes out), the Raspberry Pi and the tape that I print on. I can print objects up to 6 inches on a side, so a big 6 inch cube. If I paid more money I could get the 10 inch model, but so far for my hobbies I'm happy with that size. I can break things up and assemble them with acetone or bolts if I want to make larger models. One fellow 3D-printed a whole full-sized motorcycle with a small printer and assembled the parts.

My 3D Printing setup with Octoprint and a Printrbot Simple Metal

Here is Brandon's printer. Again, $600 vs. $25000.

Stratasys

By the way, is this a silly comparison? Perhaps. But no more than a Tesla vs. a Challenger Hellcat. Actually, I think my printer is a Geo Metro. But I get great mileage!

Ok, here's the prints. Feel free to click to zoom in to make your decision. Which cup came from which printer?

Coffee Cup 3D Print from a Printrbot Simple Metal on one side and a Stratasys uPrint SE Pro on the otherCoffee Cup 3D Print from a Printrbot Simple Metal on one side and a Stratasys uPrint SE Pro on the other

Coffee Cup 3D Print from a Printrbot Simple Metal on one side and a Stratasys uPrint SE Pro on the otherCoffee Cup 3D Print from a Printrbot Simple Metal on one side and a Stratasys uPrint SE Pro on the other

Here's slightly larger pics. Note I am not/have not moved the cups side to side. Left/right is consistent for this photo series.

Coffee Cup 3D Print from a Printrbot Simple Metal on one side and a Stratasys uPrint SE Pro on the other

Coffee Cup 3D Print from a Printrbot Simple Metal on one side and a Stratasys uPrint SE Pro on the other

Which is which?

The $599 Printrbot Simple Model printing at 0.2mm is on the left. The $20k uPrint SE Plus printing at 0.1mm is on the right.

The uPrint's base was messed up somehow. A bad start perhaps, but unfortunate as it's supposed to just work since Brandon used the one-time-use custom bases that the uPrint comes with. He also used the dissolving bath to take the white support structure off. You can see some of the white still there, perhaps it wasn't in long enough. My print had supports but I just pulled them off with my hands. Of course, if you have an intricate print with small parts that's not always possible. This is a very simple object, to be clear. It's not interlocking gears or something.

Here's the uPrint cup. Brandon said it took 8 hours and 22 minutes.

Coffee Cup 3D Print from a Stratasys uPrint SE Pro

Here's the Printrbot's cup. Note the "Z scar" (an artifact from the printer moving up the Z-Axis) on the print? On my print it ended up by the handle, but on Brandon's it ended up on the side of the cup, marring the print, in my opinion.

Coffee Cup 3D Print from a Printrbot Simple Metal

What's the takeaway? If we assume that I have a totally dialed-in well calibrated super cheap consumer/hobbyist 3D Printer and that Brandon has a $20k professional 3D Printer that's maybe got some calibration issues, they seem very comparable.

However, in real one-time costs my cup cost me 21.02 meters of filament, costing me perhaps $2 maybe a little more if you count the few pieces of tape. For Brandon and his Pro printer, in direct costs, he used $23.62 in model material, $2.06 in support material, and $5.20 build plate, for a total of $30.88 for this cup.

Naysayers will say that this isn't a great model to have chosen. Clearly my little Printrbot Simple Metal can only make things of a certain size, but it's clearly fair to say that it's a surprisingly competent printer when it's calibrated well. Additionally, if I were a 3D modeling shop with a Pro printer, I think I would definitely pick up a few sub-$1000 printers for basic stuff as the big printers may be costing you money. If I was a small business I would really do my homework before buying a pro printer that claims to be problem- and maintenance-free. Go read Brandon Potter's account of his "pro print" and compare notes!

NOTE: This post is intended in no way to talk up Printrbot nor to talk down Stratasys. It's a simple one time anecdote as it happened, using a simple model.

What do you think, Dear Reader?


Sponsor: Big thanks to Infragistics for sponsoring the feed this week! Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls.  Get super-charged performance with the world’s fastest HTML5 Grid – Download for free now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

The .NET CoreCLR is now open source, so I ran the GitHub repo through Microsoft Power BI

February 4, '15 Comments [34] Posted in Azure | Learning .NET | Open Source
Sponsored By

The hits keep on coming, Dear Reader. Just as we announced a few months back, .NET Core is open source. We said it would run on Windows, Mac, and Linux, but then the work of doing it has to actually happen. ;)

Go check out the .NET Framework Blog. Today the .NET team put the Core CLR up on GitHub. It's open source and it's under the MIT License. This includes the Core CLR source, the new RyuJIT, the .NET GC, native interop and everything you need to fork, clone, and build your own personal copy of the .NET Core CLR. What a cool day, and what an immense amount of work (both technical and legal) to make it happen. Years in the making, but still lots of work to do.

The GitHub repo has 2.6ish MILLION lines of code. They say when it's all said and done.NET Core will be about 5 MILLION lines of open source code.

The .NET Blog did a nice pie chart, but honestly, I found it to be not enough. It basically was a big grey circle that said "other 2.2M." ;)

I'd like a little more insight, but I don't know if I have the compute power, or the patience, frankly, to analyze this code repository. Or do I?

I decided to import the repository into Microsoft Power BI preview. Power BI (BI means "Business Intelligence") is an amazing service that you can use (usually for FREE, depending on your data source) to pull in huge amounts of data and ask questions of that data. Watch for a great video on this at http://friday.azure.com this week or next.

I logged into http://powerbi.com (It's US only for the preview, sorry) and clicked Get Data. I then selected GitHub as the source of my data and authorized Power BI to talk to GitHub on my behalf. Crazy, AMIRITE?

Screenshot (10)

After a few minutes of data chewing, I'm officially adding "BI and Big Data Analyst" to my resume and you can't stop me. ;)

What does Power BI tell me about the .NET Team's "CoreCLR" GitHub repository?

Here's what Power BI told me.

image

Let's dig in. Looks like Stephen Toub has worked on a LOT of this code. He's super brilliant and very nice, BTW.

image

Editing the query and looking at Dates and Times, it seems the .NET Team commits code at ALL hours. They are really feeling "committable" around 3 to 4 pm, but they'll even put code in at 4 in the morning!

image

Here's a more intense way to look at it.

image

One of the insanely cool things about Power BI is the ability to ask your data questions in plain English. Given that my SQL abilities have atrophied to "Select * from LittleBobbyTables" this is particularly useful to me.

I asked it "issues that are open sorted by date" and you'll notice that not only did it work, but it showed me what I meant underneath my query.

image

What about issues closed by a certain person?

image

I'm running around in this tool just building charts and asking questions of the repo. It's all in HTML5 but it's just like Excel. It's amazing.

image

Open issues from last year?

image

Average time to close an issue in hours?

image

It's amazing to be running queries like this on something as significant as the now open-sourced .NET Core CLR. I didn't need to be an employee to do it. I didn't need special access, I just did it. I'm enjoying this new Microsoft, and very much digging Power BI. Next I'm going to put my Blood Sugar and Diabetes Data in Power PI and encourage others to do the same.

P.S. Check out the code for the Core CLR Hello World app. When was the last time you saw an ASCII Art Linux Penguin in Microsoft Source code? ;)


Sponsor: Big thanks to Infragistics for sponsoring the feed this week! Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls.  Get super-charged performance with the world’s fastest HTML5 Grid – Download for free now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

The new Raspberry Pi 2 will run Windows 10 and run Universal Apps

February 2, '15 Comments [42] Posted in Win10
Sponsored By

I'm a huge Raspberry Pi fan. I've got three around the house, I use one for a Media Center, one for 3D Printing, and one for messing about. Now I'm gonna get a BUNCH more as the Raspberry Pi 2 has been announced and for a $35 computer that fits in your pocket this new version has some amazing things going for it.

  • Still tiny! Same size as a Raspberry Pi B+. My cases will still work. ;)
  • HDMI full sized! Ethernet! Camera port!
  • Still uses Micro USB for power!
  • BUT now it has...
    • A 900 MHz quad-core ARM Broadcom Cortex A7 with a BCM2836 system on a chip adds up to 3x to 6x the performance. Woof.
    • 1 GIG of RAM (shared with GPU)

Raspberry Pi 2I love using my Raspberry Pi as a "Dedicated Device." While it's clearly a general purpose computer, it's so cheap and powerful I'll use it for one thing and have it do that one thing well. Watch for water in my basement and text me if a sensor gets wet. A tiny Minecraft machine for my kids. A 3D Printing Print Server. A small games emulator. An open source media player.

And now it seems I'll be able to hack on a Raspberry Pi 2 running Windows 10 while I deploy a Universal Windows App!

Windows 10 is coming to the Raspberry Pi 2

Not only did the Raspberry Pi Foundation announce the Raspberry Pi 2, but it seems that Windows 10 will support Raspberry Pi 2 and we can get it free for the Maker community through the Windows Developer Program for IoT coming later this year. Last year Microsoft announced the Windows Developer Program for IoT and put Windows on the Intel Galileo board. Today Windows gets even better for IoT and Maker scenarios by supporting makers on RPi2.

This means you could theoretically have a Surface Pro 3 running a Universal App. Then a Windows Phone also running that same Universal App. And finally a Raspberry Pi 2 (note there's no shell) also running a Universal App. I could make my little Raspberry Pi 2 a dedicated device that runs Windows 10 plus my App. I can write code for it using the same languages, tools and techniques that I already know.

It's pretty clear that the way to go with Windows 10 from a developer's perspective is Universal Apps. You get a great development experience, good API coverage, tooling that makes cross-compilation easy, and now you can go from Raspberry Pi 2, to Phones, Tablets, Xboxen, the cloud and beyond. I'm pretty geeked.


Sponsor: Big thanks to Infragistics for sponsoring the feed this week! Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls.  Get super-charged performance with the world’s fastest HTML5 Grid – Download for free now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Creating exact 3D Models for 3D Printing with JavaScript and OpenJSCAD

February 1, '15 Comments [18] Posted in 3D Printing | Musings
Sponsored By

I have this 3D Printed Spool Holder on the top of my Printrbot Simple Metal 3D Printerl that looks like this:

Printrbot Simple Metal

It works great and fits my RioRand generic PLA Filament spool exactly. However, I went down to Fry's Electronics to get some filament today and all they had was small Makerbot spools. They were cheap, so I got two. When I got home I noticed that the hole in the spool is HUGE. It totally won't fit my spool holder.

This brings us to..

The Three Rules of 3D Printing

  1. All problems in 3D Printing can be solved by 3D Printing something
  2. The only things that 3D Printing people print is stuff to make their 3D printers work better.
  3. See rules 1 and 2.

So, I needed an adapter for my 3D Printer (which I have nearly a week of experience with, so fear me) and opened up Tinkercad.com to create it. Someone recommended Tinkercad as a great HTML5 website for doing quick designs.

image

I got lost in this app. I couldn't find a way to make two cylinders and simply center them within each other. You can nudge them around but can't center them against their own centers. I actually found forum posts going back to 2012 with members of the team saying "yes, we need that feature" but couldn't figure it out. It's a lovely app and my kids enjoy it but I feel like if you want absolute precision this may not be the place. Then I realized that perhaps this 3D Model was more of a math problem than a modeling problem.

Now I realize I'm biased, and I am a programmer, but with a small set of digital calipers and the excellent OpenJSCAD documentation I was able to create my adapter in just 10 minutes of hacking and just 7 to 12 lines of JavaScript (depending on how you count).

function main() {
return union(
difference(
cylinder({h: 40, r:26, center:true}),
cylinder({h: 40, r:15.5, center:true})
),
difference(
cylinder({start: [0,0,0], end: [0,0,24], r1: 52.5, r2: 26, fn: 50}).translate([0,0,-44]),
cylinder({start: [0,0,0], end: [0,0,24], r1: 32.5, r2: 15.5, fn: 50}).translate([0,0,-44])
)
).translate([0,0,45]);
}

From here I downloaded my STL (the 3D description of the object)...

OpenJSCAD

I then ran it through the Microsoft 3D Model Repair Service (a good idea to make sure all your designs are manifold and watertight).

Repetier

Then into Repetier and sliced into G-Code (instructions to the printer on how to move) and printed it with OctoPrint on my OctoPi.

image

I'm clearly not a 3D designer or modeler and I apparently don't have the patience for CAD tools that won't let me type in a direct number. I KNOW this should be 31mm in diameter, don't force me to use a mouse to "eyeball it." I was thoroughly impressed with the concept and execution of OpenJSCAD. Of course, OpenJSCAD is a JavaScript implementation of OpenSCAD, the "Programmers Solid 3D CAD Modeler" so I'll be exploring their software and amazing gallery as well! If you're creating anything with regularity that's more mechanical and less organic, OpenJSCAD or OpenSCAD is the way to go, clearly.


Sponsor: Big thanks to Amyuni for sponsoring the feed this week! Amyuni PDF Converter and Creator for .NET enables you to integrate powerful PDF functionality with just a few lines of code. Generate and process optimized PDFs with industry proven technology. Switch Now!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.