pid
int64
2.28k
41.1M
label
int64
0
1
text
stringlengths
1
28.3k
4,186,249
1
Searching and capturing a character using regular expressions Python <p>While going through one of the problems in <a href="http://www.pythonchallenge.com/" rel="nofollow">Python Challenge</a>, I am trying to solve it as follows:</p> <p>Read the input in a text file with characters as follows:</p> <pre><code>DQheAbsaMLjTmAOKmNsLziVMenFxQdATQIjItwtyCHyeMwQTNxbbLXWZnGmDqHhXnLHfEyvzxMhSXzd BEBaxeaPgQPttvqRvxHPEOUtIsttPDeeuGFgmDkKQcEYjuSuiGROGfYpzkQgvcCDBKrcYwHFlvPzDMEk MyuPxvGtgSvWgrybKOnbEGhqHUXHhnyjFwSfTfaiWtAOMBZEScsOSumwPssjCPlLbLsPIGffDLpZzMKz jarrjufhgxdrzywWosrblPRasvRUpZLaUbtDHGZQtvZOvHeVSTBHpitDllUljVvWrwvhpnVzeWVYhMPs kMVcdeHzFZxTWocGvaKhhcnozRSbWsIEhpeNfJaRjLwWCvKfTLhuVsJczIYFPCyrOJxOPkXhVuCqCUgE luwLBCmqPwDvUPuBRrJZhfEXHXSBvljqJVVfEGRUWRSHPeKUJCpMpIsrV....... </code></pre> <p>What I need is to go through this text file and pick all lower case letters that are enclosed by only three upper-case letters on each side.</p> <p>The python script that I wrote to do the above is as follows:</p> <pre><code>import re pattern = re.compile("[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]") f = open('/Users/Dev/Sometext.txt','r') for line in f: result = pattern.search(line) if result: print result.groups() f.close() </code></pre> <p>The above given script, instead of returning the capture(list of lower case characters), returns all the text blocks that meets the regular expression criteria, like</p> <pre><code>aXCSdFGHj vCDFeTYHa nHJUiKJHo ......... ......... </code></pre> <p>Can somebody tell me what exactly I am doing wrong here? And instead of looping through the entire file, is there an alternate way to run the regular expression search on the entire file?</p> <p>Thanks</p>
54,312
0
<p>Yes, of course there is :-) object oriented techniques are a tool ... if you use the wrong tool for a given job, you will be over complicating things (think spoon when all you need is a knife).</p> <p>To me, I judge "how much" by the size and scope of the project. If it is a small project, sometimes it does add too much complexity. If the project is large, you will still be taking on this complexity, but it will pay for itself in ease of maintainability, extensibility, etc.</p>
7,956,164
0
<p>Try waiting for window's <code>load</code> event, it waits until all iframes have loaded.</p> <pre><code>$(window).load(function(){ // images and iframes have loaded }) </code></pre>
3,289,313
0
<p>Assuming that's VB.Net, you need to escape the <code>)</code>:</p> <pre><code>If Regex.IsMatch(Output, "\b" &amp; "Serial\)" &amp; "\b") Then 'do something End If </code></pre> <p>In .Net regular expressions, parentheses are the grouping characters.</p> <hr> <p>If, as you say, the word 'Serial)' is generated dynamically, you will have to <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.escape.aspx" rel="nofollow noreferrer">escape</a> it before passing it to the RE engine:</p> <pre><code>If Regex.IsMatch(Output, "\b" &amp; Regex.Escape("Serial)") &amp; "\b") Then 'do something End If </code></pre> <hr> <p>As one other answerer has posted, this won't match <code>"Serial) xyz"</code> (for example) since there's no <code>\b</code> between the <code>)</code> and space (<code>\b</code> only exists <em>between</em> <code>\w</code> and <code>\W</code> characters and both <code>)</code> and a space are <code>\W</code>).</p> <p>You may have to resort to an ugly hack like:</p> <pre><code>If Regex.IsMatch(Output, "\s" &amp; Regex.Escape("Serial)") &amp; "\s") _ Or Regex.IsMatch(Output, "\s" &amp; Regex.Escape("Serial)") &amp; "$") _ Or Regex.IsMatch(Output, "^" &amp; Regex.Escape("Serial)") &amp; "\s") _ Or Regex.IsMatch(Output, "^" &amp; Regex.Escape("Serial)") &amp; "$") _ Then 'do something End If </code></pre> <p>I thought that maybe you could match a character class consisting of (<code>^</code> or <code>$</code>) and <code>\s</code> along the lines of:</p> <pre><code>If Regex.IsMatch(Output, "[\s^]" &amp; Regex.Escape("Serial)") &amp; "[\s$]") Then 'do something End If </code></pre> <p>but this doesn't appear to work based on the regex tester <a href="http://regexlib.com/RETester.aspx" rel="nofollow noreferrer">here</a> so you may have to go for the ugly hack version or you could combine them into a single regex as in:</p> <pre><code>var input = "Serial)" var escaped = Regex.Escape (input) var regex = "\s" &amp; escaped &amp; "\s|^" &amp; escaped &amp; "$|\s" &amp; escaped &amp; "$|^" &amp; escaped &amp; "\s" If Regex.IsMatch(Output, regex) Then 'do something End If </code></pre>
10,314,039
0
<p>Usually when the add-to-cart button does not display it is because your product has no inventory set. Remember that the configurable product needs to be set to in stock and the associated simple products have to have at least one item with non-zero inventory and be set as 'in stock'.</p>
26,203,268
0
Is there a maximum limit to listview or gridview? <p>Is there a limit in rows in listview, or rows and columns in the case of gridview, that could slow down the app? </p> <p>I'm looking at, a maximum nearly 5,000 individual datas with at least 3 table attributes to be displayed in each row of the listview.</p>
6,499,962
0
<p>I would do a loop. Keep adding days until you hit a day that works.</p>
8,978,532
0
NSView subclass over another NSView subclass? <p>I'm trying to create an Cocoa-AppleScript Application with some basic functions, and I want to display a background image for the window and then display a color box above it. </p> <p>I finally figured out how to set the background image via this guide (<a href="http://www.mere-mortal-software.com/blog/details.php?d=2007-01-08" rel="nofollow noreferrer">http://www.mere-mortal-software.com/blog/details.php?d=2007-01-08</a>), but I don't know how to set a color box above it. The basic layout I'm trying to achieve is this:</p> <p><img src="https://i.stack.imgur.com/o25EI.png" alt="enter image description here"></p> <p>The window view has a class of <code>ViewBackground</code> which is a subclass of <code>NSView</code>. The <code>ViewBackground.m</code> file looks like this:</p> <pre><code>-(void)drawRect:(NSRect)rect { NSImage *anImage = [NSImage imageNamed:@"repeat"]; [[NSColor colorWithPatternImage:anImage] set]; NSRectFill([self bounds]); } </code></pre> <p>Like I said, that works fine. The problem is when I try to put the box with the background color white above it. I thought I would be able to do this by making a new subclass of <code>NSView</code>, <code>ContentBackground</code>. The <code>ContentBackground.m</code> file looks like this:</p> <pre><code>-(void)drawRect:(NSRect)rect { [[NSColor whiteColor] set]; NSRectFill(rect); } </code></pre> <p>The hierarchy of my windows looks like this:</p> <p><img src="https://i.stack.imgur.com/PzF0I.png" alt="enter image description here"></p> <p>Now this <em>sometimes</em> works, but usually produces this result in the debugger:</p> <pre><code>int main(int argc, char *argv[]) { [[NSBundle mainBundle] loadAppleScriptObjectiveCScripts]; return NSApplicationMain(argc, (const char **)argv); Thread 1: Stopped at breakpoint 1 } </code></pre> <p>What am I doing wrong and how can I fix this?</p> <p>Also, the content (buttons, etc..) will go on top of the <code>ContentBackground</code> box.</p>
21,300,539
0
<p>Reading your comments, i see that it is not a ZF2 error, and probably not even a third party module, so it could be an ElFinder Error. Probably it cannot find some required resources.</p> <p>Reading some code and some webdites, i think that probably you are just lacking the url option of the viewhelper, so ElFinder can find the backend route he tries to connect to. </p> <p>With the QuElFinder, the route to the connector is <code>/quelfinder/connector</code> so in your view, the code will be:</p> <pre><code>echo $this-&gt;QuElFinder('elfinder', array( 'width' =&gt; "50%", 'height' =&gt; '300', 'url' =&gt; '/quelfinder/connector' ) ); </code></pre> <p>Also, you should go to <code>QuElFinder/config/module.config.php</code> and check everything under </p> <pre><code> 'QuConfig'=&gt;array( 'QuElFinder'=&gt;array( </code></pre> <p>because as you can see in the QuElFinder controller, in the <code>connectorAction()</code> function, it is reading that configuration, and there is a lot of paths.</p>
1,133,967
0
<p>the usage of ccc:fid is an extension of the namespace which needs to be declared in xml in order to be able to use it in libraries like simplexml. </p> <p>Here are some examples of descriptions of usin a namespace:</p> <ul> <li><a href="http://www.w3.org/TR/1999/REC-xml-names-19990114/" rel="nofollow noreferrer">http://www.w3.org/TR/1999/REC-xml-names-19990114/</a></li> <li><a href="http://www.w3.org/TR/xml-names/" rel="nofollow noreferrer">http://www.w3.org/TR/xml-names/</a></li> </ul> <p>Hope that helps, albeit it is a little complicated. </p>
34,315,845
0
<p>In Private Sub DetailsView1_ItemInserting event I changed </p> <p>Dim txtYearPlant As TextBox = DirectCast(DirectCast(sender, DetailsView).FindControl("YearPlant"), TextBox) </p> <p>TO</p> <p>Dim txtYearPlant As TextBox = TryCast(view.FindControl("YearPlant"), TextBox) e.Values.Add("YearPlant", txtYearPlant.Text)</p> <p>So now the value in the PlantYear textbox is saved to the record.</p>
3,532,484
0
<p>Your replace statement should be a regex string. <code>$</code> indicates the end of a line in regex, to find a dollar sign you need to escape each one with a <code>\</code> so your regex should be <code>\$</code> for each one you want to match.</p> <p>for the rest, just use CSS</p>
38,851,957
0
<p>for all the googlers coming here - you're probably looking for this:</p> <pre><code>var pad_array = function(arr,len,fill) { return arr.concat(Array(len).fill(fill)).slice(0,len); } </code></pre>
34,941,141
0
<p>finally figure out the answer, add a custom TypedJsonString class,</p> <pre><code>public class TypedJsonString extends TypedString { public TypedJsonString(String body) { super(body); } @Override public String mimeType() { return "application/json"; } } </code></pre> <p>convert my json object to TypedJsonString,</p> <pre><code>TypedJsonString typedJsonString = new TypedJsonString(jsonObject.toString()); </code></pre> <p>changed the api class as follows,</p> <pre><code>Observable&lt;Item&gt; getListOfFeed(@Body TypedJsonString typedJsonString); </code></pre>
33,778,234
0
Telegram Bot API: How to avoid Integer overflow in updates id? <p>Telegram bot api get updates function takes last update id as offest parameter. But update id is signed 32bit integer, so it is just 2147483647. Currently my bot receiving update id 348691972. 2147483647 is a small number, for example current China and India population is more then int 32.<br> What will happen when update id will overflow and how to avoid it? Is it some kind of problem 2000?</p>
16,189,144
0
OleDbCommand and Unicode Char <p>I have an application that run a lot of query using OleDbCommand. Every query is plain SQL text, and the command does not use parameters. </p> <p>Now, the application should support chinese char and I do not wanto to change every query by adding the N char in front of the string to specify.</p> <p>I am trying to do something like that, but It does not work:</p> <pre><code> OleDbCommand command = new OleDbCommand("?", connect); command.CommandType = CommandType.Text; command.Parameters.AddWithValue("query", qry); OleDbDataAdapter da = new OleDbDataAdapter(command); </code></pre> <p>where qry is the query to execute without the N char in front of every string.</p> <p>I really do not wat to change every query, it would be a mess.</p> <p>Do you have a solution for me?</p>
93,989
0
Prevent multiple instances of a given app in .NET? <p>In .NET, what's the best way to prevent multiple instances of an app from running at the same time? And if there's no "best" technique, what are some of the caveats to consider with each solution?</p>
30,134,561
0
<p>This is one of those cases where type signatures really help. Stare for a second at the type signature: </p> <pre><code>(+=) :: (ArrowXml a) =&gt; a b XmlTree -&gt; a b XmlTree -&gt; a b XmlTree </code></pre> <p>First off, <code>ArrowXml</code> is a subclass of <code>Arrow</code>, which describes some sort of machinery taking some input to some output. You can think of it like a big factory with conveyor belts taking things to different machines, and we're building these factory machines and hence factories with functions. Three of the Arrow combinators, for example, are:</p> <pre><code>(&amp;&amp;&amp;) :: (Arrow a) =&gt; a b c -&gt; a b c' -&gt; a b (c, c') |infixr 3| Fanout: send the input to both argument arrows and combine their output. arr :: (Arrow a) =&gt; (b -&gt; c) -&gt; a b c Lift a function to an arrow. (.) :: (Category cat) =&gt; cat b c -&gt; cat a b -&gt; cat a c morphism composition. </code></pre> <p>Now look at the lowercase letter (type variable) very closely in:</p> <pre><code>(+=) :: (ArrowXml a) =&gt; a b XmlTree -&gt; a b XmlTree -&gt; a b XmlTree </code></pre> <p>Clearly we're taking two machines which turn <code>b</code>s into <code>XmlTree</code>s and "merging them together" into one machine which takes a <code>b</code> in and expels an <code>XmlTree</code>. But importantly, this type signature tells us that more or less the <strong>only</strong> way that this can be implemented is:</p> <pre><code>arr1 += arr2 = arr f . (arr1 &amp;&amp;&amp; arr2) where f :: (XmlTree, XmlTree) -&gt; XmlTree f = _ </code></pre> <p>This is because of "free theorems"; if you don't know the type of a parameter then we can prove that you can't really <em>do</em> much with it. (It can be a little more complicated because the arrow might have structures which aren't totally encapsulated by <code>arr</code>, like internal counters which are summed together with <code>.</code> which are then set to <code>0</code> when using <code>arr</code>. So actually replace <code>arr f</code> with a generic <code>a (XmlTree, XmlTree) XmlTree</code> and you're good to go.)</p> <p>So we must have <strong>parallel execution</strong> of the two arrows here. That's what I'm trying to say. Because the combinator <code>(+=)</code> doesn't know what <code>b</code> is, it has no choice but to blithely feed the <code>b</code> to the arrows in parallel and then try to combine their outputs together. So, <code>deep (hasName "bar")</code> does not look at <code>foo</code>.</p> <p>You can possibly make a mutually recursive solution with <code>deep (hasName "bar") . foo</code> if you really want, but it seems potentially dangerous (i.e. infinite loop), so it may be safer to simply define something like:</p> <pre><code>a ++= b = a += (b . a) </code></pre> <p>where the "current" a is "fed" to b to produce the update. To do this you will have to import <code>.</code> from <code>Control.Category</code> as it is not the same as <code>Prelude..</code> (which does function composition only). This looks like:</p> <pre><code>import Prelude hiding ((.)) import Control.Category ((.)) </code></pre>
13,616,399
0
<p>First, I'd better do it on SQL Server side :)<br> But if you don't want or cannot to do it on server side you can use this approach:</p> <p>It is obvious that you need to store SessionID somewhere you can create a txt file for that or better some settings table in SQL Server or there can be other approaches.</p> <p>To add columns <code>SessionID</code> and <code>TimeCreated</code> to OLE Destination you can use <a href="http://www.dotnetfunda.com/articles/article1233-use-of-derived-column-in-ssis.aspx" rel="nofollow">Derived columns</a></p>
32,709,481
0
UIViewController no longer has members topViewController or viewControllers in XCode 7 <p>After updating to XCode 7 and converting my project to the latest Swift 2 syntax, there is one error I cannot seem to fix. I have a segue to a navigation controller and need to pass data to the top view controller in its stack. The following has always worked until now:</p> <pre><code>override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let destinationVC = segue.destinationViewController.viewControllers[0] as! MYViewController // OR let destinationVC = segue.destinationViewController.topViewController as! MYViewController // ... } </code></pre> <p>But now the compiler gives error: </p> <p><code>Value of type 'UIViewController' has no member 'viewControllers'</code> or <code>Value of type 'UIViewController' has no member 'topViewController'</code></p> <p>I do not see how else to access the view controller(s) on the stack. Any ideas? Thanks in advance!</p>
33,894,262
0
<p>Take a look at the OpenCV doc:</p> <p>For <a href="http://docs.opencv.org/master/dd/d1a/group__imgproc__feature.html#ga04723e007ed888ddf11d9ba04e2232de" rel="nofollow">Canny</a>:</p> <blockquote> <p><strong>apertureSize:</strong> aperture size for the Sobel operator.</p> </blockquote> <p>And for <a href="http://docs.opencv.org/master/d4/d86/group__imgproc__filter.html#gacea54f142e81b6758cb6f375ce782c8d" rel="nofollow">Sobel</a>:</p> <blockquote> <p><strong>ksize:</strong> size of the extended Sobel kernel; it must be 1, 3, 5, or 7.</p> </blockquote> <p>So the aperture size in <code>Canny</code> is limited by the <code>Sobel</code> kernel size.</p> <p>This is verified in the <a href="https://github.com/Itseez/opencv/blob/master/modules/imgproc/src/canny.cpp#L609-L610" rel="nofollow">source code</a> :</p> <pre><code> if ((aperture_size &amp; 1) == 0 || (aperture_size != -1 &amp;&amp; (aperture_size &lt; 3 || aperture_size &gt; 7))) CV_Error(CV_StsBadFlag, "Aperture size should be odd"); </code></pre> <p>So, unless you rewrite yourself some code, there's no way to use Canny with a larger aperture size. You can apply your custom <em>large sobel filter</em> with <a href="http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/filter_2d/filter_2d.html" rel="nofollow">filter2d</a>, and then code the Canny non maxima suppression.</p> <p>However, Sobel with mask larger then 3x3 is rarely used in practice.</p>
11,651,167
0
Connection R to Cassandra using RCassandra <p>I have an instance of Cassandra running on my localhost. For this example I have used the default configuration provided in conf\cassandra.yaml</p> <p>I tried to connect R to Cassandra using the RCassandra package. </p> <p>Basically, i have just installed the RCassandra package in R and tried to connect.</p> <pre><code>library("RCassandra") RC.connect('localhost','9160') RC.connect('127.0.0.1','9160') </code></pre> <p>None of those are working. Here is the error I get:</p> <pre><code>Error in RC.connect("localhost", port = "9160") : cannot connect to locahost:9160 </code></pre> <p>Using Cassandra-cli with the same parameters work. Can you please help on that.</p> <p>Thank you</p>
34,436,956
0
<p>Use a transparent <code>border</code> on all the other <code>&lt;li&gt;</code> to make it good.</p> <pre><code>ul.menu li { float: left; list-style-type: none; border: 2px solid transparent; } </code></pre> <p><strong>Fiddle: <a href="https://jsfiddle.net/8cu4bL3s/" rel="nofollow">https://jsfiddle.net/8cu4bL3s/</a></strong></p>
33,529,333
0
<p>Yes, validators are only run if the path is changed, and they also only run if they're not <code>undefined</code>. Except the Required validator, which runs in both cases. </p>
17,025,966
0
<p>You can use <a href="http://docs.oracle.com/javase/6/docs/api/java/util/List.html#removeAll%28java.util.Collection%29" rel="nofollow"><code>boolean removeAll(Collection&lt;?&gt; c)</code></a> method.</p> <p>Just note that this method modifies the <code>List</code> on which you invoke it. In case you to keep the original <code>List</code> intact then you would have to make a copy of the list first and then the method on the copy.</p> <p>e.g.</p> <pre><code>List&lt;Employee&gt; additionalDataInListA = new ArrayList&lt;Employee&gt;(listA); additionalDataInListA.removeAll(listB); </code></pre>
33,362,460
0
Does every view have its own canvas/bitmap to draw on? <p>I have a relativelayout with three full screen child views of the same custom view class. I am wondering whether I should be worried about memory. Judging by this answer: <a href="http://stackoverflow.com/questions/4576909/understanding-canvas-and-surface-concepts">Understanding Canvas and Surface concepts</a></p> <p>All views get passed the same canvas with underlying bitmap to draw on so that the memory is not tripled. Can anyone confirm? It would make sense, otherwise a full screen textview would be very inefficient. </p> <p>Bonus: is the purpose of canvas to define a drawable area of a bitmap and translating the view coordinates to bitmap coordinates?</p>
7,438,401
0
MySQL REPLACE rows WHERE field a equals x and field b equals y <p>I'm trying to construct a 'new comments' feature where the user is shown the number of new comments since the last visit. I've constructed a 'Views' table that contains the topic id, the user id and a timestamp. What's the best way of updating the timestamp every time the user visits that topic or inserting a fresh row if one doesn't exist? At the moment I have:</p> <pre><code>REPLACE INTO Views (MemberID, TopicID, Visited) SET ('$_SESSION[SESS_MEMBER_ID]', '$threadid', '$t') WHERE MemberID = $_SESSION[SESS_MEMBER_ID] AND TopicID = $threadid </code></pre> <p>However, this does not work. Is it possible to do this in one query?</p>
20,804,034
0
<p>I placed this as an edit in Alex's answer, it did not get reviewed though so I'll post it here, as it is useful information imho.</p> <p>You can also pass a vector of Points, makes it easier to do something with them afterwards:</p> <pre><code>std::vector&lt;cv::Point2i&gt; locations; // output, locations of non-zero pixels cv::findNonZero(binaryImage, locations); </code></pre> <p>One note for the <code>cv::findNonZero</code> function in general: if <code>binaryImage</code> contains zero non-zero elements, it will throw because it tries to allocate '1 x n' memory, where n is <code>cv::countNonZero</code>, and n will obviously be 0 then. I circumvent that by manually calling <code>cv::countNonZero</code> beforehand but I don't really like that solution that much.</p>
3,074,100
0
<p>solved:</p> <p>remove <code>margin-bottom:10px;</code> from your </p> <pre><code> .itemsWrapper { margin-bottom:10px; overflow:auto; width:100%; background: green; } </code></pre> <p><a href="http://jsbin.com/ajoka/11" rel="nofollow noreferrer">http://jsbin.com/ajoka/11</a></p>
19,128,203
0
<p>JayData does <strong>NOT</strong> track complex types (like arrays or custom type objects) inner values.. It just tracks the reference to the value.</p> <p>In case you want to force the update in this case, you have to make a "deep copy" or encapsulate you current object into another one for the reference to change. For example using jQuery:</p> <pre><code>entity.field = jQuery.extend({}, field); </code></pre> <p>Nothing really changes for your object values, but it gets encapsulated in jQuery's object and the reference has changed, so JayData thinks it's value has changed and sends the updated values to the server.</p> <p>It is a workaround, but as my friend said: "Do you really care about how much <strong><em>clients'</em></strong> CPU you use?" :)</p>
39,083,635
0
How to use HttpClient to connect to an API that is expecting a custom type? <p>I have a .net controller that accepts POST events. It is expecting 2 dates from the client system(c# console app).</p> <p>How can I connect to this controller and send the needed data if the console app does not know anything about the ContestDates class?</p> <p>Here is the controller:</p> <pre><code>public class ContestDates { public DateTime FirstDate { get; set; } public DateTime SecondDate { get; set; } } [HttpPost("api/contestDates/random")] public IActionResult PostRandomDates(ContestDates contestDates) { //do stuff with contestDates... return Ok(); } </code></pre> <p>Thanks!</p>
27,805,043
0
<p>I know this is an old post, but I was able to get rid of the error by commenting out the call to "strip_save_dsym" from tools/strip_from_xcode line 61ish. I have no idea if that still creates a proper build, but it does clear out the errors. Here is the link that lead me to this <a href="http://www.magpcss.org/ceforum/viewtopic.php?f=6&amp;t=701#p2869" rel="nofollow">fix</a>.</p>
16,327,293
0
<p>Just do this:</p> <pre><code>if ($var[strlen($var) - 1] == "?") { $var = substr($var, 0, strlen($var) - 1); } </code></pre>
14,158,927
0
<p>Hi try it using Converter</p> <pre><code> public class BoolToColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is bool &amp;&amp; (bool)value) return new SolidColorBrush(Colors.Red); else return null; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } &lt;Window.Resources&gt; &lt;conv:BoolToColorConverter x:Key="boolToColorConverter"/&gt; &lt;/Window.Resources&gt; &lt;GridViewColumn Header="Product" Width="60" DisplayMemberBinding="{Binding ProductID}" BackGround="{Binding Equality, Converter={StaticResource boolToColorConverter}}" /&gt; </code></pre> <p>I hope this will give you an idea.</p>
15,531,622
0
<p>It would be better if you sorted the objects you are populating richtextbox1 with instead of trying to split and parse the text of richtextbox1.</p> <p>Lets say you have a list with students</p> <pre><code>List&lt;Student&gt; studentList = new List&lt;Student&gt;(); </code></pre> <p>That list could be sorted by using something similar to this:</p> <pre><code>StringBuilder sb = new StringBuilder(); studentList.OrderByDescending(x=&gt;x.Average) .ToList() .ForEach(x=&gt; sb.Append(String.Format("{0} {1} {2} {3} {4}" + Environment.NewLine,x.Id,x.Name,x.Sname,x.DOB,x.Average))); richTextBox2.Text = sb.ToString(); </code></pre>
7,523,215
0
Serializing Tree into nested list using python <p>I have a binary tree class like this:</p> <pre><code>class BinaryTree: def __init__(self, data, left=None, right=None): self.data = data self.left = left self.right = right </code></pre> <p>Now I'm facing a task to serialize this structure in to a nested list. BTW, I have a left-to-right traversal function in mind:</p> <pre><code>def binary_tree(tree): if tree: for node_data in binary_tree(tree.left): yield node_data for node_data in binary_tree(tree.right): yield node_data </code></pre> <p>Or there is a general way to serialize it into mixed nested structure? For example, {[]}, or [{}]?</p>
2,388,141
0
<p>I used to be a Java programmer, When I moved to C/C++ I enjoyed using <a href="http://www.eclipse.org/cdt/" rel="nofollow noreferrer">Eclipse CDT</a>, it is a good, customizable and powerful IDE. <a href="http://qt.nokia.com/products" rel="nofollow noreferrer">QtCreator</a> is another nice full Qt integrated tool.</p>
1,437,503
0
<p>Once you harvest the links, you can use <a href="http://it2.php.net/curl" rel="nofollow noreferrer">curl</a> or file_get_contents (in a safe environment file_get_contents shouldn't allow to walk over http protocol though)</p>
38,863,200
0
<p><code>do/try/catch</code> will catch errors that are thrown by some other method, but it won't catch runtime exceptions, such as you are getting from the forced downcast. For example, if <code>data</code> was invalid JSON then an error will be thrown and caught. In your case it seems the JSON is valid, but it is a dictionary, not an array. </p> <p>You want something like </p> <pre><code>setQA = nil do { if let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as? [AnyObject] { setQA = json print(setQA) } else { self.customAlert("Invalid response from server") } } catch _ { self.customAlert("Error parsing JSON") } </code></pre>
13,745,347
0
Make whole <li> as link with proper HTML <p>I know this has been up a lot of times before, but I couldn't find any solution in my specific case.</p> <p>I've got a navigation bar and I want the whole <code>&lt;li&gt;</code>'s to be "linked" or "clickable" if you will. Now only the <code>&lt;a&gt;</code> (and the <code>&lt;div&gt;</code>'s I've fiddled with) is "clickable".</p> <p>I've tried the <code>li a {display: inner-block; height: 100%; width: 100%}</code> method but the results where just horrible.</p> <p>The source can be found here: <a href="http://jsfiddle.net/prplxr/BrcZK/">http://jsfiddle.net/prplxr/BrcZK/</a></p> <h2>HTML</h2> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;asdf&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="wrapper"&gt; &lt;div id="menu"&gt; &lt;div id="innermenu"&gt; &lt;ul id="menulist"&gt; &lt;li class="menuitem"&gt;&lt;a href="index.php"&gt;&lt;div class="menulink"&gt;Lnk1&lt;/div&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="menuitem"&gt;&lt;a href="index.php"&gt;&lt;div class="menulink"&gt;Lnk2&lt;/div&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="menuitem"&gt;&lt;a href="index.php"&gt;&lt;div class="menulink"&gt;Lnk3&lt;/div&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="menuitem"&gt;&lt;a href="index.php"&gt;&lt;div class="menulink"&gt;Lnk4&lt;/div&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Do anyone have a neat solution to this?</p> <p>Thank you in advance!</p>
33,195,084
0
<p>Possibly add three divs inside your first. each with their own .png?</p> <pre><code>&lt;div&gt; &lt;div id="blue" style="z-index: 1;"&gt;&lt;img src="blue.png"&gt;&lt;/div&gt; &lt;div id="yellow"style="z-index: 2;"&gt;&lt;img src="yellow.png"&gt;&lt;/div&gt; &lt;div id="red" style="z-index: 1;"&gt;&lt;img src="red.png"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre>
40,684,641
0
<p>Maybe an idea which might work for you:</p> <p>To ban a user, create an entry in your database to the user to flag the user as banned with a timestamp NOW + X</p> <pre><code>{ "users" : { "bad_user" : { "banned" : { "until" : 123456 // timestamp NOW + X } } } } </code></pre> <p>Now whenever the user logs in afterwards, you check wether the user is banned and immediately try to delete that entries. If it fails, penalty time is still running. If it succeeds, well then the user can use your app :)</p> <p>The trick is to use firebase rules to restrict possible changes.</p> <p>something like:</p> <pre><code>{ "rules" : { "users" : { "$uid" : { // ... "banned" : { .write : "(!newData &amp;&amp; now &lt; data.child('until').val() )" .... </code></pre> <p>Please note - these are not working rules, but should help to figure it out.</p>
1,953,654
0
<p>That's the simplest way to do it; don't be disappointed.</p>
35,160,200
0
Express & Passport with multiple subdomains <p>I'm merging two little apps into one, that is supposed to be accessed via two subdomains. To do so I'm using the module "express-subdomain". I'm trying to use Passport so when a user logs in in the first app, he is logged in in both apps. However using <code>req.isAuthenticated()</code> I can indeed login in the "first" app, but then I'm not in the "second" one.</p> <p>I'm searching for any solution to have a passport authentification in the first subdomain and being logged in in the second one, including keeping two disctinct apps if needed.</p> <p>Assuming that passport is correctly configured for a local strategy, as well as the routers and the rest of the app. Here is what it looks like :</p> <p><strong>app.js</strong></p> <pre><code>// &lt;- requires etc var passport = require('./configurePassport.js')(require('passport')); var app = express(); app.use(cookieParser()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); app.use(expressSession({ secret: 'bestSecretEver', resave: false, saveUninitialized: false })); app.use(passport.initialize()); app.use(passport.session()); // and others var firstRouter = express.Router(); firstRouter.use('/public', express.static(__dirname + '/first/public')); firstRouter.use(favicon(__dirname + '/first/public/favicon.ico')); // &lt;- setting first router's GET, POST etc app.use(subdomain('sub1', firstRouter)); // for sub1.example.com var secondRouter = express.Router(); secondRouter.use('/public', express.static(__dirname + '/second/public')); secondRouter.use(favicon(__dirname + '/second/public/favicon.ico')); // &lt;- setting second router's GET, POST etc app.use(subdomain('sub2', secondRouter)); // for sub2.example.com </code></pre> <p>Any idea ?</p>
34,063,937
0
<p>You can use a form inside your application. And, ask users to fill that form. The forms needs to be connected to an database server. You may use 000webhost.com (free) to create your database. Just populate the table in database from the user response. For this follow the following procedure: <br>1. Create a online database (000webhost.com) <br>2. Write php code to insert data into the database form and save that php on the file manager on server. <br>3. From android create a async task to execute that php. <br>4. Pass your parameter or user response as request attributes while executing the php. <br>5. php will save user's response on your server. <br> Now you can access that database from anywhere.</p> <p>Note: This may require an internet connection in application.</p>
3,379,561
0
Integrate an E-Mail server into ASP.NET <p>I've a general design question:<br /> <br /> I have a mailserver, written in C#.<br /> Then I have a web forum software, written in for ASP.NET in C#.<br /> <br /> Now I'd like to integrate the mailserver into the ASP.NET forum application. For example, I'd like to make it possible that one can create a mailinglist from the forum, and give users the oportunity to add oneselfs to the mailinglist members in the forum, and then add the new list-members to the respective mailinglist on the server.</p> <p>Since the server is a separate console/winforms/service application, I first thought I'd best use .NET remoting for this.</p> <p>But my second thought was, that some users might host their forum on a host where <br /> (a) they don't have a virtual machine where they can do what they want<br /> (b) the admin of the host might not want to install an additional mailserver or charge extra for this<br /> (c) the user might have a service plan that only permits to add a web-application, not external programs (very likely)<br /> <br /><br /> Now, I wanted to ask:<br /> Is it possible to fully integrate a mailserver into an ASP.NET application somehow ? (I have the full source of the server + ASP.NET application)</p> <p>Well, it probably won't be a page or a ashx handler, but something like a http module ? Or what's the general way to integrate TCP/IP applications into asp.net ? (Of course I'm assuming the respecive ports are available/forwarded - and I'll make it possible to also run it with the e-mail server as external application)</p>
31,186,164
0
<p>I finally decided to switch to AVPlayer</p> <p>setCurrentPlayback is</p> <pre><code>int32_t timeScale = playerView.currentItem.asset.duration.timescale; CMTime time = CMTimeMakeWithSeconds(value, timeScale); [playerView seekToTime:time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero]; </code></pre> <p>Duration is</p> <pre><code>CMTime duration = playerView.currentItem.asset.duration; float seconds = CMTimeGetSeconds(duration); </code></pre> <p>Same pause and Play functions.</p>
7,020,453
0
<p>There is an equation given <a href="http://math.stackexchange.com/questions/41940/is-there-an-equation-to-describe-regular-polygons/41946#41946">here</a> (the last one).</p> <p>By looping over all the x and y coordinates, and checking that the output of this equation is less than zero, you can determine which points are 'inside' and colour them appropraitely.</p>
37,776,272
0
Why invariant generic type parameterized with subclass of upper bounds fails to conform? <p>Given:</p> <pre><code>class Invar[T] trait ExtendsAnyref extends AnyRef def f(a: Invar[ExtendsAnyref]) = {} </code></pre> <p>The following is erroneous</p> <pre><code>scala&gt; val x: Function1[Invar[_ &lt;: AnyRef], Unit] = f &lt;console&gt;:13: error: type mismatch; found : Invar[ExtendsAnyref] =&gt; Unit required: Invar[_ &lt;: AnyRef] =&gt; Unit val x: Function1[Invar[_ &lt;: AnyRef], Unit] = f ^ </code></pre> <p>Why?</p> <p>I understand that in Scala, generic types have by default nonvariant subtyping. Thus, in the context of this example, instances of <code>Invar</code> with different type parameters would never be in a subtype relationship with each other. So an <code>Invar[ExtendsAnyref]</code> would not be usable as a <code>Invar[AnyRef]</code>.</p> <p>But I am confused about the meaning of <code>_ &lt;: AnyRef</code> which I understood to mean "some type below <code>AnyRef</code> in the type hierarchy." <code>ExtendsAnyref</code> is some type below <code>AnyRef</code> in the type hierarchy, so I would expect <code>Invar[ExtendsAnyref]</code> to conform to <code>Invar[_ &lt;: AnyRef]</code>.</p> <p>I understand that function objects are contravariant in their input-parameter types, but since I use <code>Invar[_ &lt;: AnyRef]</code> rather than <code>Invar[AnyRef]</code> I understood, apparently incorrectly, the use of the upper bounds would have the meaning "<code>Invar</code> parameterized with <code>Anyref</code> or any extension thereof."</p> <p>What am I missing?</p>
30,061,259
0
<p>To allow nice zooming you should add this line to the two you show:</p> <pre><code>chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Zoomable = true; </code></pre> <p>Here is a function to calculate an average of the visible points' 1st YValues:</p> <pre><code>private void chart1_AxisViewChanged(object sender, ViewEventArgs e) { // for a test the result is shown in the Form's title Text = "AVG:" + GetAverage(chart1, chart1.Series[0], e); } double GetAverage(Chart chart, Series series, ViewEventArgs e) { ChartArea CA = e.ChartArea; // short.. Series S = series; // references DataPoint pt0 = S.Points.Select(x =&gt; x) .Where(x =&gt; x.XValue &gt;= CA.AxisX.ScaleView.ViewMinimum) .DefaultIfEmpty(S.Points.First()).First(); DataPoint pt1 = S.Points.Select(x =&gt; x) .Where(x =&gt; x.XValue &lt;= CA.AxisX.ScaleView.ViewMaximum) .DefaultIfEmpty(S.Points.Last()).Last(); double sum = 0; for (int i = S.Points.IndexOf(pt0); i &lt; S.Points.IndexOf(pt1); i++) sum += S.Points[i].YValues[0]; return sum / (S.Points.IndexOf(pt1) - S.Points.IndexOf(pt0) + 1); } </code></pre> <p>Note that the <code>ViewEventArgs</code> parameter is providing the values of the position and size of the View, but these are just the <code>XValues</code> of the datapoints and not their indices; so we need to search the <code>Points</code> from the left for the 1st and from right for the last point.</p> <p><strong>Update</strong> Sometimes the zooming runs into a special problem: When the data are more finely grained than the default <code>CursorX.IntervalType</code> it just won't let you zoom. In such a case you simply have to adapt to the scale of your data, e.g. like this: <code>CA.CursorX.IntervalType = DateTimeIntervalType.Milliseconds;</code></p>
26,761,856
0
Rounding error on percent of total and back <p>A and B are integers.</p> <p>Is it <strong>certain</strong>, with all the complexities of rounding errors in JavaScript, that:</p> <p><code>(A/(A+B))*(A+B) === A</code></p> <p>This is to say that if the user enters 10, and 20 for A and B respectively, can I store the summed total (30) with A = .33333333 and B = .66666666 and later multiply the sum by these decimals to get back to the value of 10 (with no rounding error)?</p>
25,184,607
1
Sort a dictionary of arrays in python with a tuple as the key <p>I a dictionary with a string tuple as the key and an array as the value:</p> <pre><code>some_dict = {} some_dict[(A,A)] = [1234, 123] some_dict[(A,B)] = [1235, 13] some_dict[(A,C)] = [12, 12] some_dict[(B,B)] = [12621, 1] ... </code></pre> <p>I am writing this to a csv file:</p> <pre><code>for k,v in some_dict.iteritems(): outf.write(k[0]+","+k[1]+","+str(v[0])+","str(v[1])+"\n") </code></pre> <p>output:</p> <pre><code>A,A,1234,123 A,B,1235,13 A,C,12,12 B,B,12621,1 </code></pre> <p>I'd like to sort it based on the first number "column" before writing to a file (or after and just rewrite?) so the output should be like:</p> <pre><code>B,B,12621,1 A,B,1235,13 A,A,1234,123 A,C,12,12 ^ Sorted on this 'column' </code></pre> <p>How do I do this? The file is very large, so doing it before writing would be better I think.</p>
15,818,792
0
<p>I installed JRE version 6 on my machine and this cleared the problem. (I previously had version 7 on the machine.)</p>
17,990,096
0
<h2>Focus Handling</h2> <p>Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer. </p> <p>Change default behaviour of directional navigation by using following XML attributes:</p> <pre><code>android:nextFocusDown="@+id/.." android:nextFocusLeft="@+id/.." android:nextFocusRight="@+id/.." android:nextFocusUp="@+id/.." </code></pre> <p>Besides directional navigation you can use tab navigation. For this you need to use</p> <pre><code>android:nextFocusForward="@+id/.." </code></pre> <p>To get a particular view to take focus, call </p> <pre><code>view.requestFocus() </code></pre> <p>To listen to certain changing focus events use a <a href="http://developer.android.com/reference/android/view/View.OnFocusChangeListener.html"><code>View.OnFocusChangeListener</code></a></p> <hr> <h2>Keyboard button</h2> <p>You can use <a href="http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions"><code>android:imeOptions</code></a> for handling that extra button on your keyboard.</p> <blockquote> <p>Additional features you can enable in an IME associated with an editor to improve the integration with your application. The constants here correspond to those defined by imeOptions. </p> </blockquote> <p>The constants of imeOptions includes a variety of actions and flags, see the link above for their values. </p> <p><strong>Value example</strong></p> <p><a href="http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_NEXT">ActionNext</a> : </p> <blockquote> <p>the action key performs a "next" operation, taking the user to the next field that will accept text.</p> </blockquote> <p><a href="http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_MASK_ACTION">ActionDone</a> :</p> <blockquote> <p>the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.</p> </blockquote> <p><strong>Code example:</strong></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" tools:context=".MainActivity" &gt; &lt;EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="32dp" android:layout_marginTop="16dp" android:imeOptions="actionNext" android:singleLine="true" android:ems="10" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1" android:layout_below="@+id/editText1" android:layout_marginTop="24dp" android:imeOptions="actionDone" android:singleLine="true" android:ems="10" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>If you want to listen to imeoptions events use a <a href="http://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html"><code>TextView.OnEditorActionListener</code></a>. </p> <pre><code>editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { performSearch(); return true; } return false; } }); </code></pre> <hr>
20,531,709
0
<p>Not that familiar with how you query the db, but you probably have iterate over the result set like this:</p> <pre><code>&lt;table&gt; @foreach(var n in nilstock) { &lt;tr&gt;&lt;td&gt;@n.STOCKCODE&lt;/td&gt;&lt;td&gt;@n.TOTALSTOCK&lt;/td&gt;&lt;/tr&gt; } &lt;table&gt; </code></pre>
14,141,611
0
<pre><code>&lt;div id = "container"&gt; &lt;div id="header"&gt;&lt;/div&gt; &lt;div id="content"&gt;&lt;/div&gt; &lt;div id="footer"&gt;&lt;/div&gt; &lt;/div&gt; #container {min-width:620px;} </code></pre> <p>See example: <a href="http://jsfiddle.net/calder12/xN2PV/3/" rel="nofollow">http://jsfiddle.net/calder12/xN2PV/3/</a></p> <p>Point to note. min-width is not supported in IE6. I doubt this matters, if it does you'll need a different solution.</p>
2,777,887
0
What's wrong with my logic (Java syntax) <p>I'm trying to make a simple program that picks a random number and takes input from the user. The program should tell the user if the guess was hot (-/+ 5 units) or cold, but I never reach the else condition.</p> <p>Here's the section of code:</p> <pre><code> public static void giveHint (int guess) { int min = guess - 5; int max = guess + 5; if ((guess &gt; min) &amp;&amp; (guess &lt; max)) { System.out.println("Hot.."); } else { System.out.println("Cold.."); } } </code></pre>
20,846,012
0
<p>This should work for you. Check out the in-line comments.</p> <pre><code># 1. Let's assume the folder c:\test contains a bunch of plain text files # and we want to find only the ones containing 'foo' AND 'bar' $ItemList = Get-ChildItem -Path c:\test -Filter *.txt -Recurse; # 2. Define the search terms $Search1 = 'foo'; $Search2 = 'bar'; # 3. For each item returned in step 1, check to see if it matches both strings foreach ($Item in $ItemList) { $Content = $null = Get-Content -Path $Item.FullName -Raw; if ($Content -match $Search1 -and $Content -match $Search2) { Write-Host -Object ('File ({0}) matched both search terms' -f $Item.FullName); } } </code></pre> <p>After creating several test files, my output looks like the following:</p> <pre><code>File (C:\test\test1.txt) matched both search terms </code></pre>
19,610,950
0
<p>Instead of doing this: <code>public static final TitleType MR = new TitleType(1, "Mr");</code></p> <p>You should use the EntityManager to fetch that Object. Otherwhise Hibernate will notice, that this Object (with id 1) is already stored, but since you did not load it, the entity manager does not have it inside its own collection -> that's a detached entity.</p> <p>So, you should do:</p> <pre><code>TitleType MR = em.find(TitleType.class, 1); Person p = new Person(...); p.setTitleType(MR); em.merge(p); </code></pre>
21,383,203
0
<p>Your input text is full of a mix of word and non-word characters, so the only way to determine a word boundary is to look behind and ahead for spaces:</p> <pre><code>re.findall(ur'(?&lt;![^ ])เดตเดฟ[^ ]+เดฃเต?(?![^ ])', inputtext, flags=re.UNICODE) </code></pre> <p>where <code>inputtext</code> is a Unicode value. The <code>(?&lt;!...)</code> and <code>(?!...)</code> are negative lookbehind and lookahead assertions; the match locations in the text that are <em>not</em> preceded or followed by a non-space character, respectively.</p> <p>Within your boundary text, we match non-spaces as well.</p> <p>This matches your expected input:</p> <pre><code>&gt;&gt;&gt; print re.findall(ur'(?&lt;![^ ])เดตเดฟ[^ ]+เดฃเต?(?![^ ])', inputtext, flags=re.UNICODE)[0] เดตเดฟเดšเดพเดฐเดฃ </code></pre>
8,830,512
0
how create simple side menu with jquery? <p>i have menu in side location and that code is : </p> <pre><code>&lt;ul&gt; &lt;li&gt; &lt;span class="arz"&gt; first menu &lt;/span&gt; &lt;ul id="arz"&gt; &lt;li&gt; first submenu &lt;/li&gt; &lt;li&gt; second submenu &lt;/li&gt; &lt;li&gt; third submenu &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="words"&gt; two menu &lt;ul id="words"&gt; &lt;li&gt; first submenu &lt;/li&gt; &lt;li&gt; second submenu &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; </code></pre> <p></p> <p>and jquery code is : </p> <pre><code>$(document).ready(function(){ $(".submenu").click(function(){ $(this).children(this).slideToggle("slow"); }); }); </code></pre> <p>but i want by clicking on <em>first menu</em> <code>ul</code> element with <code>id="arz" using</code>slideToggle<code>,<br> this code do it but when i click on every submenu item corresponding ul use</code>slideToggle`. by thanks<br> aya</p>
38,844,857
0
<p>You can try following</p> <pre><code>use tempdb create table #ttt ( c1 int identity not null, c2 int not null, c3 int default -1, c4 as (case when c3 &lt; 0 then c3+1 else c3 end), c5 as (case when c3 &lt; 0 then 'DEFAULT VALUE' else 'USER SUPPLIED' end) ) insert into #ttt values (10, 20) insert into #ttt values (11, 21) insert into #ttt (c2) values (20) select * from #ttt /*For selections, you can use */ Select C1, C2, C4 from #ttt </code></pre>
25,184,942
0
<p>Actually an array is a fixed pointer to the first element in the array (I think this is known as an L-value). This means your assignments at the end for the tempState, currState and nextState cannot work (as you have discovered).</p> <p>After declaring space for the 2 2d-arrays, you could then declare pointers to the 2d arrays which you might be able to work in a reasonable way. To use the pointers for indexing into the 2-d array, the compiler would need to be aware of the size of the last dimension(s) of the array.</p>
17,439,523
0
<pre><code>$('#element').keyUp(function(e){ var max = 2; var text = $(e.currentTarget).text().substring(0,max); $(e.currentTarget).text(text); }); </code></pre>
36,843,211
0
<p><code>RDD</code> is Apache Spark's abstraction for a <strong>Distributed Resilient Dataset</strong> </p> <p>To create an <code>RDD</code> you'll need an instance of <code>SparkContext</code>, which can be thought of as a "connection" or "handle" to a <em>cluster</em> running Apache Spark. </p> <p><strong>Assuming</strong>:</p> <ul> <li>You have an instantiated <code>SparkContext</code></li> <li>You want to treat your input as a "flat" sequence of <code>(Double, Double)</code> values, <em>ignoring</em> the way these are currently "split" into sub-sequences in <code>Seq[Seq[(Double, Double)]]</code></li> </ul> <p>You can create an RDD as follows:</p> <pre><code>val sc: SparkContext = ??? val output: Seq[Seq[(Double, Double)]] = ??? val rdd: RDD[(Double, Double)] = sc.parallelize(output.flatten) </code></pre>
40,985,875
0
Getters, Setters and Constructors in Java - Making a car and stocking it <p>I'm trying to create a class in Java using BlueJ. My class is named Automobile. My goal is to be able to use my Constructor method to create cars with the variables: year, color, brand, number of doors, number of kilometers, if it's automatic (boolean), if it's sold (boolean), a description, and an identification number. All the variables have a set default value, a minimum and a maximum accepted value.</p> <p>I have to use getVariablename and setVariablename for my methods. My color and brand variables are int, and I made methods to retrieve their String counterparts in a table in my class. </p> <p>My issue is I don't understand the principle of setting my variable in one method and getting it in another (while making sure it's an accepted value). Also, once I have my Setter and Getter method, what do I have to write down in the creation of my Constructor method?</p> <p>Up to now, I have this :</p> <pre><code>public class Automobile { private static final String[] COLORS = { "Other", "Noir", "Blanc", "Bleu Nuit", "Bleu Clair", "Vert Pomme", "Vert Bouteille", "Taupe", "Argent", "Sable"}; private static final String[] BRANDS = { "Autre", "Mazda", "Toyota", "Ford", "GM", "Hyunday", "BMW", "SAAB", "Honda"}; public static final int COLOR_DEF = 8; public static final int COLOR_MIN = 0; public static final int COLOR_MAX = COULEURS.length - 1; public static final int BRAND_DEF = 4; public static final int BRAND_MIN = 0; public static final int BRAND_MAX = MARQUES.length - 1; public static final double KILO_DEFAULT = 55000; public static final double KILO_MIN = 15000; public static final double KILO_MAX = 140000; public static final int TWO_DOORS = 2; public static final int FOUR_DOORS = 4; public static final int DOORS_DEFAULT = FOUR_DOORS; public static final boolean AUTO_DEF = true; public static final int YEAR_MIN = 1997; public static final int YEAR_MAX = 2016; public static final int YEAR_DEFAUT = 2007; public static final String COMM_DEFAUT = ""; public static String color (int cou) { String chainecolor = ""; if (cou &gt;= COLOR_MIN &amp;&amp; cou &lt;= COLOR_MAX) { chainecolor = COLORS[cou]; } return chainecolor; } //This method is to return the String value of a color from its int value using the COLORS table. If invalid it returns an empty chain. public static String brand (int br) { String chainebrand = ""; if (ma &gt;= BRAND_MIN &amp;&amp; ma &lt;= BRAND_MAX) { chainebrand = BRANDS[br]; } return chainebrand; } //same thing for the brand public Automobile (int brand, int year, int color, boolean automatic, double kilometers,int nbrDoors, String description, boolean sold){ //To be completed } //here i'm supposed to create getters that return int values for everything but automatic, sold and description public void setYear ( int year ) { if (year &gt;= YEAR_MIN &amp;&amp; YEAR &lt;= YEAR_MAX) { year = year; } } // supposed to be the setter for my year, as long as it's within the accepted values public void setMarque (int brand){ if (brand &gt;= BRAND_MIN &amp;&amp; brand &lt;= BRAND_MAX) { brand = brand; } } //same, for the brand public void setColor (int color) { if (color &gt;= COLOR_MIN &amp;&amp; color &lt;= COLOR_MAX){ color = color; } }// same for the color public void setNbrDoors (int p) { if (p == TWO_DOORS || p == FOUR_DOORS){ p = p; } } // same for the door. I am forced to use (int p) as the variable for this method, which confuses me as to how I will refer to it from nbrDoors up in the Automobile constructor method } // Automobile </code></pre> <p>So my difficulties lie in: </p> <ul> <li><p>Are the examples of setters that I made valid for this purpose? I do not understand the need for p = p, or color = color...</p></li> <li><p>How do I create a getter method that will be able to go pick up the Variable p from setNbrDoors, return its value and have it be used for nbrDoors in the Automobile constructor?</p></li> <li><p>What am I supposed to write in the Constructor method, such as it will be able to get its values from the getters?</p></li> </ul> <p>This is all because the second part is I will have to create a little code to ask the user to input all the values for variables, then create a table to stock the Cars the user creates.</p> <p>P.S.: the work is originally in french, so I translated the variable and method names best I could for your better understanding. Also, the variable names, methods, etc are all imposed, I am FORCED to make the class this way exactly.</p> <p>EDIT: As such, the use of static for brand and color conversion are also imposed. Those 2 methods are solely for returning a String of character from an int value. they are not used in the Constructor. Finally, the exceptions will be handled in the second part of the work using a separate validation loop. The Automobile class is really used solely to handle the creation of the "car" object.</p>
13,319,747
0
How can i increment the counter? <p>At the registration time i wanted if side is left then my left count will increment and side is Right then my right is increment and both side is filled then their sponcor will increment... How can i do this????</p> <p>HERE i wanted to increment the my counter but it is not working propperly always counter show me null...., please tell me where m wrong.???</p> <pre><code>DECLARE @regid int SET @regid=@@IDENTITY DECLARE @RegistrationCode varchar(100) DECLARE registrationcodeCursor CURSOR FOR SELECT [dbo].[RegistrationCode] ( 'P4U',@fname,@mname,@lname,'000',@regid,'34',@dob ) OPEN registrationcodeCursor FETCH FROM registrationcodeCursor INTO @RegistrationCode CLOSE registrationcodeCursor DEALLOCATE registrationcodeCursor UPDATE Registration_Master SET regCode=@RegistrationCode WHERE registrationid=@regid DECLARE @regid1 int SET @regid1=@@IDENTITY DECLARE @usernm varchar(50) DECLARE usernameCursor CURSOR FOR SELECT [dbo].[fullusername] ( @fname,' ',@mname,' ',@lname ) OPEN usernameCursor FETCH FROM usernameCursor INTO @usernm CLOSE usernameCursor DEALLOCATE usernameCursor UPDATE Registration_Master SET username=@usernm WHERE registrationid=@regid1 --Pair Matching SET @count_mem=0 WHILE(@sponcorid!=NULL) BEGIN IF(@regCode !=NULL) BEGIN DECLARE @countl int IF(@side ='LEFT') BEGIN UPDATE Registration_Master SET @count_mem=@count_mem+1 WHERE regCode=@regCode AND side='LEFT' AND count_mem=@count_mem END DECLARE @countr int IF(@side='RIGHT') BEGIN UPDATE Registration_Master SET @count_mem=@count_mem+1 WHERE regCode=@regCode AND side='RIGHT' AND count_mem=@count_mem END IF(@countl=@countr) BEGIN UPDATE Registration_Master SET @count_mem=@count_mem+1 WHERE regCode=@regCode IF(@regCode!=NULL) BEGIN UPDATE Registration_Master SET @count_mem=@count_mem+1 WHERE sponcorid=@sponcorid AND count_mem=@count_mem END END END END SELECT registrationid, regCode, fname,mname,lname,username, p_password,question,answer, person_address, gender, sponcorid, dob,productname, payment, sponcorname, side, mobile, bankname, baccno, bankbranch, PAN, IFSC_code, email_id, member_status, count_mem,smart_pin,createddate, is_activate FROM Registration_Master WHERE registrationid=@@IDENTITY </code></pre>
12,194,433
0
Comparing variables inside a /F loop (BATCH) <p>I have this code:</p> <pre><code>@echo off SETLOCAL ENABLEDELAYEDEXPANSION SET /A counter=0 SET /A counter2=0 for /f %%h in (users.txt) do ( set /a counter2=0 set /a counter=!counter!+1 for /f %%i in (users.txt) do ( set /a counter2=!counter2!+1 IF !counter! gtr !counter2! echo !counter! and !counter2! ) ) </code></pre> <p>For some reason I the If statement in there errors. If I cross it out it all runs just fine. What's wrong with my syntax? Thanks!</p>
33,129,705
0
<p>You may try below query </p> <pre><code>SELECT DATEADD(MINUTE,(LEFT(@hour,2)*60+RIGHT(@hour,2)),@conductor_date) </code></pre>
8,551,762
0
Bind a popup to another draggable popup relatively <p>I use a jQuery UI dialog in which there is another pop-up. </p> <pre class="lang-js prettyprint-override"><code>$("#dialog").dialog({ autoOpen: false, show: "blind", hide: "explode" }); $("#opener").click(function() { $("#dialog").dialog("open"); return false; }); // BUTTONS $('.fg-button').hover(function() { $(this).removeClass('ui-state-default').addClass('ui-state-focus'); }, function() { $(this).removeClass('ui-state-focus').addClass('ui-state-default'); }); // MENUS $('#hierarchybreadcrumb').menu({ content: $('#hierarchybreadcrumb').next().html(), backLink: false }); </code></pre> <p>See here the live version: <a href="http://jsfiddle.net/nrWug/1" rel="nofollow">http://jsfiddle.net/nrWug/1</a></p> <p>If I open the iPod menu and than drag the dialog, the iPod menu is displaced. How can I bind these two to make the dialog draggable and resizable?</p>
16,530,501
0
<p>While you can change the VM sizes now as part of an in-place update, you should expect some instance downtime. The Windows Azure fabric controller will walk the upgrade domains, taking 1 upgrade domain down to change the VM sizes, and then moving on to the next. If you have 2 instances, you shouldn't have noticed an entire outage (just 1 machine going down at a time).</p> <p>You can see some further details at <a href="http://msdn.microsoft.com/en-us/library/windowsazure/hh472157.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windowsazure/hh472157.aspx</a>. </p>
1,905,416
0
<p>You can use spring with hibernate. You just need to make a bean for your hibernate configuration and load it using aop or bean name into your application startup.</p> <p>Here is a tutorial : <a href="http://www.roseindia.net/struts/hibernate-spring/spring-context.shtml" rel="nofollow noreferrer">http://www.roseindia.net/struts/hibernate-spring/spring-context.shtml</a> and another one : <a href="http://www.ibm.com/developerworks/web/library/wa-spring2/" rel="nofollow noreferrer">http://www.ibm.com/developerworks/web/library/wa-spring2/</a></p>
39,331,307
0
<p>Neo4j does not support storing another object as a nested property. Neo4j-OGM only supports </p> <blockquote> <p>any primitive, boxed primitive or String or arrays thereof, essentially anything that naturally fits into a Neo4j node property. </p> </blockquote> <p>If you want to work around that, you may need to create a custom type convertor. For example, </p> <pre><code>import org.neo4j.ogm.typeconversion.AttributeConverter class XYZ{ XYZ(Integer x, String y) { this.x = x this.y = y } Integer x String y } public class XYZConverter implements AttributeConverter&lt;XYZ, String&gt; { @Override public String toGraphProperty(XYZ value) { return value.x.toString() + "!@#" + value.y } @Override public XYZ toEntityAttribute(String value) { String[] split = value.split("!@#") return new XYZ(Integer.valueOf(split[0]), split[1]) } } </code></pre> <p>You can then annotate the @NodeEntity with a @Convert like this</p> <pre><code>@NodeEntity class Node { @GraphId Long id; @Property String name @Convert(value = XYZConverter.class) XYZ xyz } </code></pre> <p>On the flip side, its not a good practice to do this, since ideally you should link Node and XYZ with a 'hasA' relationship. Neo4j has been designed to optimally handle such kind of relationships, so it would be best to play with to strengths of neo4j</p>
29,054,976
0
Download in .zip file works with website image but not image from Amazon S3 with signed Url <p>I have an object with signed Urls to images on Amazon S3. My example is simplified to one image and my goal is to download a zip file with that image.</p> <p>This image works with my code in the variable <code>$fileUrl</code></p> <blockquote> <p><a href="http://google.com/images/logo.png" rel="nofollow">http://google.com/images/logo.png</a></p> </blockquote> <p>But not this (in variable <code>$fileUrl</code>), I get a corrupt .zip file. I can open the image in the browser with the signed url.</p> <blockquote> <p><a href="https://mybucketname.s3.amazonaws.com/94c70e8a-61f6-4f58-a4b7-1679df5a7c1f.jpg?response-content-disposition=attachment%3B%20filename%3D94c70e8a-61f6-4f58-a4b7-1679df5a7c1f.jpg&amp;AWSAccessKeyId=AKIAJNY3GPOFFLQ&amp;Expires=1426371544&amp;Signature=HDNhGKHDsjEgqkMreN3tbozkfzo%3D" rel="nofollow">https://mybucketname.s3.amazonaws.com/94c70e8a-61f6-4f58-a4b7-1679df5a7c1f.jpg?response-content-disposition=attachment%3B%20filename%3D94c70e8a-61f6-4f58-a4b7-1679df5a7c1f.jpg&amp;AWSAccessKeyId=AKIAJNY3GPOFFLQ&amp;Expires=1426371544&amp;Signature=HDNhGKHDsjEgqkMreN3tbozkfzo%3D</a></p> </blockquote> <pre><code> $zipName = 'zipfile.zip'; # create new zip opbject $zip = new ZipArchive(); $fileUrl = 'https://mybucketname.s3.amazonaws.com/94c70e8a-61f6-4f58-a4b7-1679df5a7c1f.jpg?response-content-disposition=attachment%3B%20filename%3D94c70e8a-61f6-4f58-a4b7-1679df5a7c1f.jpg&amp;AWSAccessKeyId=AKIAJNY3GPOFFLQ&amp;Expires=1426371544&amp;Signature=HDNhGKHDsjEgqkMreN3tbozkfzo%3D'; # create a temp file &amp; open it $tmp_file = tempnam('.',''); $zip-&gt;open($tmp_file, ZipArchive::CREATE); # download file $download_file = file_get_contents($fileUrl); #add it to the zip $zip-&gt;addFromString(basename($fileUrl),$download_file); # close zip $zip-&gt;close(); # send the file to the browser as a download header('Content-type: application/zip'); header('Content-disposition: attachment; filename='.$zipName); header('Content-Length: ' . filesize($tmp_file)); readfile($tmp_file); </code></pre>
17,276,299
0
<pre><code>Caused by: java.lang.NullPointerException at android.content.ContextWrapper.getResources(ContextWrapper.java:81) </code></pre> <p>This suggests you're trying to access your resources too early, for example when initializing your member variables. Only call <code>getResources()</code> in <code>onCreate()</code> or later in activity lifecycle.</p> <p>After fixing that you'll find that <code>mWebView</code> is <code>null</code> as suggested by others. You'll need to <code>setContentView()</code> first before calling <code>findViewById()</code> to find components in your content view hierarchy.</p>
26,690,852
0
Is it possible to insert an icon in the arc of a donut chart with D3? <p>I have a Donut Chart with 3 categories (arcs): Facebook (50%), Twitter(30%) and Instagram(20%). Plot the chart is fairly easy, but I want to know how to insert an icon in each arc with the respective symbol of the social network (using D3 or even C3).</p> <p>Thanks! </p>
9,152,166
0
<p>You cannot use <code>document.write()</code> once the document is loaded. Doing so will cause the entire document to be cleared and a new one started. If you want to add text to a document that has already been loaded, then you can use the appropriate jQuery methods to modify existing elements or add new ones.</p> <p>To help you with the exact code, we would need to see your HTML and a more complete description of exactly what you're trying to add to it.</p> <p>As some examples, one can add objects to an element with the <code>.append()</code> jquery method or using the <code>.html()</code> method.</p>
11,335,888
0
<p>Apple users can download your .apk file, however they cannot run it. It is a different file format than iPhone apps (.ipa)</p>
6,649,409
0
<p>i was struggling a while back with the same problem. i was following ryan bates screencast on delayed_job and got the same error 'uninitialized constant Delayed::Job'. In the screencast ryan creates a file called mailing_job.rb(located under lib folder) with the delayed_job perform method inside, which allows you to use the enqueue method. After doing some research i found that rails 3 does not automatically load the lib folder files into your app.(not entirely sure)<br /></p> <p>Try this<br /> In your controller where you use this:<br /></p> <pre><code>"Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc" </code></pre> <p>Try to require the file like this. <br /></p> <pre><code>require 'mailing_job' class AssetsController &lt; ApplicationController def some_method Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc end end </code></pre>
27,848,102
0
<p>In the usual case destructor is not caused for objects created in <strong><code>main()</code></strong>. But there is a good &amp; elegant solution - you can put your code into the <strong>extra parentheses</strong>, and then the destructor will be invoked:</p> <pre><code>int main() { { myApp app; app.run(); getchar(); } // At this point, the object's destructor is invoked } </code></pre>
18,447,107
0
How do I tell solr where my document collection is? <p>My sysadmin installed <a href="http://lucene.apache.org/solr/" rel="nofollow">solr</a> here: <code>/software/packages/solr-4.3.1/</code> I followed the <a href="http://lucene.apache.org/solr/4_3_1/tutorial.html" rel="nofollow">tutorial</a> (using Jetty) successfully. We have a working installation and things work as expected. I also, using <a href="http://www.solarium-project.org/" rel="nofollow">Solarium</a>, can query the example/collection1 document set from my website.</p> <p>Now I want to create my own document set that will live outsite of <code>/software/packages/solr-4.3.1/</code> but still use the instance of solr that lives in <code>/software/packages/solr-4.3.1/</code>. I copied over the example directory to <code>/path/to/mydocs</code>. I tried to go through the tutorial again from the new location. No dice. How do I tell solr where my document collection is?</p>
16,225,047
0
How to check if button is clicked while text input has focus using jQuery <p>I'm relatively new to code and have been building a little project called <a href="http://keyboardcalculator.com/" rel="nofollow">http://keyboardcalculator.com/</a> to improve my jQuery.</p> <p>I'm trying to add some more features to improve some things - and I've coded them! - but I want to add a button at the bottom of the page that displays a div to tell people what they are. </p> <p>I don't want to tarnish the user flow when the button is clicked - and a big part of that for me is that I don't want the user to have to click back into one of the text-input boxes to keep doing calculations. </p> <p>I want the focus to go back onto the last text-input that the user had focus on. This is my attempt to get it working on the #ansinput text-input field (the big one with the answer in):</p> <pre><code>if ($('#ansinput').is(':focus')) { $('#more-commands-button').click(function() { alert('hello') }); } </code></pre> <p>But I'm not getting my alert. </p> <p>Any help as where to go from here would be fantastic!</p> <p>Thank you very much StackOverflow!</p>
34,508,804
1
Count number of foreign keys in Django <p>I've read the documentation and all the other answers on here but I can't seem to get my head around it. </p> <p><strong>I need to count the number of foreign keys in an other table connected by a foreign key to a row from a queryset.</strong></p> <pre><code>class PartReference(models.Model): name = models.CharField(max_length=10) code = models.IntegerField() class Part(models.Model): code = models.ForeignKey(PartReference) serial_number = models.IntegerField() </code></pre> <p>I'll do something like:</p> <pre><code>results = PartReference.objects.all() </code></pre> <p>But I want a variable containing the count of the number of parts like any other field, something like:</p> <pre><code>results[0].count </code></pre> <p>to ultimately do something like:</p> <pre><code>print(results[0].name, results[0].code, results[0].count) </code></pre> <p>I can't wrap my head around the <a href="https://docs.djangoproject.com/en/1.9/ref/models/relations/" rel="nofollow">Django documentation</a>- There is a some stuff going on with <code>entry_set</code> in the example, but doesn't explain where <code>entry</code> came from or how it was defined.</p>
6,348,833
0
how to improve the quality of resultant video when merging audio-video with ffmpeg? <p>When merging an audio and video with ffmpeg, the quality of the resultant video goes down. How to we improve the quality(esp. the audio quality)?</p> <p>The audio quality gets degraded to quite an extent with random screeches in between. I've tried converting the audio to mp3 and video to mp4 before merging them, tried various audio-video parameters like bitrate, sample-rate, qscale etc but still unsuccessful. Any help would be greatly appreciated!</p>
10,779,145
0
get user's name and pic from id - graph API iOS <p>I am developing a game which is saving opponents ID. So I wanted to know how can I get user's name and and profile pic from the id here is what goes in for the parameter in </p> <pre><code>[facebook requestWithGraphPath:@"_______" andDelegate:self]; </code></pre> <p>thanks</p>
35,956,230
0
<p>Oke i have a (ugly?) temporary Fix... What works till now What the working method is for now:</p> <pre><code>class class1(): ... init etc... def function1(inputs): do something return(output1) def function2(inputs): temp = class1(some inputs) returnval = temp.function1() do something else return(output2) </code></pre> <p>In my opinion it is a ugly solution so if somebody knows a better one!! comment please!!</p>
35,398,599
0
<p>I had the same issue, what fixed it for me: Delete bin and obj folders, Uninstall-Package Akka, then Install-Package Newtonsoft.Json to latest version (8.0+) Then, Install-Package Akka, which will pick up the latest version of Newtonsoft.Json and be happy :).</p>
40,465,194
0
How to run a infinite angular forEach loop in angularjs? <pre><code>InstitutionStructure.teamHierarchy().then(function(response) { $scope.hierarchyList = response.data; $scope.hierarchyListsData = _.where($scope.hierarchyList, {reportingMemberId: null}); angular.forEach($scope.hierarchyListsData, function(value1, key1) { value1.teamMember = []; angular.forEach($scope.hierarchyList, function(value2, key2) { if(value1.teamMemberId === value2.reportingMemberId) { value1.teamMember.push(value2); } }) }) </code></pre> <p>From the above code I have loaded my hierarchyListsData continuously and I have to fetch list that corresponds to have teamMemberId which is equal to reportingMemberId till the object has no other corresponding values. Please help to find the solution.</p>
7,741,032
0
<p>You are missing an include file</p> <pre><code>#include &lt;netdb.h&gt; </code></pre>
32,212,331
0
LINQ query with many tables, left outer joins, and where clause <p>I need to translate this SQL query into LINQ in c#. I would appreciate any help or guidance you can give. (I'm using entity framework 6).</p> <pre><code>SELECT f.FacId ,sli.SitLocIntId ,ei.EnvIntId ,p.PhoId FROM Fac AS f join SitLocInt AS sli on f.FacId = sli.FacId join EnvInt AS ei on sli.EnvIntId = ei.EnvIntId join EnvIntTyp AS eit on ei.EnvIntTypId = eit.EnvIntTypId left outer join Aff AS a on ei.EnvIntId = a.EnvIntId left outer join AffCon AS ac on a.AffId = ac.AffId left outer join Con AS c on ac.ConId = c.ConId left outer join Pho AS p on c.ConId = p.ConId WHERE EnvIntTyp = 'Fleet' </code></pre> <p>I've been looking at group join syntax, but with so many tables, a lot of left outer joins and a where clause I haven't made much headway. So far I have</p> <pre><code> var testQuery = from f in _CEMDbContext.setFac join sli in _CEMDbContext.setSitLocInt on f.FacId equals sli.FacId join ei in _CEMDbContext.setEnvInt on sli.EnvIntId equals ei.EnvIntId join eit in _CEMDbContext.setEnvIntTyp on ei.EnvIntTypId equals eit.EnvIntTypId into eiGroup from item in eiGroup.DefaultIfEmpty().Where(e =&gt; e.EnvIntTyp == "Fleet") select new BusinessParticipant { fac = f, sitLocInt = sli, envInt = ei, // pho = p, // not working... Phone number from table Pho. }; var TestList = testQuery.ToList(); </code></pre> <p>Getting the EnvIntTyp "Fleet" and all its associated data including Fac, SitLocInt, and EnvInt is working. But I run into trouble when I try to get the phone number from table Pho which may or may not exist. Is there a nice way to chain together all the left outer joins? Thanks for advice or direction!</p> <p><b>Edit</b> I don't just need the Ids as I wrote in the SQL query, but the whole object. Plus, I should mention that EnvIntTyp is a member of the table of the same name.</p> <p><b>Edit 2</b> Here are (parts of) the relevant entities. Fac is an abbreviation for Facility. SitLocInt is an abbreviation for SiteLocationInterest. EnvInt stands for EnvironmentalInterest. Aff is for Affiliation. Con is for Contact. Pho is for Phone.</p> <pre><code>public partial class Facility { public Facility() { this.SiteLocationInterests = new List&lt;SiteLocationInterest&gt;(); } public int FacilityId { get; set; } public string FacilityIdentifier { get; set; } public string FacilityName { get; set; } public int SiteTypeId { get; set; } public string FacilityDescription { get; set; } [ForeignKey("GeographicFeature")] public Nullable&lt;int&gt; GeographicFeatureId { get; set; } [Display(Name = "resAddress", ResourceType = typeof(CEMResource))] public string AddressLine1 { get; set; } [Display(Name = "resAddressLine2", ResourceType = typeof(CEMResource))] public string AddressLine2 { get; set; } public string City { get; set; } [Display(Name = "resState", ResourceType = typeof(CEMResource))] public string StateCode { get; set; } [Display(Name = "resZip", ResourceType = typeof(CEMResource))] public string AddressPostalCode { get; set; } public string CountyName { get; set; } public virtual GeographicFeature GeographicFeature { get; set; } public virtual ICollection&lt;SiteLocationInterest&gt; SiteLocationInterests { get; set; } } public partial class SiteLocationInterest { public int SiteLocationInterestId { get; set; } [ForeignKey("Facility")] public Nullable&lt;int&gt; FacilityId { get; set; } [ForeignKey("EnvironmentalInterest")] public Nullable&lt;int&gt; EnvironmentalInterestId { get; set; } public Nullable&lt;int&gt; EventId { get; set; } [ForeignKey("GeographicFeature")] public Nullable&lt;int&gt; GeographicFeatureId { get; set; } public System.DateTime CreateDate { get; set; } public string CreateBy { get; set; } public System.DateTime LastUpdateDate { get; set; } public string LastUpdateBy { get; set; } public virtual EnvironmentalInterest EnvironmentalInterest { get; set; } public virtual Facility Facility { get; set; } public virtual GeographicFeature GeographicFeature { get; set; } } public partial class EnvironmentalInterest { public EnvironmentalInterest() { this.Affiliations = new List&lt;Affiliation&gt;(); this.SiteLocationInterests = new List&lt;SiteLocationInterest&gt;(); } public int EnvironmentalInterestId { get; set; } public string EnvironmentalInterestIdentifier { get; set; } public string EnvironmentalInterestFacilityIdentifier { get; set; } public string FacilityIdentifier { get; set; } public string EnvironmentalInterestName { get; set; } [ForeignKey("EnvironmentalInterestType")] public int EnvironmentalInterestTypeId { get; set; } public Nullable&lt;int&gt; EnvironmentalInterestSubTypeId { get; set; } public string EnvironmentalInterestDescription { get; set; } public virtual ICollection&lt;Affiliation&gt; Affiliations { get; set; } public virtual EnvironmentalInterestType EnvironmentalInterestType { get; set; } public virtual ICollection&lt;SiteLocationInterest&gt; SiteLocationInterests { get; set; } } public partial class Affiliation { public Affiliation() { this.AffiliationContacts = new List&lt;AffiliationContact&gt;(); } public int AffiliationId { get; set; } public string AffiliationIdentifier { get; set; } public string AffiliationName { get; set; } [ForeignKey("Entity")] public Nullable&lt;int&gt; EntityId { get; set; } [ForeignKey("EnvironmentalInterest")] public Nullable&lt;int&gt; EnvironmentalInterestId { get; set; } public int AffiliationTypeId { get; set; } public int StatusTypeId { get; set; } public virtual EnvironmentalInterest EnvironmentalInterest { get; set; } public virtual ICollection&lt;AffiliationContact&gt; AffiliationContacts { get; set; } } public partial class AffiliationContact { public int AffiliationContactId { get; set; } public int AffiliationId { get; set; } public int ContactId { get; set; } public virtual Affiliation Affiliation { get; set; } public virtual Contact Contact { get; set; } } public partial class Contact { public Contact() { this.AffiliationContacts = new List&lt;AffiliationContact&gt;(); this.Phones = new List&lt;Phone&gt;(); } public int ContactId { get; set; } public string ContactIdentifier { get; set; } public int EntityId { get; set; } public Nullable&lt;int&gt; MailAddressId { get; set; } public int ContactTypeId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string EmailAddress { get; set; } public virtual ICollection&lt;AffiliationContact&gt; AffiliationContacts { get; set; } public virtual Entity Entity { get; set; } public virtual ICollection&lt;Phone&gt; Phones { get; set; } } public partial class Phone { public int PhoneId { get; set; } public int ContactId { get; set; } public int ContactTypeId { get; set; } public string PhoneNumber { get; set; } public string PhoneExtensionNumber { get; set; } public virtual Contact Contact { get; set; } public virtual ContactType ContactType { get; set; } } </code></pre>
9,659,476
0
<p>if you are fine adding variables to the global scope then:</p> <pre><code>var firstname; var secondname; var checkName = function() { if(firstname != null &amp;&amp; secondname != null){ console.log(firstname); console.log(secondname); } } $('#first_name').live("change", function(){ firstname=$(this).val(); checkName(); }); $('#second_name').live("change", function(){ secondname=$(this).val(); checkName(); }); </code></pre>
984,887
0
<p>C compiles down to machine code and doesn't require any runtime support for the language itself. This means that it's possible to write code that can run before things like filesystems, virtual memory, processes, and anything else but registers and RAM exist.</p>
2,359,493
0
Starting multiple gui (WinForms) threads so they can work separetly from one main gui in C#? <p>I've one MainForm window and from that user can press 3 buttons. Each of the button starts new Form in which user can do anything he likes (like time consuming database calls etc). So i decided to put each of the forms in it's own threads:</p> <pre><code> private Thread subThreadForRaportyKlienta; private Thread subThreadForGeneratorPrzelewow; private Thread subThreadForRaporty; private void pokazOplatyGlobalne() { ZarzadzajOplatamiGlobalneDzp varGui = new ZarzadzajOplatamiGlobalneDzp(); varGui.ShowDialog(); } private void pokazRaportyKlienta() { RaportyDzpKlient varGui = new RaportyDzpKlient(); varGui.ShowDialog(); } private void pokazRaportyWewnetrzne() { RaportyDzp varGui = new RaportyDzp(); varGui.ShowDialog(); } private void pokazGeneratorPrzelewow() { ZarzadzajPrzelewamiDzp varGui = new ZarzadzajPrzelewamiDzp(); varGui.ShowDialog(); } private void toolStripMenuGeneratorPrzelewow_Click(object sender, EventArgs e) { if (subThreadForGeneratorPrzelewow == null || subThreadForGeneratorPrzelewow.IsAlive == false) { subThreadForGeneratorPrzelewow = new Thread(pokazGeneratorPrzelewow); subThreadForGeneratorPrzelewow.Start(); } else { } } private void toolStripMenuGeneratorRaportow_Click(object sender, EventArgs e) { if (subThreadForRaporty == null || subThreadForRaporty.IsAlive == false) { subThreadForRaporty = new Thread(pokazRaportyWewnetrzne); subThreadForRaporty.Start(); } else { } } private void toolStripMenuGeneratorRaportowDlaKlienta_Click(object sender, EventArgs e) { if (subThreadForRaportyKlienta == null || subThreadForRaportyKlienta.IsAlive == false) { subThreadForRaportyKlienta = new Thread(pokazRaportyKlienta); subThreadForRaportyKlienta.Start(); } else { } } </code></pre> <p>I've got couple of questions and i hope someone could explain them:</p> <ol> <li>When i use <code>Show()</code> instead of <code>ShowDialog()</code> the windows just blink for a second and never shows. What's the actual difference between those two and why it happens?</li> <li>When i use <code>ShowDialog</code> everything seems normal but i noticed not everything gets filled properly in one of the gui's (one listView stays blank even thou there are 3 simple add items in <code>Form_Load()</code>. I noticed this only in one GUI even thou on first sight everything works fine in two other gui's and i can execute multiple tasks inside those Forms updating those forms in background too (from inside the forms methods). Why would this one be diffrent?</li> <li>What would be proper way of doing this? Tasks performed in each of those Forms can be time consuming and i would like to give user possibility to jump between those 4 windows without problem so he can execute what he likes. </li> </ol>
23,883,398
0
<pre><code>Panel div = new Panel(); Panel innerdiv = new Panel(); TextBox txt = new TextBox(); innerdiv.Controls.Add(txt); div.Controls.Add(innerdiv); CustomAttributes.Controls.Add(div); </code></pre> <p>Your <code>CustomAttributes</code> holds <code>Panel</code>. Try this :</p> <pre><code>var textboxes = CustomAttributes.Controls.OfType&lt;Panel&gt;() .Select(p =&gt; p.Controls.OfType&lt;Panel&gt;().First()) .Select(p =&gt; p.Controls.OfType&lt;TextBox&gt;().First()) </code></pre>
32,576,059
0
<p>You can allocate the array as a contiguous bloc like this. Suppose you want ints:</p> <pre><code>int (*arr)[secondCount] = malloc( sizeof(int[firstCount][secondCount]) ); </code></pre> <p>You could hide this behind a macro which takes the typename as a macro argument, although the code is simple enough that that is not really necessary.</p>
34,595,020
0
Symfony 2: How to dynamically adjust configuration parameters <p>For my <code>AppBundle</code> (THE APPLICATION ITSELF, NOT A REUSABLE BUNDLE) I have a configuration parameter that is a path. I'd like to be sure the path ends with a <code>/</code>.</p> <p>In this moment I have a method in the entity that uses this path (yes is an entity and not a controller) adjust the configuration parameter with a code like this:</p> <pre><code>public function buildLogoFolder($folder) { // Replace the placeholder with the current Entity's URL $folder = str_replace('{entity_domain}', $this-&gt;getDomain()-&gt;getCanonical(), $folder); $folder = rtrim(ltrim($folder, '/'), '/') . '/'; return $folder; } </code></pre> <p>As the <code>$folder</code> parameter comes from the <code>config.yml</code> file I'd like to move outside of the entity this adjustment.</p> <p>I think I should use a solution similar to the one suggested <a href="http://stackoverflow.com/questions/14651871/how-to-dynamically-append-sections-to-symfony-2-configuration">here</a>, that is the use of the <code>DependencyInjection</code> component.</p> <p>I think the process is very similar to the <a href="http://symfony.com/doc/current/cookbook/bundles/extension.html" rel="nofollow">loading of</a> a <a href="http://symfony.com/doc/current/cookbook/bundles/configuration.html" rel="nofollow">configuration file</a> for a new bundle as explained in the Symfony's documentation but I'm not sure on how to proceed.</p> <p>Is there someone who can put me on the right way?</p> <p><strong>I'd like to automate the process. I want read the <code>folder</code> configuration parameter value and then adjust it with the method I wrote above.</strong></p> <p><strong>I want to be sure that the <code>folder</code> parameter configured ever ends with a trailing slash, also if the developer didn't write it in the configuration.</strong></p> <p><strong>So, If the developer write something like <code>path/to/folder</code> the resulting configuration parameter is automatically adjusted to <code>path/to/folder/</code></strong>.</p>
22,110,067
0
<p>If you select only HEAD, than any changes in any revisions prior to HEAD will not be included in the merge. You either need to select ALL the revisions in the branch whose changes are not yet included in your branch, or leave the range specifier empty to allow SVN to figure out which revisions to merge.</p> <p><strong>Edited to add example</strong></p> <p>When you do a "range of revisions" merge, you are picking individual CHANGES to cherry-pick over into your merge destination. If you say "merge HEAD" you are not saying "merge all changes up through HEAD", you are saying "merge only the specific change that happened in the very last revision on that branch". Consider a trunk with revision 122; a MayBranch with revisions 123, 124, and 125; and an AugustBranch with revisions 126 and 127. Both branches were copied from trunk revision 122.</p> <p>You want all three changes on the MayBranch&ndash;123, 124, and 125&ndash;to be merged into your AugustBranch. If you select all three revisions, or leave the revision specifier empty, this will happen. The merge will use revision 122 on trunk as the BASE, with 125 on MayBranch as source revision, and 127 on AugustBranch as destination revision.</p> <p>If instead you select HEAD as the revision to merge, SVN will use revision 124 on MayBranch as the BASE, with 125 as the source revision and 127 as destination as before. Since BASE is now the place where revision 125's changes were started from, you only get the changes that specifically happened in revision 125.</p> <p>The final result is as if you had exported only revision 125 on MayBranch as a diff, and then applied that diff to the AugustBranch. Except this is done with merge tracking information included so that SVN knows how to get the whole branch automatically later if you like.</p>
207,981
1
How to enable MySQL client auto re-connect with MySQLdb? <p>I came across PHP way of doing the trick:</p> <pre><code>my_bool reconnect = 1; mysql_options(&amp;mysql, MYSQL_OPT_RECONNECT, &amp;reconnect); </code></pre> <p>but no luck with MySQLdb (python-mysql).</p> <p>Can anybody please give a clue? Thanks.</p>
18,674,145
0
Clear upper bytes of __m128i <p>How do I clear the <code>16 - i</code> upper bytes of a <code>__m128i</code>?</p> <p>I've tried this; it works, but I'm wondering if there is a better (shorter, faster) way:</p> <pre><code>int i = ... // 0 &lt; i &lt; 16 __m128i x = ... __m128i mask = _mm_set_epi8( 0, (i &gt; 14) ? -1 : 0, (i &gt; 13) ? -1 : 0, (i &gt; 12) ? -1 : 0, (i &gt; 11) ? -1 : 0, (i &gt; 10) ? -1 : 0, (i &gt; 9) ? -1 : 0, (i &gt; 8) ? -1 : 0, (i &gt; 7) ? -1 : 0, (i &gt; 6) ? -1 : 0, (i &gt; 5) ? -1 : 0, (i &gt; 4) ? -1 : 0, (i &gt; 3) ? -1 : 0, (i &gt; 2) ? -1 : 0, (i &gt; 1) ? -1 : 0, -1); x = _mm_and_si128(x, mask); </code></pre>
2,077,746
0
<p>Most of the answers here I don't think are really going to wow anyone, especially a tech crowd. They might be surprised that Perl can do it, but they aren't going to be surprised that you can do the task. However, even if they aren't surprised that you can do it, they might be surprised how fast, or with how little code, you can do it.</p> <p>If you're looking for things to show them that will wow them, you have to figure out what they think is hard in their jobs and see if Perl could make it really easy. I find that people tend not to care if a language can do something they don't already have an interest in. That being said, impressing anyone with Perl is the same as impressing anyone in any other subject of field: you have to know them and what they will be impressed by. You have to know your audience.</p> <p>Perl doesn't really have any special features that allow it to do any one thing that some other language can also do. However, Perl combines a lot of features that you usually don't find in the same programming language.</p> <p>Most of the things that I'm impressed by have almost nothing to do with the language:</p> <ul> <li><p>There's a single codebase that runs on a couple hundred different platforms, despite differences in architecture.</p></li> <li><p>Perl's <a href="http://search.cpan.org/" rel="nofollow noreferrer">CPAN</a> is still unrivaled among other languages (which is really sad because it's so easy to do the same thing for other languages).</p></li> <li><p>The testing culture has really raised the bar in Perl programming, and there's a lot of work that teases out platform dependencies, cross-module issues, and so on without the original developer having to do much.</p></li> </ul>

No dataset card yet

Downloads last month
40

Models trained or fine-tuned on c17hawke/stackoverflow-dataset

Space using c17hawke/stackoverflow-dataset 1