<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jack Pincus on Medium]]></title>
        <description><![CDATA[Stories by Jack Pincus on Medium]]></description>
        <link>https://medium.com/@Jwpincus?source=rss-1c98888dfbc0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*li32HgHfty4MPaUpsC6UcQ.jpeg</url>
            <title>Stories by Jack Pincus on Medium</title>
            <link>https://medium.com/@Jwpincus?source=rss-1c98888dfbc0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:59:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Jwpincus/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I Made a Thing!]]></title>
            <link>https://medium.com/@Jwpincus/i-made-a-thing-f59f194a1aa?source=rss-1c98888dfbc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f59f194a1aa</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Jack Pincus]]></dc:creator>
            <pubDate>Thu, 24 Aug 2017 19:40:43 GMT</pubDate>
            <atom:updated>2017-08-24T19:40:43.097Z</atom:updated>
            <content:encoded><![CDATA[<h4>‘Dev-ops is hard’ edition.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*reapRNcuadyTka_s80ldcg.png" /><figcaption>There are 21 Batmans registered to vote in WA state. Not kidding.</figcaption></figure><h4><strong>TLDR:</strong></h4><p>The app is <a href="http://138.68.28.154/">here</a>. It’s a searchable database of every voter in WA state. The app isn’t the main product, I wanted to learn about deploying to production away from Heroku. I used Digital Ocean VPS’s to do this. If all you want to know is how to do that go <a href="https://www.digitalocean.com/community/tutorials/how-to-use-the-dokku-one-click-install-image-to-deploy-your-app">here</a>.</p><h4>Background</h4><p><strong>Disclaimer</strong>: Like all of my blogs, this is documenting a learning experience. This one especially is pretty far outside my domain of experience, and is as much notes for me as it is meant to be helpful to others. I would love to hear about any corrections and suggestions that you might have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77uyYHvPueE8iXmxp28DNg.png" /><figcaption>Those are some fun memories behind making some of these.</figcaption></figure><p>One thing that I want to get better at is understanding the process for deploying an app to a production environment. Almost all of my experience is in running in the development environment on my own machine, and in deploying to Heroku. Heroku is an amazing service, but it definitely follows the convention over configuration philosophy.</p><p>This dive into the dev-ops pool was inspired in turn by an app I’m building to play with optimizing SQL queries, and experiment with MongoDB in Rails, as well as learning some light data visualization (more on all of that next week). I intentionally chose a big dataset to play with to make optimizations really obvious, the Washington State voter records database. In raw form it is a CSV of 4.6 million rows listing every voter in the state. It comes with a bonus CSV listing the date and voter associated with every single ballot cast since 2015. It comes out to 1.2 GB of CSV. This would get expensive on Heroku quickly (this app would cost $16–57/mo. depending on DB design). A basic VPS that can run this app comes in at $2.50-$5/mo (there are even some basic free VPS plans, I’m not sure I trust that though).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iQx6Jk0icoScEqmQaslFjA.png" /><figcaption>No thanks.</figcaption></figure><p>As I mentioned earlier Heroku is strong on convention, what that gets you is ease of use. Deploying to Heroku is literally three commands. What it costs you is flexibility. Heroku has a way that it wants you to do everything, and that’s that.</p><p>I decided that at least knowing how to deploy to production on a real server, even on a small scale, is definitely a worthy skill.</p><h4>In Practice</h4><p>I decided to go the VPS route since it offers the most configuration, and would be the best learning experience in terms of universal applicability. There’s a lot to choose from and there are far more knowledgeable people out there comparing them. I went with Digital Ocean on the advice of a friend.</p><p>The actual process of configuring the server is something that is very well documented, digital oceans has great guides for their servers, but which would apply equally well to almost any VPS. You can opt to have rails and all of the dependencies pre-installed, or just have a barebones server with Ubuntu.</p><p>The details of the actual steps to deploy depend on how you are planning on getting it done, and how much manual control you want over the process. Google is definitely your friend here.</p><p>Two tools that are definitely very useful are Dokku and Capistrano. Both are designed to automate deploying an app to a server from a local machine. Dokku is largely modeled to be a lot like a private version of Heroku (again some flexibility is sacrificed for convenience.) Capistrano is a little more involved to set up, but is very powerful and flexible once it’s working. I deployed the same app on both to two different VPS’s, just to see how it worked. <strong>Oddly enough, performance is way better on the app deployed using Dokku </strong>(page load times of 6s. vs 4s… step two of this project is doing database and query optimizations to get that down to a more acceptable time)<strong>. </strong>Not sure why that difference exists, as the apps and databases are otherwise identical.</p><h4>Lessons learned</h4><p>Devops is such a huge skillset that its really a career path. However, a little bit of understanding the process goes a long way towards helping me understand even more about the frameworks and tools that I’m using to create my software.</p><p><strong>Linux: </strong>I use the terminal all day in OS X (I just learned that it’s now called MacOS as of 2016. Go figure). But setting up servers remotely requires operating exclusively in the terminal. Learning how to set up users, permissions, rsa keys and all of the admin tasks was step 1. It was a bad start, the first thing I did was accidentally turn off root SSH permissions without turning on SSH permissions for any other users. Oops. Locked out in the first 10 minutes. Eventually I got in the swing of things. I will say that with all the time I’ve spent SSHed into other machines this week, <strong>I am becoming a big fan of VIM.</strong></p><p>This process felt a lot like TDD: try something, get an error, research the fix, move to the next error.</p><p>Deploying really reinforced the TDD aspect. As already mentioned I don’t have enough experience to write a guide, but I will say that Capistrano and Dokku are great. Dokku was definitely the easiest for me (Digital Ocean can even pre-load a server with Dokku). Capistrano was a little more involved, but seemed more transparent about what was happening, and a little more adaptable.</p><p><strong>Challenges: </strong>Seeding the database was the hardest part about this whole process. I did learn a ton about how Postgres operates and some of the amazing features that it offers as a client/server service. Remember, the seed file CSV that I was using was 1.2 GB, and the seed rake task took about 2 hours on a Macbook pro with heaps of resources. If possible, I wanted to avoid trying to seed the database from the CSV files, especially on a VPS with 512 mb of memory and a low powered processor.</p><p>There are a lot of ways to make that seed happen, but again, it feels like the TDD process of fixing a chain of errors. In the end, I wrote a custom rake task that called on Postgres to make a database .dump from the fully seeded DB on my dev machine. I then used Rsync to transfer that file over SSH to the server. I had another rake task set-up that reversed the process on the server, taking the .dump file and using that to seed the database. That knocked the seeding process down to less than 5 mins.</p><h4>Conclusions:</h4><p>Is this really a practical way to deploy? I suspect the answer is, as always, it depends. It took me two days to deploy my app the first time. Now that I know how to do it, and how to solve the errors that I run into, I suspect that I could get it done in an hour or so. The same deploy to Heroku could be done in a matter of minutes, if that. But their are definite advantages to having full control over the machine running your software. I think that it would really depend on the use case, and the tradeoff between developer time, and server budget.</p><p>I do feel a lot more comfortable with what is going on under the hood in a server now that I’ve seen the spectrum of deployment options. It’s another tool that I can reach for, and something that I suspect will come in handy in my career.</p><h4>Call to action</h4><p>I love developing and writing about what I’m doing.</p><ul><li>If you have <strong>feedback</strong> I would love to hear it, that’s what the comment section is for. Or send me an email: <a href="/service/mailto:jwpincus@gmail.com">JWPincus@gmail.com</a></li><li>If you liked this project, <strong>please click the clapper</strong> right below this.</li><li>If you want to share it with the world: please do. <strong>Twitter, Linkedin, Facebook, Myspace, Friendster, Reddit </strong>are all options. Not Yo, however.</li><li>I moved up to Seattle, and am looking for a position. I’d love to talk development over coffee, if you’re in the area (even if you aren’t looking to hire). If you’re not near Seattle, I carry a phone with me at -literally- all times. <a href="/service/mailto:jwpincus@gmail.com"><strong>Get in touch!</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f59f194a1aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Made a Thing!]]></title>
            <link>https://medium.com/@Jwpincus/i-made-a-thing-316ff35c6df5?source=rss-1c98888dfbc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/316ff35c6df5</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[facial-recognition]]></category>
            <category><![CDATA[turing-school]]></category>
            <dc:creator><![CDATA[Jack Pincus]]></dc:creator>
            <pubDate>Sat, 05 Aug 2017 20:10:53 GMT</pubDate>
            <atom:updated>2017-08-05T20:27:36.551Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ewtZcnqvlqjYJHEvq_iiNg.jpeg" /><figcaption>It does more than it looks like it can.</figcaption></figure><h4>Facial Recognition Edition III!</h4><p>So this is the final write up for the broader facial recognition project. You can <a href="https://medium.com/@Jwpincus/i-made-a-thing-facial-recognition-e694bc1ac8c8">read part 1 here</a> and <a href="https://medium.com/@Jwpincus/i-made-a-thing-c9635139db32">part 2 here</a>. This has been a really fun project, and I’ve learned a ton about facial recognition, image capture in the browser, a little Python, and physical computing in this final part.</p><h4>Background</h4><p>The first part of this project linked above details building a service that allows users to register a facial profile, and manage devices or apps and the users that can use those devices via facial recognition. Essentially it’s very much like Oauth ‘login with facebook/gmail/twitter’ links that you see on a lot of sites now.</p><p>Having made the service, I wanted to have a device that can use the service to recognize users. The origins of the idea was to be able to use facial recognition for access control (doors, the beer fridge, etc.). So my device was made with this general purpose in mind.</p><h4>In Action</h4><p>After registering my device with <a href="https://re-cognizer.herokuapp.com/">the web service</a> (<a href="https://medium.com/@Jwpincus/i-made-a-thing-c9635139db32">workflow for that is detailed here</a>). It now has a unique app key associated with it for authentication calls.</p><p>The actual device is contained in a box that is designed to be mounted on a wall. It senses when a person moves within 90 cm. and takes a photo of the person. It sends that image to the web service. The web service will respond with whether it recognizes the face and that face is authorized. The device will then allow use of whatever is connected via an electrical relay.</p><p>So with the facial recognition device hooked up to a door lock, the process for opening the door would work like this. A person walks up to the box, their photo is automatically taken when they are close enough. If they are listed as an authorized user of that particular door on the web service, then the door will receive the signal to unlock. No keycard or need to buzz you in.</p><h4><strong>Technical Details</strong></h4><p><strong>Hardware:</strong></p><p>The actual brains of the device is a Raspberry Pi Zero W computer. It is basically the smallest cheapest computer that you can buy. This is fine, as what we are asking it to do doesn’t take a lot of horsepower. And realistically this computer could do some much heavier lifting if we needed it to.</p><p>There are four other physical devices that are wired into the RPi. An ultrasonic distance sensor. A camera module. A single button. And an electrical relay. The wiring diagram that I drew up looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*JBNK2WXCPbHDDAw3s6s2Zg.png" /><figcaption>Did I mention that I have no training in drawing electronic schematics?</figcaption></figure><p>The actual device looks like this with the covering off:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ckhe8gQM6i9BnMfBLzY0oA.jpeg" /><figcaption>Raspberry pi at the top. Button to the left. Prototyping breadboard in the middle. Relay at the bottom. The camera and distance sensor are attached to the top and not visible in the photo, although you can see their wiring heading off to the left.</figcaption></figure><p><strong>Software:</strong></p><p><a href="https://github.com/jwpincus/facial-circuit-control">Repo here</a></p><p>The Raspberry Pi is a really great choice for hardware prototyping. The amount of support for just about any physical interface is better than any other option. That said, the language of choice is Python, which is great, but not something that I have a ton of experience in.</p><p>I wrote two distinct classes. One that handled taking photos, and the other that handled getting a distance reading from the distance sensor.</p><p><a href="https://github.com/jwpincus/facial-circuit-control/blob/master/camera.py">The camera class</a> uses the RPi’s built in python camera library. When the snap method is called the RPi turns on the camera, waits for the sensor to adjust to the lighting conditions, and then saves the image in a 400px by 300px jpeg.</p><p><a href="https://github.com/jwpincus/facial-circuit-control/blob/master/distance_sensor.py">The distance sensor class</a> measures the time it takes for a sound pulse sent by the sensor to return. It uses a multiplier based on the speed of sound to determine how far away whatever echoed the sound signal back is, and returns that number in centimeters. There is some additional logic to handle a timeout when the sensor doesn’t properly send the signal for the echo.</p><p><a href="https://github.com/jwpincus/facial-circuit-control/blob/master/face_auth_runner.py">There is a third file</a> that acts as the runner that calls all of the classes as needed, and sends the HTTP requests to the service. the ‘runner’ is setup to initialize the GPIO pins controlling the hardware, and then starts an infinite loop. Inside of the loop the computer continuously runs distance checks using the sensor class. When it senses that someone has moved within 90 cm. it calls the camera class. The resulting photo is encoded into a base64 jpeg, and sent using Python’s request library. The server’s authentication response determines whether the relay is activated, or if the distance sensing loop is restarted. If the relay is activated, the runner waits in another infinite loop until it senses that the button is pushed. When the button is pushed, the relay is turned off, and the authentication is revoked. The initial distance sensing loop is then restarted for the next user to walk up.</p><p><strong>Challenges:</strong></p><p>Hardware is hard! Even with all of the support available, troubleshooting can be really tricky. The biggest issues I had were in trying to isolate bugs to either the software or the hardware. It can be really hard to tell if an issue is in the code or the components. It adds a layer of complication to developing for sure. Packaging and design are also important. I used a project box that takes up WAY more space than necessary. But I wanted it to be easy to work with firstly. Making it elegant can come later.</p><p>I learned a lot about Python in this process as well. I have a lot more to learn (I’m guessing I need to start with a style guide, but some guidance in best practices with Python OOP wouldn’t hurt). If I had my choice of languages, the code could have been a lot cleaner. However, it does work well, so the code can’t be that bad.</p><h4>Wrap-up</h4><p>It’s really hard to describe exactly how something like this works in words. But I think it’s enough to say that it is a little magical to walk up to something, and have it recognize your face and do work for you. The actual hardware can be configured for a number of different scenarios. Instead of having it log out when the button is pushed, it could be setup to logout after a set period of time, or even when it senses that the user has moved away (much more useful for a door lock). Right now I have it hooked up to a coffee machine, which is why it is set-up to only log off when i push the button.</p><p>I had a ton of fun with this project. Just like playing with the initial facial recognition tools, building one thing leads to ideas for more uses. I definitely plan on working more with physical computing.</p><h4>Call to action</h4><p>I love developing and writing about what I’m doing.</p><ul><li>If you have <strong>feedback</strong> I would love to hear it, that’s what the comment section is for. Or send me an email: <a href="/service/mailto:jwpincus@gmail.com">JWPincus@gmail.com</a></li><li>If you liked this project, <strong>please click that little green heart</strong> right below this.</li><li>If you want to share it with the world: please do. <strong>Twitter, Linkedin, Facebook, Myspace, Friendster, Reddit </strong>are all options. Not Yo, however.</li><li>I’m moving up to Seattle, and looking for a new position. I’d love to talk development over coffee, if you’re in the area (even if you aren’t looking to hire). If you’re not near Seattle, I carry a phone with me at -literally- all times. <a href="/service/mailto:jwpincus@gmail.com"><strong>Get in touch!</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=316ff35c6df5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Made A Thing!]]></title>
            <link>https://medium.com/@Jwpincus/i-made-a-thing-c9635139db32?source=rss-1c98888dfbc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9635139db32</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[facial-recognition]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Jack Pincus]]></dc:creator>
            <pubDate>Sun, 30 Jul 2017 21:12:11 GMT</pubDate>
            <atom:updated>2017-08-24T19:50:41.953Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Facial Recognition Edition II</strong></h4><h4>With an added bonus thing I made, at the end!</h4><p>Do you like this project? <strong>Please share, comment, and recommend!</strong></p><h4><strong>TL;DR</strong></h4><p>Use your beautiful face to open doors! Literally. Or keep certain faces on the other side of that locked door. My app makes it super easy to control who is and isn’t allowed to access real life things using facial recognition. <a href="https://re-cognizer.herokuapp.com/">You can play with it live here.</a></p><h4><strong>What’s the big idea?</strong></h4><p>I want to be able to confirm identity in places where a traditional keyboard, mouse, and display is impractical, like out in the real world away from a desk.</p><p>This is a spin on last week’s ‘I Made a Thing’ post. Reading <a href="https://medium.com/@Jwpincus/i-made-a-thing-facial-recognition-e694bc1ac8c8">this</a> will give you a little more context. Starting from where I left off with basic web login using facial recognition, I decided to develop in the direction of making an authentication platform. The premise is that a device can use a photo of a user to determine if they are authorized.</p><p><strong>It might be easier to explain this with an example: A door to be specific.</strong></p><p>Doors are, at their root, an access control device. You need a key or some other permission - like somebody buzzing you in - to get access to the other side of the door. With the app I’ve designed, a door equipped with a camera can send my app a photo, and the app will tell the door if it recognizes the person in the photo, and whether that person is allowed in.</p><p>The web interface for my app allows whoever owns the door to set which specific people can open it. So you could set it to allow a house-sitter/dog-walker/cable-guy in while you are away from the house, and then disable or enable that on a person by person basis. No more lending keys out, or changing out a passcode and sending it to everybody once a month. Each person’s facial features are a unique key which can be enabled and disabled by each device’s owner.</p><p>Of course, a door is just one example. Anything with a camera that can connect to the internet can use my web app.</p><p><strong>Besides the actual web app, I’ve also built a basic access control device.</strong> It allows anything that can be operated electrically to be controlled by the identification service. More on that in the technical section.</p><h4>In action</h4><p>So there’s a couple of cool new features.</p><ul><li>You can register apps or devices that can then call my api to authenticate using a photo.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*pseb_gYAcEUOg0V6N7pGCg.gif" /><figcaption>Decide on a name, and decide on the rejection confidence that the AI should use (basically, how sure do you want to be that you have the right user).</figcaption></figure><ul><li>You can add or remove users to your app/device that you want to be able to authenticate. My app will send back an authentication confirmation with the user’s first name and email address when it is sent a photo of a user that it recognizes. By default, the owner of the app or device is added as the first authorized user.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*0NFd_79ZK3wWpXggr4SErQ.gif" /><figcaption>There’s a grammatical error in the captions of this gif that is driving me nuts…</figcaption></figure><ul><li>Users can see a record of when they have successfully been identified by devices. It shows the time, the photo that was taken, and the name of the app.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*pIy2lioFD65xwFAkr-u1HQ.gif" /><figcaption>What my authentication log looks like.</figcaption></figure><h4>Technical</h4><p><a href="https://github.com/jwpincus/face_finder">On Github</a></p><p><strong>A bunch of credit is due to </strong><a href="https://www.kairos.com/"><strong>Kairos</strong></a><strong> and their facial recognition API.</strong> They are the ones doing the heavy lifting when it comes to actually processing the images. Kairos also has a great pricing structure for hobby projects: personal projects are free with some very reasonable rate limits.</p><p>It is also worth mentioning that in limited experimentation I have yet to be able to fool the Kairos API. I already unsuccessfully tried my driver’s license, and a phone screen with my photo to try and spoof my way in last week. More impressively I recently tried holding a high quality photo of myself (albeit several years old, but unmistakably me) up to the webcam, which was also rejected. I don’t doubt that it can be fooled, but kudos to Kairos for having a very robust algorithm.</p><p><strong>Rails</strong>: from the Rails perspective this modification of the <a href="https://medium.com/@Jwpincus/i-made-a-thing-facial-recognition-e694bc1ac8c8">original app from last week</a> is relatively simple. I added models for apps/devices. I then connected Users to apps with three junction tables. One that records the owners of the app/device (Unfulfilled potential. Right now there is no way to add a second owner to the app/device from the web, but the capability exists), one that records the authorized users on an app/device, and the last one that records successful authorizations of the user. This is what the schema looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xP90wAwLW_syMFS5Yx1olQ.png" /><figcaption>Created using <a href="http://ondras.zarovi.cz/sql/demo/">this awesome site</a>. Worth noting: that site can take a visual representation of your schema, and then WRITE THE SQL TO SET UP THAT DATABASE FOR YOU.</figcaption></figure><p><strong>Other challenges: </strong>What happens when things don’t work? As apps like this build in complexity, and especially when dealing with an external API, you have to imagine all of the ways that things can go wrong, and then test for them. As mentioned before, setting up a test suite for something that takes a picture through the webcam is REALLY hard. Most of my testing for the webcam features has been manual. As this project gets bigger, finding where in the stack things went wrong gets more and more challenging. This is where it really pays to do things the right way. Following good OO principles and design patterns makes it a lot easier to isolate issues. Lots of credit to the instructors at <a href="https://medium.com/u/4d5de5a312c8">Turing School</a> who are absolute sticklers for high quality code (much to my benefit, and sometimes to my annoyance).</p><p><strong>One more thing: </strong>This app would be VERY boring if I hadn’t made any app/device that consumed the API. So that’s what I did. Using a Raspberry Pi Zero W, a proximity sensor, a camera module, and a relay, I can now do some really cool stuff with my own app. I’ll talk more about it in a future post (probably next week). What it does:</p><ul><li>Senses when a person is within 90 cm. (For fellow Americans: That’s half an inch short of a yard). This is adjustable from 2 cm.</li><li>Takes a photo when a person is in range.</li><li>Sends the photo to the web app.</li><li>Turns on an electrical relay if the person is recognized and authorized to use the device. This relay can be hooked into anything that operates electrically, in this case I’m just wiring it into an outlet. So whatever is plugged into that outlet is only powered when a user is recognized.</li><li>When the user wants to power down whatever is plugged in, there is a button they push that deactivates the circuit and has the device start looking for people it recognizes again. It can also be set up to timeout after a given time, or to shut down the circuit when the person moves out of range.</li></ul><h4>Wrap-up</h4><p>I’m pretty proud of this app. The idea was hatched when I was having a few beers with a group of developers at their office. This was in Vancouver, where beer is expensive enough that the company asks employees to chip in to help cover costs. The developers working there were lamenting not so much that they had to chip in every time they grabbed a drink, but that it was a pain to carry around cash. There was some speculation about using their RFID cards to maintain a ledger. This is what lit the spark that led to this personal project. Find a way to make it easy and painless to identify and authorize people.</p><h4><strong>Call to action</strong></h4><p>I love developing and writing about what I’m doing.</p><ul><li>If you have <strong>feedback</strong> I would love to hear it, that’s what the comment section is for. Or send me an email: <a href="/service/mailto:jwpincus@gmail.com">JWPincus@gmail.com</a></li><li>If you liked this project, <strong>please click that little green heart</strong> right below this.</li><li>If you want to share it with the world: please do. <strong>Twitter, Linkedin, Facebook, Myspace, Friendster, Reddit </strong>are all options. Not Yo, however.</li><li>I’m moving up to Seattle, and looking for a new position. I’d love to talk development over coffee, if you’re in the area (even if you aren’t looking to hire). If you’re not near Seattle, I carry a phone with me at -literally- all times. <a href="/service/mailto:jwpincus@gmail.com"><strong>Get in touch!</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9635139db32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I made a thing!]]></title>
            <link>https://medium.com/@Jwpincus/i-made-a-thing-facial-recognition-e694bc1ac8c8?source=rss-1c98888dfbc0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e694bc1ac8c8</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Jack Pincus]]></dc:creator>
            <pubDate>Sat, 22 Jul 2017 21:20:12 GMT</pubDate>
            <atom:updated>2017-08-05T20:28:25.583Z</atom:updated>
            <content:encoded><![CDATA[<h3>I Made a Thing!</h3><h4>Facial Recognition Edition</h4><p><strong>What’s the Big Idea? </strong>In verifying someone’s identity you can look to three broad categories. Something you know, like a password. Something you have, like a keycard. Or, something you are, like your facial features.</p><p>This project concentrates on that last one. I wanted to explore the idea of using facial recognition to authenticate users. <strong>I built a basic Rails app that allows users to sign in using <em>either</em> a password and email, or using their email and a webcam captured image.</strong></p><h4><a href="https://re-cognizer.herokuapp.com/"><strong>I encourage you to play with it here</strong></a><strong>. (It’s currently on Heroku’s free tier and there may be a slight delay loading the landing page.)</strong></h4><p><strong>Using the app. </strong>When a user first registers their account is created in much the same workflow as just about every site on the internet, name, email, password and confirmation. Account created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*o_Ynu5qWiuKoFgaJzZFm3w.gif" /></figure><p>The next part is where it gets fun. After account creation, the user is prompted to enroll a reference image that will be checked against future sign in attempts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*E_-90f-VJoT7mk8iyjuvmA.gif" /><figcaption>I will not apologize for my shirt</figcaption></figure><p>At this point we have a user, and we have a reference image that can be checked against. So when a user wants to log in they can use either something they know (password), or who they are (facial features). Like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Czqom6LHGBzmzvIu2FlxGA.gif" /></figure><p>From there, you can use it for the same purposes as any web app that has a user model.</p><p><strong>Technical talk. </strong><a href="https://github.com/jwpincus/facial-login-standalone">Github repo here</a>. This is built on top of a pretty bog standard user authentication model using the Bcrypt gem. <a href="https://gist.github.com/thebucknerlife/10090014">This is an excellent write up of that process</a> so I won’t explain it here.</p><p>Starting from there I wanted to add in the ability to use facial features as an authentication factor. I originally started playing with the excellent OpenCV library, which would allow me complete control, and do the processing locally. I quickly realized that face recognition is an exceptionally complex task, and for any degree of reliability, I would probably want to reach for an external service to handle facial recognition.</p><p>After playing with some of the features at Amazon’s Rekognition, and Microsoft’s Face API, I decided on <a href="https://www.kairos.com/">Kairos</a>. They offer an easy to use API that comes with a great free tier for playing around on personal projects.</p><p>I then <a href="https://github.com/jwpincus/facial-login-standalone/blob/master/app/services/kairos_service.rb">wrote a service class</a> for my Rails app. This does two things (okay three, but the third one is an easter egg for other developers, look at the linked file if you’re curious). 1. It has an enrollment method that takes that <em>signup</em> image, and has the Kairos API create a facial profile for that user. 2. It has a visual auth method that takes a <em>login </em>image and has Kairos reference it against that particular user’s enrolled image. Kairos then tells us what the likelihood is that they are the same person. You can set your own rejection threshold with the ENV[‘confidence’] variable. I found that 0.7 worked well, although for higher security, bumping it up to .85 or .9 seemed to yield good results without too many false rejections.</p><p>The results of calling the Kairos service class can then be used in the session controller to create a logged in session, or reject the attempt (worth noting is that the create_webcam method is called through AJAX, which is why we are returning a js redirect):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HL90e417PRj90zYPDGAWag.png" /></figure><p><strong>Challenges: </strong>I’m not a JS wizard. I explored using the getUserMedia functions to access the webcam, but ended up reaching for <a href="https://github.com/jhuckaby/webcamjs">WebcamJS</a> as it very neatly wraps up getUserMedia into some very nice pre-written functions. It also provides an easy fallback to a flash alternative for browsers that don’t support getUserMedia.</p><p>Testing was also a challenge. For obvious reasons, it is really hard to automate testing something that requires a real human face. I simply was unable to find a way to mock webcam images for an integration test. That’s not to say that it isn’t possible, just that it isn’t easy.</p><p>Handling photos with no recognizable faces, or too many faces was also an issue. Luckily Kairos provides enough information in the returned information to set up some error handling. Right now, it isn’t handled particularly well to the view, only telling the user that something didn’t work, but not giving context.</p><p><strong>Some closing thoughts. </strong>While I haven’t yet been able to spoof my way into an account, I suspect that it would not be hard. It rejected my driver license photo, although that may be a reflection of the Colorado DMV’s photographic ability. More interestingly, it rejected a photo of me displayed on a phone and held up to the camera. I suspect, but haven’t tested, that a color print would fool the system.</p><p>With that in mind, you want to use this system for purposes where certainty is not required, or use it as part of a two factor system.</p><p><strong>Certainty not required… what could you possibly use this for, Jack?</strong></p><p><strong>Scenario</strong>: I used to run a youth experiential education program. We would take HS and college aged kids out on trips from 3 weeks to 90 days. One of the best ways to keep parents informed was with a blog of photos and daily activities. However, parents are largely interested in seeing just the photos that have their kids in them. At our peak we could have as many as 300 different students on 4 or 5 continents pumping out hundreds or thousands of photos per day in a dozen or more blog posts. This system could be built out to check all blog photos in a day, and find all of the registered users in them, and send out an email summary of photos of the student.</p><p><strong>Scenario 2</strong>: Use it to create an Oauth like system for IOT devices, access control and access logging. More on this in a week or so.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e694bc1ac8c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>