Skip to content

Instantly share code, notes, and snippets.

View liesislukas's full-sized avatar
🚀
Excited

Lukas Liesis liesislukas

🚀
Excited
View GitHub Profile
export default function openInTab({url}) {
let instance = window.open('about:blank');
if (url.indexOf('http') !== 0) {
url = `http://${url}`;
}
let meta = `<meta http-equiv="refresh" content="0;url=${url}">`;
instance.document.write(meta);
instance.document.close();
return false;
}
@liesislukas
liesislukas / Fix ssl.ca.location issue on OSX
Created December 14, 2017 19:06
Fix ssl issue while installing node-rdkafka on OS X
before npm i:
install openssl: `brew install openssl`
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib
const _ = require('lodash');
function orderObjectFields(input) {
if (!input) {
return input;
}
if (_.isString(input)) {
return input;
} else if (_.isArray(input)) {
@liesislukas
liesislukas / encodings.js
Last active July 20, 2017 13:42
All possible encodings used on web. I need to validate if encoding string is "valid" and these are all encodings. Check comment below
const validEncodings = [
'US-ASCII', 'iso-ir-6', 'ANSI_X3.4-1968', 'ANSI_X3.4-1986', 'ISO_646.irv:1991', 'ISO646-US', 'us', 'IBM367', 'cp367',
'csASCII', 'ISO-8859-1', 'ISO_8859-1:1987', 'iso-ir-100', 'ISO_8859-1', 'latin1', 'l1', 'IBM819', 'CP819',
'csISOLatin1', 'ISO-8859-2', 'ISO_8859-2:1987', 'iso-ir-101', 'ISO_8859-2', 'latin2', 'l2', 'csISOLatin2',
'ISO-8859-3', 'ISO_8859-3:1988', 'iso-ir-109', 'ISO_8859-3', 'latin3', 'l3', 'csISOLatin3', 'ISO-8859-4',
'ISO_8859-4:1988', 'iso-ir-110', 'ISO_8859-4', 'latin4', 'l4', 'csISOLatin4', 'ISO-8859-5', 'ISO_8859-5:1988',
'iso-ir-144', 'ISO_8859-5', 'cyrillic', 'csISOLatinCyrillic', 'ISO-8859-6', 'ISO_8859-6:1987', 'iso-ir-127',
'ISO_8859-6', 'ECMA-114', 'ASMO-708', 'arabic', 'csISOLatinArabic', 'ISO-8859-7', 'ISO_8859-7:1987', 'iso-ir-126',
'ISO_8859-7', 'ELOT_928', 'ECMA-118', 'greek', 'greek8', 'csISOLatinGreek', 'ISO-8859-8', 'ISO_8859-8:1988',
@liesislukas
liesislukas / runCron.js
Created May 5, 2017 07:43
Node.js cron runner. Interval is set using moment.js add() function. Check sample code
/*
Sample usage:
runCron({promise: screenshotsCache, intervalNumber: 5, intervalString: 'minutes'});
This will call "screenshotsCache" Promise every 5 minutes.
If promise resolves after 6 minutes, it will be called again immediately because 5 mins already passed.
*/
@liesislukas
liesislukas / js.js
Last active April 25, 2017 14:13
Modified LiquidMetal algorithm with more weight for strings that have bigger max sequence & huge boost for sequences in front
(function (global) {
let SCORE_NO_MATCH = 0.0;
let SCORE_MATCH = 1.0;
let SCORE_TRAILING = 0.8;
let SCORE_TRAILING_BUT_STARTED = 0.9;
let SCORE_BUFFER = 0.85;
let WORD_SEPARATORS = ' \t_-';
let LiquidMetal = {
lastScore: null,
@liesislukas
liesislukas / gist:1473ec0876cc264c4c7d317af211dc06
Last active May 5, 2017 07:44
WooCommerce: update attributes for all products by using search to filter the products before update.
var WooCommerceAPI = require('woocommerce-api');
var WooCommerce = new WooCommerceAPI({
url: 'https://xxxx.lt',
consumerKey: 'xxxxx',
consumerSecret: 'xxxxx',
wpAPI: true,
version: 'wc/v1'
});
function helper({timeout, id, value, data}) {
@liesislukas
liesislukas / gist.js
Last active April 24, 2017 14:55
normalized levenshtein to get % of match between 2 strings. 1 = 100%, 0 = 0%
let levenshtein = function (str1, str2) {
let current = [], prev, value;
for (let i = 0; i <= str2.length; i++)
for (let j = 0; j <= str1.length; j++) {
if (i && j)
if (str1.charAt(j - 1) === str2.charAt(i - 1))
value = prev;
else
value = Math.min(current[j], current[j - 1], prev) + 1;
@liesislukas
liesislukas / 00.howto_install_phantomjs.md
Created February 24, 2017 07:28 — forked from julionc/00.howto_install_phantomjs.md
How to install PhantomJS on Debian/Ubuntu

How to install PhantomJS on Ubuntu

Version: 1.9.8

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
@liesislukas
liesislukas / h2load_installation.sh
Created November 9, 2016 21:52 — forked from hedleysmith/h2load_installation.sh
Installing nghttp2 & h2load on Ubuntu 14.04
#! /bin/bash
sudo apt-get update
sudo apt-get install g++ make binutils autoconf automake autotools-dev libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev -y
git clone https://github.com/nghttp2/nghttp2.git && cd nghttp2
autoreconf -i
automake
autoconf
./configure --enable-apps
make