How would I do something like below?
[
'foo'
['bar', 'baz'],
[
'one',
['two', 'three']
]
].each { |word| puts word }
# I want this to return:
foo
bar
baz
one
two
three
Many job sites have broken searches that don't let you narrow down jobs by experience level. Even when they do, it's usually wrong. This requires you to wade through hundreds of postings that you can't apply for before finding a relevant one, quite tedious. Since I'd rather focus on writing cover letters etc., I want to write a program to look through a large number of postings, and save the URLs of just those jobs that don't require years of experience.
I don't require help writing the scraper to get the html bodies of possibly relevant job posts. The issue is accurately detecting the level of experience required for the job. This should not be too difficult as job posts are usually very explicit about this ("must have 5 years experience in..."), but there may be some issues with overly simple solutions.
In my case, I'm looking for entry-level positions. Often they don't say "entry-level", but inclusion of the words probably means the job should be saved.
Next, I can safely exclude a job the says it requires "5 years" of experience in whatever, so a regex like /\d\syears/ seems reasonable to exclude jobs. But then, I realized some jobs say they'll take 0-2 years of experience, matches the exclusion regex but is clearly a job I want to take a look at. Hmmm, I can handle that with another regex. But some say "less than 2 years" or "fewer than 2 years". Can handle that too, but it makes me wonder what other patterns I'm not thinking of, and possibly excluding many jobs. That's what brings me here, to find a better way to do this than regexes, if there is one.
I'd like to minimize the false negative rate and save all the jobs that seem like they might not require many years of experience. Does excluding anything that matches /[3-9]\syears|1\d\syears/ seem reasonable? Or is there a better way? Training a bayesian filter maybe?
Given a Rakefile that executes some RSpec tests by way of a Spec::Rake::SpecTask, how can I programmatically determine the number of tests that passed, failed, and are pending once the task that ran the tests is finished?
Hi
I know this is something simple I am doing wrong.
I have three tables, installation, neighborhood, schools
Installation:
has_many :schools
has_many :neighborhoods
Neighborhood:
has_many :installations
has_many :schools
Schools:
belongs_to :installations
belongs_to :neighborhoods
I can't figure out how to show the name of the neighborhood the school is located in on the index view. I can get it to show on the show view once I have the school id. But on the index view I can't figure out what to put in the controller that will allow me to access the neighborhood name from the neighborhood_id that is in the School model. I am sure this is so easy and I am screwing up something stupid.
HELP!
Hello,
I often need to assign a variable, if the source value is set. So far I have done it like this:
filters[:red] = params[:search][:red] unless params[:search][:red].nil?
This works but looks a bit clumsy. There must be a more DRY way of getting this result.
Any suggestions?
Best regards.
Asbjørn Morell.
I have a program that takes as input an array of lat/long points. I need to perform a check on that array to ensure that all of the points are within a certain radius. So, for example, the maximum radius I will allow is 100 miles. Given an array of lat/long (coming from a MySQL database, could be 10 points could be 10000) I need to figure out if they will all fit in a circle with radius of 100 miles.
Kinda stumped on how to approach this. Any help would be greatly appreciated.
I'm trying to configure Paperclip to provide different missing images based on the instance's category attribute. Every category of the object has its own missing image.
This is my first take:
EDIT to add full models:
class Service < ActiveRecord::Base
attr_accessible :logo, :logo_file_name, :logo_content_type, :logo_file_size, :logo_updated_at
belongs_to :category, :counter_cache => true
has_attached_file :logo,
:path => "/:id-:style-:filename",
:url => ":s3_eu_url",
:default_url => "/logos/:style/#{self.category.name]}.png",
:styles => { :large => "600x400>",
:medium => "300x200>",
:small => "100x75>",
:thumb => "60x42>" }
end
class Category < ActiveRecord::Base
attr_accessible nil
has_many :services
end
In my view, image_tag service.logo.url(:thumb) outputs:
undefined method `category' for #<Class:0x0000010a731620>
Any ideas?
EDIT2:
A working default_url is :default_url => "/logos/:style/missing.png",
SOLUTION:
See my own answer below.
When building the following factory:
Factory.define :user do |f|
f.sequence(:name) { |n| "foo#{n}" }
f.resume_type_id { ResumeType.first.id }
end
ResumeType.first returns nil and I get an error.
ResumeType records are loaded via fixtures. I checked using the console and the entries are there, the table is not empty.
I've found a similar example in the factory_girl mailing list, and it's supposed to work.
What am I missing? Do I have to somehow tell factory_girl to set up the fixtures before running the tests?
I have a script file for parsing through a SQLite database. I now need to create a CRON job that will download and unzip said database from a third-party (already hosting as SQLITE). I understand this can be done using WGET and UNZIP, but given Heroku's read only file system, is this possible entirely in memory? Thanks.
I'm getting the following error:
Unknown action
No action responded to show. Actions: activate, destroy, index, org_deals, search, and suspend
Controller:
class Admin::HomepagesController < Admin::ApplicationController
def org_deals
@organization = Organization.find(:all)
end
Routes:
admin.resources :organizations, :collection => {:search => :get}, :member => {:suspend => :get, :activate => :get}
To note: This is a controller inside of a controller.
Any ideas why this is?
Hello:
I have a note table with columns:
title :string
content :text
rating :integer
and a thinking_sphinx configuration:
define_index do
indexes :title, :sortable => true
indexes :content
end
Then I can search the notes and assign weights to title and content to define the order or the result:
Note.search "abc", :match_mode => :extended, :field_weights => {
:title => 10,
:content => 3
}
Now I want to assign a weight to the rating column
The type of the rating column is integer. The range of the rating is [1, 2, 3, 4, 5].
Can I just add weight at the :field_weights
:field_weights => {
:title => 10,
:content => 3,
:rating => 5
}
or I need to do something else to make the note which has higer rating display first?
I have four models:
User
Award
Badge
GameWeek
The associations are as follows:
User has many awards.
Award belongs to user.
Badge has many awards.
Award belongs to badge.
User has many game_weeks.
GameWeek belongs to user.
GameWeek has many awards.
Award belongs to game_week.
Thus, user_id, badge_id and game_week_id are foreign keys in awards table.
Badge implements an STI model. Let's just say it has the following subclasses: BadgeA and BadgeB.
Some rules to note:
The game_week_id fk can be nil for BadgeA, but can't be nil for BadgeB.
Here are my questions:
For BadgeA, how do I write a validation that it can only be awarded one time? That is, the user can't have more than one -- ever.
For BadgeB, how do I write a validation that it can only be awarded one time per game week?
Hello there.
I'm trying to make this test fail :)
it "should display the question" do
@ui.should_receive(:puts).with("What's your name?").once
@ui.ask_question("What's your name?")
end
At the moment it passes even if I don't call puts in my function.
My situation is like this.
Company has many users and users may belongs to many companies.
And current implementation is something like below.
class Company
has_many :employments
has_many :users, :through = :employments
end
class Employment
belongs_to :company
belongs_to :user
end
class User
has_many :employments
has_many :companies, :through = :employments #This doesn't looks correct
end
User has many companies doesn't looks logically meaningful.It must be some thing like belongs_to_many companies.
Do I need to use has_and_belongs_to_many? But that also will gives the same meaning.
Can some one please suggest the right way for representing these relationships?
I have a Model Campaign.
A Campaign has many Events.
Each Event has an attribute :days.
A Campaign also has_many Contacts.
Each Contact as a :date_entered attribute.
The from_today(contact,event) method returns a number, which is the number of days from the contact's :date_entered till today minus the event's :days. In other words, a positive number shows the number of days from today till the :days of the event is elapsed. If it is negative, if means that the number of days that has elapsed since the :date_entered is greater than the :days attribute of an event. In other words, the event is overdue.
What I would like to be able to do is do campaign.overdue and this would result in a total number of contacts that have an overdue event. It shouldn't count multiple events for a single contact, just one contact.
How do I do that? It seems like I would need to cycle through all the events for every contact and keep a counter but I'm assuming that there is a better way.
This is my code:
[email protected] do |a|
-if @i%3 == 0
%ul
%li=link_to a.name, a
-@i += 1
I need the li to be inside the ul which is inside the if-statement.
I can't do it because of the indentation. Can't I just tell the li to indent automatically?
Thanks
thanks for your time first...after all the searching on google, github and here, and got more confused about the big words(partition/shard/fedorate),I figure that I have to describe the specific problem I met and ask around.
My company's databases deals with massive users and orders, so we split databases and tables in various ways, some are described below:
way database and table name shard by (maybe it's should be called partitioned by?)
YZ.X db_YZ.tb_X order serial number last three digits
YYYYMMDD. db_YYYYMMDD.tb date
YYYYMM.DD db_YYYYMM.tb_ DD date too
The basic concept is that databases and tables are seperated acording to a field(not nessissarily the primary key), and there are too many databases and too many tables, so that writing or magically generate one database.yml config for each database and one model for each table isn't possible or at least not the best solution.
I looked into drnic's magic solutions, and datafabric, and even the source code of active record, maybe I could use ERB to generate database.yml and do database connection in around filter, and maybe I could use named_scope to dynamically decide the table name for find, but update/create opertions are bounded to "self.class.quoted_table_name" so that I couldn't easily get my problem solved. And even I could generate one model for each table, because its amount is up to 30 most.
But this is just not DRY!
What I need is a clean solution like the following DSL:
class Order < ActiveRecord::Base
shard_by :order_serialno do |key|
[get_db_config_by(key), #because some or all of the databaes might share the same machine in a regular way or can be configed by a hash of regex, and it can also be a const
get_db_name_by(key),
get_tb_name_by(key),
]
end
end
Can anybody enlight me? Any help would be greatly appreciated~~~~
Hi, I would like to go through a table and look for a word, if that word appears, i would like to click on a radio button in the same row, but not the same column, then stop the loop.
I have something like this at the moment but i dont know where to go on from here.
@ie.div(:class, 'tableclass').table(:index, 1).each do | row |
row.each do | cell |
if (cell.text() == 'text')
##Set radio button
break end end end
I tried selecting a radio by name and index, but i do not know how to get the row number that it is currently at. Thanks.
I want to replace the inner_text in all paragraphs in my XHTML document.
I know I can get all text with Nokogiri like this
doc.xpath("//text()")
But I want only operate on text in paragraphs, how I can select all text in paragraphs without affecting eventually existent anchor texts in links ?
#For example : <p>some text <a href="/">This should not be changed</a> another one</a>
example: Person has_many Comments. Comments has named_scope :approved. And I need to serialize Person with all approved comments to JSON. So it should look like this:
person.to_json(:include => :comments)
but how can I add there that named scope? To serialize just that approved ones?
I have a bunch of rake building tasks.
They each have unique input / output properties, but the majority of the properties I set on the tasks are the same each time. Currently I'm doing that via simple repetition like this:
task :buildThisModule => "bin/modules/thisModule.swf"
mxmlc "bin/modules/thisModule.swf" do |t|
t.input = "src/project/modules/ThisModule.as"
t.prop1 = value1
t.prop2 = value2 ... (And many more property=value sets that are the same in each task)
end
task :buildThatModule => "bin/modules/thatModule.swf"
mxmlc "bin/modules/thatModule.swf" do |t|
t.input = "src/project/modules/ThatModule.as"
t.prop1 = value1
t.prop2 = value2 ... (And many more property=value sets that are the same in each task)
end
In my usual programming headspace I'd expect to be able to break out the population of the recurring task properties to a re-usable function.
Is there a rake analogy for this? Some way I can have a single function where the shared properties are set on any task? Something equivalent to:
task :buildThisModule => "bin/modules/thisModule.swf"
mxmlc "bin/modules/thisModule.swf" do |t|
addCommonTaskParameters(t)
t.input = "src/project/modules/ThisModule.as"
end
task :buildThatModule => "bin/modules/thatModule.swf"
mxmlc "bin/modules/thatModule.swf" do |t|
addCommonTaskParameters(t)
t.input = "src/project/modules/ThatModule.as"
end
Thanks.
I think I'm just missing something obvious. I send a user a perishable token embedded in a link. They click on it, and they come back to the site. I want to log them in automatically (I'm not building a banking app).
This seems like this should be simple, but all the examples I've found require a password. How do I skip this completely? I just seem to get UserSession.create to work.
When I try to pull down a database while at work I get the following error:
:>heroku db:pull
Auto-detected local database: sqlite://db/development.sqlite3
Bad credentials given for http://heroku:[hidden]@taps.heroku.com
Note that when I am at home I am able to run this command just fine. I wanted to know if you have any suggestions for common reasons I would get this error.