Skip to content

Instantly share code, notes, and snippets.

View parhamr's full-sized avatar

Reid Parham parhamr

View GitHub Profile
@vjt
vjt / awesome-nginx.conf
Created January 31, 2011 19:43
*AWESOME* nginx configuration for Ruby/Rack web applications
#
# mmm m m mmm mmm mmm mmmmm mmm
# " # "m m m" #" # # " #" "# # # # #" #
# m"""# #m#m# #"""" """m # # # # # #""""
# "mm"# # # "#mm" "mmm" "#m#" # # # "#mm"
#
# nginx configuration For Ruby/Rack web applications
#
# Cooked up with style, care and a bit of *secret*
# nerdy spice. :-)
@knzconnor
knzconnor / 1_intro_to_subject.rb
Created February 8, 2011 07:45
A pattern for testing class methods in ruby with rspec explicit subjects
# RSpec's subject method, both implicitly and explicitly set, is useful for
# declaratively setting up the context of the object under test. If you provide a
# class for your describe block, subject will implicitly be set to a new instance
# of this class (with no arguments passed to the constructor). If you want
# something more complex done, such as setting arguments, you can use the
# explicit subject setter, which takes a block.
describe Person do
context "born 19 years ago" do
subject { Person.new(:birthdate => 19.years.ago }
it { should be_eligible_to_vote }
@jnx
jnx / rbenv-install-system-wide.sh
Created October 1, 2011 20:09
rbenv install and system wide install on Ubuntu 10.04 LTS.
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Add rbenv to the path:
@tonyc
tonyc / gist:1384523
Last active June 3, 2024 15:34
Using strace and lsof

Using strace and lsof to debug blocked processes

You can use strace on a specific pid to figure out what a specific process is doing, e.g.:

strace -fp <pid>

You might see something like:

select(9, [3 5 8], [], [], {0, 999999}) = 0 (Timeout)

@jeremy2
jeremy2 / database.yml.erb
Created March 6, 2012 23:17
Engine Yard custom Chef Recipe for generating database.yml configuration file
#
# This file should be in .../cookbooks/database/templates/default/database.yml.erb
#
<%= @environment %>:
adapter: <%= @adapter %>
database: <%= @database %>
username: <%= @username %>
password: <%= @password %>
host: <%= @host %>
@parhamr
parhamr / 0: Magento 1.12 Enterprise multi-store cluster configuration.md
Last active October 13, 2023 14:20
A highly available, fault tolerant, distributed, and load balanced LEMP cluster.
#!/bin/bash
touch -r backup.sql backup.sql.marker
while :;
do
if [[ -n $(find . -name *.sql -newer backup.sql.marker) ]];
then
echo "Backup finished at $(date)" | mailx -s 'New Backup' kyle@kyleterry.com
break
fi
#!/bin/bash
# In order for this parser to work, the file needs to be structured with
# tickets like the following:
#
# 12345678 - Some ticket title
# Action: UAT Needed.
# State: (APPROVED|PENDING|FAILED)
# Pivotal: https://www.pivotaltracker.com/s/projects/745189/stories/12345678
# Github: https://github.com/copious/Zumiez.com/pull/123
@parhamr
parhamr / Magento1.12-SQL_type_example.md
Last active December 25, 2015 17:18
MySQL 5.6.11 skips indices when given quoted INTs

Removing quotes from an INT column allows MySQL to use the index and this can reduce rows scanned by 99.997 percent. Example from Magento 1.12 on a production database; the query takes nearly a second to execute:

mysql> explain DELETE FROM `catalog_product_index_price` WHERE entity_id IN('433284', 433283)\G;
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: catalog_product_index_price
         type: ALL
possible_keys: NULL
@peterjaap
peterjaap / Mage_Catalog_Model_Resource_Url_getProduct.php
Last active May 4, 2017 06:09
Modified Mage_Catalog_Model_Resource_Url::_getProduct function. This function now contains a boolean that you can set to switch between rewriting the URL's for ALL products and rewriting only the URL's of products that are visible. Idea inspired by Alan Storm's blog on Scaling Magento - http://alanstorm.com/scaling_magento_at_copious
<?php
protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
{
$products = array();
$websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
$adapter = $this->_getReadAdapter();
if ($productIds !== null) {
if (!is_array($productIds)) {
$productIds = array($productIds);