Printable PDF create

http://www.analogpixel.org/pages/create/ is a webpage that pops up random words and pictures meant for idea generation / brain storming .  Problem is i’m going to be on a plane for 8 hours next month and won’t have access to wifi (I don’t think so.)  So I created a version of create that outputs a PDF of roughly the same stuff (minus the medium and illustration friday boxes)

http://www.analogpixel.org/pages/createpdf/?numpages=3

This was written in ruby with Sinatra and Prawn

To output a pdf in Sinatra using Prawn you do something like this:

get '/pages/createpdf/' do
  content_type 'application/pdf'

 pdf = Prawn::Document.new :page_layout => :landscape  do
     text "some text"
 end

 pdf.render
end

To load an image from a url instead of a file in Prawn you would:

require "open-uri"

..
..

image open("http://urltopic/pic.jpg"), :width => 170, :height => 170

Ruby Threaded SSH

#!/usr/bin/ruby
#
# http://www.ruby-doc.org/core-1.9.3/Thread.html
# http://net-ssh.github.com/ssh/v2/api/index.html
#
# usage:
# ssh-agent bash
# ssh-add key
# ./sshlist.rb <LIST> '<CMD>'
#

if ARGV.length != 2
  puts "./sshlist.rb <LIST> <CMD>"
  exit
end

require 'net/ssh'

threadlist = []

def con(hostname)

        result = `/bin/ping -q -c 2 #{hostname}`
        if not $?.exitstatus == 0
          puts "Unable to ping:" + hostname
          return -1
        end

        begin
          Net::SSH.start(hostname , 'root' ) do |ssh|
                  output = ssh.exec! ARGV[1]
                  puts hostname + ":" + output
          end
        rescue
          puts "failed on :" + hostname + ".."
        end
end

fileList = File.open(ARGV[0]).read.split("\n")

  while fileList.length > 0 do

  (1..30).each do |n|

        line = fileList.pop
        line.strip!

        threadlist.push Thread.new {  con line }
        if fileList.length == 0
          break
        end

  end

        threadlist.each do |th|
          th.join 10
        end

  end

This ruby script using net::ssh and a list of machines and connects to 30 at a time to run a command. After 10 seconds the batch of 30 is killed off and the next 30 start. net::ssh will take a password, but I just use ssh keys.

Continue reading