Skip to content

Instantly share code, notes, and snippets.

View lucasuyezu's full-sized avatar

Lucas Uyezu lucasuyezu

  • Tiohti:áke, unceded Kanien’kehá:ka Territory
  • X @coralton
View GitHub Profile
use std::collections::HashMap;
// Given a list of integers, use a vector and return the mean (the average value)
pub fn vec_mean(vec: &Vec<i32>) -> f64 {
let sum = vec_sum(&vec);
sum as f64 / vec.len() as f64
}
// Given a list of integers, use a vector and return the median (when sorted, the value in the middle position)
@lucasuyezu
lucasuyezu / scheduler.go
Created February 27, 2015 01:13
Load Balancing between the number of available procs
package main
import (
"fmt"
"runtime"
)
func main() {
procs := runtime.GOMAXPROCS(0)

Apresentação

Lucas Uyezu

  • IaaS dev @ Locaweb
  • Java 2005 - 2008
  • Android 2011-2012
  • Ruby 2008 - Today
  • @coralton
  • github.com/lucasuyezu
puts "1) Fetching data"
http = EventMachine::HttpRequest.new("https://api.bitcoinaverage.com/ticker/global/all").get
http.errback { p '3) Not-done! Error!'; EM.stop }
http.callback do
# 1 second later
$redis.set(response_body["data"])
puts "3) Storing fetched data"
p http.response_header.status
p http.response_header
puts "Fetching data"
respose_body = HTTParty.get "https://api.bitcoinaverage.com/ticker/global/all"
# 1 second later
puts "Storing fetched data"
$redis.set(response_body["data"])
puts "Done!"
# Setup
$redis = Redis.connect
# Conversion
currency, amount = parse_tweet("0.5 in #USD")
result = convert('USD', 0.5)
reply("#{amount} in #{currency} is #{result}")
$redis.sadd("conversions", "#{amount} in #{currency} at #{Time.now}")
# Checking later
# Setup
$conversions = 0
# Conversion
currency, amount = parse_tweet("0.5 in #USD")
result = convert('USD', 0.5)
reply("#{amount} in #{currency} is #{result}")
$conversions += 1
# Checking later
@lucasuyezu
lucasuyezu / example.rb
Created December 15, 2014 16:00
example
# Good
class V2::BackupsController < ApplicationController
# All REST methods, as shown before
end
class V2::RestoresController < ApplicationController
def index
# List restores (via GET)
end
@lucasuyezu
lucasuyezu / example.rb
Created December 15, 2014 15:58
example
# Bad
class BackupsController < ApplicationController
def index
end
def show
end
# All other REST methods
-rw------- 1 lucasuyezu staff 3 Sep 1 17:01 .CFUserTextEncoding
-rw-r--r--@ 1 lucasuyezu staff 21508 Sep 1 13:06 .DS_Store
drwx------ 8 lucasuyezu staff 272 Sep 1 20:21 .Trash
drwxr-xr-x 11 lucasuyezu staff 374 May 6 15:55 .atom
-rw------- 1 lucasuyezu staff 573 Jul 28 15:04 .bash_history
drwxr-xr-x 3 lucasuyezu staff 102 Jun 13 15:26 .berkshelf
drwxr-xr-x 2 lucasuyezu staff 68 Apr 4 15:26 .bin
drwxr-xr-x 4 lucasuyezu staff 136 Jul 28 15:03 .boot2docker
drwxr-xr-x 3 lucasuyezu staff 102 Apr 4 15:51 .bundle
-rw-r--r-- 1 lucasuyezu staff 422 Aug 4 19:05 .byebug_hist