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 / 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);
var n = 7;
var center = Math.round(n / 2);
var steps = 1;
var stepCnt = n * n;
var y = center;
var x = center;
var getPos = (function* getPos() {
while (true) {
yield 'up'
// exchange btc to eth
// trx - transaction from db
let hitbtc = new ccxt.hitbtc();
hitbtc.apiKey = '';
hitbtc.secret = '';
// check balance
const balance = await hitbtc.fetchBalance();
// balance >= trx.amountFrom check in btc
@you-think-you-are-special
you-think-you-are-special / DI.js
Last active April 23, 2018 07:49
JavaScript dependency injection container example
function argsList(method) {
method = method.toString();
const fn = /^function\s*[^\(]*\(\s*([^\)]*)\)/m;
const cls = /constructor\s*[^\(]*\(\s*([^\)]*)\)/m;
const FN_ARGS = method[0] === 'f' ? fn : cls;
const depsStr = method.match(FN_ARGS);
const deps = (depsStr) ? depsStr[1].trim().split(/[\s,]+/) : [''];
if (deps[0] === '') {
return [];
@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 / 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;
kill -9 $(lsof -t -i :9000)
<?php
foreach(Yii::app()->user->getFlashes() as $key => $message) {
echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
}
?>
<?php
protected function checkMethodExists($method)
{
if (!method_exists($this, $method))
throw new CException("Method CController::{$method}() not found");
}
?>
@you-think-you-are-special
you-think-you-are-special / DS.php
Created July 17, 2013 07:25
DIRECTORY_SEPARATOR
<?php defined('DS') or define('DS', DIRECTORY_SEPARATOR); ?>