Skip to content

Instantly share code, notes, and snippets.

@knugie
knugie / GIF-Screencast-OSX.md
Last active May 25, 2022 — forked from dergachev/GIF-Screencast-OSX.md
Screencast to animated GIF
View GIF-Screencast-OSX.md

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@knugie
knugie / plain_binary_dump_and_restore.sh
Last active May 25, 2022
Dump and Restore binary files in hex format
View plain_binary_dump_and_restore.sh
xxd -p org.bin | tr -d '\n' > tmp
xxd -p -r tmp > cpy.bin
@knugie
knugie / wget_entire_site.md
Last active May 25, 2022
Download entire webpage using wget
View wget_entire_site.md
@knugie
knugie / count_unique_elements_in_array.rb
Last active May 25, 2022
Count unique elements in Array
View count_unique_elements_in_array.rb
require 'benchmark'
require 'open3'
require 'histogram/array'
array = Array.new(10_000_000) { rand(60) }
puts 'uniq, count:'
uniq_count = Benchmark.measure do
array.uniq.map { |key| array.count(key) }
end
@knugie
knugie / keybase.md
Last active May 25, 2022
Keybase proof
View keybase.md

Keybase proof

I hereby claim:

  • I am knugie on github.
  • I am knugie (https://keybase.io/knugie) on keybase.
  • I have a public key whose fingerprint is 4F54 2255 6028 FAFB 7458 E545 4276 8876 DFB2 3E2B

To claim this, I am signing this object:

@knugie
knugie / integer_underscore.rb
Last active May 25, 2022
Format Ruby Integers with underscore
View integer_underscore.rb
# <#Integer>.underscore(n) returns a string, seperating n digits by
# an underscore. n is 3 by default. This is supposed to make
# working with large numbers easier.
# example:
# 1000000000000000.underscore #=> "1_000_000_000_000_000"
# 100_00000_00_0000_00.underscore #=> "1_000_000_000_000_000"
# 987654321.underscore(6) #=> "987_654321"
class Integer
def underscore(s=3)
self.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1_")
@knugie
knugie / pdftk_snippets.sh
Last active May 25, 2022
usefull pdftk commands
View pdftk_snippets.sh
# merge all pdf files from a directory to a single pdf file
pdftk *.pdf cat output out.pdf
# reverse page order of a pdf file
PDFTK_PAGES=$(pdftk in.pdf dump_data | grep NumberOfPages | sed "s/^.*: //")
pdftk in.pdf cat $PDFTK_PAGES-1 output out.pdf
# Strip metadata in pdf
PDFTK_FILE=in.pdf
pdftk $PDFTK_FILE dump_data | sed -e 's/\(InfoValue:\)\s.*/\1\ /g' | pdftk $PDFTK_FILE update_info - output out.pdf
@knugie
knugie / rgb2hsl.rb
Last active May 25, 2022
Convert RGB to HSL color model
View rgb2hsl.rb
def rgb2hsl(r,g,b)
= r.to_f / 255
= g.to_f / 255
= b.to_f / 255
c_max = [, , ].max
c_min = [, , ].min
Δ = c_max - c_min
h = Δ.zero? ? 0 : (60 * case c_max
when then (( - ) / Δ) % 6
when then (( - ) / Δ) + 2
@knugie
knugie / mov2mp4.sh
Last active May 25, 2022
convert .mov to .mp4 using ffmpeg
View mov2mp4.sh
ffmpeg -i movie.mov -vcodec copy -acodec copy out.mp4
@knugie
knugie / mp42gif.sh
Last active May 25, 2022
Generate a gif from an mp4 file
View mp42gif.sh
# Using ffmpeg
ffmpeg -y -i video.mp4 -vf fps=1,scale=600:-1:flags=lanczos,palettegen palette.png
ffmpeg -i video.mp4 -i palette.png -filter_complex "setpts=0.125*PTS,fps=5,scale=600:-1:flags=lanczos[x];[x][1:v]paletteuse" video.gif
# OR
# Using ffmpeg and gifsicle (https://www.lcdf.org/gifsicle/)
ffmpeg -i video.mp4 -s 600x400 -r 3 -f gif - | gifsicle --delay=3 > video.gif