Lighting Talk Presentation

August 4, 2009

Here’s the PDF of the lightning talk…

ruby-vim

RubyVimrc

August 4, 2009

" http://www.vim.org/scripts/script.php?script_id=1984 fuzzyfinder
" http://www.vim.org/scripts/script.php?script_id=2540 snipMate
" http://www.vim.org/scripts/script.php?script_id=1643 supertab
" http://www.vim.org/scripts/script.php?script_id=1567 rails
" http://www.vim.org/scripts/script.php?script_id=69 project
" http://www.vim.org/scripts/script.php?script_id=1658 NERDTree
" http://www.vim.org/scripts/script.php?script_id=356 dbext
" http://github.com/jamis/fuzzyfinder_textmate/tree/master

set hidden
set incsearch nohlsearch
set autoread autowrite
set backspace=2
set pastetoggle=<F6>
filetype on
filetype indent on

" visual helpers
set number
set showmode
set showcmd
set t_Co=256
colorscheme mondrian

if has("syntax")
syntax on
endif

if has("autocmd")
augroup LOCAL
au!
autocmd FileType sh set sw=4 ts=4 et si
autocmd FileType vim set sw=4 ts=4 et si
autocmd FileType scheme set sw=4 ts=4 et si
autocmd FileType ruby,eruby set sw=2 ts=2 et si
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1

autocmd BufWritePre *.{rb,sh,scm} call DeleteTrailingWhiteSpace()
autocmd BufWritePost *.{rb,sh,scm} exe system("chmod +x " . expand("%") )
autocmd BufWritePost *vimrc source %
augroup END
endif

if has("ruby")
echo "has ruby"
source $HOME/.vim/local/blogger.vim
endif

function! DeleteTrailingWhiteSpace()
normal mz
%s/\s\+$//ge
normal `z
endfunction

RubyInterfaceToWordPress

August 4, 2009

A simple interface to WordPress from ruby

#!/usr/bin/ruby
require 'net/https'
require 'uri'
require 'cgi'
require 'rubygems'
require 'atom/entry'
require 'atom/collection'

class GoogleSucks
attr_accessor :username, :password
@@auth_url = 'https://www.google.com/accounts/ClientLogin&apos;

def get_authenticated_session
# from http://code.google.com/apis/gdata/articles/using_ruby.html
url = URI.parse(@@auth_url)
http = Net::HTTP.new(url.host, url.port)
if (url.scheme == "https")
http.use_ssl = true
end
username = CGI.escape(username)
password= CGI.escape(password)
data = "accountType=Google&Email=#{username}&Passwd=#{password}&service=blogger&source=RUSSIA-WEHAVEVODKA-1.0"
puts data
headers = { 'Content-Type' => 'application/x-www-form-urlencoded'}
resp, data = http.post(url.path, data, headers)
if (resp != Net::HTTPSuccess)
puts "yay! you probably got a captcha!"
puts resp
puts data
return nil
end
cl_string = data[/Auth=(.*)/, 1]
puts cl_string
headers["Authorization"] = "GoogleLogin auth=#{cl_string}"
return http
end
end

class WordPressSucksLess
attr_accessor :username, :password, :authorname

def post(title, body, tags)
blog_url = "http://#{ username }.wordpress.com"
post_url = "http://#{ username }.wordpress.com/wp-app.php/posts"

if (File.exist? body)
body = IO.read(body)
end

entry = Atom::Entry.new
entry.title = title
entry.content = body
entry.updated!

author = Atom::Author.new
author.name = authorname
author.uri = blog_url
entry.authors << author

tags.each do |t|
c = Atom::Category.new
c["scheme"] = blog_url
c["term"] = t.strip
entry.categories << c
end

h = Atom::HTTP.new
h.user = username
h.pass = password
h.always_auth = :basic

c = Atom::Collection.new(post_url, h)
res = c.post! entry
puts res.read_body
end
end

class Blog < WordPressSucksLess
def initialize
@username = ''
@password = ''
@authorname = ''
end
end

BlogRubyWithVim

August 4, 2009

" Blog to wordpress via vim
function! Blog(title)
let file = tempname()
" get any pre-existing post
execute 'ruby blog = Blog.new'
execute 'edit ' . file
execute "augroup Blog"
execute "autocmd!"
execute 'autocmd BufWritePost ' . file . ' ruby blog.post( "' . a:title . '", "' . file . '", [])'
execute 'autocmd BufDelete ' . file . ' execute delete("' . file . '")'
execute "augroup END"
startinsert
execute "set syntax=html"
execute "set ft=html"
endfunction()

if has("ruby")
rubyfile ~/.vim/local/blogger.rb
command! -nargs=1 Blog :call Blog("<args>")
endif

DorkBot4000

August 4, 2009

DorkBot4000 FP!!!