Skip to content

Instantly share code, notes, and snippets.

@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)
@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 / 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)
##INFO=<ID=BaseQRankSum,Number=1,Type=Float,Description=".">
##INFO=<ID=InbreedingCoeff,Number=1,Type=Float,Description=".">
##INFO=<ID=ReadPosRankSum,Number=1,Type=Float,Description=".">
##INFO=<ID=NEGATIVE_TRAIN_SITE,Number=0,Type=Flag,Description=".">
##INFO=<ID=POSITIVE_TRAIN_SITE,Number=0,Type=Flag,Description=".">
##INFO=<ID=TOMMO_POSSIBLE_PLATFORM_BIAS_SITE,Number=0,Type=Flag,Description=".">
##INFO=<ID=CLNREVSTAT,Number=A,Type=String,Description=".">
##INFO=<ID=CLNSIGCONF,Number=A,Type=String,Description=".">
##INFO=<ID=CLNDISDBINCL,Number=A,Type=String,Description=".">
##INFO=<ID=CLNSIGINCL,Number=A,Type=String,Description=".">
@misshie
misshie / chisq_test.rb
Created October 19, 2023 02:34
2x2 table chi squared test ... use at your own risk ;)
require 'statistics2'
def chisq_test(a, b, c, d)
total = a + b + c + d
row1_total = a + b
row2_total = c + d
col1_total = a + c
col2_total = b + d
e_a = (row1_total * col1_total).to_f / total
e_b = (row1_total * col2_total).to_f / total
@misshie
misshie / tab2xl.rb
Created April 9, 2020 05:23
A Ruby script conveting a tab delimited text file into an Excel XLSX file using the RubyXL library https://github.com/weshatheleopard/rubyXL
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'
require 'rubyXL'
require 'rubyXL/convenience_methods/cell'
require 'rubyXL/convenience_methods/color'
require 'rubyXL/convenience_methods/font'
require 'rubyXL/convenience_methods/workbook'
require 'rubyXL/convenience_methods/worksheet'
@misshie
misshie / parse-duplicated-options.rb
Last active March 28, 2017 03:25
Parse duplicated command-line options into a hash of arrays using Ruby
#!/usr/bin/env ruby
# $ ./klass.rb --hoge=fuga --hoge=puyo --foo=bar
# {:h=>false, :hoge=>["fuga", "puyo"] :foo=>["bar"]}
require 'optparse'
class Klass
attr_reader :opts
def initialize(opts)
@misshie
misshie / blink-enclosure.rb
Created October 5, 2016 02:22
Blink all locate LEDs of an SAS-enclosure binded to a block device
@misshie
misshie / PhysPosGrouping.vb
Last active November 9, 2015 02:59
An Excel VBA macro: Alterternate background of each row according to a key column (column C such as "chr1:123-123;A>T")
Sub PhysPosGrouping()
Dim oRange As Range
Dim lRorB As Long
Dim lColR As Long
Dim gcount As Long
Set oRange = ActiveSheet.UsedRange
lRowB = oRange.Row + oRange.Rows.Count - 1
lColR = oRange.Column + oRange.Columns.Count - 1
@misshie
misshie / byobua
Last active November 8, 2015 23:43
An application sample of "peco" to select attaching byobu session
#!/bin/bash
sel=$(byobu ls | peco | cut -d ":" -f 1)
if [ ! -z "${sel}" ] ; then
byobu a -t ${sel}
fi