require 'rubygems'
require 'mongo'
require 'pry'
require 'win32ole'
db = Mongo::Connection.new.db("test")
x = db['text']
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
require 'win32ole' | |
#check if there is an excel application open | |
#yes | |
#check through the open excel applications, see if one of the tab names is the same as the one specified in the parameter | |
#yes | |
#set that workbook and that sheet equal to the variables @wb and @ws1 | |
#no | |
#create a new workbook, delete all of the pages except "Sheet1", rename "Sheet1" to "openxls" | |
#no |
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
require 'win32ole' | |
#check if there is an excel application open | |
#yes | |
#check through the open excel applications, see if one of the tab names is the same as the one specified in the parameter | |
#yes | |
#set that workbook and that sheet equal to the variables @wb and @ws1 | |
#no | |
#create a new workbook, delete all of the pages except "Sheet1", rename "Sheet1" to "openxls" | |
#no |
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
require 'win32ole' | |
#check if there is an excel application open | |
#yes | |
#check through the open excel applications, see if one of the tab names is the same as the one specified in the parameter | |
#yes | |
#set that workbook and that sheet equal to the variables @wb and @ws1 | |
#no | |
#create a new workbook, delete all of the pages except "Sheet1", rename "Sheet1" to "openxls" | |
#no |
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
require 'win32ole' | |
#check if there is an excel application open | |
#yes | |
#check through the open excel applications, see if one of the tab names is the same as the one specified in the parameter | |
#yes | |
#set that workbook and that sheet equal to the variables @wb and @ws1 | |
#no | |
#create a new workbook, delete all of the pages except "Sheet1", rename "Sheet1" to "openxls" | |
#no |
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
<%= form_tag("/search", :method => "get") do %> | |
<%= label_tag(:q, "Search for:") %> | |
<%= text_field_tag(:q) %> | |
<%= submit_tag("Search") %> | |
<% end %> | |
This will generate the following HTML: | |
<form accept-charset="UTF-8" action="/search" method="get"> | |
<label for="q">Search for:</label> | |
<input id="q" name="q" type="text" /> |
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
require 'string_score/ext/string' | |
"JAMES DOWNY".downcase.score("Downy, James".downcase) | |
#=> 0 | |
"JAMES DOWNY".downcase.score("James Downy".downcase) | |
#=> 1 | |
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
w = [[2],[1],[3]] | |
#=> [[2], [1], [3]] | |
x = w.dup | |
#=> [[2], [1], [3]] | |
x.each do |a| | |
a << 1 | |
end | |
Now you know the fundamental requirement for thread-safe code: mutation of shared state must be done atomically. Any time you change a variable that is shared by many threads, it needs to be done atomically. Unfortunately Ruby and most other mainstream languages only give you one tool to do this: the lock aka the mutex.
Mutex is short for “mutual exclusion” as in “only one thread can be executing this code at a time”. Usage is simple:
@mutex = Mutex.new
@mutex.synchronize do
i += 1
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
y = 3 | |
if y != 2 || y != 4 | |
puts "ok" | |
end | |
# => "ok" | |
# Is there a way to shorten this? |
OlderNewer