This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>My To Do list</h2> | |
<ul> | |
<li> | |
Go to the mall | |
</li> | |
<li> | |
Send a letter | |
</li> | |
<li> | |
Pay the bill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
regexp = '\w(\d)' | |
string = 'abc123!@#' | |
# 1st way - with #findall | |
occurances = re.findall(regexp, string) | |
print 'regexp:', regexp | |
print 'string:', string | |
print 'occurances:', occurances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f = open('my_file', 'w') | |
f.write("writing to file, line 1\n") | |
f.write("writing to file, line 2\n") | |
f.close() | |
f = open('my_file', 'r') | |
for line in f.readlines(): | |
print line | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xboxdrv --trigger-as-button --wid 0 --led 2 --deadzone 4000 --silent & | |
sleep 1 | |
xboxdrv --trigger-as-button --wid 1 --led 3 --deadzone 4000 --silent & | |
sleep 1 | |
xboxdrv --trigger-as-button --wid 2 --led 4 --deadzone 4000 --silent & | |
sleep 1 | |
xboxdrv --trigger-as-button --wid 3 --led 5 --deadzone 4000 --silent & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#example.rb | |
class Example | |
def initialize(method_name) | |
send method_name | |
end | |
end | |
#example_test.rb | |
require 'mocha' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span | |
onmousedown='document.getElementById("display").innerHTML += "mousedown<br />"' | |
onclick='document.getElementById("display").innerHTML += "click<br />"' | |
onmouseup='document.getElementById("display").innerHTML += "mouseup<br />"'> | |
Click me! | |
</span> | |
<br /> | |
<span id='display'> | |
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Time | |
def last_month_day | |
Date.new(self.year, self.mon, -1).day | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def method(var = 123) | |
var+=1 | |
end | |
def another_method(var) | |
var ||= 123 | |
var+=1 | |
end | |
method(nil) #first method raises <<undefined method `+' for nil:NilClass>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1..5).map{|n|n.succ} | |
(1..5).map(&:succ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def method(arg) | |
#<<arg>> is not a local copy of global variable - <<string>> and <<arg>> are the same object. | |
arg.upcase! | |
arg.object_id #We will return object_id to see if it's true | |
end | |
string = 'John' | |
id = string.object_id | |
id2 = method(string) | |
id == id2 #=> true |
OlderNewer