Invalid JSON:Unexpected non-whitespace character after JSONat line 2, column 1
| {"QuestionId": 2390741, "AnswerCount": 2, "Tags": "<ruby-on-rails><activerecord>", "CreationDate": "2010-03-05T23:56:04.013", "AcceptedAnswerId": "2390862", "Title": "Correct ActiveRecord joins query assistance", "Body": "<p>Need a little help with a SQL / ActiveRecord query. Let's say I have this:</p>\n\n<pre><code>Article < ActiveRecord::Base\n has_many :comments\nend\n\nComment < ActiveRecord::Base\n belongs_to :article\nend\n</code></pre>\n\n<p>Now I want to display a list of \"Recently Discussed\" articles - meaning I want to pull all articles and include the last comment that was added to each of them. Then I want to sort this list of articles by the created_at attribute of the comment.</p>\n\n<p>I have watched the Railscast on include /joins - very good, but still a little stumped.</p>\n\n<p>I think I want to use a named_scope, something to this effect:</p>\n\n<pre><code>Article < ActiveRecord::Base\n has_many :comments\n\n named_scope :recently_commented, :include => :comments, :conditions => { some_way_to_limit_just_last_comment_added }, :order => \"comments.created_at DESC\"\nend\n</code></pre>\n\n<p>Using MySQL, Rails 2.3.4, Ruby 1.8.7</p>\n\n<p>Any suggestions? :)</p>\n", "Lable": "No"} | |
| {"QuestionId": 2489567, "AnswerCount": 1, "Tags": "<javascript><jquery><ruby-on-rails><ajax><json>", "CreationDate": "2010-03-22T01:34:57.107", "AcceptedAnswerId": null, "Title": "How to show server errors in Rails 2.3.5 with JSON and jQuery", "Body": "<p>I've got in-place editing on a page in my app (using Rails 2.3.5 and jQuery). I want to know how to display an error on the page when the update fails.</p>\n\n<p>I'm using ajax (an XMLHttpRequest) to save an update to a Comment object. The controller has an update method like this:</p>\n\n<pre><code>def update\n @comment = Comment.find(params[:id])\n respond_to do |format|\n # if @comment.update_attributes!(params[:comment])\n if false #deliberately forcing a fail here to see what happens\n format.json { render :nothing => true }\n else\n format.json { render :json => @comment.errors, :status => :unprocessable_entity }\n end\n end\nend\n</code></pre>\n\n<p>In Firebug, I can see the server returns a \"422\" (an appropriate validation error status code). But it's a response to an XMLHttpRequest so there is no redirect to an error page. </p>\n\n<p>I think I actually want to do this:</p>\n\n<pre><code>format.json { render :json => @comment.errors}\n</code></pre>\n\n<p>or maybe this:</p>\n\n<pre><code>format.json {render :json => { :status => :error, :message => \"Could not be saved\" }.to_json, :status => 400 }\n</code></pre>\n\n<p>and trigger some Javascript function that iterates through (and displays) any errors.</p>\n\n<p>I'm using a rails plugin <a href=\"http://github.com/janv/rest_in_place/\" rel=\"nofollow noreferrer\">REST in Place</a> to implement the in-place editing. It doesn't appear to have any callback function to handle a failure. What are my options? Can I write some Javascript to respond to a failure condition without hacking the plugin? Do I have to hack the rest_in_place plugin to handle a failure condition? Is there a better plugin (for Rails or jQuery) that handles in-place editing, including failure conditions?</p>\n\n<p><strong>UPDATE</strong></p>\n\n<p>This post from Peter Bui <a href=\"http://paydrotalks.com/posts/45-standard-json-response-for-rails-and-jquery\" rel=\"nofollow noreferrer\">Standard JSON Response for Rails and jQuery</a> was helpful in showing how to handle an error message from the server using <code>XMLHttpRequest.status</code>. I looked at his implementation of a blog using ajax <a href=\"http://github.com/paydro/talks\" rel=\"nofollow noreferrer\">paydro-talks</a>. I'm surprised at the complexity required to handle a simple error condition. Usually Rails has all the goodness baked in but it seems server errors with JSON are out of scope. Can that be?</p>\n\n<p>I also looked at grimen's <a href=\"http://github.com/grimen/validatious-on-rails/\" rel=\"nofollow noreferrer\">validatious-on-rails</a> which accommodates models validations when ajax XMLHttpRequest is used. It's not clear to me how I'd use it to handle the general case of a \"save\" failing when validations succeed.</p>\n", "Lable": "No"} | |
| {"QuestionId": 2598475, "AnswerCount": 2, "Tags": "<assembly><fibonacci><oisc>", "CreationDate": "2010-04-08T08:32:10.497", "AcceptedAnswerId": "2609628", "Title": "Fibonacci using SBN in OISC in Machine Language", "Body": "<p>I want to generate fibonacci series using SBN in an OISC architecture. My initial approach is to implement it in assembly language first and then convert it to machine language. The first steps involve storing 0 and 1 in 2 registers and then subtract 1 from 0 and repeatedly subtract 1 in the consequent steps. Everytime it will generate a negative number and since its negative, it branches off and fetches the absolute value finding instruction.</p>\n\n<p>Is my approach correct? My confusion in the meaning of OISC. Correct me if i'm wrong, if i perform a subtraction and then an absolute value finding, it means that that i'm using 2 instructions everytime. or is it that in the OISC processor both these instructions are done at the sametime which would mean that my approach is correct. </p>\n", "Lable": "No"} | |
| {"QuestionId": 2641122, "AnswerCount": 2, "Tags": "<asp.net><javascript><css><controls><formatting>", "CreationDate": "2010-04-14T21:19:27.397", "AcceptedAnswerId": "2641232", "Title": "Formatting Controls in ASP.NET", "Body": "<p>I feel as though this this is a simple question, but can't find an answer anywhere. We've got an interface we're trying to move to an ASP.NET control. It currently looks like:</p>\n\n<pre><code><link rel=\"\"stylesheet\"\" type=\"\"text/css\"\" href=\"\"/Layout/CaptchaLayout.css\"\" />\n<script type=\"\"text/javascript\"\" src=\"\"../../Scripts/vcaptcha_control.js\"\"></script>\n\n<div id=\"captcha_background\">\n <div id=\"captcha_loading_area\">\n <img id=\"captcha\" src=\"#\" alt=\"\" />\n </div>\n\n <div id=\"vcaptcha_entry_container\">\n <input id=\"captcha_answer\" type=\"text\"/>\n <input id=\"captcha_challenge\" type=\"hidden\"/>\n <input id=\"captcha_publickey\" type=\"hidden\"/>\n <input id=\"captcha_host\" type=\"hidden\"/>\n </div>\n\n <div id=\"captcha_logo_container\"></div>\n </div>\n</code></pre>\n\n<p>However all the examples I see of ASP.NET controls that allow for basical functionality - i.e.</p>\n\n<pre><code>public class MyControl : Panel\n{\npublic MyControl()\n{\n}\n\nprotected override void OnInit(EventArgs e)\n{\nScriptManager.RegisterScript( ... Google script, CSS, etc. ... );\n\n\nTextBox txt = new TextBox();\ntxt.ID = \"text1\";\nthis.Controls.Add(txt);\n\nCustomValidator vld = new CustomValidator();\nvld.ControlToValidate = \"text1\";\nvld.ID = \"validator1\";\nthis.Controls.Add(vld);\n}\n}\n</code></pre>\n\n<p>Don't allow for the detailed layout that we need. Any suggestions on how I can combine layout and functionality and still have a single ASP control we can drop in to pages? The ultimate goal is for users of the control to just drop in:</p>\n\n<pre><code><captcha:CaptchaControl ID=\"CaptchaControl1\" \nrunat=\"server\"\nServer=\"http://localhost:51947/\"\n/>\n</code></pre>\n\n<p>and see the working control.</p>\n\n<p>Sorry for the basic nature of this one, any help is greatly appreciated.</p>\n", "Lable": "No"} | |
| {"QuestionId": 2661248, "AnswerCount": 3, "Tags": "<objective-c><cocoa>", "CreationDate": "2010-04-18T05:34:17.387", "AcceptedAnswerId": "2661330", "Title": "Does the respondsToSelector method have to exist?", "Body": "<p>Does a method which I check for with respondsToSelector have to actually exist?</p>\n\n<p>What if I only define it in the interface part and fail to implement it? I'm looking at a poor-man's virtual function in Objective-C.</p>\n", "Lable": "No"} | |
| {"QuestionId": 2774889, "AnswerCount": 1, "Tags": "<xml><xslt>", "CreationDate": "2010-05-05T16:04:50.403", "AcceptedAnswerId": "2774958", "Title": "Issue with XSL for website sitemap XML", "Body": "<p>The XSL for a website sitemap is not working as expected.</p>\n\n<p>The URL elements are not being looped through?</p>\n\n<p>Please can you take a look:</p>\n\n<p>XML:</p>\n\n<p><a href=\"http://www.telephonesystems.co.uk/sitemap.xml\" rel=\"nofollow noreferrer\">http://www.telephonesystems.co.uk/sitemap.xml</a></p>\n\n<p>XSL:</p>\n\n<p><a href=\"http://www.telephonesystems.co.uk/css/sitemap.xsl\" rel=\"nofollow noreferrer\">http://www.telephonesystems.co.uk/css/sitemap.xsl</a></p>\n\n<p>Thanks</p>\n", "Lable": "No"} | |
| {"QuestionId": 2775778, "AnswerCount": 2, "Tags": "<php><mysql><twitter>", "CreationDate": "2010-05-05T18:26:47.217", "AcceptedAnswerId": "2775917", "Title": "Efficiently fetching and storing tweets from a few hundred twitter profiles?", "Body": "<p>The site I'm working on needs to fetch the tweets from 150-300 people, store them locally, and then list them on the front page. The profiles sit in groups. </p>\n\n<p>The pages will be showing</p>\n\n<ul>\n<li>the last 20 tweets (or 21-40, etc) by date, group of profiles, single profile, search, or \"subject\" (which is sort of a different group.. I think..)</li>\n<li>a live, context-aware tag cloud (based on the last 300 tweets of the current search, group of profiles, or single profile shown)</li>\n<li>various statistics (group stuffs, most active, etc) which depend on the type of page shown.</li>\n</ul>\n\n<p>We're expecting a fair bit of traffic. The last, similar site peaked at nearly 40K visits per day, and ran intro trouble before I started caching pages as static files, and disabling some features (some, accidently..). This was caused mostly by the fact that a page load would <em>also</em> fetch the last x tweets from the 3-6 profiles which had not been updated the longest..</p>\n\n<p>With this new site I can fortunately use cron to fetch tweets, so that helps. I'll also be denormalizing the db a little so it needs less joins, optimize it for faster selects instead of size.</p>\n\n<p>Now, <strong>main question</strong>: how do I figure out which profiles to check for new tweets in an efficient manner? Some people will be tweeting more often than others, some will tweet in bursts (this happens a lot). I want to keep the front page of the site as \"current\" as possible. If it comes to, say, 300 profiles, and I check 5 every minute, some tweets will only appear an hour after the fact. I can check more often (up to 20K) but want to optimize this as much as possible, both to not hit the rate limit <em>and</em> to not run out of resources on the local server (it hit mysql's connection limit with that other site).<br>\n<strong>Question 2:</strong> since cron only \"runs\" once a minute, I figure I have to check multiple profiles each minute - as stated, at least 5, possibly more. To try and spread it out over that minute I could have it sleep a few seconds between batches or even single profiles. But then if it takes longer than 60 seconds altogether, the script will run into itself. Is this a problem? If so, how can I avoid that?<br>\n<strong>Question 3:</strong> any other tips? Readmes? URLs?</p>\n", "Lable": "No"} | |
| {"QuestionId": 2841519, "AnswerCount": 1, "Tags": "<vb.net>", "CreationDate": "2010-05-15T19:45:15.570", "AcceptedAnswerId": "2841526", "Title": "Code snippet to lock my PC", "Body": "<p>This is a part of my project, my project basically uses a motion sensor to detect any intrusion. So one of the modules is to lock the PC on detection of an intruder. Is there a way to lock the PC using Visual Basic? </p>\n\n<p>(Because most of the other modules have been programmed in Visual Basic.) I am basically looking for source code that can implement something similar to \"Windows button + L\".</p>\n", "Lable": "No"} | |
| {"QuestionId": 2855550, "AnswerCount": 6, "Tags": "<naming-conventions><class-design><abstract-class>", "CreationDate": "2010-05-18T08:19:36.747", "AcceptedAnswerId": "2855598", "Title": "MyClassBase or BaseMyClass?", "Body": "<blockquote>\n <p><strong>Possible Duplicates:</strong><br>\n <a href=\"https://stackoverflow.com/questions/510839/using-base-in-a-class-name\">Using “Base” in a Class Name</a><br>\n <a href=\"https://stackoverflow.com/questions/826821/c-class-naming-convention-is-it-baseclass-or-classbase-or-abstractclass\">C# Class naming convention: Is it BaseClass or ClassBase or AbstractClass</a><br>\n <a href=\"https://stackoverflow.com/questions/429470/naming-conventions-for-abstract-classes\">Naming Conventions for Abstract Classes</a> </p>\n</blockquote>\n\n\n\n<p>What is the better way to name base abstract classes? I still can't decide where to put 'Base' word. Should it be 'BaseMyClass' or 'MyClassBase'?</p>\n\n<p>How do you name those and why?</p>\n", "Lable": "No"} | |