Skip to content

Instantly share code, notes, and snippets.

View siberex's full-sized avatar
🛠️
Your stack will not be full without me

Stepan Legachev siberex

🛠️
Your stack will not be full without me
View GitHub Profile
@siberex
siberex / clone-tree.sh
Created August 25, 2016 21:57
Clone tree structure
# http://ilyabirman.ru/meanwhile/all/clone-directory-structure/
SRC='/Volumes/My Passport/Porno/'
DEST='/tmp'
find "$SRC" -type f | while read f; do mkdir -p "$(dirname "$DEST$f")" && touch "$DEST$f"; done
@siberex
siberex / geo-points-distribute-nearby.js
Last active September 13, 2016 06:35
Random locations nearby specified location limited by radius
/**
* Get random geo point [latitude, longitude] within some distance from specified geo point (lat, long)
*
* Points will be uniformly-distributed on multiple calls.
*
* → Demo is here: http://jsfiddle.net/siberex/f72ffn1x/
*
* @param lat Latitude in degrees
* @param lng Longitude in degrees
* @param distance Distance in meters to limit point distribution to.
"use strict";
const rp = require('request-promise');
const util = require('util');
// https://developers.google.com/maps/documentation/timezone/start#get-a-key
let apiKey = 'AIzaSyCFljyx_4s3t6ldM5alxXPqcD7P9X6TYUM';
let coords = [[-22.681019,14.522226],[2.5724996,-27.8163698],[4.557567,4.6163235],[4.4254036,8.790334],[0.344051,9.4742473],[0.3834557,9.4475747],[-20.4457012,57.7176283],[0.3757385,9.4549369],[3.0552875716039662,9.964265981535153],[0.3546091,9.4734645],[89.9999999999996,0],[0.4093177,9.4320854],[0.470328,9.398915],[0.391981,9.4431912],[-1.1482112,8.6987966],[7.3679758,-24.2785494],[11.0904651,-28.864397],[0.40260293,9.43583089],[4.2393411,8.405862],[-22.008171379566193,35.3210552316159],[0.3718994,9.4592005],[6.3413884,3.3973382],[4.0709123,9.7037695],[4.9128139,-1.737505],[-20.174795,57.770134],[0.3711196,9.4582866],[0.3836682,9.4472672],[26.2327904,50.5381572],[-20.17276879,57.77063021],[-20.0052654,57.5698832],[4.443256666666667,8.027361666666668],[-20.28077,57.36534333333334],[41.40668
"use strict";
// node --harmony test-googleapi-async.js
const rp = require('request-promise');
const util = require('util');
const https = require('https');
// https://developers.google.com/maps/documentation/timezone/start#get-a-key
let apiKey = 'AIzaSyCFljyx_4s3t6ldM5alxXPqcD7P9X6TYUM';
"use strict";
const co = require('co');
co(function* () {
let test = function(value) {
return new Promise((resolve, reject) => {
if (value) {
resolve(value);
// sib.li
/*
Usage:
(async () => {
let throttler = new PromiseThrottle(reqLimit);
let results = [];
while(true) {
let p = new Promise(...);
if ( !throttler.enqueue( p ) ) {
let resultsChunk = await throttler.flush();
#!/bin/bash
### Install latest openssl and rabbitmq-c libs for Debian
### (replacing libssl-dev and librabbitmq-dev from packages)
set -eu
set -o pipefail
cd /tmp
@siberex
siberex / str2utf16.js
Last active May 28, 2020 15:13
Convert string to UTF16-encoded representation (useful for emoji parsing)
// Converts string to UTF16-encoded representation (useful for emoji parsing)
let toUtf = str => (
typeof str === 'string'
&& str.length > 0
&& str.split('').map(
char => '\\u' + (
// Zero-pad up to 16 bits (0xFFFF)
'0000' + char.charCodeAt(0).toString(16)
).slice(-4).toUpperCase()
).join('')
@siberex
siberex / ruby-run.c
Created April 12, 2017 01:34
Launch Ruby from threaded C/C++ app
/*
Launch some ruby script from threaded C code.
1. Create test.rb script, like this example with random number factorial output:
$ cat test.rb
def fact(n) (2..n).reduce(1, :*) end
puts "#{x = rand(100)}! = #{fact(x)}"
2. Compile and run:
$ gcc ruby-run.c -o ruby-run -lpthread -lruby
#!/usr/bin/env bash
for port in $(seq 80 90)
do
#bash -c "</dev/tcp/localhost/${port}" &> /dev/null
nc -w 0 -v localhost ${port} </dev/null &> /dev/null
ret=$?
if [ $ret != 0 ]; then
printf "Port %d is available\n" $port
else