William Jones

1

votes
1

answer
268

views

How to get all docvecs of a model

I have around a 1000 documents, and I have trained them using gensim's doc2vec class. I need all the 1000 docvecs from the model to perform a kmeans clstering. But the maximum docvecs I'm able to get is 10. Any idea, how to get all of them?. Below is my code snippet. ` tagged_data = [TaggedDocument(...
William Jones
1

votes
0

answer
32

views

Javascript: setInterval pausing and skipping while tab is inactive

If setInterval's interval is 10 milliseconds, then it will pause if the tab is inactive, but if it is set to 1 second, then it doesn't pause and keeps counting when the tab is inactive. Here are some examples: 1 second - num = 0; window.setInterval(function() { num = num + 1; document.getElementB...
William Jones
1

votes
1

answer
120

views

CSS to create a group of text with an even left edge with auto width

I'm trying to create a layout something like this (you'll need to use your imagination): A B B B A is a piece of text, B is a piece of text whose left edge I would like to line up evenly with itself. To further complicate matters, B is by default hidden, and should not be taken into account in set...
William Jones
1

votes
1

answer
255

views

Ruby on Rails testing: How can I test or at the very least see a form_for's error_messages_for?

I'm working on creating a tests, and I can't figure out why the creation of a model from a form_for is failing in the test but works in real browsers. Is there a straightforward way for me to see what the problems are in the model creation? Even better would be, is there a straightforward way for m...
William Jones
1

votes
2

answer
631

views

Smartest way to import massive datasets into a Rails application?

I've got multiple massive (multi gigabyte) datasets I need to import into a Rails app. The datasets are currently each in their own database on my development machine, and I need to read from them and create rows in tables in my Rails database based on the information they contain. The tables in m...
William Jones
1

votes
1

answer
319

views

Understanding REST conceptually with Rails

I'm a little late to the party, but I'm trying to wrap my brain around how REST is supposed to work, both in general and in Ruby on Rails. I've read a bunch of articles online about this already, but still don't feel like I'm getting the big picture. REST as I understand it, is a series of aspiratio...
William Jones
1

votes
1

answer
151

views

Ruby on Rails: Is there a way to temporarily disable polymorphic associations?

I've got an association between models that is polymorphic. Example: class Review belongs_to :review_subject, :polymorphic => true end However, I would like to make a call on this :review_subject association where I know all the results will be of a certain type. In my case, I want to do this so I c...
William Jones
1

votes
1

answer
103

views

Ruby on Rails: Update to a gem clobbering my model's pre-existing attribute, options?

A gem I've been using adds methods to models. It recently updated its method names such that one of the method names is now the same as one of my model's pre-existing database attributes. Are there any workarounds to this problem other than renaming the column in my database and updating all of my c...
William Jones
1

votes
1

answer
797

views

UWP/WinRT: How to make the tab key behave as normal in a TextBox?

By default, the Textbox doesn't insert tab characters. When you press Tab, it instead moves focus to the next element. When you press Ctrl-Tab, it inserts a tab character. How can this behavior be fixed to act like people normally expect text boxes to behave, such that the Tab key inserts an indent...
William Jones
1

votes
1

answer
24

views

Haskell string manipulation

I am trying to create a function that combines strings given a list of Integers. For example, say the function was given [1,2,3], then the output would be ' ***'. Basically, each number represents a * with spaces before it. So the number 5 would be ' *' which is 4 spaces followed by the *. Howeve...
William Jones
1

votes
2

answer
0

views

Ruby on Rails: How best to escape a string in a model?

I want my application to sanitize html on input rather than on display, so that the fields saved into the database are sanitized. I've been doing this with strip_tags, and it was working great. However, this has the downside that it means the user can't input anything that's bracketed with < and >....
William Jones
1

votes
2

answer
0

views

Ruby on Rails: How are people making search forms on sites with the broken textfield parsing that removes quotation marks?

I'm using Sunspot Solr search, which works fine for the most part for basic search. It's supposed to be able to handle quotation marks around phrases, so that a search for test case will return documents with both test and case, whereas a search for 'test case' should return documents with the phras...
William Jones
1

votes
1

answer
551

views

UWP/WinRT: How to enable undo hooks on a TextBox?

The TextBox class already supports undo, as it is present and functional in the context menu. I would like to implement undo/redo buttons as found in every common document editor such as Microsoft Word. They would be disabled when they have no action to take, and when there is an undo/redo stack to...
William Jones
1

votes
2

answer
991

views

UWP/WinRT: How to access a control generated by a template from the item it is bound to?

I have a Pivot whose contents are generated using data binding. For each Item in a vector, a Grid is generated, and within each grid a TextBlock is generated. If I have a particular Item from the vector, how can I access the corresponding TextBlock that was generated from it in my code behind? My fi...
William Jones
1

votes
2

answer
37

views

Rigidbodies moving without input when two levels are connected

I am trying to make to make a game in Unity where you collide with the button to open the door and access the next level. When the two levels are disconnected, like in the first picture, it functions perfectly and the player and doors do not move until a force is applied to them. But, if I change it...
William Jones
1

votes
1

answer
35

views

Unity - Object reference is set in editor but isn't set in game

I have a Unity project in which the door is set to the GameObject 'Door'. It is fine and set in the editor (i.e. when I'm not playing it), but as soon as I hit play, it turns to 'None (GameObject)'. My script uses the Rigidbody component of the door, but I access that through the script. Do I need t...
William Jones
1

votes
3

answer
298

views

Ruby on Rails: Is there a way to find with ActiveRecord that will first try the cache and if it fails run a query?

Let's say that I'm looking for a specific item in a has_many association. Is there a way to find that won't rehit the database if what I'm requesting is already cached? Here's my situation (which is not working and does not do what I requested): class User has_many :friendships def some_function(bud...
William Jones
1

votes
1

answer
270

views

Ruby on Rails: Best way to tie together two models that correspond one to one

If I have two models that are guaranteed to have a one-to-one correspondence, i.e. if one is created, I will always also need the other, and if one is deleted, I will also want to get rid of the other, what's the best way to tie them together? I see that the has_one/belongs_to :dependent method take...
William Jones
1

votes
3

answer
849

views

SQL statement to split a table based on a join

I have a primary table for Articles that is linked by a join table Info to a table Tags that has only a small number of entries. I want to split the Articles table, by either deleting rows or creating a new table with only the entries I want, based on the absence of a link to a certain tag. There ar...
William Jones
1

votes
2

answer
1k

views

How to get a Ruby substring of a Unicode string?

I have a field in my Rails model that has max length 255. I'm importing data into it, and some times the imported data has a length > 255. I'm willing to simply chop it off so that I end up with the largest possible valid string that fits. I originally tried to do field[0,255] in order to get this,...
William Jones
1

votes
1

answer
78

views

In unobtrusive JavaScript, once you've separated content and scripts, what do you do for a script that adds content?

I'm trying to follow best practices for unobtrusive JavaScript in my Rails 3 application. I've separated the HTML content and JavaScripts on my site for the most part. However, I have a form, where on the click of a script, it used to add additional HTML form elements. What's the best practice for t...
William Jones
1

votes
1

answer
3.3k

views

Ruby-on-Rails: How to pull out most recent entries from a limited subset of a database table

Imagine something like a model User who has many Friends, each of who has many Comments, where I'm trying to display to the user the latest 100 comments by his friends. Is it possible to draw out the latest 100 in a single SQL query, or am I going to have to use Ruby application logic to parse a big...
William Jones
5

votes
2

answer
3.3k

views

Ruby on Rails: Is there a way to make blank form inputs submit nil? [duplicate]

Possible Duplicate: Make blank params[] nil Is there a way to make blank form inputs submit nil? Right now, I'm going through and in a before_save manually converting all '' into nil. This really doesn't seem very DRY, and I feel like I must be missing something.
William Jones
2

votes
1

answer
1.1k

views

With Amazon EC2 and S3, is it possible to do both transfers to AND FROM S3 through EC2, making it free?

This may be a silly question, but seeing as transfers between EC2 and S3 are free as long as within the same region, why isn't it possible to stream all transfers to and from S3 through EC2 and make the transfers completely free? Specifically, I'm looking at Heroku, which is a Ruby on Rails hosting...
William Jones
2

votes
2

answer
265

views

When optimizing database queries, what exactly is the relationship between number of queries and size of queries?

To optimize application speed, everyone always advises to minimize the number of queries an application makes to the database, consolidating them into fewer queries that retrieve more wherever possible. However, this also always comes with the caution that data transferred is still data transferred,...
William Jones
2

votes
2

answer
61

views

jQuery function queueing confusion

I'm trying to understand exactly what it means when I put multiple calls in a row on jQuery, because I'm not getting the results I expect in similar situations. Example 1: $(this).animate({opacity: 0.25}, 250).animate({opacity: 1.0}, 250); As expected, this gives a quick flash of translucency before...
William Jones
21

votes
2

answer
8.9k

views

Best way to handle view and helper-only constants in Rails

I have a constant that is only used in views, but it's used in different ways in different places. It's an array of option names, and is used for select boxes, but I also use this in other views to see if strings are found in this array, and respond accordingly. What's the best way to handle this t...
William Jones
6

votes
2

answer
4.5k

views

Ruby on Rails: Use form_for on a model, and flip the form value

I've got a form_for form, and within it, I'm using a form helper check box. The model has a field that's a boolean value, but I'd like to be able to display it on my form in terms of its converse since I think that's easier for users to understand. Is there any way for me to have a Rails form helper...
William Jones
11

votes
5

answer
12.6k

views

Rails 3: How to trigger a form submission via javascript?

I have a form that for the most part just submits as a normal form, so I don't want to set in the form_tag the :remote => true option. However, under certain circumstances I'd like to be able have a javascript function post the form as if it had been posted by :remote => true. What would I need to d...
William Jones
2

votes
2

answer
784

views

Ruby on Rails: What are partial hash arguments and full set arguments?

I'm using asserts_redirected_to in my unit tests, and I'm receiving this warning: DEPRECATION WARNING: Using assert_redirected_to with partial hash arguments is deprecated. Specify the full set arguments instead. What is a partial hash argument, and what is a full set argument? These aren't terms t...
William Jones
5

votes
3

answer
1.8k

views

Ruby on Rails: Accessing production database data for testing

With Ruby on Rails, is there a way for me to dump my production database into a form that the test part of Rails can access? I'm thinking either a way to turn the production database into fixtures, or else a way to migrate data from the production database into the test database that will not get ro...
William Jones
4

votes
3

answer
3.4k

views

Ruby on Rails: How to set a database timeout in application configuration?

I'd like to set my database to timeout requests that do not complete within a set amount of time, in order to prevent outlier requests from monopolizing the entire application. Is there anything I can add to my Rails configuration files in order to set this? I tried to add a line I saw often online...
William Jones
6

votes
1

answer
2.4k

views

Counting string length in javascript and Ruby on Rails

I've got a text area on a web site that should be limited in length. I'm allowing users to enter 255 characters, and am enforcing that limit with a Rails validation: validates_length_of :body, :maximum => 255 At the same time, I added a javascript char counter like you see on Twitter, to give feedba...
William Jones
2

votes
1

answer
1.1k

views

Ruby on Rails: Best way to fill out a model Hash or Array field?

I've got a model that has a serialized hash as a field. I'm trying to create a form that enables users to fill this out. Is there a way to use Rails form_for helper to concisely build the hash? The model is an Article, and an Article can have many authors which are stored in a serialized hash. class...
William Jones
5

votes
1

answer
907

views

Rails 3: User input escaping working differently in views and mailer

I'm using the following set of code in both my views and the mailer: I begin by calling html_safe (h) on the user_input, in order to escape any dangerous code. I then call auto_link to enable any links in their input, and then I call simple_format to enable line breaks and such. This works perfectly...
William Jones
2

votes
1

answer
194

views

Avoiding Javascript Jumping Elements in Dynamic Forms

I'm trying to use javascript to code up a dynamic form, where elements are shown or hidden based on whether or not checkboxes are selected. For the most part, it works okay. I defined methods that read the value of the checkbox, and rearrange the page accordingly, and then set them to the checkboxe...
William Jones
2

votes
1

answer
898

views

How to make Ruby on Rails RESTful routes pretty and human friendly?

With Ruby on Rails, REST is a great concept in terms of simplifying things for the developer and making resources easy for machines to access, but it also produces phenomenally ugly URLs for humans. For example, using the popular RESTful Authentication plugin to handle user login and authentication,...
William Jones
12

votes
1

answer
12.2k

views

Ruby on Rails: How to sanitize a string for SQL when not using find?

I'm trying to sanitize a string that involves user input without having to resort to manually crafting my own possibly buggy regex if possible, however, if that is the only way I would also appreciate if anyone can point me in the right direction to a regex that is unlikely to be missing anything. T...
William Jones
1

votes
2

answer
974

views

Regex to strip symbols but not foreign characters in Ruby

Does anyone have a good regex for stripping all symbols (';.,_\[email protected]!% the carriage return etc) from a string, without damaging any foreign characters (é 多 فا etc)? Non-regex would be even better, I suppose, but I don't see any Ruby or Rails methods that do this.
William Jones
1

votes
3

answer
4k

views

Disabling forms with javascript on submit to prevent double submit

I'd like to disable a form after it is submitted in order to prevent double submissions. Pretty standard use case I would think, but all of the examples I can find out there are flawed. Everything I can find is based on disabling the submit button, but this doesn't prevent the form from being re-sub...
William Jones

View additional