Skip to content

Instantly share code, notes, and snippets.

View daGrevis's full-sized avatar
⌨️
Keyboard operator

Raitis Stengrevics daGrevis

⌨️
Keyboard operator
View GitHub Profile
@daGrevis
daGrevis / time_bench.py
Created February 14, 2012 15:46
Time benchmark in Python
import time
t1 = time.time()
r = []
for i in range(1000000):
r.append(i)
t2 = time.time() - t1
@daGrevis
daGrevis / size_bench.py
Created February 14, 2012 16:20
Size benchmark in Python
import sys
o = "I'm string!"
r = sys.getsizeof(o)
print r
@daGrevis
daGrevis / strict.js
Created February 15, 2012 14:09
Example of `"use strict";` in JavaScript
(function() {
'use strict';
// Code here...
}());
@daGrevis
daGrevis / bubble.py
Created February 15, 2012 16:16
Bubble sort in Python
def bubble(list):
length = len(list) - 1
sorted = False
while not sorted:
sorted = True
for i in range(length):
@daGrevis
daGrevis / regex_for_i18n_name_with_spaces.php
Created February 16, 2012 14:43
Regex for i18n name with spaces
<?php
$regex = '/^\pL+( \pL+)*$/uD';
$values = array(
'John Smith',
'Jānis Bērziņš',
'Hack3r',
'I like periods.',
);
@daGrevis
daGrevis / benchmark_boilerplate.php
Created February 28, 2012 17:09
Benchmark boilerplate (in PHP)
<?php
const TIMES = 1000000;
function bench($function, $times = null) {
$times = $times !== null ? $times : TIMES;
$begin = microtime(true);
@daGrevis
daGrevis / emptyForm.js
Created March 7, 2012 07:28
emptyForm.js
/**
* @author daGrevis
*/
(function($) {
'use strict';
$.fn.emptyForm = function() {
return this.each(function() {
@daGrevis
daGrevis / i18n-helper.js
Created March 8, 2012 10:05
i18n helper
function a(b) {
c =
b
.toLowerCase()
.split(' ')
.join('-')
.replace(/[^A-Za-z-]+/, '');
console.log(c);
@daGrevis
daGrevis / gist:2329883
Created April 7, 2012 15:52
Fake-load Auto-modeler
<?php
class AutoModeler extends AutoModeler_Core {
/**
* Sets data and changes state to loaded.
*
* @param array Data
*
* @author daGrevis
@daGrevis
daGrevis / protected_and_static_functions_in_class_with_the_same_name.php
Created April 16, 2012 13:18
`Fatal error: Cannot redeclare Foo::bar() in /var/www/foo/bar.php on line 8`
<?php
class Foo {
protected function bar($a, $b) {
}
public static function bar() {
}