pid
int64
2.28k
41.1M
label
int64
0
1
text
stringlengths
1
28.3k
12,685,885
0
InnoDB frequently updated table running slow <p>I have a very simple table to track users activity. It's structure is as following:</p> <pre><code>userId appId lastActivity PRIMARY(userId, appId) </code></pre> <p>Table allows to track, if user is active within a specific application. It's updated once a minute for each user and read as frequently to count number of users online within a specific application.</p> <p>Lately I've noticed, that updates took a while to perform:</p> <pre><code>2012-10-01 16:49:10 - WARN --&gt; Heavy query; array ( 'caller' =&gt; 'updateActivity', 'query' =&gt; 'INSERT INTO user_activity VALUES(4953, 1, 1349095750) ON DUPLICATE KEY UPDATE lastActivity = 1349095750', 'elapsed' =&gt; 0.134618, ) 2012-10-01 18:26:06 - WARN --&gt; Heavy query; array ( 'caller' =&gt; 'updateActivity', 'query' =&gt; 'INSERT INTO user_activity VALUES(4533, 1, 1349101566) ON DUPLICATE KEY UPDATE lastActivity = 1349101566', 'elapsed' =&gt; 0.581776, ) 2012-10-01 18:27:16 - WARN --&gt; Heavy query; array ( 'caller' =&gt; 'updateActivity', 'query' =&gt; 'INSERT INTO user_activity VALUES(5590, 1, 1349101636) ON DUPLICATE KEY UPDATE lastActivity = 1349101636', 'elapsed' =&gt; 0.351321, ) 2012-10-01 20:54:32 - WARN --&gt; Heavy query; array ( 'caller' =&gt; 'updateActivity', 'query' =&gt; 'INSERT INTO user_activity VALUES(3726, 1, 1349110472) ON DUPLICATE KEY UPDATE lastActivity = 1349110472', 'elapsed' =&gt; 0.758706, ) </code></pre> <p>Table uses InnoDB as storage engine.</p> <p><strong>My questions</strong></p> <ol> <li><p>Is there any problem at all?</p></li> <li><p>Is there any problem in my design?</p></li> <li><p>Where to start to find performace problems in this specific situation?</p></li> </ol>
6,546,606
0
XJC non-transient non-serializable instance field data <p>After generating java classes I received:</p> <pre><code>public class myClass { @XmlElement(name = "Data", required = true) @XmlSchemaType(name = "date") protected XMLGregorianCalendar data; @XmlElement(name = "Time", required = true) protected XMLGregorianCalendar time; ......... </code></pre> <p>FindBugs warns that myClass defines non-transient non-serializable instance field data. Is it warning acceptable or need to fix? Thanks.</p>
2,802,948
0
How to make an AJAX call immediately on document loading <p>I want to execute an ajax call as soon as a document is loaded. What I am doing is loading a string that contains data that I will use for an autocomplete feature. This is what I have done, but it is not calling the servlet. </p> <p>I have removed the calls to the various JS scripts to make it clearer. I have done several similar AJAX calls in my code but usually triggered by a click event, I am not sure what the syntax for doing it as soon as the document loads, but I thought this would be it (but it's not):</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;script src="../js/jquery.js" type="text/javascript"&gt; &lt;/script&gt; &lt;link rel="stylesheet" href="../css/styles.css" type="text/css"&gt; &lt;link rel="stylesheet" href="../css/jquery.autocomplete.css" type="text/css"&gt; &lt;script type="text/javascript" src="../js/jquery.bgiframe.min.js"&gt; &lt;/script&gt; &lt;script type="text/javascript" src="../js/jquery.dimensions.js"&gt; &lt;/script&gt; &lt;script type="text/javascript" src="../js/jquery.autocomplete.js"&gt; &lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $.ajax({ type: "GET", url: "AutoComplete", dataType: 'json', data: queryString, success: function(data) { var dataArray = data; alert(dataArray); } }); $("#example").autocomplete(dataArray); }); &lt;/script&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; API Reference: &lt;form&gt;&lt;input id="example"&gt; (try "C" or "E")&lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><b>EDIT:</b> my code now looks more like Karim's:</p> <pre><code>$(document).ready(function(){ $.ajax({ type: "GET", url: "../AutoComplete", success: function(data) { $("#example").autocomplete(data); } }); }); </code></pre> <p>Nonetheless the autocomplete still doesn't work (admittedly another question altogether, so I will also post another question so it has an appropriate title).</p> <p>My variable "data" that is being sent back looks like ... "Manuscript|Text|Information Object|Basketball|Ball|Sporting Equipment|Tarantula".split("|");</p> <p>If I do </p> <pre><code>var dataArray = "Manuscript|Text|Information Object|Basketball|Ball|Sporting Equipment|Tarantula".split("|"); </code></pre> <p>and then</p> <pre><code>$("#example").autocomplete(dataArray); </code></pre> <p>It all works fine, but when I get the value of dataArray from the server it doesn't.</p>
17,693,635
0
Tie Object's visibility to another object's visibility <p>I'm looking for a way to do what the title says. For example there are two DOM-elements a and b, where a is visible when b is visible and hidden, when b is hidden.</p> <p>Is there a way to do this with jquery?</p> <p>Thanks in advance!</p> <p><strong>Since there seem to be some misunderstandings of what I'm looking for, here is a better description</strong></p> <p>Imagine a website with a variety of DOM-elements. On the left and on the right site are a black and a red dot. The visibility of the black dot is changed via a button-click-callback. In my case, I have no access to this function, so I can't just add <code>$('#red_dot').hide()</code> to it. In this scenario I need to find a way to have the red dot show, when the black dot is shown and hide as soon as the black dot is hidden.</p>
10,606,234
0
Subversion on Perforce Projects <p>I have a project that's currently in a Perforce repository. Unfortunately, due to some testing restrictions, I have a test machine (private build of something that resembles linux) that, for whatever reason, does not run Perforce, but is able to run subversion. Is it possible, or a good idea, to load everything into subversion while it is still tied into Perforce?</p> <p>This is a VS2010 project, and I know that VS2010 will see the source control bindings that Perforce has. Will putting this into subversion screw this up?</p> <p>Yes I know for testing all I have to do is copy the compiled build, however we are also looking at making changes on the fly, so we do want to do some code editing on the target machine as well.</p>
28,659,697
0
performance on mantle, dx and ogl <p>So recently with all the commotion on the new API for 3d graphics which supposedly accelerate graphics by a huge amount I am wondering why this hasn't been done before. What is so different between the old way and the new way?</p> <p>I would like to know how it is achieved and maybe even an overview how it works from the gpu to the driver to the API of DX or OGL.</p>
28,747,823
0
<p>A comparison of the M2M protocols based on characteristics, like any other comparisons, should be made in a certain context. In this case, the context refers to the domain or the application domain you are using for building the comparison. </p> <p>An application for a certain domain usually has a set of requirements that need to be met. Building a list of common requirements is a sensible thing to do. Not only it will improve the structure of the article, but it will also offer the possibility to expand/improve the article as new requirements are being discovered. By analysing these requirements you can find some fine-grained criteria that you can choose to discuss.</p> <p><strong>Functional requirements</strong></p> <ol> <li>Interoperability</li> <li>Interface for: device - gateway, device - network application server, device - device</li> <li>Protocol load: information volume, connectionless/connection- oriented</li> <li>Routing capability</li> <li>IP based/non IP based</li> <li>Communication patterns</li> <li>Resource discovery</li> <li>Resource management</li> <li>Stateful/Stateless</li> </ol> <p><strong>Non-functional requirements</strong></p> <ol> <li>Scalability</li> <li>Security</li> <li>Privacy</li> <li>Lightweight</li> <li>Real-time</li> <li>Expandability</li> <li>Usability</li> <li>Openness</li> <li>Reliability</li> </ol>
22,010,093
0
How do I install the JMF 2.1.1e [2014] <p>So I Downloaded JMF from here:<a href="http://www.oracle.com/technetwork/java/javase/download-142937.html" rel="nofollow">http://www.oracle.com/technetwork/java/javase/download-142937.html</a> installed it(There was only an installation wizard version).</p> <p>Then what am I meant to do? java had no docs on it the documentation that came with the download just said in a nutshell run the wizard.</p> <p>Is it just meant to work like some kind of magical java package? I launched eclipses to see If I could use the javax.media.*; package but nope it still does not exist.</p> <p>I have read many threads on this but they are from 2013 and don't really help.. As I am sure it was different then.</p> <p>Is eclipse missing something.. Is anyone able to import the JMF packages in eclipse?</p> <p>Tell me its not just a myth and infact one can use the new JMF in eclipse.</p> <p>Where should the packadge be installed it once again siad nothing in the documentation about if it should go in a jre bin or jdk bin...</p> <p>I feel like the underpants gnomes from south park. RunWizard --> ? --> Profit. Like I am missing something important but I cant find that peice of information anywhere.</p>
17,021,057
0
Char equivalent for Tabstop <p>I want to split a string with Tabstops. What is the correct char[] equivalent for usage with </p> <pre><code>Split.(char[] x, int i) </code></pre>
38,593,222
0
Create Custom grid css depending on Array Length <p>I have array with data <code>[1,2,3,4,5,6,7]</code> and I want to show 2 items on 1 line</p> <pre><code>&lt;div class=row&gt; &lt;div&gt;data1&lt;/div&gt; &lt;div&gt;data2&lt;/div&gt; &lt;/div&gt; &lt;div class=row&gt; &lt;div&gt;data3&lt;/div&gt; ... </code></pre> <p>So I want do it with JS. As I understand I need smth like <code>[[1,2],[3,4],[5,6],[7]]</code>, but cant understand how to make it. It'll be great if someone did it before and can help me.</p>
12,656,879
0
<p>I did the same as in this <a href="http://stackoverflow.com/a/6401135/262462">http://stackoverflow.com/a/6401135/262462</a> but edited this part</p> <pre><code>function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { // do this or they'll all go to jpeg $image_type=$this-&gt;image_type; </code></pre> <p>to this</p> <pre><code>function save($filename, $image_type="original", $compression=75, $permissions=null) { if ($image_type=="original") $image_type=$this-&gt;image_type; </code></pre>
7,230,479
0
Convert header of email to another encoding in ActionMailer in Ruby <p>I have a website written on ruby 1.8.5 and rails 1.2.6. </p> <p>There is a feedback page.</p> <p>So.</p> <p>i've got a model class:</p> <pre><code>class Feedback::Notify &lt; ActionMailer::Base def answer_for_managers(question) recipients [email protected] from "[email protected]" subject "Обратная связь: ответ на вопрос" body "question" =&gt; question content_type "text/html" end end </code></pre> <p>Then i have a controller:</p> <pre><code>class Feedback::QuestionController &lt; Office::BaseController def update Feedback::Notify.deliver_answer_for_managers(@question) end end </code></pre> <p>The problem is when a message is sent its subject looks like: =?utf-8?Q?=d0=9e=d0=b1=d1=80=d0=b0=d1=82=d0=bd=d0=b0=d1=8f_=d1=81=d0=b2=d1=8f=d0=b7=d1=8c=3a_=d0=a1=d0=be=d1=82=d1=80=d1=83=d0=b4=d0=bd=d0=b8=d0=ba_=d0=be=d1=82=d0=b2=d0=b5=d1=82=d0=b8=d0=bb_=d0=bd=d0=b0_=d0=b2=d0=be=d0=bf=d1=80=d0=be=d1=81_=d0=ba=d0=bb=d0=b8=d0=b5=d0=bd=d1=82=d0=b0_=23=35=36_=d0=be=d1=82_=32=36=2e=30=38=2e=32=30=31=31_=31=31=3a=33=33?=</p> <p>so it's url-encoded.</p> <p>Is there any way to prevent converting subject text to url-encoding? All files are in UTF8 encoding</p>
30,859,614
0
<blockquote> <p>I want to start web-service but without web-server</p> </blockquote> <p>If it is just a plain HTML without back-end but not a web-service, then you can create a shared folder and open it as a file from your network. HTML and front-end JS scripts will work well. However, the link will be like:</p> <pre><code>file:\\COMPUTER-001\Camera\CameraCapture.html </code></pre> <p>If it is ok for you, then you can easily do this without web-server. </p> <p>You surely cannot make it work this way without any HTTP-server:</p> <p><a href="http://COMPUTER-001/CameraCapture.html" rel="nofollow">http://COMPUTER-001/CameraCapture.html</a></p> <p>Is it worth it?<br> Install a simple web-server, you even won't need to configure it if a single HTML file is everything you need.</p>
5,458,039
0
<p>I think this line is the problem:</p> <pre><code>&lt;td align="left" valign="top"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;img alt="" id="asd" onclick="" style="cursor: pointer" src="" /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;/td&gt; </code></pre> <p>Remove the span end tag that is not open.</p> <pre><code>&lt;td align="left" valign="top"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;img alt="" id="asd" style="cursor: pointer" src="" /&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;/td&gt; </code></pre>
3,025,612
0
<p>I upgraded my cygwin installation at home and ran into a similar problem (though maybe not the exact same problem -- the perl debugger still responds to my input but does not display my input, and fubars my input even after I quit the debugger). In the meantime while I figure what is going on, my workaround is to fire up xemacs, launch a shell (<code>M-x shell</code>), and run the perl debugger from the emacs buffer.</p> <p>If this works for you, then there is something funky going on with your cygwin terminal settings. If your debugger hangs even in an emacs buffer, then something else funky is going on but I have no idea what it could be.</p>
22,532,945
0
<p>elaborating on my comment, the only way the solver learns what the constraints are is by going 'out of bounds' , so you should very much expect out of bounds values and handle them gracefully.</p> <p>A typical way to do this is:</p> <pre><code>G(1) = X(1) * x(2) - x(3) ** 2 if(g(1).gt.0)then f=log(g(1)) else f=-10.e30 endif </code></pre> <p>It may not matter what you return in the out of bounds case but check the docs for the imsl routine to see if it says something about that.</p> <p>just by the way, note since you hard coded <code>active(1)=.true.</code> there is no need for the <code>if(active(1))..</code> construct.</p>
18,362,097
0
<p>I think you're trying to construct an array consisting of the names of all zero-length files and directories in <code>$DIR</code>. If so, you can do it like this:</p> <pre><code>mapfile -t ZERO_LENGTH &lt; &lt;(find "$DIR" -maxdepth 1 -size 0) </code></pre> <p>(Add <code>-type f</code> to the find command if you're only interested in regular files.)</p> <p>This sort of solution is almost always better than trying to parse <code>ls</code> output.</p> <p>The use of process substitution (<code>&lt; &lt;(...)</code>) rather than piping (<code>... |</code>) is important, because it means that the shell variable will be set in the current shell, not in an ephimeral subshell.</p>
6,787,059
0
<p>Click on the small triangle in the upper right corner of the problems view and select "Configure Contents". In that dialog check "Show all items" and uncheck "Use item limits" to show all warnings.</p>
19,489,963
0
<p>You need to define the table the function returns, and insert into it, rather than selecting.</p> <pre><code>CREATE FUNCTION dbo.get_numseq (@max_rows AS BIGINT,@min_rows AS BIGINT) RETURNS @t TABLE (n int) AS begin -- returns up to 4,294,967,296 records ;WITH lv0 AS (SELECT 0 AS g UNION ALL SELECT 0), lv1 AS (SELECT 0 AS g FROM lv0 AS a CROSS JOIN lv0 AS b), lv2 AS (SELECT 0 AS g FROM lv1 AS a CROSS JOIN lv1 AS b), lv3 AS (SELECT 0 AS g FROM lv2 AS a CROSS JOIN lv2 AS b), lv4 AS (SELECT 0 AS g FROM lv3 AS a CROSS JOIN lv3 AS b), lv5 AS (SELECT 0 AS g FROM lv4 AS a CROSS JOIN lv4 AS b), Nums AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS n FROM lv5) insert @t SELECT n FROM Nums where n &gt;= @min_rows and n &lt;= @max_rows ORDER BY n return end </code></pre> <p>See <a href="http://technet.microsoft.com/en-us/library/ms191165(v=sql.105).aspx" rel="nofollow">http://technet.microsoft.com/en-us/library/ms191165(v=sql.105).aspx</a></p>
10,001,439
0
<p>If your frequency is not exactly an integer value, then this line:</p> <pre><code>phase = phase - (2 * M_PI * freq); </code></pre> <p>will adjust and rotate the phase by an amount not equal to 2pi, thus producing a discontinuity.</p>
14,007,443
0
android sdk realtime audio record <p>I use this code to record and play back recorded audio in real time using the <a href="http://developer.android.com/reference/android/media/AudioTrack.html" rel="nofollow">AudioTrack</a> and <a href="http://developer.android.com/reference/android/media/AudioRecord.html" rel="nofollow">AudioRecord</a></p> <pre><code>package com.example.audiotrack; import android.app.Activity; import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioRecord; import android.media.AudioTrack; import android.media.MediaRecorder; import android.os.Bundle; import android.util.Log; public class MainActivity extends Activity { private int freq = 8000; private AudioRecord audioRecord = null; private Thread Rthread = null; private AudioManager audioManager = null; private AudioTrack audioTrack = null; byte[] buffer = new byte[freq]; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO); final int bufferSize = AudioRecord.getMinBufferSize(freq, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT); audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, freq, AudioFormat.CHANNEL_CONFIGURATION_MONO, MediaRecorder.AudioEncoder.AMR_NB, bufferSize); audioTrack = new AudioTrack(AudioManager.ROUTE_HEADSET, freq, AudioFormat.CHANNEL_CONFIGURATION_MONO, MediaRecorder.AudioEncoder.AMR_NB, bufferSize, AudioTrack.MODE_STREAM); audioTrack.setPlaybackRate(freq); final byte[] buffer = new byte[bufferSize]; audioRecord.startRecording(); Log.i("info", "Audio Recording started"); audioTrack.play(); Log.i("info", "Audio Playing started"); Rthread = new Thread(new Runnable() { public void run() { while (true) { try { audioRecord.read(buffer, 0, bufferSize); audioTrack.write(buffer, 0, buffer.length); } catch (Throwable t) { Log.e("Error", "Read write failed"); t.printStackTrace(); } } } }); Rthread.start(); } } </code></pre> <p>My problem : </p> <p>1.the quality of audio is bad</p> <p>2.when I try different frequencies the app crashes</p>
4,317,501
0
<p>I am not able to see your images (blocked!) so I'll just try to describe the "correct" design. If a player living in a zone doesn't necessarily mean they own it, you should have four tables: </p> <pre><code>PLAYER (playerid, &lt;other fields&gt;) ZONE (zoneid, &lt;other fields&gt; PLAYER_ZONE(playerid, lives_in_zoneid) ZONE_OWNER (zoneid, owner_playerid) </code></pre> <p>Otherwise three tables would suffice.</p>
11,965,188
0
<p>PHP will send a chunked response by default if headers are sent and no <code>Content-Length</code> header was specified. If you're familiar with the HTTP spec, this is the only logical thing to do since the client on the other end needs to know when the HTTP message you're sending ends so it can stop reading.</p> <p>If you want to do this manually, you need to ...</p> <ol> <li>Send the appropriate headers yourself and call <code>flush()</code></li> <li>Manually output the chunked HTTP message</li> </ol> <p>So you might do something like the following. The idea is that you need to manually send your own headers and manually chunk your own message. If you simply don't send a <code>Content-Length</code> header, however, PHP will send a chunked message for you by default.</p> <pre><code>header("Transfer-encoding: chunked"); header("Trailer: X-My-Trailer-Header"); flush(); echo dechex(strlen($myChunk)) . "\r\n"; echo $myChunk; echo "\r\n"; flush(); echo "0\r\n"; flush(); echo "X-My-Trailer-Header: some-value\r\n"; flush(); </code></pre>
27,624,169
0
<p>Have you considered using a PerformanceCounter <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter(v=vs.110).aspx</a>? You just count the number of objects created, and the performance counter automatically calculates the average "speed" (I think you mean the rate at which objects are created, or objects per second).</p>
3,422,989
0
<p>I can't reproduce the issue. I used the following test class:</p> <pre><code>package com.stackoverflow.q3421918; public class Hello { public static void main( String[] args ) { System.out.println( args[0] + " " + args[1] ); } } </code></pre> <p>And the following pom.xml:</p> <pre><code>&lt;project&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;com.stackoverflow.q3421918&lt;/groupId&gt; &lt;artifactId&gt;Q3421918&lt;/artifactId&gt; &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt; &lt;!-- this was a test for a workaround --&gt; &lt;properties&gt; &lt;myprop&gt;${langdir}&lt;/myprop&gt; &lt;/properties&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;junit&lt;/groupId&gt; &lt;artifactId&gt;junit&lt;/artifactId&gt; &lt;version&gt;3.8.1&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt; &lt;version&gt;1.2&lt;/version&gt; &lt;executions&gt; &lt;execution&gt; &lt;phase&gt;test&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;java&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;configuration&gt; &lt;mainClass&gt;com.stackoverflow.q3421918.Hello&lt;/mainClass&gt; &lt;arguments&gt; &lt;argument&gt;${myprop}&lt;/argument&gt; &lt;argument&gt;${langdir}&lt;/argument&gt; &lt;/arguments&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/project&gt; </code></pre> <p>And here is the output I get:</p> <pre> $ mvn clean package -Dlangdir=C:/somedir [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Q3421918 [INFO] task-segment: [clean, package] [INFO] ------------------------------------------------------------------------ ... [INFO] Preparing exec:java [WARNING] Removing: java from forked lifecycle, to prevent recursive invocation. [INFO] No goals needed for project - skipping [INFO] [exec:java {execution: default}] Hello c:/somedir c:/somedir [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ ... </pre> <p>Tested with Maven 2.2.1.</p>
31,905,071
0
<p>Wasn't sure what you meant by a 'dropdownList'. For this example I used a ComboBox.</p> <pre><code> Dim StartTime As DateTime = #12:00:00 AM# 'load combo box Do StartTimeDDL.Items.Add(StartTime.ToString("hh:mm tt")) StartTime = StartTime.AddMinutes(30) Loop While StartTime.TimeOfDay.TotalDays &gt; 0 Dim selectTime As DateTime = #2:10:12 PM# 'TEST find this &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; 'round time to 30 minutes Dim numSecs As Integer = (CInt(selectTime.TimeOfDay.TotalSeconds) \ 1800) * 1800 'the OP said 'les say current time is 12:00:00 AM than I was to select 12:30 AM" 'so.... numSecs += 1800 'round up 30 minutes ???????? 'create 'find' Dim ts As New TimeSpan(0, 0, numSecs) Dim findDate As New DateTime(ts.Ticks) StartTimeDDL.SelectedIndex = StartTimeDDL.FindStringExact(findDate.ToString("hh:mm tt")) </code></pre>
34,865,004
0
<p>If you want to select a Node by default, you can do it by setting the node's <code>selected</code> property to <code>true</code> when you initialise the dataSource. Another option would be to call the TreeView <code>select()</code> method after the TreeView completed the data loading. (See the <a href="http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#events-dataBound" rel="nofollow">dataBound</a> event for more details since the TreeView initialization may be completed before the data gets fully loaded)</p> <p>For the selection, there's a <a href="http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#methods-findByUid" rel="nofollow">findByUid</a> method that can be used in the TreeView. The <code>findByUid</code> function will return the jQuery nodes matching the specified <code>uid</code>. You can then use the results to select a node programatically by using the <code>select()</code> method:</p> <pre><code>var dataItem = treeview.dataSource.get(10); var node = treeview.findByUid(dataItem.uid); treeview.select(node); </code></pre>
7,127,674
0
start file upload upon selection <p>Normally, to upload a file, it would be two-steps process - select a file and then confirm upload. I am working on uploading profile picture. Since profile pic is usually small, I want to reduce mouse-clicks for my users by making the file upload to start upon file selection. Please suggest good, and perhaps common, ways to achieve this (I would also like to learn their pitfalls, if any). Thanks.</p>
3,785,697
0
NSString range of string at occurrence <p>i'm trying to build a function that will tell me the range of a string at an occurrence.</p> <p>For example if I had the string "hello, hello, hello", I want to know the range of hello at it's, lets say, third occurrence.</p> <p>I've tried building this simple function, but it doesn't work.</p> <p>Note - the top functions were constructed at an earlier date and work fine.</p> <p>Any help appreciated.</p> <pre><code>- (NSString *)stringByTrimmingString:(NSString *)stringToTrim toChar:(NSUInteger)toCharacterIndex { if (toCharacterIndex &gt; [stringToTrim length]) return @""; NSString *devString = [[[NSString alloc] init] autorelease]; for (int i = 0; i &lt;= toCharacterIndex; i++) { devString = [NSString stringWithFormat:@"%@%@", devString, [NSString stringWithFormat:@"%c", [stringToTrim characterAtIndex:(i-1)]]]; } return devString; [devString release]; } - (NSString *)stringByTrimmingString:(NSString *)stringToTrim fromChar:(NSUInteger)fromCharacterIndex { if (fromCharacterIndex &gt; [stringToTrim length]) return @""; NSString *devString = [[[NSString alloc] init] autorelease]; for (int i = (fromCharacterIndex+1); i &lt;= [stringToTrim length]; i++) { devString = [NSString stringWithFormat:@"%@%@", devString, [NSString stringWithFormat:@"%c", [stringToTrim characterAtIndex:(i-1)]]]; } return devString; [devString release]; } - (NSRange)rangeOfString:(NSString *)substring inString:(NSString *)string atOccurence:(int)occurence { NSString *trimmedString = [inString copy]; //We start with the whole string. NSUInteger len, loc, oldLength; len = 0; loc = 0; NSRange tempRange = [string rangeOfString:substring]; len = tempRange.length; loc = tempRange.location; for (int i = 0; i != occurence; i++) { NSUInteger endOfWord = len+loc; trimmedString = [self stringByTrimmingString:trimmedString fromChar:endOfWord]; oldLength += [[self stringByTrimmingString:trimmedString toChar:endOfWord] length]; NSRange tmp = [trimmedString rangeOfString:substring]; len = tmp.length; loc = tmp.location + oldLength; } NSRange returnRange = NSMakeRange(loc, len); return returnRange; } </code></pre>
31,946,302
0
Background image on Phonegap causes incredible slowness? <p>So after much frustration, I finally pin-pointed the problem. The following causes severe decline in speed in my phonegap app:</p> <pre><code>body.default { background: #000000 url(../img/background.jpg) no-repeat center top fixed; background-size: cover; } </code></pre> <p>The image was 1500 x 1500 pixels and about 350Kb. I optimized it a bit and decreased the dimensions to 1000 x 1000. This resulted in a final size of 106Kb. </p> <p>The problem is, even when I make it smaller like this, it still slows down the app considerably. However if I have this:</p> <pre><code>body.default { background: none; background-size: cover; } </code></pre> <p>Then the speed is nice and fast. So I know the background is causing the slowness.</p> <p>What can I do to still show a good quality as the background, without killing performance?</p> <p><strong>UPDATE</strong></p> <p>I've managed to get an "ok" result if I decrease the image size to 36 kb. Of course, then I loose a lot of the quality, but it has an overlay, so it's not that noticeable. However, I think that it might be background-size: cover, that might be inefficient, but I haven't tested that yet. I will keep trying...</p>
19,980,418
0
<p>This will return true for elements that are currently in the document, and selectors which match elements in the document.</p> <pre><code>function isInDoc(sel) { var $sel = jQuery(sel); return $sel.length &amp;&amp; jQuery.contains(document.documentElement, $sel[0]); } </code></pre>
573,548
0
<p>The only 'attack' you are addressing through email confirmation, is registering new accounts using random email addresses.</p> <p>IOW, if you leave that step out, an 'attacker' could:</p> <ol> <li>register accounts using just random gibberish addresses</li> <li>register accounts using other people's addresses</li> </ol> <p>Fortunately, in most applications, such an attack isn't very destructive. It may help the attacker forge someone else's identity in a social networking app, or make life <em>slightly</em> easier for a spambot, or it could be used just to annoy the legitimate owner of an email address -- but that's about it.</p> <p>I'd say keep the registration requirement just in case, but scrap the two-step process (let the users create username+password right away).</p>
38,547,098
0
<p>I disabled Javascript and visited <a href="https://www.searchiqs.com/nybro/" rel="nofollow noreferrer">https://www.searchiqs.com/nybro/</a> and the form looks like this:</p> <p><a href="https://i.stack.imgur.com/U8GZf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U8GZf.png" alt="enter image description here"></a> </p> <p>As you can see the <em>Log In</em> and <em>Log In as Guest</em> buttons are disabled. This will make it impossible for Mechanize to work because it can not process Javascript and you won't be able to submit the form. </p> <p>For this kind of problems you can use Selenium, that will simulate a full Browser with the disadvantage of being slower than Mechanize.</p> <p>This code should log you in using Selenium:</p> <pre><code>from selenium import webdriver from selenium.webdriver.common.keys import Keys usr = "" pwd = "" driver = webdriver.Firefox() driver.get("https://www.searchiqs.com/nybro/") assert "IQS" in driver.title elem = driver.find_element_by_id("txtUserID") elem.send_keys(usr) elem = driver.find_element_by_id("txtPassword") elem.send_keys(pwd) elem.send_keys(Keys.RETURN) </code></pre>
39,248,920
0
missing parameter #2 in call error in CGRectIntersectsRect <p>I am writing a small game in swift, in which a boat has to go around obstacles. However, I keep getting this "missing argument for parameter #2 in call" error in CGRectInersectsRect. I have checked how to call it in the directory, and am calling it correctly. What is the issue with my code?. Here it is:</p> <pre><code> if (CGRectIntersectsRect(boat: CGRect, obstacleImageView: CGRect)) { endGame() } } </code></pre>
32,072,295
0
How work jquery ui tabs using option selected <p>Is there a way to use option selected as Tab selector in <a href="https://jqueryui.com/tabs/" rel="nofollow">Jquery ui tabs</a>. I use Javascript to make select options looks like standard tab selectors but couldn`t inject to jquery tabs to replace original HTML lists selectors.</p> <pre><code>&lt;div id="tabs"&gt; &lt;select class="feature-select"&gt; &lt;option rel="#tab-1" selected="" value=""&gt;Tab 1&lt;/option&gt; &lt;option rel="#tab-2" value=""&gt;Tab 2&lt;/option&gt; &lt;/select&gt; &lt;div id="tab-1"&gt; &lt;p&gt;Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.&lt;/p&gt; &lt;/div&gt; &lt;div id="tab-2"&gt; &lt;p&gt;Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>JSFiddle: <a href="http://jsfiddle.net/0e2cxeL2/" rel="nofollow">http://jsfiddle.net/0e2cxeL2/</a></p>
4,815,002
0
ASP.NET 4 routing question <p>I am trying to do the following in my Global.asax file:</p> <p>At the moment i have to define my route like this:</p> <pre><code>routes.MapPageRoute( "ViewPage", "pages/{slug}", "~/viewpage.aspx", false ); </code></pre> <p>Notice the word pages before the <code>{slug}</code></p> <p>Now if i define it like this:</p> <pre><code>routes.MapPageRoute ( "ViewPage", "{slug}", "~/viewpage.aspx", false ); </code></pre> <p>It does not work.</p> <p>My CSS and JS files wont load, i get a 404.</p> <p>But, if i do this:</p> <pre><code>routes.MapPageRoute ( "ContactPage", "contact", "~/contact.aspx", false ); </code></pre> <p>It works fine??</p> <p>Basically i want my urls to look like this:</p> <p><code>example.com/contact</code> or <code>example.com/about-us</code> and it is all served dynamically from the database based on the {slug}.</p> <p>Can anyone help?</p>
34,642,083
0
Want to change the default wrapping behavior of char* in swig java <p>So there's this line in the swig documentation</p> <blockquote> <p>When <code>char *</code> members of a structure are wrapped, the contents are assumed to be dynamically allocated using malloc or new (depending on whether or not SWIG is run with the -c++ option). When the structure member is set, the old contents will be released and a new value created.</p> </blockquote> <p>I don't want the old contents to be released from memory because I'm using some sort of <code>char*</code> buffer, and I also need the default setter. I can use the <code>%ignore &lt;field&gt;</code> to overwrite the getter but then I'll lose the default setter. Can someone please help? Thanks.</p>
26,378,441
0
<p>Try with this:</p> <pre><code>RAISERROR('your message here',16,1) </code></pre>
8,079,775
1
Is it possible to open a file in shared mode without changing the file handler? <p>In Python I open a temporary file for write by using <a href="http://docs.python.org/library/tempfile.html" rel="nofollow"><code>tempfile.mkstemp</code></a> in order to be sure that the file is destroyed when released (even if application crashes).</p> <p>Now I need to pass this file to another application but this application is not going to be able to open the file as long the file is opened for write.</p> <p>Can I change the access mode or reopen the file without changing the file handle in order to prevent it from being deleted too soon?</p> <p>Update: opening the file in read mode does not solve the problem, the file must be opened in <code>shared</code> mode.</p>
17,311,044
0
<p>The true C99 way to do this is to have:</p> <pre><code>int f(int p[static 4]) { p[0] = 1; p[1] = 2; p[2] = 3; p[3] = 4; return c; } </code></pre> <p>The <code>static 4</code> inside the square brackets indicates to the compiler that the function expects an array of <em>at least</em> 4 elements. clang will issue a warning if it knows at compile-time that the value you are passing to <code>f</code> doesn't contain at least 4 elements. GCC may warn too but I don't use this compiler often.</p>
33,155,492
0
<p>Here is a solution which I don't recommand but If you want to use <code>DbContext.Database</code>, here it is:</p> <pre><code>using(var db = new MyDbContext(connectionString)) { db.Database.ExecuteSqlCommand("CREATE PROCEDURE MyProcedure ... END;"); var command = "EXEC MyProcedure;"; IEnumerable&lt;Customer&gt; customers = db.Database.SqlQuery&lt;Customer&gt;(command, null); } </code></pre>
10,429,570
0
Can't install opencv from source <p>It's OpenCV-2.4.0</p> <pre><code>cd opencv mkdir release cd release cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON .. make </code></pre> <p>Error:</p> <pre><code>In file included from OpenCV-2.4.0/modules/core/src/system.cpp:460: OpenCV-2.4.0/release/modules/core/version_string.inc:35:1: warning: missing terminating " character In file included from OpenCV-2.4.0/modules/core/src/system.cpp:460: OpenCV-2.4.0/release/modules/core/version_string.inc:35: error: missing terminating " character OpenCV-2.4.0/release/modules/core/version_string.inc:36:11: error: too many decimal points in number OpenCV-2.4.0/release/modules/core/version_string.inc:36:29: error: invalid suffix "st" on integer constant OpenCV-2.4.0/release/modules/core/version_string.inc:40:29: warning: character constant too long for its type OpenCV-2.4.0/release/modules/core/version_string.inc:57: error: stray ‘@’ in program OpenCV-2.4.0/release/modules/core/version_string.inc:57: error: stray ‘@’ in program OpenCV-2.4.0/release/modules/core/version_string.inc:68:10: error: #include expects "FILENAME" or &lt;FILENAME&gt; OpenCV-2.4.0/release/modules/core/version_string.inc:71: error: stray ‘\’ in program OpenCV-2.4.0/release/modules/core/version_string.inc:71:9: warning: missing terminating " character OpenCV-2.4.0/release/modules/core/version_string.inc:71: error: missing terminating " character OpenCV-2.4.0/release/modules/core/version_string.inc:74:23: warning: missing terminating " character OpenCV-2.4.0/release/modules/core/version_string.inc:1515: error: stray ‘\’ in program OpenCV-2.4.0/release/modules/core/version_string.inc:1515:4: warning: missing terminating " character OpenCV-2.4.0/release/modules/core/version_string.inc:1515: error: missing terminating " character OpenCV-2.4.0/release/modules/core/version_string.inc: In function ‘const std::string&amp; cv::getBuildInformation()’: OpenCV-2.4.0/release/modules/core/version_string.inc:36: error: expected ‘,’ or ‘;’ before ‘version’ OpenCV-2.4.0/release/modules/core/version_string.inc:138: error: ‘z_stream’ was not declared in this scope OpenCV-2.4.0/release/modules/core/version_string.inc:140: error: expected ‘;’ before ‘typedef’ OpenCV-2.4.0/release/modules/core/version_string.inc:161: error: ‘gz_header’ was not declared in this scope OpenCV-2.4.0/release/modules/core/version_string.inc:163: error: expected ‘;’ before ‘typedef’ OpenCV-2.4.0/release/modules/core/version_string.inc:1505: error: ‘ZEXTERN’ was not declared in this scope OpenCV-2.4.0/release/modules/core/version_string.inc:1505: error: expected ‘;’ before ‘const’ OpenCV-2.4.0/release/modules/core/version_string.inc:1511: warning: no return statement in function returning non-void OpenCV-2.4.0/release/modules/core/version_string.inc: At global scope: OpenCV-2.4.0/release/modules/core/version_string.inc:1515: error: expected unqualified-id before ‘)’ token OpenCV-2.4.0/modules/core/src/system.cpp:462: error: expected unqualified-id before ‘return’ OpenCV-2.4.0/modules/core/src/system.cpp:465: error: ‘string’ does not name a type OpenCV-2.4.0/modules/core/src/system.cpp:474: error: ‘string’ does not name a type OpenCV-2.4.0/modules/core/src/system.cpp:503: error: ISO C++ forbids declaration of ‘Exception’ with no type OpenCV-2.4.0/modules/core/src/system.cpp:503: error: expected ‘,’ or ‘...’ before ‘&amp;’ token OpenCV-2.4.0/modules/core/src/system.cpp: In function ‘void error(int)’: OpenCV-2.4.0/modules/core/src/system.cpp:506: error: ‘exc’ was not declared in this scope OpenCV-2.4.0/modules/core/src/system.cpp:510: error: ‘exc’ was not declared in this scope OpenCV-2.4.0/modules/core/src/system.cpp:526: error: ‘exc’ was not declared in this scope OpenCV-2.4.0/modules/core/src/system.cpp: At global scope: OpenCV-2.4.0/modules/core/src/system.cpp:543: error: expected declaration before ‘}’ token make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o] Error 1 make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2 make: *** [all] Error 2 </code></pre> <p>What should i do?</p>
2,031,722
0
<p>Check Alex's answer in order to understand python decorators; by the way:</p> <p>1) what aren't you understanding of decorators? Don't you understand decorators as a general concept, or Python decorators? Beware, the "classical" decorator pattern, java annotations and python decorators are different things.</p> <p>2) python decorators should always return a function, e.g. in your code the return value of param_checker([...]) should be a function that accepts a function as param (the func to be decorated), and returns a function with the same signature as my_decorated_function. Take a look at the following example; the decorator function is executed just once (when the class is created), while the decorated func is then executed at every call. In this specific example, it then invokes the original func, but that's not a requirement.</p> <pre><code>def decorator(orig_func): print orig_func def decorated(self, a): print "aahahah", orig_func(self, a) return decorated class Example(object): @decorator def do_example(self, a): return 2 * a m = Example() m.do_example(1) </code></pre> <p>3) you might not be doing the best thing in the way you're using decorators. They should usually be employed when there's some concept which is quite orthogonal to what you're actually programming, and can be reused around - it's essentially the Python way of doing AOP. Your param_checker might not be that orthogonal - if your decorator gets just used once, then it's probably not a good place to use a decorator at all. Your param_checker seems to be the case - it assumes that the decorated func takes a single arg which is a dictionary - are there many funcs in your code with such a signature and behaviour? If the answer is "no", just check for params at the begininng of the func and raise an exception if they're missing.</p>
37,849,726
0
<p>Here is a working version</p> <p>Changes:</p> <ul> <li>Added <code>$dbname</code> to <code>mysqli_connect</code> function</li> <li>Added the backtick ` char between the table names, to avoid errors with reserved keyword from MySQL</li> <li>Changed mysql_ functions to mysqli_</li> <li>Close the file</li> <li>Close the connection</li> </ul> <p><a href="http://pastebin.com/B3jZ4wc9" rel="nofollow">Here</a> is the code</p> <p><strong>NOTE:</strong> sorry I don't why, but when I pasted the code in the answer, all de code identation was messed up, even trying to indent it properly, I wasted like 10 minutes :(</p>
13,172,514
0
<p>You can call <a href="http://en.cppreference.com/w/cpp/string/basic_string/find"><code>std::string::find</code></a> in a loop and the use <a href="http://en.cppreference.com/w/cpp/string/basic_string/substr"><code>std::string::substr</code></a>.</p> <pre><code>std::vector&lt;std::string&gt; split_string(const std::string&amp; str, const std::string&amp; delimiter) { std::vector&lt;std::string&gt; strings; std::string::size_type pos = 0; std::string::size_type prev = 0; while ((pos = str.find(delimiter, prev)) != std::string::npos) { strings.push_back(str.substr(prev, pos - prev)); prev = pos + 1; } // To get the last substring (or only, if delimiter is not found) strings.push_back(str.substr(prev)); return strings; } </code></pre> <p>See example <a href="http://ideone.com/UHWNQW">here</a>.</p>
18,256,026
0
PhantomJS exited unexpectedly with exit code -1073741819 <p>I run a bunch of Jasmine specs with PhantomJS (via Grunt) on a Windows 7 PC, and I happen to get the following error:</p> <pre><code>Testing jasmine specs via phantom ...... Running PhantomJS...ERROR &gt;&gt; 0 [ '' ] Warning: PhantomJS exited unexpectedly with exit code -1073741819. Use --force to continue. Aborted due to warnings. </code></pre> <p>The error does not appear if I delete a bunch of tests; however I have no idea what causes the error. </p> <p>What I also find strange, it that it only occurs now and then.</p> <p>Any idea why this happens?</p>
6,032,228
0
CurrencyManager alternative in vb.NET? <p>I am developing a VB.NET application in which I use a DataGrid; I can't use the newer DataGridView due to version. But now when I try to compile this, I get the error:</p> <blockquote> <p>BC30002: Type 'CurrencyManager' is not defined.</p> </blockquote> <p>It errors on line:</p> <blockquote> <p>Dim CM As New CurrencyManager(dgTable.BindingContext)</p> </blockquote> <p>What can I replace this line with? I have read on the internet that since my application should be web-based, I cannot use the Windows namespace. I think what I am asking for is a pretty simple solution, but I am a very new VB programmer. More of my code below.</p> <p>Global.vb file:</p> <pre><code>Imports System.Data Imports System.Data.OLEDB Imports System.Web Imports System.Math Imports system.data.SqlClient Imports System.Windows.Forms Imports System.Windows.Forms.CurrencyManager Namespace GlobalFunctions Public Class GlobalF Public Shared Function GlobalF_Load(ByVal dgTable As DataGrid) Dim dv As New DataView Dim ds As New DataSet Dim CM As New CurrencyManager(dgTable.BindingContext) dv = New DataView(ds.Tables(0)) dgTable.DataSource = dv dv.Sort = "Part No." 'CM = (System.Windows.Forms.CurrencyManager) dgTable.BindingContext([dv]) Dim sender As New sender() dv.ListChanged += New ListChangedEventHandler(dv_ListChangedEvent) End Function Public Shared Function btnFind_Click(ByVal sender As Object, ByVal e As EventArgs) If (txtFind.Text = "") Then Response.write("Enter some criteria to find.") txtFind.Focus() Else Dim i As Int i = dv.Find(txtFind.Text) If (i &gt; dv.Table.Rows.Count Or i &lt; 0) Then Response.Write("Record Not found") Else CM.Position = i End If End If End Function Private Shared Function dv_ListChangedEvent(ByVal sender As Object, ByVal e As ListChangedEventArgs) Handles btnFind.ListChanged If (dv.Sort.Substring((dv.Sort.Length - 4), 4) = "DESC") Then lblFind.Text = "Enter Search Criteria " + dv.Sort.Substring(0, dv.Sort.Length - 5) Else lblFind.Text = "Enter Search Criteria " + dv.Sort End If End Function </code></pre> <p>and my ASPX file:</p> <p>Public DSTableData As New System.Data.DataSet Public dv As New DataView</p> <pre><code> Sub Main() '------------------------- Query database and get arrays for the chart and bind query results to datagrid ---------------------------------------- If check1.Checked Then DSTableData = GlobalFunctions.GlobalF.FillSparePartsTable(1) Else DSTableData = GlobalFunctions.GlobalF.FillSparePartsTable(0) End If 'dv = DataView(DSTableData(0)) dgTable.DataSource = DSTableData dgTable.DataBind() GlobalFunctions.GlobalF.GlobalF_Load(dgTable) End Sub </code></pre>
7,133,517
0
<p>Please check out my edit. If you <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/JSON/stringify" rel="nofollow"><strong>JSON.stringify</strong></a> your object, then your code will work as you expect.</p> <pre><code>var gmarkers = {key: 'value'}; var ss = document.createElement('script'); var scr = "function caller(){ alert("+JSON.stringify(gmarkers)+") ;}"; //alert(scr); var tt1 = document.createTextNode(scr); ss1.appendChild(tt1); var hh1 = document.getElementsByTagName('head')[0]; hh1.appendChild(ss1); caller() var tt = document.createTextNode(scr); ss.appendChild(tt); var hh = document.getElementsByTagName('head')[0]; hh.appendChild(ss); caller(); </code></pre>
38,352,894
0
android volume gain AudioTrack DatagramPacket <p>I need help to apply a volume gain on audio stream to increase the volume output of device.</p> <p>Here is some code of my app:</p> <pre><code>private static final int SAMPLE_RATE = 8000; // Hertz private static final int BUF_SIZE = 372; //Bytes </code></pre> <p>...</p> <pre><code>AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC, SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, BUF_SIZE, AudioTrack.MODE_STREAM); </code></pre> <p>...</p> <pre><code>DatagramPacket packet = new DatagramPacket(buf, BUF_SIZE); socket.receive(packet); </code></pre> <p>...</p> <pre><code>track.write(packet.getData(), 0, packet.getLength()); </code></pre> <p>Someone can help me?</p> <p>Thanks in advance.</p>
2,344,652
0
<p>Do it in the <code>Session_Start</code> method in your <a href="http://msdn.microsoft.com/en-us/library/2027ewzw.aspx" rel="nofollow noreferrer">Global.asax</a> like so...</p> <pre><code>protected void Session_Start(object sender, EventArgs e) { Session["AttemptCount"]=new Hashtable(); } </code></pre> <p><strong>Update:</strong></p> <p>Then simply just do a check to see if the session variable exists, if it doesn't only then create the variable. You could stick it in a property to make things cleaner like so...</p> <pre><code>public Hashtable AttemptCount { get { if (Session["AttemptCount"] == null) Session["AttemptCount"]=new Hashtable(); return Session["AttemptCount"]; } } </code></pre> <p>And then you could just call on the property <code>AttemptCount</code> wherever you need like so...</p> <pre><code>public void doEvent(object sender, EventArgs e) { AttemptCount.Add("Key1", "Value1"); } </code></pre>
22,700,203
1
Python: default argument values vs global variables <p>I saw this default values usage in the Python's <a href="http://hg.python.org/cpython/file/2.7/Lib/Queue.py" rel="nofollow">Queue</a> module:</p> <pre><code>def _put(self, item, heappush=heapq.heappush): heappush(self.queue, item) def _get(self, heappop=heapq.heappop): return heappop(self.queue) </code></pre> <p>I wonder why the variables are used as function arguments here? Is it just a matter of taste or some kind of optimization?</p>
40,006,652
1
Passing an array where single value is expected? <p>I am trying to implement simple optimization problem in Python. I am currently struggling with the following error:</p> <p><strong>Value Error</strong>: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()</p> <p>As far as I understand, this means that I am somewhere trying to plug in an array where only single value can be accepted. Nevertheless, I haven't managed to come up with a solution, nor have I discovered where is the problem.</p> <p>My code follows</p> <pre><code>def validationCurve(X, y, Xval, yval): #[lmbda_vec, error_train, error_val] = # VALIDATIONCURVE(X, y, Xval, yval) returns the train and # validation errors (in error_train, error_val) for different # values of lmbda. Given the training set (X,y) and validation # set (Xval, yval). lmbda_vec = [0, 0.001, 0.003, 0.01, 0.03, 0.1, 0.3, 1]; m = len(y); X = numpy.concatenate((numpy.ones((m,1)), X), axis = 1); n = len(Xval); Xval = numpy.concatenate((numpy.ones((n,1)), Xval), axis = 1); error_train = numpy.zeros((len(lmbda_vec), 1)); error_val = numpy.zeros((len(lmbda_vec), 1)); for i in range(0,len(lmbda_vec)): lmbda = lmbda_vec[i]; theta = trainLinearReg(X, y, lmbda); error_train[i] = linearRegCostFunction(X, y, theta, lmbda); error_val[i] = linearRegCostFunction(Xval, yval, theta, lmbda); return lmbda_vec, error_train, error_val def trainLinearReg(X, y, lmbda): #[theta] = TRAINLINEARREG (X, y, lmbda) trains linear # regression usingthe dataset (X, y) and regularization # parameter lmbda. Returns the trained parameters theta. alpha = 1 # learning rate num_iters = 200 # number of iterations initial_theta = (numpy.zeros((len(X[0,:]),1))) #initial guess #Create "short hand" for the cost function to be minimized costFunction = lambda t: linearRegCostFunction(X, y, t, lmbda); #Minimize using Conjugate Gradient theta = minimize(costFunction, initial_theta, method = 'Newton-CG', jac = True, options = {'maxiter': 200}) return theta def linearRegCostFunction(X, y, theta, lmbda): # [J, grad] = LINEARREGCOSTFUNCTION(X, y, theta, lmbda) # computes the cost of using theta as the parameter for # linear regression to fit the data points in X and y. # Returns the cost in J and the gradient in grad. # Initialize some useful values m, n = X.shape; # number of training examples J = 0; grad = numpy.zeros((n ,1)) J = numpy.dot((y- X @ theta).T, (y-X @ theta)) + lmbda*(theta[1:].T @ theta[1:]) J = J/m grad = (X.T @ (y - X @ theta))/m grad [1:] += (lmbda*theta[1:])/m grad = grad[:]; return grad </code></pre> <p>I am trying to obtain an optimal regularization parameter by computing cost function and minimizing with respect to theta. My input values are:</p> <pre><code>X.shape = (100,25), y.shape = (100,1) Xval.shape = (55,25), yval.shape = (55,1) </code></pre> <p>Outputted errors are:</p> <pre><code> --&gt; 129 lmbda_vec , error_train, error_val = validationCurve(Xtrain, ytrain, Xva lid, yvalid ) ---&gt; 33 theta = trainLinearReg(X, y, lmbda); ---&gt; 49 theta = minimize(costFunction, initial_theta, method = 'Newton-CG', jac = True, options = {'maxiter': 200}) </code></pre> <p>Later I won't to use the optimized model to predict y on new X. <strong>Could you please advice me where is the problem in my code?</strong></p> <p>Also, if you observe any points for improvement in my code, please let me know. I will be glad to hear and improve.</p> <p>Thank you!</p>
40,780,572
0
mouseup event not firing on object tag in mac firefox <p>I have binded the mouseup event after mousedown. It works fine on all tags and browsers, but in mac firefox it behaves ambiguously. mouseup event is not firing over object tag on mac firefox but it works on firefox on windows. It want to stop dragging this object on mouseup but it keeps on dragging.I also used mouseleave but it was also not working.</p>
16,806,480
0
<p>For the second button add</p> <pre><code>android:id="@+id/button2" </code></pre> <p>and change</p> <pre><code>android:layout_alignLeft="@+id/button1" </code></pre> <p>to</p> <pre><code>android:layout_alignLeft="@id/button1" </code></pre> <p>Change your layout as follow:</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:gravity="start" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="your total is 0" android:textSize="65sp" /&gt; &lt;Button android:id="@+id/button1" android:layout_width="100sp" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_gravity="center" android:text="add" /&gt; &lt;Button android:id="@+id/button2" android:layout_width="100sp" android:layout_height="wrap_content" android:layout_alignLeft="@id/button1" android:layout_below="@+id/textView1" android:layout_marginLeft="117dp" android:text="subtract" /&gt; &lt;/RelativeLayout&gt; </code></pre>
15,284,884
0
How to access the local project file using java.nio.file.Path? <p>I am new to java.nio world.</p> <p>I have a log file app.log inside my Java module. (I am using Intellij 11).</p> <p>In a module, i have test folder, i have a local file app.jar.</p> <p>I want to read this file into InputStream using Files.newInputStream(path) method.</p> <p>The problem is that in windows, i have to give complete value for input path as,</p> <pre><code>Path path = Paths.get("C:\\Perforce\\depot\\Project\\module\\src\\test\\a\\b\\c\\app.jar"); </code></pre> <p>I am not sure if somebody gets this code and has similar folder structure on their machine to access app.jar</p> <p>I have kept the file app.jar in local folder where my test is written. Is there a way through which i can generalize this Path? if my Test class is under the same folder where app.jar is residing, is there any mechanism to avoid mentioning the complete local path?</p> <p>Thanks, Vijay Bhore</p>
10,275,468
0
<p>Basically you're trying to change the property value during DataBinding. The problem is that WPF tries to be smart and not listen on property changes raised during DataBinding. This is a well know problem with numerous workarounds: </p> <ul> <li><a href="http://stackoverflow.com/questions/857116/change-value-in-setter-property-when-using-wpf-two-way-databinding">Change value in setter property when using WPF two-way databinding</a></li> <li><a href="http://www.lhotka.net/weblog/DataBindingIssueInWPFWithSolution.aspx" rel="nofollow noreferrer">Data binding issue in WPF: with solution</a></li> </ul> <p>Although MS made some fixes in WPF4.0 see: <a href="http://karlshifflett.wordpress.com/2009/05/27/wpf-4-0-data-binding-change-great-feature/" rel="nofollow noreferrer">WPF 4.0 Data Binding Change (great feature)</a> </p> <p>But I did some quick testing and none of them is working in your case because of the <code>UpdateSourceTrigger=PropertyChanged</code>.</p> <p>However I can came up a very dirt workaround which is "works":</p> <pre><code>public decimal Col1 { get { return _Col1; } set { //Change the property value based on condition _Col1 = value &gt; 100 ? 100 : value; UpdateSum(); //HACK: Simulate that the property change not fired from the setter Dispatcher.CurrentDispatcher .BeginInvoke(new Action(() =&gt; NotifyPropertyChanged("Col1"))); //HACK: Cancel the bindig based on condition if (value &gt; 100) throw new Exception(); } } </code></pre> <p>See it action:</p> <p><img src="https://i.stack.imgur.com/EFhQZ.png" alt="enter image description here"></p> <p>Notice: after typing the third 5 the cursor moves the the beginning of the TextBox and it remains there if you type the next 5.</p> <p>I don't think that the above mention code should be the solution, I've just played a bit. I think you should go with <code>UpdateSourceTrigger=LostFocus</code> and do the binding manually from the textbox <code>TextChanged</code> event... But I'm afraid there is no clean solution for your problem.</p>
31,500,034
0
c# socket send file <p>im trying to use the <code>SendFile</code> method <a href="https://msdn.microsoft.com/en-us/library/sx0a40c2(v=vs.110).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/sx0a40c2(v=vs.110).aspx</a></p> <pre><code> TcpClient client; private void Form1_Load(object sender, EventArgs e) { client = new TcpClient(); client.Connect("10.0.0.1", 10); string fileName = @"C:\Users\itapi\Desktop\da.jpg"; Console.WriteLine("Sending {0} to the host.", fileName); client.Client.SendFile(fileName); } </code></pre> <p>server code:</p> <pre><code> TcpListener listener; TcpClient cl; private void Form1_Load(object sender, EventArgs e) { listener = new TcpListener(IPAddress.Any, 10); listener.Start(); cl = listener.AcceptTcpClient(); } </code></pre> <p>my question is: how i am supposed to get the file in the other side? i dont want to use networkstream only pure socket. any help would be apperciated</p>
1,580,199
0
Linq to Sql - Populate JOIN result into a List <p>I am not sure if this can be done, but here's the scenario.</p> <p>I want to turn this sql into linq:</p> <pre><code>SELECT * FROM Department d INNER JOIN Employee e ON e.DepartmentID = d.DepartmentID </code></pre> <p>Department - Employee is 1 to many relationship.</p> <p>I have created a custom object that I would like to populate the result into. </p> <pre><code>public class DepartmentSummary { public Department Department { get; set; } public List&lt;Employee&gt; Employees {get; set;} } </code></pre> <p>The Linq I came up with is </p> <pre><code>var result = from d in dba.Department join e in dba.Employee d.DepartmentID equals e.DepartmentID into j1 select new DepartmentSummary { Department = d, Employees = j1.ToList() }; </code></pre> <p>I tried it out and it's not working. Can anyone shed some light for me please? I would like to perform an inner join between Department and Employee. For each Department in the resultset, I would like to create one DepartmentSummary object which holds that department and a list of employees belonging to that department.</p> <p>Does Linq provides an ad hoc solution for this or must I iterates through the result set and create a list of DepartmentSummary manually?</p> <p>Thanks,</p> <p>EDIT: Looks like this works for me</p> <pre><code>var result = from d in dba.Department join e in dba.Employee d.DepartmentID equals e.DepartmentID into j1 where j1.Count() &gt; 0 select new DepartmentSummary { Department = d, Employees = j1.ToList() }; </code></pre>
3,637,416
0
<p>Is this some kind of weird code-golf?</p> <p>Try this, it might work...</p> <pre><code>dpcom.library = function(name, func) { var p = name.split('.'), e, root = this; while (e = p.shift()) root = root[e] = root[e] || (!p.length ? func : {}); } </code></pre>
3,485,308
0
<p>mate... make the searchable columns into "fulltext" colums and then do</p> <p><code>SELECT * FROM books WHERE MATCH(fulltext_column) AGAINST('animal book a')</code></p> <p>best way. :) see <a href="http://devzone.zend.com/article/1304" rel="nofollow noreferrer">http://devzone.zend.com/article/1304</a></p>
838,689
0
<p>DataGrids represent actual DataItems.</p> <pre><code>DataGrid dg = new DataGrid(); dg.Items.Count; //Number of Items...i.e. Rows; dg.Items[0].Cells.Count; //Number of columns for that Items </code></pre>
3,442,440
0
<p>login to <a href="http://developer.apple.com" rel="nofollow noreferrer">the iphone developer portal</a> all the certificates/profiles can be found there or if in need be regenerated</p>
6,049,179
0
how to pass data from json to a php function? <pre><code>[registration] =&gt; Array ( [first_name] =&gt; test [location] =&gt; Array ( [name] =&gt; Santa Ana [id] =&gt; 1.08081209215E+14 ) [gender] =&gt; female [password] =&gt; 123654789 ) </code></pre> <p>and i need to insert that data into a database by using:</p> <pre><code>$carray = fns_create_talent($login, $pass, $gender, $name); </code></pre> <p>any idea on how to get them from a place to another?</p> <p>i was thinking that i need to assign the array values to the post vars. maybe:</p> <pre><code>$login = registration.first_name... </code></pre> <p>any ideas? thanks</p>
40,846,559
0
<p>You have flex-basis on content as 100%</p> <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>html, body { height: 100%; margin: 0 } .box { display: flex; flex-flow: column; height: 100%; } .box .row { border: 1px dotted grey; } .box .row.header { flex: 0 1 auto; /* The above is shorthand for: flex-grow: 0, flex-shrink: 1, flex-basis: auto */ } .box .row.content { flex: 1 1 100%; background-color: yellow; } .box .row.footer { flex: 0 1 40px; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="box"&gt; &lt;div class="row header"&gt; &lt;p&gt;&lt;b&gt;header&lt;/b&gt; &lt;br /&gt; &lt;br /&gt;(sized to content)&lt;/p&gt; &lt;/div&gt; &lt;div class="row content"&gt; &lt;div style="height:100%; width:90%; background-color:red;"&gt; Should fill the remaining space &lt;/div&gt; &lt;/div&gt; &lt;div class="row footer"&gt; &lt;p&gt;&lt;b&gt;footer&lt;/b&gt; (fixed height)&lt;/p&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>Hope it helps</p>
16,047,252
0
Identifying What Javascript is Running on a <span> through Chrome Inspector or Firebug <p>I am working on a site that has info being generated dynamically into <code>&lt;span&gt;&lt;/span&gt;</code> tags through jQuery. The span has a class of "Price" and an id of a Product Code and it's being generated from a JSON data sheet according to the ID. The problem is, this is part of a much bigger framework and I can't seem to find where the Javascript is that's accomplishing this so I can troubleshoot it.</p> <p>I'm trying to figure out how to find that out using Google Chrome Inspector or Firebug. I'm assuming the page records this info when it's loaded but I can't seem to find where that info would lie. I know this may be pretty basic but I new to the Inspectors beyond just reading the HTML and CSS. Thanks for your help!</p>
7,910,927
0
Unable to get windows login name of the user? <p>In my ASP.NET application deployed on an intranet, I am using something like this in a Web Service to get the Windows Login of the current user:</p> <pre><code>string user = User.Identity.Name.ToString(); </code></pre> <p>and added the following to my <code>Web.config</code> file:</p> <pre><code>&lt;system.web&gt; &lt;authentication mode="Windows" /&gt; &lt;identity impersonate="false" /&gt; &lt;/system.web&gt; </code></pre> <p>This works when I deploy my site locally but does not work when I publish it and use an actual URL (not the localhost) to access it. Am I missing something? I want to get the Windows Login name of the user currently accessing my website. Any suggestions?</p>
24,984,011
0
using google maps api to show locations with multiple custom marker <p>I am a JavaScript newbie . i am currently experimenting with a small google map based task.i have a large set of latitude and longitudes, around thousand and for each set of latitude and longitude pair i have some value which is gained from some servey . i can catogorize each value something like excellent, good or bad </p> <p>Now for above scenario what i want to do is show all the categorized value in the specific latitudes and longitudes and use different custom marker for excellent ,good or bad value.my question is can i use Google maps api without key and how can i use multiple color based custom marker to show all the latitudes and longitudes Is there any limit to use custom marker in maps</p> <p>A help would be appreciated</p>
24,825,303
0
<p>You could make use of <a href="http://docs.oracle.com/javase/tutorial/reflect/" rel="nofollow">java reflection API</a> and call <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getDeclaredFields--" rel="nofollow">Class#getDeclaredFields</a> to retrieve all fields in a class, iterate over the array returned by this method and call the register and pass it <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Field.html#getName--" rel="nofollow">Field#getName</a></p> <pre><code>for(Field field : getClass().getDeclaredFields()) { validationRegisterer.register(field.getName(), MandatoryFieldValidator.class); } </code></pre>
33,036,254
0
Xamarin forms block user back key press <p>In my Xamarin forms application I want to show a confirmation message when user clicks the back button from Main-page. Is there any way to achieve this? I overrided the OnBackButtonPressed method in my MainPage. But still the app is closing while back key press. Here is my code </p> <pre><code>protected override bool OnBackButtonPressed () { //return base.OnBackButtonPressed (); return false; } </code></pre>
30,356,086
0
Divide by zero error sql <p>I get the divide by zero error using this:</p> <pre><code>Select Top 100 *, Case (a.value) When 0.0 Then Null Else ((cast(b.value as decimal) - cast(a.value as decimal))/cast(a.value as decimal)) * 100 End as 'Montly Price Change (%)' From AllProducts a Join AllProducts b On a.series_id=b.series_id And (b.Date = DATEADD(month, 1, a.Date)) </code></pre> <p>I can't find a way to fix it.. I've tried </p> <pre><code>Select Top 100 *, Case cast((a.value) as decimal) When 0.0 Then Null Else ((cast(b.value as decimal) - cast(a.value as decimal))/cast(a.value as decimal)) * 100 End as 'Montly Price Change (%)' From AllProducts a Join AllProducts b On a.series_id=b.series_id And (b.Date = DATEADD(month, 1, a.Date)) </code></pre> <p>but this makes my entire column null for some reason..</p>
17,679,183
0
<pre><code>private static List&lt;string&gt; wordsToRemove = "DE DA DAS DO DOS AN NAS NO NOS EM E A AS O OS AO AOS P LDA AND".Split(' ').ToList(); public static string StringWordsRemove(string stringToClean) { return string.Join(" ", stringToClean.Split(' ').Except(wordsToRemove)); } </code></pre> <p>Modification to handle punctuations:</p> <pre><code>public static string StringWordsRemove(string stringToClean) { // Define how to tokenize the input string, i.e. space only or punctuations also return string.Join(" ", stringToClean .Split(new[] { ' ', ',', '.', '?', '!' }, StringSplitOptions.RemoveEmptyEntries) .Except(wordsToRemove)); } </code></pre>
30,185,003
0
<p>Using</p> <pre><code>X500Name x500name = new JcaX509CertificateHolder(certificate).<b>getSubject</b>();</code></pre> <p>will give you more detailed output than <code>getIssuer()</code>.</p>
11,788,545
0
<p>Please use <a href="http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/" rel="nofollow">http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/</a> link for reference. But if you will tell what specific you are looking for I might be able to help you better. Here is little detail about @GeneratedValue annotation… I love this blog post on same topic <a href="http://elegando.jcg3.org/2009/08/hibernate-generatedvalue/" rel="nofollow">http://elegando.jcg3.org/2009/08/hibernate-generatedvalue/</a>. He has done good job explaining. </p>
25,563,054
0
<p>From those results, do you have <a href="http://en.wikipedia.org/wiki/D-Bus" rel="nofollow">d-bus daemon</a> installed? I don't know much about d-bus, but have you tried disabling it or modifying the config and then see if you can restart hivemq on port 1883.</p>
34,084,730
0
<p>Ok, got it working.</p> <p>When using Session State Server you have to call Server.ClearError() within Application_Error, otherwise the Request will be terminated and Session state will not be written.</p> <pre><code>void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); HttpContext.Current.Session["Error"] = ex.Message; Response.Redirect("error.aspx",false); Server.ClearError(); } </code></pre>
27,000,065
0
<p>You haven't said what you want to achieve. I assume that you need that each of your instances react on a specific way, depending on a certain class variable.</p> <p>However, if you don't need a per-instance behaviour, then you can use static variables. The following works:</p> <pre><code>#include &lt;iostream&gt; using namespace std; struct test { static string t1; void say(const string &amp;val=t1){ cout &lt;&lt; val &lt;&lt; "!" &lt;&lt; endl; } }; string test::t1; int main() { cout &lt;&lt; "Hello World" &lt;&lt; endl; test::t1 = string("asd"); test a; a.say(); a.say("bla"); test::t1 = string("blahblah"); a.say(); return 0; } </code></pre> <p>... which means that all the objects of the class <code>test</code> will use the static string <code>t1</code> as their default value.</p> <p>You can "hack" a little bit, and use this as an ugly sentinel:</p> <pre><code> void say(const string &amp;val=t1){ if (&amp;val == &amp;t1) { // They are using the default value, so act as you want } else { // they are providing a value } } </code></pre>
21,974,222
0
<p>Try this:</p> <pre><code>System.Windows.Forms.Cursor.Position = new Point { X = xxx, Y = yyy }; </code></pre> <p>Or try to use the native WinAPI for XP (or earlier):</p> <pre><code>[DllImport("user32.dll")] public static extern long SetCursorPos(int x, int y); public void SetCursorPosition(Point p) { SetCursorPos(p.X, p.Y); } </code></pre>
10,263,478
0
Is it possible to use inheritance in xsd with variable element order? <p>Is it possible to use inheritance in xsd with variable element order?</p> <p>Basically, something like this does not work, since "all" is not allowed inside "extension":</p> <pre><code>&lt;xs:complexType name="root"&gt; &lt;xs:complexContent&gt; &lt;xs:all&gt; &lt;xs:element name="A" type="xs:string"/&gt; &lt;xs:element name="B" type="xs:string"/&gt; &lt;/xs:all&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="extended"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="root"&gt; &lt;xs:all&gt; &lt;xs:element name="C" type="xs:string"/&gt; &lt;xs:element name="D" type="xs:string"/&gt; &lt;/xs:all&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; </code></pre> <p>The simplest solution would be just to use "sequence" instead of "all", but in my case this is not an option, since the element order is not guaranteed, so something like this:</p> <pre><code>&lt;obj&gt; &lt;B/&gt; &lt;C/&gt; &lt;D/&gt; &lt;A/&gt; &lt;/obj&gt; </code></pre> <p>will be invalid because of the wrong element order, but is should not be since all the elements are present.</p>
20,284,188
0
How to get a layout size before it's displayed? <p>I inflate a layout containing an <code>ImageView</code> and a <code>RelativeLayout</code>. The layout has its width set to <code>match_parent</code> and its height set to <code>wrap_content</code>. The height is determined by the <code>ImageView</code>, but the image set to the <code>ImageView</code> is loaded dynamically from the internet.</p> <p>Since I know the image ratio, I'd like to set the size of the <code>ImageView</code> before it's displayed to avoid a jump in the UI due to the change in the layout height when the image is set.</p> <p>To set the size I need the layout width, to compute the <code>ImageView</code> height.</p> <p>I tried</p> <pre><code>int width = header.getMeasuredWidth(); </code></pre> <p>but since the layout is not drawn yet it returns 0</p> <p>I also tried to use <code>measure</code> before, as suggested <a href="http://stackoverflow.com/a/5383811/326849">here</a></p> <pre><code>header.measure(0, 0); int width = header.getMeasuredWidth(); </code></pre> <p>but <code>measure</code> returns a <code>NullPointerException</code></p> <p>How can I do that?</p> <p><b>list_header.xml</b></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;ImageView android:id="@+id/pic" android:layout_width="match_parent" android:layout_height="wrap_content" /&gt; &lt;RelativeLayout android:id="@+id/header_text_container" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:background="#789987"&gt; &lt;/RelativeLayout&gt; &lt;/RelativeLayout&gt; </code></pre> <p><b>MyListFragment.java</b></p> <pre><code>@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mListView = (ListView) getView().findViewById(R.id.listview); View header = getActivity().getLayoutInflater().inflate(R.layout.list_header, null); int width = header.getMeasuredWidth(); // 0 because not drawn yet ImageView pic = (ImageView) header.findViewById(R.id.pic); pic.setLayoutParams(new LayoutParams(width, (int) (width/imgRatio))); pic.invalidate(); header.invalidate(); /* ... */ } </code></pre>
12,668,678
0
<p>HTML</p> <pre><code>&lt;div class="main"&gt; &lt;div class="Parent"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>CSS</p> <pre><code>.Parent{ width:200px; height:100px; background:red; position:absolute; right:0; top:200px; } .main{ width:700px; margin:auto; height:1000px; background:blue; } </code></pre> <p>​ <a href="http://jsfiddle.net/afshinprofe/qhCsJ/5/" rel="nofollow">DEMO</a></p>
37,344,759
0
<p>It really depends on what you are trying to keep.</p> <p><code>wp-config.php</code> stores your database connection details and a few other settings.</p> <p><code>wp-content</code> is the directory that stores all of your uploads and plugins. Essentially all of your uploaded content.</p> <p>The file and folder shown above are what you would typically want to keep. However, the infection could very well have spread to the php files in there too - so keep that mind!</p> <p>The alternative method is listed below:</p> <p>A good idea would be to follow the manual upgrade process instead</p> <ol> <li>Get the latest WordPress zip (or tar.gz) file.</li> <li>Unpack the zip file that you downloaded.</li> <li>Deactivate plugins.</li> <li>Delete the old wp-includes and wp-admin directories on your web host (through your FTP or shell access).</li> <li>Using FTP or your shell access, upload the new wp-includes and wp-admin directories to your web host, in place of the previously deleted directories.</li> <li>Upload the individual files from the new wp-content folder to your existing wp-content folder, overwriting existing files. Do NOT delete your existing wp-content folder. Do NOT delete any files or folders in your existing wp-content directory (except for the one being overwritten by new files).</li> <li>Upload all new loose files from the root directory of the new version to your existing wordpress root directory.</li> </ol> <p>If you get stuck here - have a look at <a href="https://codex.wordpress.org/Upgrading_WordPress_Extended" rel="nofollow">https://codex.wordpress.org/Upgrading_WordPress_Extended</a></p>
6,338,900
0
UITextField autocomplete <p>Is it possible to autocomplete a UITextField bases on what is being entered? The reason why I need this is because I have a predefined set of words that the user needs to choose and the list is about 1000 item long. I want to display in UITableView and let the user chose but having 1k items in table list isn't I think a good idea. Thanks</p>
4,125,090
0
Windows 7, IE8: Creating CAxWindow finished with Access Denied error <p>I have Windows 7, and Internet Explorer 8, Visual Studio 2008. I need to create Active X window which will show page from other site. I try to create CAxWindow window while IE in Protected Mode. It returns Access Denied error (5) if current site isn't trusted.</p> <p>Class of new window defined as:</p> <pre><code>class CNewWnd: public CWindowImpl&lt;CNewWnd, CAxWindow, CWinTraits&lt;WS_CHILD | WS_BORDER, WS_EX_TOOLWINDOW&gt;&gt; </code></pre> <p>Create new window implemented as:</p> <pre><code>hWndContainer = Create(hParent, r); </code></pre> <p>where hParent is HWND of browser. As result hWndContainer = NULL and GetLastError() returns 5.</p> <p>MSDN's article "Understanding and Working in Protected Mode Internet Explorer" describes only working with System Registry, Files and Processes - none of word about windows creating.</p>
28,526,405
0
Remove duplicates according to data in 2 columns by priority in Excel <p>I am trying to remove duplicates in Excel by comparing 2 columns and by priority, meaning:</p> <p>I have priority by category such as cat 1 > cat 2 > cat 3 > cat 4</p> <p>And I want to match if some text that appears in column 2 and 4 matches any other row it will delete the row that has the lower category priority</p> <p>Here is an image: <a href="http://i.imgur.com/aN3cQwL.png" rel="nofollow">http://i.imgur.com/aN3cQwL.png</a></p> <p>Explanation of the image: Orange cells should be deleted, blue ones should be kept.</p> <p><strong>Update:</strong></p> <p>What I am trying to achieve: I have a list of URLs in column B (Source URLs), another list of URLs in column C (which are target URLs of links), anchor text in column D, column A contains the data source to help me identify from where I pulled the data from. I just want to make sure that there aren't any duplicates between all data sources but maintaining a certain priority, which will prefer to delete duplicates from Category 2 if the exact source URL and anchor appear in Category 1 and etc.</p>
27,826,071
0
How do I cancel orphaned NSUserNotifications on OS X? <p>I was doing some development with NSUserNotification in an OS X Yosemite app. It's all working great now, but in the process of development, I somehow orphaned scheduled daily NSUserNotifications on my system. Now I get notifications all day long that are unconnected to my app: clicking "Show" does not launch or switch to the app. I can disable all notifications for the app, but then the <em>actual</em>, non-orphaned notifications stop appearing, too.</p> <p>Is there some place on the system where I can find a list of scheduled notifications and delete all the orphans? Maybe a file to edit or a database to update?</p>
26,075,248
0
Why are not all images showing up in this slider? <p>Here is my code </p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function() { var startSlider = function() { var startSlide = $(".slider li:first"); var nextSlide = $(".active").next("li"); $(".active").removeClass(); if(nextSlide.html() == null) { nextSlide = startSlide; } nextSlide.addClass("active"); setTimeout(startSlider, 1000); }; setTimeout(startSlider, 1000); }); &lt;/script&gt; &lt;style&gt; .active{ display:none; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;ul class="slider" style="list-style:none;"&gt; &lt;li&gt;&lt;div class="active" style="background:#F00;height:100px;width:100px;margin:6px; position: fixed; top: 100px;"&gt;&lt;/div&gt;&lt;/li&gt; &lt;li&gt;&lt;div style="background:#0F0;height:100px;width:100px;margin:6px; position: fixed; top:100px;"&gt;&lt;/div&gt;&lt;/li&gt; &lt;li&gt;&lt;div style="background:#00F;height:100px;width:100px;margin:6px; position: fixed; top:100px;"&gt;&lt;/li&gt; &lt;li&gt;&lt;div style="background:#000;height:100px;width:100px;margin:6px; position: fixed; top: 100px;"&gt;&lt;/div&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>When I run this code only blue and black divs show up again and again.What can be the posible reason for that? I tried to put active class at different position but it did not help.I removed the typo suggested in answer it was not in the original code and showed up only here.</p>
30,893,418
1
Django runserver from Python script <p>The normal way to start the Django server is to run the following command from a terminal or a bash script:</p> <pre><code>python manage.py runserver [Ip.addr]:[port] </code></pre> <p>e.g. </p> <pre><code>python manage.py runserver 0.0.0.0:8000 </code></pre> <p>How can I start a Django server from a Python script?</p> <p>One option is the following </p> <pre><code>import os if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings") from django.core.management import execute_from_command_line args = ['name', 'runserver', '0.0.0.0:8000'] execute_from_command_line(args) </code></pre> <p>Is there a better way?</p>
5,176,200
0
<p>I've seen you already accepted an answer but there are two things here that I wanted to rectify:</p> <ol> <li>It's <em>not needed</em> to retain a scheduled timer but it doesn't do any harm (as long as you release it when it's no longer needed). The "problematic" part of a timer/target relationship is that...</li> <li><strong>a timer retains its target</strong>. And you've decided to set that target to <code>self</code>.<br> That means — retained or not — the timer will keep your object alive, as long as the timer is valid.</li> </ol> <p>With that in mind, let's revisit your code from bottom to top:</p> <pre><code>- (void)dealloc { [timer_porthole invalidate]; // 1 [timer_porthole release]; timer_porthole = nil; // 2 [super dealloc]; } </code></pre> <p><strong>1</strong> is pointless:<br> If <code>timer_porthole</code> was still a valid timer (i.e. scheduled on a runloop) it would retain your object, so this method wouldn't be called in the first place...</p> <p><strong>2</strong> no point here, either:<br> This is <code>dealloc</code>! When <code>[super dealloc]</code> returns, the memory that your instance occupied on the heap will be freed. Sure you can nil out your part of the heap before it gets freed. But why bother?</p> <p>Then there is</p> <pre><code>-(void) kill_timers{ [timer_porthole invalidate]; timer_porthole=nil; // 3 } </code></pre> <p><strong>3</strong> given your initializer (and as others have pointed out) you are leaking your timer here; there should be a <code>[timer_porthole release]</code> before this line.</p> <hr> <p>PS:</p> <p>If you think it all over, you'll see that retaining the timer (at least temporarily) creates a <em>retain-cycle</em>. In this particular case that happens to be a non-issue which is resolved as soon as the timer is invalidated...</p>
37,374,718
1
Error with pip install MySQL-python <p>I have been trying for a few days to fix this, looking at other questions but I can't find a question wth the same error that I am getting.</p> <p>I have been attempting to follow this tutorial <a href="https://realpython.com/learn/start-django/" rel="nofollow">https://realpython.com/learn/start-django/</a> and get to this point:</p> <p>Database settings First, install MySQL-python, which is a database connector for Python:</p> <pre><code>$ pip install MySQL-python </code></pre> <p>Everything has worked okay up to here but when I try and install MySQL-python I get the following error:</p> <blockquote> <pre><code>(env) Camerons-MacBook-Pro:django15_project camrail$ pip install MySQL-python Collecting MySQL-python Using cached MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: sh: mysql_config: command not found Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup.py", line 17, in &lt;module&gt; metadata, options = get_config() File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "/private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3v/czm4shrx0yg5jts39qktf6t00000gn/T/pip-build-2rNsQQ/MySQL-python/ (env) Camerons-MacBook-Pro:django15_project camrail$ </code></pre> </blockquote> <p>I found this answer <a href="https://opensourcehacker.com/2011/03/02/installing-mysql-python-connector-on-osx/" rel="nofollow">https://opensourcehacker.com/2011/03/02/installing-mysql-python-connector-on-osx/</a> that says the MySQL utilities are not made available, so I followed their advice to fix it but to no avail. I have also tried installing developer tools <code>xcode-select --install</code> as some have suggested. I have tried reinstalling <code>ez_setup</code>.</p> <p>Not really sure where to go from here, any help greatly appreciated.</p>
20,807,011
0
<p>I figured it out myself. Instead of <code>/Revision:/</code>, use:</p> <pre><code>result=$(svn info $svn | awk '/^Last Changed Rev:/ { print $4 }') </code></pre>
19,217,771
0
What is localhost path for accessing server file in android?? <p>I want to send variable from <strong>android application</strong> to wamp server and retrieve data from server. Please suggest me and what is path of localhost for wamp server. I am using "<strong>localhost/TestAndroid/check.php</strong>". The error is occurred data is not parsed. Please suggest me with code. How to accessing data from android application(JSON+Android+HTTPClient)?.<br> Thanks Nitin</p>
35,993,187
1
xmpppy: how to get auth response from server <p>Upon registration attempt, server sends a message containing a token, which should later be passed in messages during the conversation. Something like</p> <pre><code>{ "from" : "jid@server", "to" : "jid@client", "type" : "token", "token" : "T0K3N" } </code></pre> <p>I tried the simple client connection sequence:</p> <pre><code>c = xmpp.Client('myClient') c.connect(server=(localhost, 5222)) c.auth('jid', 'password') </code></pre> <p>And connection establishes successfully. However, I'm not getting token from server. How can I listen and consume the reply?</p> <p>Edit: I see that server tries to send the token, but fails with "cannot relay to offline receiver" message. Do I connect incorrectly?</p>
8,647,287
0
Do not use this tag. Use [tomcat] instead.
6,658,633
0
Refreshing IE window automatically does not work in VB.Net <p>I have tried to write a simple function to bring an Internet Explorer windows to the foreground and then press F5 to refresh it using the dll function:</p> <pre><code> Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Integer) As Integer </code></pre> <p>and then later call this function using:</p> <pre><code> SetForegroundWindow(processID.MainWindowHandle.ToInt32) SendKeys.Send("{F5}") </code></pre> <p>However, when I tried to debug the code, the setforeground does not work.</p> <p>I am using a Windows 2008 (64 bit) so I thought I should use ToInt64 instead. However that did not seem to do the trick as well, when I called SetForegroundWindow, nothing seems to come up. </p> <p>Is there any other recommendation? I am using VS 2008.</p> <p>Many thnaks!</p>
13,665,631
0
<p>You can initialize vectors this way:</p> <pre><code>vector&lt;int&gt; a(2,3); //vector a contains 2 elements: 3 and 3 a[0] = 4;//vector a contains 2 elements: 4 and 3 vector&lt;int&gt; b; b = a; </code></pre> <p>And there are some other ways you can check here: <a href="http://www.cplusplus.com/reference/vector/vector/vector/" rel="nofollow">http://www.cplusplus.com/reference/vector/vector/vector/</a></p> <p>EDIT:</p> <p>If you want to initialize with zeros:</p> <pre><code>vector&lt;int&gt; a(2); </code></pre> <p>should do the work, the vector a will contain 2 zeros.</p>
25,268,581
0
<p>PROBLEM: I had similar problem with a file created from other computer (a css in my case). To solve the problem I read that it is necessary to change the permissions but I don't know to do this on Windows so I try this alternative:</p> <p>SOLUTION: Open the file, copy the content and paste it in a new file, this makes sure the permissions are ok. </p> <p>When changing the name by using F2 it didn't work for me, I believe it is because the permissions where still the same.</p>
38,763,754
0
<p>Cassandra table-schema details will be stored as meta data in system keyspaces. </p> <p>Cassandra snapshot just creates a copy of sstables for the requested keyspace/column_familes. So to restore the snapshot, you need to explicitly create the schema in destination cluster.</p>
3,926,182
0
<p>Yes, it's always good to have a known issues section; if nothing else, to keep your inbox empty of the same emails complaining about the same bugs you already know about.</p>
20,094,692
0
<p>It isn't <code>OFFSET</code> that stops this working - your basic <code>VLOOKUP</code> won't work because the "table array" needs to be 2 columns at least if you have the "col_index-num" as 2</p> <p>What are you trying to do with this formula?</p> <p><code>=VLOOKUP($B6,$C$30:$C$36,2,0)</code></p> <p>If you want to look up B6 in C30:C36 and find the corresponding value in the next column you need to use this version</p> <p><code>=VLOOKUP($B6,$C$30:$D$36,2,0)</code></p> <p>Note "D" in place of second "C"</p> <p>and for a corresponding fix to the <code>OFFSET</code> version you can use</p> <p><code>=VLOOKUP($B6,OFFSET(C30,0,C4):OFFSET(D36,0,C4),2,0)</code></p>
24,584,056
0
How to insert a image in WordPress that will display on admin product image? <blockquote> <p>$insert = $wpdb->insert( $prefix."posts", array("post_title" => $posTitle,"post_content" => $postContent,"post_status" => "publish","post_type" =>"product"));</p> </blockquote> <p>I insert image path in wordpress posts table and post parent contain ID of product ID also add _thumbnail_id in postmeta table product id my main focus is to display image in post product page in wp-admin </p>