Skip to content

Instantly share code, notes, and snippets.

@justinkelly
justinkelly / simple_encrypt.php
Created September 16, 2011 13:47
Simple mcrypt encrypt & decrypt functions for PHP
<?php
$salt ='whatever_you_want'
function simple_encrypt($text)
{
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
}
function simple_decrypt($text)
@justinkelly
justinkelly / seconds_since.php
Created September 19, 2011 04:04
Get the number of seconds since Jan 1, 0001 in PHP
<?php
/*
* Very simple way to get the number of seconds from Jan 1, 0001 or any other date
* the normal date/time functions only work from 1 Jan 1970
* Requires PHP 5.3 or above
* Start: must be in YYYY-MM-DD format
* End: must be in YYYY-MM-DD format
*/
@justinkelly
justinkelly / max_key_in_array.php
Created September 19, 2011 12:00
To get the largest key in an array : PHP
<?php
/*
* To get the largest key in an array
*/
$array = array( 0 => 'first', 1=> 'second', /* ... */ 99 => 'nth' );
$max_key = max( array_keys( $array ) ); // 99
?>
@justinkelly
justinkelly / Model-Db-Table-Deals.php
Created October 19, 2011 00:24
Populate a Zend Form Multiselect
<?php
public function addDeal($form)
{
$location ="";
foreach($form->getElement('location_id')->getValue() as $key=>$value)
{
if($key==0)
{
$location = $value ;
@justinkelly
justinkelly / REAMDE.txt
Created November 17, 2011 20:53
Use content from Wordpress in another page
Install this plugin http://wordpress.org/extend/plugins/ps-disable-auto-formatting/
It will disable the way WP auto formats your html in the page content editor
@justinkelly
justinkelly / db_refresh.sh
Created December 30, 2011 03:21
Simple MySQL - db refresh script - delete tables and import .sql
#!/bin/bash
MUSER="MYSQL_USER"
MPASS="MYSQL_PASSWORD"
MDB="MYSQL_DB"
FILE="/path/to/sql/to/import.sql"
# Detect paths
MYSQL=$(which mysql)
AWK=$(which awk)
@justinkelly
justinkelly / cron.php
Created January 4, 2012 01:40
SimpleInvoices cron.php file
<?php
#include/class/cron.php
class cron {
public $start_date;
public $domain_id;
public function insert()
@justinkelly
justinkelly / .htaccess
Created January 5, 2012 12:19
Exclude file/directories/urls from Apache .htaccess password protected site
AuthType Basic
AuthName "Auth Required"
AuthUserFile /path/to/.htpasswd
Require valid-user
# allow public access to the following resources
SetEnvIf Request_URI "(path/to/directory/)$" allow
SetEnvIf Request_URI "(path/to/file\.phpt)$" allow
SetEnvIf Request_URI "(util)$" allow
Order allow,deny
Allow from env=allow
@justinkelly
justinkelly / randomCode.php
Created January 20, 2012 11:51
Simple PHP function to generate a random apha-numeric code with only readable characters
<?php
/*
* Simple PHP function to generate a random apha-numeric code with only readable characters
*/
function randomCode($length=4) {
/* Only select from letters and numbers that are readable - no 0 or O etc..*/
$characters = "23456789ABCDEFHJKLMNPRTVWXYZ";
@justinkelly
justinkelly / desktop.default.css
Created January 30, 2012 22:24
Workflowy.com: Completed hidden css problem
/*
* Original CSS
* - which caused this issue in Chrome on Windows -> http://minus.com/mbbbT3JZrH
*/
.showCompletedButton {
padding: 8px 10px;
width: 118px;
}