Skip to content

Instantly share code, notes, and snippets.

Avatar

Eustáquio Rangel taq

View GitHub Profile
View class_instance_variable.rb
class Test
class << self
attr_accessor :count
end
@count = 0
def initialize
self.class.count += 1
end
end
View find_by_sample.rb
class ActiveRecord::Base
def self.find_by_sample(sample)
columns = self.columns.reject {|column| %w(id created_at updated_at).include?(column.name) }
cond_str, cond_val = [], []
columns.each do |column|
value = sample.send(column.name)
next if value.nil?
cond_str << "#{column.name}=?"
cond_val << value
end
View html5.rb
module ActionView
module Helpers
module FormHelper
def email_field(object_name, method, options = {})
InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("email", options)
end
def url_field(object_name, method, options = {})
InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("url", options)
end
def search_field(object_name, method, options = {})
@taq
taq / ruby-version.bash
Created Nov 17, 2010
Ruby version Bash function
View ruby-version.bash
# First parameter is a bash printf formatting string
# From second till fifth parameter, rvm-prompt format parameters
__ruby_ps1 () {
if [ ! -f ./Rakefile ] &&
[ "$(find -maxdepth 1 -name '*.rb' | head -n1)" == "" ]; then
exit 1
fi
if [ -f ~/.rvm/bin/rvm-prompt ]; then
rst=$(~/.rvm/bin/rvm-prompt $2 $3 $4 $5)
fi
View rvm-version.bash
__rvm_ps1 () {
if [ ! -f ~/.rvm/bin/rvm-prompt ]; then
exit 0
fi
RVM_VERSION=$(~/.rvm/bin/rvm-prompt)
FMT="%s"
if ([ -f "$(pwd)/Rakefile" ] ||
[ "$(find . -maxdepth 1 -name '*.rb' | head -n1)" != "" ]) &&
[ ! -z "$RVM_VERSION" ]; then
if [ -n "$1" ]; then
View gist:1371466
$ rvm install 1.9.2 --trace &> /tmp/rvm.log
1.9.2 --trace
rvm 1.9.2 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]
+ /scripts/cli : __rvm_parse_args() 693 > [[ -n '' ]]
+ /scripts/cli : __rvm_parse_args() 694 > export 'PS4=+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ /scripts/cli : __rvm_parse_args() 694 > PS4='+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ /scripts/cli : __rvm_parse_args() 722 > [[ -z install ]]
+ /scripts/cli : __rvm_parse_args() 724 > [[ 0 -eq 1 ]]
@taq
taq / gist:1759632
Created Feb 7, 2012
Apple’s great GPL purge
View gist:1759632
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.
@taq
taq / binwrite.c
Created Apr 12, 2012
Escrevendo no arquivo, em C
View binwrite.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 / binread.c
Created Apr 12, 2012
Lendo do arquivo, em C.
View binread.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 / binreadint.sh
Created Apr 12, 2012
Lendo um inteiro do arquivo, em shell
View binreadint.sh
od --read-bytes=4 -t d -An teste.bin | tr -d ' '