Personal and development blog of Kamran Ayub

about me

Hi, my name is Kamran. I am a web developer and designer, residing in Minnesota. I’ve been programming since 2001 and I am familiar with many different languages, both web-based and server-based. I love to tinker around and think of new ways to solve problems.

Triggering a Travis Build Programmatically

For Exalibur.js we wanted to be able to keep our master branch documentation up-to-date on the website. The website is built using Assemble.io and GitHub pages and after successfully automating my blog, naturally I turned to Travis CI to set up automated documentation generation.

Travis normally sets up a hook in your GitHub repository to automatically trigger a build after you push a commit (or pull request). This is real nice but unfortunately that’s where it stops. If you want to trigger a build for another repository, you have to do it manually.

I asked Travis about this and their response is promising (Twitter can be nice sometimes):

Until that time, though, something has to be done.

One approach I saw was a small Ruby script to forge a webhook POST message. This is actually a nice idea but since Excalibur uses Node to build, I needed something else and didn’t want to port it over.

Instead I borrowed some code from @patrickketner that uses the node-travis-ci npm package to submit a build through the public API. I modified Patrick’s code since I need to use GitHub personal access tokens like I did previously.

You still need to follow the same steps to set up the GH_TOKEN environment variable but once you do, all you have to do is execute this Node.js script (changing the repo).

So for example, in your .travis.yml file, you just need:

  – npm install travis-ci
  – node trigger-build.js

All set. Now when you commit to one repository, you can trigger a build for another one. This allows us to automatically keep our docs up-to-date with whatever master has.

You can reference Excalibur to see how we execute the script. Additionally, you can reference excaliburjs.com’s Travis configuration to see how we use TypeDoc to generate documentation for the latest version of master.

written in Automation, CI, Javascript, Node.js, Tips, Travis-CI

Continuous Deployment With Travis-CI

One of the fun things we did for Sweep Stacks (our Ludum Dare entry) during development was to setup continuous deployment. Since our GitHub repository was public, we could leverage the excellent Travis CI build tool.

This allowed us to work on the game and have our dedicated tester play every new build hot off the press. It reduced the amount of bugs we shipped with and created a very fast feedback loop for QA. In the end it allowed us to push a polished game an hour or so before the deadline hit. After the voting began, it also allowed us to quickly push bug fixes that were reported by players.

If you’re new to Travis CI, you can learn more about what it is and how to get started by reading my Tech.pro tutorial.

Once you have your project building, you can then write a little bash script to deploy it! By “deploying”, what I really mean is pushing your built code to your production branch on GitHub for final deployment. For example, we use GitHub pages to host Sweep Stacks.

Let’s look at the process.

Customizing Travis Config

You will need to execute a script to deploy your site, so you will need to customize your _travis.yml file.

Here is what mine looks like for this blog (built using Octopress):

language: ruby
  - 1.9.3
    - source
  - GH_REF: github.com/kamranayub/kamranayub.github.io.git
  - bundle exec rake generate
  - chmod ugo+x deploy.sh
  - '[ "${TRAVIS_PULL_REQUEST}" != "false" ] || ./deploy.sh'

Let’s break it down:

language: ruby

Easy, since I use Octopress (built on Jekyll) for my blog, we need to use Ruby.

  - 1.9.3

The version of Octopress I use requires Ruby 1.9.3.

    - source

We only want Travis to initiate builds for the source branch, since that is where the source files are for my blog.

  - GH_REF: github.com/kamranayub/kamranayub.github.io.git

We will need to be able to clone and push to our repository, so we store it in an environment variable for easy access. GH_REF will be available to our bash script.

  - bundle exec rake generate
  - chmod ugo+x deploy.sh
  - '[ "${TRAVIS_PULL_REQUEST}" != "false" ] || ./deploy.sh''

In our Travis script, we build the blog (rake generate). We then mark our deploy.sh file as executable (since I’m on Windows). After that we execute our deploy as long as this isn’t a pull request (don’t want to build other people’s changes!). Disabling pull request builds can also be set in your Travis project settings.

Deploy script

Here’s the script I use to do the deployment:

As you can see it’s fairly simple. One thing to make sure of is hiding your access token (GH_TOKEN), we use to authenticate which I’ll show you how to generate and use.

The access token

The whole reason this works is because we are authenticating to GitHub using a Personal Access Token (stored in GH_TOKEN). This is an OAuth token that you can create when using Two-Factor Auth to authenticate 3rd party tools like Visual Studio, or in our case, authenticating in a script.

You can generate a token by:

  1. Going to Applications in your Settings
  2. Clicking “Generate New Token”
  3. Selecting your permissions (for Travis, all you need is public_repo)
  4. Once created, copy the token to your clipboard (you must regenerate it if you lose it)

Now we need to configure Travis to expose this token securely to our script.

  1. On Travis, go to the Settings of your project (top-right)
  2. Click the “Environment Variables” tab (and ensure Build Pull Requests is ‘Off’)
  3. Create a new environment variable called GH_TOKEN
  4. In the Value field, paste in your token, being sure to remove any trailing whitespace
  5. Ensure “Display value in build logs” is Off

Once created, you’re all set! GH_TOKEN will now be available to your deploy.sh script.

Testing it out

You should be ready to test your deployment. Commit any changes you have to your repository and you should start seeing the build output once it starts. If there are any errors, now you can fix them until your build passes.

Happy deploying!

written in Automation, CI, Tips, Travis-CI

Just Released the New Keep Track of My Games Beta

Keep Track of My Games

This last weekend I finally released the beta version of the new Keep Track of My Games site. It’s been a long time coming but now it actually lets you keep track of your games. The original site only let you track new games and the new version still offers notifications but now you can organize and tag your collection to track games you’ve played or haven’t played yet (backlog) or new games.

Over the next few months, I want to add social features and more syncing capabilities to services like Steam, Xbox, and PSN. I also want to add deal notifications for any game in your wishlist.

If you use the site, let me know what you think or vote up ideas on the roadmap!

written in Announcements,, Gaming,, KTOMG, News,

Ludum Dare 29 Game Jam Success!

This last weekend I spent 72 hours working on a game for the Ludum Dare 29 game jam. LD is a competition where you get a prompt for a game and then have to spend 48 hours (solo) or 72 hours (jam) and bang out a game. The solo competition has strict rules but the game jam has looser rules and allows for team development. It was a caffeine-filled rush and I hope to write a blog post shortly about how it all went down. It was a ton of fun! I worked with my friends Erik Onarheim and Josh Edeen, both primary contributors to the Excalibur.js game engine. I am also a contributor but I haven’t done a ton with the engine core, moreso the usability of the API, opening GH issues, and the website.

Kraken Unchained

In the meantime, be sure to check out the fruits of our labor! It’s a game where you play as the Kraken and you destroy ships. We originally had a ton of ideas, as you can see in our GitHub repository, but with only 72 hours your scope is pretty narrow. Still, we’re very happy with what came out and we’re glad that Excalibur.js pulled through!

Play Kraken Unchained. Vote for it on the LD site. You can also take a peek at the post-LD version which is in on-going development. It does support touch and fixes some issues in IE10/11.

You can also view the entirety of the source code on GitHub!


Getting WebSockets to Work on Windows Azure

I was banging my head against the wall for the past hour or so wondering why I was falling back to XHR polling when I deployed my Node.js application to Azure. I’m using socket.io and everything looks like it’s in order, works locally, etc. It was failing with a WebSocket handshake error.

What I saw in the Chrome developer console was something like:

Error during WebSocket handshake: Unexpected response code: 502

In my Azure Node.js console (azure site log tail SITENAME), I was seeing EPIPE errors.

It turns out, this little tidbit from the original Windows Azure blog post on Web Sockets did the trick.

Modify your web.config and add:

<webSocket enabled="false" />

To your system.webServer configuration. Also, another good point in that blog post is to use SSL, since you get SSL for free with a *.azurewebsites.net site.

Hope this helps someone else out there. This should be added to the official Azure tutorial on using web sockets with Node.js.

written in Azure, Node.js, WebSockets

5 Tips to Improve Your ASP.NET MVC Codebase

I have an urge to write a quick list of tips for improving an ASP.NET MVC application because I just got done reviewing some code for a support ticket at work. It’s still fresh in my mind and I wanted to get some of my thoughts down to share with others. If you have been doing MVC for a while, I don’t think much of this is news. It’s more for those of you that don’t do MVC often or are new to MVC.

written in MVC, Tips Read on →

Just Released: Have I Been Pwned?

I just released Have I Been Pwned? to the Windows Phone store. It’s a tiny, tiny app that only took me a couple hours to build. You can find the source code on GitHub.

HaveIBeenPwned.com is a website created by Troy Hunt, a security MVP, that checks to see if your email address appears in a database of all the breached email addresses in prominent hacks like Gawker, Sony, and Adobe. I’ve definitely been pwned, so it’s a good service to use to quickly see if you need to change your passwords.

I plan to add the background task soon but I wanted the initial release out there so that I can just submit updates to it. If you want to contribute, send me a pull request!

written in App, Windows Phone

Just Released: Bowling Calculator App


I just released my second Windows Phone app, Bowling Calculator. It’s an open source app that I created when I gave my talk at TCCC15. If you’re a fellow developer, feel free to send me a pull request with any bug fixes or enhancements. I want to keep it focused on the simple use case of scoring a bowling game; I don’t need it to track multiple games or keep track of history. It’s purpose is to serve as a production-ready sample app and to also be good at what it aims to do.


MiniProfiler RavenDB Pull Request Accepted

I just got a notification that my pull request for adding RavenDB support to MiniProfiler went through! It’s always really cool to see your contributions get pulled in. The MiniProfiler guys were really easy-going, @yellis was even kind enough to take on the testing. That kind of acceptance for pull requests is great to see because it makes me feel good about contributing and is a bit less intimidating.

written in GitHub, OSS Read on →