Skip to content

Instantly share code, notes, and snippets.

View dlisboa's full-sized avatar

Diogo Lisboa dlisboa

View GitHub Profile
filename = "db/rrd/tanque-2-18.rrd"
rrd_version = "0003"
step = 1
last_update = 1297711771
header_size = 2228
ds[reading].index = 0
ds[reading].type = "GAUGE"
ds[reading].minimal_heartbeat = 3
ds[reading].min = -8.2906880000e+06
ds[reading].max = 8.2906870000e+06
(define (pick-random n)
"Retorna um inteiro randômico entre 1 e n-1"
(+ 1 (random (- n 1))))
;; quanto maior a tolerância, maior a certeza de que o número
;; é realmente um primo, e não um primo composto. Porém o tempo
;; do algoritmo é proporcional à tolerância, então 10 é um número
;; razoável
(define tolerancia 10)
@dlisboa
dlisboa / jmp.c
Created October 24, 2013 16:34 — forked from anonymous/-
#include <setjmp.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
jmp_buf jump;
int status = setjmp(jump);
puts("yes");
longjmp(jump, status);
class Score
class << self
def score(choice, query)
return 1.0 if query.length == 0
return 0.0 if choice.length == 0
choice = choice.downcase
query = query.downcase
match_length = compute_match_length(choice, query.each_char.to_a)
struct bar {
char* name;
int age;
};
struct bar bars[] = {
{"Narciso", 25},
{"Salsa", 25}
}
img {
color: red;
test-foo: bar;
line-height: 1.2em;
}
@dlisboa
dlisboa / ugly.rb
Last active December 30, 2015 19:18
def main_domain_url site
URI::Generic.build scheme: request.scheme,
host: site.address,
port: request.port,
path: '/'
end
@dlisboa
dlisboa / foo.rb
Last active December 30, 2015 22:38
File.open("foo", "w+") {|f| f.puts "bar"}
File.open("foo", "w+") {|f| f.read } #=> queria "bar", mas retorna ""
# API que eu quero
resolver.with_file do |file|
file.write 'bar'
end # => 3
require 'irb/completion'
def vi
require 'tempfile' unless defined? Tempfile
@f ||= Tempfile.new('irb-interactive')
system('vim', @f.path)
Object.class_eval File.read(@f.path) if $?.success?
end
require 'delegate'
class User
end
class UserDecorator
def initialize(user)
@user = user
end
end