Skip to content

Instantly share code, notes, and snippets.

View siutin's full-sized avatar
🐴

martin chan siutin

🐴
View GitHub Profile
const TreeNode = function (value) {
this.left = null
this.right = null
this.value = value
}
// accept muliple sorted unqiue numbers arrays
const buildTreeNodes = function (...arrs) {
let node = new TreeNode()
for (let i = 0; i < arrs.length; i++) {
@siutin
siutin / picture-in-picture.md
Last active August 11, 2018 19:24
simulate picture-in-picture for youtube in Ubuntu
mkdir ~/picture-in-pictures/
/bin/bash -c 'youtube-dl --ignore-errors --yes-playlist -o "${HOME}/./picture-in-picture/%(playlist_id)s-%(playlist_index)s" `xclip -selection c -o`'

start a player instance

@siutin
siutin / jruby_bug_spec.rb
Created November 30, 2017 15:01
jruby bug
require 'spec_helper'
RSpec.describe "jruby bug", type: :request do
# Creates a ruby module to namespace all the classes in if required
def register_module(module_name)
# dynamically create nested modules
module_names = module_name.split("::").inject([]) { |n, c| n << (n.empty? ? [c] : [n.last] + [c]).flatten }
puts "module_names: #{module_names}"
module_names.map do |module_name_array|
@siutin
siutin / tuplet.rs
Last active February 14, 2023 20:45
A Rust macro for unpacking a vector to a tuple of options
// A Rust macro for unpacking a vector to a tuple of options
// Original from https://stackoverflow.com/questions/29504873/unpack-a-take-iterator-into-a-tuple/43967765#43967765
macro_rules! tuplet {
{ ($y:ident $(, $x:ident)*) = $v:expr } => {
let ($y,$($x),*, _) = tuplet!($v ; 1 ; ($($x),*) ; ($v.get(0)) ); };
{ ($y:ident , * $x:ident) = $v:expr } => {
let ($y,$x) = tuplet!($v ; 1 ; () ; ($v.get(0)) ); };
{ ($y:ident $(, $x:ident)* , * $z:ident) = $v:expr } => {
let ($y,$($x),*, $z) = tuplet!($v ; 1 ; ($($x),*) ; ($v.get(0)) ); };
@siutin
siutin / human2bytes
Last active May 24, 2017 10:04
a bash script for converting human number to bytes
#!/bin/bash
INPUT=$1
PAT="^([0-9]+|([0-9]+).([0-9]+))([GgMmKk])?$"
if [[ ! $INPUT =~ $PAT ]]; then
echo "error: bad format"
exit 1
fi
@siutin
siutin / main.rb
Created December 25, 2016 12:27
Bulk rename with Exif Datetime (exiftool required)
require 'fileutils'
require 'pathname'
require 'mini_exiftool'
# ----------------------------------------------------------------------------------------------
source_root = "/tmp/source"
output_root = "/tmp/dest"
exts = "JPG,ORF"
# ----------------------------------------------------------------------------------------------
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
# myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
@siutin
siutin / gist:72f6a5b2c6dfdcc597c6
Last active August 29, 2015 14:18
defualt virtual host example - ubuntu-rails-apache-passenger
<VirtualHost *:80>
# ServerName localhost
DocumentRoot /var/www/app/current/public
<Directory /var/www/app/current/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted