Invalid JSON:Unexpected non-whitespace character after JSONat line 2, column 1
| {"QuestionId": 11565136, "AnswerCount": 1, "Tags": "<php><cakephp>", "CreationDate": "2012-07-19T16:23:14.880", "AcceptedAnswerId": "11565925", "Title": "CakeEmail - Send HTML and Plain-text message manually", "Body": "<p>I want to send a plain-text and html email from CakePHP using the built-in function, but without touching the .ctp files.</p>\n\n<p>Here's what i want from the CakeEmail : </p>\n\n<pre><code>//Send email to user\n$email = new CakeEmail('default');\n$email->to($customers['Customer']['email']);\n$email->subject('Password reset');\n$email->htmlMessage('<div>Reset the password</div>');\n$email->textMessage('Password the reset');\n$email->send();\n</code></pre>\n\n<p>But apparently, these functions don't exist, so anyone know of an alternative solution?\nI doesn't want to touch the Email folder of CakePHP, as the email layout & content is generated dynamically.</p>\n\n<p>Cake version 2.0.6</p>\n\n<p>Bascially, i want a CakePHP version of this code : <a href=\"http://www.daniweb.com/web-development/php/threads/2959/sending-htmlplain-text-emails\" rel=\"nofollow\">http://www.daniweb.com/web-development/php/threads/2959/sending-htmlplain-text-emails</a>\nCapable of sending both HTML and Plain-text email</p>\n", "Lable": "No"} | |
| {"QuestionId": 11580132, "AnswerCount": 1, "Tags": "<iphone><facebook><image><post><share>", "CreationDate": "2012-07-20T13:15:24.273", "AcceptedAnswerId": null, "Title": "Post image on Facebook wall through iPhone app", "Body": "<blockquote>\n <p><strong>Possible Duplicate:</strong><br>\n <a href=\"https://stackoverflow.com/questions/750328/documented-process-for-using-facebook-connect-for-the-iphone-to-upload-photos\">Documented process for using facebook connect for the iPhone to upload photos</a> </p>\n</blockquote>\n\n\n\n<p>I have a\u05de iPhone app and would like to know how to make an image which, when clicked, the image will be posted to the user's Facebook profile.</p>\n\n<p>The app is based on Facebook, i mean, you register with your Facebook account.</p>\n", "Lable": "No"} | |
| {"QuestionId": 11608532, "AnswerCount": 3, "Tags": "<python><comparison><set><python-2.x>", "CreationDate": "2012-07-23T08:03:19.127", "AcceptedAnswerId": "11608544", "Title": "How to hide the 'set' keyword in output while using set in python", "Body": "<p>Ok so I have two lists in python</p>\n\n<pre><code>a = ['bad', 'horrible']\nb = ['bad', 'good']\n</code></pre>\n\n<p>I'm using the set operator to compare the two lists and give an output if a common word exists between the two sets. </p>\n\n<pre><code>print set(a) & set (b)\n</code></pre>\n\n<p>This gives the output as,</p>\n\n<pre><code>set(['bad'])\n</code></pre>\n\n<p>Is there anyway to remove the keyword 'set' in the output??</p>\n\n<p>I want the output to look like</p>\n\n<pre><code>['bad']\n</code></pre>\n", "Lable": "No"} | |
| {"QuestionId": 11640681, "AnswerCount": 4, "Tags": "<c++><multithreading><mutex>", "CreationDate": "2012-07-24T23:19:52.140", "AcceptedAnswerId": "11640729", "Title": "Thread-safe way to build mutex protection into a C++ class?", "Body": "<p>I'm trying to implement a producer/consumer model multithreaded program in C++ for a project I'm working on. The basic idea is that the main thread creates a second thread to watch a serial port for new data, process the data and put the result in a buffer that is periodically polled by the main thread. I've never written multi-threaded programs before. I've been reading lots of tutorials, but they're all in C. I think I've got a handle on the basic concepts, but I'm trying to c++ify it. For the buffer, I want to create a data class with mutex protection built in. This is what I came up with.</p>\n\n<p>1) Am I going about this the wrong way? Is there a smarter way to implement a protected data class?</p>\n\n<p>2) What will happen in the following code if two threads try to call <code>ProtectedBuffer::add_back()</code> at the same time?</p>\n\n<pre><code>#include <deque>\n#include \"pthread.h\"\n\ntemplate <class T>\nclass ProtectedBuffer {\n std::deque<T> buffer;\n pthread_mutex_t mutex;\npublic:\n void add_back(T data) {\n pthread_mutex_lock(&mutex);\n buffer.push_back(data);\n pthread_mutex_unlock(&mutex);\n }\n void get_front(T &data) {\n pthread_mutex_lock(&mutex);\n data = buffer.front();\n buffer.pop_front();\n pthread_mutex_unlock(&mutex);\n }\n};\n</code></pre>\n\n<p>Edit:\nThanks for all the great suggestions. I've tried to implement them below. I also added some error checking so if a thread somehow manages to try to lock the same mutex twice it will fail gracefully. I think.</p>\n\n<pre><code>#include \"pthread.h\"\n#include <deque>\n\n\nclass Lock {\n pthread_mutex_t &m;\n bool locked;\n int error;\npublic:\n explicit Lock(pthread_mutex_t & _m) : m(_m) {\n error = pthread_mutex_lock(&m);\n if (error == 0) {\n locked = true;\n } else {\n locked = false;\n }\n }\n ~Lock() {\n if (locked)\n pthread_mutex_unlock(&m);\n }\n bool is_locked() {\n return locked;\n }\n};\n\nclass TryToLock {\n pthread_mutex_t &m;\n bool locked;\n int error;\npublic:\n explicit TryToLock(pthread_mutex_t & _m) : m(_m) {\n error = pthread_mutex_trylock(&m);\n if (error == 0) {\n locked = true;\n } else {\n locked = false;\n }\n }\n ~TryToLock() {\n if (locked)\n pthread_mutex_unlock(&m);\n }\n bool is_locked() {\n return locked;\n }\n};\n\ntemplate <class T>\nclass ProtectedBuffer{\n pthread_mutex_t mutex;\n pthread_mutexattr_t mattr;\n std::deque<T> buffer;\n bool failbit;\n\n ProtectedBuffer(const ProtectedBuffer& x);\n ProtectedBuffer& operator= (const ProtectedBuffer& x);\npublic:\n ProtectedBuffer() {\n pthread_mutexattr_init(&mattr);\n pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_ERRORCHECK);\n pthread_mutex_init(&mutex, &mattr);\n failbit = false;\n }\n ~ProtectedBuffer() {\n pthread_mutex_destroy(&mutex);\n pthread_mutexattr_destroy(&mattr);\n }\n void add_back(T &data) {\n Lock lck(mutex);\n if (!lck.locked()) {\n failbit = true;\n return;\n }\n buffer.push_back(data);\n failbit = false;\n }\n void get_front(T &data) {\n Lock lck(mutex);\n if (!lck.locked()) {\n failbit = true;\n return;\n }\n if (buffer.empty()) {\n failbit = true;\n return;\n }\n data = buffer.front();\n buffer.pop_front();\n failbit = false;\n }\n void try_get_front(T &data) {\n TryToLock lck(mutex);\n if (!lck.locked()) {\n failbit = true;\n return;\n }\n if (buffer.empty()) {\n failbit = true;\n return;\n }\n data = buffer.front();\n buffer.pop_front();\n failbit = false;\n }\n void try_add_back(T &data) {\n TryToLock lck(mutex);\n if (!lck.locked()) {\n failbit = true;\n return;\n }\n buffer.push_back(data);\n failbit = false;\n }\n};\n</code></pre>\n", "Lable": "No"} | |
| {"QuestionId": 11694623, "AnswerCount": 1, "Tags": "<c#><sql-server-ce>", "CreationDate": "2012-07-27T19:39:47.503", "AcceptedAnswerId": "11694843", "Title": "SQL Server Compact Insertion", "Body": "<p>i want to insert data into sql server Compact edition the database table screenshot is <a href=\"http://www.flickr.com/photos/56760865@N04/7657986538\" rel=\"nofollow\">Here >>> </a>\ni Want to add data in users the addition script is as follows</p>\n\n<pre><code>SqlCeConnection Con = new SqlCeConnection();\nCon.ConnectionString = \"Data Source = 'Database.sdf';\" +\n \"Password='Password';\";\nCon.Open();\nint Amount=Convert.ToInt32(AmBox.Text),\nCode=Convert.ToInt32(MCode.Text),\nNum=Convert.ToInt32(MNum.Text);\nstring Name=Convert.ToString(NBox.Text),\nFName=Convert.ToString(SOBox.Text),\nAddress=Convert.ToString(AdBox.Text);\n\nSqlCeCommand Query =new SqlCeCommand(\"INSERT INTO Users VALUES \" + \n \"(++ID,Name,FName,Address,Code,Num,Amount)\",Con);\nQuery.ExecuteReader();\n</code></pre>\n\n<p>When it runs it generates an error SAYING \"The column name is not valid [Node Name (if any) =,Column name=ID ]</p>\n\n<p>I don't figure out the problem kindly tell me thanks!</p>\n", "Lable": "No"} | |
| {"QuestionId": 11802853, "AnswerCount": 1, "Tags": "<c#><entity-framework>", "CreationDate": "2012-08-03T20:30:18.343", "AcceptedAnswerId": "11802879", "Title": "Initialize new instance of an entity framework object with constructor?", "Body": "<p>Is it possible to use a constructor with EF entities?</p>\n\n<p>I want to add a new instance of an Entity Framework entity and add it to a List<></p>\n\n<p>i.e.</p>\n\n<pre><code>List<MyObject> objectList = new List<MyObject>();\nobjectList.Add(new MyObject( \"property\" , 1);\n</code></pre>\n\n<p>instead of</p>\n\n<pre><code>List<MyObject> objectList = new List<MyObject>();\nMyObject object = new MyObject();\nobject.Name = \"property1\";\nobject.ID = 1;\nobjectList.Add(object);\n</code></pre>\n", "Lable": "No"} | |
| {"QuestionId": 11913501, "AnswerCount": 3, "Tags": "<c++><string><cin>", "CreationDate": "2012-08-11T09:29:19.913", "AcceptedAnswerId": "11913546", "Title": "Using while(cin>>x)", "Body": "<blockquote>\n <p><strong>Possible Duplicate:</strong><br>\n <a href=\"https://stackoverflow.com/questions/2735315/c-cin-whitespace-question\">C++ cin whitespace question</a> </p>\n</blockquote>\n\n\n\n<p>I'm having problem trying to understand this piece of code. I'd like to apologize if this question has already been answered but I didn't find it anywhere. I'm a beginner and its a very basic code. The problem is <strong>>></strong> operator stops reading when the first white space \ncharacter is encountered but why is it in this case it outputs the complete input string even if we have white spaces in our string. It outputs every word of the string in separate lines. How is it that <em>cin>>x</em> can take input even after the white space? Plz help me out with the functioning of this code. Thanks in advance.</p>\n\n<pre><code>#include<iostream>\n#include<string>\nusing std::cout;\nusing std::cin;\nusing std::string;\nusing std::endl;\nint main()\n{\nstring s;\nwhile (cin >> s)\ncout << s << endl;\nreturn 0;\n}\n</code></pre>\n", "Lable": "No"} | |
| {"QuestionId": 11934744, "AnswerCount": 2, "Tags": "<php><regex>", "CreationDate": "2012-08-13T12:59:15.440", "AcceptedAnswerId": null, "Title": "Regex : negative assertion", "Body": "<p>I'm stuck with an easy regex to match URLs in a content. The goal is to remove the folder from the links like \"/folder/id/123\" and to replace them with \"id/123\" so it's a short relative one in the same folder.</p>\n\n<p>Actually I did</p>\n\n<pre><code>$pattern = \"/\\/?(\\w+)\\/id\\/(\\d)/i\"\n$replacement = \"id/$2\";\nreturn preg_replace($pattern, $replacement, $text);\n</code></pre>\n\n<p>and it seems to work fine.</p>\n\n<p>However, the last test that I'd like to to is to test that each url matched does NOT containt http://, if it's an external site which also use the same pattern /folder/id/123.</p>\n\n<p>I tried /[^http://] or (?<!html)... and different things without success. Any help would be verys nice :-)</p>\n\n<pre><code> $pattern = \"/(?<!http)\\b\\/?(\\w+)\\/id\\/(\\d)/i\"; ???????\n</code></pre>\n\n<p>Thanks !</p>\n\n<p>Here is some examples : Thanks you VERY MUCH for your help :-)</p>\n\n<pre><code>(these should be replaced, \"same folder\" => short relative path only)\n<a href=\"/mysite_admin/id/414\">label</a> ==> <a href=\"id/414\">label</a>\n<a href=\"/mYsITe_ADMIN/iD/29\">label with UPPERCASE</a> ==> <a href=\"id/414\">label with UPPERCASE</a>\n\n(these should not be replaced, when there is http:// => external site, nothing to to)\n<a href=\"http://mysite_admin/id/414\">label</a> ==> <a href=\"http://mysite_admin/id/414\">label</a>\n<a href=\"http://www.google_admin.com\">label</a> ==> <a href=\"http://www.google_admin.com\">label</a>\n<a href=\"http://anotherwebsite.com/id/32131\">label</a> ==> <a href=\"http://anotherwebsite.com/id/32131\">labelid/32131</a>\n<a href=\"http://anotherwebsite_admin.com/id/32131\">label</a> ==> <a href=\"http://anotherwebsite_admin.com/id/32131\">label</a>\n</code></pre>\n", "Lable": "No"} | |
| {"QuestionId": 11949255, "AnswerCount": 3, "Tags": "<mysql><sql><algorithm><sql-server-2008>", "CreationDate": "2012-08-14T09:16:06.037", "AcceptedAnswerId": "11949727", "Title": "Get Index of each letter series from dictionary database", "Body": "<p>I have dictionary database and i have created one UI interface ,to place buttons alphabetically , on click of each Letter , i want to fetch first word in the Letter series </p>\n\n<p>Is there any trick or sql query by which i can list out, first word of each series against it's index</p>\n\n<p>Note : i also have , Index column for each word in the database.</p>\n", "Lable": "No"} | |
| {"QuestionId": 12179979, "AnswerCount": 4, "Tags": "<c#><reporting>", "CreationDate": "2012-08-29T14:14:03.563", "AcceptedAnswerId": "12180009", "Title": "How do I get the current Date in C#", "Body": "<p>I am using the Reporting feature in Visual Studio and I need to create a prop/variable to store the current date so I can display it on my form. I cannot seem to find the proper way to do this in the report view.</p>\n\n<p>I originally tried a property of : </p>\n\n<pre><code>public DateTime CurrentDate {get;}\n</code></pre>\n\n<p>This did not work because there is no setter for it. To fix the problem I :</p>\n\n<pre><code>public DateTime CurrentDate{get{return DateTime.Now;}}\n</code></pre>\n\n<p>Thanks for the suggestions. They lead me in the right direction.</p>\n", "Lable": "No"} | |
| {"QuestionId": 12271173, "AnswerCount": 1, "Tags": "<r><linear-regression><least-squares><lm>", "CreationDate": "2012-09-04T20:51:03.067", "AcceptedAnswerId": "12271589", "Title": "Linear least squares fitting", "Body": "<p>DF</p>\n\n<pre><code> times a b s ex \n1 0 59 140 1e-4 1\n2 20 59 140 1e-4 0 \n3 40 59 140 1e-4 0\n4 60 59 140 1e-4 2\n5 120 59 140 1e-4 20\n6 180 59 140 1e-4 30\n7 240 59 140 1e-4 31\n8 360 59 140 1e-4 37\n9 0 60 140 1e-4 0\n10 20 60 140 1e-4 0\n11 40 60 140 1e-4 0\n12 60 60 140 1e-4 0\n13 120 60 140 1e-4 3300\n14 180 60 140 1e-4 6600\n15 240 60 140 1e-4 7700\n16 360 60 140 1e-4 7700\n# dput(DF) \nstructure(list(times = c(0, 20, 40, 60, 120, 180, 240, 360, 0, \n20, 40, 60, 120, 180, 240, 360), a = c(59, 59, 59, 59, 59, 59, \n59, 59, 60, 60, 60, 60, 60, 60, 60, 60), b = c(140, 140, 140, \n140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140\n), s = c(1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04, \n1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04, 1e-04), ex = c(1, \n0, 0, 2, 20, 30, 31, 37, 0, 0, 0, 0, 3300, 6600, 7700, 7700)), .Names = c(\"times\", \n\"a\", \"b\", \"s\", \"ex\"), row.names = c(NA, 16L), class = \"data.frame\")\n</code></pre>\n\n<p>DF2 </p>\n\n<pre><code>prime times mean \n g1 0 1.0000000 \n g1 20 0.7202642 \n g1 40 0.8000305 \n g1 60 1.7430986 \n g1 120 16.5172242 \n g1 180 25.6521268 \n g1 240 33.9140056 \n g1 360 34.5735984 \n #dput(DF2)\n structure(list(times = c(0, 20, 40, 60, 120, 180, 240, 360), \nmean = c(1, 0.7202642, 0.8000305, 1.7430986, 16.5172242, \n25.6521268, 33.9140056, 34.5735984)), .Names = c(\"times\", \n\"mean\"), row.names = c(NA, -8L), class = \"data.frame\")\n</code></pre>\n\n<p>DF is an example of a larger data frame which actually has hundreds of combinations of the 'a','b', and 's' values which result in different 'ex' values. What I want to do is find the combination of 'a','b', and 's' whose 'ex' values (DF) best fit the 'mean' values (DF2) at equivalent 'times'. \nThis fitting will be a comparison of 8 values at a time (ie, times == c(0,20,40,60,120,180,240,360).</p>\n\n<p>In this example, I would want 59, 140, and 1e-4 for the 'a', 'b', and 's' values, because those 'ex' values (DF) best fit the 'mean' values (DF2). </p>\n\n<p>I would like 'a','b', and 's' values for those values which 'ex' (DF) best fits 'mean' (DF2) </p>\n\n<p>Since I want one possible combination of the 'a','b', and 's' values a linear least squares fit model would be best. I would be comparing 8 values at a time -- where 'times' == 0 - 360. \nI don't want 'a', 'b', and 's' values which work best for each individual time point. I want 'a', 'b', and 's' values where all 8 'ex' (DF) best fit all 8 'mean' values (DF2)\nThis is where I need help.</p>\n\n<p>I have never used linear least squares fitting, but I assume what I'm trying to do is possible. </p>\n\n<pre><code> lm(DF2$mean ~ DF$ex,....) # i'm not sure if I should combine the two \n # data frames first then use that as my data argument, then \n # where I would include 'times' as the point of comparison, \n # if that would be used in subset? \n</code></pre>\n", "Lable": "No"} | |
| {"QuestionId": 12283113, "AnswerCount": 6, "Tags": "<python><list><sublist>", "CreationDate": "2012-09-05T13:55:57.937", "AcceptedAnswerId": null, "Title": "Printing item from a sublist", "Body": "<pre><code>data = [['a','b'], ['a','c']]\nprint data[0[0]]\n>>> 0\n</code></pre>\n\n<p>When I try this, I get an error. How could I print the 1st item from 1st list?</p>\n", "Lable": "No"} | |