Skip to content

Instantly share code, notes, and snippets.

View samnang's full-sized avatar
🚀

Samnang Chhun samnang

🚀
View GitHub Profile
@samnang
samnang / mysql_database_factory.rb
Created October 25, 2010 15:34
Implement Abstract Factory
class MySqlDatabaseFactory
class << self
def create_connection
MySqlConnection.new
end
def create_generator
MySqlGenerator.new
end
end
@samnang
samnang / program.rb
Created October 26, 2010 17:35
Temperature Converter
require 'temperature_converter'
#================= Program ==================#
print %Q{
Welcome to super simple temperature converter
=============================================
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
Please select our converter method[1]:}
@samnang
samnang / program.rb
Created October 26, 2010 17:39
Rubyists are cool! is another example of Ruby metaprogramming.
class Person < Struct.new(:name, :programs_ruby)
def cool_feeling
puts "#{name} is definietly cool!"
end
end
class People < Struct.new(:list)
def who
SelectQuery.new(self)
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
get "/proof/:id" do
@color = "red"
@listing = Listing.first(:alias_id => params[:id], :portal_uuid => 'A4E7890F-A188-4663-89EB-176D94DF6774')
nokogiri :proof
end
get "/directory" do
@categories = Category.all(:portal_uuid => "A4E7890F-A188-4663-89EB-176D94DF6774",
:subcategory_count => 0,
1. Why use VIM?
VIM rocks!
VI or VIM?
I hate the mouse!
I am a text person
I love touch-typing (huh - what is touch typing% again..)
You have production server with only SSH access!
2. Vim -- you already knew
Command mode & Insert mode
@samnang
samnang / metaprogramming_ex2.rb
Created December 10, 2010 08:31
Write your code here. Use binding method without using any variables or constants or define_singleton_method.
class A
@@a = 1
@a = 2
a = 3
singleton_class.send(:define_method, :bindings) { binding }
end
p eval('[@@a, @a, a]', A.bindings)
ID, account, tel, last_access, name
'A-23-112', 'ashbb', 2234, 'Aug 13th', 'Satoshi'
'B-34-122', 'tiger', 5543, 'May 1st', 'Satish'
'A-15-982', 'pen', 7812, 'Sep 24th', 'Michael'
//Swap value between two variables
int a = 5, b = 10;
int temp = a;
a = b;
b = temp;
//Output message 3 times
for(int i = 0; i <= 3; i++)
Console.WriteLine("Hello");
class A
end
puts "--" + A.instance_methods(false).join(', ')
class A
def otro
end
end