Skip to content

Instantly share code, notes, and snippets.

@ajbonner
ajbonner / rr_sluper_multi.rb
Last active December 12, 2015 08:39
Multithreaded Ruby Rogue Podcast Slurper
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
MAX_THREADS = 5
thread_pool = []
index = Nokogiri::HTML(open('http://rubyrogues.com/episode-guide/'));
@ajbonner
ajbonner / rr_sluper.rb
Created February 9, 2013 16:23
Script to pulldown all the Ruby Rogue Podcast MP3s as only the latest 50 are in their feed
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
index = Nokogiri::HTML(open('http://rubyrogues.com/episode-guide/'));
index.css('a[rel=bookmark]').each do |link|
podcast = Nokogiri::HTML(open(link['href']));
title = podcast.css('.entry-title').text
@ajbonner
ajbonner / xdebug.sh
Created January 9, 2013 20:09
A pair of bash functions to speed up enabling and disabling xdebug on debian like systems
function enable_xdebug() {
sudo sed -i'' 's/^;*//g' /etc/php5/conf.d/xdebug.ini
}
function disable_xdebug() {
sudo sed -i'' 's/^/;/g' /etc/php5/conf.d/xdebug.ini
}
@ajbonner
ajbonner / application_controller.rb
Created October 15, 2012 10:38
How not to rescue_from exceptions
class ApplicationController < ActionController::Base
# Catch all exceptions at a stretch
rescue_from Exception, :with => :handle_exceptions
private
# Handle exceptions
def handle_exceptions(e)
case e
@ajbonner
ajbonner / local.xml
Created September 3, 2012 10:38
Snippet showing how to disable Magneto's Database Logging Events
<config>
...
<global>
...
<frontend>
<events>
<controller_action_predispatch>
<observers><log><type>disabled</type></log></observers>
</controller_action_predispatch>
<controller_action_postdispatch>
@ajbonner
ajbonner / Result.php
Created August 30, 2012 08:12
Unescaped input in breadcrumbs - Magento 1.6.x Mage_CatalogSearch_Block_Result
/**
* Prepare layout
*
* @return Mage_CatalogSearch_Block_Result
*/
protected function _prepareLayout()
{
// add Home breadcrumb
$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
if ($breadcrumbs) {
@ajbonner
ajbonner / chef-from-src.sh
Created August 17, 2012 10:22
Build Chef From Source
#!/usr/bin/env bash
wget --no-check-certificate -O chef.tgz https://github.com/opscode/chef/tarball/10-stable
mkdir chef-stable
tar zxf chef.tgz --strip-components=1 -C chef-stable
cd chef-stable/chef
gem build chef.gemspec
/opt/ruby/bin/gem install chef --no-ri --no-rdoc
cd ../../
rm -rf chef-stable
@ajbonner
ajbonner / adminhtml.xml
Created August 11, 2012 11:32
Disable Magento Adminhtml Menu Option
<?xml version="1.0"?>
<!-- Disable Catalog Price Rules Menu Entry -->
<config>
<menu>
<promo translate="title" module="catalogrule">
<children>
<catalog translate="title" module="catalogrule">
<depends>
<module>Disable_This_Module</module>
@ajbonner
ajbonner / core_file_storage_fix.sql
Created August 16, 2011 17:12
Fix for magento 1.5.x base table or view not found 'core_file_storage'
DROP TABLE IF EXISTS core_file_storage;
CREATE TABLE IF NOT EXISTS core_file_storage (
`file_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`content` LONGBLOB NOT NULL,
`upload_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`filename` varchar(255) NOT NULL DEFAULT '',
`directory_id` int(10) unsigned DEFAULT NULL,
`directory` varchar(255) DEFAULT NULL,
PRIMARY KEY (`file_id`),
UNIQUE KEY `IDX_FILENAME` (`filename`, `directory`),
@ajbonner
ajbonner / tablesize_report.sql
Created July 14, 2011 14:21
Get a list of large tables within a mysql database
SELECT count(*) tables,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') data,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES
WHERE table_schema = 'database-name'
ORDER BY data_length+index_length DESC LIMIT 10;