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
// 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 [];
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'
@you-think-you-are-special
you-think-you-are-special / callPrivateMethod.php
Created June 9, 2015 11:32
Call private method in php for testing
<?php
function callPrivateMethod($object, $method, $args)
{
$classReflection = new \ReflectionClass(get_class($object));
$methodReflection = $classReflection->getMethod($method);
$methodReflection->setAccessible(true);
$result = $methodReflection->invokeArgs($object, $args);
$methodReflection->setAccessible(false);
return $result;
@you-think-you-are-special
you-think-you-are-special / backup.sh
Created May 25, 2015 12:47
Backup website into cloud (Yandex Disk)
#!/bin/bash
GPG_COMMAND="gpg -c -z 0 --batch --passphrase XXXXXXXXXX"
FS_FILE=/tmp/$SERVER_NAME-fs.$TIME.tar.gz.gpg
MYSQL_FILE=/tmp/$SERVER_NAME-mysql.$TIME.sql.gz.gpg
# Archiving filesystem
tar -cz /etc /root /home | $GPG_COMMAND > $FS_FILE
<?php
function binarySearch(array $searchArray, $needle)
{
$length = count($searchArray);
$centerKey = (int)($length / 2);
$currentKey = $centerKey;
$start = 0;
$end = $length - 1;
<?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]];
<?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;
@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: alexander@codeordie.ru
* 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]) {
@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);