Skip to content

Instantly share code, notes, and snippets.

View tomas-stefano's full-sized avatar

Tomas D'Stefano tomas-stefano

  • Ministry of Justice, Department for Education
  • London
View GitHub Profile
@tomas-stefano
tomas-stefano / Ps1
Created November 19, 2010 16:36
PS1
PS1=" ${RUBY_PROMPT}${YELLOW}\w\a${NO_COLOR} (${PROMPT_COLOR}${BRANCH}${NO_COLOR}${STATE}${NO_COLOR})\n⤷ "
@tomas-stefano
tomas-stefano / rspec
Created November 24, 2010 16:53
How I study RSpec
$ git clone https://github.com/rspec/rspec-core.git
$ git clone https://github.com/rspec/rspec-expectations.git
$ git clone https://github.com/rspec/rspec-mocks.git
$ mate rspec-mocks rspec-expectations rspec-core
@tomas-stefano
tomas-stefano / http_headers.rb
Created November 28, 2010 15:00
Http Headers with EventMachine
require 'rubygems'
require 'eventmachine'
module HttpHeaders
def post_init
send_data "GET /\r\n\r\n"
@data = ""
end
def receive_data(data)
require 'rubygems'
require 'eventmachine'
require 'em-http'
require 'json'
EM.run do
username = "username"
password = "secret"
term = "ruby"
@tomas-stefano
tomas-stefano / chat_client.rb
Created December 1, 2010 00:14
Chat Client using EM
require 'rubygems'
require 'eventmachine'
module ChatClient
def self.list
@list ||= []
end
def post_init
@name = "anonymous_#{rand(99999)}"
@tomas-stefano
tomas-stefano / Array#delete
Created December 7, 2010 16:25
Delete should delete one element of the array instead of all
class Array
alias :delete_all :delete
undef :delete
def delete(element)
each_with_index do |index, element_of_array|
delete_at(index) if element == element_of_array
end
end
end
@tomas-stefano
tomas-stefano / Array#delete.rb
Created December 7, 2010 16:25
Delete should delete one element of the array instead of all
class MyArray < Array
alias :delete_all :delete
undef :delete
def delete(element)
each_with_index do |index, element_of_array|
delete_at(index) if element == element_of_array
end
end
end
@tomas-stefano
tomas-stefano / integer_to_char.c
Created December 7, 2010 16:32
Integer to char in C (with long long support)
void integer_to_char(long long value, char* str, int base) {
static char num[] = "0123456789abcdefghijklmnopqrstuvwxyz";
char *wstr = str;
int sign;
lldiv_t res;
// Validate base
if (base < 2 || base > 35) {
*wstr = '\0';
return;
@tomas-stefano
tomas-stefano / The Solution.haml
Created December 22, 2010 13:24
Attempt to Reproduce the bug
### HAML AND DATAMAPPER ######
### Assuming that @episodes is:
#
# [#<Episode @id=1 @title="Cache Variable">, #<Episode @id=2 @title="Cache Variable"> , #<Episode @id=3 @title="Cache Variable">]
#
#current_episode
### HAML AND DATAMAPPER ######
### Assuming that @episodes is:
#
# [#<Episode @id=1 @title="Cache Variable">, #<Episode @id=2 @title="Cache Variable"> , #<Episode @id=3 @title="Cache Variable">]
#
#current_episode
- unless @episodes.empty?