If a regular internet user wishes to contact a TCP service on their computer but without having to go through the hassle of firewall translation I think I'm right in saying that the 'best' way to do this is by having a 3rd party in the middle that will accept connections from both the user's home computer and their travelling computer an...
I'd like to understand how the following code works:
def url
@url ||= {
"basename" => self.basename,
"output_ext" => self.output_ext,
}.inject("/:basename/") { |result, token|
result.gsub(/:#{token.first}/, token.last)
}.gsub(/\/\//, "/")
end
I know what it does; somehow it returns the url corresponding to a file loc...
I've been rooting around through the net/http code and haven't quite come up with a solution for this. I need to perform a multipart POST request, which I have already figured out, but it would be really nice to inject a callback periodically in the upload so I could increment a progress bar. Does anyone know a way to get code to execute...
Hi guys,
I've been struggling with this one the whole day. In my Rails 2.3.5 app, I had a bunch of custom code which allowed the following to happen:
>> strip_hash_keys_for_json({ "a" => 1 }).to_json
=> "{ a: 1 }"
So you see that string keys don't get quoted. It was implemented by creating a String descendant class that returned self...
Let's say I used the following command to create a "User" model:
script/generate model User username:string
This creates the user.rb file along with the migration rb file to create the Users table. Now, I want to add an email column to my User model. What's the best way to do that? Do I do it manually and write the migration file by ha...
I currently have an RoR app in production across four application servers with independent logs per instance. What's the best way to aggregate the logging to a common location without resorting to syslog?
...
I need to keep track of the users lat/lng/city/country for my application with the following two requirements:
1) Get the users lat/lng/city/country automatically. (This is easy, I can use the ip or if they have a browser that supports geolocation, even better).
2) The user is allowed to customize this location (maybe the ip address lo...
Hi,
I have a CommonFunctions Module inside the lib/ folder. I have a Question Model, which includes the CommonFunctions module. Now I am trying to access the favorite function of the CommonFunctions like Question.favorite. But I am getting NoMethodError. I have included the code. Can anyone please tell me where I am doing the mistake
E...
How would one install rubygems on a usb stick so that it would work like it would normally, but all files go on the stick? I have no experience at all with rubygems and have no idea of its inner workings, so please, go easy on me! Thanks in advance, ell.
Edit: Basically, so it is entirely portable!
...
Is there a way to work with HDFS Api using Ruby? As I can understand there is no multilanguage file Api and the only way is to use native Java Api. I tried using JRuby but this solution is to unstable and not very native. Also I looked at HDFS Thrift Api but it's not complete and also lacks many features (like writing to indexed files).
...
Hi,
I am trying to retrieve the class name of an object. When I tried using the const_get, i am getting the entire model's table structure. So I used the following code.
Code
def classname(object)
return object.class.to_s.split("(")[0]
end
def classrating(object_id)
classtype = classname(object_id)
return classtype
...
Is there a way to create aliases for instance variables (not talking about db alias attributes) other than assigning it to another instance var?
For ex:
@imavar
alias_attribute(@hesavar, @imavar)
...
Hello, I haven't used Ruby. I don't what gems are. But I know how to install them and do basic things like that.
I heard of Jekyll and decided to start my own using Heroku. I found Rack-Jekyll that will work on Heroku.
I created my site as per Jekyll instructions and it is running fine on my system. Then I did what I was told to do in ...
Can Ruby 1.9.1 finally get a list of filenames if the filenames have unicode characters on Windows?
I think back in the Ruby 1.8.6 and 1.8.7 days, that wasn't possible on Windows.
...
RubyGems.org, the official gems site, provides poor functions. I want to find some good gems for my website, but it's impossibleit only provides several "New Gems" / "Most downloaded today" gems, and a list of all gems by indices. And the "search" is poor as well.
Anyone know any good site for finding/voting and discussing gems?
...
I checked here a while ago, and learned how to open firefox from within Ruby (from this post http://stackoverflow.com/questions/435328/open-firefox-browser-with-ruby-automation-script ), and I just made a script which would open all of my common internet sites when run, but it only does so if firefox is already open. If it is not open, i...
I'm using ruby and googles reverse geocode yql table to ideally automate some search query I have. The problem I hit is turning the query into a legal url format. The issue is that the encoding I'm using is returning illegal urls. The query I'm running is as follows
query="select * from google.geocoding where q='40.714224,-73.961452'"
...
I would like to dynamically specify the parent class for a class in Ruby. Consider this code:
class Agent
def self.hook_up(calling_class, desired_parent_class)
# Do some magic here
end
end
class Parent
def bar
puts "bar"
end
end
class Child
def foo
puts "foo"
end
Agent.hook_up(self, Parent)
end
Child.new.b...
I do dump the value of RUBY_VERSION => 1.8.7
every time, the value of [1,3,5].shuffle is also [1,3,5]
i have to add a srand(Time.now.to_i) or srand() in front of it to make it random...
I thought srand is automatically called? but maybe not in a .cgi environment?
if i use irb, and look at [1,3,5].shuffle, and exit, and re-enter irb, e...
Hi,
I am trying to find all the subclasses of a certain type called Command in Ruby, and I came across the following code which did the trick perfectly, however I don't really understand how it works, mainly the class << [Subtype] part. I have tried reading up on this, but I feel there is still some Ruby magic which I am missing. Can so...