Skip to content

Instantly share code, notes, and snippets.

View caironoleto's full-sized avatar
🎯
Focusing

Cairo Noleto caironoleto

🎯
Focusing
View GitHub Profile
@caironoleto
caironoleto / _form.html.erb
Created January 9, 2011 18:37
_form.html.erb template using formtastic (put this file into your rails app in lib/templates/erb/scaffold/_form.html.erb)
<%%= semantic_form_for @<%= singular_table_name %> do |form| %>
<%%= form.inputs :id => :form_body %>
<%%= form.buttons :commit, :id => :form_body %>
<%% end %>
require 'rubygems'
require 'sinatra'
require 'json'
require 'httparty'
class Http
include HTTParty
end
jobs = {"governador" => 13, "senador" => 15, "deputado-federal" => 16, "deputado-estadual" => 17}
module ActiveSupport
module Cache
class SmartMemCacheStore < MemCacheStore
alias_method :orig_read, :read
alias_method :orig_write, :write
def read(key, options = nil)
lock_expires_in = options.delete(:lock_expires_in) if !options.nil?
lock_expires_in ||= 30
require 'rubygems'
require 'sinatra'
require 'nokogiri'
require 'open-uri'
require 'sinatra/content_for'
class String
def to_slug
ret = self.strip
ret.gsub! /['`]/,""
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
if RUBY_VERSION == "1.8.6"
check_auth_args user, secret, authtype if user or secret
[whatever@server ~]$ curl http://api.twitter.com/1/account/rate_limit_status.xml
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<reset-time type="datetime">2010-04-17T02:00:08+00:00</reset-time>
<remaining-hits type="integer">19963</remaining-hits>
<hourly-limit type="integer">20000</hourly-limit>
<reset-time-in-seconds type="integer">1271469608</reset-time-in-seconds>
</hash>
[whatever@server ~]$ lol
require 'rubygems'
require 'active_record'
require 'net/http'
require 'uri'
email = "YOUR_EMAIL_HERE"
password = "YOUR_PASSWORD_HERE"
ActiveRecord::Base.establish_connection(:adapter => "mysql", :socket => "/tmp/mysql.sock", :user => "root", :password => "root", :database => "YOUR_DATABASE_HERE")
results = ActiveRecord::Base.connection.execute("SELECT * FROM `wp_posts` WHERE post_type = 'post' and post_status='publish' order by post_date asc;")
# The basic idea is that we take the existing data via ActiveRecord
# and create new documents in MongoDB using MongoMapper.
# This method is necessary as we want to keep all the associations of existing dataset
# and by the way, clean up empty columns
# We rely on models still being ActiveRecord::Base, I bet you can figure out how the look like.
# And have the newer MongoDB ones here in a module, painful as we have to set the collection_name
# Don't put a +timestamps!+ into your MongoMapper models yet because this would change the updated_at if existing
# As you see in the MongoDB models, a few loose their indepence, e.g. Source as I
# plan to add other sources besides flickr, or Page and Album which only make sense in
# their parent Website
./configure \
--prefix=/usr \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access_log \
--error-log-path=/var/log/nginx/error_log \
--pid-path=/var/run/nginx.pid \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--with-md5-asm --with-md5=/usr/include \
def interesting_tables
ActiveRecord::Base.connection.tables
end
class BackupDB < ActiveRecord::Base
end
destination_db = 'new'
BackupDB.establish_connection destination_db.intern