Skip to content

Instantly share code, notes, and snippets.

Avatar
👍
Love your code.

CHIKURA Shinsaku chsh

👍
Love your code.
View GitHub Profile
@chsh
chsh / hash_pathable.rb
Created Jul 10, 2021
Allow to lookup ruby's Hash using xpath like syntax.
View hash_pathable.rb
# usage:
# hash = { a: 1, b: { x: 'y'}, c: [{m: 10, n: 2}, { m: 20, n: 3} ] }
# hash.path('/a') => 1
# hash.path('b/x') => 'y'
# hash.path('/c[0]/n') => 2
# hash.path('/not/existent/key') => nil
# GenericUtils
module GenericSupport
module Pathable
@chsh
chsh / view_component_helper.rb
Created Jun 4, 2021
ViewComonent helper using DSL flavor.
View view_component_helper.rb
# usage:
# = render vc.path1.path2(:name, arg1: 'a')
# or
# = render vc('path1/path2/name', arg1: 'a')
module ViewComponentHelper
class VisualComponentChainer
def initialize
@nest = []
@chsh
chsh / ffx265.sh
Last active May 26, 2021
Aggregate pics to hevc(H.265). - ffmpeg encoding params for apple macbook with acceralation hardware.
View ffx265.sh
#!/bin/bash
for arg; do
dir=${arg}
# ffmpeg -framerate 60 -i $dir/seq%06d.jpg -vf deflicker=s=10:m=2 -c:v hevc_videotoolbox -b:v 200000k -tag:v hvc1 $dir.mp4
ffmpeg -framerate 60 -pattern_type glob -i "$dir/seq*.jpg" -vf deflicker=s=10:m=2 -c:v hevc_videotoolbox -b:v 200000k -tag:v hvc1 $dir.mp4
done
@chsh
chsh / example.slim
Last active Apr 30, 2021
Idea: Writing Tailwind CSS with ruby's method chain.
View example.slim
body(class=tw.text.px_4.py_2.hover__text_gray_200)
button(class=tw.btn.btn_primary) CLICK!
@chsh
chsh / zoom_signature_generator.rb
Created Apr 1, 2021
Zoom Video SDK client signature generator.
View zoom_signature_generator.rb
require 'jwt'
def generate_instant_token(topic, password: '')
sdk_key = ENV['ZOOM_SDK_KEY']
sdk_secret = ENV['ZOOM_SDK_SECRET']
iat = Time.now.to_i
exp = iat + 60 * 60 * 2
View convert-seconds-into-hh-mm-ss-in-ruby.rb
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
@chsh
chsh / detect_num_non_gray_colors.rb
Last active May 22, 2018
Detect num non gray colors using ImageMagick's convert command.
View detect_num_non_gray_colors.rb
list = `convert 9784152097712_10.jpg -format %c histogram:info:`.split("\n")
rgbs = list.map { |line| $1 if line =~ /\s+#([\dA-F]+)\s+/ }
num_non_gray = rgbs.select { |rgb|
r = rgb[0,2]; g = rgb[2,2]; b = rgb[4,2]
r != g || g != b
}.count
num_non_gray > 0 # true: 正しい画像, false: (一色かどうかはわからないが)グレー画像
@chsh
chsh / Gemfile
Last active Mar 6, 2018
Allow to refer user related info using thread global `Current` (like CurrentAttributes in Rails 5.2 ;-)
View Gemfile
gem 'request_store'
@chsh
chsh / file0.rb
Last active Oct 8, 2017
irbでソースコードフォルダ毎に履歴を分けて保存する ref: http://qiita.com/chshii/items/ba10dcc8dcc24b315d16
View file0.rb
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 80000 # このあたりはお好みで。
require 'digest/md5'
require 'fileutils'
history_base = File.join(ENV['HOME'], '.irb', 'histories')
FileUtils.mkdir_p history_base unless Dir.exist? history_base
pwd_hash = Digest::MD5.hexdigest(`pwd`.chomp)
IRB.conf[:HISTORY_FILE] = File.join(history_base, pwd_hash)
@chsh
chsh / amazon_url_shortener.js
Created Sep 3, 2017
Amazon.co.jp URL shortener bookmarklet.
View amazon_url_shortener.js
javascript:var asin=document.getElementById('ASIN').value;location.href='http://amazon.jp/dp/'+asin;