Skip to content

Instantly share code, notes, and snippets.

View xuanxu's full-sized avatar

Juanjo Bazán xuanxu

View GitHub Profile
@xuanxu
xuanxu / teams_ids.rb
Created March 19, 2021 11:22
Getting GitHub Team's ID
require 'octokit'
def gh
@gh ||= Octokit::Client.new auto_paginate: true, access_token: ENV['GH_ACCESS_TOKEN']
end
def teams_with_ids(organization)
gh.org_teams(organization).map {|t| [t.name, t.id]}
end
require 'csv'
require 'open-uri'
require 'gruff'
# loading original data
body_count_data = CSV.read(open("http://files.figshare.com/1332945/film_death_counts.csv"), headers: true)
# adding a new column with the full title and year
body_count_data.map do |row|
row << {"Deaths_Per_Minute" => (row["Body_Count"].to_i / row["Length_Minutes"].to_f),
@xuanxu
xuanxu / medusa.rb
Created July 26, 2013 10:13
Tank built for the 1st Madrid.rb RTanque competition
# Silly Tank built for the Madrid.rb RTanque duel
# Author: @xuanxu
class Medusa < RTanque::Bot::Brain
NAME = 'Medusa'
include RTanque::Bot::BrainHelper
def tick!
move_to_destination
@xuanxu
xuanxu / db_localdump.rb
Created April 11, 2013 10:19
Dump and download postgres production db
# Dump production postgres database and save it locally
Capistrano::Configuration.instance(:must_exist).load do
namespace :db do
desc "Backup the PostgreSQL database and download file to local"
task :localdump, :roles => :db, :only => {:primary => true} do
now = Time.now
backup_time = [now.year,now.month,now.day,now.hour,now.min,now.sec].join('-')
set :backup_file, "#{shared_path}/tmp/#{environment_database}-snapshot-#{backup_time}.sql"
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
<!-- layout file -->
<% if current_user %>
Welcome <%= current_user.username %>. Not you? <%= link_to "Log out", logout_path %>
<% else %>
<%= link_to "Sign up", signup_path %> or <%= link_to "log in", login_path %>.
<% end %>