Skip to content

Instantly share code, notes, and snippets.

View axelrivera's full-sized avatar

Axel Rivera axelrivera

View GitHub Profile
@axelrivera
axelrivera / hack.sh
Created March 31, 2012 13:47 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@axelrivera
axelrivera / resultados.rb
Created November 7, 2012 01:44
Resultados Elecciones de Puerto Rico en Ruby
#!/usr/bin/env ruby
# You should run `gem install httparty` first
require 'httparty'
def comma_numbers(number, delimiter = ',')
number.to_s.reverse.gsub(%r{([0-9]{3}(?=([0-9])))}, "\\1#{delimiter}").reverse
end
@axelrivera
axelrivera / resultados2.rb
Created November 9, 2012 07:45
Ruby 11 lines no external libraries
require 'net/http'
require "rexml/document"
require "rexml/xpath"
puts "RESULTADOS GOBERNACION ELECCIONES DE PUERTO RICO\n---------------------\n\n"
loop do
doc = REXML::Document.new(Net::HTTP.get_response(URI('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml')).body)
puts "#{Time.now.strftime("%B %d, %Y %H:%I:%S %p")}\n\n"
resultados = doc.elements.collect('/default/option') { |e| { name: REXML::XPath.first(e,'name/es').text, party:REXML::XPath.first(e,'pe/es').text, votes: REXML::XPath.first(e,'votes').text.to_i } }
resultados.each {|r| puts "#{r[:name]} (#{r[:party]}) => #{r[:votes].to_s.reverse.gsub(%r{([0-9]{3}(?=([0-9])))}, "\\1,").reverse} (#{sprintf("%.2f", (r[:votes].to_f / resultados.inject(0) { |sum, r| sum + r[:votes] }.to_f) * 100)}%)"}
sleep(10)
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
# Install rvm system-wide
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
# Update the packages
apt-get update
apt-get upgrade
apt-get install build-essential
# get the packages required by ruby
rvm pkg install zlib
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Monokai Bright</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@axelrivera
axelrivera / Constants.h
Created August 2, 2013 13:24
Function to test empty objects in Objective-C
static inline BOOL IsEmpty(id thing) {
return thing == nil
|| thing == [NSNull null]
|| ([thing respondsToSelector:@selector(length)]
&& [(NSData *)thing length] == 0)
|| ([thing respondsToSelector:@selector(count)]
&& [(NSArray *)thing count] == 0);
}
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(_site.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
UIGraphicsBeginImageContext(_site.frame.size);
}
[_site.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@axelrivera
axelrivera / setenv.sh
Last active December 28, 2015 10:29 — forked from terrancesnyder/setenv.sh
#! /bin/sh
# ==================================================================
# ______ __ _____
# /_ __/___ ____ ___ _________ _/ /_ /__ /
# / / / __ \/ __ `__ \/ ___/ __ `/ __/ / /
# / / / /_/ / / / / / / /__/ /_/ / /_ / /
#/_/ \____/_/ /_/ /_/\___/\__,_/\__/ /_/
# Multi-instance Apache Tomcat installation with a focus
# on best-practices as defined by Apache, SpringSource, and MuleSoft
guard 'shell' do
watch(/relation_tree_spec\.rb/) { `clear && ruby relation_tree_spec.rb` }
end