Skip to content

Instantly share code, notes, and snippets.

@tlhl28
tlhl28 / gist:1053143
Created June 29, 2011 04:26
Simple mysql query class --- php
<?php
/**
* ======Usage=====
*
* $db = new Database("127.0.0.1","user","pwd","db1");
* $data = $db->selectDb("db2")
* ->selectTable("table1")
* ->show("column1 as no1")
* ->filter("column1 >", 0)
* ->filter("column2 LIKE", "%hello%")
@tlhl28
tlhl28 / gist:1028858
Created June 16, 2011 07:54
random number/word
<?php
function random_key($length)
{
$output='';
for ($a = 0; $a < $length; $a++) {
$output .= chr(mt_rand(48, 57));
}
return $output;
}
function random_word($length)
@tlhl28
tlhl28 / gist:1028856
Created June 16, 2011 07:53
convert STDObject to array.
<?php
function objectToArray( $object )
{
if(!is_object($object) && !is_array($object)) {
return $object;
}
if(is_object($object )) {
$object = get_object_vars( $object );
}
return array_map( 'objectToArray', $object );
@tlhl28
tlhl28 / gist:1028800
Created June 16, 2011 06:52
use triple_des(des3) in python;
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import binascii
import hashlib
import base64
import pyDes
# iv and key is hex string
iv = '3132333435363738'
@tlhl28
tlhl28 / gist:1028797
Created June 16, 2011 06:49
use triple_des(des3) in php; $iv and $key is hex string.
<?php
function PaddingPKCS7($data) {
$block_size = mcrypt_get_block_size("tripledes", "cbc");
$padding_char = $block_size - (strlen($data) % $block_size);
$data .= str_repeat(chr($padding_char),$padding_char);
return $data;
}
function fmt3DESEx($data, $key, $iv) {
@tlhl28
tlhl28 / gist:1028789
Created June 16, 2011 06:44
Soap Header Authentication --- PHP
<?php
$url = "http://localhost:8000/PortalService";
//targetNamespace
$uri = "http://localhost/partalService";
$key = "xxx";
$pwd = "xxx";
$options=array(
//'soap_version'=>SOAP_1_2,