1 2 3 4 5 |
|
The easiest fix for this is to set the paste mode before you head into insert the code:
1
|
|
You’ll notice the statusline shows you in PASTE
mode and the tooltip shows -- INSERT (paste) --
. Paste in your code and things should be good. When you’re done, revert back with:
1
|
|
Another option is to set your pastetoggle key.
1
|
|
The above code will set the F2 key to toggle between paste and nopaste.
What I REALLY want is a way to yy and pp from my system clipboard and have it work in vim. One large problem with this is that the methods that OS X uses to go to and from the clipboard (pbcopy and pbpaste) break when you work in tmux sessions.
To fix this, we need to install reattach-to-user-namespace
from ChrisJohnsen/tmux-MacOSX-pasteboard. We can install this threw brew:
1
|
|
and in our .vimrc, add the following line:
1
|
|
Now, anything you yank from vim is available in the clipboard, and anything in the clipboard is available to paste in vim!
]]>First off, I like keeping my query validations separate by putting them into app/controllers/validates and then including them at startup. Each controller should then have their own validator.
Validating specific queries can be done with ActionController::Parameters. By creating an ActionController::Parameters object and passing in the request params, we can then #permit specific queries to be made.
For example, let’s say you’re building a location aware app that needs to query via latitude and longitude. You can build an ActionController::Parameters object to permit only the ?latitude and ?longitude queries:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
If a query other than ?latitude=X&longitude=Y are passed, a ActionController::UnpermittedParameters exception is returned. We’ll need to rescue_from this exception in order to return our error to the user. Our Locations Controller would look something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
ActionController::Parameters.action_on_unpermitted_parameters is set to :raise so that errors are thrown instead of logged.
Now, a query such as /locations?latitude=47.60&longitude=-122.33 would return a valid location for us, but a query containing anything else would return an error. For example:
1 2 3 |
|
So that’s pretty awesome. Now end users of the API will know they can only use specific queries. But which queries? It’d be nice if there was a way to let an end user know which queries were needed. If only Rails had a way to validate certain values…
Enter ActiveModel::Validations. The same validations we use on our ActiveRecord Models can be used to validate queries we make to the API.
To do this, we need to include ActiveRecord::Validations in our API validations. Then, you can validate queries just like you validate models.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Not only can we validate the presence of a certain query, we can validate that it must be in a certain format, contain certain items, etc… Anything you can validate with ActiveModel::Validations you can now validate in your API.
A few changes need to be made in our Locations Controller in order to make this work:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Now we get the following errors:
1 2 3 |
|
There’s so much more that you can do with this. I’ve built a demo app and put it on Github to show off the usage described in this post. Check it out @ https://github.com/benwoody/validate_params
]]>I’ve recently decided to pick up learning the Go programming language. Why Go? I don’t remember why. But I think I was interested in beefing up backend services for some of the webapps I deploy. Plus, the Gopher is kinda cool. Also, the language itself is very easy to read in a Ruby type way.
The one pain in the ass thing about Go is that, as of now, the resources for learning it are few and far between. So I figured, “Hey, why don’t I just write about the things I’m learning?” So, hey, I’m doing that.
I’ve started a repository on github, benwoody/go_learn. There, I plan on adding the code example I will be writing about in this very blog!
So as a first post on my Go learning journey, I present to you a list of Go learning resources!
The end result of this is to show my progression of starting at the beginning (Hello, world!), all the way up to more advanced Go topics… whatever those may be.
]]>I’ve seen a lot of different posts on how to get going with pair programming. Many of them suggest having another person ssh in to your computer and have at it. I like to keep remote work separate though AND I just happen to have a VPS for just such a thing. So let’s set up remote pair programming!
On your remote machine, create a new passwordless user:
1
|
|
This will create a new user with no password on your machine. We’re not going to be needing a password because users will be logging in with their ssh keys.
When I first set this up, I was keeping track of my friends keys and adding them to the pair users .ssh, but that got really old, really quick. Luckily, there’s an app for that! Or a gem really…
Hopefully you have ruby installed on your remote machine. Now, depending on how you have your environment setup and where you have your ruby gems installed, you’ll need to make sure the pair user has permissions to install gems and use them locally. It does? Awesome, let’s keep going.
Install Chris Hunts awesome github-auth gem. This will let us grab a users SSH keys from Github and add them to your authorized_keys.
1
|
|
To add or remote a user to pair with:
1 2 3 4 5 |
|
To get this going, add yourself to the authorized_keys and then add your friend.
Then, both of you can simply
1
|
|
and BAM you got some pairin’ goin’ on!*
When you’re done, just remove their access!**
* I’ll probably write up a nice post on how I have my pair environment set up at a later date.
** Note that this setup means you have some sort of trust with the person you are pairing with. This probably isn’t the BEST security practice. Optionally, you could add the pair user to a group with limited access.
]]>I assumed installing 2.0.0-rc2 would be easy using rbenv:
1
|
|
But it didn’t turn out that easy:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Some googleing turned up this issue for rbenv, https://github.com/sstephenson/ruby-build/issues/288, which shows the issue being a problem with version of OpenSSL installed on Mountain Lion.
So I tried the suggested
1
|
|
AND
1
|
|
AFTER I had used brew to install/upgrade the newest version of OpenSSL. NOTHING WORKED. SAME ERROR.
Problem? It seemed to be an issue with the most current version of rbenv/ruby-build used with brew. So I had to uninstall both from brew and use the git-clone method instead, giving me the newest version.
Installing with
1
|
|
worked just fine after that.
]]>You can find it at: https://github.com/benwoody/github-pidgin-emoji
A list of emoticons can be found at http://www.emoji-cheat-sheet.com/
Below be the code snippet to generate the Pidgin theme file
1
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
1 2 3 4 5 6 |
|
and my favorite:
1
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|