Skip to content

Instantly share code, notes, and snippets.

@muminc
muminc / latency.markdown
Created February 14, 2022 23:30 — forked from hellerbarde/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

#!/bin/bash
wait_seconds=10
loop_sleep=0.25
# bash shell can't divide floats, using bc
max_wait_loop=`echo "$wait_seconds/$loop_sleep" | bc`
APP_PID=$(ps -x | grep "java" | grep -v "grep" | awk '{print $1}')
if [ ! -z "$APP_PID" ]; then
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
namespace MainProjectSSL
{
class Program
{
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.PrivateKeyDetails;
import org.apache.http.ssl.PrivateKeyStrategy;
import org.apache.http.ssl.SSLContexts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.ScheduledMethodRunnable;
@muminc
muminc / TestPKCS11.java
Created June 25, 2019 22:12 — forked from yusukemihara/TestPKCS11.java
perform HTTPS GET on SSL client verification using Java PKCS#11
/*
* perform HTTPS GET on SSL client verification using Java PKCS#11
*
* requirement:
* * PKCS#11 enable security token
* * the token has stored cert and key for ssl client verification,and ca cert
* PKCS#11 library(.dll or .so) for the token
*
* usage:
* java -cp . -D java.security.debug=sunpkcs11 TestPKCS11 https://www.example.com/
@muminc
muminc / pom.xml
Created June 9, 2019 22:45
making ErrorProne work with nullaway and lombok
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.choudhury</groupId>
<artifactId>error-nullaway</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
@muminc
muminc / AutoCompletingTextArea
Created June 23, 2016 10:42
JavaFX AutoCompleting TextArea
import javafx.collections.ObservableList;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyCode;