Skip to content

Instantly share code, notes, and snippets.

<?php
class TimezonesHelper extends AppHelper {
function show() {
$zones = array(
'Pacific/Apia' => 'Apia, Upolu, Samoa', // UTC-11:00
'US/Hawaii' => 'Honolulu, Oahu, Hawaii, United States', // UTC-10:00
'US/Alaska' => 'Anchorage, Alaska, United States', // UTC-09:00
'US/Pacific' => 'Los Angeles, California, United States', // UTC-08:00
'US/Mountain' => 'Phoenix, Arizona, United States', // UTC-07:00
@squarepegsys
squarepegsys / grepJars.sh
Created June 17, 2011 19:18
grepJars -- how to find a class in a directory of jar files
# handiest shell function/alias I have ever written
function grepJars() {
for x in `find . -name "*.jar"`; do
echo $x
unzip -l $x|grep $1
done
}
@squarepegsys
squarepegsys / chunker.py
Created August 31, 2011 15:31
Get Python list in chunks
#!/usr/bin/env python
import unittest
## get a list in chunks
## if we run out of items in the list, start again from the beginning
class Chunker(object):
@squarepegsys
squarepegsys / gist:1293054
Created October 17, 2011 16:46
how our Camel routes file starts
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<import resource="classpath*:/META-INF/spring/itb-master-route.xml"/>
<import resource="classpath*:/META-INF/spring/jms-inbound-beans.xml"/>
<import resource="classpath*:/META-INF/spring/itb-beans.xml"/>
<camel:routeContext id="jmsInboundRoutes">
@squarepegsys
squarepegsys / onHashCodeAndEquals.markdown
Created December 1, 2011 01:25
Some thoughts on .hashCode and .equals in Java

Thoughts about .equals and .hashCode

Here is a little context: we were tracking down a memory leak in our application and saw this big HashMap in the dump file. The HashMap was from ehcache. The problem was that the objects that were used as the key did not implement .hashCode. Oops. We used Eclipse's generated .equals and .hashCode to get us by and that got us through the heat of the moment.

So, today, a couple of developers were on a PMD/FindBugs hunt and,

@squarepegsys
squarepegsys / sieve.scala
Created September 4, 2012 15:21
My first scala experiment -- The Sieve of Eratosthenes
/*
Whenever I start learning a language, the first program I try
to write is an implementation of The Sieve of Eratosthenes.
It requires you to work with lists, which I think is
very important for any language.
This is my first stab of the Sieve in Scala.
*/
@squarepegsys
squarepegsys / parts_parser.scala
Created September 5, 2012 20:07
A parser in Scala
/*
This is a version of a parser I wrote in Python for
www.powerhousetoolparts.com. After reading about Case Classes and Pattern Matching,
I was wondering how nice it would be in Scala. And, while I don't
cover all the edge cases, it's nice indeed.
The file has records like:
FLE100102 WRENCH 14MM EACH(ACTIVE)S2650FLEX PARTS 5.830 5.830FLEX 76.00
FLE100110 SPANNER WRENCH EACH(ACTIVE)S2650FLEX PARTS 5.500 5.500FLEX 7.00
@squarepegsys
squarepegsys / StringCalcTest.scala
Created September 10, 2012 14:29
My attempt of the String Kata in Scala
import org.scalatest.FunSuite
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.BeforeAndAfter
import com.squarepegsystems.StringCalculator
// Tests for the String Kata
// see http://osherove.com/tdd-kata-1/
@squarepegsys
squarepegsys / readonlyadmin.py
Created November 13, 2012 19:52
ReadOnlyAdmin
## adopted from http://gremu.net/blog/2010/django-admin-read-only-permission/
class ReadOnlyAdmin(admin.ModelAdmin):
"""
"""
def has_add_permission(self, request,obj=None):
"""
Arguments:
@squarepegsys
squarepegsys / .gitignore
Last active December 14, 2015 15:39 — forked from karmi/.gitignore
.DS_Store
*.log
Gemfile.lock