Skip to content

Instantly share code, notes, and snippets.

@knugie
knugie / reduce_pdf.sh
Created October 24, 2013 19:12
reduce pdf size
#reduce PDF size
#-dPDFSETTINGS
# /screen
# /ebook
# /printer
# /prepress
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -sOutputFile=out.pdf in.pdf
@knugie
knugie / jpg_to_2048.sh
Last active December 4, 2023 06:20
resize and optimize JPEG images to box-fit 2048x2048 pixels with 80% JPEG quality
#! /usr/bin/env bash
# brew install imagemagick
# brew install jpegoptim
mkdir 2048
for image in *.[jJ][pP][eE]?[gG]; do
convert $image -resize 2048x2048\> ./2048/$image
jpegoptim --strip-all -q --max=80 ./2048/$image
done
@knugie
knugie / integer_underscore.rb
Last active May 26, 2023 15:18
Format Ruby Integers with underscore
# <#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 / .zshrc
Last active February 4, 2023 19:10
# Use alt+arrow to move cursor by word# Mac OS X El Capitan # iTerm2 # zsh # ~/.zshrc
# Skip forward/back a word with opt-arrow
# https://gist.github.com/knugie/fc9964695951b4c13ed3
bindkey -e
bindkey '\e\e[C' forward-word
bindkey '\e\e[D' backward-word
@knugie
knugie / mov2mp4.sh
Last active October 6, 2022 14:22
convert .mov to .mp4 using ffmpeg
ffmpeg -i movie.mov -vcodec copy -acodec copy out.mp4
@knugie
knugie / cancelAllRequestAnimFrame.js
Created October 10, 2014 03:39
cancel all request animation frames
window.cancelRequestAnimFrame = ( function() {
return window.cancelAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFrame ||
window.oCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame ||
clearTimeout
} )();
for (var i = 1; i < 99999; i++) {
@knugie
knugie / GIF-Screencast-OSX.md
Last active May 25, 2022 19:56 — forked from dergachev/GIF-Screencast-OSX.md
Screencast to animated GIF

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 19:55
Dump and Restore binary files in hex format
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 19:47
Download entire webpage using wget
@knugie
knugie / count_unique_elements_in_array.rb
Last active May 25, 2022 19:47
Count unique elements in Array
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