Skip to content

Instantly share code, notes, and snippets.

View forresty's full-sized avatar

Feng Ye forresty

View GitHub Profile
module Androsphinx
class Node
# 最基础的树节点
def initialize(name)
@name = name
@childrens = []
end
def add_child(child)
@childrens << child
#require the csv done
#create array done
#extract email address done
#push address into array done
#create a hash done
#for each address in the array
#if in the hash, ++
#if not, set the value to 1
#sort the hash by value
#top 5
class Fixnum
alias :original_plus :+
def +(another)
original_plus(another).original_plus(another)
end
end
puts 1 + 1
# 1. print welcome message
# 2. ask for first number (or exit)
# 3. ask for operation (or exit)
# 4. ask for second number (or exit)
# 5. perform calculation
# 6. show result
# 7. go back to 2
# Armanni TODO required file DONE
# grabbed text from file DONE
# filter the text
# split it with empty space DONE
# downcase text DONE
# create empty hash DONE
musicians = [
'Jimmy Page',
'Bieber',
'Robert Plant',
'John Paul Jones',
'John Bonham'
]
# def print_musicians(musicians)
forrest_is_handsome && forrest_is_tall # => false
forrest_is_handsome || forrest_is_tall # => true
def colorful?(number)
nums = number.to_s.split('').map(&:to_i)
results = []
(1..nums.size).each do |batch_size|
(0..(nums.size - batch_size)).each do |start_pos|
product = nums[start_pos, batch_size].inject(&:*)
require_relative 'tic_tac_toe'
def print_board(board)
puts board[0..2].join
puts board[3..5].join
puts board[6..8].join
end
def prompt_player_input(player)
puts "Player #{player}, now is your turn. enter position (0..8)"
@forresty
forresty / unicode_whitespace.rb
Created March 9, 2015 13:54
find what [[:space:]] really is
#!/usr/bin/env ruby
(0...1114112).each do |i|
next if (0xD800..0xDFFF).include?(i) # surrogate area
str = [i].pack('U*')
if str.match(/[[:space:]]/)
p [i, str]
end
end