Skip to content

Instantly share code, notes, and snippets.

View bastos's full-sized avatar
:shipit:
Shipping something

Tiago Bastos bastos

:shipit:
Shipping something
View GitHub Profile
@bastos
bastos / light_sensor.pde
Created May 9, 2009 21:10
Light Sensor Example with Arduino
int LDR = 0; // select the input pin for the LDR
int lightOnPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
int turnOnValue = 1000;
void setup() {
pinMode(LDR, INPUT); // declare the LDR as an INPUT
pinMode(lightOnPin, OUTPUT); // declare the ledPin as an OUTPUT
@bastos
bastos / gist:104579
Created April 30, 2009 17:55
Stupid example
require 'rubygems'
require 'sinatra'
require 'rest_client'
require 'json'
DB = 'http://localhost:5984/notes'
get '/' do
data = RestClient.get "#{DB}/_all_docs?include_docs=true"
result = JSON.parse(data)
# do not make noise
set bell-style none
export PATH=~/.gem/ruby/1.8/bin/:$PATH
# Mysql
alias mysqlstart='sudo /opt/local/bin/mysqld_safe5 &'
alias mysqlstop='/opt/local/bin/mysqladmin5 -u root -p shutdown'
# http://pastebin.com/f7a69dcd7
@bastos
bastos / gist:83566
Created March 23, 2009 14:33
Little benchmark between Curl and Net::Http
#!/usr/bin/env ruby
require 'benchmark'
require 'rubygems'
require 'curl'
require 'net/http'
URL = "URL HERE"
Benchmark.bm do|b|
b.report("CURL") do
1000.times do
@bastos
bastos / gist:79867
Created March 16, 2009 13:10
Little Script to reload a rails app on server for tests...
#!/usr/bin/env sh
# On CRON:
# 00,15,30,45 * * * * /home/user/project/reload.sh >> /home/user/log/release_web.log 2>&1
echo "Rebuilding" > /home/user/project/current/public/index.html
# Update the code
svn update /home/user/project/current
# Run migrations
cd /home/user/project/current
rake RAILS_ENV=$RAILS_ENV db:migrate;
# Restart memcached.
@bastos
bastos / gist:65170
Created February 16, 2009 13:45
Test Memcached
require 'rubygems'
require 'memcache'
memcache_options = {
:namespace => 'agp:test:key',
:multithread => true
}
memcached_servers = [ ENV['MEMCACHED_LOCATION'] || '0.0.0.0:12211']
# Based on:
# http://github.com/bmizerany/heroku-sinatra-app
# http://www.sinatrarb.com/book.html#heroku
# trial-and-error
#
# I tried using Blake's sample code from github,
# but for some reason my Heroku.com app was running in
# a directory called /mnt. This did not correspond to the
# name of my app. The code below is more explicit when it
# comes to the name of the app file. That is the only difference.
...
before_filter :set_views_paths_for_layout
# Add new paths to templates paths.
def set_views_paths_for_layout
paths = []
...
paths << create_a_new_path("#{RAILS_ROOT}/app/views/shared")
@bastos
bastos / gist:56866
Created February 2, 2009 10:29
Download all videos from Ruby Conf 2008 Confreaks Website
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
open('http://feeds.feedburner.com/Rubyconf2008-Confreaks') do |f|
Hpricot.XML(f).search("link").each do |link|
puts "Downloading #{link.inner_text}"
`wget -c #{link.inner_text}`
@bastos
bastos / example.rb
Created January 9, 2009 20:37
Render for Sinatra using markaby and with cache.
require "rubygems"
require "sinatra"
require "render"
Sinatra::EventContext.send :include, Render
SVN_REPO_PATH = "/home/tiago/projects/repo/trunk"
get "/" do
render :cache => true, :expire => 60 do