Skip to content

Instantly share code, notes, and snippets.

View michalbcz's full-sized avatar

Michal Bernhard michalbcz

View GitHub Profile
@michalbcz
michalbcz / json-to-ndjson.md
Created March 27, 2021 13:08 — forked from bzerangue/json-to-ndjson.md
JSON to NDJSON

NDJSON is a convenient format for storing or streaming structured data that may be processed one record at a time.

  • Each line is a valid JSON value
  • Line separator is ‘\n’

1. Convert JSON to NDJSON?

cat test.json | jq -c '.[]' > testNDJSON.json
@michalbcz
michalbcz / flickr-background.js
Last active February 6, 2017 15:22 — forked from krtek/flickr-background.js
Flickr background
"use strict";
var API_KEY = '__API_KEY__';
var PHOTOSET_IDS = ['__ID1__', '__ID2__', '__ID3__'];
var cartagenaApp = angular.module('cartagenaApp');
cartagenaApp.directive('flickrBackground', function(Flickr, $http) {
var _flickrBackground = function($scope, $element) {
var nextPhoto;
@michalbcz
michalbcz / latency.markdown
Created October 10, 2016 06:57 — 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

private void test(List<ExchangeRate> exchangeRates) {
Map<String, ExchangeRate> rateType11Map = new HashMap<String, ExchangeRate>();
Map<String, ExchangeRate> rateType12Map = new HashMap<String, ExchangeRate>();
Collections.sort(exchangeRates, new Comparator<ExchangeRate>() {
@Override
public int compare(ExchangeRate e1, ExchangeRate e2) {
return ComparisonChain.start()
.compare(e1.getRateCurrency(), e2.getRateCurrency())
.compare(e1.getRateType(), e2.getRateType())
@michalbcz
michalbcz / md5.groovy
Created September 17, 2013 06:55 — forked from ikarius/md5.groovy
def generateMD5(String s) {
MessageDigest digest = MessageDigest.getInstance("MD5")
digest.update(s.bytes);
new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
}
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