Skip to content

Instantly share code, notes, and snippets.

@jayzeng
jayzeng / namedparameters.php
Created January 30, 2013 06:51
how to do named parameters
<?php
// pdo
$params = array(':username' => 'John', ':email' => $mail );
$pdo->prepare('
SELECT * FROM users
WHERE username = :username
AND email = :email');
$pdo->execute($params);
@jayzeng
jayzeng / dbconnection.php
Created January 30, 2013 06:44
dbconnection
<?php
// pdo
$pdo = new PDO("mysql:host=localhost;dbname=database", "username", "password");
// mysqli, oo way
$mysqli = new mysqli('localhost', 'username', 'password', 'database');
// mysqli, procedural
$mysqli = mysqli_connect('localhost', 'username', 'password', 'database');
@jayzeng
jayzeng / browser editor.js
Created January 30, 2013 05:18
ace editor
data:text/html, <style%20type%3D"text%2Fcss">%23e%7Bposition%3Aabsolute%3Btop%3A0%3Bright%3A0%3Bbottom%3A0%3Bleft%3A0%3B%7D<%2Fstyle><div%20id%3D"e"><%2Fdiv><script%20src%3D"http%3A%2F%2Fd1n0x3qji82z53.cloudfront.net%2Fsrc-min-noconflict%2Face.js"%20type%3D"text%2Fjavascript"%20charset%3D"utf-8"><%2Fscript><script>var%20e%3Dace.edit("e")%3Be.setTheme("ace%2Ftheme%2Fmonokai")%3Be.getSession().setMode("ace%2Fmode%2Fphp")%3B<%2Fscript>
<?php
class InvalidIpFormatException extends \InvalidArgumentException {}
class InvalidIpRangeException extends \InvalidArgumentException {}
class IpV4Validator
{
private $_ip;
@jayzeng
jayzeng / errorhandler.php
Created January 23, 2013 08:31
global error handler
<?php
// custom error handler to suppress errors
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
return '';
}
set_error_handler('exception_error_handler');
?>
<?php
class IpV4Validator
{
private $_ip;
public function __construct( $ipAddr ) {
$this->_ip = $ipAddr;
}
<?php
// Duck typing
class Car
{
public function run() {
return 'car is running';
}
}
@jayzeng
jayzeng / repo.py
Last active December 11, 2015 02:59
repo set up
#!/usr/bin/python
import subprocess
devs = {}
devs['jayzeng'] = 'jayzeng'
devs['davidremm'] = 'davidremm'
devs['beau'] = 'beauhoyt'
devs['yanmei'] = 'wyiemay'
devs['niek'] = 'nieksand'
devs['lee'] = 'leehasoffers'
#!/usr/bin/env ruby
require 'net/telnet'
cache_dump_limit = 100
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3)
slab_ids = []
localhost.cmd("String" => "stats items", "Match" => /^END/) do |c|
matches = c.scan(/STAT items:(\d+):/)
slab_ids = matches.flatten.uniq
end
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.