Skip to content

Instantly share code, notes, and snippets.

Krzysztof Kowalczyk kjk

Block or report user

Report or block kjk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View faster_binary_tree.go
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime/debug"
"runtime/pprof"
"strconv"
@kjk
kjk / windows.h__.js
Created Oct 4, 2016
windows.h.js INFINITY
View windows.h__.js
var ffi = require('ffi'),
ref = require('ref'),
Struct = require('ref-struct'),
Library = require('./Library'),
Type = ref.Type,
NULL = ref.NULL,
isNull = ref.isNull;
var groups = ['libs', 'types', 'structs', 'callbacks', 'enums'];
@kjk
kjk / html_in_js.js
Created Aug 12, 2016
try to find a natural way to encode html in js
View html_in_js.js
var s = ```
div class="txt-c" style="display: flex"
div class="maxl paxl box-shadow-key-1" style="width: 33%;"
code
.box-shadow-key-1
div class="maxl paxl box-shadow-amb-1" style="width: 33%;"
code
.box-shadow-amb-1
div class="maxl paxl box-shadow-1" style="width: 33%;"><code>.box-shadow-1</code>
<div class="txt-c" style="display: flex">
@kjk
kjk / solarized-light.json
Last active Jul 25, 2017
trying to set powershell colors (based on https://github.com/lukesampson/concfg). Didn't work
View solarized-light.json
{
"black": "#002b36",
"dark_blue": "#268bd2",
"dark_green": "#859900",
"dark_cyan": "#2aa198",
"dark_red": "#dc322f",
"dark_magenta": "#d33682",
"dark_yellow": "#b58900",
"gray": "#eee8d5",
"dark_gray": "#073642",
@kjk
kjk / 3.5-chromium.txt
Last active Nov 25, 2017
clang-format styles
View 3.5-chromium.txt
kjkmacpro:sumatrapdf kjk$ clang-format -dump-config -style=Chromium
---
Language: Cpp
# BasedOnStyle: Chromium
AccessModifierOffset: -1
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
View latency.markdown

Latency numbers every programmer should know

1 typical CPU instruction ..................   1 ns
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
@kjk
kjk / go_smaz_faster.md
Created Dec 11, 2014
Improving smaz benchmarking
View go_smaz_faster.md

Before:

Krzysztofs-MacBook-Pro-4:go-smaz kkowalczyk$ go test -bench=.
PASS
BenchmarkCompression	     500	   3451735 ns/op	  39.60 MB/s
BenchmarkDecompression	     500	   2740847 ns/op	  27.58 MB/s

After:

Krzysztofs-MacBook-Pro-4:go-smaz kkowalczyk$ go test -bench=.
View NoFreeAllocator.cpp
/* Copyright 2014 the SumatraPDF project authors (see AUTHORS file).
License: Simplified BSD (see COPYING.BSD) */
/* NOTE: this is unfinished work in progress */
/* NoFreeAllocator (ScratchAllocator ?) is designed for quickly and easily
allocating temporary memory that doesn't outlive the stack frame
in which it was allocated.
Consider this piece of code:
View dump_pe.py
import os
import pefile
# needs https://code.google.com/p/pefile/ to be installed
# i.e. download it, extract and python setup.py install
d = os.path.join("win", "Debug")
files = os.listdir(d)
def is_pe(s):
if s.endswith(".dll"):
@kjk
kjk / bzcompress.go
Last active Sep 10, 2016
how to compress multiple files to a single file using bzip2, in Go
View bzcompress.go
func bz2CompressFiles(dstPath string, srcFiles []string) {
os.Remove(dstPath)
fileOut, err := os.Create(dstPath)
u.PanicIfErr(err)
cmd := exec.Command("bzip2", "--best", "-z")
cmd.Stdout = fileOut
stdin, err := cmd.StdinPipe()
u.PanicIfErr(err)
You can’t perform that action at this time.