Skip to content

Instantly share code, notes, and snippets.

@knugie
knugie / count_files.sh
Created February 5, 2016 21:02
List number of files in each directory
find -P . -type f | rev | cut -d/ -f2- | rev | cut -d/ -f1-2 | cut -d/ -f2- | sort | uniq -c
@knugie
knugie / git_hub_pretty_print_markdown_bookmarklet.txt
Created January 28, 2016 22:28
Bookmarklet to pretty-print GitHub markdown file
javascript:(function(e,a,g,h,f,c,b,d)%7Bif(!(f=e.jQuery)%7C%7Cg>f.fn.jquery%7C%7Ch(f))%7Bc=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function()%7Bif(!b&&(!(d=this.readyState)%7C%7Cd=="loaded"%7C%7Cd=="complete"))%7Bh((f=e.jQuery).noConflict(1),b=1);f(c).remove()%7D%7D;a.documentElement.childNodes%5B0%5D.appendChild(c)%7D%7D)(window,document,"1.3.2",function($,L)%7B$('%23header, .pagehead, .breadcrumb, .commit, .meta, %23footer, %23footer-push, .wiki-actions, %23last-edit, .actions, .header,.site-footer,.repository-sidebar,.file-navigation,.gh-header-meta,.gh-header-actions,#wiki-rightbar,#wiki-footer,.commit-tease').remove();%20$('%23files,%20.file').css(%7B%22background%22:%22none%22,%20%22border%22:%22none%22%7D);%20$('link').removeAttr('media');%7D); var removeMe = document.getElementsByClassName("file-header")[0]; removeMe.parentNode.removeChild(removeMe);
@knugie
knugie / AES-256-CBC-sample.rb
Last active January 28, 2016 22:05
AES - symmetric algorithms for encryption and decryption
require 'openssl'
require 'digest/sha2'
# Config
alg = "AES-256-CBC"
# Key
key = OpenSSL::Cipher::Cipher.new(alg).random_key
# Init Digest
@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 / wget_entire_site.md
Last active May 25, 2022 19:47
Download entire webpage using wget
@knugie
knugie / mts_to_mp4.sh
Last active October 2, 2017 18:20
Convert (Sony) MTS files to MP4
ffmpeg -i in.mts -c:v mpeg4 -qscale:v 5 -acodec libmp3lame -b:a 192k out.mp4
@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
/*jslint browser: true, indent: 2 */
(function () {
'use strict';
var rgb, style, idx = 0, store = {}, tiles = document.getElementById('box').childNodes;
for (idx; idx < tiles.length; idx += 1) {
rgb = tiles[idx].style.backgroundColor.split("(")[1].split(")")[0].split(",");
store[Math.sqrt(Math.pow(rgb[0], 2), Math.pow(rgb[2], 2), Math.pow(rgb[2], 2))] = tiles[idx];
}
style = Object.keys(store).map(function (key) { return [key, store[key]]; }).
sort(function (a, b) { return parseInt(a[0], 10) < parseInt(b[0], 10) ? 1 : -1; })[0][1].style;
@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 / sort_quiz_question.rb
Created January 10, 2015 17:11
ruby sort quiz question
ary = [['a', :hello], ['b', :foo], ['b', :bar], ['b', :baz], ['a', :world]]
# QUIZ:
# How do you sort "ary" so equal objects stay in the same relative order to each other?
# "ary" should be sorted by the first element of each entry.
# Try now: http://tryruby.org/
expected = [['a', :hello], ['a', :world], ['b', :foo], ['b', :bar], ['b', :baz]]
# HINT: