I would like to include cron tasks in my Capistrano deployment files instead of using the following command to manually edit the crontab file:
crontab -e [username]
Is there a script I could use within the Capistrano run command to set the contents of the crontab?
...
Let's say I have a Ruby array
a = [1, 2, 3, 4]
If I want all but the first item, I can write a.drop(1), which is great. If I want all but the last item, though, I can only think of this way
a[0..-2] # or
a[0...-1]
but neither of these seem as clean as using drop. Any other built-in ways I'm missing?
...
I'm working on extending the NotAMock framework for stubbing methods in rspec, and getting the stubs to yield to a methods block.
The code in this Gist works perfectly when I code it on my own (which is done-up to resemble how NotAMock stubs methods).
but when I incorporate the object.instance_eval... code into the NotAMock framework, ...
I'm writing a delayed_job clone for DataMapper. I've got what I think is working and tested code except for the thread in the worker process. I looked to delayed_job for how to test this but there are now tests for that portion of the code. Below is the code I need to test. ideas? (I'm using rspec BTW)
def start
say "*** Starting...
I'm a little stumped on this one and I'm also not still on 1.8 so I don't have lookahead.
I have a bunch of strings which can look like:
"a/b/c/d/e/f 1/2/3"
which I want to turn into:
"a/b/c/d/e" "f" "1/2" "3"
So basically I want it to split by the last slash before the beginning of whitespace. I feel like I can do this normally b...
Ryan Tomayko touched off quite a fire storm with this post about using Unix process control commands.
We should be doing more of this. A lot more of this. I'm talking about fork(2), execve(2), pipe(2), socketpair(2), select(2), kill(2), sigaction(2), and so on and so forth. These are our friends. They want so badly just to help us.
...
Ruby Code:
# Turn hash input into JSON, store it in variable called "my_input"
my_input = { "itemFilter" => { "keywords" => "milk" }}.to_json
# Open connection to website.com
@http = Net::HTTP.new("website.com")
# Post the request to our API, with the "findItems" name and our JSON from above as the value
response_code, data = @ht...
Last night, I was thinking about what i think are advanced ruby language features, namely Continuations (callcc) and Binding objects. I mean advanced because I have a statically-typed oo langages background (C#, Java, C++), I discovered ruby very recently, so these language features are not very familiar to me.
I'm wondering what could...
I want to modify the test runner when using Ruby and shoulda. The standard runner produces output like this:
....
Finished in 0.009167 seconds
4 examples, 0 failures
As a starting point, I'd like to be able to modify this. Later, I want to create custom HTML output.
How do I get started on this? I've done a lot of googling, but can...
I've got a sorted array:
array = [[4, 13], [1, 12], [3, 8], [2, 8], [0, 3]]
Which shows me a position (array[n][0]) and the number of occurrences of that position (array[n][1]).
I need to test to see if more than one item in the array has the same number of occurrences as the last item.
I thought I might be able to do it with this:
...
Hello .
I have to confirm the detail of my gradutaion project recently.
My setup a goal for myself, that is it should have values( maybe as a opensource project or tools that can be use by others).
Can you suggest some ideas or projects pertaining to one of :
Web architect, Social Media, Ruby, ROR, Testing.
Thanks!:D
...
On my Ruby on Rails application I need to execute 50 background jobs in parallel. Each job creates a TCP connection to a different server, fecths some data and updates an active record object.
I know different solutions to perform this task but any of them in parallel. For example, delayed_job (DJ) could be a great solution if only it c...
I'm curious as to why when I build my project using CruiseControl.rb, it runs it in production mode? Even though my application should not be in production mode. I even tried to specify: ENV['RAILS_ENV'] ||= 'development' in my app's environment.rb
...
-> irb
>> (Date.today +3).to_s
=> "2009-10-22"
>> (Date.today + 3).to_s
=> "2009-10-25"
between "+3" and "+ 3", there is a difference?
...
Thanks to the help in a previous question, I've got the following code returning the expected results with find_all.
Original array (sorted by votes[0]):
votes_array = [{"votes"=>[13], "id"=>"4", "elected"=>0}, {"votes"=>[12], "id"=>"1", "elected"=>0}, {"votes"=>[8], "id"=>"3", "elected"=>0}, {"votes"=>[3], "id"=>"2", "elected"=>0}, {...
I'm new to RoR, and I've just used scaffold to generate a table and create the pages for CRUD operations. Now I want to add a new field to this. One place I found tells me how to do that in the database, but is there a way to do it where it will add the field to all the pages too, or is that just a manual operation and I need to make sur...
I am trying to import data from a DB to another. The source DB has TIMESTAMP (mysql) the destination has DATETIME (mysql). I am trying something like that:
start_at = DateTime.at(row['QA_CONF_START_STAMP']) #start_at
But it is not working
...
I'm interested in how one would go in getting this to work :
me = "this is a string"
class << me
alias :old<< :<<
def <<(text)
old<<(text)
puts "appended #{text}"
end
end
I'd like that when something gets appended to the me variable, the object will use the redefined method.
If I try to run this, I get syntax error, une...
Basically what the question says. How can I delete a character at a given index position in a string? The String class doesn't seem to have any methods to do this.
If I have a string "HELLO" I want the output to be this
["ELLO", "HLLO", "HELO", "HELO", "HELL"]
I do that using
d = Array.new(c.length){|i| c.slice(0, i)+c.slice(i+1, c....
Example
business_hours['monday'] = [800..1200, 1300..1700]
business_hours['tuesday'] = [900..1100, 1300..1700]
...
I then have a bunch of events which occupy some of these intervals, for example
event = { start_at: somedatetime, end_at: somedatetime }
Iterating over events from a certain date to a certain date, I create another ar...