Skip to content

Instantly share code, notes, and snippets.

View Oshuma's full-sized avatar

Dale Campbell Oshuma

  • @unite-us
  • Earth
View GitHub Profile
<?php
class SearchController extends AppController
{
var $name = 'Search';
var $uses = array('Address', 'LiftVendor', 'SubVendor', 'ZipCode');
/* Search by zip code. */
function zip($zip_code) {
set_time_limit(0); // Because this action could take a while...
$this->layout = false; // Used through Ajax, so don't need a layout.
@Oshuma
Oshuma / jquery.togglizers.js
Created May 7, 2009 00:54
Simple jQuery effect toggles.
// Simple jQuery effect toggles.
// Use just like the jQuery.toggle() method.
//
// $('#some-link').click(function() {
// $('#some-div').slideToggle();
// });
jQuery.fn.fadeToggle = function() {
if (this.css('display') == 'none') this.fadeIn();
else this.fadeOut();
#!/usr/bin/env python
import os
import sys
from optparse import OptionParser
global DEBUG
global APP_DIR
global CAKE_DIR
@Oshuma
Oshuma / gist:118931
Created May 27, 2009 21:48
value_or_default()
<?php
// Reason #5,671 PHP sucks balls: Can't set default array values
// (default return values for non-existing keys).
// Returns the $key's value from $array if it exists; otherwise return $default.
function value_or_default($array, $key, $default = '') {
return array_key_exists($key, $array) ? $array[$key] : $default;
}
<?php
// CakePHP does stupid shit often times.
// http://api.cakephp.org/view_source/object/#line-112
function dispatchMethod($method, $params = array()) {
if (empty($params)) return $this->{$method}();
// We only hit this if there are parameters passed ($params isn't empty).
return call_user_func_array(array(&$this, $method), $params);
}
<?php
// Rounds the given timestamp (string) up 15 minutes.
function round_timestamp($timestamp) {
$interval = 15; // minutes
$date_format = "%d-%b-%y %I:%M:%S %p %Z";
$time_array = strptime(strftime($date_format, strtotime($timestamp)), $date_format);
$minutes = $time_array['tm_min'];
$delta = $minutes % $interval;
$time_array['tm_min'] = $minutes + ($delta * ($delta < $interval / 2 ? -1 : 1));
@Oshuma
Oshuma / accordion.html
Created July 2, 2009 01:49
Simple ass jQuery accordion effect.
<!-- Add a class to the link and info elements. -->
<li>
<a class="show-info" href="#">Show The Element</a>
<div class="info" style="display: none;">
Some content here.
</div>
</li>
<!-- etc. -->
// Add the typical onclick jazz for selected links.
// (Insert your framework of choice.)
$('#tabs a').each(function(index, tab) {
$(tab).attr('onclick', '; return false;');
});
@Oshuma
Oshuma / rails.watchr.rb
Created October 4, 2009 02:31
rails.watchr.rb
def run_tests(test_type)
case test_type
when :all
system('rake test')
when /(controllers|functional)\/?/
system('rake test:functionals')
when /(models|unit)\/?/
system('rake test:units')
else
# do nothing...
@Oshuma
Oshuma / oshuma.zsh-theme
Created October 8, 2009 05:22
oshuma.zsh-theme
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[blue]%}(%{$fg[yellow]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%})%{$fg[red]%}✗✗✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})───"
PROMPT=$'\n%B%{$fg[blue]%}┌─[%b%{$fg[yellow]%}%D{%a %b %d, %I:%M:%S}%B%{$fg[blue]%}]%b
%B%{$fg[blue]%}| [%{$fg[green]%}%n%b%{$fg[white]%}@%B%{$fg[cyan]%}%m%{$fg[blue]%}]%b%{$reset_color%} - %B%{$fg[blue]%}[%b%{$reset_color%}%~%B%{$fg[blue]%}]%b
%B%{$fg[blue]%}└─[%{$fg[red]%}$%{$fg[blue]%}]$(git_prompt_info)%B%{$fg[blue]%}≫%b %{$reset_color%}'
PS2=$' %B%{$fg[blue]%}➜%b%{$reset_color%} '