Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View hmic's full-sized avatar

Hans-Joachim Michl hmic

  • Living in China/Shenzhen, from Germany, Hessen, nearby Frankfurt/Main
View GitHub Profile
@hmic
hmic / hash.h
Created January 25, 2012 14:03
php hash function "from the source"
/*
* DJBX33A (Daniel J. Bernstein, Times 33 with Addition)
*
* This is Daniel J. Bernstein's popular `times 33' hash function as
* posted by him years ago on comp.lang.c. It basically uses a function
* like ``hash(i) = hash(i-1) * 33 + str[i]''. This is one of the best
* known hash functions for strings. Because it is both computed very
* fast and distributes very well.
*
* The magic of number 33, i.e. why it works better than many other
for( i = 0; i < MAX_STRING_LEN; i++ ) {
bk = 0;
in[0] = 0;
for( n = i; n >= 0; n-- ) {
in[n] = 1;
}
len = strlen(in);
for( j = len; j >= 0; j-- ) {
for( n = 1; n < 255; n++ ) {
in[j] = n;
@hmic
hmic / abtest.php
Last active August 29, 2015 14:03
A-B Test (call it benchmark) to show that php evaluates operands from left to right and does not at all evaluate operands, if the condition cannot be met anymore
define('ITERATIONS', 1000000);
define('ROUNDS', 10);
function original($singular, $args = null) {
if ($args === null) {
return true;
} else {
return false;
}
}
@hmic
hmic / Vagrantfile
Created August 18, 2014 12:42
Change memory and cpus for your vagrant vm
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
end
<?php
$string ="1b5b33366d436f6465736e69666665722e436c65616e7570207368656c6c1b5b306d20666f722043616b655048500a0a322066696c657320666f756e642e20436865636b696e67202e2e2e0a2f686f6d652f7472617669732f6275696c642f6465726575726f6d61726b2f63616b657068702d636f6465736e69666665722f74657374732f746573745f6170702f556e757365645573652f556e75736564557365457874656e6465642e7068703a0a202d20436f6f6c466f6f0a202d20536f6d654f74686572436c6173730a202d204974657261746f724974657261746f72466f6f0a202d204461746574696d650a202d204361736553656e736974697665436c6173730a3520756e75736564207573652073746174656d656e7428732920666f756e642e0a2f686f6d652f7472617669732f6275696c642f6465726575726f6d61726b2f63616b657068702d636f6465736e69666665722f74657374732f746573745f6170702f556e757365645573652f556e757365645573652e7068703a0a202d20536f6d654f74686572436c6173730a3120756e75736564207573652073746174656d656e7428732920666f756e642e0a46696e6973686564210a4120746f74616c206f66203620756e75736564207573652073746174656d656e7428732920666f756e642e0a";
while(strlen($string) > 0
<?php
echo $this->Form->create('Event');
echo $this->Form->input('Event.reservation_id', array('empty' => __('Create a reservation for this event'), 'required' => false));
echo $this->Form->end();
$this->Js->buffer('urls.reservationsGet = "' . $this->Html->url(array('controller' => 'reservations', 'action' => 'get')) . '/";');
?>
<script type="text/javascript">
$('#EventReservationId').on('change', function() {
@hmic
hmic / .htaccess
Created October 21, 2014 12:22
Addition to (cakephp) .htaccess to redirect non-www to www URLs
# add this to redirect non-www to www urls
RewriteCond ${HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
@hmic
hmic / AppModel.php
Created February 17, 2015 09:43
Disabling crc32 based cache methods in cakephp-1.3
class AppModel extends Model {
public function __construct($id = false, $table = null, $ds = null) {
if($ds) {
$ds->cacheMethods = false;
$ds->cacheSources = false;
}
parent::__construct($id, $table, $ds);
$this->setDataSource($this->useDbConfig);
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$db->cacheMethods = false;
@hmic
hmic / Test.php
Last active August 29, 2015 14:17
SQL Table and baked Model (cakephp-2.6.2)
<?php
App::uses('AppModel', 'Model');
/**
* Test Model
*
*/
class Test extends AppModel {
}
@hmic
hmic / AppController.php
Last active August 29, 2015 14:27
CakePHP: Don't refer to the same page (again)
class Appcontroler extends Controller {
public function referer($default = null, $local = false)
{
$referer = $this->request->session()->read('Session.referer');
if($default === null && $referer) {
return $referer;
}
return parent::referer($default, $local);
}