Skip to content

Instantly share code, notes, and snippets.

@Irio
Irio / gist:2854516
Created June 1, 2012 19:18
for in CoffeeScript
weekday = 10
console.log 'this will be printed 10 times' for index in [0..(weekday-1)]
@Irio
Irio / gist:2891178
Created June 7, 2012 19:54
Distinction between Movie Info by id or imdb_id on Tmdb requests
/* http://api.themoviedb.org/3/movie/188?api_key=my_key&language=en */
{"adult":false,"backdrop_path":"/wyey4NS4Z1z7293R8FFBETL6DSr.jpg","belongs_to_collection":null,"budget":0,"genres":[{"id":28,"name":"Action"},{"id":53,"name":"Thriller"}],"homepage":"","id":188,"imdb_id":"tt0401792","original_title":"Sin City","overview":"The Sin City series. Director Robert Rodriguez makes the legendary comic artist Frank Miller (Batman and Daredevil) into a series of films depicting his Sin City comics. The films however are not for children.","popularity":0.06,"poster_path":"/mYxbfd8pZz9YTtEFRaOcQboOvMk.jpg","production_companies":[],"production_countries":[],"release_date":null,"revenue":0,"runtime":0,"spoken_languages":[],"tagline":"","title":"Sin City","vote_average":0.0,"vote_count":0}
/* http://api.themoviedb.org/3/movie/tt0401792?api_key=my_key&language=en */
{"adult":false,"backdrop_path":"/kftq445wZNaKEqJ9gXwYOIfI2p1.jpg","belongs_to_collection":{"id":188,"name":"Sin City","poster_path":"/mYxbfd8pZz9YTtEFRaO
@Irio
Irio / gist:2924290
Created June 13, 2012 14:06
twitter username regex
# twitter_link = https://twitter.com/#!/irio
# twitter_link = https://twitter.com/#!/irio/
# twitter_link = https://twitter.com/irio/
# twitter_link = https://twitter.com/irio
"@" + /twitter.com\/(#!\/)?(.[^\/]+)/.match(twitter_link)[2] # => "@irio"
@Irio
Irio / gist:3041785
Created July 3, 2012 18:40
oauth with devise2
# OAuth
config.omniauth :facebook, "306897372733415", "178333649c7a3ae4842038a110e36e19",
{:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
@Irio
Irio / add_facebook_uid_to_users.rb
Created July 4, 2012 14:44
OAuth2 with Devise
class AddFacebookUidToUsers < ActiveRecord::Migration
def change
add_column :users, :facebook_uid, :string
end
end
@Irio
Irio / gist:3067105
Created July 7, 2012 16:28
Invalid json response from MoIP
?({"Status":"EmAnalise","Codigo":0,"CodigoRetorno":"","TaxaMoIP":"1.45","StatusPagamento":"Sucesso","Classificacao":{"Codigo":999,"Descricao":"No suportado no ambiente Sandbox"},"CodigoMoIP":69690,"Mensagem":"Requisio processada com sucesso","TotalPago":"14.30"})
@Irio
Irio / fake_parser.rb
Created July 8, 2012 01:23
Skip parse on HTTParty
class FakeParser
def self.call(body, format)
body
end
end
@Irio
Irio / gist:3105041
Created July 13, 2012 14:02
defining class methods
class SinglePages
file :about, %w(text)
class << self
# Generate write method to this file
def file(filename, attrs)
define_method "write_#{filename}" do |properties_hash|
puts properties_hash
end
end
@Irio
Irio / gist:3124502
Created July 16, 2012 19:24
bootstrap scaffold | show.html.erb
<%- model_class = @rental.class -%>
<h1><%=t '.title', :default => model_class.model_name.human %></h1>
<dl class="dl-horizontal">
<dt><strong><%= model_class.human_attribute_name(:start_date) %>:</strong></dt>
<dd><%= @rental.start_date %></dd>
<dt><strong><%= model_class.human_attribute_name(:end_date) %>:</strong></dt>
<dd><%= @rental.end_date %></dd>
<dt><strong><%= model_class.human_attribute_name(:ocupation) %>:</strong></dt>
<dd><%= @rental.ocupation %></dd>
@Irio
Irio / PropositionListActivity.java
Created July 24, 2012 01:08
Android - How to move ActionBar.Tab's icon as your needs (example using ActionBarSherlock)
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockActivity;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Menu;