Skip to content

Instantly share code, notes, and snippets.

@cythrawll
cythrawll / Dao.php
Last active February 7, 2019 12:38
<?php
abstract class Dao {
protected $db;
public function __construct(PDO $db) {
$this->db = $db;
}
public function setDb(PDO $db) {
$this->db = $db;
@cythrawll
cythrawll / Author.php
Last active October 7, 2015 07:48
Example of three layered Service
<?php
class Author extends Entity {
public $name;
public $penNames;
}
#include "php_sample.h"
#define CODEANGEL_NS "CodeAngel"
PHP_FUNCTION(sample_hello_world)
{
php_printf("Hello World!\n");
}
static const zend_function_entry php_sample_functions[] = {
LoadModule php5_module modules/libphp5.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
@cythrawll
cythrawll / Crypter.php
Created December 10, 2013 03:41
early idea for easy crypther
<?php
class Crypter {
public static $cipher = MCRYPT_TWOFISH;
public $key;
public $authKey;
public function __construct($key, $authKey) {
$this->key = base64_decode($key);
$this->authKey = base64_decode($authKey);
}
<?php
$str = '[0710:020602938:7041]';
switch(1) {
case preg_match('/^(\[)[A-Z0-9]{4}:(' . rand(10000,29999) . '|' . rand(50000,99999) . '):[A-z]{3}(\])(.*)+/', $str):
/* ... */
break;
case preg_match('/^(\[)[A-Z0-9]{4}:[0-9]{9}:[0-9]{4}(\])+/', $str):
/* ... */
break;
function bin2hex (s) {
// From: http://phpjs.org/functions
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// + bugfixed by: Linuxworld
// + improved by: ntoniazzi (http://phpjs.org/functions/bin2hex:361#comment_177616)
// * example 1: bin2hex('Kev');
// * returns 1: '4b6576'
// * example 2: bin2hex(String.fromCharCode(0x00));
// * returns 2: '00'
<?php
class StreamThingy {
public $fh; //this si your fopen statement
public $readFunc;
public function onRead($function) {
$this->readFunc = $function;
}
public function execute() {
<?php
class Match {
public $id;
public $challenger;
public $defender;
}
<project name>/
src/ --where you put your classes according to psr-4
tests/ -- gotta have your unit/integration/function tests yo
vendor/ -- where composer puts third party libs
public/ -- docroot