This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
class Timer(object): | |
"""A simple timer class""" | |
def __init__(self): | |
pass | |
def start(self): | |
"""Starts the timer""" |
OlderNewer