Skip to content

Instantly share code, notes, and snippets.

View cfcosta's full-sized avatar

Cainã Costa cfcosta

  • São Paulo, Brazil
View GitHub Profile
@cfcosta
cfcosta / LocaleStealer.java
Created February 13, 2012 19:49
Listagem de países com reus respectivos locales, roubado direto do java.utils.Locale.
import java.util.Locale;
class LocaleStealer {
public static void main(String[] args) {
Locale[] availableLocales = Locale.getAvailableLocales();
System.out.println("countries:")
for (Locale locale : availableLocales) {
if(! locale.getDisplayCountry().equals("")) {
System.out.println(String.format(" - [\"%s\", \"%s\"]", locale, locale.getDisplayCountry()));
typedef struct {
int up;
int down;
int left;
int right;
} movement;
typedef movement acceleration;
typedef movement speed;
#ifndef H_STACK_COLLECTION
#define H_STACK_COLLECTION
#define traverse_stack(stack) sprite_node *current = first; \
while(*current = *current->next)
#include "graphics.h"
typedef struct {
sprite *sprite;
void stack_remove(sprite_node *node)
{
node->previous->next = node->next;
SDL_FreeSurface(node->image);
free(node);
}
#include "sprite_stack.h"
void stack_remove(sprite_node *node)
{
node->previous->next = node->next;
SDL_FreeSurface(node->sprite->image);
free(node);
}
clang -DPACKAGE_NAME=\"shmup\" -DPACKAGE_TARNAME=\"shmup\" -DPACKAGE_VERSION=\"0.1\" -DPACKAGE_STRING=\"shmup\ 0.1\" -DPACKAGE_BUGREPORT=\"cainan.costa@gmail.com\" -DPACKAGE=\"shmup\" -DVERSION=\"0.1\" -I. -D_GNU_SOURCE=1 -D_THREAD_SAFE -I/usr/local/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE -I/usr/local/include/SDL -Wall -Werror -ansi -finline-functions -g -O2 -MT shmup-sprite_stack.o -MD -MP -MF .deps/shmup-sprite_stack.Tpo -c -o shmup-sprite_stack.o `test -f 'sprite_stack.c' || echo './'`sprite_stack.c
In file included from sprite_stack.c:1:
./sprite_stack.h:9:5: error: unknown type name 'sprite_node'
sprite_node *previous;
^
./sprite_stack.h:10:5: error: unknown type name 'sprite_node'
sprite_node *next;
^
2 errors generated.
make[1]: *** [shmup-sprite_stack.o] Error 1
INFINITY = (1/0.0)
count = case violations.length
when 0..5
[yellow, violations.length.to_s, clear].join
when 6..10
[red, violations.length.to_s, clear].join
when 11..INFINITY
[bold, red, violations.length.to_s, clear].join
end
@cfcosta
cfcosta / trigram.rb
Created March 5, 2012 05:03
Trigram similarity index for words.
require 'minitest/autorun'
class String
def match_index_to(other)
this = self.to_trigrams.first
other = other.to_trigrams.first
2.0 * ((this & other).size).to_f / (this.size + other.size).to_f
end
@cfcosta
cfcosta / gist:2124269
Created March 19, 2012 19:05
integration test helper for rails with minitest
ENV['RAILS_ENV'] = "test"
unless defined?(Bundler)
require 'bundler/setup'
end
require 'minitest/autorun'
require 'factory_girl'
MiniTest::Unit::TestCase.send(:include, FactoryGirl::Syntax::Methods)
>> require "minitest/mock"
=> true
>> mock = MiniTest::Mock.new
=> #<MiniTest::Mock:0x007fc48ca57d70 @expected_calls={}, @actual_calls={}>
>> mock.respond_to? :abc
=> false
>> mock.expect(:abc, "123")
=> #<MiniTest::Mock:0x007fc48ca57d70 @expected_calls={:abc=>{:retval=>"123", :args=>[]}}, @actual_calls={}>
>> mock.respond_to? :abc
=> true