Skip to content

Instantly share code, notes, and snippets.

@timmatheson
timmatheson / start_and_end_dates_from_week_number.rb
Created November 3, 2010 19:44
Takes a week number and returns a range of dates occurring during the given week.
def start_and_end_dates_from_week_number(number)
end_time = Time.now.at_beginning_of_year.utc + (number).weeks
((end_time-1.week)..end_time)
end
@timmatheson
timmatheson / jquery_progress_bars.html
Created January 4, 2011 06:33
jQuery Animated Progress Bar Examples
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>jQuery Progress Bars</title>
<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$(".progress-bar").each(function(){
#!/usr/bin/ruby
# strips anchor text from $stdin
# usage
# cat links.txt | ruby /usr/bin/link_parser
# Fetch input and strip anchor text.
while line = $stdin.gets do
puts line.to_s.gsub(/<a[^>]*>|<\/a>/,'')
end
@timmatheson
timmatheson / php-compile.sh
Created April 5, 2011 19:58
PHP 5.2.17 on Snow Leopard configuration options.
#!/usr/bin bash
sudo CFLAGS='-arch i386' CCFLAGS='-arch i386' CXXFLAGS='-arch i386' sudo ./configure --prefix=/usr/local --with-apxs2=/usr/sbin/apxs --with-ldap=/usr --with-kerberos=/usr --enable-cli --with-zlib-dir=/usr --enable-exif --enable-ftp --enable-mbstring --enable-mbregex --enable-sockets --with-iodbc=/usr --with-curl=/usr --with-config-file-path=/etc --sysconfdir=/private/etc --with-mysql-sock=/var/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --with-openssl=/usr --with-xmlrpc --with-xsl=/usr --without-pear --with-libxml-dir=/usr --with-iconv=/usr/local --with-pdo-mysql=/usr/local/mysql/bin/mysql_config --with-gd --with-jpeg-dir=/opt/local --with-png-dir=/opt/local --with-freetype-dir=/opt/local --with-mcrypt=/opt/local;
sudo make;
sudo make install;
@timmatheson
timmatheson / config.xml
Created May 12, 2011 22:15
module settings
<?xml version="1.0"?>
<config>
<modules>
<Mezzmer_HomeTryOn>
<version>1.0.0</version>
</Mezzmer_HomeTryOn>
</modules>
<global>
<blocks>
<!-- Block Section -->
@timmatheson
timmatheson / images.js
Created July 1, 2011 16:54
Example of hiding some images by class name using jquery.
$j("img.women").hide(); // Hide Women Class Images
$j("img.men").hide(); // Hide Men Class Images
@timmatheson
timmatheson / test.phtml
Created July 1, 2011 17:16
hide certain images based on magento current category
<script type='text/javascript'>
$j(document).ready(function(){
<?php
if( isset( Mage::registry('current_category')->getName() )){
echo strtolower( Mage::registry('current_category')->getName() ) == 'mens' ? "$j('img.womens').hide();" : "$j('img.mens').hide();";
}
?>
});
</script>
@timmatheson
timmatheson / donations_revenue.sql
Created July 1, 2011 17:24
capture 30 day revenue for order donations
select donations.organization, (sum(orders.grand_total) * (3 / 100)) from sales_flat_order as orders
inner join donations on donations.order_id = orders.increment_id
where orders.created_at between adddate(curdate(), interval -30 day)
and curdate()
group by donations.organization;
# This file is part of the OpenWISP User Management System
#
# Copyright (C) 2010 CASPUR (wifi@caspur.it)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# simple method to allow you to underscore all keys in a hash
class Hash
def underscore
self.each_key{ |k| self[k.to_s.underscore] = self[k]; self.delete(k) }
end
end