Skip to content

Instantly share code, notes, and snippets.

/*
* CakePHP Model Snippet
* Validates an email address and checks that it doesn't already exist in the database
*/
var $validate = array(
'email' => array(
'form' => array(
'rule' => 'email',
'message' => 'Please enter a valid email address',
'allowEmpty' => false,
@igniteflow
igniteflow / default-select-cakephp.php
Created November 12, 2010 15:09
Set a default value on a select form element in CakePHP
echo $form->input('field_name', array(
'type' => 'select',
'options' => $arrayOfOptions, // typically set from $this->find('list') in controller
'label'=> 'Label name here',
'value' => $arrProjectLeaderDetails['id'], // specify default value
'escape' => false, // prevent HTML being automatically escaped
'error' => false,
'class' => 'input_select_medium'
));
@igniteflow
igniteflow / gmail-style-button.css
Created November 17, 2010 13:34
gmail style button
#gmail {
border-radius: 3px;
-moz-border-radius: 3px;
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ddd));
background: -moz-linear-gradient(top, #fff, #ddd);
border: 1px solid #bbb;
}
@igniteflow
igniteflow / fb:tabs
Created December 10, 2010 10:36
Facebook fb:tab style without the overhead of the <fb:serverfbml> call
/* css */
div#fb-tab {
border-bottom: 1px solid #898989;
}
div#fb-tab ul {
padding: 4px;
}
div#fb-tab li {
background-color: #6D84B4;
border: 1px solid #36588F;
/* match a string at the beginning of string */
SELECT 'Test' REGEXP '^The'; -- 0
SELECT 'The Test' REGEXP '^The'; -- 1
/* if a name is not prefixed with 'The ' then add it */
UPDATE [table]
SET Name = CONCAT('The ', TRIM(Name))
WHERE Name NOT REGEXP '^The'
/* copy a column from one table to another */
@igniteflow
igniteflow / bash snippets
Created May 10, 2011 15:18
Some useful bash commands
# replace all occurrences of day in file old with night, and write to file
# new. from http://www.grymoire.com/Unix/Sed.html#uh-0
sed s/day/night/ <old >new
@igniteflow
igniteflow / rename.py
Created September 19, 2011 16:41
Python script to rename files in directory, transforming spaces to hyphens and the chars to lowercase
import os
"""
Renames the filenames within the same directory to be Unix friendly
(1) Changes spaces to hyphens
(2) Makes lowercase (not a Unix requirement, just looks better ;)
Usage:
python rename.py
"""
@igniteflow
igniteflow / binary_upload.py
Created September 23, 2011 13:56
Python binary string compatible with Java byte array (as used in SOAP web services)
import base64
"""
Some useful functions for interacting with Java web services from Python.
"""
def make_file_java_byte_array_compatible(file_obj):
"""
Reads in a file and converts it to a format accepted as Java byte array
:param file object
@igniteflow
igniteflow / suds_exception_catcher.py
Created September 23, 2011 13:59
An exception catcher for SOAP web service calls made with the SUDS Python library
def try_except(fn, *args):
"""
A decorator to catch suds exceptions
Simply add @try_except to the client call function
"""
def wrapped(*args):
try:
fn(*args)
except suds.WebFault as detail:
return detail
@igniteflow
igniteflow / stopwatch.py
Created September 30, 2011 09:42
A simple stopwatch implemented in Python
import datetime
class Timer(object):
"""A simple timer class"""
def __init__(self):
pass
def start(self):
"""Starts the timer"""