Skip to content

Instantly share code, notes, and snippets.

@misshie
misshie / percentile.rb
Created April 16, 2024 05:56
Calculate percentaile values in an array of float values
#!/usr/bin/env ruby
class Percentile
ROUND_DIGIT = 1
def pctile(data0)
return [] if data0.empty?
data = data0.map{|x|Integer(x.round(ROUND_DIGIT) * (10 ** ROUND_DIGIT))}
sorted_data = data.sort
index_sum = Hash.new(0)
count = Hash.new(0)
@misshie
misshie / myhandler.rb
Created February 13, 2025 02:27
OJ library's simple call-back handler to process JSON with duplicated keys
#!/usr/bin/env ruby
require 'oj'
class MyHandler
# see Oj::ScHandler
def hash_start ; {} ; end
def hash_end ; end
def array_start ; [] ; end
def array_end ; end
def add_value(value) ; value ; end
@misshie
misshie / partial-init.el
Last active March 3, 2025 03:22
Emacs init.el Configuration to Prevent Sudden Session Disconnection in Microsoft RDP
;; Explicitly copy/paste between the kill-ring and x-clipboard
;; using the xlip command
;; C-c y : yank from x-clipboard
;; C-c c : copy from kill-ring to x-clipboard
(setq x-select-enable-clipboard nil)
(setq x-select-enable-primary nil)
(defun yank-from-x-clipboard()
"Yank from X clipboard using xclip."
(interactive)