Skip to content

Instantly share code, notes, and snippets.

@tsnoad
tsnoad / gist:460942
Created July 2, 2010 04:46
soap interface to sugarcrm
<?php
// set up options array
$options = array(
"location" => 'http://192.168.25.28/soap.php',
"uri" => 'http://192.168.25.28',
"trace" => 2
);
// connect to soap server
@tsnoad
tsnoad / gist:466365
Created July 7, 2010 06:02
questions for evan
<?
//just say i have an object without __set() defined...
//will this work?
$foo->squiggle = "zebra";
//now just say the set function is defined like this:
function __set($name, $value) {
var_dump($name, $value);
@tsnoad
tsnoad / MADNESS!.php
Created July 9, 2010 06:30
php's __get __set crazyness
<?php
//Define a simple class
class Foo {
//run this whenever a variable of this class is set
function __set($name, $value) {
//store the value we're setting in a completely arbitrary place
$this->morp = $value;
}
<?
//tabular.php line 2856
case "editsquidconstraint":
$output->title = "Edit Constraint";
$output->title_desc = "";
$output->data .= Tabular_view::view_editconstraint($blah);
break;
@tsnoad
tsnoad / gist:614667
Created October 7, 2010 06:44
insert days into a psql database
#!/bin/bash
#As reconcile.php runs, it adds entries to invoice, receipt, etc. tables.
#The timestamp fields in these tables reference the dw_timestamp table
#So, we need to add every conceivable date to dw_timestamp
#back to 1900 should be enough ^_^
#set a variable to use as an iteration counter
export i=0;
@tsnoad
tsnoad / gist:2642087
Created May 9, 2012 05:25
SSHA password hashing. this format is used by OpenLDAP to store passwords
<?
function make_salt($salt_size=32) {
//list of possible characters from which to cerate the salt
$sea = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
//how many possible characters are there
$sea_size = strlen($sea);
$salt = "";
@tsnoad
tsnoad / gist:2642139
Created May 9, 2012 05:33
simple checking and correction of australian and international phone numbers
<?
function checkPhone($int_dial_code, $area_code, $local_number) {
//try to check and reformat australian numbers
if ($int_dial_code == "61") {
//combine the area code and local number
$full_phone = $area_code.$local_number;
//strip spaces and hyphens
$full_phone = str_replace(array(" ", "-"), "", $full_phone);
@tsnoad
tsnoad / year_to_finyear.sql
Last active December 14, 2015 00:48
get financial year from a date in oracle
with dates as (
select sysdate-240 as sometime from dual
union select sysdate-180 as sometime from dual
union select sysdate-120 as sometime from dual
union select sysdate-60 as sometime from dual
union select sysdate as sometime from dual
union select sysdate+60 as sometime from dual
union select sysdate+120 as sometime from dual
union select sysdate+180 as sometime from dual
union select sysdate+240 as sometime from dual
<?php
if ($_FILES['userfile']['size'] > 5 * 1024 * 1024) {
$error = 'File is too large.';
@unlink($_FILES['userfile']['tmp_name']) || $error .= $php_errormsg;
}
@tsnoad
tsnoad / gist:6518408
Created September 11, 2013 01:47 — forked from e0da/gist:1989787
#!/usr/bin/env ruby
require 'base64'
require 'digest'
# get 16 random hex bytes
#
def new_salt
16.times.inject('') {|t| t << rand(16).to_s(16)}
end