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 / UserSetter.php
Created March 26, 2015 10:01
Yii2 UserSetter Behavior
<?php
/**
* Created by Alexander Litvinov
* Email: alexander@codeordie.ru
* May be freely distributed under the MIT license
*/
namespace common\behaviors;
use Yii;
@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: alexander@codeordie.ru
* May be freely distributed under the MIT license
*/
let singleton = Symbol();
let singletonEnforcer = Symbol();
@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 / Registry.js
Created February 17, 2015 12:34
ES6 JS implementation of Registry pattern
/**
* Created by Alexander Litvinov
* Email: alexander@codeordie.ru
* May be freely distributed under the MIT license
*/
'use strict';
import _ from 'lodash'
@you-think-you-are-special
you-think-you-are-special / Url.php
Last active August 29, 2015 14:13
Yii2 Url Behavior
<?php
/**
* Email: <alexander@codeordie.ru>
* Date: 19.01.15
* Time: 12:10
*
* use \behaviors\Url
* ...
*
* public function behaviors()
@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
*/
server{
listen 80;
server_name example.com;
access_log /home/path_to_site/access.log;
error_log /home/path_to_site/error.log;
location / {
proxy_pass http://0.0.0.0:8002;
proxy_set_header Host $host;
<?php
trait Options {
public function setOptions(array $options)
{
// apply options
foreach ($options as $key => $value) {
$method = 'set' . $this->normalizeKey($key);
if (method_exists($this, $method)) {
$this->$method($value);
<?php
trait Singleton
{
protected static $instance;
protected function __construct()
{
static::setInstance($this);
}
/**
* Created by alexander on 24.02.14.
*/
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
var User = new Schema({
name: String,
created: {type: Date, default: Date.now}
});