Skip to content

Instantly share code, notes, and snippets.

View antonfisher's full-sized avatar

Anton Fisher antonfisher

View GitHub Profile
// http://jsfiddle.net/antonfisher/qky16fp3/
// For human:
/**
* Get Array key by percentage
*
* getArrayKeyByPercent(["a", "b", "c"], 0) ==> "a"
* getArrayKeyByPercent(["a", "b", "c"], 50) ==> "b"
* getArrayKeyByPercent(["a", "b", "c"], 90) ==> "c"
@antonfisher
antonfisher / split-vs-sed.js
Created November 10, 2015 08:55
Build in Nodejs split function VS bash 'sed & tr' command
/**
* Usage:
* $npm install shelljs
* $node split-vs-sed.js
*/
/**
* Results:
*
* $ node split-vs-sed.js
@antonfisher
antonfisher / check_directory_exits.sh
Last active November 20, 2015 09:17
BASH: check_directory_exits
##
# Check directory
# $1 {String} - path
# $2 {Number} - show error
#
# @returns {Number} 0 - exists / 1 - not exists
#
# Example:
# check_directory_exits /tmp 1;
#
@antonfisher
antonfisher / get_full_path.sh
Last active December 4, 2015 10:07
BASH: get_full_file_path
##
# Get full file/directory path
#
# Examples:
# full_path=$(get_full_path '/tmp'); # /tmp
# full_path=$(get_full_path '~/..'); # /home
# full_path=$(get_full_path '../../../'); # /home
#
# @param {String} $1 - relative path
# @returns {String} absolute path
@antonfisher
antonfisher / mic-to-ssh.sh
Last active December 9, 2015 07:28
BASH mic output piped to ssh
#!/usr/bin/env bash
while true; do
arecord -r 44100 -c 1 2>/dev/null | ssh pi@10.0.0.151 "cat > /tmp/record.fifo";
sleep 1;
done;
var extJsTT = {
button: {
click: function () {},
is: {
enabled: function () {},
},
wait: {
is: {
enabled: function () {},
},
@antonfisher
antonfisher / create-orphan-branch.sh
Created January 25, 2016 00:37
Create orphan branch for github documentation
git checkout --orphan docs
git rm -rf .
git reset
git add ...
git push
git co master
var ActiveDirectory = require('activedirectory');
var ad = new ActiveDirectory({
url: 'ldap://10.10.10.10',
baseDN: 'dc=domain,dc=com',
username: 'Administrator',
password: 'kokoko'
});
ad.findUser('', function (err, user) {
/**
*
* Search with tree vs filter()
*
* Generate data file:
* echo "module.exports = [" > /tmp/data.js; for n in {1..1000000}; do echo "\"bk-${n}\"," >> /tmp/data.js; done; echo "]" >> /tmp/data.js;
*
* Run search:
* node --max-old-space-size=4096 ./fulltext-prefix-search-tree-vs-filter.js
*
/**
*
* Search value with tree vs filter()
*
* Generate data file:
* echo "module.exports = [" > /tmp/data.js; for n in {1..1000000}; do echo "\"bk-${n}\"," >> /tmp/data.js; done; echo "]" >> /tmp/data.js;
*
* Run search:
* node --max-old-space-size=4096 ./prefix-search-tree-vs-filter.js
*