Skip to content

Instantly share code, notes, and snippets.

View etozzato's full-sized avatar
💀
I work hard so my cat doesn't have to

Emanuele Tozzato etozzato

💀
I work hard so my cat doesn't have to
View GitHub Profile
@etozzato
etozzato / Rakefile.rb
Created October 30, 2009 16:44
Rakefile for Sinatra
require 'rubygems'
require 'active_record'
require 'yaml'
require 'rake'
def initialize_active_record
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.establish_connection(config['development'])
ActiveRecord::Base.default_timezone = :utc
end
<?php
//attempt 1
@q =
//attempt 2
$q = 'mekdigital' unless $q
//attempt 3
$q = 'mekdigital' unless $q;
<% if flash[:notice] %>
<div id="notice">
<%= flash[:notice] %>
<%= javascript_tag "fade_notice();" %>
</div>
<% end %>
function fade_notice(){
setTimeout("$('notice').fade();", 3500);
}
<script language='javascript' src='http://app.headcounters.com/users.js'></script>
# Author: Emanuele Tozzato (mailto:etozzato@gmail.com)
#
# = Description
# Execute given block until true for given attempts.
# = Usage
# exec! { gateway.perform_handshake('2897-XSANI-19827') }
module Exec
CONFIG = {
:default_attempts => 3,
# app.rb
get '/number.js' do
@n = rand(100)
erb :number
end
<!-- example.html -->
<script language='javascript' src='http://localhost:3000/number.js'></script>
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Mongrel: port 3000 is already in use, trying 3001
class FailController < ApplicationController
def index
Fail.add_request(request.host, request.path, request.env['HTTP_REFERER'] || '', request.remote_ip || "0.0.0.0")
respond_to do |format|
format.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
format.all { render :nothing => true, :status => "404 Not Found" }
end
end
def valid_dns?
return true if self.cname
begin
require 'resolv'
heroku = Resolv.getaddresses("proxy.heroku.com")
ip = Resolv.getaddress(self.landing.gsub('http://', ''))
update_attribute(:cname, true) if heroku.include?(ip)
return self.cname
rescue
return false