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
<?php
function binarySearch(array $searchArray, $needle)
{
$length = count($searchArray);
$centerKey = (int)($length / 2);
$currentKey = $centerKey;
$start = 0;
$end = $length - 1;
@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
@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;
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 / 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 [];
// 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