Skip to content

Instantly share code, notes, and snippets.

View taq's full-sized avatar

Eustáquio Rangel taq

View GitHub Profile
@taq
taq / prepend.rb
Created November 3, 2012 19:02
Module#prepend - using include on 1.9.x
class C
def x; "x"; end
end
module M
def x; '[' + super + ']'; end
def y; "y"; end
end
class C
@taq
taq / keyword.rb
Created November 3, 2012 18:53
Ruby 2.0 keyword arguments
def foo(str: "foo", num: 123456)
[str, num]
end
p foo(str: 'buz', num: 9) #=> ['buz', 9]
p foo(str: 'bar') # => ['bar', 123456]
p foo(num: 123) # => ['foo', 123]
p foo # => ['foo', 123456]
p foo(bar: 'buz') # => ArgumentError
@taq
taq / symbol_array.rb
Created November 3, 2012 18:47
Ruby 2.0 symbol array literal
p [:ruby, :"2.0", :symbol, :array, :literal]
#=> [:ruby, :"2.0", :symbol, :array, :literal]
p %i(ruby 2.0 symbol array literal)
#=> [:ruby, :"2.0", :symbol, :array, :literal]
@taq
taq / htmlescape.html
Created May 18, 2012 21:40
HTML escape test
<!DOCTYPE HTML>
<html>
<head>
<title>HTML escape test</title>
</head>
<body>
<p>This is a test.</p>
</body>
</html>
@taq
taq / htmlescape.rb
Created May 18, 2012 21:39
HTML escape
#!/bin/ruby
require "cgi"
STDOUT.print CGI.escapeHTML(ARGV.size>0 ? File.read(ARGV[0]) : STDIN.read)
@taq
taq / binreaddouble.sh
Created April 12, 2012 20:14
Lendo um double do arquivo, em shell.
od --skip-bytes=4 --read-bytes=8 -t fD -An teste.bin | printf "%.0f" $(tr -d ' ')
@taq
taq / binreadint.sh
Created April 12, 2012 20:13
Lendo um inteiro do arquivo, em shell
od --read-bytes=4 -t d -An teste.bin | tr -d ' '
@taq
taq / binread.c
Created April 12, 2012 20:08
Lendo do arquivo, em C.
#include <stdio.h>
int main(int argc, char **argv) {
FILE *file;
int i;
double d;
file = fopen("teste.bin","rb");
fread(&i,sizeof(int),1,file);
fread(&d,sizeof(double),1,file);
printf("%d\n %#f\n",i,d);
@taq
taq / binwrite.c
Created April 12, 2012 20:07
Escrevendo no arquivo, em C
#include <stdio.h>
int main(int argc, char **argv) {
int i = 123;
double d = 456789;
FILE *file;
file = fopen("teste.bin","wb");
printf("gravando int com %d bytes\n",sizeof(int));
fwrite(&i,sizeof(int),1,file);
printf("gravando double com %d bytes\n",sizeof(double));
@taq
taq / gist:1759632
Created February 7, 2012 13:18
Apple’s great GPL purge
From http://meta.ath0.com/2012/02/05/apples-great-gpl-purge/, with access forbidden right now:
Apple obligingly allows you to browse and download the open source software they use in OS X. Since they have listings for each version of OS X, I decided to take a look at how much software they were using that was only available under the GNU public license. The results are illuminating:
10.5: 47 GPL-licensed packages.
10.6: 44 GPL-licensed packages.
10.7: 29 GPL-licensed packages.
This clearly supports the idea that Apple is aggressively trying to remove all GPL-licensed software from OS X. While the removal of Samba and GCC got some attention, the numbers show that there’s a more general purging going on.