Skip to content

Instantly share code, notes, and snippets.

View rATRIJS's full-sized avatar

Rolands Atvars rATRIJS

View GitHub Profile
@rATRIJS
rATRIJS / gist:2477927
Created April 24, 2012 08:35
Some random regex vs strpos test results
/$: include '/home/rolands/Public/Web/regexvsstrpos.php'
# Return
int(1)
/$: test_test_valid_strpos('some string goes here that is valid')
# Return
float(10.26731300354)
@rATRIJS
rATRIJS / regexvsstrpos.php
Created April 24, 2012 08:32
Some random regex vs strpos test
<?php
function test_valid_strpos($s) { foreach(array(';', ',', '|', '[', ']') as $c) if(false !== strpos($s, $c)) return false; return true; }
function test_valid_regex($s) { return preg_match('/[;,|\[\]]/', $s) === 0; }
function test_valid_strpbrk($s) { return false === strpbrk($s, ';,|[]'); }
function test_test_valid_strpos($s) { $t = microtime(true); for($i = 0; $i < 1000000; $i++) test_valid_strpos($s); return (microtime(true) - $t); }
function test_test_valid_regex($s) { $t = microtime(true); for($i = 0; $i < 1000000; $i++) test_valid_regex($s); return (microtime(true) - $t); }
function test_test_valid_strpbrk($s) { $t = microtime(true); for($i = 0; $i < 1000000; $i++) test_valid_strpbrk($s); return (microtime(true) - $t); }
@rATRIJS
rATRIJS / oop.php
Created February 7, 2012 19:43
Random OOP example
<?php
class DB {
public static function insert($table, $properties) {
// izveido SQL un izpildi
}
}
class Model {
public function __construct($properties) {
foreach($properties as $property_name => $property_value)
@rATRIJS
rATRIJS / html5-fake-history-example.html
Created October 24, 2011 20:29
HTML5 Fake History Example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>HTML5 'pushState' History Example</title>
<script type="text/javascript" charset="utf-8">
var original = document.location.href;
history.pushState({
isFakeHistory: true,
fakeHistoryURL: "fake-history.html"