Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

smagch smagch

🏠
Working from home
View GitHub Profile
@smagch
smagch / useTimeout.js
Created Jul 16, 2020
useTimeout React hook
View useTimeout.js
const useTimeout = (delay) => {
const [ timeoutFunc, setFunction ] = useState(null);
useEffect(
() => {
if (!timeoutFunc) {
return;
}
let mounted = true;
@smagch
smagch / convert_4k.sh
Created May 12, 2020
convert multiple movies
View convert_4k.sh
#!/usr/bin/env bash
distdir="$(pwd)/dist$RANDOM$RANDOM"
mkdir "$distdir"
for input in "$@"; do
base=$(basename "$input")
output="$distdir/${base,,}"
ffmpeg -i "$input" \
@smagch
smagch / encode_4k.sh
Last active Mar 20, 2020
ffmpeg for a6400
View encode_4k.sh
# ffmpeg -i input.mp4 -crf 28 -b:a 128k -color_range 1 -color_trc arib-std-b67 -color_primaries bt2020 -colorspace bt2020nc output_28.mp4
# ffmpeg -i output28.mp4 -c copy -map 0 -segment_time 00:01:00 -reset_timestamps 1 -f segment output_%03d.mp4
ffmpeg -i input.mp4 -crf 28 -b:a 128k -color_range 1 -color_trc arib-std-b67 -color_primaries bt2020 -colorspace bt2020nc -segment_time 60 -f segment -reset_timestamps 1 output_%03d.mp4
@smagch
smagch / index.html
Created Nov 26, 2019
open/collapse for an element with `height: auto`
View index.html
<html>
<head>
<style>
.item {
display: block;
overflow: hidden;
}
.head {
height: 30px;
line-height: 30px;
@smagch
smagch / index.html
Created Oct 16, 2019
iOS focus test
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>iOS focus Test</title>
<style>
.modal {
transition: opacity 0.3s;
@smagch
smagch / hook.js
Last active Jun 28, 2019
react hooks: resize check
View hook.js
import { useState, useEffect } from 'react';
import { debounce } from 'lodash';
export const useResizeState = () => {
const [ resizing, setResizing ] = useState(false);
useEffect(() => {
const handleResizeEnd = debounce(() => {
setResizing(false);
}, 300);
@smagch
smagch / slide.html
Last active Mar 4, 2019
Simple slider: should fix margin
View slide.html
<html>
<style>
html, body {
margin: 0;
}
.hidden-wrapper {
overflow: hidden;
}
.wrapper {
width: 100%;
@smagch
smagch / README.md
Last active Nov 12, 2018
gftable: transform json input to GitHub Flavored markdown table
View README.md

gftable

Command-line which transform JSON array input to GFM Table

Usage

$ echo '{ "rows": [ { "id": 1, "name": "Tomoya" }, { "id": 2, "name": "Tomoko" } ] }' | jq .rows | gftable
@smagch
smagch / README.md
Created Oct 25, 2018
Algolia Example
View README.md
@smagch
smagch / index.html
Created Aug 28, 2018
horizontal scroll testing: Intersection Observer API
View index.html
<!DOCTYPE html>
<html>
<head>
<style>
.h-container {
position: absolute;
left: 0;
right: 0;
top: 100px;
height: 300px;