Skip to content

Instantly share code, notes, and snippets.

View vitobotta's full-sized avatar

Vito Botta vitobotta

View GitHub Profile
@vitobotta
vitobotta / Importing posts from Wordpress into Jekyll.rb
Created March 26, 2011 22:50
The script I used to import posts from my Wordpress blog into a new Jekyll one.
%w(rubygems sequel fileutils yaml active_support/inflector).each{|g| require g}
require File.join(File.dirname(__FILE__), "downmark_it")
module WordPress
def self.import(database, user, password, table_prefix = "wp", host = 'localhost')
db = Sequel.mysql(database, :user => user, :password => password, :host => host, :encoding => 'utf8')
%w(_posts _drafts images/posts/featured).each{|folder| FileUtils.mkdir_p folder}
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XML Sitemap</title>
@vitobotta
vitobotta / contact_form.rhtml
Created April 22, 2011 21:19
ERB version of my Sinatra-powered contact form for Jekyll
See blog post at http://vitobotta.com/sinatra-contact-form-jekyll/
<!DOCTYPE html>
<html>
<head>
<link href='/stylesheets/contact-form.css' type='text/css' rel='stylesheet' media='screen' />
<meta name="robots" content="noindex, noarchive, noodp, noydir" />
</head>
<body>
<% if @sent == true %>
@vitobotta
vitobotta / contact-form.rb
Created April 22, 2011 21:50
A Sinatra-powered contact form for Jekyll
# See blog post at http://vitobotta.com/sinatra-contact-form-jekyll/
%w(rubygems sinatra liquid active_support/secure_random resolv open-uri pony haml).each{ |g| require g }
APP_ROOT = File.join(File.dirname(__FILE__), '..')
set :root, APP_ROOT
set :views, File.join(APP_ROOT, "_layouts")
not_found do
@vitobotta
vitobotta / brb-client-auto-reconnect.rb
Created May 13, 2011 14:27
Example of BrB Client with auto reconnec
class Client
attr_reader :hostname, :host, :port
def initialize(port, host)
@port, @host = port, host
connect!
EM.reactor_thread.join
end
def connect!
@vitobotta
vitobotta / connection-pool-test.rb
Created July 8, 2011 12:22
Connection pool testing with JRuby and MRI
require "rubygems"
if defined?(JRUBY_VERSION)
gem "activerecord-jdbc-adapter", '>= 1.0.2'
gem "activerecord-jdbcmysql-adapter", '>= 1.0.2'
gem 'jruby-openssl'
gem 'jdbc-mysql'
else
gem 'mysql2', '= 0.2.7'
end
@vitobotta
vitobotta / indexes.rake
Created September 13, 2011 16:42
List unindexed foreign keys
namespace :indexes do
desc "List unindexed foreign keys"
task :unindexed_foreign_keys => :environment do
ActiveRecord::Base.logger = Logger.new('/dev/null')
missing_indexes = {}
connection = ActiveRecord::Base.connection
connection.tables.collect do |table|
@vitobotta
vitobotta / resque-recovery.sh
Created May 24, 2012 18:53
Resque: automatically kill stuck workers and retry failed jobs
#!/bin/bash
# Also see: http://vitobotta.com/resque-automatically-kill-stuck-workers-retry-failed-jobs/
[[ -f /tmp/retry-failed-resque-jobs ]] && rm /tmp/retry-failed-resque-jobs
ps -eo pid,command |
grep [r]esque |
grep "Processing" |
while read PID COMMAND; do
@vitobotta
vitobotta / example.feature
Created June 4, 2012 21:32 — forked from matschaffer/example.feature
Cucumber - confirmation box with JavaScript
@javascript
Scenario: confiming when saving inactive
Given I expect to click "OK" on a confirmation box saying "Are you sure?"
When I press "Save"
Then the confirmation box should have been displayed
And I should see "TV" in the "Campaign Keywords" section
@vitobotta
vitobotta / config.ru
Created June 4, 2012 21:41 — forked from jlindsey/config.ru
Simplest rack app
require 'rack'
map '/' do
use Rack::Static, urls: ['/assets', '/templates'], root: File.expand_path('../public', __FILE__)
app = lambda do |env|
headers = {
'Content-Type' => 'text/html',
'Cache-Control' => 'no-cache'
}