Skip to content

Instantly share code, notes, and snippets.

View ezirmusitua's full-sized avatar
🎯
Focusing

ezirmusitua ezirmusitua

🎯
Focusing
View GitHub Profile
@ezirmusitua
ezirmusitua / scroll-to-positon.js
Created January 14, 2019 04:09
[Inside element scroll to position] scroll to position inside element(scollable element) #javascript #html
const elem = document.querySelecor('#scollableElement');
// scroll to specific position
elem.scrollTop = 100px;
elem.scrollLeft = 200px;
// scroll to bottom/right
elem.scrollTop = elem.scrollHeight;
elem.scrollLeft = elem.scrollWidth;
@ezirmusitua
ezirmusitua / run-tron-testnet.sh
Last active January 18, 2019 04:11
[Start local tron test net] start local tron test net with persistency #blockchain #docker #tron
docker run -it -p 9090:9090 -e "mnemonic=wrong bit chicken kitchen rat" -e "accounts=20" --rm --name tron trontools/quickstart
@ezirmusitua
ezirmusitua / validate-json-string.js
Created January 17, 2019 15:30
[Validate json string format] Validate json string format #javascript #json #regex #node
function validateJsonStr(jsonStr) {
let content = jsonStr.replace(/\\["\\\/bfnrtu]/g, '@');
content = content.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
content = content.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
return /^[\],:{}\s]*$/.test(jsonStr);
}
@ezirmusitua
ezirmusitua / check-port-usage.cmd
Created January 17, 2019 15:32
[Check port usage] check port usage with cmd in windows #windows #terminal #network
netstat -ano | findstr <port_number>
@ezirmusitua
ezirmusitua / manage-process.cmd
Created January 17, 2019 15:35
[Manage process] mange process in cmd #windows #terminal #system
# find process /? - show help
tasklist | findstr <pid/name>
# kill process /? - show help
taskkill /F /T /IM <name>
taskkill /F /T /PID <name>
@ezirmusitua
ezirmusitua / extract-substring.sh
Created January 17, 2019 15:48
[Extract substring] extract substring with cut in bash #bash #linux
# one line
## explaination
### 1. echo something and pipe to cut for processing
### 2. -d<char> means cut string by char
### 3. -f<num> means get the second set of cutted result
echo 'someletters_12345_moreleters.ext' | cut -d'_' -f 2
# multi line
INPUT='someletters_12345_moreleters.ext'
SUBSTRING=$(echo $INPUT| cut -d'_' -f 2)
@ezirmusitua
ezirmusitua / capture-screenshot.js
Last active January 17, 2019 15:53
[Capture screenshot] implement capture screenshot in electron #electron #node
const fs = require('fs')
const os = require('os')
const path = require('path')
const electron = require('electron')
const desktopCapturer = electron.desktopCapturer
const electronScreen = electron.screen
const shell = electron.shell
const screenshot = document.getElementById('screen-shot')
const screenshotMsg = document.getElementById('screenshot-path')
@ezirmusitua
ezirmusitua / fix-node-module-version.sh
Created January 17, 2019 15:58
[Fix NODE_MODULE_VERSION] fix NODE_MODULE_VERSION in electron #electron #node
# This error is cause by node_module node version not matched
# generally, it happend when you switch node version(with nvm & conda) but did not re-install dependencies
# in some case, it was cause by the electron node version is not compatiable with local node
## 1. install electron-rebuild
yarn add electron-rebuild --dev
## 2. remove node_modules
sudo rm -rf node_modules
## 3. re-install
yarn
@ezirmusitua
ezirmusitua / prettify-object-log.js
Created January 17, 2019 15:59
[Prettify object console log] Prettify object console log #javascript #node
var user = {
first: 'John',
last: 'Doe',
age: 42
};
// plain console log
console.log(JSON.stringify(user, undefined, 2));
// or with interpolation:
console.log(`User: ${JSON.stringify(user, undefined, 2)}`);
@ezirmusitua
ezirmusitua / create-eos-account.js
Created January 17, 2019 16:01
[Create EOS account] create EOS account with eosjs #javascript #node #blockchain #eos
const config = {
chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
keyProvider: ['MY PRIVATE KEY'],
httpEndpoint: 'https://api.eosnewyork.io:443',
verbose: false, // API activity
broadcast: true,
sign: true,
expireInSeconds: 60
}