Posts tagged with “programming”
Sharing user credentials between MySQL Servers with MySQL Cluster
Andrew Morgan has a great post up about a new feature in MySQL Cluster 7.2 that alleviates a pain point I've encountered in the past. Andrew explains,
The Developer Release for MySQL Cluster 7.2 includes a new feature that allows the system data required for checking user access to be shared amongst all of your MySQL Servers. By default all of the tables holding these credentials are stored in MyISAM and so are local to that MySQL Server.This can become painful to manage – every time you want to create a new user or change their permissions you need to repeat it on every server, miss one out and the user won’t be able to access that server (or will still be able to access it after you withdraw their privileges).
Head over and check it out, and subscribe to my MySQL Cluster bundle on Google Reader!
MySQL Cluster: Generating Partition Reports
If you're using MySQL Cluster and have recently added a nodegroup, you can use the following code to generate a report of what tables are currently partitioned across the nodes as you apply ALTER ONLINE TABLE ... REORGANIZE PARTITION to them to get them partitioned:
select count(p.table_name) as partitions, p.table_schema, p.table_name from tables t join partitions p on (t.table_schema=p.table_schema and t.table_name=p.table_name) where t.engine='ndbcluster' group by p.table_schema, p.table_name order by partitions desc;
You'll get a nice clean report of all your tables, what schema they belong to, and how many partitions they have. Use in combination with my method of finding the largest tables in MySQL and you'll ensure smooth growth of your cluster!
Find Largest Tables in MySQL
If you're trying to find what tables in your MySQL deployment are consuming the most amount of space, you can use the following query to find this information directly from the information schema.
SELECT CONCAT(table_schema, '.', table_name), CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows, CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA, CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx, CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size, ROUND(index_length / data_length, 2) idxfrac, engine FROM information_schema.TABLES ORDER BY data_length + index_length DESC LIMIT 25;
You'll get a list of the top 25 tables by total size (index size + data size), how many rows they have, and the engine they are using to be stored. Being able to see what engine is being used is especially helpful when running MySQL Cluster.
Auto-Dim Your Display at Night [Linux]
If you're at all like me, you often find yourself tapping away late at night on some project that you just need to hammer out those last few lines before you get to bed. Inevitably, that just doesn't happen.
So, I came up with the following solution subtly remind me that I really should be going to sleep (or hey, at least make the LCD easier on my eyes while I'm working!):
Edit the crontab for your root user using crontab -e. Add the following:
0 22 * * * echo -n "0" > /proc/acpi/video/VGA/LCD0/brightness # dims LCD to 0% at 10 PM
0 7 * * * echo -n "100" > /proc/acpi/video/VGA/LCD0/brightness # brightens LCD to 100% at 7 AM (all-nighter time!)
You can test either of these commands from the command line directly; you'll also need to make sure the path to your LCD's brightness setting is correct.
Fixing Textareas with Padding
Ever run into an issue where you need a <textarea> to have a width of 100% and some non-zero padding?
Use this:
textarea {
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
}
Problem solved.
Display Foursquare Badges in Chyrp without using Javascript
If you notice, I currently display my Foursquare badges over in the right hand side. I'm not sure about how long I'll display them specifically, so here's a screenshot:

I recently received an email inquiring about how I accomplished this. Well, since I use Chyrp, here's how I did it:
- In includes/controller/Main.php, add the following, somewhere around line 715 (immediately after $this->context["sql_queries"] =& SQL::current()->queries;):
// BEGIN Foursquare Badges
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, "http://api.foursquare.com/v1/user.json?badges=1");curl_setopt($cURL, CURLOPT_HEADER, 0);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($cURL, CURLOPT_USERPWD, "your@email.com:your_password_here");$strPage = curl_exec($cURL);
curl_close($cURL);$foursquare = json_decode($strPage);
$badges = $foursquare->user->badges;
foreach ($badges as $badge) {
$this->context['foursquare_badges'] .= '<img src="'.$badge->icon.'" title="'.$badge->description.'" />';
}
// END Foursquare Badges - In themes/your_theme_name/content/sidebar.twig, wherever you want to display your foursquare tags, simply add:
<div>
<h1>Foursquare Badges</h1>
$foursquare_badges
</div></code>You can display this wherever you like, in any part of your Chyrp template.
Be aware that this requires PHP's CURL module. I encourage you to enable Chyrp's caching module as well, so every page load does not incur a single API request (I have a feeling that they probably won't appreciate it). The benefit of this is that your Foursquare badges will now be output by your server, so they are both indexable by search engines and degrade very gracefully when the client doesn't have Javascript enabled (NoScript users, particularly).
Enjoy!
RSS is back, or "a brief history of EricMartindale.com"
Hello there, adoring internet-stalkers! (I'm kidding. ~_~) You may have noticed (if you were loyal, that is ;)) that my Feedburner-powered RSS Feed has been lacking in activity lately. There's a reason for that.
Recently, I got rid of WordPress and Sweetcron in favor of a new CMS platform, Chyrp. I had been running Wordpress for a long time, using it to share my thoughts with the general internet populace. However, it had become a bit of a chore to maintain, and it really felt like duplicate work on top of all the other content-generation I was already performing (i.e., forum posts, blog comments, Last.fm "Loved" Tracks, Google Reader shared items, etc.), so I began to look for a way to aggregate this content into a central place.
For a while, FriendFeed served this purpose well, but I didn't like the lack of control I had over the source. Facebook also filled part of this gap (and it still does, to a point), and they've even purchased FriendFeed, but I was looking for something quite a bit more customizable and self-hosted. Through various referrals, I came across Yongfook's Sweetcron project which was a new platform designed specifically for this new thing they called, *le gasp*, "Lifestreaming".
However, after fighting with Sweetcron and its aggregation methods, particularly its lack of support for various service feed formats; I decided to look into something else. Initial searches landed me upon Tumblr, who had conveniently announced a feature that syncs comments across multiple services (or aggregates). Sadly, I didn't want to get back into a world where all my code was hosted by someone else, and I had no control over it. I kept Sweetcron running on my site under lifestream/, but I continued searching for a better solution.
I then stumbled across Bazooka, which was billed as "the first free PHP tumblelog engine". Thanks to Bazooka developer Evan Walsh, who alerted me to a more up-to-date and current replacement called Chyrp. And I was sold. I immediately spent a few hours converting my existing content from WordPress and SweetCron over to a test installation of Chyrp, and then took the next night changing my site structure and 301'd all my old links to the new URLs.
That's where EricMartindale.com stands today. I've spent a few weeks getting my stream set up the way I want it, and I'm turning the RSS feed back on. Posts should begin flowing into your RSS reader very shortly. Post comments, feedback, and questions here!
Edit 10:13 PM EST: It looks like Feedburner is having some trouble parsing my new RSS content. You can subscribe to my direct feed and it will always work.
Edit 10:58 PM EST: I've fixed the problem and committed the patch to GitHub.