check_postgres meets pgbouncer
Recently the already well-known PostgreSQL monitoring tool check_postgres gained an ability to monitor pgbouncer, the PostgreSQL connection pooling daemon more closely. Previously check_postgres could verify pgbouncer was correctly proxying connections, and make sure its settings hadn’t been modified. The pgbouncer administrative console, reports many useful pgbouncer statistics and metrics; now check_postgres can monitor some of those as well.
pgbouncer’s description of its pools consists of “client” elements and “server” elements. “Client” refers to connections coming from clients, and “server” to connections to the PostgreSQL server. The new check_postgres actions pay attention only to the pgbouncer “SHOW POOLS” command, which provides the following metrics:
- cl_active: Connections from clients which are associated with a PostgreSQL connection. Use the pgb_pool_cl_active action.
- cl_waiting: Connections from clients that are waiting for a PostgreSQL connection to service them. Use the pgb_pool_cl_waiting action.
- sv_active: Connections to PostgreSQL that are in use by a client connection. Use the pgb_pool_sv_active action.
- sv_idle: Connections to PostgreSQL that are idle, ready to …
nagios postgres
Cross Browser Development: A Few CSS and JS Issues
Coding cross browser friendly JavaScript and CSS got you down? In a recent project, Ron, David, and I worked through some painful cross browser issues. Ron noted that he even banged his head against the wall over a couple of them :) Three of these issues come up frequently in my other projects full of CSS and JS development, so I wanted to share.
Variable Declaration in JS
In several cases, I noticed that excluding variable declaration (“var”) resulted in broken JavaScript-based functionality in IE only. I typically include variable declaration when I’m writing JavaScript. In our project, we were working with legacy code and conflicting variable names may have be introduced, resulting in broken functionality. Examples of before and after:
Bad | Better |
---|---|
var display_cart_popup = function() { popup_id = '#addNewCartbox'; left = (parseInt($(window).width()) - 772) / 2; ... }; |
var display_cart_popup = function() { var popup_id = '#addNewCartbox'; var left = (parseInt($(window).width()) - 772) / 2; ... }; |
... address_display = ''; |
browsers css javascript
Simple audio playback with Yahoo Mediaplayer
Recently I had need to show a list of MP3 files with a click-to-play interface.
I came upon a very simple self-contained audio player:
<script type="text/javascript" src="http://mediaplayer.yahoo.com/js"></script>
The code to set up my links for playing was dirt-simple:
<script type="text/javascript">
var player = document.getElementById('player');
function add_to_player() {
var link = this;
player.src.replace(/audioUrl=.*/,'audioUrl=' + link.src);
return false;
}
var links = document.getElementsByTagName('A');
for (var i = 0; i < links.length; i++) {
if (links[i].src.match(/\.mp3$/)) {
links.onclick = add_to_player;
}
}
</script>
You could use various ways to identify the links to be player-ized, but I chose to just associate the links with a class, “mp3”:
<a class="mp3" href="/path/to/file.mp3">Audio File 1</a>
Obviously, if jQuery is in use for your page, you can reduce the code to an even smaller snippet.
javascript audio
Youth Debate and other client news
I want to draw attention to several of our clients who have been in the news lately:
The Youth Debate 2010 site is live and currently accepting question submissions from youth interested in hearing video responses from the DNC & RNC chairmen before the November midterm elections. It’s a simple site, developed and deployed quickly with an eye toward handling a very high amount traffic over a short period of time. We’re excited to see what questions and answers come out of the project.
Jared Loftus, entrepreneur and owner of The College District, was profiled in a recent BusinessReport.com article about his business. We’ve written about Jared’s business and some of the technical details underpinning his sites in past blog posts, including one upon launch of 4 additional sites and one comparing College District multi-site architecture to Spree.
Our client FLOR.com is a well-known retail modular carpet seller and a division of the public company Interface, Inc. We’ve been pleased to work with them to add new features to and support the operations of their ecommerce system for the past 3 years. Interface’s founder, Ray Anderson, has been on a mission to reduce negative …
clients
Git branches and rebasing
Around here I have a reputation for finding the tiniest pothole on the path to Git happiness, and falling headlong into it while strapped to a bomb …
But at least I’m dedicated to learning something each time. This time it involved branches, and how Git knows whether you have merged that branch into your current HEAD.
My initial workflow looked like this:
$ git checkout -b MY_BRANCH
(some editing)
$ git commit
$ git push origin MY_BRANCH
(later)
$ git checkout origin/master
$ git merge --no-commit origin/MY_BRANCH
(some testing and inspection)
$ git commit
$ git rebase -i origin/master
This last step was the trip-and-fall, although it didn’t hurt me so much as launch me off my path into the weeds for a while. Once I did the “git rebase”, Git no longer knows that MY_BRANCH has been successfully merged into HEAD. So later, when I did this:
$ git branch -d MY_BRANCH
error: the branch 'MY_BRANCH' is not fully merged.
As I now understand it, the history is no longer a subset of the history associated with MY_BRANCH, so Git can’t tell the two are related and refuses to delete the branch unless you supply it with -D. A relatively harmless situation, but it set off all …
git
Implementing Per Item Discounts in Spree
Discounts in Spree
For a good overview of discounts in Spree, the documentation is a good place to start. The section on Adjustments is particularly apropos.
In general, the way to implement a discount in Spree is to subclass the Credit class and attach or allow for attaching of one or more Calculators to your new discount class. The Adjustment class file has some good information on how this is supposed to work, and the CouponCredit class can be used as a template of how to do such an implementation.
What we Needed
For my purposes, I needed to apply discounts on a per Item basis and not to the entire order.
The issue with using adjustments as-is is that they are applied to the entire order and not to particular line items, so creating per line item discounts using this mechanism is not obviously straight forward. The good news it that there is nothing actually keeping us from using adjustments in this manner. We just need to modify a few assumptions.
Implementation Details
This is going to be a high-level description of what I did with (hopefully) enough hints about what are probably the important parts to point someone who wants to do something similar in the same direction. …
ecommerce ruby rails spree
SEO friendly redirects in Interchange
In the past, I’ve had a few Interchange clients that would like the ability to be able to have their site do a SEO friendly 301 redirect to a new page for different reasons. It could be because either a product had gone out of stock and wasn’t going to return or they completely reworked their url structures to be more SEO friendly and wanted the link juice to transfer to the new URLs. The normal way to handle this kind of request is to set up a bunch of Apache rewrite rules.
There were a few issues with going that route. The main issue is that to add or remove rules would mean that we would have to restart or reload Apache every time a change was made. The clients don’t normally have the access to do this so it meant they would have to contact me to do it. Another issue was that they also don’t have the access to modify the Apache virtual host file to add and remove rules so again, they would have to contact me to do it. To avoid the editing issue, we could have put the rules in a .htaccess file and allow them to modify it that way, but this can present its own challenges because some text editors and FTP clients don’t handle hidden files very well. The other issue is that even …
interchange seo
Conventions
Written and spoken communication involve language, and language builds on a lot of conventions. Sometimes choosing one convention over another is an easy way to reduce confusion and help you communicate more effectively. Here are a few areas I’ve noticed unnecessary confusion in communication, and some suggestions on how we can do better.
2-dimensional measurements
Width always comes first, followed by height. This is a longstanding printing and paper measurement custom. 8.5” x 11” = 8.5 inches wide by 11 inches high. Always. Of course it never hurts to say specifically if you’re the one writing: 8.5” wide x 11” high, or 360px wide x 140px high.
If a third dimension comes into play, it goes last: 10” (horiz.) x 10” (vertical) x 4” (deep).
Dates
In file names, source code, databases, or spreadsheets, use something unambiguous and easily sortable. A good standard is ISO 8601, which orders dates from most significant to least significant, that is, year-month-day, or YYYY-MM-DD. For example, 2010-01-02 is January 2, 2010. If you need to store a date as an integer or shave off 2 characters, the terser YYYYMMDD is an option with the same benefits but a little less readability.
For easier …
tips