Skip to content

Instantly share code, notes, and snippets.

View holyjak's full-sized avatar
💓
Loving Clojure

Jakub Holý holyjak

💓
Loving Clojure
View GitHub Profile
@holyjak
holyjak / oz.clj
Created November 4, 2018 12:21
Comparison of gnuplot, Incanter, oz/vega-lite for plotting usage data - Oz
(ns clj-charting.oz
(:require
[oz.core :as oz]
[incanter.core :refer :all]
[clj-charting.usage-chart-preparation :refer [read-usage-data moving-window-means]]))
(defn dataset->map-list
"Incanter dataset into a list of maps like
{\"0\" 1541065398391, \"1\" 446693376, \"2\" 99.9, \"cpu_mean\" 89}"
[ds]
@holyjak
holyjak / incanter.clj
Last active November 4, 2018 12:16
Comparison of gnuplot, Incanter, oz/vega-lite for plotting usage data - Incanter
(ns clj-charting.incanter
(:require
[incanter.core :refer :all]
[incanter.charts :refer :all]
[clj-charting.usage-chart-preparation :refer [read-usage-data moving-window-means]])
(:import
[org.jfree.chart JFreeChart]
[org.jfree.chart.plot XYPlot]
(org.jfree.chart.axis ValueAxis NumberAxis NumberTickUnit TickUnitSource TickUnit)
(java.text NumberFormat DecimalFormat FieldPosition)))
@holyjak
holyjak / usage-chart-preparation.clj
Last active November 4, 2018 12:00
Incanter - prepare usage data
(ns clj-charting.usage-chart-preparation
(:require
[incanter.core :refer :all]
[incanter.stats :as s]
[incanter.io :as io]))
(defn- resolve-unit-suffix
"Replace values such as 333k, 800m, 1.2g with the corresponding value in bytes"
[val-suffixed]
(if-let [[_ val unit] (and
@holyjak
holyjak / README.md
Created November 1, 2018 12:01
Incanter: show bytes as kB/MB/GB on an axis

Modify an axis to display the number of bytes with scale suffixes such as kB, MB, GB, and display more reader-friendly ticks such as "500MB" instead of "496M".

The trick is to supply a custom "tick source" that tells JFreeChart what ticks it should prefer. I cheat a little and reuse the existing IntegerTickUnitSource, optimally I would rewrite it to work with multiples of 2 rather than 10.

@holyjak
holyjak / async-context.js
Created November 1, 2018 10:00
Async hooks on Nodejs
const asyncHooks = require('async_hooks'); // Node 8.9+
const querystring = require('querystring');
const crypto = require("crypto");
const context = {};
function createHooks() {
function init(asyncId, type, triggerId, resource) {
// if (context[triggerId]) {
// context[asyncId] = context[triggerId];

Keybase proof

I hereby claim:

  • I am holyjak on github.
  • I am holyjak (https://keybase.io/holyjak) on keybase.
  • I have a public key ASByIJYo8u5KNW4WoEq0JoTvuM-vqKnd47DQwd9hhd5cEwo

To claim this, I am signing this object:

@holyjak
holyjak / plot-usage.gp
Last active January 30, 2024 22:28
Gnuplot script to plot memory, CPU usage of a process from `top`
#!/usr/bin/env -S gnuplot --persist -c
# Plot memory and CPU usage over time. Usage:
# usage-plot.gp <input file> [<output .png file>]
# where the input file has the columns `<unix time> <memory, with m/g suffix> <% cpu>`
# To create the input file, see https://gist.github.com/jakubholynet/931a3441982c833f5f8fcdcf54d05c91
# Arguments:
infile=ARG1
outfile=ARG2
set term x11
@holyjak
holyjak / monitor-usage.sh
Last active February 14, 2023 14:03
Script to monitor the usage of CPU, memory by a process via `top`
#!/bin/sh
##
## BEWARE: Check with your impl. of top what exactly it returns, it migth differ from mine
##
# Usage: ./monitor-usage.sh <PID of the process>
# Output: top.dat with lines such as `1539689171 305m 2.0`, i.e. unix time - memory with m suffix - CPU load in %
# To plot the output, see https://gist.github.com/holyjak/1b58dedae3207b4a56c9abcde5f3fdb5
export PID=$1
rm top.dat
while true; do top -p $PID -bn 1 -em | egrep '^ *[0-9]+' | awk -v now=$(date +%s.%N) '{print now,$6,$9}' >> top.dat; done
@holyjak
holyjak / README.md
Last active October 13, 2018 07:42
Node 8 out of memory issue due to setTimeout

My Node app is running out of all available memory within 3 minutes when I use Promise.race with setTimeoutPromise.

The server just reads a (~ 50MB) JSON from Redis, parses it, stringifies it, and send OK to the caller.

When I invoke it with 3 concurrent users accessing it constantly, its memory usage grows from ± 100MB to the max heap size confgiured to 3.3GB within ± 3 minutes, after which the app freezes and eventually crashes with FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory during JSON.parse.

Key facts

@holyjak
holyjak / deploy_codedeploy.rb
Created January 9, 2018 09:23
Patch Travis CI CodeDeploy support to correctly register revisions
# Modified Travis-CI deployment tool (dpl) provider for AWS CodeDeploy
# that does also correctly register the revision
require 'dpl/cli'
require 'dpl/provider'
require 'dpl/provider/code_deploy'
require 'time'
module DPL
class Provider