Skip to content

Instantly share code, notes, and snippets.

View chsh's full-sized avatar
👍
Love your code.

CHIKURA Shinsaku chsh

👍
Love your code.
View GitHub Profile
@chsh
chsh / to-circle.sh
Created April 14, 2022 05:10
Crop square image to circle.
#!/bin/bash
#
# usage: to-path.sh files(to crop circle)
#
for path in "$@"
do
convert $path \( +clone -threshold -1 -negate -fill white -draw "circle `identify -format %w $path | awk '{print $1/2}'`, `identify -format %h $path | awk '{print $1/2}'` `identify -format %w $path | awk '{print $1/2}'`, 0" \) -alpha Off -compose copy_opacity -composite circle-`basename $path`
done
@chsh
chsh / rials-template-with-good-job.rb
Created January 23, 2022 05:29
rails template with goo_job
# rails basic configuration
environment_development_data = <<CODE
config.action_mailer.default_url_options = { host: 'http://localhost:3000' }
config.active_job.queue_adapter = :good_job
CODE
environment environment_development_data, env: 'development'
environment_production_data = <<CODE
config.action_mailer.default_url_options = { host: 'SET-YOUR-SERVICE-HOST-HERE' }
@chsh
chsh / hash_pathable.rb
Created July 10, 2021 23:46
Allow to lookup ruby's Hash using xpath like syntax.
# 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 June 4, 2021 11:54
ViewComonent helper using DSL flavor.
# 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 01:33
Aggregate pics to hevc(H.265). - ffmpeg encoding params for apple macbook with acceralation hardware.
#!/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 April 30, 2021 13:30
Idea: Writing Tailwind CSS with ruby's method chain.
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 April 1, 2021 13:50
Zoom Video SDK client signature generator.
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
@chsh
chsh / convert-seconds-into-hh-mm-ss-in-ruby.rb
Created October 20, 2019 11:14 — forked from shunchu/convert-seconds-into-hh-mm-ss-in-ruby.rb
Convert seconds into HH:MM:SS in Ruby
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 06:53
Detect num non gray colors using ImageMagick's convert command.
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 March 6, 2018 05:04
Allow to refer user related info using thread global `Current` (like CurrentAttributes in Rails 5.2 ;-)
gem 'request_store'