Skip to content

Instantly share code, notes, and snippets.

View lsantos's full-sized avatar

Leandro Bueno Santos lsantos

View GitHub Profile
(1..100).map do |n|
if n % 15 == 0
"FizzBuzz"
elsif n % 3 == 0
"Fizz"
elsif n % 5 == 0
"Buzz"
else
"x"
end
require 'minitest/autorun'
class StringPairsFinder
def find(s)
return if s.nil?
tokens = s.split
result = Result.new
tokens.each_with_index do |t,i|
@lsantos
lsantos / gist:6073523
Created July 24, 2013 19:10
Spring rest controller
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.santos.leandro.spring.mvc.models.Season;
import com.santos.leandro.spring.services.SeasonService;
@lsantos
lsantos / gist:5774809
Last active December 18, 2015 11:19
This class gets ride of those annoying eclipse warnings for type safety when you have an api like hibernate query, which wasn't prepared to work with Java generics.
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.RandomAccess;
public class CollectionUtils {
public static <E> List<E> typeSafeCopy(@SuppressWarnings("rawtypes") List list, Class<E> clazz) {
List<E> returnList = (list instanceof RandomAccess) ? new ArrayList<E>(list.size()) : new LinkedList<E>();
@lsantos
lsantos / gist:5766303
Last active December 18, 2015 10:09
Wrapper to filter what methods get printed for commons lang ToStringBuilder
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(value = ElementType.METHOD)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface ToStringBuilderIgnore {
}
@lsantos
lsantos / ipad_url_worker.rb
Created June 17, 2011 14:52
Fix for pga failures when expiring the cache
module IPad::Api
class UrlMapper
class << self
def urls_for(args, options = {:include_base_url => false})
league, model, id, *extra = args
object = get_model(league, model, id)
model_urls(league, model).map { |url|
instance_eval("\"#{url}\"") unless (url.match(/\#\{id\}/) && id.blank?) || (url.match(/\#\{league\}/) && league.blank?)
@lsantos
lsantos / options.rb
Created June 9, 2011 20:24
using a hash as method parameter
# Use Hash#assert_valid_keys (from ActiveSupport) to document what
# keys to use when calling the method
def greet(options)
options.assert_valid_keys(:first_name, :last_name)
puts "Hello #{options[:first_name]} #{options[:last_name]}!"
end
#=> Hello Thuva Tharma!
greet(:first_name => "Thuva", :last_name => "Tharma")
#=> Unknown key(s): name (ArgumentError)
@lsantos
lsantos / stresst_test_tool
Created April 27, 2011 21:49
poor's man stress test tool
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
urls = %w(
http://development.thescore.com/nhl/events/2820-philadelphia-at-buffalo/box_score
http://development.thescore.com/mlb/events/5795/box_score
http://development.thescore.com/ncaaf/events/3118/box_score
http://development.thescore.com/nba/7275-cleveland-at-boston/box_score
http://development.thescore.com/ncaab/events/14267/box_score