Skip to content

Instantly share code, notes, and snippets.

View nechkin's full-sized avatar
🎯
Focusing

Sergey nechkin

🎯
Focusing
View GitHub Profile
@nechkin
nechkin / gist:1b887d38370e76e1072d
Created August 26, 2014 03:31
Version of [binarySearch] optimized for comparable keys
// From dart algorithm package
/** Version of [binarySearch] optimized for comparable keys */
int _comparableBinarySearch(List<Comparable> list, Comparable key) {
int min = 0;
int max = list.length;
while (min < max) {
int mid = min + ((max - min) >> 1);
var element = list[mid];
int comp = element.compareTo(key);
if (comp == 0) return mid;
@nechkin
nechkin / bash_loop_files_basename
Created December 21, 2014 16:41
Bash loop over files extracting file basename from path
http://stackoverflow.com/questions/18845814/bash-extracting-file-basename-from-long-path
files=( /very/long/path/to/various/files/*.file )
for file in "${files[@]}"
do
filename="${file##*/}"
filenameWithoutExtension="${filename%.*}"
echo "$filenameWithoutExtension"
done
#!/bin/bash
# Install:
# curl -O https://gist.github.com/nechkin/0ac33fad55f777c9994d#file-autossh-initd-elastic-tunnel-setup-sh
# chmod u+x autossh-initd-elastic-tunnel-setup.sh
# ./autossh-initd-elastic-tunnel-setup.sh
SSH_USER="EBdev"
SSH_SERVER="172.22.40.10"
SSH_PORT="22"
user="root"
group="root"
chroot="/"
chdir="/"
nice=""
#!/bin/sh
# Init script for kibana
# From Kibana package
# Generated by pleaserun.
# Implemented based on LSB Core 3.1:
# * Sections: 20.2, 20.3
#
### BEGIN INIT INFO
# Provides: kibana
# Required-Start: $remote_fs $syslog
@nechkin
nechkin / wkhtmltopdf.tablesplit.js
Created October 13, 2016 11:08 — forked from niflostancu/wkhtmltopdf.tablesplit.js
WkHtmlToPdf Table Splitting Hack
/**
* WkHtmlToPdf table splitting hack.
*
* Script to automatically split multiple-pages-spanning HTML tables for PDF
* generation using webkit.
*
* To use, you must adjust pdfPage object's contents to reflect your PDF's
* page format.
* The tables you want to be automatically splitted when the page ends must
* have a class name of "splitForPrint" (can be changed).
@nechkin
nechkin / idea
Created October 27, 2018 16:56 — forked from chrisdarroch/idea
Open a project in IntelliJ IDEA from your command line!
#!/bin/sh
# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
wd=`pwd`
# were we given a directory?
if [ -d "$1" ]; then
# echo "checking for things in the working dir given"
wd=`ls -1d "$1" | head -n1`
@nechkin
nechkin / JavaPuzzler01.java
Last active December 13, 2018 03:24
Java Puzzler 01 generic overload
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Type is erase in bytecode, but which method to call is inferred at compile type, when generics are available
*/
class Scratch {
// can be called with Arrays.asList("a", "b"), type is inferred to String
@nechkin
nechkin / test_ms_ready_k8s.pl
Created April 19, 2019 20:37
Perl script to test that pods are ready in kubernetes
#!/usr/local/bin/perl
use strict;
use YAML::Tiny;
my $maxAttempts = 60;
my $timeoutSeconds = 60;
# шаблон для команды получения списка Ready статусов для всех подов с заданым лейблом
my $separator = '\t';
my $jsonPath = '{range .items[*]}{@.metadata.name}{"'.$separator.'"}{@.status.conditions[?(@.type=="Ready")].status}{"\n"}{end}';
@nechkin
nechkin / wait_proc
Last active May 8, 2019 12:06
bash scripts wait for process to finish
#!/bin/bash
# script runs rabbit-init.jar waits 30 seconds for it to finish
# (wait time can be set with WAIT_TOTAL env property)
properties_location=$1
wait_pid() {
local pid="$1"; shift
local wait_total="${1:-10}"; shift # 10 seconds as default timeout