Checking user's input and disallowing certain words - ruby-on-rails

I have created a text input in which the user can input a website. However I want to disallow specific domains.
At first I want to be able to check if the input(domain, e.g. google.com) matches a specific word (e.g. google) - (I will later create a domains' blacklist).
In the controller (Rails) I want to check the input first before saving the object.
Any clue how can I check the input for a specific word?

You could do that in regexp but there is a gem that is compliant to several rfc that would suit you better:
https://github.com/sporkmonger/addressable#example-usage

You can try this
URI("http://www.google.com/").host =~ /google/
Here you can iterate through you blocked list of domains and can check above condition for each blocked domain.

Related

How to make active admin email search to trim preceeding suceeding spaces in rails application

i have active admin in my rails application. while searching the users based on their email,in the right side of the page(filters), if i enter any email that contains preceding and succeeding spaces,then the results are empty
i want to customise the active admin filter search, in such a way that it trims these preceding and succeeding spaces and provide the results while searching. how can i implement this. as i am new to the active admin i do not know how to customise it.
def override_search
end
It might be overkill, but one way would be to use a ransacker. Another way would be to define a custom formtastic input. However, the easiest way might be to attach some JavaScript to the input onBlur to trim any content before submission.

ResearchKit: Validate email

I'm attempting to create a form step where one of the form step items is an email input. For this I want to validate the email against certain domains i.e.
#gmail.com, #icloud.com, #me.com
I can see we have an email answer format in the form of this:
ORKEmailAnswerFormat()
However I can't see anywhere in this type that allows me to apply a validation regex. Looking into this I see we have the following
ORKAnswerFormat.textAnswerFormatWithValidationRegex(validationRegex, invalidMessage)
I suppose this is my best option? If so, would anyone know of a regex (my regex isn't the greatest!) in swift that would handle the 3 domains stated above?
I have something like this...(not the greatest i know!)
[A-Z0-9a-z._%+-]+#gmail.com
[A-Z0-9a-z._%+-]+#(?:icloud|me|gmail)\.com
(or, if you don't care about capturing:)
[A-Z0-9a-z._%+-]+#(icloud|me|gmail)\.com
Now I made two modifications. I escaped the . and I made it so that the other two domains are options.
I suggest that you convert the whole thing to lower case. I don't know Swift, but you may be able to use one of its functions or the i modifier:
(?i)[0-9a-z._%+-]+#(icloud|me|gmail)\.com

Quickfixj not honoring custom fields in a repeating group

I am using FIXT1.1 and FIX Application version 5.0SP2.
I added some custom fields to the QuotSetAckGrp, part of MassQuoteAcknowledgement message. However, when quickfix reads the repeating group, it does not read the custom fields as part of the repeating groups. Instead, it treats the custom fields are regular parent-level fields and throws a "Tag appears more than once" session level reject.
Appreciate any inputs to help resolve the issue.
You need to modify the receiver's AppDataDictionary to match the messages that your sender is sending. Also, you need to set UseDataDictionary=Y in your config.
QF/j needs to look at the DD xml file to know what fields are in a repeating group, else it cannot know where each group member ends.
When the engine encounters a field that isn't inside the DD's repeating group definition, it assumes that the current group member ended with the previous tag.
Here's a howto for customizing your DD:
http://quickfixn.org/tutorial/custom-fields-groups-and-messages
(The above link is for QF/n, but it's nearly the same for QF/j.)
See the QuickFIX/J User FAQ, topic "I altered my data dictionary. Should I regenerate/rebuild QF/J?".
OUTGOING MSGS: The DD xml file is irrelevant when you construct
outgoing messages. You can pretty much add whatever fields you want to
messages using the generic field setters (setString, setInt, etc) and
QF will let you. The only trouble is with repeating groups. QF will
write repeating group element ordering according to the DD that was
used for code generation. If you altered any groups that are part of
outgoing messages, you DEFINITELY need to rebuild.
To rebuild QuickFIX/J to accept your custom data dictionary, please refer to the answer I gave in the following StackOverflow post.
HTH.

Rails Dynamic tag generation from context

Let's say I want to trend all comments posted on a site and create dynamic tags. For example, If there are x number of comments that contain the word iPad I would like to create automatically create a tag called "iPad" and put it in a tag cloud.
Is this possible? I checked out the acts_as_taggable gem but it requires one to specify a tag, I guess I am looking for a way to generate tags from content.
Well something like the yahoo term extraction service might do the trick and there is a plugin for it http://expressica.com/auto_tags/.
Though it is not for commercial use.
Sure, this is possible.
Just parse the content of each comment as it's passed in and attach the tags you're interested in.
This can either work on a whitelist - where you specify all the tags you're interested in and attach those if relevant.
Or it could work on a blacklist - where you specify all the words to ignore, e.g. "the", "on". This approach is probably a lot more time consuming, but would allow for more dynamic results.
I would probably work on a white list, then have an ability to add new tags to the whitelist and have it go back and retroactively add the tags where applicable.

Django URLs - How to pass in multiple caterories via the clean URL without the need for?

I want to stay way from GET params. Don't want to use POST and I have at least two different categories to build the URL for.
The visitors are first asked to choose a location wich can be one of, for example:
http://foo.com/United-States/ ||
http://foo.com/United-States/California/ ||
http://foo.com/United-States/California/San-Francisco-Region/ ||
http://foo.com/United-States/California/San-Francisco/
Once a location is selected, then they can pick a category which can be one of for example:
http://foo.com/Electronics/ ||
http://foo.com/Electronics/Camera/ ||
http://foo.com/Electronics/Camera/Digital/ ||
http://foo.com/Electronics/Camera/Digital/SLR/
So, how would I go about combining both of the above URL in one, once they are done with selecting the location and the category?
I might need to pass in the page number for pagination. (http://foo.com/page/2/)
I'd like to keep the URL clean and self explanatory.
I know how to do one type of URL at a time but not combining multiple types.
If I were to do a GET, then I would be doing: http://foo.com/?locid=23323&catid=335&page=2, but I like to take advantage of Django's clean URL and stay way from the ?& stuff.
Thanks,
VN44CA
I think that this would be to many information in the URL. I assume that any location has its unique ID, the same goes to category. Why not build a URL:
http://foo.com/United-States/Electronics/
http://foo.com/California/Digital/
http://foo.com/San-Francisco/SLR/
and so on...
2 arguments are enough in your case. Or you can change category name to be more meaningful.
http://foo.com/Electronics/Camera/Digital/ => http://foo.com/Digital-Cameras/
Depending on how you are using the location data, and how often a user will want to change the location, it may be best stored in the session instead of having it specified in the URL.
For example, I am unlikely to start off looking for SLR digital cameras in San Francisco and then go looking for basketballs in Baltimore.
Obviously this won't be sufficient if you want permalinks to any location-category combination, though.
After thinking about this for a while, I found that the best solution (for me) to this is to have a string just hold all the arguments that I need in a clean URL.
So, when users first come to http://foo.com/ they are presented with a locations to select. Cookies are empty at this point.
So, a user goes ahead and selects United-State, the URL will look like http://foo.com/12334_0_0_0/United-States/ and the location cookie is set to 1234 which is the id for location United States.
Now the user selects California and the URL changes to http://foo.com/1235_0_0_0/United-States-California/ and cookie is replace from United states to 1235 which is the id for the location California. At this point the user selects Category Electronics. so the URL changes to http://foo.com/1235_3333_0_0/Electronics/ and 3333 is saved in the Category Cookies.
If the users drops down to SLR Camera, then s/he'll see http://foo.com/1235_3344_0_0/SLR-Cameras/.
This way, the first portion of the URL keeps track of up to 4 arguments which can be passed around and the names (slugs) are merely for presentation and SEO.
I think this would work right? It would be cool to have the x_y_z_p portion of the URL encoded into some random text and decode back into args & numbers.
Let me know what you do think?

Resources