Generating Morse Code Sounds from Text

I decided to port my python morse code script over into a live demo web page (this is because live demos are infinitely easier with HTML5/javascript web pages which are client-side, instead of web server based solutions that would cost me compute resources to run/maintain).

We want to have an input text box, and after the user submits, convert it to a sequence of morse code dots and dashes (dit's and dah's),

Morse code conversion is simple enough, a look-up dictionary. Then to generate the sounds, I actually started with generating the audio data from a python script into base64 encoded strings that was then loaded by the javascript. This mostly worked, with some interesting loading issues on mobile web pages.

I then transitioned to using Tone.js, which is pretty fantastic and provided an easy method for generating the morse code tones programmatically, and with more accurate timing than the existing javascript setTimeout methods (which can lag by several 100ms).

Here's a …

Calculating your upcoming Life Crises Events

A friend of mine was having their quarter-life crisis (apparently it's a thing), which happens around the age of 25, so unfortunately I've missed mine already. This got me thinking about all the life crises that I've already missed and have coming up. I wanted to make a script that given my birthday would let me know all about my life crises. Have a 2/7th life crisis party or something, who knows.

So there's the obvious mid-life crisis, which happens around your 40's. Let's assume a lifespan is 100 years, then let's find our mid-life and quarter-life crisis times. On top of that, why not our 1/3 and 2/3 life crises? or even 3/5th of 5/7th. Also, let's put this on a little HTML5/javascript web page that will provide to-the-second accurate estimates for upcoming crises.

Needless to say, this is probably not what one should do when a friend is having a life crisis (they weren't entirely as enthusiastic about this script as I was). Anyway, never let an …

Creating ExistentialRickBot, probably the silliest Redditbot yet

So I'd written SchmeckleBot, a simple bot that converts currency from schmeckles to USD. But I decided to go even simpler, still in the theme of Rick and Morty (if you loved Futurama watch this!).

In the pilot episode, when Morty sees something during a chase scene that causes an existential crisis, Rick quickly snaps him out of it with the pithy quote 'Don't think about it!'.

It should be immediately obvious that a reddit bot needs to exist and reply with that quote whenever an existential question is asked on the r/rickandmorty subreddit. And thus was born ExistentialRickBot.

The core logic is dead simple, if an existential question is posted, respond with an existential answer.

questions = ['why', 'happen', 'think'] # Match if any of these are found in messagedefisExistentialQuestion(message): return'?'in message andany([q in message.lower() for q in questions]) defgetAnswerToExistentialQuestion(): return"The answer is don…

Writing SchmeckleBot, a simple Reddit bot

This post will discuss the ideation and building of SchmeckleBot. So, before I wrote the Tensorflow chessbot, I wanted to learn the basics of building Reddit bots, and decided to choose something that was both fun and solved an existing problem.

I frequent the /r/rickandmorty subreddit, which if you haven't heard about it is a place to talk about Rick and Morty, a hilarious and awesome TV show (check it out if you're into animated TV shows like Futurama or Archer). Every so often redditors comment on a post saying they'll buy something for X amount of schmeckles, a unit of currency from one of the episodes of Rick and Morty. Here's one such post

Boogilywoo2411 points3 months ago Hey there! I'm Mr.SculptureBuyer. I'll pay 50 schmeckles for that sculpture!
According to the creator Dan Harmond a schmeckle is about $148 (the reason for this conversion is pretty great). So 50 schmeckles would be $7,400 USD. We want a bot that responds something like this (in fact, exa…

Learning TensorFlow #2 - Predicting chess pieces from images using a single-layer classifier

Let's train a tensorflow neural network to tell what piece is on a chess square. In the previous post discussed how to parse input images which contained a chessboard into 32x32 grayscale chess squares. Let's look again at our input and outputs.

Input 32x32 grayscale normalized image of a single chess tile containing a piece or empty Output A label for which piece we think it is, there are 6 white pieces and 6 black pieces, and 1 more for an empty square, so 13 possible choices.
Let's define our output label as an integer value from 0-12, where 0 is an empty square, 1-6 is white King, Queen, Rook, Bishop, Knight Pawn, and then 7-12 are the same for black. A black pawn in this case would be 12 then. In a one-hot label vector, this would be [0, 0,0,0,0,0,0, 0,0,0,0,0,1], where the 12th index is 1 and the rest are zero.
How do we generate training data where we know the labels? One way is to take screenshots of the starting chessboard position, where we know exactly where all th…

Learning TensorFlow #1 - Using Computer Vision to turn a Chessboard image into chess tiles

I've been wanting to learn how to use TensorFlow, an open-source library that google recently released for machine learning and other applications. The introductory tutorials are great, teaching how to classify written numbers, but it would be nice to try something different and new.

So what sort of problems could we solve? Well, one problem that I'd been having involved chess. There's a web forum called Reddit, which has several subforums (they call them subreddits) where people can post about specific topics, in this case the one I'm interested in is the chess subreddit. About once or twice a day someone will publish a new post that links to an image of a 2D online chessboard in a certain layout.

They're either from games, or sometimes are called tactics puzzles, which is where a person is given a certain layout of chess pieces and tries to guess the next best move or series of moves for one of the sides. A lot of the times, after guessing the sequence, I wanted …

Generating Sentences with Markov Chains and N-grams using IPython Notebook

Remember the chat bot assistants that plagued Web 1.0? At first glance, the sentences seemed reasonable, and we start to believe perhaps it's a human? But inevitably a non-sequitur such as thisis reached: Interviewer: You asked me where I was from already.
Eugene: So what that you were from already By the way, what’s your occupation? I mean – could you tell me about your work? Why does this happen? How are these sentences being generated? I've always wondered how chat bots like Alice or Eugenework. 

Now, they are obviously much more complex than this tutorial will delve into, but we can touch on some of the core principles. One of them is this idea of understanding the relationships between words in sentences. How can we get a machine to understand these relationships?
Before going further, this entire post is based on this nicer formatted IPython Notebook, feel free to read through that instead. It turns out there's the right way, and then there's the easy way. The right…