Skip to content

Instantly share code, notes, and snippets.

@knugie
knugie / decrypt.rb
Last active March 26, 2022 07:56 — forked from equivalent/gist:b492f6779e99ee9defb2
WIP: Ruby AES Encryption using AES-256-CBC
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
@knugie
knugie / keyboard_controller.rb
Last active March 10, 2022 07:57 — forked from efi/keyboard_controller.rb
Send system keyboard events in JRuby via java.awt.Robot
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
#!/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
}
@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 / meta_module3.rb
Last active December 21, 2015 13:38
metaprogramming with modules in ruby This will only work with ruby 2.0 http://ruby-doc.org/core-2.0/Module.html#method-i-prepend
module One
def a(*)
puts 'One...'
super
end
end
module Two
def a(*)
puts 'Two...'