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 / 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
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
clang -DPACKAGE_NAME=\"shmup\" -DPACKAGE_TARNAME=\"shmup\" -DPACKAGE_VERSION=\"0.1\" -DPACKAGE_STRING=\"shmup\ 0.1\" -DPACKAGE_BUGREPORT=\"[email protected]\" -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
#include "sprite_stack.h"
void stack_remove(sprite_node *node)
{
node->previous->next = node->next;
SDL_FreeSurface(node->sprite->image);
free(node);
}
void stack_remove(sprite_node *node)
{
node->previous->next = node->next;
SDL_FreeSurface(node->image);
free(node);
}
#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;
typedef struct {
int up;
int down;
int left;
int right;
} movement;
typedef movement acceleration;
typedef movement speed;
@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()));
require 'fiber'
class Job
include Enumerable
def initialize(jobs)
@jobs = jobs
end
def each(&block)
$ irb
>> require 'bundler/setup'
true
>> require 'active_support/core_ext/string/inflections'
true
>> "FakeResource".tableize
"fake_resource"
>> require 'active_support/core_ext'
true
>> "FakeResource".tableize