Skip to content

Instantly share code, notes, and snippets.

@granolocks
granolocks / abuse_sqlite.rb
Last active May 23, 2016 20:25
lets try to abuse sqlite for fun and profit
require 'data_mapper'
require 'thread'
werdz = %w{
The beet is the most intense of vegetables. The radish, admittedly,
is more feverish, but the fire of the radish is a cold fire, the fire of
discontent not of passion. Tomatoes are lusty enough, yet there runs through
tomatoes an undercurrent of frivolity. Beets are deadly serious. Slavic
peoples get their physical characteristics from potatoes, their smoldering
inquietude from radishes, their seriousness from beets. The beet is the
@granolocks
granolocks / codingchallenge.md
Last active March 10, 2021 14:36
Useful for Coding Exercises

Do as many of the following as you can in the time given. Order of completion does not matter.

CIPHER

Implement a Caesar cipher, both encoding and decoding. The key is an integer from 1 to 25. This cipher rotates the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts "HI" to "JK", but key 20 encrypts "HI" to "BC". This simple "monoalphabetic substitution cipher" provides almost no security, because an attacker who has the encoded message can either use frequency analysis to guess the key, or just try all 25 keys.

@granolocks
granolocks / badtz.rb
Created April 15, 2015 22:41
bad tz conversion
to_pst = Proc.new do |unix|
t = Time.at(unix).utc
t -= (7*60*60) # shift back 7 hours to fake PST
"#{t.strftime("%Y-%m-%d %H:%M:%S")} PST"
end
@granolocks
granolocks / worst_possible.rb
Created April 14, 2015 13:49
worst possible ruby
p = Proc.new do
(0..32).
to_a.
map do |_|
(
('a'..'z').to_a +
%w{ ' " ; : \{ \} , . - _ = + ( ) * & ^ % $ # @ ! } +
[' ']
).shuffle.first
end
@granolocks
granolocks / pwniesay
Last active August 29, 2015 14:13
Pwnie Say
#!/usr/bin/env ruby
MAX_WIDTH = 40
TOP_CAP = "_"
BOTTOM_CAP = "-"
SINGLE_ROW_LEFT_END = "<"
SINGLE_ROW_RIGHT_END = ">"
MULTI_ROW_END = "|"
UP_LEFT_CORNER = "/"
UP_RIGHT_CORNER = "\\"
@granolocks
granolocks / rpn_spec.rb
Created January 7, 2015 02:15
Reverse Polish Notation Calculator
require 'rspec'
module RPN
def calculate(input="")
do_calculate(input.split(' ').map{|t|t == "#{t.to_i}" ? t.to_i : t.to_sym})
end
def do_calculate(tokens=[])
if tokens.length == 3
x,y,opp = tokens
@granolocks
granolocks / attr_stat.rb
Created December 23, 2014 19:33
attr_stat
#!/usr/bin/env ruby
require 'csv'
@file = ARGV[0]
@attr = ARGV[1]
if ARGV[2]
@pattern = eval(ARGV[2]) # >:)
end
if @file && @attr
@granolocks
granolocks / test_helper.erl
Created June 10, 2014 13:29
test_helper.erl
-module(list_helper).
-author("granolocks").
-export([
test/0,
test/1,
test/2,
index/2
]).
@granolocks
granolocks / class_module.rb
Last active August 29, 2015 13:56
variations on class module relationships
module Mojule
def self.something
puts "something!"
end
def something_else
puts "something else!"
end
def still_something_else
@granolocks
granolocks / verify.sh
Last active January 3, 2016 12:49
Verify Y / N
f_verify(){
echo "1. Yes"
echo "2. No"
read -p "Are you sure?: " input
matches=$(echo $input | grep -ie "^[Y|1]")
if [ $? -ne 0 -a -n $matches ]; then
echo "You must enter 'yes' to continue."
exit