Skip to content

Instantly share code, notes, and snippets.

View you-think-you-are-special's full-sized avatar
:octocat:
Coding...

Aleksandr Litvinov you-think-you-are-special

:octocat:
Coding...
View GitHub Profile
@you-think-you-are-special
you-think-you-are-special / global.php
Created November 25, 2014 10:08
Yii global helper functions
<?php
/**
* This file contains constants and shortcut functions that are commonly used.
* Please only include functions are most widely used because this file
* is included for every request. Functions are less often used are better
* encapsulated as static methods in helper classes that are loaded on demand.
*/
/**
* This is the shortcut to DIRECTORY_SEPARATOR
*/
@you-think-you-are-special
you-think-you-are-special / Url.php
Last active August 29, 2015 14:13
Yii2 Url Behavior
<?php
/**
* Email: <[email protected]>
* Date: 19.01.15
* Time: 12:10
*
* use \behaviors\Url
* ...
*
* public function behaviors()
@you-think-you-are-special
you-think-you-are-special / Registry.js
Created February 17, 2015 12:34
ES6 JS implementation of Registry pattern
/**
* Created by Alexander Litvinov
* Email: [email protected]
* May be freely distributed under the MIT license
*/
'use strict';
import _ from 'lodash'
@you-think-you-are-special
you-think-you-are-special / System.import.js
Created February 17, 2015 14:43
Import several modules in ES6 style
Promise.all(
['module1', 'module2', 'module3']
.map(x => System.import(x)))
.then(([module1, module2, module3]) => {
// Use module1, module2, module3
});
@you-think-you-are-special
you-think-you-are-special / Singleton.js
Created February 18, 2015 10:52
ES6 Singleton example. Use: import Singleton from 'Singleton'; let instance = Singleton.instance;
'use strict';
/**
* Created by Alexander Litvinov
* Email: [email protected]
* May be freely distributed under the MIT license
*/
let singleton = Symbol();
let singletonEnforcer = Symbol();
@you-think-you-are-special
you-think-you-are-special / UserSetter.php
Created March 26, 2015 10:01
Yii2 UserSetter Behavior
<?php
/**
* Created by Alexander Litvinov
* Email: [email protected]
* May be freely distributed under the MIT license
*/
namespace common\behaviors;
use Yii;
@you-think-you-are-special
you-think-you-are-special / BarcodeScanner.js
Created March 30, 2015 08:42
JavaScript barcode scanner detector
function BarcodeScannerDetector(options) {
this.options = options || {}; // Default
this.options.keypressDelay = this.options.keypressDelay || 100; // Delay between press
this.chars = []; // Our barcode
this.events();
}
BarcodeScannerDetector.prototype.delay = function(callback, ms) {
clearTimeout(this.timer);
this.timer = setTimeout(callback, ms);
@you-think-you-are-special
you-think-you-are-special / literal.php
Last active August 29, 2015 14:18
Type hints hack for literal Values in PHP. For a production environment this method is somewhat unusable.
<?php
/**
* Created by Alexander Litvinov
* Email: [email protected]
* May be freely distributed under the MIT license
*/
function typehint($level, $message) {
if($level == E_RECOVERABLE_ERROR && preg_match('/^Argument (\d)+ passed to (?:(\w+)::)?(\w+)\(\) must be an instance of (\w+), (\w+) given/', $message, $match)) {
if($match[4] == $match[5]) {
<?php
function stupid_sort($array)
{
$i = 0;
$n = count($array);
while ($i < $n - 1) {
if ($array[$i + 1] < $array[$i]) {
list($array[$i], $array[$i + 1]) = array($array[$i + 1], $array[$i]);
$i = 0;
<?php
function bubble_sort($array)
{
$n = count($array);
for ($i = 0; $i < $n - 1; $i++) {
for ($j = 0; $j < $n - 1 - $i; $j++) {
if ($array[$j] > $array[$j + 1]) {
list($array[$j], $array[$j + 1]) = [$array[$j + 1], $array[$j]];