Skip to content

Instantly share code, notes, and snippets.

Nícolas Iensen nicolasiensen

View GitHub Profile
View recent_activities_view.sql
CREATE VIEW recent_activities AS
(SELECT problems.name as title, problems.id as activable_id, problems.user_id, problems.created_at, problems.hashtag, 'Problem' as activable_type FROM problems ORDER BY problems.created_at DESC LIMIT 10) UNION ALL
(SELECT ideas_problems.name as title, ideas.id as activable_id, ideas.user_id, ideas.created_at, ideas_problems.hashtag, 'Idea' as activable_type FROM ideas INNER JOIN problems ideas_problems ON (ideas_problems.id = ideas.problem_id) ORDER BY ideas.created_at DESC LIMIT 10) UNION ALL
(SELECT tasks.title, task_subscriptions.id as activable_id, task_subscriptions.user_id, task_subscriptions.created_at, tasks.hashtag,
View funders_or_sponsors.rb
def self.funders_or_sponsors(opts={})
find_by_sql <<-SQL
SELECT *
FROM (
(SELECT "users".* FROM "users" WHERE "users"."sponsor" = 't')
UNION
(SELECT DISTINCT "users".* FROM "users" INNER JOIN "successful_transactions" ON "successful_transactions"."user_id" = "users"."id")
) AS t
SQL
end
View Gemfile.lock
GIT
remote: git://github.com/rbCAS/casino-activerecord_authenticator.git
revision: c159fbaf59b54e945e4be9ddd049e28eaf172ca3
branch: casino3
specs:
casino-activerecord_authenticator (3.0.0.pre.1)
activerecord (~> 4.1.0)
bcrypt (~> 3.0)
casino (~> 3.0.0.pre.1)
phpass-ruby (~> 0.1)
View cas.yml
defaults: &defaults
login_ticket:
lifetime: 600
service_ticket:
lifetime_unconsumed: 300
lifetime_consumed: 86400
proxy_ticket:
lifetime_unconsumed: 300
lifetime_consumed: 86400
frontend:
View .bash_profile
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://MediaDoneRight.com
# SETUP CONSTANTS
# Bunch-o-predefined colors. Makes reading code easier than escape sequences.
# I don't remember where I found this. o_O
View mailchimp_columns.rb
# Subscription.create/Subscription.update
# if subscription.payment_option == "creditcard"
# PLAN
# SUBUPDATED
# SUBVALUE
# Invoice.create/Invoice.update
# NINVOICES
# LINVOICE
View facaacontecer.rb
def canceled_subscriptions
canceled_subscriptions = []
offset = 0
subscriptions = Moip::Subscription.new.load offset
while subscriptions.any?
subscriptions.each do |subscription|
if subscription["status"] == "CANCELED"
canceled_subscriptions << subscription["code"]
end
View share.rb
def share authorizations, urls
authorizations.each do |a|
puts a.email
begin
api = Koala::Facebook::API.new(a.token)
post = api.put_wall_post("A qualquer momento, os deputados poderão decidir se a nossa Internet será livre ou dominada pelos interesses das empresas de telecomunicação. Clique no link para mandar um email a eles e mostrar que quem trabalhar contra a neutralidade da Internet estará comprando briga com a sociedade em ano de eleição. #salveainternet", link: "http://bit.ly/salveainternet", name: "Réu em 3 processos no STF, aliado das teles e inimigo da internet", description: "O voto que define o futuro da Internet será nos próximos dias. Você vai deixar o Eduardo Cunha ganhar sem dizer nada?", picture: urls.sample)
a.update_attribute :facebook_post_id, post["id"]
rescue Exception => e
a.update_attribute :last_token_renew, false
puts e.message
View create_view_facts.rb
class CreateViewFacts < ActiveRecord::Migration
def up
create_view :facts, "
SELECT c.id, c.created_at, c.name, c.description_html, c.link, c.mobilization_id, 'campaigns' as relname FROM campaigns c
UNION ALL
SELECT p.id, p.created_at, p.name, p.description as description_html, p.link, p.mobilization_id, 'problems' as relname FROM problems p;"
end
def down
drop_view :facts
@nicolasiensen
nicolasiensen / gist:6196787
Created Aug 9, 2013
Distance between two geospatial points in MySql
View gist:6196787
SET @orig_lat = "50";
SET @orig_lng = "5";
SET @dest_lat = "45";
SET @dest_lng = "30";
SELECT 3956 * 2 * ASIN(SQRT( POWER(SIN((@orig_lat - @dest_lat) * pi()/180 / 2), 2) + COS(@orig_lat * pi()/180) * COS(@dest_lat * pi()/180) * POWER(SIN((@orig_lng - @dest_lng) * pi()/180 / 2), 2) ));
You can’t perform that action at this time.