pid
int64
2.28k
41.1M
label
int64
0
1
text
stringlengths
1
28.3k
32,963,059
0
<p>[EDIT from generator to function]</p> <p>You can try a function:</p> <pre><code>def check_answer(question, answer): while True: current_answer = input(question) if current_answer == answer: break print "Something wrong with question {}".format(question) return current_answer answerX = check_answer("Question about X?\n", "TrueX") answerY = check_answer("Question about Y?\n", "TrueY") answerZ = check_answer("Question about Z?\n", "TrueZ") </code></pre> <p>Not sure if you want to keep the values, but if you need to tweak it, this should give you hints. </p> <p>Results:</p> <pre><code>Question about X? "blah" Something wrong with question Question about X? Question about X? "blah" Something wrong with question Question about X? Question about X? "TrueX" Question about Y? "TrueY" Question about Z? "blah" Something wrong with question Question about Z? Question about Z? "blah" Something wrong with question Question about Z? Question about Z? "TrueZ" </code></pre> <p>Edit per comment:</p> <pre><code>def check_answer(question, answers): while True: current_answer = input(question) if current_answer in answers: break print "Something wrong with question {}".format(question) return current_answer answerX = check_answer("Question about X?\n", ("TrueX", "TrueY") </code></pre>
40,945,088
1
What does numpy.cov actually do <p>I am new to python and to linear algebra and I have a question about covariance of a matrix.</p> <p>I have a 21 by 2 matrix, where the first column represents the average score(from 0 to 10) of the video games released that year and second columns are years ranging from 1996 to 2016.</p> <p>I was playing around with the data and I noticed that by doing np.cov(X) I got a very interesting graph. I will list the graph below. It is my understanding that covariance shows the dependence among the variables in a dataset, but will it be correct to state that based on this covariance graph we can say that the average score of the games rises as the years rise ?</p> <p><a href="https://i.stack.imgur.com/llLT9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/llLT9.jpg" alt="enter image description here"></a></p> <p>Thanks.</p>
5,532,477
0
C# Datagridview Edit Cell <p>I'm trying to put the cursor and focus in the last row and a specific cell with the column named 'CheckNumber'. I thought I had it with this:</p> <pre><code> var c = dataGridView1.RowCount; DataGridViewCell cell = dataGridView1.Rows[c-1].Cells[0]; dataGridView1.CurrentCell = cell; dataGridView1.BeginEdit(true); </code></pre> <p>but it keeps coming up with this error:</p> <p>Index -1 does not have a value.</p> <p>Can someone please point me in the right direction!? This is driving me nuts.</p> <p>Thank you!</p>
39,932,204
0
ASP.NET Identity Fluent NHibernate bind the mappings: <p><a href="https://nhibernateidentity.codeplex.com/documentation" rel="nofollow">https://nhibernateidentity.codeplex.com/documentation</a> In this docs is written:</p> <p>First you need install the package:</p> <pre><code> PM&gt; Install-Package NHibernate.Identity </code></pre> <p>After you installed you need to bind the mappings:</p> <pre><code>.Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;IdentityUser&gt;()) </code></pre> <p>How and where? Can someone try to explain. I want to use Nhiberant with Identity</p>
24,148,675
0
<p>What you have here is an example of infinite recursion, as there is nothing there to allow us to exit the recursive loop. As others have previously said, this will cause a stack overflow error, as the JVM will continually create and assign a memory allocation to the Test object until it runs out of space in memory.</p>
28,359,052
0
<p>callback for each row created while drawing the table:</p> <pre><code>"fnCreatedRow" : function(nRow, aData, iDataIndex) { $('td:last-child', nRow).text(100); } </code></pre> <p>check out the fiddle i just created : <a href="http://jsfiddle.net/yrn2nfj3/" rel="nofollow">http://jsfiddle.net/yrn2nfj3/</a></p>
21,056,491
0
Maple converting vectors to data to plot <p>I have a list of vectors, like this:</p> <pre><code>{x = 7, y = 0.}, {x = 2.5, y = 0.}, {x = -2.3, y = 0.}, {x = 2.5, y = 2.7}, {x = 2.5, y = -2.7} </code></pre> <p>How do I convert these to data I can plot? I've been trying with the "convert" function, but can't get it to work.</p> <p>When I manually convert it to something like <code>[[7, 0], [2.5, 0], [-2.3, 0], [2.5, 2.7], [2.5, -2.7]]</code> it works, though there has to be an automatic way, right?</p> <p>A little more info about what I'm doing if you're interested:</p> <p>I have a function U(x,y), of which I calculate the gradient and then check where it becomes 0, like this:</p> <pre><code>solve(convert(Gradient(U(x, y), [x, y]), set), {x, y}); </code></pre> <p>that gives me my list of points. Now I would like to plot these points on a graph.</p> <p>Thanks!</p>
36,555,353
0
<p>If you re-used the application name (deleted the old application and created a new one with the same name) it could take up to 24 hours for the dns to be routed to the correct server. if you are going to do rapid create/delete/create cycles, you should use different application names so that you don't have to wait on DNS updates.</p>
19,458,114
0
Adjust color to powertools extension for visual studio <p>I use Visual Studio 2012, and the productivity powertools extension. I often use the "quick find" function that comes with this extension - the little blue 'dot' that shows in the scrollbar, when you highlight a word, or part of it, showing all the usages for the selection in that page. </p> <p>How can I change the color of this dot? It is only nearly visible with the dark-theme. </p>
19,641,005
0
<p>Don't do <code>right : 0</code> in your <code>stick</code> class. In fixed elements, the position attributes are relative to the viewport. </p> <p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/position#Fixed_positioning" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/CSS/position#Fixed_positioning</a></p>
40,858,857
0
<p>Expanding on @Brendan's answer.</p> <p>Your logger currently outputs to the console using a <a href="https://docs.python.org/2/library/logging.handlers.html#streamhandler" rel="nofollow noreferrer"><code>StreamHandler</code></a>.</p> <p>By adding a <a href="https://docs.python.org/2/library/logging.handlers.html#filehandler" rel="nofollow noreferrer"><code>FileHandler</code></a>, you can log to a file.</p> <p>Each handler instance can be customized to have its own format and logging level.</p> <p>If you want to log using the same format, you will have to set the format on the new FileHandler as well.</p> <pre><code>fh = logging.FileHandler(r'/path/to/log.txt') fh.setFormatter(formatter) logger.addHandler(fh) </code></pre> <p>Read more: <a href="https://docs.python.org/2/howto/logging-cookbook.html" rel="nofollow noreferrer">Python logging cookbook</a></p>
35,848,093
0
<p>As others have mentioned, you cannot do this. But instead you can use ArrayList (or any other List) and where needed, convert it to simple array, like this:</p> <pre><code>ArrayList&lt;String&gt; arrayList = new ArrayList&lt;&gt;(); String strings[] = (String[])arrayList.toArray(); </code></pre>
33,334,886
0
<p>Once you have the access token ("<code>token</code>" in your code above), you just need to save it. It sounds like you're building a web app, so yes, you would typically store this in the user's session or perhaps associated with the user in a database, if you have such a thing.</p>
11,305,473
0
<p>When the View is bound to the Model:</p> <ul> <li><p>If the View needs to change or you have multiple views a change to the Model will cause changes to all the Views bound to that Model. </p></li> <li><p>From the View's perspective, the object it is bound to might not be that intuitive; when you need to add a properties and/or commands to the the object do you add those to the ViewModel and keep the 'original' properties in the Model or do you modify the Model?</p></li> </ul> <p>Having a ViewModel gives you an extra abstraction between a single Model and multiple (versions of) Views</p> <p>All in all it is just a guideline but be aware that what seems OK today might be not so great when you need to modify/update the application.</p>
23,223,144
0
<p>You can use this rule in your root .htaccess:</p> <pre><code>RewriteEngine On RewriteCond %{THE_REQUEST} \s/([^~]+?)/([^/~\s]+)/? [NC] RewriteRule ^(.+?)/([^/~]+)/?$ /$1~$2 [R=301,L,NE] RewriteRule ^([^~]+)(.+)$ /$1/$2 [R=301,L,NE] </code></pre>
3,065,222
0
How can I execute a SQL query in emacs lisp? <p>I want to execute an SQL query and get its result in elisp:</p> <pre><code>(let ((results (do-sql-query "SELECT * FROM a_table"))) (do-something-with results)) </code></pre> <p>I'm using Postgres, and I already know all of my connection information (host, username, password, db et al) I just want to execute the query and get the result back, synchronously.</p>
34,686,217
0
How can I add a line to one of the facets? <pre><code>ggplot(all, aes(x=area, y=nq)) + geom_point(size=0.5) + geom_abline(data = levelnew, aes(intercept=log10(exp(interceptmax)), slope=fslope)) + #shifted regression line scale_y_log10(labels = function(y) format(y, scientific = FALSE)) + scale_x_log10(labels = function(x) format(x, scientific = FALSE)) + facet_wrap(~levels) + theme_bw() + theme(panel.grid.major = element_line(colour = "#808080")) </code></pre> <p>And I get this figure</p> <p><a href="https://i.stack.imgur.com/VIMue.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VIMue.png" alt="enter image description here"></a></p> <p>Now I want to add <strong>one geom_line</strong> to one of the facets. Basically, I wanted to have a dotted line (Say x=10,000) in only the <strong>major</strong> panel. How can I do this?</p>
23,180,238
0
<p>Have you tried</p> <pre><code>Class.forName("com.foo.Foo"); </code></pre> <p>Edit: To invoke the static method, you will need to do something like:</p> <pre><code>Class clazz = Class.forName("com.foo.Foo"); Method method = clazz.getMethod("methodName", String.class); Object o = method.invoke(null, "whatever"); </code></pre> <p>This will depend on your method and its parameters. See the reflection tutorial for more on this: <a href="http://docs.oracle.com/javase/tutorial/reflect/" rel="nofollow">http://docs.oracle.com/javase/tutorial/reflect/</a> </p>
14,528,016
0
<p>As stated in <a href="https://github.com/lecar-red/bootstrapx-clickover/issues/25" rel="nofollow">this issue</a>, you need to add <code>html: true</code> to your clickover options.</p> <pre><code>$("#spec").clickover({placement:'top', title: "Sensitive information", content: message, width: 170, height: 110, html: true}); </code></pre>
30,933,595
0
<pre><code>$result[0] </code></pre> <p>is probably not an object.</p> <p>try using print_r to print the contents of that variable after json_decode.</p>
37,683,503
0
Turning JSON into date object <p>I have get request here </p> <pre><code>$http.get('php/getactivity.php') .then( function (response) { $scope.data.activities = response.data; }, function (response) { // error handling } ); </code></pre> <p>which gets data from database . in my php</p> <pre><code>&lt;?php include('dbconnect.php'); $result = $conn-&gt;query("SELECT * FROM Activities WHERE EventID =1;"); $outp = ""; while($rs = $result-&gt;fetch_array(MYSQLI_ASSOC)) { if ($outp != "") { $outp .= ","; } $outp .= '{"ActivityDate":"' . $rs["ActivityDate"] . '",'; $outp .= '"StartTime":"' . $rs["StartTime"] . '",'; $outp .= '"EndTime":"' . $rs["EndTime"] . '"}'; } $outp ='['.$outp.']'; $conn-&gt;close(); echo($outp); ?&gt; </code></pre> <p>which gets the date string from the database. An example of the data is as such : </p> <p>Thu Jan 01 1970 11:11:00 GMT+0800 (Malay Peninsula Standard Time)</p> <p>Because I'm accessing the data using <code>ng-repeat</code> and <code>{{ActivityDate||date:"dd/MM/yyyy"}}</code> to make it show on the view, I cannot convert it do a date object manually using <code>new Date()</code>.</p> <p>I have tried adding new date to the json produced as such but it does not work:</p> <p><code>$outp .= '"ActivityDate": new Date("'. $rs["ActivityDate"] . '"),';</code></p> <p>What is the right way to do it?</p>
245,815
0
<p>What you want to do (at least from what I read here and on the Django documentation site) is create a <a href="http://docs.djangoproject.com/en/dev/howto/custom-file-storage/#howto-custom-file-storage" rel="nofollow noreferrer">custom storage system.</a></p> <p>This should give you exactly what you need - it's the motivation they use to start the example, after all!</p>
35,438,156
0
logstash add_field and remove_field <p>I'm attempting to simplify my logstash config. I want to split the program field into separate fields (as show below) however I would prefer to use just one grok statement (if it's at all possible!)</p> <p>Of the two examples below I get an _grokparsefailure on the second example, but not the first. Since grok has the add_field and remove_field options I would assume that I could combine it all into one grok statement. Why is this not the case? Have I missed some ordering/syntax somewhere?</p> <p>Sample log:</p> <pre><code>2016-02-16T16:42:06Z ubuntu docker/THISTESTNAME[892]: 172.16.229.1 - - [16/Feb/2016:16:42:06 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36" "-" </code></pre> <p>Why does this work:</p> <pre><code>filter { # Extracts the docker name, ID, image etc elements mutate { add_field =&gt; { "[@metadata][program]" =&gt; "%{program}" } remove_field =&gt; "[program]" } grok { patterns_dir =&gt; "/logstash/patterns_dir/docker" match =&gt; { "[@metadata][program]" =&gt; "%{D_ID}" } } } </code></pre> <p>But this does not:</p> <pre><code>filter { grok { add_field =&gt; { "[@metadata][program]" =&gt; "%{program}" } remove_field =&gt; "[program]" patterns_dir =&gt; "/logstash/patterns_dir/docker" match =&gt; { "[@metadata][program]" =&gt; "%{D_ID}" } } } </code></pre>
9,016,152
0
<p>Nowadays there are excellent Python libs that do this for you - <a href="http://urllib3.readthedocs.org/" rel="nofollow">urllib3</a> and <a href="http://docs.python-requests.org/" rel="nofollow">requests</a></p>
32,144,964
0
<p>The thing that you are trying to do is to access the <code>/storage</code> folder just without read write permissions which is required by laravel.</p> <blockquote> <h3>Using File Manager</h3> <p>One of the easy and basic ways to change the permissions is through File manager in cPanel. To change the permissions for a file or folder in cpanel, please do the following:</p> <ol> <li>Click File Manager</li> <li>Click the name of the file for which you would like to change the permissions.</li> <li>Select the Change Permissions link at the top right of the page.</li> <li>Select the permissions you would like to set for the file.</li> <li>Click Change Permissions</li> </ol> <h3>Using FTP</h3> <p>Connect to FTP. Go to the file and right click. Choose Permissions or Attributes or Properties (depends on your program).</p> <h3>Using SSH or a script</h3> <p>This can be done with chmod command.</p> </blockquote> <p>From <a href="http://support.hostgator.in/articles/cpanel/how-to-change-permissions-chmod-of-a-file" rel="nofollow">HostGator</a> website which is most probably your hosting provider.</p> <p><strong>EDIT</strong>: The directory should have the recursive mode enabled. You are not just giving permissions to one directory, but you are giving it to each and every subdirectory that you find inside that folder. If you still see an error, please post last few errors from your logs.(If it's stored which might not be there).</p>
26,849,108
0
<p>There are multiple things:</p> <ol> <li>The crash is caused by an exception and the crash report does not show the required <code>Last Exception Backtrace</code>.</li> <li>Symbolicating the main thread will only show you the <code>main.m</code> call in frame 12 and the uncaught exception handler in frame 2 of thread 0</li> <li>The crash report is written by an old version of <a href="http://plcrashreporter.org/" rel="nofollow">PLCrashReporter</a> (identified by the two <code>[TODO]</code> texts on top) or you are using another server for uncaught exceptions. As is, the crash report will not help you.</li> <li>You should use <code>atos</code> with the apps dSYM instead of the app binary. Using the app binary will never show you filenames or line numbers and will only show you class name and methods if you don't strip symbols from the executable. But you should strip them from the executable to keep the binary size as low as possible (saves 30-50%).</li> <li><p>The way you are calling <code>atos</code> is wrong. <code>0x7f68bb0 0x3017d000 + 84904</code> is not a valid option, and in fact your crash report doesn't even contain that. Instead you need to use only the first address after the binary name per frame. So for the following line:</p> <pre><code>2 Example 0x001ffe3b 0x4000 + 2080315 </code></pre> <p>You would use atos as follows:</p> <pre><code>`atos -arch -armv7 -l 0x4000 -o Example.app.dSYM 0x001ffe3b` </code></pre></li> </ol> <p>You should update your crash reporting SDK to use the latest PLCrashReporter version and make sure exceptions are shown properly in the report.</p>
35,488,437
0
<p>Unfortunately not all of the various components' command line flags are modifiable when starting a GKE cluster. If you're just trying to run a one-off load test, you could manually modify the flags passed to the Kubelet on each node, but since that flag isn't even controllable by Kubernetes's Salt templates, there isn't even an option to control it with an environment variable.</p> <p>The value was chosen due to performance limitations and will be drastically bumped up (to 100) in version 1.2 of Kubernetes, which is scheduled for release in March.</p>
13,380,023
0
Global variable is not showing result inside a ajax call <p>Here index is a global variable. I am manipulating the index in another function.</p> <p>after that I call this function. its showing the actual result outside and after the ajax call but not showing inside the ajax call. </p> <pre><code>var urlSearch = "http://192.168.10.113/collective-intellegence/UserClickPersonClassifier?userid=1&amp;query=asp.net"; alert(index); $.ajax({ url: urlSearch, type: 'POST', dataType: 'json', success: function (data) { alert(index); } }); </code></pre> <p>Is there any mistake done by me.</p> <p>Please help to solve this problem.</p> <p>Thanks in advance.</p>
632,963
0
<p>There is no alternate for the direct child selector in IE6 (it should work in IE7 though).</p> <p>Instead you need to use the descendant selector (a space) and design your classes to compensate.</p>
26,628,825
0
<p>Your code is leaving uninitialized memory and that might cause <a href="http://en.wikipedia.org/wiki/Undefined_behavior" rel="nofollow">undefined behavior</a>, make sure that every pointer/data is zero'ed out before proceeding setting your flags/pointers:</p> <pre><code>WNDCLASSEX wndClass; memset(&amp;wndClass, 0, sizeof(WNDCLASSEX)); </code></pre> <p>or even better:</p> <pre><code>WNDCLASSEX wndClass = { 0 }; </code></pre>
20,090,735
0
Background color of tr is not changing using jquery <p>I would like to change the background olor of a tr while clicking on its child td.I cant add <code>onclick</code> to tr since it is dynamically generating from a gridview control of asp.net after rendering.</p> <p>my mark up is</p> <pre><code>&lt;tbody&gt; &lt;tr&gt; &lt;td style="width:27%;"&gt;&lt;span onclick="SelectAddressRow(this)"&gt;Ajish&lt;/span&gt;&lt;/td&gt; &lt;td style="width:40%;"&gt;&lt;span onclick="SelectAddressRow(this)"&gt;22&lt;/span&gt;&lt;/td&gt; &lt;td style="width:33%;"&gt;&lt;span onclick="SelectAddressRow(this)"&gt;Male&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; </code></pre> <p>my code is </p> <pre><code>function SelectAddressRow(column) { var tableRow=$(column).parent(); $(tableRow).parent().css({ "background-color": "#B3B3B3" }); } </code></pre> <p>but it is not working,But it affects for a td if the statement is replaced by</p> <pre><code>$(tableRow).css({ "background-color": "#B3B3B3" }); </code></pre>
8,216,644
0
<p>So that I understand, you have not yet built any ORM Entities? (CFC for each table)</p> <p>If you have not, all you have to do is setup all your tables (use cfbuilder with a RDS connection to build your ORM CFC files)</p> <p>Once you have all your tables referenced in ORM Persisted CFC files, you can do this with a cfquery tag and dbtype = "HQL" and return the data with QueryConvertForGrid()</p> <p>Then just return the data you want to your cfgrid via json or directly on the page into the cfgrid tag.</p>
27,553,917
0
<p>This code base has a deep level of dependency. This causes a stack overflow in <code>javadoc</code> because the default stack size is too small to support this level of dependencies.</p> <p>To work around this a the following flag can be added to the 'javadoc' command:</p> <pre><code>javadoc -J-Xss1m ... </code></pre> <p>This passes the flag <code>-Xss1m</code> to the java VM that is running javadoc which increases the stack size to 1 megabyte. See <a href="http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html" rel="nofollow">JavaDoc</a> documentation for more information. After running the command with this option javadoc was able to successfully generate documentation for the <a href="https://sourceforge.net/projects/byuediftools/" rel="nofollow">BYUEDIFTools</a></p>
36,177,636
0
<p>Your IAM role only gives access to GetObject and ListObject. Copying also requires PutObject as you write to S3. I think this should work:</p> <pre><code>{ "Version": "2008-10-17", "Id": "Policy1458587151478", "Statement": [ { "Sid": "AllowPublicRead", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": ["s3:GetObject","s3:PutObject"], "Resource": "arn:aws:s3:::bucketname/*" }, { "Sid": "AllowPublicList", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::bucketname" } ] } </code></pre>
11,188,424
0
<p>Why didn't you try it yourself?</p> <pre><code>List&lt;String&gt; list = new ArrayList&lt;String&gt;(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); list.add("F"); list.add("G"); for(int i = 0; i &lt; list.size(); i++) System.out.println("index " + i + ": " + list.get(i)); System.out.println(); list.remove(0); // remove "A" for(int i = 0; i &lt; list.size(); i++) System.out.println("index " + i + ": " + list.get(i)); </code></pre> <p><strong>OUTPUT:</strong></p> <pre><code>index 0: A index 1: B index 2: C index 3: D index 4: E index 5: F index 6: G index 0: B index 1: C index 2: D index 3: E index 4: F index 5: G </code></pre>
40,267,851
0
<p>I am no expert in Cross Platform Mobile Development (in fact, I was just searching for a cross platform mobile development languages/frameworks), but you could take a look at <a href="https://www.xamarin.com/" rel="nofollow">Xamarin</a>, especially as you have a C# Background.</p> <p>You may also want to take a look at <a href="https://cordova.apache.org/" rel="nofollow">Apache Cordova</a> (and <a href="http://phonegap.com/" rel="nofollow">Adobe Phonegap</a>), they use HTML+CSS+JavaScript.</p> <p>I recently found <a href="https://flutter.io/" rel="nofollow">Flutter</a>, the development language is <a href="https://www.dartlang.org/" rel="nofollow">Dart</a> and it's an early stage OSS project (as of 2016 october) and <a href="https://haxe.org" rel="nofollow">Haxe</a>. They both seem like an active projects, so worth following the progress on GitHub.</p> <p>If I had to choose and I already had skills in C#, I'd go with Xamarin.</p>
20,876,153
0
Please user insertBefore() JS HTML DOM METHOD for add string before your element content <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Node.insertBefore" rel="nofollow">Check MDN</a></p> OR user appendChild() JS HTML DOM METHOD for add string after your element content <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Node.appendChild" rel="nofollow">Check MDN</a></p>
33,995,027
0
<p>There are no such settings in Email Alert.</p> <p>However , both of the event in email alert and in Team Room are listening to the same server side event. Simply returns in different ways. Moreover, most of the events which they listen to are the same. Such as Build, Code, WorkItem, Checkin(pull). </p> <p><a href="https://i.stack.imgur.com/pMzL2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pMzL2.png" alt="enter image description here"></a> <a href="https://i.stack.imgur.com/eI0Bs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eI0Bs.png" alt="enter image description here"></a></p> <p>In other words, you can get the same result of your email when an event has been added to a project's team room by setting the same conditions in your email alter.</p>
37,001,712
0
<p>This worked for me,(Using ShareIntent) </p> <pre><code>private void shareOnTwitter(){ Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("text/plain"); // shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Extra Subject"); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "check this application"); // shareIntent.putExtra(Intent.EXTRA_STREAM, "Extra Stream"); PackageManager pm = context.getPackageManager(); List&lt;ResolveInfo&gt; activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { //"com.twitter.android.PostActivity".equals(app.activityInfo.name) if ((app.activityInfo.name).contains("twitter")) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shareIntent.setComponent(name); context.startActivity(shareIntent); break; } } } </code></pre> <p>Just call <code>shareOnTwitter()</code> in you btn <code>OnClickListener()</code></p>
20,121,816
0
<p>I encountered this error when trying to debug to run a web application after publishing from VS 2012 to IIS 7.5. After some hair pulling, I realised that the problem was the fact that I did not change the jquery script and signalr paths when deploying.</p> <p>To solve the issue I had to add the virtual directory name ("TestingChat") to the path of the script tags for jquery and signalr.</p> <p>E.g. From this: </p> <pre><code>&lt;script src="Scripts/jquery-1.8.2.min.js" &gt;&lt;/script&gt; &lt;script src="/signalr/hubs"&gt;&lt;/script&gt; </code></pre> <p>To </p> <pre><code>&lt;script src="/TestingChat/Scripts/jquery-1.8.2.min.js" &gt;&lt;/script&gt; &lt;script src="TestingChat/signalr/hubs"&gt;&lt;/script&gt; </code></pre>
6,731,072
0
SHAREPOINT 2007 LLISTS created by helpdesk.wsp <p>I am given a task to make a feature that autogenerates a ticket ID for a list. However, I found out that the template used for the site is a helpdesk.wsp template. Now, I am having problems stapling the said feature to Service Requests because it is currently under LLISTS and not LISTS.</p> <p>See attached image.<img src="https://i.stack.imgur.com/s8m7L.jpg" alt="enter image description here"></p> <p>Can someone help me on this?</p> <p>Thanks. janejanejane</p>
5,470,117
0
UPDATE MySQL using VB.NET <p>I am using VB.NET with a MySQL database. I want to update this code to do it all in ONE SQL instead of THREE. Anyone know how?</p> <p>Here's the code I'm using, works fine but too slow with multiple lines...</p> <pre><code>If count3 = "1" Then Dim myCommand As New MySqlCommand Dim myAdapter As New MySqlDataAdapter Dim SQL As String myCommand.Connection = conn myAdapter.SelectCommand = myCommand SQL = "UPDATE employees SET emprole1 = '" &amp; val2 &amp; "' WHERE emprole1 = '" &amp; val1 &amp; "'" myCommand.CommandText = SQL myCommand.ExecuteNonQuery() SQL = "UPDATE employees SET emprole2 = '" &amp; val3 &amp; "' WHERE emprole2 = '" &amp; val2 &amp; "'" myCommand.CommandText = SQL myCommand.ExecuteNonQuery() SQL = "UPDATE employees SET emprole3 = '" &amp; val4 &amp; "' WHERE emprole3 = '" &amp; val3 &amp; "'" myCommand.CommandText = SQL myCommand.ExecuteNonQuery() End If </code></pre>
24,954,918
0
<p>I found a solution here: <a href="https://productforums.google.com/forum/#!searchin/tag-manager/gtm.load/tag-manager/0Lpevpf2Fss/OMJFuaM04BsJ" rel="nofollow">https://productforums.google.com/forum/#!searchin/tag-manager/gtm.load/tag-manager/0Lpevpf2Fss/OMJFuaM04BsJ</a></p> <p>I didnt push my variables but assigned them to dataLayer. Its overwritten, so the gtm objects are missing.</p>
21,514,842
0
<p><strong>INPUT:</strong></p> <pre><code>1. walking down the street 2. to go to the store 3. to buy some groceries </code></pre> <p><strong>Use this:</strong></p> <pre><code>.sub(/[a-zA-Z]/){|c| c.upcase} </code></pre> <p><strong>OUTPUT:</strong></p> <pre><code>1. Walking down the street 2. to go to the store 3. to buy some groceries </code></pre>
7,692,638
0
<p>Can you use the <code>Set&lt;T&gt;()</code> operation:</p> <pre><code>try { db.SaveChanges(); } catch { db.Set&lt;T&gt;().Remove(obj); } </code></pre> <p>?</p>
34,635,577
0
Batch scripting: read lines and execute a command after every other line read <p>Suppose I have a text file like this</p> <pre><code>node1.log node2.log node3.log node4.log etc... </code></pre> <p>I want to read each line by line and execute</p> <pre><code>alan.exe node1.log node2.log alan.exe node3.log node4.log </code></pre> <p>etc..</p> <p>What is the best way to accomplish this?</p>
30,581,518
0
<p>Here's a simple project using sockets and files to read to and write from that I did a while ago. Hopefully viewing this code will clarify the questions you have with your own code. Due to the time constraints, I didn't convert it to include the code snippets you've provided, but if you're still stuck with your own code after taking a look at mine, I'll see what I can do. </p> <p>A few things to note if you run this code:</p> <ul> <li>This project uses server and client GUIs that are a little messy (I'm not very good at designing GUIs), but the functionality should still be useful. </li> <li>You need to provide the same port number as a command line argument for both the server and client. You can do this in Eclipse via Run button dropdown -> Run configurations... -> arguments tab ->typing a port number (I used 12345) -> click run). Do this for both the server and client.</li> <li>Make sure to run the server before you run the client</li> <li>This example only reads from files. There's no writing functionality.</li> <li>Once the client has successfully started, type the name of the file you want to read from (ie: readfile1.txt) including the file extension.</li> <li>This uses relative path names starting from the root project directory so if your Users.txt file is in your src folder, you'd type "src/Users.txt".</li> <li>Type the file name in the client's input field at the top of the client GUI to have the entire contents of that file printed below. You can type as many file names as you want one at a time.</li> </ul> <p><strong>Server code</strong></p> <pre><code>import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.EOFException; import java.io.File; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.ServerSocket; import java.net.Socket; import java.util.Scanner; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; public class FileServer extends JFrame { //main function public static void main(String[] args) { int port = Integer.parseInt(args[0]); //String file = args[1]; FileServer server = new FileServer(port); server.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); server.runServer(); } //FileServer class declarations private File file; //for this example, the file is stored in the root project directory and includes the file extension (ie: .txt, etc) private ServerSocket ss; private Socket connection; private JTextField field; private JTextArea displayArea; private int portNum; private ObjectOutputStream oos; private ObjectInputStream ois; public FileServer(int port) { super("Server"); //file = new File(f); //sent from client or done here? portNum = port; field = new JTextField(); field.setEditable(false); field.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { sendData(event.getActionCommand()); field.setText(""); } }); //ends addActionListener add(field, BorderLayout.NORTH); displayArea = new JTextArea(); add(new JScrollPane(displayArea)); setSize(500, 300);//size of JFrame setVisible(true); }//end constructor /** * code that executes the server obj. Think of it as FileServer's main(). This is called from main(). */ public void runServer() { try { ss = new ServerSocket(portNum, 100); //creates server socket with port # specified by user and a queue of 100 while (true) { //infinite loop to continually listen for client connections try { waitForConnection(); //wait for client connections getStreams(); //get I/O streams processConnection(); } catch (EOFException e) { e.printStackTrace(); } finally { closeConnection(); } } } catch (IOException e) { e.printStackTrace(); } }//end runServer /** * creates socket obj to interact with client. Socket created when connection with client made * @throws IOException */ public void waitForConnection() throws IOException { displayMessage("Waiting for connection\n"); connection = ss.accept(); //returns socket obj when connection made with client displayMessage("Connection made with " + connection.getInetAddress().getHostName()); }//end waitForConnection /** * gets IO stream objs for FileServer class */ public void getStreams() { try { oos = new ObjectOutputStream(connection.getOutputStream()); oos.flush(); ois = new ObjectInputStream(connection.getInputStream()); } catch (IOException e) { e.printStackTrace(); } displayMessage("\n Got both IO streams \n"); }//end getStreams /** * receives filename sent from client and creates file */ public void processConnection() throws IOException { sendData("Connection successful"); setTextFieldEditable(true); do { //added do while for testing try { String message = (String) ois.readObject(); //should read in filename then create file obj displayMessage("\n " + message + " received from client\n"); displayMessage("Type in absolute path of file in text field above"); file = new File(message); if(!file.exists()) { sendData("File not found"); } else { Scanner cin = new Scanner(file); while(cin.hasNextLine()) { message = cin.nextLine(); sendData(message); } cin.close(); } } catch (ClassNotFoundException e) { e.printStackTrace(); } } while(true); }//end processConnection /** * closes IO streams */ public void closeConnection() throws IOException { displayMessage("\nClosing connections\n"); setTextFieldEditable(false); oos.close(); ois.close(); connection.close(); }//end closeConnection /** * sends message to client * @param message */ public void sendData(String message) { try{ oos.writeObject(message);//this is what sends message oos.flush(); displayMessage("\n in sendData: " + message + "\n"); } catch(IOException e) { displayArea.append("\n Error writing object"); e.printStackTrace(); } }//end sendData public void displayMessage(final String message) { SwingUtilities.invokeLater( new Runnable() { public void run() { displayArea.append(message); } });//end SwingUtilties } private void setTextFieldEditable( final boolean editable ) { SwingUtilities.invokeLater( new Runnable() { public void run() // sets enterField's editability { field.setEditable( editable ); } // end method run } // end anonymous inner class ); // end call to SwingUtilities.invokeLater } // end method setTextFieldEditable } </code></pre> <p><strong>Client code</strong></p> <pre><code>import java.io.EOFException; import java.io.File; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.InetAddress; import java.net.Socket; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; public class FileClient extends JFrame { public static void main(String[] args) { int port = Integer.parseInt(args[0]); String fileName = args[1]; //must use absolute path for filename FileClient app = new FileClient("127.0.0.1", port, fileName); app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); app.runClient(); } private JTextField enterField; // enters information from user private JTextArea displayArea; // display information to user private ObjectOutputStream output; // output stream to server private ObjectInputStream input; // input stream from server private String message = ""; // message from server private String chatServer; // host server for this application private Socket client; // socket to communicate with server private int portNum; private String fileName; private File file; // initialize chatServer and set up GUI public FileClient( String host, int port, String fileName ) { super( "Client" ); portNum = port; this.fileName = fileName; //file = new File(fileName); chatServer = host; // set server to which this client connectsS enterField = new JTextField(); // create enterField enterField.setEditable( false ); enterField.addActionListener( //need to find a way to send fileName to server without having to type it in new ActionListener() { // send message to server public void actionPerformed( ActionEvent event ) { sendData( event.getActionCommand() ); enterField.setText( "Messages will be displayed in other text box" ); } // end method actionPerformed } // end anonymous inner class ); // end call to addActionListener add( enterField, BorderLayout.NORTH ); displayArea = new JTextArea(); // create displayArea add( new JScrollPane( displayArea ), BorderLayout.CENTER ); setSize( 500, 300 ); // set size of window setVisible( true ); // show window } // end Client constructor // connect to server and process messages from server public void runClient() { try // connect to server, get streams, process connection { connectToServer(); // create a Socket to make connection getStreams(); // get the input and output streams processConnection(); // process connection sendData(fileName); //sends name of file to server to retrieve displayMessage("Sent request for " + fileName + " to server."); } // end try catch ( EOFException eofException ) { displayMessage( "\nClient terminated connection" ); } // end catch catch ( IOException ioException ) { ioException.printStackTrace(); } // end catch finally { closeConnection(); // close connection } // end finally } // end method runClient // connect to server private void connectToServer() throws IOException { displayMessage( "Attempting connection\n" ); //not getting here // create Socket to make connection to server client = new Socket( InetAddress.getByName( chatServer ), portNum ); // display connection information displayMessage( "Connected to: " + client.getInetAddress().getHostName() ); } // end method connectToServer // get streams to send and receive data private void getStreams() throws IOException { // set up output stream for objects output = new ObjectOutputStream( client.getOutputStream() ); output.flush(); // flush output buffer to send header information // set up input stream for objects input = new ObjectInputStream( client.getInputStream() ); displayMessage( "\nGot I/O streams\n" ); } // end method getStreams // process connection with server private void processConnection() throws IOException //problem possibly due to processConnection being in infinite loop? { // enable enterField so client user can send messages setTextFieldEditable( true ); do // process messages sent from server { try // read message and display it { message = input.readObject().toString(); // read new message displayMessage( "\n" + message ); // display message } // end try catch ( ClassNotFoundException classNotFoundException ) { displayMessage( "\nUnknown object type received" ); classNotFoundException.printStackTrace(); } // end catch } while ( !message.equals( "SERVER&gt;&gt;&gt; TERMINATE" ) ); } // end method processConnection // close streams and socket private void closeConnection() { displayMessage( "\nClosing connection" ); setTextFieldEditable( false ); // disable enterField try { output.close(); // close output stream input.close(); // close input stream client.close(); // close socket } // end try catch ( IOException ioException ) { ioException.printStackTrace(); } // end catch } // end method closeConnection // send message to server private void sendData( String message ) //need to send filename to server { try // send object to server { output.writeObject(message); //output.writeObject(fileName); //is writeObject the appropriate write method? output.flush(); // flush data to output displayMessage( "\nCLIENT&gt;&gt;&gt; " + message ); } // end try catch ( IOException ioException ) { displayArea.append( "\nError writing object" ); ioException.printStackTrace(); } // end catch } // end method sendData // manipulates displayArea in the event-dispatch thread private void displayMessage( final String messageToDisplay ) { SwingUtilities.invokeLater( new Runnable() { public void run() // updates displayArea { displayArea.append( messageToDisplay ); } // end method run } // end anonymous inner class ); // end call to SwingUtilities.invokeLater } // end method displayMessage // manipulates enterField in the event-dispatch thread private void setTextFieldEditable( final boolean editable ) { SwingUtilities.invokeLater( new Runnable() { public void run() // sets enterField's editability { enterField.setEditable( editable ); } // end method run } // end anonymous inner class ); // end call to SwingUtilities.invokeLater } // end method setTextFieldEditable } // end class Client </code></pre> <p>I hope this helps.</p>
27,497,638
0
<p>You could do this using a callback function.</p> <pre><code>var r = s.replace(/{{[^}]*}}/g, function(v) { return v.replace(/&amp;#x27;/g, '"'); }); </code></pre>
12,621,382
0
Active Record has_many generates sql with foreign key IS NULL <p>I don't expect a model with NULL as foreign key to belong to anything!</p> <p>I have the following rails app, modelling ants and ant hills (inspired by Jozef).</p> <pre><code>$ rails -v Rails 3.2.8 $ rails new ant_hill $ cd ant_hill </code></pre> <p>Create the ant hill and ant models. An ant can belong to an ant hill and an ant hill can have many ants.</p> <pre><code>$ rails generate model AntHill name:string $ rails generate model Ant name:string ant_hill_id:integer $ vim app/models/ant.rb $ cat app/models/ant.rb class Ant &lt; ActiveRecord::Base belongs_to :ant_hill end $ vim app/models/ant_hill.rb $ cat app/models/ant_hill.rb class AntHill &lt; ActiveRecord::Base has_many :ants end $ rake db:migrate == CreateAntHills: migrating ================================================= -- create_table(:ant_hills) -&gt; 0.0013s == CreateAntHills: migrated (0.0016s) ======================================== == CreateAnts: migrating ===================================================== -- create_table(:ants) -&gt; 0.0035s == CreateAnts: migrated (0.0037s) ============================================ </code></pre> <p>Run the following code in a console.</p> <pre><code>$ rails c Loading development environment (Rails 3.2.8) </code></pre> <p>Create a couple of ants, persisted, that don't belong to any ant hill.</p> <pre><code>1.9.2-p290 :001 &gt; Ant.create! name: "August" =&gt; #&lt;Ant id: 1, name: "August", ant_hill_id: nil, created_at: "2012-09-27 12:01:06", updated_at: "2012-09-27 12:01:06"&gt; 1.9.2-p290 :002 &gt; Ant.create! name: "Bertil" =&gt; #&lt;Ant id: 2, name: "Bertil", ant_hill_id: nil, created_at: "2012-09-27 12:01:13", updated_at: "2012-09-27 12:01:13"&gt; </code></pre> <p>Now instantiate an ant hill, but don't save it just yet.</p> <pre><code>1.9.2-p290 :003 &gt; ant_hill = AntHill.new name: "Storkullen" =&gt; #&lt;AntHill id: nil, name: "Storkullen", created_at: nil, updated_at: nil&gt; </code></pre> <p>I expect this ant hill to not have any ants and it doesn't.</p> <pre><code>1.9.2-p290 :004 &gt; ant_hill.ants =&gt; [] </code></pre> <p>I still expect the ant hill to not have any ants but now it has two.</p> <pre><code>1.9.2-p290 :005 &gt; ant_hill.ants.count (0.1ms) SELECT COUNT(*) FROM "ants" WHERE "ants"."ant_hill_id" IS NULL =&gt; 2 </code></pre> <p>Same here, it should never generate a query containing "IS NULL" when dealing with foreign keys. I mean "belongs_to NULL" can't belong to anything, right?</p> <pre><code>1.9.2-p290 :006 &gt; ant_hill.ants.all Ant Load (0.4ms) SELECT "ants".* FROM "ants" WHERE "ants"."ant_hill_id" IS NULL =&gt; [#&lt;Ant id: 1, name: "August", ant_hill_id: nil, created_at: "2012-09-27 12:01:06", updated_at: "2012-09-27 12:01:06"&gt;, #&lt;Ant id: 2, name: "Bertil", ant_hill_id: nil, created_at: "2012-09-27 12:01:13", updated_at: "2012-09-27 12:01:13"&gt;] </code></pre> <p>After it is persisted it behaves as expected.</p> <pre><code>1.9.2-p290 :007 &gt; ant_hill.save! =&gt; true 1.9.2-p290 :008 &gt; ant_hill.ants.count (0.4ms) SELECT COUNT(*) FROM "ants" WHERE "ants"."ant_hill_id" = 1 =&gt; 0 1.9.2-p290 :009 &gt; ant_hill.ants.all Ant Load (0.4ms) SELECT "ants".* FROM "ants" WHERE "ants"."ant_hill_id" = 1 =&gt; [] </code></pre> <p>Any insight? Is this the expected behavior?</p>
29,790,119
0
<p><code>flexbox</code> can solve your problem.</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>#container { display: flex; align-items: stretch; } #container &gt; div { border: 1px solid black; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;div id="container"&gt; &lt;div class="col-xs-12 col-sm-6 col-md-4 col-lg-3"&gt; &lt;div class="blog-item"&gt; &lt;div class="img"&gt;IMAGE&lt;/div&gt; &lt;div class="title"&gt;SOME TITLE&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="col-xs-12 col-sm-6 col-md-4 col-lg-3"&gt; &lt;div class="blog-item"&gt; &lt;div class="img"&gt;image2&lt;/div&gt; &lt;div class="title"&gt;title2&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="col-xs-12 col-sm-6 col-md-4 col-lg-3"&gt; &lt;div class="blog-item"&gt; &lt;div class="img"&gt;image3&lt;/div&gt; &lt;div class="title"&gt;title3&lt;/div&gt; &lt;div class="desc"&gt;long descriptions&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="col-xs-12 col-sm-6 col-md-4 col-lg-3"&gt; &lt;div class="blog-item"&gt; &lt;div class="img"&gt;image4&lt;/div&gt; &lt;div class="title"&gt;title4&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
21,004,730
0
Creation of DataTemplate in code-behind fails <p>I'm trying to create a <code>DataTemplate</code> in my code and I came across <a href="http://stackoverflow.com/a/7171332/1094430">this asnwer</a>.</p> <p>So I just copied and edited the code, but it fails with this exception:</p> <blockquote> <p>First-chance exception 'System.Windows.Markup.XamlParseException' in System.Windows.ni.dll Unknown parser error: Scanner 2147500037. [Line: 4 Position: 36]</p> </blockquote> <p>Here's the generated XAML code:</p> <pre><code>&lt;DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:simplebackground="clr-namespace:Plugins.Backgrounds.SimpleBackground"&gt; &lt;simplebackground:SimpleBackground/&gt; &lt;/DataTemplate&gt; </code></pre> <p>and here's the XAML code that I'm currently using in my page (this one's working):</p> <pre><code>&lt;phone:PhoneApplicationPage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:simpleBackground="clr-namespace:Namespace.Backgrounds.SimpleBackground" x:Class="Namespace.Backgrounds.SimpleBackground.SimpleBackground" mc:Ignorable="d" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" d:DesignHeight="480" d:DesignWidth="480"&gt; &lt;phone:PhoneApplicationPage.Resources&gt; &lt;DataTemplate x:Key="DataTemplate"&gt; &lt;simpleBackground:SimpleBackground /&gt; &lt;/DataTemplate&gt; &lt;/phone:PhoneApplicationPage.Resources&gt; ............. &lt;phone:PhoneApplicationPage&gt; </code></pre> <p>To generate the XAML I'm using this C# code:</p> <pre><code>public static DataTemplate Create(Type type) { var templateString = "&lt;DataTemplate\r\n" + "xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\r\n" + "xmlns:" + type.Name.ToLowerInvariant() + "=\"clr-namespace:" + type.Namespace + "\"&gt;\r\n" + "&lt;" + type.Name.ToLowerInvariant() + ":" + type.Name + "/&gt;\r\n" + "&lt;/DataTemplate&gt;"; return XamlReader.Load(templateString) as DataTemplate; } </code></pre> <p>What's wrong with it? The exception's message is not that useful :(</p>
6,277,846
0
<p>This is happening because you have created float based layout on the various block elements. Floating elements break out of the normal flow of the page.</p> <p>You don't think you need to apply float on the <code>td</code>'s. You can make use of the <code>text-align: left;</code> for aligning the element in the <code>td</code>.</p>
4,606,140
0
<p>Merging all the arrays together isn't necessary. Use <code>sort</code> to get the correct index ordering for the elements in <code>@x</code>:</p> <pre><code>@sort_by_x = sort { $x[$a] &lt;=&gt; $x[$b] } 0 .. $#x; # ==&gt; (0, 2, 1) </code></pre> <p>Then apply that index ordering to any other array:</p> <pre><code>@x = @x[@sort_by_x]; @y = @y[@sort_by_x]; @z = @z[@sort_by_x]; </code></pre>
14,289,505
0
<p>20 million rows is not a lot for MySQL. Just index the zip/postal code and it will be fast. Way under 200ms fast. No need to split between tables. MySQL does get slow when the result set is large, but it doesn't seem like you would encounter that issue. MySQL will do just fine with hundreds of millions of records for basic queries like yours.</p> <p>You will need to adjust the MySQL settings so that it uses more memory. The default settings are pretty low. </p> <p>MySQL does support spacial indexes. So you could pull the longitude/latitude for the postal codes and use a spacial index to do proximity searches. Doesn't seem like you are looking for that though.</p> <p>If you want things really, really fast, go the route you were thinking of but use memcache or redis. You can use the zip/postal code as the lookup key. You would still need a persistant disk based data store to load the data from. I don't think memcache/redis is necessary, but it's an option.</p>
25,223,113
0
<p>Finally found the problem. The problem was with following tag in web.config file. However, I do not know why GoDaddy does not accept it. Nevertheless, it works now!</p> <pre><code>&lt;staticContent&gt; &lt;mimeMap fileExtension=".otf" mimeType="application/font-sfnt" /&gt; &lt;/staticContent&gt; </code></pre>
26,440,751
0
<p>You cannot make an "eternal service", nor would that be the correct approach for this problem. <a href="http://commonsware.com/blog/2014/07/27/role-services.html" rel="nofollow">Only have a service running when it is <strong>actively delivering value to the user</strong></a>. Watching the clock tick is not actively delivering value to the user.</p> <p>Use <code>AlarmManager</code> to arrange to get control at the time to do the reminder.</p>
3,082,730
0
<p>PROBLEM: "&amp;&amp;" and "||" is converted to a method like "AndCondition(a, b)", so "!a.HasValue || a.Value == b" becomes "OrCondition(!a.HasValue, a.Value == b);" The reason for this is probably to get a generic solution to work for both code and SQL statements. So instead, use the "?:" notation.</p> <p>For more, see my blog post: <a href="http://peetbrits.wordpress.com/2008/10/18/linq-breaking-your-logic/" rel="nofollow noreferrer">http://peetbrits.wordpress.com/2008/10/18/linq-breaking-your-logic/</a></p> <pre><code>// New revised code. public static int NumberUnderReview(int? ownerUserId, List&lt;int&gt; ownerGroupIds) { return ( from c in db.Contacts where c.Active == true &amp;&amp; c.LastReviewedOn &lt;= DateTime.Now.AddDays(-365) &amp;&amp; ( // Owned by user // !ownerUserId.HasValue || // c.OwnerUserId.Value == ownerUserId.Value ownerUserId.HasValue ? c.OwnerUserId.Value == ownerUserId.Value : true ) &amp;&amp; ( // Owned by group // ownerGroupIds.Count == 0 || // ownerGroupIds.Contains( c.OwnerGroupId.Value ) ownerGroupIds.Count != 0 ? ownerGroupIds.Contains( c.OwnerGroupId.Value ) : true ) select c ).Count(); } </code></pre>
25,105,442
0
<pre><code>[cling$] .help ... .&gt; &lt;filename&gt; - Redirect command to a given file '&gt;' or '1&gt;' - Redirects the stdout stream only '2&gt;' - Redirects the stderr stream only '&amp;&gt;' (or '2&gt;&amp;1') - Redirects both stdout and stderr '&gt;&gt;' - Appends to the given file </code></pre> <p>This is how one can redirect the streaming of execution results.</p>
40,464,887
0
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>input[type="text"]{ color : transparent; text-shadow : 0 0 0 #000; } input[type="text"]:focus{ outline : none; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text" value="test message" /&gt;</code></pre> </div> </div> </p>
39,857,613
0
Swift 2.3: Is there a way to figure out the state of Location Services, Location Updates? <p><code>locationManager.startUpdatingLocation()</code> turns your location updates on and <code>locationManager.stopUpdatingLocation()</code> turns your updates off.</p> <p>But I'd like to know if there's a way to get the current state. <br/> I tried <code>respondsToSelector</code> but that isn't quite right and probably obviously always returning <code>true</code>.</p> <p>I'm trying to make a switch that'll allow the user to turn on and off location updates. <br/> Getting the default value of the switch is my issue.</p> <p>Update for clarity: I'm trying to see the state of location updates rather than the state of the service.</p>
9,887,374
1
Find the two longest strings from a list || or the second longest list in PYTHON <p>I'd like to know how i can find the two longest strings from a list(array) of strings or how to find the second longest string from a list. thanks</p>
16,815,474
0
Why did parseFrom() function hang using protobuf in java socket? <p>I just want to create echo server/client using protobuf and java.</p> <p>I tested with protobuf-java-2.4.1 and jdk1.7.</p> <p>I wrote echo server code like below</p> <pre><code>// create server socket and accept for client connection. // ... link = servSock.accept(); Person person = Person.parseFrom(link.getInputStream()); // blocking position person.writeTo(link.getOutputStream()); </code></pre> <p>I think it is not necessary to note Person.proto.</p> <p>The client code is only send Person object using socket input stream and receive echo Person object.</p> <pre><code>// socket connect code was omitted. Person person = Person.newBuilder().setId(1).setName("zotiger").build(); person.writeTo(echoSocket.getOutputStream()); person = Person.parseFrom(echoSocket.getInputStream()); </code></pre> <p>But server was blocked in parseFrom function when the server and client both run.</p> <p>I found if i use writeDelimitedTo() and parseDelimitedFrom(), then that is ok. I don't understand why the writeTo() and parseFrom() function does not working.</p> <p>Why did the server blocking in there?</p> <p>Is it necessary to send some end signal from client side?</p>
35,518,577
0
<p>Full disclosure: From my personal blog</p> <p><a href="http://stackentry.blogspot.in/2016/01/addition-of-two-numbers-in-android.html" rel="nofollow">Addition program in android</a></p> <p>XML and Java code for addition of two numbers in android</p> <p>Mainactivity.java</p> <pre><code>public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private EditText editText,editText2,editText4; int v1,v2,v3; String s="ans"; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); button.setOnClickListener(this); } @Override public void onClick(View v) { editText=(EditText)findViewById(R.id.editText); editText2=(EditText)findViewById(R.id.editText2); editText4=(EditText)findViewById(R.id.editText4); v1=Integer.parseInt(editText.getText().toString()); v2=Integer.parseInt(editText2.getText().toString()); v3=v1+v2; s=String.valueOf(v3); editText4.setText(s); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } </code></pre> <p>activitymain.xml </p> <pre><code> &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"&gt; &lt;EditText android:layout_width="500dp" android:layout_height="40dp" android:id="@+id/editText2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="60dp" /&gt; &lt;EditText android:layout_width="500dp" android:layout_height="40dp" android:id="@+id/editText" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/editText2" /&gt; &lt;EditText android:layout_width="800dp" android:layout_height="40dp" android:id="@+id/editText4" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_below="@+id/editText" /&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="OK" android:id="@+id/button" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /&gt; &lt;/RelativeLayout&gt; </code></pre>
35,849,824
0
<p>You can setup <code>channels</code> for each song , add song to each channel and then manipulate channel instead of music object.</p> <p>Here is a working code. It changes volume differently for each song thats added to each channel. The program assumes all songs in <code>audio</code> folder within your current working directory.</p> <p>The program is oversimplified to illustrate concept. You can of course create list of songs and channels then add and manipulate them based on index.</p> <p><strong>Program</strong></p> <pre><code>import pygame def checkifComplete(channel): while channel.get_busy(): #Check if Channel is busy pygame.time.wait(800) # wait in ms channel.stop() #Stop channel if __name__ == "__main__": music_file1 = "sounds/audio1.wav" music_file2 = "sounds/audio2.wav" #set up the mixer freq = 44100 # audio CD quality bitsize = -16 # unsigned 16 bit channels = 2 # 1 is mono, 2 is stereo buffer = 2048 # number of samples (experiment to get right sound) pygame.mixer.init(freq, bitsize, channels, buffer) pygame.mixer.init() #Initialize Mixer #Create sound object for each Audio myAudio1 = pygame.mixer.Sound(music_file1) myAudio2 = pygame.mixer.Sound(music_file2) #Create a Channel for each Audio myChannel1 = pygame.mixer.Channel(1) myChannel2 = pygame.mixer.Channel(2) #Add Audio to first channel myAudio1.set_volume(0.8) # Reduce volume of first audio to 80% print "Playing audio : ", music_file1 myChannel1.play(myAudio1) checkifComplete(myChannel1) #Check if Audio1 complete #Add Audio to second channel myAudio2.set_volume(0.2) # Reduce volume of first audio to 20% print "Playing audio : ", music_file2 myChannel2.play(myAudio2) checkifComplete(myChannel2) </code></pre> <p><strong>Program Output</strong></p> <pre><code>Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. &gt;&gt;&gt; ================================ RESTART ================================ &gt;&gt;&gt; Playing audio : sounds/audio1.wav Playing audio : sounds/audio2.wav &gt;&gt;&gt; </code></pre>
17,201,906
0
Use of different object properties for same function <p>In the avatar generator I'm working on I have several button events that do the same thing but with different body parts. I don't want to have different functions doing the same thing, so I want to use one function for all body parts.</p> <p>Line 14 below uses the object propery 'AvGen.eyes.currEyesNr', but instead I want to use the one for the clicked button. What can I put in as an argument and how can I use the parameter in the function to be able to use the correct object parameter?</p> <pre><code> 1. prevBodyBtn.on('click', function(){ 2. if (AvGen.theBody.currBodyNr &gt; 0) { 3. changePart(-1); 4. } 5. }); 6. 7. prevEyesBtn.on('click', function(){ 8. if (AvGen.eyes.currEyesNr &gt; 0) { 9. changePart(-1); 10. } 11. }); 12. 13. function changePart(direction) { 14. AvGen.eyes.currEyesNr += direction; // &lt;-- this is now always 'AvGen.eyes.currEyesNr' but should be dynamic 15. 16. var body = AvGen.theBody.bodies[AvGen.theBody.currBodyNr], 17. eyes = AvGen.eyes.eyes[AvGen.eyes.currEyesNr], 18. nose = AvGen.nose.noses[AvGen.nose.currNoseNr]; 19. mouth = AvGen.mouth.mouths[AvGen.mouth.currMouthNr]; 20. 21. AvGen.addSVG(body, eyes, nose, mouth); 22. } </code></pre>
33,891,626
0
<p>It's really simple, as it turns out.</p> <pre><code>this.setValue(foo, "Text"); </code></pre> <p>The only tricky part is that <code>foo</code> has to be a valid value, as in, it exists in <code>this._.items</code>.</p> <p>If it's invalid, the richCombo will break. "Text" can be whatever you want it to be.</p>
32,781,842
0
<p>Short answer: Because DOS behaved this way, and <code>cmd</code> tries to mimic DOS.</p> <p>Originally, DOS had a 'current director' for each drive, so if you write <code>cd d:\folder</code> you change the current directory for the <code>D</code> drive.</p> <p>You can read more about this here: <a href="http://blogs.msdn.com/b/oldnewthing/archive/2010/10/11/10073890.aspx" rel="nofollow">http://blogs.msdn.com/b/oldnewthing/archive/2010/10/11/10073890.aspx</a></p>
31,903,313
0
Positioning mesh in three.js <p>I m trying to understand how i can positioning my cubes in the canvas. But i don't understand how positioning work. I m looking a way to detect if my mesh meet the limit of the canvas. But what is the unit of position.x or position.y ? </p> <p>And what is the relation between the canvas width , height and meshs on in the canvas?</p> <p>Thanks.</p> <pre><code> var geometry = new Array(),material = new Array(),cube = new Array(); var i = 0; for(i=0; i &lt; 10;i++){ geometry[i] = new THREE.BoxGeometry(1,1,1); material[i] = new THREE.MeshBasicMaterial({ color: 0x33FF99 }); cube[i] = new THREE.Mesh(geometry[i], material[i]); scene.add(cube[i]); } camera.position.z = 5; var render = function () { requestAnimationFrame(render); var xRandom = 0; var yRandom = 0; var zRandom = 0; var sens = 1; for (i = 0; i &lt; cube.length ; i++) { document.getElementById('widthHeight').innerHTML = " " + window.innerHeight + " " + window.innerWidth + "&lt;br&gt; x:" + cube[i].position.x + " &lt;br&gt; y:" + cube[i].position.y + " &lt;br&gt; z:" + cube[i].position.z; xRandom = (Math.random() * 0.010 + 0.001) * sens; yRandom = (Math.random() * 0.010 + 0.001) * sens; zRandom = (Math.random() * 0.010 + 0.001) * sens; cube[i].position.setX(xRandom + cube[i].position.x); cube[i].position.setY(yRandom + cube[i].position.y); cube[i].position.setZ(zRandom + cube[i].position.z); cube[i].rotation.x += 0.0191; cube[i].rotation.y += 0.0198; } renderer.render(scene, camera); }; render(); </code></pre> <p>i added a PlaneGeometry and some tests to detect if cubes reach limit x or y of the new PlaneGeometry. </p> <pre><code> var geometry = new Array(),material = new Array(),cube = new Array(); var i = 0; var planeMap = new THREE.PlaneGeometry(100, 100); var materialMap = new THREE.MeshBasicMaterial({ color: 0xCE0F0F }); var map = new THREE.Mesh(planeMap,materialMap); scene.add(map); for(i=0; i &lt; 5; i++){ geometry[i] = new THREE.BoxGeometry(3,3,3); material[i] = new THREE.MeshBasicMaterial({ color: 0x336699 }); cube[i] = new THREE.Mesh(geometry[i], material[i]); scene.add(cube[i]); } camera.position.z = 100; var render = function () { requestAnimationFrame(render); var xRandom = 0,yRandom = 0,zRandom = 0,x=0,y=0,z=0; var sensX = 1, sensY = 1, sensZ = 1; var widthHeight = document.getElementById('widthHeight'); for (i = 0; i &lt; cube.length ; i++) { if (cube[i].geometry.type == "BoxGeometry") { widthHeight.innerHTML = " " + window.innerHeight + " " + window.innerWidth + "&lt;br&gt; x:" + cube[i].position.x + " &lt;br&gt; y:" + cube[i].position.y + " &lt;br&gt; z:" + cube[i].position.z; var currentCube = cube[i].position; var widthCube = cube[i].geometry.parameters.width; var heightCube = cube[i].geometry.parameters.height; x = currentCube.x; y = currentCube.y; z = currentCube.z; if (x &gt;= ((map.geometry.parameters.width / 2) - widthCube)) { sensX = -1; } if (x &lt;= ((map.geometry.parameters.width / 2) - widthCube)*-1) { sensX = 1; } if (y &gt;= ((map.geometry.parameters.height / 2) - heightCube)) { sensY = -1; } if (y &lt;= ((map.geometry.parameters.height / 2) - heightCube)*-1) { sensY = 1; } xRandom = (Math.random() * 0.650 + 0.001) * sensX * (i + 1); yRandom = (Math.random() * 0.850 + 0.001) * sensY * (i + 1); //zRandom = (Math.random() * 0.450 + 0.001) * sensZ * (i + 1); cube[i].position.setX(xRandom + x); cube[i].position.setY(yRandom + y); cube[i].position.setZ(zRandom + z); cube[i].rotation.x += 0.01; cube[i].rotation.y += 0.01; } } </code></pre>
5,538,966
0
Going crazy here, can't figure out why rename(), copy() functions don't work <p>Here is what I have,</p> <pre><code>$name = "image.jpeg"; $to = "/var/www/vhosts/site.com/httpdocs/termination_files/personal_photos/original/".$name; $from = "/var/www/vhosts/site.com/httpdocs/public/userimages/original/".$name; </code></pre> <p>and </p> <pre><code>rename($from,$to); </code></pre> <p>or</p> <pre><code>copy($from,$to); </code></pre> <p>Shouldn't this work?! Directory permissions are set to 755, paths are copied from ssh, so they're accurate. Files exist in the from location. </p>
16,046,113
0
Compiled MuPDF library integration in android project <p>I have compiled mupdf library but when I integrate it in my existing android project to render the PDF it give me the following error :</p> <pre><code>java.lang.ExceptionInInitializerError </code></pre> <p>I have followed the following steps for integration :</p> <p>Steps are explained here : <a href="http://pastebin.com/YzHUhzE7" rel="nofollow">http://pastebin.com/YzHUhzE7</a></p> <p>When i change the package name in mupdf test project then the native code get modified and the above expiation arises . So if any one knows how to integrate MuPDF compiled in my project .</p>
1,307,857
0
<p>If you want to call another page and get the response back as string, you can use <code>WebClient</code> class.</p> <pre><code>var myWebClient = new WebClient(); string resultStr = myWebClient.DownloadString("http://www.google.com"); </code></pre>
10,573,130
0
Implications of using std::vector in a dll exported function <p>I have two dll-exported classes A and B. A's declaration contains a function which uses a std::vector in its signature like:</p> <pre><code>class EXPORT A{ // ... std::vector&lt;B&gt; myFunction(std::vector&lt;B&gt; const &amp;input); }; </code></pre> <p>(EXPORT is the usual macro to put in place _<em>declspec(dllexport)/</em>_declspec(dllimport) accordingly.)</p> <p>Reading about the issues related to using STL classes in a DLL interface, I gather in summary:</p> <ul> <li><p>Using std::vector in a DLL interface would require all the clients of that DLL to be compiled with the same <em>version</em> of the same compiler because STL containers are not binary compatible. Even worse, depending on the use of that DLL by clients conjointly with other DLLs, the ''instable'' DLL API can break these client applications when system updates are installed (e.g. Microsoft KB packages) (really?).</p></li> <li><p>Despite the above, if required, std::vector can be used in a DLL API by exporting <code>std::vector&lt;B&gt;</code> like:</p> <pre><code>template class EXPORT std::allocator&lt;B&gt;; template class EXPORT std::vector&lt;B&gt;; </code></pre> <p>though, this is usually mentioned in the context when one wants to use std::vector as a <em>member</em> of A (http://support.microsoft.com/kb/168958).</p></li> <li><p>The following Microsoft Support Article discusses how to access std::vector objects created in a DLL through a pointer or reference from within the executable (http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q172396). The above solution to use <code>template class EXPORT ...</code> seems to be applicable too. However, the drawback summarized under the first bullet point seems to remain.</p></li> <li><p>To completely get rid of the problem, one would need to wrap std::vector and change the signature of <code>myFunction</code>, PIMPL etc..</p></li> </ul> <p>My questions are:</p> <ul> <li><p>Is the above summary correct, or do I miss here something essential?</p></li> <li><p>Why does compilation of my class 'A' not generate warning C4251 (class 'std::vector&lt;_Ty>' needs to have dll-interface to be used by clients of...)? I have no compiler warnings turned off and I don't get any warning on using std::vector in <code>myFunction</code> in exported class A (with VS2005).</p></li> <li><p>What needs to be done to correctly export <code>myFunction</code> in A? Is it viable to just export <code>std::vector&lt;B&gt;</code> and B's allocator? </p></li> <li><p>What are the implications of returning std::vector by-value? Assuming a client executable which has been compiled with a different compiler(-version). Does trouble persist when returning by-value where the vector is copied? I guess yes. Similarly for passing std::vector as a constant reference: could access to <code>std::vector&lt;B&gt;</code> (which might was constructed by an executable compiled with a different compiler(-version)) lead to trouble within <code>myFunction</code>? I guess yes again..</p></li> <li><p>Is the last bullet point listed above really the only clean solution?</p></li> </ul> <p>Many thanks in advance for your feedback.</p>
21,368,094
0
What is wrong with this short C code <p>I'm trying to scan input, if user types "yes" put "etc" otherwise exit. But it's not working right, when i type yes it says invalid instead. Thanks ahead of time. </p> <pre><code>#include &lt;stdio.h&gt; char yes='yes'; char name[100]; int main() { puts("Starting History Project please Enter your name: "); scanf("%s",&amp;name); printf("Hey %s!",name); puts("My name is C! Are you interested about my history? yes or no"); scanf("%s", &amp;yes); if (yes == 'yes') { printf("Starting ADT \n"); } else { printf("Invalid\n"); exit(0); } return(0); } </code></pre>
13,596,956
0
<p>I used a variation of Shawn's solution.. it looks nice on the Emulator.</p> <p>1) Decide on the # of columns, I chose 4 </p> <p>2) Set the Column Width</p> <pre><code>float xdpi = this.getResources().getDisplayMetrics().xdpi; int mKeyHeight = (int) ( xdpi/4 ); GridView gridView = (GridView) findViewById(R.id.gridview); gridView.setColumnWidth( mKeyHeight );// same Height &amp; Width </code></pre> <p>3) Setup the image in your adapter's getView method</p> <pre><code>imageView = new ImageView( mContext ); // (xdpi-4) is for internal padding imageView.setLayoutParams(new GridView.LayoutParams( (int) (xdpi-4)/2, (int) (xdpi-4)/2)); imageView.setScaleType( ImageView.ScaleType.CENTER_CROP ); imageView.setPadding(1, 1, 1, 1); </code></pre> <p>4) Layout</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numColumns="4" android:verticalSpacing="0dp" android:horizontalSpacing="0dp" android:gravity="center" android:listSelector="@null" /&gt; &lt;!-- android:columnWidth="90dp" Specified in code android:stretchMode="columnWidth" no noticable change --&gt; </code></pre> <p>That's it. </p>
3,382,479
0
cocoa : dock like window <p>I am looking to create a NSWindow behaving like the dock window: - Appears when the mouse cursor stays at one edge of the screen - Does not takes the focus (the app having the focus keeps it) but reveives mouse events</p> <p>Any idea on how I can implement this?</p> <p>Thanks in advance for your help,</p>
8,574,298
0
<p>You have to use relative paths all over your app:</p> <p><code>~</code> won't work within static html code.</p> <p>You can write</p> <pre><code>&lt;img src="@Url.Content("~/images/logos/hdr.png")" /&gt; </code></pre> <p>or </p> <pre><code>&lt;img src="../images/logos/hdr.png" /&gt; </code></pre> <p>The first approach is good for layout files where your relative path might be changing when you have different length routing urls.</p> <p><strong>EDIT</strong></p> <p>Regarding to your question about normal links:</p> <p>When linking to another page in your app you don't specify the view file as the target but the action which renders a view as the result. For that you use the HtmlHelper <code>ActionLink</code>:</p> <pre><code>@Html.ActionLink("Linktext", "YourController", "YourAction") </code></pre> <p>That generates the right url for you automatically: </p> <pre><code>&lt;a href="YourController/YourAction"&gt;Linktext&lt;/a&gt; </code></pre> <p><strong>EDIT 2</strong></p> <p>Ok, no MVC - so you have to generate your links yourself.</p> <p>You have to use relative paths, too. Don't start any link with the <code>/</code> character!</p> <pre><code>&lt;a href="linkOnSameLevel.cshtml"&gt;Link&lt;/a&gt; &lt;a href="../linkOnParentLevel.cshtml"&gt;Link&lt;/a&gt; &lt;a href="subFolder/linkOnOneLevelDown.cshtml"&gt;Link&lt;/a&gt; </code></pre> <p><strong>EDIT 3</strong></p> <p>When using Layout pages you can use the <code>Href</code>extension method to generate a relative url:</p> <pre><code>&lt;link href="@Href("~/style.css")" ... </code></pre>
9,756,102
0
<p>For AJAX requests running through a controller action, you'd need to use <code>flash.now</code> so that the flash message will be available for the current request. So in your case, <code>flash.now[:notice] = "bar"</code>. </p>
19,013,767
1
Using python docx to create a document and need to modify the paragraph style and save it <p>I am trying to modify "Text Body" style for paragraph in word 2010 so that the Below paragraph spacing is much less. But when I change that value it will not save it so that when I reopen word the modifications are gone.</p> <p>The reason I want to save it is that when the document gets created using python docx and I pass the paragraph function the style it will be with the new values. Anyone have any ideas about this?</p>
27,564,469
0
lua function argument expected near <eof> <p>I try to use lua in a C++ project. For lua executing I write this:</p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;lua.hpp&gt; ... luaEngine = luaL_newstate(); luaL_openlibs(luaEngine); register_results(luaEngine); // For register c++ object in the LUA script as metatable lua_pushstring(luaEngine, resultsId.c_str()); lua_setglobal(luaEngine, "resultsId"); lua_pushboolean(luaEngine, needReloadModel); lua_setglobal(luaEngine, "needReload"); ... e = luaL_loadbuffer(luaEngine, script.c_str(), script.size(), NULL); if(e != 0) // error message e = lua_pcall(luaEngine, 0, 1, 0); if(e != 0) // error message ... lua_close(luaEngine); </code></pre> <p>And the lua script:</p> <pre class="lang-lua prettyprint-override"><code>local Res = ResUpdateLUA(resultsId) if current_result == "Normal" or current_result=='-' then status = 'E' else status = 'O' end needReload = Res:setShowAnalyte('2320', status) </code></pre> <p>That didn't work and I've got error message:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>[string "?"]:7: function arguments expected near &lt;eof&gt; </code></pre> </blockquote> <p>But when I add</p> <pre class="lang-lua prettyprint-override"><code>print(needReload) </code></pre> <p>at the end of the lua script it works nice. What am I doing wrong?</p>
19,995,768
0
How to do a C# code before onsubmit() javascript function <p>I want to execute first a C# code before a form redirects to another page.</p> <p>How will i do that?</p>
5,833,681
0
<p>Read up on thing called "Closure Tables". It might make few things easier for you.</p>
28,641,178
0
Unpacking packed primitives (such as an enum) from NSArray or NSDictionary during fast enumeration <p>You can put primitives in an NSArray or NSDictionary by packing them with the @() syntax. For example:</p> <pre><code>typedef enum { MyEnumOne, MyEnumTwo } MyEnum NSDictionary *dictionary = @{ @(MyEnumOne) : @"one", @(MyEnumTwo) : @"two" }; </code></pre> <p>But how do you then use this with fast enumeration? For example, something like:</p> <pre><code>for (MyEnum enum in dictionary) { ... } </code></pre> <p>This results in the error <code>Selector element type 'MyEnum' is not a valid object</code></p>
20,315,925
0
Why should I use cookies other than for storing a session id? <p>For HTTP as far as I understand are two ways to store data belonging to a client and bring some kind of state into a otherwise stateless Browser-webcontainer-connection: 1) Data stored in cookies on the client-side - or 2) A session ID stored in a cookie and the associated data stored in a webcontainer on the server-side. When I compare these two possibilities I can't come up with a reason, why one should go the first way. But still, when I look at my browser's cookies, I see a lot of data stored in them. </p> <ul> <li>A webcontainer (like tomcat) can store arbitrary data together with a session id - A cookie is quite limited in size.</li> <li>Cookies are more vulnerable, since they are stored on the client's side. Keep data on the server-side is, as it looks for me, just more secure. </li> <li>Both, cookies and webcontainer-sessions, can define expiration dates.</li> <li>Both, browser and webcontainer, persist their data over restarts.</li> </ul> <p>Can anyone come up with a scenario where the use of cookies for storing session data has benefits or is even necessary?</p>
21,249,347
0
<p>For the $_POST variables use syntax as $_POST['your variable name']</p> <p>I corrected your code as below:</p> <pre><code>&lt;form action="test.php" method="post"&gt; First Name: &lt;input type="text" name="fname"&gt;&lt;br&gt; Last Name: &lt;input type="text" name="lname"&gt;&lt;br&gt; E-mail: &lt;input type="text" name="email"&gt;&lt;br&gt; &lt;input type="hidden" name="submitted" value="1"&gt; &lt;input type="submit"&gt; &lt;/form&gt; &lt;?php //If form was submitted if ($_POST['submitted']==1) { $errormsg = ""; //Initialize errors if ($_POST['fname']){ $fname = $_POST['fname']; //If fname was entered } else{ $errormsg = "Please enter first name"; } if ($_POST['lname']){ $lname = $_POST['lname']; //If lname was entered } else{ if ($errormsg){ //If there is already an error, add next error $errormsg = $errormsg . ", last name"; } else{ $errormsg = "Please enter last name"; } } if ($_POST['email']){ $email = $_POST['email']; //If email was entered } else{ if ($errormsg){ //If there is already an error, add next error $errormsg = $errormsg . " &amp; email"; }else{ $errormsg = "Please enter email"; } } } if ($errormsg){ //If any errors display them echo "&lt;div class=\"box red\"&gt;$errormsg&lt;/div&gt;"; } //If all fields present if ($fname &amp;&amp; $lname &amp;&amp; $email){ //Do something echo "&lt;div class=\"box green\"&gt;Form completed!&lt;/div&gt;"; } ?&gt; </code></pre>
33,581,914
0
LINQ select all items of all subcollections that contain a string <p>I'm using jqueryui autocomplete to assist user in an item selection. I'm having trouble selecting the correct items from the objects' subcollections.<br> Object structure (simplified) is</p> <pre><code>public class TargetType { public int Id { get; set; } public string Name { get; set; } public virtual ICollection&lt;SubCategory&gt; SubCategories { get; set; } public TargetType() { SubCategories = new HashSet&lt;SubCategory&gt;(); } } public class SubCategory { public int Id { get; set; } public string Name { get; set; } public virtual ICollection&lt;SubTargetType&gt; SubTargetTypes { get; set; } public SubCategory() { SubTargetTypes = new HashSet&lt;SubTargetType&gt;(); } } </code></pre> <p>Currently I'm doing this with nested foreach loops, but is there a better way?<br> Current code:</p> <pre><code>List&lt;SubTargetResponse&gt; result = new List&lt;SubTargetResponse&gt;(); foreach (SubCategory sc in myTargetType.SubCategories) { foreach (SubTargetType stt in sc.SubTargetTypes) { if (stt.Name.ToLower().Contains(type.ToLower())) { result.Add(new SubTargetResponse { Id = stt.Id, CategoryId = sc.Id, Name = stt.Name }); } } } </code></pre>
15,557,209
0
How do I store DatePicker Time in a SQLite database? Mine keeps crashing <p>I've created a simple record keeping application using various resources around the internet. I'm able to successfully store text data - however when I attempt to incorporate a <code>TimePicker</code> I end up crashing my entire app. I was instructed how to add this functionality in a previous post - but when I attempt to add fields for the timepicker data the entire app closes (and of course does not save the data) </p> <p><a href="http://stackoverflow.com/questions/15540395/how-do-i-store-timepicker-data-in-my-simple-record-keeping-app">How do I store TimePicker Data in my simple record keeping app?</a></p> <p>I was instructed (by the user above) to use the following:</p> <pre><code>CREATE TABLE ...... dtField date, tmpName Text..... </code></pre> <p>use following for saving date as text</p> <p>//sample date format - 2013-03-21 13:12:00</p> <pre><code>android.text.format.DateFormat.format("yyyy-MM-dd hh:mm:ss", dtDate.getTime()) </code></pre> <p>The first half of which I've implemented (I believe). The second half I'm not too sure how to implement correctly (the first thing I need help with), and my app is force closing as well after making these changes (the second thing I need help with.)</p> <p>Any help resolving this issue is greatly appreciated! (I'm a bit of a noob - so the more detailed the instructions - the better!)</p> <p>Thanks in advance,</p> <p>Amani Swann</p> <p>P.S.</p> <p>I updated the source code below with Robby Pond's suggested:</p> <p>Replace</p> <p>EditText timeEt with</p> <p>TimePicker timeEt</p> <p>but I'm im still unable to run the code shown below. </p> <p>Can someone take a look at the logcat or problems log and let me know if you can tell what is causing the issue at this point? The suggestion by Robby Pond was helpful but I have a deeper issue with the (current) source code below. </p> <p>P.S.</p> <p>I know the error cannot be resolved to a type usually indicates there is a class missing or perhaps an XML issue but the error indicates 'TimePicker cannot be resolved to a type' however I don't have a TimePicker.Java - I just want to use the timepicker buttons coded in the XML below.</p> <p>XML: DATA INPUT </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"&gt; &lt;LinearLayout android:id="@+id/linearLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="5dp"&gt; &lt;EditText android:id="@+id/nameEdit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:imeOptions="actionNext" android:hint="@string/name_hint" android:inputType="textPersonName|textCapWords"/&gt; &lt;EditText android:id="@+id/capEdit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:imeOptions="actionNext" android:hint="@string/cap_hint" android:inputType="textPersonName|textCapWords"/&gt; &lt;TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Data Limit" android:textColor="#ffffff" android:textAppearance="?android:textAppearanceMedium" /&gt; &lt;SeekBar android:id="@+id/seekBar1" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" android:gravity="left" android:textColor="#ffffff" android:text="10MB" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" android:gravity="right" android:textColor="#ffffff" android:text="Unlimited Data" /&gt; &lt;/LinearLayout&gt; &lt;TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bandwidth Limit" android:textColor="#ffffff" android:textAppearance="?android:textAppearanceMedium" /&gt; &lt;SeekBar android:id="@+id/seekBar1" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" android:gravity="left" android:textColor="#ffffff" android:text="10kbs" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.0" android:textColor="#ffffff" android:gravity="right" android:text="Unlimited Bandwidth" /&gt; &lt;/LinearLayout&gt; &lt;TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:textAppearanceSmall" /&gt; &lt;TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="WiFi Time Limit" android:textColor="#ffffff" android:textAppearance="?android:textAppearanceMedium" /&gt; &lt;TimePicker android:id="@+id/timeEdit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:layout_weight="1.0" /&gt; &lt;EditText android:id="@+id/codeEdit" android:inputType="textUri" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ems="10" android:lines="1" android:hint="@string/code_hint" android:imeOptions="actionNext" /&gt; &lt;Button android:id="@+id/saveBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:layout_gravity="center_horizontal" android:text="@string/save_btn"/&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>JAVA: DATA INPUT</p> <pre><code>package com.nfc.linkingmanager; import android.app.Activity; import android.app.AlertDialog; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class AddEditCountry extends Activity { private long rowID; private EditText nameEt; private EditText capEt; private EditText codeEt; private TimePicker timeEt; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_country); nameEt = (EditText) findViewById(R.id.nameEdit); capEt = (EditText) findViewById(R.id.capEdit); codeEt = (EditText) findViewById(R.id.codeEdit); timeEt = (TimePicker) findViewById(R.id.timeEdit); Bundle extras = getIntent().getExtras(); if (extras != null) { rowID = extras.getLong("row_id"); nameEt.setText(extras.getString("name")); capEt.setText(extras.getString("cap")); codeEt.setText(extras.getString("code")); timeEt.setText(extras.getString("time")); } Button saveButton =(Button) findViewById(R.id.saveBtn); saveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (nameEt.getText().length() != 0) { AsyncTask&lt;Object, Object, Object&gt; saveContactTask = new AsyncTask&lt;Object, Object, Object&gt;() { @Override protected Object doInBackground(Object... params) { saveContact(); return null; } @Override protected void onPostExecute(Object result) { finish(); } }; saveContactTask.execute((Object[]) null); } else { AlertDialog.Builder alert = new AlertDialog.Builder(AddEditCountry.this); alert.setTitle(R.string.errorTitle); alert.setMessage(R.string.errorMessage); alert.setPositiveButton(R.string.errorButton, null); alert.show(); } } }); } private void saveContact() { DatabaseConnector dbConnector = new DatabaseConnector(this); if (getIntent().getExtras() == null) { dbConnector.insertContact(nameEt.getText().toString(), capEt.getText().toString(), timeEt.getText().toString(), codeEt.getText().toString()); } else { dbConnector.updateContact(rowID, nameEt.getText().toString(), capEt.getText().toString(), timeEt.getText().toString(), codeEt.getText().toString()); } } } </code></pre> <p>XML: DATA OUTPUT</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="1" android:layout_margin="5dp"&gt; &lt;TableRow&gt; &lt;TextView style="@style/StyleLabel" android:text="@string/name_lbl"/&gt; &lt;TextView android:id="@+id/nameText" style="@style/StyleText"/&gt; &lt;/TableRow&gt; &lt;TableRow&gt; &lt;TextView style="@style/StyleLabel" android:text="@string/cap_lbl"/&gt; &lt;TextView android:id="@+id/capText" style="@style/StyleText"/&gt; &lt;/TableRow&gt; &lt;TableRow&gt; &lt;TextView style="@style/StyleLabel" android:text="@string/code_lbl"/&gt; &lt;TextView android:id="@+id/codeText" style="@style/StyleText"/&gt; &lt;/TableRow&gt; &lt;TableRow&gt; &lt;TextView style="@style/StyleLabel" android:text="Linked Users"/&gt; &lt;TextView android:id="@+id/codeText" style="@style/StyleText"/&gt; &lt;/TableRow&gt; &lt;TableRow&gt; &lt;TextView style="@style/StyleLabel" android:text="Time Limit"/&gt; &lt;TextView android:id="@+id/timeText" style="@style/StyleText"/&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; </code></pre> <p>DATA OUTPUT: JAVA</p> <pre><code>import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.os.AsyncTask; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.TextView; public class ViewCountry extends Activity { private long rowID; private TextView nameTv; private TextView capTv; private TextView codeTv; private TextView timeTv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_country); setUpViews(); Bundle extras = getIntent().getExtras(); rowID = extras.getLong(CountryList.ROW_ID); } private void setUpViews() { nameTv = (TextView) findViewById(R.id.nameText); capTv = (TextView) findViewById(R.id.capText); timeTv = (TextView) findViewById(R.id.timeText); codeTv = (TextView) findViewById(R.id.codeText); } @Override protected void onResume() { super.onResume(); new LoadContacts().execute(rowID); } private class LoadContacts extends AsyncTask&lt;Long, Object, Cursor&gt; { DatabaseConnector dbConnector = new DatabaseConnector(ViewCountry.this); @Override protected Cursor doInBackground(Long... params) { dbConnector.open(); return dbConnector.getOneContact(params[0]); } @Override protected void onPostExecute(Cursor result) { super.onPostExecute(result); result.moveToFirst(); // get the column index for each data item int nameIndex = result.getColumnIndex("name"); int capIndex = result.getColumnIndex("cap"); int codeIndex = result.getColumnIndex("code"); int timeIndex = result.getColumnIndex("time"); nameTv.setText(result.getString(nameIndex)); capTv.setText(result.getString(capIndex)); timeTv.setText(result.getString(timeIndex)); codeTv.setText(result.getString(codeIndex)); result.close(); dbConnector.close(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.view_country_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.editItem: Intent addEditContact = new Intent(this, AddEditCountry.class); addEditContact.putExtra(CountryList.ROW_ID, rowID); addEditContact.putExtra("name", nameTv.getText()); addEditContact.putExtra("cap", capTv.getText()); addEditContact.putExtra("time", timeTv.getText()); addEditContact.putExtra("code", codeTv.getText()); startActivity(addEditContact); return true; case R.id.deleteItem: deleteContact(); return true; default: return super.onOptionsItemSelected(item); } } private void deleteContact() { AlertDialog.Builder alert = new AlertDialog.Builder(ViewCountry.this); alert.setTitle(R.string.confirmTitle); alert.setMessage(R.string.confirmMessage); alert.setPositiveButton(R.string.delete_btn, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int button) { final DatabaseConnector dbConnector = new DatabaseConnector(ViewCountry.this); AsyncTask&lt;Long, Object, Object&gt; deleteTask = new AsyncTask&lt;Long, Object, Object&gt;() { @Override protected Object doInBackground(Long... params) { dbConnector.deleteContact(params[0]); return null; } @Override protected void onPostExecute(Object result) { finish(); } }; deleteTask.execute(new Long[] { rowID }); } } ); alert.setNegativeButton(R.string.cancel_btn, null).show(); } } </code></pre> <p>DATABASE CONNECTOR JAVA:</p> <pre><code>import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; public class DatabaseConnector { private static final String DB_NAME = "WorldCountries"; private SQLiteDatabase database; private DatabaseOpenHelper dbOpenHelper; public DatabaseConnector(Context context) { dbOpenHelper = new DatabaseOpenHelper(context, DB_NAME, null, 1); } public void open() throws SQLException { //open database in reading/writing mode database = dbOpenHelper.getWritableDatabase(); } public void close() { if (database != null) database.close(); } public void insertContact(String name, String cap, String code, String time) { ContentValues newCon = new ContentValues(); newCon.put("name", name); newCon.put("cap", cap); newCon.put("time", time); newCon.put("code", code); open(); database.insert("country", null, newCon); close(); } public void updateContact(long id, String name, String cap,String code, String time) { ContentValues editCon = new ContentValues(); editCon.put("name", name); editCon.put("cap", cap); editCon.put("time", time); editCon.put("code", code); open(); database.update("country", editCon, "_id=" + id, null); close(); } public Cursor getAllContacts() { return database.query("country", new String[] {"_id", "name"}, null, null, null, null, "name"); } public Cursor getOneContact(long id) { return database.query("country", null, "_id=" + id, null, null, null, null); } public void deleteContact(long id) { open(); database.delete("country", "_id=" + id, null); close(); } } </code></pre> <p>DATABASE HELPER JAVA:</p> <pre><code>import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; public class DatabaseOpenHelper extends SQLiteOpenHelper { public DatabaseOpenHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); } @Override public void onCreate(SQLiteDatabase db) { String createQuery = "CREATE TABLE country (_id integer primary key autoincrement,name, cap, code, time);"; db.execSQL(createQuery); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } </code></pre> <p>LOGCAT DATA:</p> <pre><code>03-21 17:17:24.276: I/Adreno200-EGLSUB(8655): &lt;ConfigWindowMatch:2165&gt;: Format RGBA_8888. 03-21 17:17:24.276: D/memalloc(8655): ion: Mapped buffer base:0x5ca41000 size:614400 offset:0 fd:57 03-21 17:17:24.276: E/(8655): Can't open file for reading 03-21 17:17:24.276: E/(8655): Can't open file for reading 03-21 17:17:24.376: D/memalloc(8655): ion: Mapped buffer base:0x5d12e000 size:614400 offset:0 fd:61 03-21 17:17:26.188: D/Activity(8655): Activity.onPause(), editTextTapSensorList size: 0 03-21 17:17:26.268: I/Adreno200-EGLSUB(8655): &lt;ConfigWindowMatch:2165&gt;: Format RGBA_8888. 03-21 17:17:26.278: D/memalloc(8655): ion: Mapped buffer base:0x5d4ce000 size:614400 offset:0 fd:68 03-21 17:17:26.318: D/memalloc(8655): ion: Mapped buffer base:0x5d937000 size:614400 offset:0 fd:72 03-21 17:17:26.328: D/memalloc(8655): ion: Unmapping buffer base:0x5ca41000 size:614400 03-21 17:17:26.328: D/memalloc(8655): ion: Unmapping buffer base:0x5d12e000 size:614400 03-21 17:17:26.468: D/Activity(8655): Activity.onPause(), editTextTapSensorList size: 0 03-21 17:17:26.549: D/memalloc(8655): ion: Mapped buffer base:0x5c929000 size:614400 offset:0 fd:54 03-21 17:17:26.619: W/IInputConnectionWrapper(8655): getExtractedText on inactive InputConnection 03-21 17:17:26.639: W/IInputConnectionWrapper(8655): getExtractedText on inactive InputConnection 03-21 17:17:48.322: D/Activity(8655): Activity.onPause(), editTextTapSensorList size: 0 03-21 17:17:48.342: W/dalvikvm(8655): threadid=1: thread exiting with uncaught exception (group=0x410889d8) 03-21 17:17:48.352: E/AndroidRuntime(8655): FATAL EXCEPTION: main 03-21 17:17:48.352: E/AndroidRuntime(8655): java.lang.Error: Unresolved compilation problems: 03-21 17:17:48.352: E/AndroidRuntime(8655): TimePicker cannot be resolved to a type 03-21 17:17:48.352: E/AndroidRuntime(8655): TimePicker cannot be resolved to a type 03-21 17:17:48.352: E/AndroidRuntime(8655): TimePicker cannot be resolved to a type 03-21 17:17:48.352: E/AndroidRuntime(8655): timeEdit cannot be resolved or is not a field 03-21 17:17:48.352: E/AndroidRuntime(8655): TimePicker cannot be resolved to a type 03-21 17:17:48.352: E/AndroidRuntime(8655): TimePicker cannot be resolved to a type 03-21 17:17:48.352: E/AndroidRuntime(8655): TimePicker cannot be resolved to a type 03-21 17:17:48.352: E/AndroidRuntime(8655): at com.nfc.linkingmanager.AddEditCountry.&lt;init&gt;(AddEditCountry.java:19) 03-21 17:17:48.352: E/AndroidRuntime(8655): at java.lang.Class.newInstanceImpl(Native Method) 03-21 17:17:48.352: E/AndroidRuntime(8655): at java.lang.Class.newInstance(Class.java:1319) 03-21 17:17:48.352: E/AndroidRuntime(8655): at android.app.Instrumentation.newActivity(Instrumentation.java:1025) 03-21 17:17:48.352: E/AndroidRuntime(8655): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1875) 03-21 17:17:48.352: E/AndroidRuntime(8655): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985) 03-21 17:17:48.352: E/AndroidRuntime(8655): at android.app.ActivityThread.access$600(ActivityThread.java:127) 03-21 17:17:48.352: E/AndroidRuntime(8655): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151) 03-21 17:17:48.352: E/AndroidRuntime(8655): at android.os.Handler.dispatchMessage(Handler.java:99) 03-21 17:17:48.352: E/AndroidRuntime(8655): at android.os.Looper.loop(Looper.java:137) 03-21 17:17:48.352: E/AndroidRuntime(8655): at android.app.ActivityThread.main(ActivityThread.java:4477) 03-21 17:17:48.352: E/AndroidRuntime(8655): at java.lang.reflect.Method.invokeNative(Native Method) 03-21 17:17:48.352: E/AndroidRuntime(8655): at java.lang.reflect.Method.invoke(Method.java:511) 03-21 17:17:48.352: E/AndroidRuntime(8655): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788) 03-21 17:17:48.352: E/AndroidRuntime(8655): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 03-21 17:17:48.352: E/AndroidRuntime(8655): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>PROBLEMS:</p> <pre><code> Description Resource Path Location Type user3SettingsSave cannot be resolved or is not a field User3Settings.java /NFC Linking Manager/src/com/nfc/linkingmanager line 35 Java Problem The import android.content.Context is never used AppActivity.java /NFC Linking Manager/src/com/nfc/linkingmanager line 5 Java Problem The import android.view.View.OnClickListener is never used AppActivity.java /NFC Linking Manager/src/com/nfc/linkingmanager line 13 Java Problem The value of the field AppActivity.button1 is not used AppActivity.java /NFC Linking Manager/src/com/nfc/linkingmanager line 18 Java Problem The value of the field AppActivity.button2 is not used AppActivity.java /NFC Linking Manager/src/com/nfc/linkingmanager line 18 Java Problem user3Tap cannot be resolved to a type User3Settings.java /NFC Linking Manager/src/com/nfc/linkingmanager line 40 Java Problem The value of the field AppActivity.button3 is not used AppActivity.java /NFC Linking Manager/src/com/nfc/linkingmanager line 18 Java Problem TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 19 Java Problem TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 30 Java Problem TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 30 Java Problem The method deactivate() from the type Cursor is deprecated CountryList.java /NFC Linking Manager/src/com/nfc/linkingmanager line 52 Java Problem The constructor SimpleCursorAdapter(Context, int, Cursor, String[], int[]) is deprecated CountryList.java /NFC Linking Manager/src/com/nfc/linkingmanager line 33 Java Problem The import android.app.AlertDialog is never used User1.java /NFC Linking Manager/src/com/nfc/linkingmanager line 4 Java Problem The import android.view.View.OnClickListener is never used User1.java /NFC Linking Manager/src/com/nfc/linkingmanager line 12 Java Problem The method deactivate() from the type Cursor is deprecated NewCore.java /NFC Linking Manager/src/com/nfc/linkingmanager line 54 Java Problem The constructor SimpleCursorAdapter(Context, int, Cursor, String[], int[]) is deprecated NewCore.java /NFC Linking Manager/src/com/nfc/linkingmanager line 35 Java Problem The import android.content.DialogInterface is never used User1.java /NFC Linking Manager/src/com/nfc/linkingmanager line 6 Java Problem The import android.widget.Button is never used Link.java /NFC Linking Manager/src/com/nfc/linkingmanager line 5 Java Problem The import android.content.Intent is never used Link.java /NFC Linking Manager/src/com/nfc/linkingmanager line 6 Java Problem The import android.view.View.OnClickListener is never used User1Settings.java /NFC Linking Manager/src/com/nfc/linkingmanager line 10 Java Problem The import android.view.View is never used Link.java /NFC Linking Manager/src/com/nfc/linkingmanager line 7 Java Problem The import android.view.View.OnClickListener is never used Link.java /NFC Linking Manager/src/com/nfc/linkingmanager line 8 Java Problem TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 99 Java Problem TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 91 Java Problem TimePicker cannot be resolved to a type AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 41 Java Problem timeEdit cannot be resolved or is not a field AddEditCountry.java /NFC Linking Manager/src/com/nfc/linkingmanager line 30 Java Problem The method showDialog(int) from the type Activity is deprecated User2Settings.java /NFC Linking Manager/src/com/nfc/linkingmanager line 37 Java Problem </code></pre>
6,315,674
0
<p>Try this:</p> <pre><code>$(function(){ $(".Link").click(function(){ var index = $(".Link").index(this); var content= $(".Content").eq(index); //Do Something with content. }); }); </code></pre>
9,400,418
0
<p>The given XML namespaces (note: that are not "xmlns imports") are correct for JSF 2.x. However, in Facelets 1.x, which is to be used standalone in JSF 1.x projects, the XML namespace for JSTL is different, it should not contain the <code>/jsp</code> path.</p> <pre><code>xmlns:c="http://java.sun.com/jstl/core" </code></pre> <p>But if you're actually already using JSF 2.x (in future JSF 2.x questions please mention and tag accordingly), then you're probably using a servletcontainer which doesn't ship with JSTL included, such as Apache Tomcat. You'd need to download JSTL separately and drop it in <code>/WEB-INF/lib</code> folder. In that case the <code>xmlns:c="http://java.sun.com/jsp/jstl/core"</code> should work.</p> <h3>See also:</h3> <ul> <li><a href="http://stackoverflow.com/tags/jstl/info">Our JSTL tag wiki page</a></li> </ul> <hr> <p><strong>Unrelated</strong> to the concrete question, using JSTL in Facelets is definitely possible. You should only make sure that you really understand the lifecycle of tag handlers like JSTL in JSF. See also <a href="http://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense">JSTL in JSF2 Facelets... makes sense?</a> You could alternatively also just use Facelets' own <code>&lt;ui:repeat&gt;</code> tag instead of the <code>&lt;c:forEach&gt;</code>.</p>
32,706,274
0
Wrap columns in rows using Angular <p><strong>Edited</strong> to include angular code (for illustration purposes only)</p> <p>I've been trying to find away in AngularJS to auto wrap columns in rows after n columns whilst not affecting the index.</p> <pre><code>&lt;div class="row"&gt; {{for (var i = 0; i &lt; list.length; i++ ) { }} &lt;div class="col-4"&gt;list[0].name&lt;/div&gt; {{ } }} </code></pre> <p>This is how it'd be done in PHP below. </p> <p>In short: </p> <pre><code>&lt;div class="row"&gt; &lt;?php $collection = array( 'item1', 'item2', 'item3', 'item4', 'item5', ); for($i = 0; $i &lt; count($collection); $i++ ) : ?&gt; &lt;div class="col-4"&gt; &lt;?php echo $collection[$i] ?&gt; &lt;/div&gt; &lt;?php if(($i + 1) % 3 === 0) :?&gt; &lt;/div&gt; &lt;!-- close row --&gt; &lt;div class="row"&gt;&lt;!-- open new row --&gt; &lt;?php endif ?&gt; &lt;?php endfor ?&gt; &lt;/div&gt; &lt;!-- close final row --&gt; </code></pre> <p>I know it can be done within a controller and pushed back into the DOM within a link function, but that just seems horrible. I'm sure I must be missing something, but conditionally adding the closing div before the opening one is proving tricky for me. </p> <p>P.S. I considered doing the example using Underscore.js, but felt this would be a little more universal. </p>
30,298,025
0
How to use a data attribute from a target div as view param in a PrimeFaces ContextMenu outcome <p>I'm trying to do the following:</p> <ul> <li>From a simple collection of elements...</li> <li>Add a PrimeFaces ContextMenu...</li> <li>Have the first menu option forward to a new page...</li> <li>Pass a data attribute from the selected element as a view param.</li> </ul> <p>It all seems pretty straightforward, until I come to the last step, and I can't seem to find a way to get this to work.</p> <p>e.g.</p> <pre><code> &lt;div class="group" data-group="GRP1"&gt; ... &lt;/div&gt; &lt;div class="group" data-group="GRP2"&gt; ... &lt;/div&gt; &lt;div class="group" data-group="GRP3"&gt; ... &lt;/div&gt; &lt;p:contextMenu targetFilter="div.group"&gt; &lt;p:menuitem value="Edit" outcome="group.xhtml?group=GRP???"/&gt; &lt;/p:contextMenu&gt; </code></pre> <p>The divs are generated HTML and I don't really have much control over those, so probably need to do something with Javascript on the client side.</p> <p>I've tried to get hold of the group from the Javascript side, but I can't see how to bind a function to the beforeShow handler. I can see that if I can register the correct event handler then the PF code will pass me the event (from which I can get the target element and the data attribute):</p> <pre><code> // from PF menu.js if(this.cfg.beforeShow) { var retVal = this.cfg.beforeShow.call(this, e); if(retVal === false) { return; } } </code></pre> <p>But I'm not sure how to access this - if I just use inline event registration then I can only pass Javascript code not a reference to my function:</p> <pre><code> function doBeforeShow(menu, event) { var group = event.target.dataset['group']; } &lt;p:contextMenu targetFilter="div.group" beforeShow="/* this is just executed JS not a bound function */"&gt; </code></pre> <p>Anyway, even if I could get the group from the JS side, I'm not really sure what I'd do with it... probably store it somewhere and attach another handler to the p:menuitem so when it was selected it could modify the outcome before calling it?</p> <p>So I'm stuck! Anyone have any ideas on how I can get this to work?</p> <p>Thanks,</p>
16,231,387
0
Good way to clear nested Maps in Java <pre><code>public class MyCache { AbstractMap&lt;String, AbstractMap&lt;String, Element&gt;&gt; cache = new TreeMap&lt;String, AbstractMap&lt;String, Element&gt;&gt;(); public Boolean putElement(String targetNamespace, Element element) { ... } public void clear() { cache.clear(); } // is it better this way? public void deepClear() { for(AbstractMap&lt;String, Element&gt; innerMap : cache.values()) { innerMap.clear(); } cache.clear(); } } </code></pre> <p>Is it necessary to iterate over the values of the root map and clear all the maps nested in the root first, or is it enough to clear the outermost map? My main question is, if there is any difference in the memory consumption of the JVM between these two methods?</p>
17,010,055
0
<p>William Pugh, one of the authors of "JSR-133: Java Memory Model and Thread Specification" maintains a webpage about the memory model here:</p> <p><a href="http://www.cs.umd.edu/~pugh/java/memoryModel/" rel="nofollow">http://www.cs.umd.edu/~pugh/java/memoryModel/</a></p> <p>The complete JSR-133 can be found here:</p> <p><a href="http://www.cs.umd.edu/~pugh/java/memoryModel/jsr133.pdf" rel="nofollow">http://www.cs.umd.edu/~pugh/java/memoryModel/jsr133.pdf</a></p> <p>Also relevant is the Java Language Specification, Section 17.4 Memory Model:</p> <p><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4" rel="nofollow">http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.4</a></p>
12,326,600
0
How to show an element in Jquery after 1 seconds only if the mouse is still over the element? <p>I'm trying to create a hover-menu inside a gridview like the one of Gmail when you put the mouse over the names in the chatlist. </p> <p>How to show an element in Jquery after 1-2 seconds <strong>only if the mouse is still over the element</strong>?</p> <p>The following is not working properly because if i just move the mouse throughout the list, all the elements will show up (even though with a delay of 1 sec.)</p> <pre><code> $('.label, .popup').hover(function(e) { setTimeout(function() { $(e.target).closest("tr").find(".popup").show(); }, 1000); }, function(e) { setTimeout(function() { $(e.target).closest("tr").find(".popup").hide(); }, 1000); }); &lt;asp:TemplateField&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="label1" CssClass="label" runat="server" Text='&lt;%# Eval("Column1") %&gt;'&gt;&lt;/asp:Label&gt; &lt;asp:Panel runat="server" ID="popup" CssClass="popup" Style="display: none; position: absolute; margin-left: 60px; width: 250px;"&gt; Random text &lt;/asp:Panel&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; </code></pre>
5,639,734
0
<p>Stumbled upon this question and thought I would offer an alternative. If you run into trouble with popup blockers, you can use plain old HTML to launch a url in a new window/tab. You won't have as much control over that is displayed (scrollbars, toolbar, etc), but it works even if javascript is disabled and is 508 compliant:</p> <pre><code>&lt;a href="http://www.google.com/" target="_blank"&gt;Open new window&lt;/a&gt; </code></pre> <p>You can read more about the various target attributes here: <a href="https://developer.mozilla.org/en/HTML/Element/a" rel="nofollow">https://developer.mozilla.org/en/HTML/Element/a</a></p>
3,024,630
0
How does one close an overlay by clicking outside of the overlay? <p>I have a jquery drop down that activates and deactivates when you click the header for the drop down</p> <pre><code>$j('#category_header').click(function() { $j('#category_dropdown').slideToggle("fast"); return false; }); </code></pre> <p>but I want it to also close when I click anywhere on the page that isnt the drop down. How do I go about doing that?</p>
31,784,840
0
Passing an object as parameter return an array in JavaScript <p>I have the following simple code :</p> <pre><code>&lt;td data-title="Authorized Version"&gt; &lt;span ng-bind="table.authorizedVersion.version"&gt;&lt;/span&gt; &lt;/td&gt; &lt;td data-title="Actions" ng-hide="userRole"&gt; &lt;button class="btn btn-default round" ng-click="modal.open('lg','pickKey', table)"&gt;&lt;/button&gt; &lt;/td&gt; </code></pre> <p>When I click on the button, I want to get the table data :</p> <pre><code>modal.open = openModal; function openModal (size, whichModal, data) { console.log(data); } </code></pre> <p>My problem is : </p> <p>table.authorizedVersion is an object. But, in the function, it appears as an empty array.</p> <p>Why is this function converting my object into an array ? </p> <p>Thank you in advance for your assistance.</p>
22,631,969
0
<p>I would add a margin / padding to the TileContainer on the left side, so it uses it's own animations and logic to resize / arrange.</p>
16,035,475
0
Removing items from a dataset that have too few mentions <p>I am beginning <strong>R</strong> user and I have a question about a problem I encountered: </p> <ul> <li>Very large dataset (almost 800k rows) </li> <li>This dataset lists all contributions to a politicians in the 90s in the US </li> </ul> <p>After some data cleaning, I needed to reduce the list to a more manageable size. Since I am interested in contributors who have donated more than once, I have decided to try to limit the size of the dataset like that.</p> <p>The dataset is loaded as "cont"</p> <p>My intention:</p> <ol> <li><p>Map frequencies of mentions:</p> <pre><code>&gt; table(cont$contributor_name) -&gt; FreqCon &gt; subset(FreqCon,Freq&gt;4) -&gt; FMI </code></pre></li> <li><p>Insert an extra column as cont[,43] with name "include" that would say TRUE or FALSE for whether I should subset it</p> <pre><code>for(i in 1:dim(FMI)[1]){ + ifelse(cont[i,11] %in% FMI[,1],cont[i,43] &lt;- TRUE, cont[i,43] &lt;- FALSE) } </code></pre></li> <li><p>Subset the dataset based on <code>cont$include</code></p></li> </ol> <p>I hope that is all relevant information. I am happy to provide more info if needed! Also:<code>cont[,11] = cont$contributor_name</code></p> <p><em>THE PROBLEM</em>: Currently, <strong>R</strong> is working very hard, but does not seem to change anything in the column. I am confused as to what I am doing wrong, since I am not getting any <code>warnings()</code> or Errors.</p> <p>Maybe I am trying to reinvent the wheel so any way of accomplishing what I set out to do would be much appreciated!</p>
39,559,996
0
No matching function (input/output) <p>I am writing a program which works with input/output and I have a problem with two functions in my code: <code>copyText</code> and <code>print</code>. They don't work at all and I can't understand the source of my problem. I will really appreciate any help. Thanks!</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;cctype&gt; using namespace std; void initialize(int&amp;, int[]); void copyText (ifstream&amp;, ofstream&amp;, char&amp;, int[]); void count(char, int[]); void print(ofstream&amp;, int, int[]); int main() { int line; int letter[26]; char ch; ifstream infile; ifstream outfile; infile.open("input.txt"); outfile.open("output.txt"); initialize(line, letter); infile.get(ch); while(infile) { copyText(infile, outfile, ch, letter); line++; infile.get(ch); } print (outfile, line, letter); infile.close(); outfile.close(); return 0; } void initialize(int&amp; loc, int list[]) { loc = 0; for (int i =0; i &lt;26; i++) list[i] = 0; } void copyText(ifstream&amp; in, ofstream&amp; out, char&amp; ch, int list[]) { while (ch != '\n') { out &lt;&lt; ch; count (ch, list); in.get(ch); } out &lt;&lt; ch; } void count(char ch, int list[]) { ch = toupper(ch); int index = static_cast&lt;int&gt;(ch)-static_cast&lt;int&gt;('A'); if (0 &lt;= index &amp;&amp; index &lt; 26) list[index]++; } void print (ofstream&amp; out, int loc, int list[]) { out &lt;&lt; endl&lt;&lt; endl; out &lt;&lt; " The number of lines is "&lt;&lt;loc &lt;&lt;endl; for (int i = 0; i&lt;26; i++) out &lt;&lt; static_cast&lt;char&gt;(i+static_cast&lt;int&gt;('A')) &lt;&lt; "count = " &lt;&lt;list[i] &lt;&lt; endl; } </code></pre>
35,021,162
0
<p><a href="http://developer.android.com/intl/ru/reference/android/widget/TimePicker.html" rel="nofollow">http://developer.android.com/intl/ru/reference/android/widget/TimePicker.html</a> I you look here you will not find such methods or parameters.</p> <p>Futher more, If you find a bug to setup this value, I do not, based on my experiance, really recommend to use something exapt default behavour. Because of there are a lot of different implementations for TimePicker. Use the default behaviour or do nothing.</p> <p>I only solutions: is to write your own timepicker using numberpicker, etc.</p>