Skip to content

Instantly share code, notes, and snippets.

View karmanov's full-sized avatar

Dmytro Karmanov karmanov

View GitHub Profile
#!/bin/sh
COUNTER=0
while true
do
TIME=`gdate +%s.%N`
# if [ $((COUNTER%10)) -eq 0 ];
# then
# # every tenth invocation will be more than a minute old
@karmanov
karmanov / Read RSA Private Key from String
Created August 20, 2018 12:48
Read RSA Private Key from String
private RSAPrivateKey readPrivateKey() throws Exception {
BufferedReader rdr = new BufferedReader(new StringReader(privateKeyString));
String pkcs8Pem = rdr.lines().collect(Collectors.joining());
pkcs8Pem = pkcs8Pem
.replace("-----BEGIN PRIVATE KEY-----", "")
.replace("-----END PRIVATE KEY-----", "")
.replaceAll("\\s+", "");
byte[] pkcs8EncodedBytes = Base64.decode(pkcs8Pem);
With a custom Collector:
import java.util.Map;
import java.util.stream.Collector;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
Clean OSX setup:
0. Common:
0.1 Show hidden file: defaults write com.apple.finder AppleShowAllFiles YES / NO
0.2 Homebrew
1. Java
1.1 https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html
2. Сделайте сброс SMC
Сброс настроек контроллера, отвечающего за работу внутренних компонентов MacBook,
был и остается действенным способом устранения различного рода неполадок.
# Path to your oh-my-zsh installation.
export ZSH=/Users/karmanov/.oh-my-zsh
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
#ZSH_THEME="robbyrussell"
ZSH_THEME="maran"
@karmanov
karmanov / latency.markdown
Created December 9, 2015 22:00 — forked from valadan/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@karmanov
karmanov / latency.txt
Created October 27, 2015 14:17 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
# download: remote -> local
scp user@remote_host:remote_file local_file
# upload: local -> remote
scp local_file user@remote_host:remote_file
@karmanov
karmanov / What Program Is Using Port 8080
Created January 6, 2015 09:15
What Program Is Using Port 8080
$ sudo lsof -i :8080 | grep LISTEN
$ sudo ps -ef | grep 12895
@karmanov
karmanov / GetParamValue.js
Last active August 29, 2015 14:11
Get parameter value from url
function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
}