├── README ├── bitify ├── README └── bitify ├── xsrfify ├── README └── xsrfify.rb └── alarm ├── README └── alarm /README: -------------------------------------------------------------------------------- 1 | This repository contains scripts too small to have their own repository. 2 | -------------------------------------------------------------------------------- /bitify/README: -------------------------------------------------------------------------------- 1 | "bitify" is a simple command line script to shorten a URL with http://bit.ly. 2 | It screen-scrapes the web site, so you don't need an account. 3 | 4 | Usage example: 5 | 6 | $ ./bitify 'http://www.example.com' 7 | -------------------------------------------------------------------------------- /xsrfify/README: -------------------------------------------------------------------------------- 1 | This script takes a POST request from stdin and returns a form with the action 2 | set to the POST request's URL and hidden form fields for all of the parameters 3 | in the body. 4 | 5 | $ ruby xsrfify.rb -h 6 | Usage: ./xsrfify.rb [options] 7 | -n, --newlines Use \n as line delimiter when parsing the POST request instead of \r\n 8 | -f, --full-page Print a full HTML page ready for XSRF instead of just the form 9 | -h, --help Show this help 10 | 11 | -------------------------------------------------------------------------------- /alarm/README: -------------------------------------------------------------------------------- 1 | == Introduction == 2 | 3 | "alarm" is a simple command line script to add a new message which should pop 4 | up at a certain time to a remind file. I'm starting remind with the following 5 | command line in my Window Manager's (XMonad) startup script: 6 | 7 | remind -z '-k zenity --info --text="%s" &' ~/.alarm_reminders 8 | 9 | This puts remind in 'daemon' mode, periodically checking the file 10 | ~/.alarm_reminders for new entries. It will then run Zenity to pop up a 11 | message box at due time. 12 | 13 | Messages can either have an absolute or relative time. Examples: 14 | 15 | - 10:00 My Message 16 | - 10s My Message 17 | - 30m My Message 18 | - 1h My Message 19 | 20 | 21 | == Example == 22 | 23 | Writing 24 | 25 | alarm '30m Dinner is ready' 26 | 27 | on Dec 27, 2009 at 12:00 o'clock will add the entry 28 | 29 | REM Dec 27 2009 AT 12:30 MSG %3 %"dinner is ready%"% 30 | 31 | 32 | == Requirements == 33 | 34 | - Zenity http://live.gnome.org/Zenity 35 | - Remind http://www.roaringpenguin.com/products/remind 36 | -------------------------------------------------------------------------------- /bitify/bitify: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | ############################################################## 4 | # # 5 | # Written by Patrick Hof # 6 | # http://www.offensivethinking.org # 7 | # # 8 | # This software is licensed under the Creative # 9 | # Commons CC0 1.0 Universal License. # 10 | # To view a copy of this license, visit # 11 | # http://creativecommons.org/publicdomain/zero/1.0/legalcode # 12 | # # 13 | ############################################################## 14 | 15 | # "bitify" is a simple command line script to shorten a URL with http://bit.ly. 16 | # It screen-scrapes the web site, so you don't need an account. 17 | 18 | require 'open-uri' 19 | 20 | unless ARGV[0] 21 | puts "Usage: #{__FILE__} " 22 | exit 23 | end 24 | 25 | site = open("http://bit.ly/?url=#{ARGV[0]}").read() 26 | site =~ /shortUrl": "(http.*?)",/ 27 | puts $1 28 | -------------------------------------------------------------------------------- /alarm/alarm: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | ############################################################## 4 | # # 5 | # Written by Patrick Hof # 6 | # http://www.offensivethinking.org # 7 | # # 8 | # This software is licensed under the Creative # 9 | # Commons CC0 1.0 Universal License. # 10 | # To view a copy of this license, visit # 11 | # http://creativecommons.org/publicdomain/zero/1.0/legalcode # 12 | # # 13 | ############################################################## 14 | 15 | # == Introduction == 16 | # 17 | # "alarm" is a simple command line script to add a new message which should pop 18 | # up at a certain time to a remind file. I'm starting remind with the following 19 | # command line in my Window Manager's (XMonad) startup script: 20 | # 21 | # remind -z '-k zenity --info --text="%s" &' ~/.alarm_reminders 22 | # 23 | # This puts remind in 'daemon' mode, periodically checking the file 24 | # ~/.alarm_reminders for new entries. It will then run Zenity to pop up a 25 | # message box at due time. 26 | # 27 | # Messages can either have an absolute or relative time. Examples: 28 | # 29 | # - 10:00 My Message 30 | # - 10s My Message 31 | # - 30m My Message 32 | # - 1h My Message 33 | # 34 | # 35 | # == Example == 36 | # 37 | # Writing 38 | # 39 | # alarm '30m Dinner is ready' 40 | # 41 | # on Dec 27, 2009 at 12:00 o'clock will add the entry 42 | # 43 | # REM Dec 27 2009 AT 12:30 MSG %3 %"dinner is ready%"% 44 | # 45 | # 46 | # == Requirements == 47 | # 48 | # - Zenity http://live.gnome.org/Zenity 49 | # - Remind http://www.roaringpenguin.com/products/remind 50 | 51 | ALARMS = "~/.alarm_reminders" 52 | FACTOR = {"s" => 0, "m" => 1, "h" => 2} 53 | NOW = Time.now 54 | 55 | case ARGV[0] 56 | when /^\s*(\d{1,2}:\d{2})\s*(.*)\s*$/ 57 | time, message = $1, $2 58 | when /^\s*(\d+)([smh])\s*(.*)\s*$/ 59 | time = (NOW + ($1.to_i * (60 ** FACTOR[$2]))).strftime("%H:%M") 60 | message = $3 61 | else 62 | system("zenity --info --text=\"Wrong format: #{ARGV[0]}\"") 63 | exit 1 64 | end 65 | 66 | unless message.empty? 67 | File.open(ALARMS, "a") do |f| 68 | f.write("REM #{NOW.strftime("%b")} #{NOW.day} #{NOW.year} AT #{time} MSG %3 %\"#{message}%\"%\n") 69 | end 70 | else 71 | system("zenity --info --text=\"Empty Message: #{ARGV[0]}\"") 72 | exit 1 73 | end 74 | -------------------------------------------------------------------------------- /xsrfify/xsrfify.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | ############################################################## 4 | # # 5 | # Written by Patrick Hof # 6 | # http://www.offensivethinking.org # 7 | # # 8 | # This software is licensed under the Creative # 9 | # Commons CC0 1.0 Universal License. # 10 | # To view a copy of this license, visit # 11 | # http://creativecommons.org/publicdomain/zero/1.0/legalcode # 12 | # # 13 | ############################################################## 14 | 15 | # This script takes a POST request from stdin and returns a form with the action 16 | # set to the POST request's URL and hidden form fields for all of the parameters 17 | # in the body. 18 | # 19 | # Be aware of a common pitfall: If you have an element with the name or id 20 | # "submit" in your post data (and the chances are high), then the JavaScript 21 | # submit() function won't work anymore. Just use the "-d" option or delete the 22 | # element from the HTML source manually. 23 | require 'cgi' 24 | require 'optparse' 25 | 26 | options = { 27 | :delimiter => "\r\n", 28 | :full => false, 29 | :delsubmit => false 30 | } 31 | OptionParser.new do |opts| 32 | opts.banner = "Usage: #{__FILE__} [options]" 33 | 34 | opts.on("-n", "--newlines", 'Use \n as line delimiter when parsing the POST request instead of \r\n') do |n| 35 | options[:delimiter] = "\n" 36 | end 37 | opts.on("-f", "--full-page", "Print a full HTML page ready for XSRF instead of just the form") do 38 | options[:full] = true 39 | end 40 | opts.on("-d", "--delete-submit", 'Automatically delete parameters with the name "submit"') do 41 | options[:delsubmit] = true 42 | end 43 | opts.on("-h", "--help", "Show this help") do 44 | puts opts 45 | exit 46 | end 47 | end.parse! 48 | 49 | # HTML header and footer for a full HTML page with JavaScript for automatic 50 | # submission of the form data. This will trigger the post request as soon as the 51 | # HTML page is fully loaded. 52 | html_header = < 54 | 55 | 66 | 67 | 68 | EOF 69 | html_footer = " \n" 70 | 71 | 72 | headers, body = $stdin.read().split(options[:delimiter]*2) 73 | if body 74 | puts html_header if options[:full] 75 | url = headers.split("\r\n")[0].split(" ")[1] 76 | data = CGI.unescape(body.chomp).split("&").map { |x| x.split("=") } 77 | puts %Q(
) 78 | data.each do |i| 79 | unless (options[:delsubmit] && i[0] == "submit") 80 | puts %Q( ) 81 | end 82 | end 83 | puts "
" 84 | puts html_footer if options[:full] 85 | end 86 | --------------------------------------------------------------------------------