Skip to content

Instantly share code, notes, and snippets.

@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 / export_table_to_csv.coffee
Created July 4, 2012 20:44
Export HTML table to CSV using javascript.
$("#btnExportHTMLToCSV").click((event) ->
$table = $("#tableToExport")
if !$table
return false
headers = []
csv = ""
$table.find("thead th").each(() ->
$th = $(this)
text = $th.text()
header = '"'+text+'"'
@shavit
shavit / worker_mongodb_queue.go
Created September 3, 2016 14:24
Go worker with MongoDB capped collection
package main
import (
"os"
"log"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"time"
)
@shavit
shavit / broadcast_udp.swift
Created November 14, 2016 03:03
Send a message using UDP in Swift 3
//: Playground - noun: a place where people can play
import Cocoa
import Darwin
func htons(value: CUnsignedShort) -> CUnsignedShort {
return (value << 8) + (value >> 8)
}
let INADDR_ANY = in_addr(s_addr: 0)
@shavit
shavit / mass_video_importer_1.rb
Created January 14, 2016 16:37
Mass video importer from *.csv files to tube sites.
#
# Import videos from CSV
#
# CSV row:
# 0 - embedded_video
# 1 - link
# 2 - categories (Funny;Euro;Cam)
# 3 - rating
# 4 - author username
@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 / 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 / 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"},
#
# If you are working with the foreman gem and .env files, you are probably need to load
# the environment varialbes from the .env file.
#
# Load the environment variables from the .env file in development.
open('.env', 'r').readlines.each {|l| kv = l.split('='); ENV[kv[0]] = kv[1];}
@shavit
shavit / haiku.ex
Created September 20, 2016 03:47 — forked from friggeri/haiku
random heroku-like name generator in Elixir
def generate_name do
# [[64][64]]
[["autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark",
"summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter",
"patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue",
"billowing", "broken", "cold", "damp", "falling", "frosty", "green",
"long", "late", "lingering", "bold", "little", "morning", "muddy", "old",
"red", "rough", "still", "small", "sparkling", "throbbing", "shy",
"wandering", "withered", "wild", "black", "young", "holy", "solitary",
"fragrant", "aged", "snowy", "proud", "floral", "restless", "divine",