Skip to content

Instantly share code, notes, and snippets.

@shavit
shavit / export.sh
Created October 30, 2018 22:26
Convert video to HLS
#!/bin/sh
video_file=${VIDEO_FILE:-video.mov}
mkdir out
ffmpeg -hide_banner -y -i $video_file \
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 800k -maxrate 856k -bufsize 1200k -b:a 96k -hls_segment_filename out/360p_%03d.ts out/360p.m3u8 \
-vf scale=w=842:h=480:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 1400k -maxrate 1498k -bufsize 2100k -b:a 128k -hls_segment_filename out/480p_%03d.ts out/480p.m3u8 \
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 2800k -maxrate 2996k -bufsize 4200k -b:a 128k -hls_segment_filename out/720p_%03d.ts out/720p.m3u8 \
@shavit
shavit / mime_types.ex
Created May 26, 2018 01:22
A list of file extensions and mime types
[{".323", "text/h323"},
{".3g2", "video/3gpp2"},
{".3gp", "video/3gpp"},
{".3gp2", "video/3gpp2"},
{".3gpp", "video/3gpp"},
{".7z", "application/x-7z-compressed"},
{".aa", "audio/audible"},
{".AAC", "audio/aac"},
{".aaf", "application/octet-stream"},
@shavit
shavit / CoreImageFilters.swift
Created May 12, 2018 18:13
CIFilter opacity
/*
Change the opacity of a CIFilter.
*/
func changeOpacity(to opacity: CGFloat, on filter: CIFilter, original image: UIImage) -> CIImage? {
guard let backgroundImage: CIImage = CIImage(image: image) else { fatalError() }
// The CIColorMatrix filter, will contain the requested filter and control its opacity
guard let overlayFilter: CIFilter = CIFilter(name: "CIColorMatrix") else { fatalError() }
let overlayRgba: [CGFloat] = [0, 0, 0, opacity]
let alphaVector: CIVector = CIVector(values: overlayRgba, count: 4)
@shavit
shavit / create_swarm.sh
Created August 15, 2017 01:25
Create swarm of Docker servers
#!/bin/sh
#
# Create a swarm manager and consul
#
# 1. Create 7 servers
# CONSUL_ADDRESS=
# SWARM_MANAGER_1_ADDRESS=
# SWARM_MANAGER_2_ADDRESS=
# LOAD_BALANCER_1_ADDRESS=
@shavit
shavit / generate_crt.sh
Created August 1, 2017 18:11
Create protobuf server with go
openssl genrsa -out server.key 2048
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 365
@shavit
shavit / index.html
Created June 1, 2017 17:51
Preload images on a webpage
<html>
<img src="" hide>
</html>
@shavit
shavit / go-revel.service
Created April 25, 2017 04:05
Go Revel Systemd script
[Unit]
Description=API web app
[Service]
PIDFile=/tmp/app.pid-0000
User=
Group=
WorkingDirectory=
ExecStart=PATH-TO-APP/bin/app/start.sh
@shavit
shavit / nginx-server.conf
Created March 12, 2017 18:10
Nginx configuration file for undefined requests
# Block access from IP
server {
listen 80 default;
server_name _;
ssl off;
# No response
return 444;
}
@shavit
shavit / free_space.sh
Created December 19, 2016 04:03
Find free space on Mac
#!/bin/sh
sudo perl -e'%h=map{/.\s/;99**(ord$&&7)-$`,$_}`du -h`;die@h{sort%h}'
@shavit
shavit / random.sh
Created December 13, 2016 23:18
Random string in Unix
#!/bin/sh
cat /dev/urandom | envcd 'a-f0-9' | head -c 16