View pdf2jpg.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gs -dNOPAUSE -sDEVICE=jpeg -r300 -dJPEGQ=100 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile="document-%02d.jpg" "document.pdf" -dBATCH |
View decrypt.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
################ | |
# Public Input # | |
################ | |
hex_message = 'a9a08f273d9e96d567ccc3db8f6a6634c895973a260e2b7cb36c1dde457293102163900cc12ffe4ec51aa02db70a0979b510911fa99d50aeadd67f7ff0c37a8ab82e5e45cb4b7d713e8365b1f0e67e188e2807fa31f674f25318de6de122517a06cfa018e0edf308eeaa87530720ecdcac42' | |
auth_data = 'something' | |
################ | |
# Secret Input # |
View decrypt.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
# We use the AES 256 bit cipher-block chaining symetric encryption. | |
# AES 256 is virtually impenetrable using brute-force methods. | |
# However, CBC introduces a data integrity vulnerability (stream cipher attacks). | |
# We should use HMAC or GCM to mitigate the issue. | |
alg = 'aes-256-cbc' | |
cipher = OpenSSL::Cipher::Cipher.new(alg) | |
cipher.decrypt |
View keyboard_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KeyboardController | |
def initialize | |
@robot = java.awt.Robot.new | |
end | |
def type *args | |
[args].flatten.map(&:to_s).map{|s|s.split(/\s+/)}.flatten.map(&:upcase).each do |n| | |
press, name = (n[0]=="-") ? [false,n[1..-1]] : [true,n] | |
press ? @robot.key_press(@code) : @robot.key_release(@code) if @code = java.awt.event.KeyEvent.const_get("VK_#{name}") | |
end | |
self |
View example_encrypt_decrypt.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From https://tjay.dev/howto-working-efficiently-with-large-files-in-ruby/ | |
# Encrypt | |
cipher = OpenSSL::Cipher::AES256.new(:CBC) | |
cipher.encrypt | |
cipher.key = KEY | |
cipher.iv = IV | |
file = nil | |
enc_file = nil |
View example.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# brew install figlet | |
# showfigfonts | |
# example: | |
figlet -D -n -f fender "The quick brown fox jumps over the lazy dog [ \ ] { | } ~" | |
# |''||''| '|| '|| | |
# || || '' || | |
# || ||''|, .|''|, .|''||` '|| ||` || .|'', || //` | |
# || || || ||..|| || || || || || || ||<< | |
# .||. .|| || `|... `|..|| `|..'|. .||. `|..' .|| \\. |
View solution.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[*100..999].count{ |x| (1..x).count { |i| x % i == 0 } == 3 } | |
# => 7 |
View worker_pool.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://hspazio.github.io/2017/worker-pool/ | |
SIZED_QUEUE_SIZE = 10 | |
############################################################################ | |
def fib(n) | |
n < 2 ? n : fib(n-1) + fib(n-2) | |
end | |
############################################################################ |
View mount-tmp.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
size=1024 # MB | |
mount_point=$HOME/tmp | |
name=$(basename "$mount_point") | |
usage() { | |
echo "usage: $(basename "$0") [mount | umount | remount | check | orphan]" \ | |
"(default: mount)" >&2 | |
} |
NewerOlder