Skip to content

Instantly share code, notes, and snippets.

View dbalabka's full-sized avatar
🔍
Search for opportunities

Dmitry Balabka dbalabka

🔍
Search for opportunities
View GitHub Profile
@dbalabka
dbalabka / api.js
Last active August 18, 2016 23:35
Google Experiment Client
(function () {
var d, f = this, k = function (a, c, b) {
a = a.split(".");
b = b || f;
a[0] in b || !b.execScript || b.execScript("var " + a[0]);
for (var e; a.length && (e = a.shift());)a.length || void 0 === c ? b = b[e] ? b[e] : b[e] = {} : b[e] = c
}, l = Date.now || function () {
return +new Date
};
var p = function (a) {
@dbalabka
dbalabka / constructor-arguments.php
Created May 19, 2017 14:14
Using new PHP7 operator "..." to provide variable number of arguments into constructor we can easier manage child classes constructor interfaces.
<?php
class ParentClass
{
public $a;
public $b;
public function __construct($a, $b)
{
$this->a = $a;
@dbalabka
dbalabka / generator.php
Last active July 31, 2017 15:00
Inteteresting PHP generators behavior
<?php
class TestGenerator {
public function task1($doGenerate = true)
{
echo "Enter generator\n";
if ($doGenerate) {
echo "Generate values\n";
yield 1;
yield 2;
@dbalabka
dbalabka / gist:f8c19044282db049e71ca143dd3e0680
Created March 23, 2018 11:17 — forked from trongthanh/gist:2779392
How to move a folder from one repo to another
# source: http://st-on-it.blogspot.com/2010/01/how-to-move-folders-between-git.html
# First of all you need to have a clean clone of the source repository so we didn't screw the things up.
git clone git://server.com/my-repo1.git
# After that you need to do some preparations on the source repository, nuking all the entries except the folder you need to move. Use the following command
git filter-branch --subdirectory-filter your_dir -- --all
# This will nuke all the other entries and their history, creating a clean git repository that contains only data and history from the directory you need. If you need to move several folders, you have to collect them in a single directory using the git mv command.
@dbalabka
dbalabka / .phpdebug
Last active January 11, 2019 09:47
!!! Script is migrated to https://github.com/torinaki/phpdebug-cli !!! XDebug PHP CLI debugging helper console commands with PhpStorm, NetBeans support.
# Installation steps:
# 1. Put this file under ~/.phpdebug
# $ curl https://gist.githubusercontent.com/torinaki/9059015/raw/.phpdebug > ~/.phpdebug
# 2. Put following lines into ~/.bashrc:
# # Get the aliases and functions
# if [ -f ~/.phpdebug ]; then
# . ~/.phpdebug
# fi
# 3. (optional) Script will try to autodetect your machine IP where runs IDE or use 127.0.0.1 otherwise.
# If automatic detection doesn't work for you, set ip directly via IDE_IP enviroment variable:
@dbalabka
dbalabka / ignore_notices_warning_selectively_test.php
Created July 22, 2019 09:23
iddqd for PHP to ignore notices and warning selectively, while using Symfony ErrorHandler. Helps to upgrade PHP smoothly.
<?php
use Symfony\Component\Debug\BufferingLogger;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Debug\ErrorHandler;
$loader = require_once __DIR__ . '/vendor/autoload.php';
class ConfigurableErrorHandler extends ErrorHandler
{
@dbalabka
dbalabka / main.dart
Created October 1, 2019 18:32
Bidirectional type inference in dart
void main() {
print(foo('bar'));
// will rise an error
foo(1);
}
foo ($s) {
return 'foo' + $s;
}
@dbalabka
dbalabka / ttfb.sh
Last active June 2, 2020 10:43 — forked from sandeepraju/ttfb.sh
cURL command to check the request timing (including TTFB)
#!/bin/bash
# file: ttfb.sh
# curl command to check the time to first byte
# ** usage **
# 1. ./ttfb.sh "https://google.com"
# 2. seq 10 | xargs -Iz ./ttfb.sh "https://google.com"
curl -o /dev/null \
-H 'Cache-Control: no-cache' \
-s \
@dbalabka
dbalabka / jackknife_numba.py
Last active April 22, 2021 11:14
scikits-bootstrap Jackknife resampling with Numba and performance testing
import scikits.bootstrap as bootstrap
import numpy as np
import time
import numba
@numba.njit(parallel=True, fastmath=True)
def _calculate_jackknife_mean_stat(data: np.ndarray) -> np.ndarray:
n = data.shape[0]
jstat = np.zeros(n)
sum = data.sum()
@dbalabka
dbalabka / bootstrap_numba.py
Last active April 22, 2021 11:14
scikits-bootstrap Bootstrapping resampling with Numba and performance testing
import scikits.bootstrap as bootstrap
import numpy as np
import time
import numba
@numba.njit(parallel=True, fastmath=True)
def _calculate_boostrap_mean_stat(data: np.ndarray, n_samples: int) -> np.ndarray:
n = data.shape[0]
stat = np.zeros(n_samples)
for i in numba.prange(n_samples):