TL;DR: Working with db transactions in Go should be simple, so I made some utilities to help with that. You can see the gist containing all the code here. The database/sql package has everything you need in order to work with db transactions for most vendors. Typically, you’ll write something like this: While this code works, there are a few of things I think could be better about it.
Monitoring your application is important - full stop. When the response time plummet’s you want to know before your customers do…and certainly before you bother to check your twitter feed. There are lots of options here, and a lot of them require a ton of upfront investment in terms of time and effort. However, a simple way to get started is to simply log total request durations and track the number of successful and failed responses.
Like a lot of developers, I use vim. Of course, I don’t use straight out of the box vim though. I use Vundle and other settings (see my dot files for more) to make it better. Sometimes there are plugins, or packages that require vim to be compiled with support for ruby and/or python. One example of this is the excellent Command-T plugin. Unfortunately, the default package doesn’t include these flags during compilation.
I use vagrant (along with chef, a vagrant plugin and my dotfiles) for my development environment. I do this for a number of reasons, but mostly, I find it’s the easiest way to get everything installed and configured properly regardless of which physical box I’m working on. There are a number of issues I needed to address to get this all working. One of those, was getting a simple rails server from inside the VM to be available from my host’s browser.
In a recent bout of insanity, I thought it would be cool to play around with concurrency in pure C. Nothing crazy, maybe controlling access to a shared resource and a semaphore or two for good measure. Since I assumed this would be no easy feat in C, I deciced I’d start with a problem I knew. So I went with the dining philosophers problem. Defining the Problem There are five (can be adjusted) philosophers sitting around a round table.
We do lightening/dev talks every week at work, where a few developers get up and talk about cool projects or anything they think is interesting. One of the recent talks by James MacAuley was about git freeze and git thaw. The basic idea is that git stash kinda sucks sometimes. To show that, let’s run through an example. Example of Using Git Stash mkdir demo_repo && cd demo_repo git init git commit -m "initial commit" --allow-empty touch README.
Recently I had the opportunity to work with GitHub’s API again. This time I was particularily interested in the Repo Contents API. The goal was to be able to publish files from disk or embedded resource (read: stream) directly to a GitHub repo without having to clone the repo somewhere and then issue a git push. The API seemed (as is always with case with the GitHub API) straightforward and had methods for creating and updating files.
I generally find that most developers are fairly aware of and willing to apply the DRY principal on their main codebase. However, when I look through people’s tests, I find that the old copy/paste habit has found it’s way into their workflow (again?). I’m using “their code” to save face here…I found this in my own code and started looking for ways to clean it up. So, let’s take a look at an example of how we can remove some duplication from our specs.
For this post, I’m going to go over getting a simple CI environment setup using Travis CI and xUnit. If you’re one of those people that just wants to see the code, click here! Our goal is to have the following scenario: whenever a push happens (to any branch) on GitHub, a build of the app will be triggered by Travis CI. If the build succeeds, it will run all of the unit tests for your app.
Last night I attended my first Ruby Brigade Meetup in Toronto and I have to admit…it was kinda fun! It was graciously hosted at Influitive’s downtown office on Adelaide St. When I got there I was happy to see some fancy boardrooms and a bunch of pairing stations for us to use. All in all, a great location. We got a little caught up in some general technology discussions so as expected we got started a little late.
I recently started playing around with EmberJS. While I was insanely impressed with how easy it was to get a single-page app up and running, I was having difficulty getting QUnit setup correctly. After some finagling I was able to get it working. In my particular case I’m using Ruby 2.0.0 and Rails 4.0.0, though I’m sure this same setup would work with previous versions with minimal (if any) tweaks.
In a previous post I went over how we could create a generic linked list implementation in C which would allow the caller to determine that type of information stored in the list (via a void *). In accordance with my desire to share and the nerdy, sadistic, love/hate relationship I have with C, I’m going to cover how we can use the linked list code from the previous post to create a generic stack implementation with very little effort.
Because I am a totally shameless nerd, I find myself writing applications in C from time to time just to make sure I still can. Aside from iOS development, I rarely have to work with C directly (without the help of a superset like C++ or Objective-C), but every once in a while I like to try and challenge myself to write an application in pure C. I’ve found that doing this has led to a much more profound understanding of modern languages and has really opened my eyes to the challenges faced by developers who write their own languages or work with compiler optimization (I know a few…it sounds like tough work!
Frequently I find myself creating basic rails apps to demonstrate a new feature, or prototype something for a spike test. Every time I created an app, I would run rails new -T, then add RSpec, Cucumber, Haml, possibly Bootstrap, etc. After the 10th app in a month, I decided that there must be an easier way. Then I saw this post: http://everydayrails.com/2011/02/28/rails-3-application-templates.html I started reading up on generators and application templates, then I thought I’d write my own, to see how it works.
I just recently installed Windows 8 on my home computer. During the installation process, I was not asked to provide a product key. This led to me not being able to activate Windows after the installation process. To resolve this, follow these steps: From the start screen, type cmd Right-click on Command Prompt and select Run as Administrator Execute the following command: slmgr -upk Press Windows+C to bring up the Charms window Select Settings and click Change PC Settings The Activate Windows tab will now ask you for your product key Oddly enough, I had trouble finding this info so I thought I’d share.
Once in a while, I find myself implementing the same helper functions in different pages. In an effort to not repeat myself, I generally move helper functions into a common cshtml file in App_Code (as suggested here). While this works great for a single application, I’ve found myself copying helpers from project to project. So in order to avoid the copy-paste nightmare, I decided to see if I could abstract the basic functionality into an extension method and then have application specific rendering.
Let me start by saying that I’ve made this mistake on many occasions in the past. I just assume that static/shared objects are thread-safe. Things like HttpContext.Current.Cache…OOPS! A typical implementation of a cache lookup might look like this: Let’s analyze this code in a little detail. Here are the steps performed: Load the object from the Cache If the object is null (not found) Create the object and store it in the cache Return the object back to the caller To start, we should ask, what happens if 10 simultaneous requests come through attempting to get to the cache object?
I recently wanted to setup a subversion server. Initially I thought of using Beanstalk since they handle pretty much everything for you for a very small monthly fee. However, I thought I might set up my own server in order to learn the process. I found a few online resources that outlined the process, but none of them were exactly what I needed, so I decided to write this post to go over the steps in detail.
Recently I’ve been working on an iOS project that loads data that we publish via the Open Data Protocol. At first everything was working perfectly. I was using JSONKit and NSOperation to download and process the information. That was until I had to get a DateTime object…which resulted in an epic fail! It turns out that WCF Data Services publish DateTime objects as a new Date object represented by the time in milliseconds (not seconds) since January 1, 1970.
Recently I needed to show a drop down list of all of the enumeration values. So I did what we all do and hit up Google. While there was plenty of information out there detailing how to convert the enum to a Dictionary<int, string> and render it, I couldn’t find something that fit my needs. Essentially I have an enumeration of field types. I wanted to display the names of those fields in a drop down list, but be able to make some of them prettier.
While I’m loving MVC3 and the Razor view engine, I was sorely disappointed when I couldn’t use the system.web/pages/namespaces collection in web.config to add global namespace includes. After a bit of hunting and looking through the web.config files underneath the views folder (in each Area), I found that this can be accomplished by adding the following to the root web.config file: Now you can add any namespaces you require under the new razor namespaces section.