Managing Multiple Hosts and SSH Identities with OpenSSH
When I started working at End Point I was faced with the prospect of having multiple SSH identities for the first time. I had historically used an RSA SSH key with the default length of 2048 bits, but for my work at End Point I needed to generate a new key that was 4096 bits long.
Although I could have used ssh-copy-id to copy my new SSH public key to all of my old servers, I liked the idea of maintaining separate “personal” and “work” identities and decided to look for a way to automatically use the right key based on the server I was trying to connect to.
For the first few days I was specifying my new identity on the command line using:
ssh -i .ssh/endpoint_rsa patrick@server.example.com
That worked, but I often forgot to specify my new SSH identity when connecting to a server, only realizing my mistake when I was prompted for a password instead of being authenticated automatically.
Host Definitions
I had previously learned the value of creating an ssh_config file when I replaced a series of command-line aliases with equivalent entries in the SSH config file.
Instead of creating aliases in my shell:
alias server1='ssh -p 2222 -L 3389:192.168.1.99:3389 …
devops hosting ssh
An update to the email_verifier gem has been released
I have just released a newer version of the email_verifier gem. It now supports Rails localization out of the box.
If you are one of gem’s users—you can safely update your Bundles!
With this release, the project has also gained its first contributors. Some time ago, one of gem’s users—Franscesco Gnarra has asked me about a possibility of having validation messages localized. While I was planning to do it myself—Francesco took an action and contributed to the project himself.
The project also received a pull request from another Rails developer—Maciej Walusiak. His commit provided a way to handle Dnsruby::NXDomain exceptions.
It’s great to see that our work is helpful for others. If you’d like to contribute yourself—I invite you to do so.
Email verifier at GitHub: https://github.com/kamilc/email_verifier
email open-source ruby rails
A review of The Rails 4 Way
With a brand new project on the horizon (and a good candidate for Ruby on Rails 4 at that), I thought it would be a productive use of my time to bone up on some of the major differences introduced with this new version. My goal was to trade a little research for as many precluded that’s-not-how-we-do-it-anymore-500-errors as I could when fleshing out my first scaffold.
With this goal in mind, I purchased a copy of The Rails 4 Way by Obie Fernandez, Kevin Faustino, and Vitaly Kushner. Considering the free-nature of everything else Rails related, I will admit to a slight aversion to paying money for a Rails book. For those of you out there with similar proclivities, I felt compelled to share my experience.
The Rails 4 Way presents itself not as a tutorial of Ruby on Rails, but as “a day-to-day reference for the full-time Rails developer.” The tone of the book and the depth of information presented hints that the authors don’t want to teach you how to write Ruby on Rails applications. They want to share insight that will help you write better Ruby on Rails applications. Much of this is accomplished by fleshing out—utilizing a plentiful source of examples and snippets—the methods and …
books rails
How to Enable MySQL Event Scheduler
You may think that you already know what’s the opposite of “DISABLED”, but with MySQL Event Scheduler you’ll be wrong.
In fact MySQL Event Scheduler may have three different states[1][2]:
DISABLED - The Event Scheduler thread does not run [1]. In addition, the Event Scheduler state cannot be changed at runtime.
OFF (default) - The Event Scheduler thread does not run [1]. When the Event Scheduler is OFF it can be started by setting the value of event_scheduler to ON.
ON - The Event Scheduler is started; the event scheduler thread runs and executes all scheduled events.
So if you’re going to find it in the DISABLED state and instinctively set it to ENABLED you’ll end up with a non-starting MySQL daemon.
Be warned and stay safe out there!
[2]: When the Event Scheduler is not running does not appear in the output of SHOW PROCESSLIST
database mysql
Testing Your Imagination
The usual blog post follows a particular format:
“I learned something new, as part of a task that I succeeded at. Here’s what I did, here’s why it worked so well, thank you for reading.”
This one’s a little different. I made a mistake, it seemed like a pretty simple thing, and then it got me thinking about why I (and in general, we software types), fall into that mistake, and how hard it is to correct.
Here’s the background: I was working on a very small bit of code that was supposed to check a ZIP code and do one of two things. The test was, in Perl,
$zip =~ /^94|95/
Screetch!
Perhaps you have already spotted the bug. Don’t feel so smug just yet. The particulars here are vital to understanding my point, but the bug could have been something more complex, or even simpler, and I am willing to bet a cubic yard of virtual cash that you have made equally embarrassing errors. I’m just more willing to talk about mine, that’s all.
Back to our tale. I wrote that mistaken bit of code (and worse, it’s not the first time I’ve made that mistake in code), and then I proceeded to test it.
- Set $zip to ‘12345’, doesn’t match, no false positive. Check!
- Set $zip to …
testing
Using JavaScript in PostgreSQL
This time I will describe two things: installing a new extension using pgxn and using JavaScript for writing a PostgreSQL stored procedure.
The last time I was describing a couple of nice features of the incoming PostgreSQL 9.3, I wrote about merging JSONs in Postgres using a stored procedure written in Python. In one of the comments there was a suggestion that I should try using JavaScript for that, as JSON is much more native there.
So let’s try JavaScript with PostgreSQL.
Installing PL/V8
PL/V8 is a PostgreSQL procedural language powered by V8 JavaScript Engine. This way we can have JavaScript backed, something funny which could be used to create something like NoSQL database, with JavaScript procedures and storing JSON.
To have this procedural language, you need to install it as a separate extension. This can be done with system packages, if your system provides them. For Ubuntu, which I use, there are packages ready, however I use PostgreSQL compiled from source, and I keep it in my local directory, so I had to install it in a little bit different way.
I keep my PostgreSQL in ~/postgres directory. The ~/postgres/bin directory is added to environmnent $PATH variable. It is …
javascript postgres
Copying Rows Between PostgreSQL Databases
A recurring question is: “how can I copy a couple of rows from one database to another”? People try to set up some replication, or dump entire database, however the solution is pretty simple.
Example
For this blog post I will create two similar tables, I will be copying data from one to another. They are in the same database, but in fact that doesn’t matter, you can use this example to copy to another database as well. Even on another server, that’s enough to change arguments for the psql commands.
The tables are:
test=# CREATE TABLE original_table (i INTEGER, t TEXT);
CREATE TABLE
test=# CREATE TABLE copy_table (i INTEGER, t TEXT);
CREATE TABLE
Now I will insert two rows, which I will copy later to the “copy_table”.
test=# INSERT INTO original_table(i, t) VALUES
(1, 'Lorem ipsum dolor sit amet'),
(2, 'consectetur adipiscing elit');
INSERT 0 2
test=# SELECT * FROM original_table ;
i | t
---+-----------------------------
1 | Lorem ipsum dolor sit amet
2 | consectetur adipiscing elit
(2 rows)
test=# SELECT * FROM copy_table;
i | t
---+---
(0 rows)
The Solution
Of course I can set up replication, which is too much effort for ad hoc copying two …
postgres
Mooving to the Mobile Web
With the rise of the myriad of mobile phones, tablets and other devices that are connected to the internet, the potential users for a given website have both increased in number and morphed in their needs in terms of a user experience. As anyone who has attempted to use a website not designed for a mobile phone browser with frantic pinch-zooms to find a tiny page control, right next to four other controls that do something totally different in a menu, can attest this is really not ideal.
And meanwhile from the other perspective, for web developers, the notion of a fragmented user base over everything from a desktop PC with a modern browser to an embedded PC built into my new LCD TV needing to view your pages gracefully can be a scary prospect. The thought of maintaining independent versions of your web infrastructure that fit each of these major use cases would likely scare everyone in your company, especially the finance people cutting all the checks.
So what is a company facing this new reality of the modern web to do? One particular solution can help to alleviate one of the more troublesome issues with new devices browsing the Internet, mobile phone display. While the phones …
browsers mobile