id
int64 4
73.8M
| title
stringlengths 10
150
| body
stringlengths 17
50.8k
| accepted_answer_id
int64 7
73.8M
| answer_count
int64 1
182
| comment_count
int64 0
89
| community_owned_date
stringlengths 23
27
⌀ | creation_date
stringlengths 23
27
| favorite_count
int64 0
11.6k
⌀ | last_activity_date
stringlengths 23
27
| last_edit_date
stringlengths 23
27
⌀ | last_editor_display_name
stringlengths 2
29
⌀ | last_editor_user_id
int64 -1
20M
⌀ | owner_display_name
stringlengths 1
29
⌀ | owner_user_id
int64 1
20M
⌀ | parent_id
null | post_type_id
int64 1
1
| score
int64 -146
26.6k
| tags
stringlengths 1
125
| view_count
int64 122
11.6M
| answer_body
stringlengths 19
51k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
36,522,313 |
Large number of errors during Gradle build after upgrading to Android Studio 2.0
|
<p>Recently, I upgraded Android Studio from version 1.5 to 2.0 but since then I observe that the number of errors and warnings has increased. Most of the errors do not make sense. Can someone please help:</p>
<pre><code>AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.validator.ValidatorResources$1) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.digester.ExtendedBaseRules$1) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$5) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$6) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$8) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$9) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$1) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$10) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$11) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$12) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$2) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$3) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$4) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanMap$7) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.BeanUtilsBean$1) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.WrapDynaClass$1) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.WrapDynaClass$2) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
AGPBI: {"kind":"error","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}
AGPBI: {"kind":"error","text":"(org.apache.commons.beanutils.locale.LocaleBeanUtilsBean$1) that doesn\u0027t come with an","sources":[{}]}
AGPBI: {"kind":"error","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]}
AGPBI: {"kind":"error","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]}
AGPBI: {"kind":"error","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]}
AGPBI: {"kind":"error","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]}
AGPBI: {"kind":"error","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]}
AGPBI: {"kind":"error","text":"indicate that it is *not* an inner class.","sources":[{}]}
</code></pre>
| 36,523,016 | 7 | 5 | null |
2016-04-09 20:29:37.7 UTC
| 15 |
2017-07-04 16:24:57.813 UTC
|
2016-04-29 02:24:41.51 UTC
| null | 445,131 | null | 3,900,531 | null | 1 | 59 |
android|android-studio
| 24,466 |
<p>You can get rid of the meaningless warnings and errors by deleting the <code>.idea</code> folder that Android Studio 1.5 created and importing the the project into Android Studio 2.0 as a gradle project. It will recreate the <code>.idea</code> folder automatically.</p>
|
14,335,966 |
How to programatically export crystal report as PDF in VB.NET
|
<pre><code>Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Web
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.CrystalReports
Imports System.IO
Imports System.Net
Imports System.Net.Mail
Public Class Form1
Dim cryRpt As New ReportDocument
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cryRpt.Load("C:\Documents and Settings\Prs1\My Documents\Visual Studio 2008\Projects\myCR\myCR\cr.rpt")
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New _
DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = _
"C:\crystalExport.pdf"
CrExportOptions = cryRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
cryRpt.Export()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
</code></pre>
<p>End Class</p>
<p>I tried the above code. I have one Windows Form and a single Crystal report file (cr.rpt) in my project folder. I'm using Oracle 10G as the database.
But I'm getting an error saying that "Logon Failed". ([Error Description]Image: <a href="http://pho.to/Zv6t" rel="noreferrer">http://pho.to/Zv6t</a>)</p>
<p>Pls do help.</p>
| 14,354,329 | 3 | 3 | null |
2013-01-15 10:42:02.73 UTC
| 2 |
2018-12-04 18:04:24.223 UTC
| null | null | null |
user1622535
| null | null | 1 | 5 |
.net|vb.net|crystal-reports
| 39,649 |
<p>Finally found the solution from <a href="https://stackoverflow.com/questions/12486925/crystal-reports-how-to-set-database-credentials">here</a></p>
<p>The only thing is, I need to set Database credentials at runtime for the Crystal Report to work fine.</p>
<pre><code>cryRpt.SetDatabaseLogon("user", "password", "server", "database")
</code></pre>
|
14,054,120 |
Adding elements to a list in R (in nested lists)
|
<p>I have a nested list l3 as:</p>
<pre><code>l1<- as.list(c(1,2,3,4,5))
l1
l2<- as.list(c(6,7,8,9,10))
l2
l3<- list(l1,l2)
l3
</code></pre>
<p>l3 shows as:</p>
<pre><code>> l3
[[1]]
[[1]][[1]]
[1] 1
[[1]][[2]]
[1] 2
[[1]][[3]]
[1] 3
[[1]][[4]]
[1] 4
[[1]][[5]]
[1] 5
[[2]]
[[2]][[1]]
[1] 6
[[2]][[2]]
[1] 7
[[2]][[3]]
[1] 8
[[2]][[4]]
[1] 9
[[2]][[5]]
[1] 10
</code></pre>
<p>I need to add a third list l4 to l3 such that l3 becomes:</p>
<pre><code>[[1]][[1]]
[1] 1
to
[[2]][[5]]
[1] 10
[[3]][[1]]
[1] 30
[[3]][[2]]
[1] 32
[[3]][[3]]
[1] 33
[[3]][[4]]
[1] 34
[[3]][[5]]
[1] 35
</code></pre>
<p>where l4 was:</p>
<pre><code>l4<- as.list(c(31,32,33,34,35))
</code></pre>
<p>how do I accomplish it? I've tried <code>(c)</code>, <code>list</code>, even explicitly put the arguments and got an <code>out of bounds error</code>. What can I use to get this done?</p>
| 14,054,360 | 2 | 1 | null |
2012-12-27 11:43:09.437 UTC
| 4 |
2012-12-27 12:09:04.29 UTC
| null | null | null | null | 1,847,296 | null | 1 | 6 |
r|list
| 46,009 |
<p>It works with <code>append</code> and <code>list</code>:</p>
<pre><code>append(l3, list(l4))
</code></pre>
<p>The result:</p>
<pre><code>> str(append(l3, list(l4)))
List of 3
$ :List of 5
..$ : num 1
..$ : num 2
..$ : num 3
..$ : num 4
..$ : num 5
$ :List of 5
..$ : num 6
..$ : num 7
..$ : num 8
..$ : num 9
..$ : num 10
$ :List of 5
..$ : num 31
..$ : num 32
..$ : num 33
..$ : num 34
..$ : num 35
</code></pre>
|
54,953,917 |
`npm audit` keeps returning "Your configured registry (https://registry.npmjs.org/) does not support audit requests.". How do I make it work again?
|
<p>Here is the error I get:</p>
<pre><code>npm ERR! code ENOAUDIT
npm ERR! audit Your configured registry (https://registry.npmjs.org/) does not support audit requests.
</code></pre>
<p>with the log file:</p>
<pre><code>0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'audit' ]
2 info using npm@6.4.1
3 info using node@v10.12.0
4 verbose npm-session 65e7a3436fc1253b
5 timing audit compress Completed in 25ms
6 info audit Submitting payload of 217372 bytes
7 http fetch POST 503 https://registry.npmjs.org/-/npm/v1/security/audits 13252ms
8 verbose stack Error: Your configured registry (https://registry.npmjs.org/) does not support audit requests.
8 verbose stack at Bluebird.all.spread.then.catch (/usr/local/lib/node_modules/npm/lib/audit.js:172:18)
8 verbose stack at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
8 verbose stack at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
8 verbose stack at Promise._settlePromise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
8 verbose stack at Promise._settlePromise0 (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
8 verbose stack at Promise._settlePromises (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:689:18)
8 verbose stack at Async._drainQueue (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:133:16)
8 verbose stack at Async._drainQueues (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:143:10)
8 verbose stack at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:17:14)
8 verbose stack at runCallback (timers.js:705:18)
8 verbose stack at tryOnImmediate (timers.js:676:5)
8 verbose stack at processImmediate (timers.js:658:5)
9 verbose cwd /Users/danielhasegan/workspace/code
10 verbose Darwin 18.2.0
11 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "audit"
12 verbose node v10.12.0
13 verbose npm v6.4.1
14 error code ENOAUDIT
15 error audit Your configured registry (https://registry.npmjs.org/) does not support audit requests.
16 verbose exit [ 1, true ]
</code></pre>
<p>I tried multiple ideas found across github but I do not have any <code>proxy</code> or <code>http-proxy</code> set. both of those return <code>null</code>:</p>
<pre><code>npm config get proxy
npm config get https-proxy
</code></pre>
<p>Any ideas? This is not transitory, ive been getting it for a while now. I find it weird I get <code>503</code>. It means something is wrong with my connection. </p>
| 59,493,573 | 9 | 6 | null |
2019-03-02 00:02:39.67 UTC
| 3 |
2021-11-11 07:12:16.58 UTC
| null | null | null | null | 1,859,251 | null | 1 | 29 |
javascript|node.js|npm|npm-audit
| 23,859 |
<p>Try running <code>npm update</code> and then <code>npm audit</code>. This should fix the problem.</p>
|
31,361,571 |
Yii2 : How to write distinct SQL query?
|
<p>I want to implement following SQL queries in Yii 2 but with no success.</p>
<p>This should give total number of unique company names:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT count(DISTINCT(company_name)) FROM clients
</code></pre>
<p>And this should display <code>company_name</code> with <code>client code</code> and <code>id(PK)</code>:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT (DISTINCT(company_name,client_code)) FROM clients
</code></pre>
<p>How to achieve this?</p>
| 31,482,645 | 4 | 11 | null |
2015-07-11 20:34:57.013 UTC
| 3 |
2018-08-26 11:27:14.813 UTC
|
2018-08-26 11:22:37.727 UTC
| null | 5,812,455 | null | 4,682,302 | null | 1 | 29 |
php|mysql|yii2
| 65,401 |
<p>Answering my own question I got following working solutions:</p>
<p><strong>Got the count for unique <code>company_name</code>:</strong></p>
<pre><code>$my = (new yii\db\Query())
->select(['company_name',])
->from('create_client')
->distinct()
->count();
echo $my;
</code></pre>
<p><strong>List of distinct <code>company_name</code> and <code>client_code</code>:</strong></p>
<pre><code>$query = new yii\db\Query();
$data = $query->select(['company_name','client_code'])
->from('create_client')
->distinct()
->all();
if ($data) {
foreach ($data as $row) {
echo 'company_name: ' . $row['company_name'] . ' client_code: ' . $row['client_code'] . '<br>';
}
}
</code></pre>
|
26,599,798 |
if-else flow in promise (bluebird)
|
<p>This is a short version of my code.</p>
<pre><code>var Promise = require('bluebird');
var fs = Promise.promisifyAll(require("fs"));
if (conditionA) {
fs.writeFileAsync(file, jsonData).then(function() {
return functionA();
});
} else {
functionA();
}
</code></pre>
<p>Both conditions call <code>functionA</code>. Is there way to avoid else condition? I can do <code>fs.writeFileSync</code> but I am looking for a non-blocking solution.</p>
| 26,600,424 | 3 | 1 | null |
2014-10-28 02:05:24.613 UTC
| 10 |
2016-09-26 11:42:54.46 UTC
| null | null | null | null | 1,427,309 | null | 1 | 40 |
node.js|promise|bluebird
| 26,110 |
<p>I think you're looking for</p>
<pre><code>(conditionA
? fs.writeFileAsync(file, jsonData)
: Promise.resolve())
.then(functionA);
</code></pre>
<p>which is short for</p>
<pre><code>var waitFor;
if (conditionA)
waitFor = fs.writeFileAsync(file, jsonData);
else
waitFor = Promise.resolve(undefined); // wait for nothing,
// create fulfilled promise
waitFor.then(function() {
return functionA();
});
</code></pre>
|
6,814,629 |
how to get selected item of combo box
|
<p>i'm using lwuit with j2me . how to get combo box selected item or index? i found the function for <a href="http://lwuit.java.net/javadocs/com/sun/lwuit/ComboBox.html#setSelectedIndex%28int%29" rel="noreferrer">setSelectedIndex</a> but not for getting the selected.</p>
| 6,826,224 | 2 | 0 | null |
2011-07-25 10:18:35.437 UTC
| 2 |
2022-06-01 09:25:29.397 UTC
| null | null | null | null | 166,476 | null | 1 | 7 |
java-me|combobox|lwuit
| 81,896 |
<p>Use this code :</p>
<pre><code>comboBox.getSelectionModel().getSelectedIndex();
</code></pre>
<p>To return the current selected offset in the list.</p>
<pre><code>comboBox.getSelectionModel().getSelectedItem();
</code></pre>
<p>To return the current selected item in the list or null for no selection</p>
|
55,499,175 |
How to fix 'Error: querySrv EREFUSED' when connecting to MongoDB Atlas?
|
<p>I am new to MongoDB 4.0.6 and tried to implement it into my website using Node/Express.js, but when I try to connect to <code>mongodb+srv://${process.env.MONGOUSER}:${process.env.MONGOPASS}@main-03xkr.mongodb.net/main</code> I'm getting this error:</p>
<blockquote>
<p>{ Error: querySrv EREFUSED _mongodb._tcp.main-03xkr.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:199:19)
errno: 'EREFUSED',
code: 'EREFUSED',
syscall: 'querySrv',
hostname: '_mongodb._tcp.main-03xkr.mongodb.net' }</p>
</blockquote>
<p>I've tried connecting to <code>mongodb://localhost:27017/main</code>, but this <strong>does</strong> seem work.</p>
<p>Here is the relevant code:</p>
<pre><code>require('dotenv').config();
const mongoose = require('mongoose');
// Database
const uri = `mongodb+srv://${process.env.MONGOUSER}:${process.env.MONGOPASS}@main-03xkr.mongodb.net/main`;
const localURI = 'mongodb://localhost:27017/main';
var Project = require('./models/project');
mongoose.connect(uri, { useNewUrlParser: true });
const db = mongoose.connection;
db.once('open', () => console.log('Successfully connected to MongoDB'));
db.on('error', (e) => console.log(e));
// Routes
app.get('/', (req, res) => {
Project.find({}, (e, projects) => {
if (e) console.log(e);
res.render('home.ejs', {
projects: projects
});
});
});
</code></pre>
<p>So does anyone know how to fix this error and maybe explain what is happening here?</p>
| 55,639,024 | 16 | 2 | null |
2019-04-03 15:43:44.593 UTC
| 6 |
2022-05-11 07:29:37.767 UTC
|
2019-04-03 17:56:04.477 UTC
| null | 5,698,355 | null | 5,698,355 | null | 1 | 35 |
node.js|mongodb|express|mongoose|mongodb-atlas
| 68,028 |
<p>If you're encountering this error try to use the older connection string for Node.js 2.2.12 or later:</p>
<pre><code>mongodb://<username>:<password>@main-shard-00-00-03xkr.mongodb.net:27017,main-shard-00-01-03xkr.mongodb.net:27017,main-shard-00-02-03xkr.mongodb.net:27017/main?ssl=true&replicaSet=Main-shard-0&authSource=admin&retryWrites=true
</code></pre>
<p>According to MongoDB, SRV is possibly not working due to Mongoose.</p>
|
7,405,009 |
How can I install a driver using InnoSetup?
|
<p>I'd like to install a driver for a serial port using InnoSetup. I have the inf file, and I can install the driver manually through device manager, but I'd like to be able to include the driver in my installer so that users don't have to go through the trouble of installing the driver themselves.</p>
| 7,409,448 | 3 | 1 | null |
2011-09-13 16:07:58.07 UTC
| 11 |
2018-01-12 12:01:11.417 UTC
| null | null | null | null | 18,480 | null | 1 | 13 |
windows|driver|inno-setup
| 17,870 |
<p>See <a href="http://msdn.microsoft.com/en-us/library/aa376957%28v=vs.85%29.aspx">InstallHinfSection</a> on MSDN. The documentation also mentions how to invoke an installation by calling 'Rundll32.exe'. Probably you'll end up with something like this:</p>
<pre><code>[Files]
..
Source: "driver\my_x86driver.inf"; DestDir: {app}\driver;
Source: "driver\my_x86driver.sys"; DestDir: {app}\driver;
[Run]
..
Filename: {sys}\rundll32.exe; Parameters: "setupapi,InstallHinfSection DefaultInstall 128 {app}\driver\my_x86driver.inf"; WorkingDir: {app}\driver; Flags: 32bit;
</code></pre>
<p><br />Note that you might need to run the setup in 64bit mode in 64bit systems to be able to install the driver:</p>
<pre><code>[Setup]
..
ArchitecturesInstallIn64BitMode=x64
</code></pre>
<p>Also you can put checks as to run the version of .inf file depending on machine architecture (e.g. <code>Check: Is64BitInstallMode</code>).</p>
|
7,025,437 |
addEventListener in jQuery
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br />
<a href="https://stackoverflow.com/questions/2398099/jquery-equivalent-of-javascripts-addeventlistener-method">jQuery equivalent of JavaScript's addEventListener method</a></p>
</blockquote>
<p>Also from a very good jQuery tutorial on : <a href="http://itunes.apple.com/in/app/designmobileweb/id486198804?mt=8" rel="nofollow noreferrer">http://itunes.apple.com/in/app/designmobileweb/id486198804?mt=8</a></p>
<p>What is the jQuery equivalent for the following statement;</p>
<pre><code>element1.addEventListener('click',doSomething2,false)
</code></pre>
<p>If it is the <code>bind()</code> method, is there any option to specify the last parameter (i.e. event bubbling or capturing ... true/false)</p>
| 7,025,511 | 4 | 7 | null |
2011-08-11 11:59:04.617 UTC
| null |
2022-01-13 18:01:23.74 UTC
|
2022-01-13 18:01:23.74 UTC
| null | 4,370,109 | null | 866,855 | null | 1 | 9 |
javascript|jquery|dom-events|addeventlistener
| 74,661 |
<p>Try this</p>
<pre><code>// Setting the third argument to false will attach a function
// that prevents the default action from occurring and
// stops the event from bubbling.
$("#element1").bind("click", doSomething2, false);
</code></pre>
|
1,964,234 |
Sorting an array related to another array
|
<p>I have two arrays, <code>x</code> and <code>y</code>, where y is the value of the tens of every element in <code>x</code>. Now, I want to sort <code>y</code>. But, the order of <code>y</code> will be different of <code>x</code>'s. So, I can't tell after sorting which element in <code>y</code> was related to, for instance, <code>x[0]</code>.</p>
<p>I want a "double sorting" maybe.</p>
| 1,964,290 | 4 | 1 | null |
2009-12-26 20:09:08.707 UTC
| 2 |
2020-05-01 08:22:10.763 UTC
|
2020-05-01 08:14:40.367 UTC
| null | 1,364,007 | null | 61,250 | null | 1 | 34 |
c#|arrays
| 25,240 |
<p><code>Array.Sort</code> has <a href="http://msdn.microsoft.com/en-us/library/85y6y2d3.aspx" rel="noreferrer">an overload</a> that accepts <strong>two</strong> arrays; one for the keys, and one for the items. The items of <strong>both</strong> are sorted according to the <code>keys</code> array:</p>
<pre><code>int[] keys = { 1, 4, 3, 2, 5 };
string[] items = { "abc", "def", "ghi", "jkl", "mno" };
Array.Sort(keys, items);
foreach (int key in keys) {
Console.WriteLine(key); // 1, 2, 3, 4, 5
}
foreach (string item in items) {
Console.WriteLine(item); // abc, jkl, ghi, def, mno
}
</code></pre>
<p>So in your case, it sounds like you want:</p>
<pre><code>Array.Sort(y,x); // or Sort(x,y); - it isn't 100% clear
</code></pre>
|
10,797,912 |
How to position a Bootstrap popover?
|
<p>I'm trying to position a Bootstrap popover for a trigger that sits on the far top-right corner of a 960px wide web page.</p>
<p>Ideally, I'd position it on the bottom and move the arrow with CSS (so the arrow is on the top-right of the popover). Unfortunately the 'placement':'bottom' positioning is not enough, since it will center it below the trigger.</p>
<p>I'm looking for solution that will place the popover statically below and on the left of the trigger. </p>
| 12,486,312 | 10 | 2 | null |
2012-05-29 11:07:16.83 UTC
| 15 |
2019-04-09 09:16:03.85 UTC
|
2019-04-04 17:14:05.7 UTC
| null | 2,756,409 | null | 722,850 | null | 1 | 56 |
javascript|css|twitter-bootstrap|css-position|popover
| 145,629 |
<p>This works. Tested.</p>
<pre><code>.popover {
top: 71px !important;
left: 379px !important;
}
</code></pre>
|
54,785,148 |
Destructuring dicts and objects in Python
|
<p>In Javascript, I can use <a href="https://medium.com/podiihq/destructuring-objects-in-javascript-4de5a3b0e4cb" rel="noreferrer">destructuring</a> to extract properties I want from a javascript objects in one liner. For example:</p>
<pre class="lang-js prettyprint-override"><code>currentUser = {
"id": 24,
"name": "John Doe",
"website": "http://mywebsite.com",
"description": "I am an actor",
"email": "example@example.com",
"gender": "M",
"phone_number": "+12345678",
"username": "johndoe",
"birth_date": "1991-02-23",
"followers": 46263,
"following": 345,
"like": 204,
"comments": 9
}
let { id, username } = this.currentUser;
console.log(id) // 24
console.log(username) //johndoe
</code></pre>
<p>Do we have something similar in Python for Python dicts and Python objects? Example of Python way of doing for python objects:</p>
<pre class="lang-py prettyprint-override"><code>class User:
def __init__(self, id, name, website, description, email, gender, phone_number, username):
self.id = id
self.name = name
self.website = website
self.description = description
self.email = email
self.gender = gender
self.phone_number = phone_number
self.username = username
current_user = User(24, "Jon Doe", "http://mywebsite.com", "I am an actor", "example@example.com", "M", "+12345678", "johndoe")
# This is a pain
id = current_user.id
email = current_user.email
gender = current_user.gender
username = current_user.username
print(id, email, gender, username)
</code></pre>
<p>Writing those 4 lines (as mentioned in example above) vs writing a single line (as mentioned below) to fetch values I need from an object is a real pain point.</p>
<pre class="lang-py prettyprint-override"><code>(id, email, gender, username) = current_user
</code></pre>
| 63,600,600 | 8 | 10 | null |
2019-02-20 11:22:10.367 UTC
| 6 |
2022-04-17 11:16:14.57 UTC
|
2021-09-02 08:02:54.533 UTC
| null | 8,384,910 | null | 7,707,677 | null | 1 | 51 |
python
| 36,667 |
<p>You can use <a href="https://docs.python.org/3/library/operator.html" rel="noreferrer"><code>operator</code></a> module from standard library as follows:</p>
<pre><code>from operator import attrgetter
id, email, gender, username = attrgetter('id', 'email', 'gender', 'username')(current_user)
print(id, email, gender, username)
</code></pre>
<p>In case you have a dict like from your example</p>
<pre><code>currentUser = {
"id": 24,
"name": "John Doe",
"website": "http://mywebsite.com",
"description": "I am an actor",
"email": "example@example.com",
"gender": "M",
"phone_number": "+12345678",
"username": "johndoe",
"birth_date": "1991-02-23",
"followers": 46263,
"following": 345,
"like": 204,
"comments": 9
}
</code></pre>
<p>just use <code>itemgetter</code> instead of <code>attrgetter</code>:</p>
<pre><code>from operator import itemgetter
id, email, gender, username = itemgetter('id', 'email', 'gender', 'username')(currentUser)
print(id, email, gender, username)
</code></pre>
|
26,200,070 |
$_SERVER['REQUEST_URI'] returns full URL instead of path to script
|
<p>My PHP app is not working because of $_SERVER['REQUEST_URI'] returns the full url to the script instead of a relative path. </p>
<p><strong>My environment:</strong><br>
Windows 7 64 bit.<br>
XAMPP Version 1.8.2<br>
PHP Version 5.4.16<br>
Apache Version Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16 </p>
<p><strong>My Virtual Host Conf:</strong></p>
<pre><code><VirtualHost *:80>
DocumentRoot "D:/HTDOCS/ivankristianto"
ServerName www.ivankristianto.local
UseCanonicalName Off
<Directory "D:/HTDOCS/ivankristianto">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
</code></pre>
<p>I created a basic script to test the $_SERVER content: </p>
<pre><code>echo '$_SERVER[\'HTTP_HOST\'] : ' . $_SERVER['HTTP_HOST'];
echo '<br/>' . '$_SERVER[\'PHP_SELF\'] : ' . $_SERVER['PHP_SELF'];
echo '<br/>' . '$_SERVER[\'REQUEST_URI\'] : ' . $_SERVER['REQUEST_URI'];
</code></pre>
<p><strong>And here is the result:</strong></p>
<pre><code>// URL: http://localhost/ivankristianto/request.php
$_SERVER['HTTP_HOST'] : localhost
$_SERVER['PHP_SELF'] : /ivankristianto/request.php
$_SERVER['REQUEST_URI'] : /ivankristianto/request.php //This is correct
</code></pre>
<p><strong>And</strong></p>
<pre><code>// URL: http://www.ivankristianto.local/request.php
$_SERVER['HTTP_HOST'] : www.ivankristianto.local
$_SERVER['PHP_SELF'] : /request.php
$_SERVER['REQUEST_URI'] : http://www.ivankristianto.local/request.php //This is wrong
</code></pre>
<p>I didn't use any proxy, all I did is just set it in my /etc/hosts. </p>
<p>I have spent hours to find out why this is happens and have been search through google and this website, but cannot find any clue. </p>
<p>Can you please point me out what's wrong? </p>
<p>Thanks.<br>
Ivan</p>
| 26,239,141 | 3 | 1 | null |
2014-10-05 06:00:56.847 UTC
| null |
2016-09-15 18:22:52.34 UTC
|
2014-10-05 07:26:23.94 UTC
| null | 3,069,697 | null | 583,879 | null | 1 | 2 |
php|apache|request-uri
| 53,005 |
<p>I finally got it working.<br>
Here is the steps i did ( i don't know why it is effected, but it is working now ). </p>
<ol>
<li>Install PHP Fastcgi on xampp, i follow this steps: <a href="https://commaster.net/content/installing-php-fastcgi-and-zend-opcache-xampp-windows" rel="nofollow">https://commaster.net/content/installing-php-fastcgi-and-zend-opcache-xampp-windows</a></li>
<li>I load the mod_fcgid, but i don't use php-cgi.exe handler</li>
<li>Update my /etc/hosts file and flush dns with this command ipconfig /flushdns</li>
<li>Restart apache</li>
</ol>
<p>And it is working somehow.<br>
Honestly i don't know why it is working, but if someone stumble the same problem, i hope the solution might help.</p>
|
26,308,167 |
C# WebRequest GET/POST
|
<p>So I thought it's time for me to learn C#, be easy with me guys, I'm very new to this.</p>
<p>I'm trying to create a very simple application (I'm using Windows Forms Application).
My goal is:</p>
<ol>
<li>Using "GET" method, get the web page</li>
<li>Read a text field (this value changes every time that the user is accessing the page</li>
<li>Using "POST" method, send some values accordingly</li>
</ol>
<p>Here is my code so far:</p>
<pre><code> private void button2_Click(object sender, EventArgs e)
{
string URI = "http://localhost/post.php";
string myParameters = "field=value1&field2=value2";
using (WebClient wc = new WebClient())
{
string getpage = wc.DownloadString("http://localhost/post.php");
MessageBox.Show(getpage);
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
MessageBox.Show(HtmlResult);
}
}
</code></pre>
<p>So far so good, It's working but it's not entirely what I want to achieve here.
I'm able to use POST method, but how do I use GET before sending the data?
I want to send data according to GET result.</p>
<p>Please let me know if I should be giving a better description to what I'm trying to do.</p>
<p>Thanks.</p>
<p><strong>Edit</strong><br/>
This is my PHP Code:</p>
<pre><code><?php
$a = session_id();
if(empty($a))
session_start();
echo "Session: ".session_id()."<br/>\n";
</code></pre>
<p>Now, back to my C# code, I get different session ID in the two messages </p>
| 26,308,209 | 3 | 1 | null |
2014-10-10 21:18:46.813 UTC
| 5 |
2018-03-06 15:31:29.24 UTC
|
2014-10-10 22:23:40.667 UTC
| null | 3,800,799 | null | 3,800,799 | null | 1 | 2 |
c#|webrequest
| 41,391 |
<h2>Reading data with GET</h2>
<blockquote>
<p>Please refer to this answer: <a href="https://stackoverflow.com/questions/1048199/easiest-way-to-read-from-a-url-into-a-string-in-net">Easiest way to read from a URL into a string in .NET</a></p>
</blockquote>
<pre><code>using(WebClient client = new WebClient()) {
string s = client.DownloadString(url);
}
</code></pre>
<h2>Sessions</h2>
<p>By default WebClient does not use any Session. So every call is handled as if you created a new Session. To do that you need something like this:</p>
<blockquote>
<p>Please refer to these answers: </p>
<ol>
<li><p><a href="https://stackoverflow.com/questions/1777221/using-cookiecontainer-with-webclient-class">Using CookieContainer with WebClient class</a></p></li>
<li><p><a href="https://stackoverflow.com/questions/11573919/reading-response-from-url-using-http-web-request">Reading Response From URL using HTTP WEB REQUEST</a></p></li>
</ol>
</blockquote>
<h2>Example code</h2>
<pre><code>public class CookieAwareWebClient : WebClient
{
private readonly CookieContainer m_container = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
HttpWebRequest webRequest = request as HttpWebRequest;
if (webRequest != null)
{
webRequest.CookieContainer = m_container;
}
return request;
}
}
// ...
private void button2_Click(object sender, EventArgs e)
{
string URI = "http://localhost/post.php";
string myParameters = "field=value1&field2=value2";
using (WebClient wc = new CookieAwareWebClient())
{
string getpage = wc.DownloadString("http://localhost/post.php");
MessageBox.Show(getpage);
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
MessageBox.Show(HtmlResult);
}
}
</code></pre>
|
7,189,676 |
Passing form variables through URL
|
<p>What I want to accomplish is logging in to a website by simply typing in the form variables in the URL.</p>
<p>HTML code:</p>
<pre><code> <form action="httpclient.html" onsubmit="return checkSubmit();" method="post" target="_parent" name="frmHTTPClientLogin">
<input type="hidden" name="mode" value="191">
<label>Username</label>
<input border="1" style="width:150px" maxlength="60" name="username">
<label>Password</label></pre>
<input type="password" border="1" style="width:150px" autocomplete="off" name="password" maxlength="60">
</code></pre>
<p>This is the relevant past of the code. Now I want to login to this site <a href="http://10.100.56.55/httpclient.html" rel="nofollow">http://10.100.56.55/httpclient.html</a> just by passing values typed in the url. Firstly is it possible. If yes then what exactly do i need to type for userame :name and password being pass ?
and what encoded URL will be passed in POST method if any?</p>
| 7,189,743 | 5 | 1 | null |
2011-08-25 11:36:31.38 UTC
| 1 |
2019-02-27 21:44:37.33 UTC
|
2011-08-25 11:42:56.687 UTC
| null | 834,613 | null | 834,613 | null | 1 | 3 |
html|forms|url|http-post|http-get
| 64,761 |
<p>If you want to type the Querystring in for the username and password, you need to do this in the address field of your browser:</p>
<pre><code>http://10.100.56.55/?username=name&password=pass
</code></pre>
<p>EDIT:
You need to find out where the form is going and what it's doing. For this, you need to check what the submit javascript function called 'checkSubmit()' is doing. You can do this by opening the page in your browser and doing a view source. If the javascript is external to the html file, check the js links on the page and open those up to find that function. The function might have the querystring parameters you're looking for.</p>
|
7,265,718 |
fork() child and parent processes
|
<p>I am trying to create a program that uses fork() to create a new process. The sample output should look like so:</p>
<p>This is the child process. My pid is 733 and my parent's id is 772.<br>
This is the parent process. My pid is 772 and my child's id is 773.</p>
<p>This is how I coded my program:</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
int main() {
printf("This is the child process. My pid is %d and my parent's id is %d.\n", getpid(), fork());
return 0;
}
</code></pre>
<p>This results in the output:</p>
<p>This is the child process. My pid is 22163 and my parent's id is 0.<br>
This is the child process. My pid is 22162 and my parent's id is 22163.</p>
<p>Why is it printing the statement twice and how can I get it to properly show the parent's id after the child id displays in the first sentence?</p>
<p>EDIT:</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
int main() {
int pid = fork();
if (pid == 0) {
printf("This is the child process. My pid is %d and my parent's id is %d.\n", getpid(), getppid());
}
else {
printf("This is the parent process. My pid is %d and my parent's id is %d.\n", getpid(), pid);
}
return 0;
}
</code></pre>
| 7,265,749 | 5 | 1 | null |
2011-09-01 03:03:13.603 UTC
| 9 |
2018-04-25 03:41:57.963 UTC
|
2011-09-01 03:46:40.01 UTC
| null | 728,168 | null | 728,168 | null | 1 | 8 |
c|fork|parent
| 140,123 |
<p>Start by reading the <a href="http://linux.die.net/man/2/fork">fork man page</a> as well as the <a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/getppid.html">getppid</a> / <a href="http://linux.die.net/man/2/getpid">getpid</a> man pages.</p>
<p>From fork's</p>
<blockquote>
<p>On success, the PID of the child process is returned in the parent's
thread of execution, and a 0 is returned in the child's thread of
execution. On failure, a -1 will be returned in the parent's context,
no child process will be created, and errno will be set appropriately.</p>
</blockquote>
<p>So this should be something down the lines of</p>
<pre><code>if ((pid=fork())==0){
printf("yada yada %u and yada yada %u",getpid(),getppid());
}
else{ /* avoids error checking*/
printf("Dont yada yada me, im your parent with pid %u ", getpid());
}
</code></pre>
<p>As to your question:</p>
<blockquote>
<p>This is the child process. My pid is 22163 and my parent's id is 0.</p>
<p>This is the child process. My pid is 22162 and my parent's id is
22163.</p>
</blockquote>
<p><code>fork()</code> executes before the <code>printf</code>. So when its done, you have two processes with the same instructions to execute. Therefore, printf will execute twice. The call to <code>fork()</code> will return <code>0</code> to the child process, and the <code>pid</code> of the child process to the parent process.</p>
<p>You get two running processes, each one will execute this <strike>instruction</strike> statement:</p>
<pre><code>printf ("... My pid is %d and my parent's id is %d",getpid(),0);
</code></pre>
<p>and</p>
<pre><code>printf ("... My pid is %d and my parent's id is %d",getpid(),22163);
</code></pre>
<p>~ </p>
<p>To wrap it up, the above line is the child, specifying its <code>pid</code>. The second line is the parent process, specifying its id (22162) and its child's (22163).</p>
|
7,580,288 |
How to determine whether T is a value type or reference class in generic?
|
<p>I have a generic method behavior of which depends on T is reference type or value type. It looks so:</p>
<pre><code>T SomeGenericMethod <T> (T obj)
{
if (T is class) //What condition I must write in the brackets?
//to do one stuff
else //if T is a value type like struct, int, enum and etc.
//to do another stuff
}
</code></pre>
<p>I can't duplicate this method like:</p>
<pre><code>T SomeGenericMethod <T> (T obj) where T : class
{
//Do one stuff
}
T SomeGenericMethod <T> (T obj) where T : struct
{
//Do another stuff
}
</code></pre>
<p>because their signatures are equal. Can anyone help me?</p>
| 7,580,347 | 5 | 0 | null |
2011-09-28 08:23:37.9 UTC
| 6 |
2020-02-06 16:24:42.233 UTC
| null | null | null | null | 958,593 | null | 1 | 58 |
c#|.net|generics
| 22,611 |
<p>You can use the <a href="http://msdn.microsoft.com/en-us/library/58918ffs.aspx" rel="noreferrer"><code>typeof</code> operator</a> with generic types, so <code>typeof(T)</code> will get the <a href="http://msdn.microsoft.com/en-us/library/42892f65.aspx" rel="noreferrer"><code>Type</code></a> reference corresponding to <code>T</code>, and then use the <a href="http://msdn.microsoft.com/en-us/library/system.type.isvaluetype.aspx" rel="noreferrer"><code>IsValueType</code></a> property:</p>
<pre><code>if (typeof(T).IsValueType)
</code></pre>
<p>Or if you want to include nullable value types as if they were reference types:</p>
<pre><code>// Only true if T is a reference type or nullable value type
if (default(T) == null)
</code></pre>
|
7,069,076 |
Split column at delimiter in data frame
|
<p>I would like to split one column into two within at data frame based on a delimiter. For example,</p>
<pre><code>a|b
b|c
</code></pre>
<p>to become</p>
<pre><code>a b
b c
</code></pre>
<p>within a data frame.</p>
<p>Thanks!</p>
| 7,069,385 | 6 | 1 | null |
2011-08-15 18:37:19.35 UTC
| 51 |
2021-04-27 13:11:31.967 UTC
| null | null | null | null | 580,530 | null | 1 | 128 |
r|dataframe
| 320,317 |
<p>@Taesung Shin is right, but then just some more magic to make it into a <code>data.frame</code>.
I added a "x|y" line to avoid ambiguities:</p>
<pre><code>df <- data.frame(ID=11:13, FOO=c('a|b','b|c','x|y'))
foo <- data.frame(do.call('rbind', strsplit(as.character(df$FOO),'|',fixed=TRUE)))
</code></pre>
<p>Or, if you want to replace the columns in the existing data.frame:</p>
<pre><code>within(df, FOO<-data.frame(do.call('rbind', strsplit(as.character(FOO), '|', fixed=TRUE))))
</code></pre>
<p>Which produces:</p>
<pre><code> ID FOO.X1 FOO.X2
1 11 a b
2 12 b c
3 13 x y
</code></pre>
|
7,351,205 |
Where to find "gmp.h"?
|
<p>I am installing a library, and got this error message:</p>
<pre><code>xxxx@ubuntu$ make
(cd num; make all)
make[1]: Entering directory `/home/xxxx/num'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/xxxx/num'
(cd itv; make all)
make[1]: Entering directory `/home/xxxx/itv'
gcc -Wcast-qual -Wswitch -Werror-implicit-function-declaration -Wall -Wextra -Wundef -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wno-unused -std=c99 -U__STRICT_ANSI__ -O3 -DNDEBUG -I../num -I../apron -I/usr/include -I/usr/include -DNUM_MPQ -c -o itvMPQ.o itv.c
In file included from itv.h:9:0,
from itv.c:5:
../num/num.h:15:17: fatal error: gmp.h: No such file or directory
compilation terminated.
make[1]: *** [itvMPQ.o] Error 1
make[1]: Leaving directory `/home/xxxx/itv'
make: *** [c] Error 2
</code></pre>
<p>So the problem is that it can not find <code>gmp.h</code>, does anyone know where this file is located, and how to make it found by the installer? By the way, at the moment my <code>Makefile</code> points mainly to <code>/usr</code> and <code>/usr/local</code>...</p>
<p><strong>Edit1</strong>: After installing <code>libgmp3-dev</code> as suggested, the current error message is <code>../num/num.h:16:18: fatal error: mpfr.h: No such file or directory</code>, does anyone know which package it is about?</p>
<p><strong>Edit2</strong>: I have installed <code>MPFR</code> by following this <a href="http://www.mpfr.org/mpfr-current/mpfr.html#Installing-MPFR" rel="noreferrer">page</a>, and that did help, now the error message is <code>gmp_caml.c:17:33: fatal error: caml/camlidlruntime.h: No such file or directory</code>, could anyone help?</p>
<p><strong>Edit3</strong>: I have done <code>apt-file search camlidlruntime</code>, and it returns <code>camlidl: /usr/lib/ocaml/caml/camlidlruntime.h</code>, but there is no <code>camlidlruntime.h</code> in my folder <code>/usr/lib/ocaml/caml/</code>, how could I check if I have installed <code>dev package of MPFR</code>? and which package it is exactly about?</p>
| 7,351,295 | 7 | 0 | null |
2011-09-08 16:11:24.673 UTC
| 12 |
2020-07-17 08:05:09.9 UTC
|
2011-09-08 18:01:55.167 UTC
| null | 702,977 | null | 702,977 | null | 1 | 74 |
c|makefile
| 103,039 |
<p>you need to install
libgmp3-dev </p>
<p>depends on your linux </p>
<pre><code>yum install libgmp3-dev
apt-get install libgmp3-dev
</code></pre>
|
7,361,135 |
How to change color and font on ListView
|
<p>I am trying to change my font(color and size) and the back ground on my ListView. I want to change it with code lines not on xml.
my list view looks like:
the xml:</p>
<pre><code> <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="18sp" android:text="@string/hello">
</TextView>
</code></pre>
<p>and my code is</p>
<pre><code>public class NewsActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ArrayAdapter listItemAdapter = new ArrayAdapter( this,android.R.layout.simple_list_item_1, v_itemList );
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,ynetList));
View v=getListView() ;
ListView lv = getListView();
</code></pre>
<p>what next? please give me an example base on my code</p>
| 7,361,323 | 9 | 2 | null |
2011-09-09 11:45:26.56 UTC
| 10 |
2016-12-07 10:06:55.66 UTC
|
2011-09-09 12:22:04.677 UTC
| null | 68,805 | null | 844,039 | null | 1 | 21 |
android|listview|fonts
| 110,669 |
<p>You need to create a CustomListAdapter. </p>
<pre><code>public class CustomListAdapter extends ArrayAdapter <String> {
private Context mContext;
private int id;
private List <String>items ;
public CustomListAdapter(Context context, int textViewResourceId , List<String> list )
{
super(context, textViewResourceId, list);
mContext = context;
id = textViewResourceId;
items = list ;
}
@Override
public View getView(int position, View v, ViewGroup parent)
{
View mView = v ;
if(mView == null){
LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = vi.inflate(id, null);
}
TextView text = (TextView) mView.findViewById(R.id.textView);
if(items.get(position) != null )
{
text.setTextColor(Color.WHITE);
text.setText(items.get(position));
text.setBackgroundColor(Color.RED);
int color = Color.argb( 200, 255, 64, 64 );
text.setBackgroundColor( color );
}
return mView;
}
}
</code></pre>
<p>The list item looks like this (custom_list.xml): </p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:textSize="20px" android:paddingTop="10dip" android:paddingBottom="10dip"/>
</LinearLayout>
</code></pre>
<p>Use the TextView api's to decorate your text to your liking</p>
<p>and you will be using it like this </p>
<pre><code>listAdapter = new CustomListAdapter(YourActivity.this , R.layout.custom_list , mList);
mListView.setAdapter(listAdapter);
</code></pre>
|
7,666,977 |
Syntax highlighting for Jade in Sublime Text 2?
|
<p>I just started using Sublime Text 2 on Mac. I also just started using <a href="http://jade-lang.com" rel="noreferrer">Jade</a> for my views in Node.js, and am wondering if there is a way to add syntax highlighting for Jade into Sublime Text 2.</p>
| 7,693,609 | 9 | 0 | null |
2011-10-05 19:58:06.877 UTC
| 39 |
2017-05-28 15:20:51.577 UTC
|
2015-12-21 19:26:41.8 UTC
| null | 5,017,283 | null | 115,182 | null | 1 | 146 |
editor|sublimetext2|pug|syntax-highlighting|sublimetext
| 50,793 |
<p>Sublime Text 2 supports Textmate syntax definition files. There is a Jade Textmate bundle at <a href="https://github.com/miksago/jade-tmbundle" rel="nofollow noreferrer">https://github.com/miksago/jade-tmbundle</a>. </p>
<p>Install by creating a new folder in your Sublime Text "Packages" folder, call the new folder <code>Jade</code>, then <code>curl -O https://raw.github.com/miksago/jade-tmbundle/master/Syntaxes/Jade.tmLanguage</code> or otherwise download that file into the new folder. The editor will load the syntax immediately.</p>
|
7,508,044 |
Android Fragment no view found for ID?
|
<p>I have a fragment I am trying to add into a view.</p>
<pre><code>FragmentManager fragMgr=getSupportFragmentManager();
feed_parser_activity content = (feed_parser_activity)fragMgr
.findFragmentById(R.id.feedContentContainer);
FragmentTransaction xaction=fragMgr.beginTransaction();
if (content == null || content.isRemoving()) {
content=new feed_parser_activity(item.getLink().toString());
xaction
.add(R.id.feedContentContainer, content)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(null)
.commit();
Log.e("Abstract", "DONE");
}
</code></pre>
<p>When this code is executed I get the following error in debug..</p>
<pre><code>java.lang.IllegalArgumentException: No view found for id 0x7f080011
for fragment feed_parser_activity{41882f50 #2 id=0x7f080011}
</code></pre>
<p><code>feed_parser_activity</code> is a Fragment that is set to Fragment layout in xml.<br>
I am using a FragmentActivity to host the Fragment Layout holding the <code>feed_parser_layout</code>.<br>
Am I coding this correctly above?</p>
| 8,158,916 | 40 | 3 | null |
2011-09-21 23:53:19.81 UTC
| 62 |
2021-10-22 07:14:27.167 UTC
|
2013-11-09 23:03:28.227 UTC
| null | 356,895 | null | 867,895 | null | 1 | 335 |
android|android-fragments|illegalargumentexception
| 334,202 |
<p>I was having this problem too, until I realized that I had specified the wrong layout in <code>setContentView()</code> of the <code>onCreate()</code> method of the FragmentActivity.</p>
<p>The id passed into <code>FragmentTransaction.add()</code>, in your case <code>R.id.feedContentContainer</code>, must be a child of the layout specified in <code>setContentView()</code>.</p>
<p>You didn't show us your <code>onCreate()</code> method, so perhaps this is the same problem.</p>
|
14,169,834 |
Spring 3.1 Environment does not work with user property files
|
<p>I am doing this..</p>
<pre><code>AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
xmlReader
.loadBeanDefinitions(new ClassPathResource("SpringConfig.xml"));
PropertySourcesPlaceholderConfigurer propertyHolder = new PropertySourcesPlaceholderConfigurer();
propertyHolder.setLocation(new ClassPathResource(
"SpringConfig.properties"));
context.addBeanFactoryPostProcessor(propertyHolder);
......
context.refresh();
</code></pre>
<p>Now in my @Configuration files, the properties present in my SpringConfig.properties are not getting picked up if I do this...</p>
<pre><code>@Autowired
private Environment env
.....
env.getProperty("my.property")
</code></pre>
<p>But I get that property if I use </p>
<pre><code>@Value("${my.property}")
private String myProperty;
</code></pre>
<p>I even tried adding couple of more lines like this, but of no use.</p>
<pre><code>ConfigurableEnvironment env = new StandardEnvironment();
propertyHolder.setEnvironment(env);
</code></pre>
<p>Does anybody know why my properties are not loaded into Environment? Thanks.</p>
| 14,170,198 | 4 | 0 | null |
2013-01-05 07:52:15.347 UTC
| 9 |
2014-10-24 23:19:00.06 UTC
| null | null | null | null | 1,364,959 | null | 1 | 18 |
java|spring
| 19,912 |
<p>PropertySourcesPlaceholderConfigurer reads property files directly(as it was done by PropertyPlaceholderConfigurer in Spring 3.0 times), it's just a postprocessor which does not change the way properties are used in the Spring context - in this case properties are only available as bean definition placeholders. </p>
<p>It's the PropertySourcesPlaceholderConfigurer who uses Environment and not vice versa. </p>
<p>Property sources framework works on the application context level, while property placeholder configurers only provide the functionality to process placeholders in the bean definitions. To use property source abstraction you should use <a href="http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/context/annotation/PropertySource.html" rel="noreferrer"><code>@PropertySource</code></a> annotation i.e. decorate your configuration class with something like
<code>@PropertySource("classpath:SpringConfig.properties")</code></p>
<p>I believe that you can do the same thing programmatically, i.e. you can get the container's ConfigurableEnvironment before the context was refreshed, modify its MutablePropertySources(you need first to get <code>AbstractApplicationContext</code> <code>environment</code> property via <code>context.getEnvironment()</code> ) via <code>getPropertySources().addFirst(new ResourcePropertySource(new ClassPathResource(
"SpringConfig.properties")));</code> but it's unlikely what you want to do - if you already have a <code>@Configuration</code> annotated class, decorating it with <code>@PropertySource("classpath:SpringConfig.properties")</code> is much simpler.</p>
<p>As for the <code>PropertySourcesPlaceholderConfigurer</code> instance - it will fetch property sources automatically(as it implements EnvironmentAware) from its application context so you need just to register a default instance of it.</p>
<p>For the examples of custom property source implementation see <a href="http://blog.springsource.org/2011/02/15/spring-3-1-m1-unified-property-management/" rel="noreferrer">http://blog.springsource.org/2011/02/15/spring-3-1-m1-unified-property-management/</a></p>
|
14,241,696 |
How to get rid of space between divs when display inline-block and stacked horizontally?
|
<p>I have three divs horizontally stacked side by side to one another and these divs are set to display: inline-block. However, I have noticed that even with using some sort of CSS reset they produce a small 4px distance between each other? Why does this occur? Is there a way to globally get rid of this from happening or do I just have to shift the divs to the left -4px?</p>
| 14,241,813 | 5 | 2 | null |
2013-01-09 16:25:10.343 UTC
| 10 |
2018-02-22 10:01:32.217 UTC
|
2013-01-09 16:26:13.013 UTC
| null | 1,558,311 | null | 1,460,983 | null | 1 | 31 |
html|css
| 39,617 |
<p>This is caused by the fact your browser will render the DIV's inline and as with words, they are separated by spaces.</p>
<p>The width of the space is determined by the font-size, hence an easy trick is to set the font-size of your containing element to 0 and then reset the font-size in your inline divs.</p>
<pre class="lang-css prettyprint-override"><code>#container { font-size: 0; }
#container > div {font-size: 1rem; display: inline-block; }
</code></pre>
<p>I have demonstrated this in this <a href="http://jsfiddle.net/Lqx5j/" rel="noreferrer">Fiddle</a>.</p>
<p>Take a look at this <a href="http://css-tricks.com/fighting-the-space-between-inline-block-elements/" rel="noreferrer">article</a> for more info.</p>
|
13,887,704 |
What's the point of the Prototype design pattern?
|
<p>So I'm learning about design patterns in school. Today I was told about the 'Prototype' design pattern. </p>
<p>I must be missing something, because I don't see the benefits from it. I've seen people online say it's faster than using <code>new</code> but this doesn't make sense; at some point, regardless of how the new object is created, memory needs to be allocated for it. </p>
<p>Doesn't this pattern run in the same circles as the 'chicken or egg' problem? Since the Prototype pattern essentially is just cloning objects, at some point the original object must be created itself (i.e. not cloned). This would mean that I need to have an existing copy of every object I want to clone already ready to clone?</p>
<p>Can anyone explain what the use of this pattern is? </p>
| 13,887,737 | 7 | 1 | null |
2012-12-14 23:30:41.66 UTC
| 21 |
2021-06-23 05:17:35.343 UTC
|
2016-08-14 18:03:58.133 UTC
| null | 1,371,329 | null | 1,905,391 | null | 1 | 73 |
design-patterns|prototype-pattern
| 26,051 |
<p>The Prototype pattern is a creation pattern based on cloning a pre-configured object. The idea is that you pick an object that is configured for either the default or in the ballpark of some specific use case and then you clone this object and configure to your exact needs.</p>
<p>The pattern is useful to remove a bunch of boilerplate code, when the configuration required would be onerous. I think of Prototypes as a preset object, where you save a bunch of state as a new starting point.</p>
|
43,531,602 |
Bulk Update in Entity Framework Core
|
<p>I pull a bunch of timesheet entries out of the database and use them to create an invoice. Once I save the invoice and have an Id I want to update the timesheet entries with the invoice Id. Is there a way to bulk update the entities without loading them one at a time?</p>
<pre><code>void SaveInvoice(Invoice invoice, int[] timeEntryIds) {
context.Invoices.Add(invoice);
context.SaveChanges();
// Is there anything like?
context.TimeEntries
.Where(te => timeEntryIds.Contains(te.Id))
.Update(te => te.InvoiceId = invoice.Id);
}
</code></pre>
| 43,531,693 | 6 | 1 | null |
2017-04-20 23:39:26.873 UTC
| 2 |
2022-02-05 10:53:54.87 UTC
|
2019-11-11 07:40:18.107 UTC
| null | 5,170,364 | null | 1,679,126 | null | 1 | 12 |
c#|.net|entity-framework|entity-framework-core
| 39,839 |
<p>If <code>TimeEntry</code> has an association to <code>Invoice</code> (check the navigation properties), you can probably do something like this:</p>
<pre><code>var timeEntries = context.TimeEntries.Where(t => timeEntryIds.Contains(te.Id)).ToArray();
foreach(var timeEntry in timeEntries)
invoice.TimeEntries.Add(timeEntry);
context.Invoices.Add(invoice);
//save the entire context and takes care of the ids
context.SaveChanges();
</code></pre>
|
29,864,642 |
Is Objects.requireNonNull less efficient than the old way?
|
<p>Since JDK 7 I've been happily using the method it introduced to reject <code>null</code> values which are passed to a method which cannot accept them:</p>
<pre><code>private void someMethod(SomeType pointer, SomeType anotherPointer) {
Objects.requireNonNull(pointer, "pointer cannot be null!");
Objects.requireNonNull(anotherPointer, "anotherPointer cannot be null!");
// Rest of method
}
</code></pre>
<p>I think this method makes for very tidy code which is easy to read, and I'm trying to encourage colleagues to use it. But one (particularly knowledgeable) colleague is resistant, and says that the old way is more efficient:</p>
<pre><code>private void someMethod(SomeType pointer, SomeType anotherPointer) {
if (pointer == null) {
throw new NullPointerException("pointer cannot be null!");
}
if (anotherPointer == null) {
throw new NullPointerException("anotherPointer cannot be null!");
}
// Rest of method
}
</code></pre>
<p>He says that calling <code>requireNonNull</code> involves placing another method on the JVM call stack and will result in worse performance than a simple <code>== null</code> check.</p>
<p>So my question: is there any <strong>evidence</strong> of a performance penalty being incurred by using the <code>Objects.requireNonNull</code> methods?</p>
| 29,864,679 | 9 | 6 | null |
2015-04-25 11:37:12.47 UTC
| 14 |
2020-12-01 15:39:23.15 UTC
|
2015-12-09 16:02:37.243 UTC
| null | 3,233,595 | null | 1,515,834 | null | 1 | 67 |
java|performance|null
| 36,916 |
<p>Let's look at the implementation of <code>requireNonNull</code> in Oracle's JDK:</p>
<pre><code>public static <T> T requireNonNull(T obj) {
if (obj == null)
throw new NullPointerException();
return obj;
}
</code></pre>
<p>So that's <strong>very simple</strong>. The JVM (Oracle's, anyway) includes an optimizing two-stage just-in-time compiler to convert bytecode to machine code. It will inline trivial methods like this if it can get better performance that way.</p>
<p>So no, not likely to be slower, not in any meaningful way, not anywhere that would matter.</p>
<blockquote>
<p>So my question: is there any <strong>evidence</strong> of a performance penalty being incurred by using the <code>Objects.requireNonNull</code> methods?</p>
</blockquote>
<p>The only evidence that would matter would be performance measurements of <em>your</em> codebase, or of code designed to be highly representative of it. You <em>can</em> test this with any decent performance testing tool, but unless your colleague can point to a real-world example of a performance problem in your codebase related to this method (rather than a synthetic benchmark), I'd tend to assume you and he/she have bigger fish to fry.</p>
<hr>
<p>As a bit of an aside, I noticed your sample method is a <code>private</code> method. So only code your team is writing calls it directly. In those situations, you might look at whether you have a use case for <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html">assertions</a> rather than runtime checks. Assertions have the advantage of not executing in "released" code at all, and thus being faster than either alternative in your question. Obviously there are places you need runtime checks, but those are usually at gatekeeping points, public methods and such. Just FWIW.</p>
|
9,538,247 |
CSS background disappears when using float:left
|
<p>This is my html:</p>
<pre><code><div class="header_wrapper">
<div class="main_nav">
<div>TEst</div>
<div>TEst</div>
<div>TEst</div>
</div>
<div class="clear"></div>
</div>
</code></pre>
<p>As you can see I want to build a menu with floating divs. Doing so the background of main_nav disappears.</p>
<pre class="lang-css prettyprint-override"><code>.header_wrapper{
height:129px;
background:url('images/layout/header.png') no-repeat #1f1f1f;
border-bottom:1px solid #1f66ad
}
.header_wrapper .main_nav{
position:relative;
top:77px; left:336px;
width:750px;
background:red;
}
.header_wrapper .main_nav div{
float:left;
}
.clear{
clear:both;
}
</code></pre>
<p>I tried to use clear:both, however the background is still gone. Any ideas why?</p>
| 9,538,268 | 4 | 1 | null |
2012-03-02 18:08:57.21 UTC
| 10 |
2012-03-02 18:42:55.07 UTC
|
2012-03-02 18:42:55.07 UTC
| null | 246,246 | null | 401,025 | null | 1 | 21 |
html|css|css-float
| 47,188 |
<p>Adding <code>overflow:auto;</code> to main_nav brings the background back.</p>
|
32,622,899 |
ITMS-90535 Unable to publish iOS app with latest Google Signin SDK
|
<p><a href="https://i.stack.imgur.com/htwqK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/htwqK.png" alt="Error ITMS-90535 : Unexpected CFBundleExecutable Key Google Sigin"></a></p>
<p>I'm using xcode 7 GM seed and installed latest Google Signin SDK through cocoapods <code>pod "Google/SignIn</code> . I get the attached error when I try to publish my app to apple app store. </p>
<p>Help!!</p>
<p>Here are the detailed versions of Google SDK pods</p>
<p><code>- Google/Core (1.0.7):
- GoogleNetworkingUtilities (~> 1.0)
- GoogleSymbolUtilities (~> 1.0)
- GoogleUtilities (~> 1.0)
- Google/SignIn (1.0.7):
- Google/Core
- GoogleSignIn (~> 2.0)
- GoogleAppUtilities (1.0.0):
- GoogleSymbolUtilities (~> 1.0)
- GoogleAuthUtilities (1.0.1):
- GoogleNetworkingUtilities (~> 1.0)
- GoogleSymbolUtilities (~> 1.0)
- GoogleNetworkingUtilities (1.0.0):
- GoogleSymbolUtilities (~> 1.0)
- GoogleSignIn (2.2.0):
- GoogleAppUtilities (~> 1)
- GoogleAuthUtilities (~> 1)
- GoogleNetworkingUtilities (~> 1)</code></p>
<p>Thank you.</p>
| 32,645,052 | 6 | 3 | null |
2015-09-17 05:02:37.017 UTC
| 16 |
2016-07-06 16:27:46.123 UTC
| null | null | null | null | 311,701 | null | 1 | 67 |
ios|xcode7|google-signin
| 26,797 |
<p>Find <code>CFBundleExecutable</code> key , remove this key from Google Signin SDK's info.plist.
You can delete all other <code>CFBundleExecutable</code> if error occurs on multiple bundles</p>
|
19,694,130 |
Page height to 100% of viewport?
|
<p>I'll start by saying that I am very very new to web development as a whole and that this is my very first responsive site so please be gentle and bear this in mind, I am the definition of the word noob at this stage. Having searched for an answer for a while and having no luck I'm hoping that someone here could help me out.</p>
<p>I'm trying to make a homepage for this website. The design is simply a block down the left hand side of the page showing the logo at the top and then a series of links underneath, all of which is on the same background. To the right of this is one big image which fills the rest of the screen. I want the whole page to fill the browser window of whatever device it is viewed on so absolutely no scrolling is necessary, i.e. width and height both 100% of the viewport. The width of the page is giving me no grief at all, sweetly adjusting to different screen sizes as I want it, with the sidebar at 20% of the width and the main image at 80%.</p>
<p>The height is a different story however. I can't seem, in any combination of CSS I've tried so far, to be able to get the height to behave at 100% of the viewport. Either the sidebar is too short and the main image is too long or both are too long etc etc. The main image I want to keep the aspect ratio of and just have it overflow it's div as required to keep most of it displayed and the side bar I just want to fit to 100% of the page height. Here is my code at present: </p>
<pre><code><html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
html
{
height: 100%;
margin: 0;
padding: 0;
}
body
{
height: 100%;
margin: 0;
padding: 0;
}
#page
{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#sidebar
{
float: left;
width: 20%;
height: 100%;
padding-bottom: 10;
margin: 0;
background: url(/Images/bg.jpg);
}
#slideshow
{
float: right;
width: 80%;
height: 100%;
overflow: hidden;
margin: 0;
padding: 0;
}
#logoimg
{
width: 80%;
margin-top: 10%;
margin-left: 10%;
margin-right: 10%;
}
#mainimg
{
width: 100%;
overflow: hidden;
}
.link
{
font-family: courier;
font-size: 1.3em;
text-align: center;
padding-top: 7%;
padding-bottom: 1%;
color: rgba(255,255,255,1.00);
}
@font-face
{
font-family: courier;
src: url(/courier_new-webfont.ttf);
src: url(/courier_new-webfont.eot);
src: url(/courier_new-webfont.woff);
}
</style>
</head>
<body>
<div id="page"><!--Whole page container-->
<div id="sidebar"><!--Side bar container-->
<div class="link" id="logo"><img id="logoimg" src="/Images/logo.png"></div>
<div class="link" id="homelink">Home<!--Home link--></div>
<div class="link" id="aboutlink">About<!--About link--></div>
<div class="link" id="gallerylink">Gallery<!--Gallery link--></div>
<div class="link" id="priceslink">Prices<!--Prices link--></div>
<div class="link" id="reviewslink">Reviews<!--Reviews link--></div>
<div class="link" id="contactlink">Contact<!--Contact link--></div>
<div class="link" id="clientslink">Clients<!--Clients link--></div>
</div>
<div id="slideshow"><img id="mainimg" src="/Images/main.jpg"><!--Image slideshow container-->
</div>
</div>
</body>
</html>
</code></pre>
<p>Any help with this would be really appreciated and don't hesitate to point out any massively amateur mistakes. I'm willing to take any criticism and learn from it. Thanks</p>
| 19,695,231 | 4 | 2 | null |
2013-10-30 21:27:27.847 UTC
| 11 |
2019-10-20 02:11:58.413 UTC
| null | null | null | null | 2,939,109 | null | 1 | 33 |
html|css|height
| 86,724 |
<p>I have made you a basic set up to show how you would style this. The best way that I have found to set the height to 100%is with the use of jQuery/Javascript. You can find the height of the window and then input that into the css with the use of it.</p>
<p>The way this works is the <code>var wH = $(window).height();</code> is finding the height and turning that into a number. Then when you use <code>$('.sideBar').css({height: wH});</code> you are inputing the height into the css of sideBar.</p>
<p><strong>jQuery</strong></p>
<pre><code>function windowH() {
var wH = $(window).height();
$('.sideBar, .mainImg').css({height: wH});
}
windowH();
</code></pre>
<p>This function I wrote is giving those two elements the height of the window. This will allow those two elements to be 100% of any browser's window.</p>
<p>I also recommend turning that <code>nav</code> into a <code>ul</code> which I included in the fiddle to show how that is possible.</p>
<p><a href="http://jsfiddle.net/Josh_Powell/vbj7k/4/show/">JSFIDDLE</a> (Remove 'show' at the end of the url to see code)</p>
<p>The next thing you will need to research is <code>media queries</code> to adjust the content to adapt better to mobile devices. Consider changing the sideBar to a horizontal nav when on mobile devices.</p>
<p><strong>If you want a pure <code>CSS</code> only approach then you can do something like this,</strong></p>
<pre><code>html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
</code></pre>
<p>By adding height&width to 100% in your <code>html</code>/<code>body</code> you can then use <code>height: 100%</code> on other elements to fill the entire page.</p>
<p>Refer to this <a href="http://jsfiddle.net/Josh_Powell/GVuEy/4/">JSFIDDLE</a> to see how it works.</p>
<p><a href="http://css-tricks.com/css-media-queries/">Helpful read about responsive web design</a></p>
|
19,322,421 |
From where do I reference a missing assembly (System.Net.Http.Formatting)?
|
<p>In my Visual Studio 2013 RC project, I'm getting this err msg:</p>
<blockquote>
<p>"<em>The type 'System.Net.Http.Formatting.MediaTypeFormatter' is defined
in an assembly that is not referenced. You must add a reference to
assembly 'System.Net.Http.Formatting, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'</em>"</p>
</blockquote>
<p>...on the <code>"var response = "</code> line of code in a Controller:</p>
<pre><code>public HttpResponseMessage PostDelivery(Delivery delivery)
{
delivery = repository.Add(delivery);
var response = Request.CreateResponse<Delivery>(HttpStatusCode.Created, delivery);
string uri = Url.Link("DefaultApi", new { id = delivery.Id });
response.Headers.Location = new Uri(uri);
return response;
}
</code></pre>
<p>Searching my hard drive for the required assembly ("System.Net.Http.Formatting"), it shows me several locations where it exists, but they are all within existing projects, as is seen here:</p>
<p><img src="https://i.stack.imgur.com/UJlOi.png" alt="enter image description here"></p>
<p>Surely there is another location from which System.Net.Http.Formatting.dll can be referenced! But where?</p>
<h2>UPDATE</h2>
<p>Trying to follow the clue here: <a href="http://www.nuget.org/packages/System.Net.Http.Formatting">http://www.nuget.org/packages/System.Net.Http.Formatting</a></p>
<p>IOW, by selecting Tools > Library Package Manager > Package Manager Console, and entering: </p>
<pre><code>Install-Package System.Net.Http.Formatting -Version 4.0.20710
</code></pre>
<p>...I see the red bulls of Pamplona (not the beverage) descending wild-eyed upon me:</p>
<p><img src="https://i.stack.imgur.com/P45oN.png" alt="enter image description here"></p>
<h2>UPDATE 2</h2>
<p>I added the System.Net.Http.Formatting.dll from here:</p>
<pre><code>C:\Users\clay\My Documents\Visual Studio 2013\Projects\MvcApplication1\MvcApplication1\bin
</code></pre>
<p>...and it now compiles and runs and works as expected, but that is obviously "not the preferred method"</p>
| 22,346,641 | 6 | 3 | null |
2013-10-11 15:58:03.913 UTC
| 9 |
2022-02-16 21:29:21.213 UTC
|
2015-04-29 13:11:54.263 UTC
| null | 888,472 | null | 875,317 | null | 1 | 58 |
.net-assembly|visual-studio-debugging|visual-studio-2013|system.net|mediatypeformatter
| 75,289 |
<p>I had the same problem. I used <a href="http://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/" rel="noreferrer">Microsoft Asp Net WebApi Client 4.0.20710</a> and it worked for me.</p>
<p>Type the following command into Tools > Library Package Manager > Package Manager Console:</p>
<pre><code>Install-Package Microsoft.AspNet.WebApi.Client -Version 4.0.20710
</code></pre>
|
34,051,747 |
Get Environment Variable from Docker Container
|
<p>What's the simplest way to get an environment variable from a docker container <em>that has not been declared in the Dockerfile</em>?</p>
<p>For instance, an environment variable that has been set through some <code>docker exec container /bin/bash</code> session?</p>
<p>I can do <code>docker exec container env | grep ENV_VAR</code>, but I would prefer something that just returns the value.</p>
<p>I've tried using <code>docker exec container echo "$ENV_VAR"</code>, but the substitution seems to happen outside of the container, so I don't get the env var from the container, but rather the env var from my own computer.</p>
<p>Thanks.</p>
| 34,052,766 | 12 | 3 | null |
2015-12-02 19:51:30.567 UTC
| 49 |
2022-07-20 17:16:37.997 UTC
|
2015-12-02 19:59:30.053 UTC
| null | 4,463,660 | null | 4,463,660 | null | 1 | 198 |
bash|docker|environment-variables
| 276,905 |
<p>The proper way to run <code>echo "$ENV_VAR"</code> inside the container so that the variable substitution happens in the container is:</p>
<pre><code>docker exec <container_id> bash -c 'echo "$ENV_VAR"'
</code></pre>
|
24,855,515 |
Debug Error -Abort() Has Been Called
|
<p>I'm trying to enter a number,n and get the least super lucky number that is more than or equal to n.
Super lucky: it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.</p>
<p>Here's my code</p>
<pre><code> #include<iostream>
#include<string>
using namespace std;
void superLucky(int n,string s, int count4, int count7)
{
if (s.size() > 10)
return;
if (( stoi(s) >= n ) && (count4 == count7) && (count4+count7)!=0)
{
cout << s << endl;
return;
}
superLucky(n, s + '4', count4+1, count7);
superLucky(n, s + '7',count4,count7+1);
}
int main()
{
int n;
cin >> n;
superLucky(n, "", 0, 0);
return 0;
}
</code></pre>
<p>Once I input some integer I get debug error R6010 - abort() has been called. What this means ? and how can I fix this ? </p>
| 24,855,641 | 3 | 2 | null |
2014-07-20 22:29:28.937 UTC
| 3 |
2016-10-13 22:28:22.95 UTC
| null | null | null | null | 3,697,826 | null | 1 | 15 |
c++|abort
| 90,322 |
<p>There are couple of issues:</p>
<ol>
<li><p>When you call <code>superLucky</code> from <code>main</code>, <code>s</code> is empty. <code>stoi(s)</code> throws an exception when <code>s</code> is empty.</p></li>
<li><p>The check <code>s.size() > 10</code> is not robust. It is platform dependent. You can use a <code>try/catch</code> block to deal with it instead of hard coding a size.</p></li>
</ol>
<p>Here's a more robust version of the function.</p>
<pre><code>void superLucky(int n,string s, int count4, int count7)
{
int d = 0;
if ( s.size() > 0 )
{
try
{
d = stoi(s);
}
catch (...)
{
return;
}
if (( d >= n ) && (count4 == count7) && (count4+count7)!=0)
{
cout << s << endl;
return;
}
}
superLucky(n, s + '7',count4,count7+1);
superLucky(n, s + '4', count4+1, count7);
}
</code></pre>
|
866,070 |
NullReferenceException was unhandled, Object Reference not set to an instance of an object
|
<p>Whenever I run my program, I get: NullReferenceException was unhandled, Object Reference not set to an instance of an object.</p>
<p>When I start the program, I have a form appear called MaxScore where the user enters the max score and presses OK. In the OK event, I call a method from MainForm to update the maxGameCountLabel on MainForm with the value entered for the max score, as a parameter.</p>
<p>When I press ok, I get the NullReferenceException at </p>
<pre><code>myGameCountLbl.Text = maxGames.ToString();
</code></pre>
<p>of my maxGameCountLblUpdate method.</p>
<p>Here is the maxGameCountLblUpdate method code which resides in MainForm:</p>
<pre><code>//Update game count label
public void maxGameCountLblUpdate(decimal maxGames)
{
maxGames = decimal.ToInt32(maxGames);
myGameCountLbl.Text = maxGames.ToString();
compGameCountLbl.Text = maxGames.ToString();
}
</code></pre>
<p>Here is my OK Button event on MaxScore:</p>
<pre><code>private void okBtn_Click(object sender, EventArgs e)
{
MainForm.maxGameCountLblUpdate(max);
}
</code></pre>
<p>Note, I have set</p>
<pre><code>public Form1 MainForm { get; set; }
</code></pre>
<p>in MaxScore</p>
<p>And I create MaxScore in MainForm with:</p>
<pre><code> using (MaxScore scoreForm = new MaxScore())
{
scoreForm.MainForm = this;
scoreForm.ShowDialog();
}
</code></pre>
<p>I can't get this to work.. I have tried many things..
Thanks!</p>
<p>EDIT: After adding a breakpoint at myGameCountLbl.Text = maxGames.ToString();
myGameCountLbl appears to be coming up as null... Im sorry for being a newb... How do I fix this? maxGames, indeed, does come up as 1, so that is not the problem</p>
| 866,216 | 5 | 1 | null |
2009-05-14 22:00:24.827 UTC
| 1 |
2013-01-14 07:11:30.227 UTC
|
2009-05-14 22:28:36.88 UTC
| null | 49,549 | null | 49,549 | null | 1 | 3 |
c#|exception|reference|null|instance
| 49,073 |
<p>Did you remove: <code>InitializeComponent();</code> from the constructor?</p>
<p>If you are using the designer to build the form UI, Visual Studio builds a method in the background (Class.designer.cs) to initialize the controls. If you don't call <code>InitializeComponent()</code> before you access the UI elements, you will get a NullReferenceException.</p>
|
713,634 |
Passing a delegate with two parameters as a parameter function
|
<p>I have a sequence of functions that look very similar but for a single line, like the following two (but I have many more of them):</p>
<pre><code>private static int HowManyHoursInTheFirstYear(IList<T> samples)
{
DateTime firstDate = samples[0].Date;
int count = 0;
while (count < samples.Count &&
samples[count].Date.Year == firstDate.Year)
{
count++;
}
return count;
}
private static int HowManyDaysInTheFirstMonth(IList<T> samples)
{
DateTime firstDate = samples[0].Date;
int count = 0;
while (count < samples.Count &&
samples[count].Date.Month == firstDate.Month) // <--- only change!
count++;
}
return count;
}
</code></pre>
<p>I was thinking about using delegates to remove this repetition in code in some elegant way, that would have allowed me to invoke something like:</p>
<pre><code>HowManyDaysInTheFirstPeriod(
samples,
delegate(DateTime d1, DateTime d2) { return d1.Month == d2.Month; });
</code></pre>
<p>thereby declaring a delegate like the following:</p>
<pre><code>delegate bool DateComparer(DateTime first, DateTime second);
</code></pre>
<p>and where HowManyDaysInTheFirstPeriod whould be something like the following:</p>
<pre><code>private static int HowManySamplesInFirstPeriod
IList<T> samples,
DateComparer comparer)
{
DateTime firstDate = samples[0].Date;
int count = 0;
while (count < samples.Count && comparer())
{
count++;
}
}
</code></pre>
<p>Unfortunately, the compiler complains that comparer needs two parameters. </p>
<p>I am relatively new to C# and hit a road-block here.
How would you solve this?</p>
| 713,651 | 5 | 1 | null |
2009-04-03 11:57:51.427 UTC
| 6 |
2012-06-11 15:26:58.767 UTC
|
2012-06-11 15:26:58.767 UTC
|
Stefano
| 41,071 |
Stefano
| 85,556 | null | 1 | 23 |
c#|delegates
| 46,088 |
<p>You're almost there! The <code>comparer</code> delegate parameter is just like any other function: <strong>You still need to pass the appropriate arguments to invoke it.</strong> In your case, that's going to mean this change:</p>
<pre><code>while (count < samples.Count && comparer(samples[count].Date, firstDate))
{
count++;
}
</code></pre>
<p><strong>(Also, note that <code>samples</code> should probably be <code>samples.Count</code>, as I have written above.)</strong></p>
|
1,030,270 |
Race conditions in django
|
<p>Here is a simple example of a django view with a potential race condition:</p>
<pre><code># myapp/views.py
from django.contrib.auth.models import User
from my_libs import calculate_points
def add_points(request):
user = request.user
user.points += calculate_points(user)
user.save()
</code></pre>
<p>The race condition should be fairly obvious: A user can make this request twice, and the application could potentially execute <code>user = request.user</code> simultaneously, causing one of the requests to override the other.</p>
<p>Suppose the function <code>calculate_points</code> is relatively complicated, and makes calculations based on all kinds of weird stuff that cannot be placed in a single <code>update</code> and would be difficult to put in a stored procedure.</p>
<p>So here is my question: What kind of locking mechanisms are available to django, to deal with situations similar to this?</p>
| 10,987,224 | 6 | 3 | null |
2009-06-23 01:53:37.477 UTC
| 32 |
2021-06-28 08:01:08.547 UTC
|
2014-03-15 11:04:57.393 UTC
| null | 992,887 | null | 121,112 | null | 1 | 46 |
python|database|django|locking|race-condition
| 22,951 |
<p>Django 1.4+ supports <a href="https://docs.djangoproject.com/en/stable/ref/models/querysets/#django.db.models.query.QuerySet.select_for_update" rel="nofollow noreferrer">select_for_update</a>, in earlier versions you may execute raw SQL queries e.g. <code>select ... for update</code> which depending on underlying DB will lock the row from any updates, you can do whatever you want with that row until the end of transaction. e.g.</p>
<pre><code>from django.db import transaction
@transaction.commit_manually()
def add_points(request):
user = User.objects.select_for_update().get(id=request.user.id)
# you can go back at this point if something is not right
if user.points > 1000:
# too many points
return
user.points += calculate_points(user)
user.save()
transaction.commit()
</code></pre>
|
1,194,656 |
Appending to an ObjectOutputStream
|
<p>Is it not possible to append to an <code>ObjectOutputStream</code>?</p>
<p>I am trying to append to a list of objects. Following snippet is a function that is called whenever a job is finished.</p>
<pre><code>FileOutputStream fos = new FileOutputStream
(preferences.getAppDataLocation() + "history" , true);
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject( new Stuff(stuff) );
out.close();
</code></pre>
<p>But when I try to read it I only get the first in the file.
Then I get <code>java.io.StreamCorruptedException</code>.</p>
<p>To read I am using</p>
<pre><code>FileInputStream fis = new FileInputStream
( preferences.getAppDataLocation() + "history");
ObjectInputStream in = new ObjectInputStream(fis);
try{
while(true)
history.add((Stuff) in.readObject());
}catch( Exception e ) {
System.out.println( e.toString() );
}
</code></pre>
<p>I do not know how many objects will be present so I am reading while there are no exceptions. From what Google says this is not possible. I was wondering if anyone knows a way?</p>
| 1,195,078 | 6 | 5 | null |
2009-07-28 14:51:03.06 UTC
| 29 |
2019-10-18 08:13:00.42 UTC
|
2011-10-15 16:54:46.93 UTC
| null | 213,269 | null | 89,904 | null | 1 | 61 |
java|serialization|append|objectoutputstream|objectinputstream
| 66,526 |
<p>Here's the trick: subclass <code>ObjectOutputStream</code> and override the <code>writeStreamHeader</code> method:</p>
<pre><code>public class AppendingObjectOutputStream extends ObjectOutputStream {
public AppendingObjectOutputStream(OutputStream out) throws IOException {
super(out);
}
@Override
protected void writeStreamHeader() throws IOException {
// do not write a header, but reset:
// this line added after another question
// showed a problem with the original
reset();
}
}
</code></pre>
<p>To use it, just check whether the history file exists or not and instantiate either this appendable stream (in case the file exists = we append = we don't want a header) or the original stream (in case the file does not exist = we need a header).</p>
<p><strong>Edit</strong></p>
<p>I wasn't happy with the first naming of the class. This one's better: it describes the 'what it's for' rather then the 'how it's done'</p>
<p><strong>Edit</strong></p>
<p>Changed the name once more, to clarify, that this stream is only for appending to an existing file. It can't be used to create a <em>new</em> file with object data.</p>
<p><strong>Edit</strong></p>
<p>Added a call to <code>reset()</code> after <a href="https://stackoverflow.com/questions/12279245/classcastexception-when-appending-object-outputstream/12438141#12438141">this question</a> showed that the original version that just overrode <code>writeStreamHeader</code> to be a no-op could under some conditions create a stream that couldn't be read.</p>
|
268,384 |
PRINT statement in T-SQL
|
<p>Why does the PRINT statement in T-SQL seem to only sometimes work? What are the constraints on using it? It seems sometimes if a result set is generated, it becomes a null function, I assumed to prevent corrupting the resultset, but could it's output not go out in another result set, such as the row count?</p>
| 268,419 | 6 | 1 | null |
2008-11-06 11:43:09.227 UTC
| 24 |
2021-07-07 04:21:58.943 UTC
| null | null | null |
ProfK
| 8,741 | null | 1 | 86 |
sql-server|tsql
| 307,462 |
<p>So, if you have a statement something like the following, you're saying that you get no 'print' result?</p>
<pre>select * from sysobjects
PRINT 'Just selected * from sysobjects'</pre>
<p>If you're using SQL Query Analyzer, you'll see that there are two tabs down at the bottom, one of which is "Messages" and that's where the 'print' statements will show up.<br>
If you're concerned about the <i>timing</i> of seeing the print statements, you may want to try using something like</p>
<pre>raiserror ('My Print Statement', 10,1) with nowait</pre>
<p>This will give you the message immediately as the statement is reached, rather than buffering the output, as the Query Analyzer will do under most conditions.</p>
|
590,159 |
Does a locked object stay locked if an exception occurs inside it?
|
<p>In a c# threading app, if I were to lock an object, let us say a queue, and if an exception occurs, will the object stay locked? Here is the pseudo-code:</p>
<pre><code>int ii;
lock(MyQueue)
{
MyClass LclClass = (MyClass)MyQueue.Dequeue();
try
{
ii = int.parse(LclClass.SomeString);
}
catch
{
MessageBox.Show("Error parsing string");
}
}
</code></pre>
<p>As I understand it, code after the catch doesn't execute - but I have been wondering if the lock will be freed. </p>
| 590,174 | 6 | 5 | null |
2009-02-26 11:31:13.513 UTC
| 20 |
2015-04-22 08:18:14.89 UTC
|
2012-08-16 09:16:08.55 UTC
| null | 512,251 |
Khadaji
| 55,520 | null | 1 | 91 |
c#|.net|multithreading|exception|locking
| 44,696 |
<p>First; have you considered TryParse?</p>
<pre><code>in li;
if(int.TryParse(LclClass.SomeString, out li)) {
// li is now assigned
} else {
// input string is dodgy
}
</code></pre>
<p>The lock will be released for 2 reasons; first, <code>lock</code> is essentially:</p>
<pre><code>Monitor.Enter(lockObj);
try {
// ...
} finally {
Monitor.Exit(lockObj);
}
</code></pre>
<p>Second; you catch and don't re-throw the inner exception, so the <code>lock</code> never actually sees an exception. Of course, you are holding the lock for the duration of a MessageBox, which might be a problem.</p>
<p>So it will be released in all but the most fatal catastrophic unrecoverable exceptions.</p>
|
1,244,788 |
<embed> vs. <object>
|
<p>Which is the right/best tag to use in my HTML file when I want to display the Adobe PDF viewer?</p>
<p>Right now I'm using the code below, but there are weird side effects (e.g. it seems to steal the starting focus that I've set to another <code><input></code> text box; it doesn't seem to play real well with the jQueryUI Resizeable class; etc.)</p>
<pre><code><embed src="abc.pdf" type="application/pdf" />
</code></pre>
<p>Could I even do the same thing with the <code><object></code> tag? Are there advantages/disadvantages to using one tag vs. the other?</p>
| 1,244,854 | 6 | 2 | null |
2009-08-07 13:47:21.687 UTC
| 74 |
2021-07-25 19:30:48.35 UTC
|
2019-08-09 15:58:15.937 UTC
| null | 3,345,644 | null | 106,357 | null | 1 | 189 |
html|pdf|embed-tag
| 229,366 |
<p><a href="http://www.webmasterworld.com/forum104/659.htm" rel="noreferrer">OBJECT vs. EMBED - why not always use embed?</a></p>
<blockquote>
<p>Bottom line: OBJECT is Good, EMBED is Old. Beside's IE's PARAM tags, any content between OBJECT tags will get rendered if the browser doesn't support OBJECT's referred plugin, and apparently, the content gets http requested regardless if it gets rendered or not. </p>
</blockquote>
<p><code>object</code> is the current standard tag to embed something on a page. <a href="http://www.webmonkey.com/blog/The_History_of_IMG_and_EMBED_Tags" rel="noreferrer"><code>embed</code> was included by Netscape (along <code>img</code>)</a> before anything like <code>object</code> were on the <a href="http://www.w3.org" rel="noreferrer">w3c</a> mind.</p>
<p>This is how you <a href="http://joliclic.free.fr/html/object-tag/en/" rel="noreferrer">include a PDF with <code>object</code></a>:</p>
<pre><code><object data="data/test.pdf" type="application/pdf" width="300" height="200">
alt : <a href="data/test.pdf">test.pdf</a>
</object>
</code></pre>
<p>If you <strong>really need</strong> the inline PDF to show in almost every browser, as older browsers understand <code>embed</code> but not <code>object</code>, you'll need to do this:</p>
<pre><code><object data="abc.pdf" type="application/pdf">
<embed src="abc.pdf" type="application/pdf" />
</object>
</code></pre>
<p>This version <em>does not validate</em>.</p>
|
42,345,254 |
Excel Solver Password: what is it and where can it be acquired/bought?
|
<p>I've been exploring VBA and excel and I've been writing a few basic codes around the Excel Solver. However robust the Excel Solver may appear, it's just not fast enough for my optimization problem (one iteration takes 20 minutes).</p>
<p>I've been looking around and speaking with more experienced programmers, and the consensus is that VBA is simply not fast and that C++, C#, and especially CUDA languages are much faster.</p>
<p>Looking at the VBA modules in Excel, the Solver module is locked by a password. I've been searching for that password and where it can be acquired for weeks to no avail.</p>
<p>Questions: Can this password be acquired? If so, how? Can it be bought from Microsoft? How much?</p>
<p>Objective: To get the Solver VBA to be able to potentially convert it to C# or C++ to make the optimization process faster. </p>
<p>P.S.
I've looked at Microsoft Solver Foundation but it wasn't helpful.</p>
<p>Thank you.</p>
| 42,345,506 | 3 | 4 | null |
2017-02-20 12:59:42.79 UTC
| 6 |
2020-10-08 14:11:27.447 UTC
| null | null | null | null | 7,593,090 | null | 1 | 8 |
excel|vba|passwords|solver
| 43,960 |
<p>You can use this password to unlock the SOLVER.XLAM project;</p>
<p>Wildebeest!!</p>
|
30,899,163 |
How do I use multiple consumers in Kafka?
|
<p>I am a new student studying Kafka and I've run into some fundamental issues with understanding multiple consumers that articles, documentations, etc. have not been too helpful with so far. </p>
<p>One thing I have tried to do is write my own high level Kafka producer and consumer and run them simultaneously, publishing 100 simple messages to a topic and having my consumer retrieve them. I have managed to do this successfully, but when I try to introduce a second consumer to consume from the same topic that messages were just published to, it receives no messages.</p>
<p>It was my understanding that for each topic, you could have consumers from separate consumer groups and each of these consumer groups would get a full copy of the messages produced to some topic. Is this correct? If not, what would be the proper way for me to set up multiple consumers? This is the consumer class that I have written so far:</p>
<pre><code>public class AlternateConsumer extends Thread {
private final KafkaConsumer<Integer, String> consumer;
private final String topic;
private final Boolean isAsync = false;
public AlternateConsumer(String topic, String consumerGroup) {
Properties properties = new Properties();
properties.put("bootstrap.servers", "localhost:9092");
properties.put("group.id", consumerGroup);
properties.put("partition.assignment.strategy", "roundrobin");
properties.put("enable.auto.commit", "true");
properties.put("auto.commit.interval.ms", "1000");
properties.put("session.timeout.ms", "30000");
properties.put("key.deserializer", "org.apache.kafka.common.serialization.IntegerDeserializer");
properties.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
consumer = new KafkaConsumer<Integer, String>(properties);
consumer.subscribe(topic);
this.topic = topic;
}
public void run() {
while (true) {
ConsumerRecords<Integer, String> records = consumer.poll(0);
for (ConsumerRecord<Integer, String> record : records) {
System.out.println("We received message: " + record.value() + " from topic: " + record.topic());
}
}
}
}
</code></pre>
<p>Furthermore, I noticed that originally I was testing the above consumption for a topic 'test' with only a single partition. When I added another consumer to an existing consumer group say 'testGroup', this trigged a Kafka rebalance which slowed down the latency of my consumption by a significant amount, in the magnitude of seconds. I thought that this was an issue with rebalancing since I only had a single partition, but when I created a new topic 'multiplepartitions' with say 6 partitions, similar issues arose where adding more consumers to the same consumer group caused latency issues. I have looked around and people are telling me I should be using a multi-threaded consumer -- can anyone shed light on that?</p>
| 30,899,709 | 3 | 3 | null |
2015-06-17 18:10:24.507 UTC
| 13 |
2020-05-01 17:09:19.617 UTC
|
2020-05-01 17:09:19.617 UTC
| null | 4,157,124 | null | 5,013,133 | null | 1 | 40 |
java|apache-kafka
| 58,748 |
<p>I think your problem lies with the auto.offset.reset property. When a new consumer reads from a partition and there's no previous committed offset, the auto.offset.reset property is used to decide what the starting offset should be. If you set it to "largest" (the default) you start reading at the latest (last) message. If you set it to "smallest" you get the first available message.</p>
<p>So add:</p>
<pre><code>properties.put("auto.offset.reset", "smallest");
</code></pre>
<p>and try again.</p>
<p><strong>* edit *</strong></p>
<p>"smallest" and "largest" were deprecated a while back. You should use "earliest" or "latest" now. Any questions, check the <a href="https://kafka.apache.org/documentation/#configuration" rel="noreferrer">docs</a></p>
|
18,021,972 |
Cannot access a disposed object error
|
<p>I am getting the error message <strong>Cannot access a disposed object.
Object name: 'ApplicationProperties'.</strong> when I tryo to re-open a form after closing it. I have noticed this is from exiting forms, and exiting is <strong>"Disposing"</strong> of them, so I have put the following code in all of my accept buttons, and cancel buttons (any button that closes a form).</p>
<pre><code> this.Hide();
this.Parent = null;
</code></pre>
<p>This code is just hiding the form. <strong>Not closing the form.</strong></p>
<p>So what my problem is, is that when I click the 'x' button on the form, then try to re-open the form I still get the error message. I have tried a couple differnet ways to modify the exiting funciton of the form such as:</p>
<pre><code> private void ApplicationProperties_FormClosing(object sender, FormClosingEventArgs e)
{
//Hiding the window, because closing it makes the window unaccessible.
this.Hide();
this.Parent = null;
}
</code></pre>
<p>But this has brought me no luck. I was wondering if anyone knows how to solve this problem. Here is the code that is working for me inside my cancel and accept buttons. It is the same for all of my buttons that close forms.</p>
<pre><code> private void OptionsCancelbtn_Click(object sender, EventArgs e)
{
//Hiding the window, because closing it makes the window unaccessible.
this.Hide();
this.Parent = null;
}
</code></pre>
<p>I have declared the instance at the top of my class on form1, and have a button inside form1 that opens form2.</p>
<pre><code>public partial class MainBox : Form
{
//Making a name for the ApplicationProperties form. It can be opened when called.
ApplicationProperties ApplicationPropertiesWindow = new ApplicationProperties();
private void ApplicationPropertiesbtn_Click(object sender, EventArgs e)
{
//Show the properties window.
ApplicationPropertiesWindow.Show();
}//End ApplicationProperties button.
}
</code></pre>
<p>After I close the program with the 'x' button on the second form I cannot access form2 again because of the error message firing at <code>ApplicationPropertiesWindow.Show();</code></p>
<p>Inside form2 I have the following code:</p>
<pre><code>public partial class ApplicationProperties : Form
{
//Creates and sets the instance MainBoxWindow.
public MainBox MainBoxWindow { get; set; }
</code></pre>
| 18,022,077 | 4 | 8 | null |
2013-08-02 16:33:23.253 UTC
| 5 |
2014-12-29 12:29:25.797 UTC
|
2013-08-02 18:32:49.84 UTC
| null | 2,505,594 | null | 2,505,594 | null | 1 | 10 |
c#|winforms
| 45,828 |
<p>Try this in your <code>FormClosing</code> event:</p>
<pre><code> private void ApplicationProperties_FormClosing(object sender, FormClosingEventArgs e)
{
//Hiding the window, because closing it makes the window unaccessible.
this.Hide();
this.Parent = null;
e.Cancel = true; //hides the form, cancels closing event
}
</code></pre>
<p>cause right now it is still closing the form, thus still causing the error.</p>
|
46,636,255 |
firebase.firestore() is not a function when trying to initialize Cloud Firestore
|
<p>When I try to initialize Firebase Cloud Firestore, I ran into the following error: </p>
<blockquote>
<p>Uncaught TypeError: <strong>WEBPACK_IMPORTED_MODULE_0_firebase</strong>.firestore is not a function</p>
</blockquote>
<p>I installed firebase with <code>npm install firebase --save</code> previously.</p>
<pre><code>import * as firebase from 'firebase';
import router from '../router';
const config = {
apiKey: "a",
authDomain: "a",
databaseURL: "a",
projectId: "a",
storageBucket: "a",
messagingSenderId: "a"
};
if(!firebase.apps.length){
firebase.initializeApp(config);
let firestore = firebase.firestore();
}
</code></pre>
| 50,684,682 | 29 | 7 | null |
2017-10-08 21:27:14.88 UTC
| 17 |
2022-07-31 20:52:13.413 UTC
|
2018-10-13 22:08:58.907 UTC
| null | 1,640,892 | null | 8,020,389 | null | 1 | 90 |
javascript|firebase|google-cloud-firestore
| 127,516 |
<p>I fixed it by importing multiple libraries: <code>firebase</code> and <code>firebase/firestore</code>. That's because the <code>firebase</code> core library does not include the firestore library.</p>
<pre><code>import firebase from 'firebase/app';
import 'firebase/firestore';
</code></pre>
|
1,596,963 |
Read a file from server with SSH using Python
|
<p>I am trying to read a file from a server using SSH from Python. I am using Paramiko to connect. I can connect to the server and run a command like <code>cat filename</code> and get the data back from the server but some files I am trying to read are around 1 GB or more in size.</p>
<p>How can I read the file on the server line by line using Python?</p>
<p>Additional Info: What is regularly do is run a <code>cat filename</code> command and store the result in a variable and work off that. But since the file here is quite big, I am looking for a way to read a file line by line off the server.</p>
<p>EDIT: I can read a bunch of data and split it into lines but the problem is that the data received in the buffer does not always include the complete lines. For eg, if buffer has 300 lines, the last line may only be half of the line on the server and the next half would be fetched in the next call to the server. I want complete lines </p>
<p>EDIT 2: what command can I use to print lines in a file in a certain range. Like print first 100 lines, then the next 100 and so on? This way the buffer will always contain complete lines.</p>
| 1,597,750 | 6 | 0 | null |
2009-10-20 20:04:00.13 UTC
| 20 |
2022-03-22 23:04:52.627 UTC
|
2019-04-01 10:10:07.26 UTC
| null | 850,848 | null | 178,437 | null | 1 | 45 |
python|ssh|paramiko
| 128,954 |
<p><a href="https://docs.paramiko.org/en/stable/api/sftp.html" rel="noreferrer">Paramiko's <code>SFTPClient</code> class</a> allows you to get a file-like object to read data from a remote file in a Pythonic way.</p>
<p>Assuming you have an open <code>SSHClient</code>:</p>
<pre><code>sftp_client = ssh_client.open_sftp()
remote_file = sftp_client.open('remote_filename')
try:
for line in remote_file:
# process line
finally:
remote_file.close()
</code></pre>
|
2,054,022 |
Is it unnecessary to put super() in constructor?
|
<p>Isn't this one automatically put by the compiler if I don't put it in a subclass's constructor?</p>
<p>That means I don't even need to care about it? In some articles they put it out.</p>
<p>And if I've got one constructor with arguments, will this be the constructor, or does it take a constructor without argument list? </p>
| 2,054,040 | 6 | 0 | null |
2010-01-13 02:42:58.453 UTC
| 60 |
2018-12-07 22:35:00.543 UTC
|
2015-09-15 06:59:02.173 UTC
| null | 966,185 | null | 206,446 | null | 1 | 184 |
java|constructor|super
| 102,400 |
<p>Firstly some terminology:</p>
<ul>
<li><strong>No-args constructor:</strong> a constructor with no parameters;</li>
<li><strong>Accessible no-args constructor:</strong> a no-args constructor in the superclass visible to the subclass. That means it is either public or protected or, if both classes are in the same package, package access; and</li>
<li><strong>Default constructor:</strong> the public no-args constructor added by the compiler when there is no explicit constructor in the class.</li>
</ul>
<p>So all classes have at least one constructor.</p>
<p>Subclasses constructors <em>may</em> specify as the first thing they do which constructor in the superclass to invoke before executing the code in the subclass's constructor.</p>
<p><strong>If the subclass constructor does not specify which superclass constructor to invoke then the compiler will automatically call the accessible no-args constructor in the superclass.</strong></p>
<p>If the superclass has no no-arg constructor or it isn't accessible then not specifying the superclass constructor to be called (in the subclass constructor) is a compiler error so it <em>must</em> be specified.</p>
<p>For example:</p>
<pre><code>public class Base { }
public class Derived extends Base { }
</code></pre>
<p>This is fine because if you add no constructor explicitly Java puts in a public default constructor for you.</p>
<pre><code>public class Base { }
public class Derived extends Base { public Derived(int i) { } }
</code></pre>
<p>Also fine.</p>
<pre><code>public class Base { public Base(String s) { } }
public class Derived extends Base { }
</code></pre>
<p>The above is a compilation error as Base has no default constructor.</p>
<pre><code>public class Base { private Base() { } }
public class Derived extends Base { }
</code></pre>
<p>This is also an error because Base's no-args constructor is private.</p>
|
2,129,123 |
Rearrange columns using cut
|
<p>I am having a file in the following format</p>
<pre>
Column1 Column2
str1 1
str2 2
str3 3
</pre>
<p>I want the columns to be rearranged. I tried below command</p>
<blockquote>
<p>cut -f2,1 file.txt</p>
</blockquote>
<p>The command doesn't reorder the columns. Any idea why its not working?</p>
| 2,129,133 | 9 | 0 | null |
2010-01-24 22:17:40.023 UTC
| 28 |
2021-11-27 13:13:52.583 UTC
|
2021-11-27 13:13:52.583 UTC
| null | 276,052 | null | 207,335 | null | 1 | 160 |
shell|csv|cut
| 139,491 |
<p>For the <code>cut(1)</code> man page:</p>
<blockquote>
<p>Use one, and only one of -b, -c or -f. Each LIST is made up of
one
range, or many ranges separated by commas. Selected input is written
in the same order that it is read, and is written exactly once.</p>
</blockquote>
<p>It reaches field 1 first, so that is printed, followed by field 2.</p>
<p>Use <code>awk</code> instead:</p>
<pre><code>awk '{ print $2 " " $1}' file.txt
</code></pre>
|
33,636,796 |
Chrome / Safari not filling 100% height of flex parent
|
<p>I want to have a vertical menu with a specific height.</p>
<p>Each child must fill the height of the parent and have middle-aligned text.</p>
<p>The number of children is random, so I have to work with dynamic values.</p>
<p>Div <code>.container</code> contains a random number of children (<code>.item</code>) that always have to fill the height of the parent. To achieve that I used flexbox. </p>
<p>For making links with text aligned to the middle I am using <code>display: table-cell</code> technique. But using table displays requires using a height 100%.</p>
<p>My problem is that <code>.item-inner { height: 100% }</code> is not working in webkit (Chrome). </p>
<ol>
<li>Is there a fix for this problem? </li>
<li>Or is there a different technique to make all <code>.item</code> fill the height of the parent with text vertical aligned to middle?</li>
</ol>
<p><a href="http://jsfiddle.net/y8mboo2s/" rel="noreferrer">Example here jsFiddle, should be viewed in Firefox and Chrome</a></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.container {
height: 20em;
display: flex;
flex-direction: column;
border: 5px solid black
}
.item {
flex: 1;
border-bottom: 1px solid white;
}
.item-inner {
height: 100%;
width: 100%;
display: table;
}
a {
background: orange;
display: table-cell;
vertical-align: middle;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="container">
<div class="item">
<div class="item-inner">
<a>Button</a>
</div>
</div>
<div class="item">
<div class="item-inner">
<a>Button</a>
</div>
</div>
<div class="item">
<div class="item-inner">
<a>Button</a>
</div>
</div>
</div></code></pre>
</div>
</div>
</p>
| 33,644,245 | 5 | 3 | null |
2015-11-10 18:16:27.727 UTC
| 118 |
2020-03-05 06:14:52.18 UTC
|
2016-07-11 02:58:07.39 UTC
| null | 3,597,276 | null | 1,021,122 | null | 1 | 290 |
css|google-chrome|webkit|flexbox
| 218,827 |
<h2>Solution</h2>
<p>Use nested flex containers.</p>
<p>Get rid of percentage heights. Get rid of table properties. Get rid of <code>vertical-align</code>. Avoid absolute positioning. <em>Just stick with flexbox all the way through.</em></p>
<p>Apply <code>display: flex</code> to the flex item (<code>.item</code>), making it a flex container. This automatically sets <code>align-items: stretch</code>, which tells the child (<code>.item-inner</code>) to expand the full height of the parent.</p>
<p><em>Important: Remove specified heights from flex items for this method to work.</em> If a child has a height specified (e.g. <code>height: 100%</code>), then it will ignore the <code>align-items: stretch</code> coming from the parent. For the <code>stretch</code> default to work, the child's height must compute to <code>auto</code> <a href="https://stackoverflow.com/q/44878379/3597276">(full explanation</a>). </p>
<p>Try this (no changes to HTML):</p>
<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.container {
display: flex;
flex-direction: column;
height: 20em;
border: 5px solid black
}
.item {
display: flex; /* new; nested flex container */
flex: 1;
border-bottom: 1px solid white;
}
.item-inner {
display: flex; /* new; nested flex container */
flex: 1; /* new */
/* height: 100%; <-- remove; unnecessary */
/* width: 100%; <-- remove; unnecessary */
/* display: table; <-- remove; unnecessary */
}
a {
display: flex; /* new; nested flex container */
flex: 1; /* new */
align-items: center; /* new; vertically center text */
background: orange;
/* display: table-cell; <-- remove; unnecessary */
/* vertical-align: middle; <-- remove; unnecessary */
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="container">
<div class="item">
<div class="item-inner">
<a>Button</a>
</div>
</div>
<div class="item">
<div class="item-inner">
<a>Button</a>
</div>
</div>
<div class="item">
<div class="item-inner">
<a>Button</a>
</div>
</div>
</div></code></pre>
</div>
</div>
</p>
<p><a href="http://jsfiddle.net/y8mboo2s/3/" rel="noreferrer">jsFiddle demo</a></p>
<hr>
<h2>Explanation</h2>
<blockquote>
<p>My problem is that <code>.item-inner { height: 100% }</code> is not working in
webkit (Chrome).</p>
</blockquote>
<p>It's not working because you're using percentage height in a way that doesn't conform with the traditional implementation of the spec.</p>
<blockquote>
<p><a href="http://www.w3.org/TR/CSS22/visudet.html#the-height-property" rel="noreferrer"><strong>10.5 Content height: the <code>height</code> property</strong></a></p>
<p><strong>percentage</strong><br> Specifies a percentage height. The percentage is calculated with respect to the height of the generated box's
containing block. If the height of the containing block is not
specified explicitly and this element is not absolutely positioned, the value computes to <code>auto</code>.</p>
<p><strong>auto</strong><br> The height depends on the values of other properties.</p>
</blockquote>
<p>In other words, for percentage height to work on an in-flow child, the parent <em>must</em> have a set height.</p>
<p>In your code, the top-level container has a defined height: <code>.container { height: 20em; }</code></p>
<p>The third-level container has a defined height: <code>.item-inner { height: 100%; }</code></p>
<p>But between them, the second-level container – <code>.item</code> – <em>does not</em> have a defined height. Webkit sees that as a missing link.</p>
<p><code>.item-inner</code> is telling Chrome: <em>give me <code>height: 100%</code></em>. Chrome looks to the parent (<code>.item</code>) for reference and responds: <em>100% of what? I don't see anything</em> (ignoring the <code>flex: 1</code> rule that is there). As a result, it applies <code>height: auto</code> (content height), in accordance with the spec.</p>
<p>Firefox, on the other hand, now accepts a parent's flex height as a reference for the child's percentage height. IE11 and Edge accept flex heights, as well.</p>
<p>Also, Chrome will accept <code>flex-grow</code> as an adequate parent reference <em>if used in conjunction with <code>flex-basis</code></em> (any numerical value works (<a href="https://stackoverflow.com/q/53870751/3597276"><code>auto</code></a> won't), including <code>flex-basis: 0</code>). As of this writing, however, this solution fails in Safari.</p>
<p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-css lang-css prettyprint-override"><code>#outer {
display: flex;
flex-direction: column;
height: 300px;
background-color: white;
border: 1px solid red;
}
#middle {
flex-grow: 1;
flex-basis: 1px;
background-color: yellow;
}
#inner {
height: 100%;
background-color: lightgreen;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="outer">
<div id="middle">
<div id="inner">
INNER
</div>
</div>
</div></code></pre>
</div>
</div>
</p>
<hr>
<h2>Four Solutions</h2>
<p><strong><em>1. Specify a height on all parent elements</em></strong></p>
<p>A reliable cross-browser solution is to specify a height on all parent elements. This prevents missing links, which Webkit-based browsers consider a violation of the spec.</p>
<p><em>Note that <code>min-height</code> and <code>max-height</code> are not acceptable. It must be the <code>height</code> property.</em></p>
<p>More details here: <a href="https://stackoverflow.com/a/31728799/3597276">Working with the CSS <code>height</code> property and percentage values</a></p>
<p><strong><em>2. CSS Relative & Absolute Positioning</em></strong></p>
<p>Apply <code>position: relative</code> to the parent and <code>position: absolute</code> to the child. </p>
<p>Size the child with <code>height: 100%</code> and <code>width: 100%</code>, or use the offset properties: <code>top: 0</code>, <code>right: 0</code>, <code>bottom: 0</code>, <code>left: 0</code>.</p>
<p>With absolute positioning, percentage height works without a specified height on the parent.</p>
<p><strong><em>3. Remove unnecessary HTML containers (recommended)</em></strong></p>
<p>Is there a need for two containers around <code>button</code>? Why not remove <code>.item</code> or <code>.item-inner</code>, or both? Although <a href="https://stackoverflow.com/q/35464067/3597276"><code>button</code> elements sometimes fail as flex containers</a>, they can be flex items. Consider making <code>button</code> a child of <code>.container</code> or <code>.item</code>, and removing gratuitous mark-up.</p>
<p>Here's an example:</p>
<p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.container {
height: 20em;
display: flex;
flex-direction: column;
border: 5px solid black
}
a {
flex: 1;
background: orange;
border-bottom: 1px solid white;
display: flex; /* nested flex container (for aligning text) */
align-items: center; /* center text vertically */
justify-content: center; /* center text horizontally */
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="container">
<a>Button</a>
<a>Button</a>
<a>Button</a>
</div></code></pre>
</div>
</div>
</p>
<p><strong><em>4. Nested Flex Containers (recommended)</em></strong></p>
<p>Get rid of percentage heights. Get rid of table properties. Get rid of <code>vertical-align</code>. Avoid absolute positioning. <em>Just stick with flexbox all the way through.</em></p>
<p>Apply <code>display: flex</code> to the flex item (<code>.item</code>), making it a flex container. This automatically sets <code>align-items: stretch</code>, which tells the child (<code>.item-inner</code>) to expand the full height of the parent.</p>
<p><em>Important: Remove specified heights from flex items for this method to work.</em> If a child has a height specified (e.g. <code>height: 100%</code>), then it will ignore the <code>align-items: stretch</code> coming from the parent. For the <code>stretch</code> default to work, the child's height must compute to <code>auto</code> <a href="https://stackoverflow.com/q/44878379/3597276">(full explanation</a>). </p>
<p>Try this (no changes to HTML):</p>
<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.container {
display: flex;
flex-direction: column;
height: 20em;
border: 5px solid black
}
.item {
display: flex; /* new; nested flex container */
flex: 1;
border-bottom: 1px solid white;
}
.item-inner {
display: flex; /* new; nested flex container */
flex: 1; /* new */
/* height: 100%; <-- remove; unnecessary */
/* width: 100%; <-- remove; unnecessary */
/* display: table; <-- remove; unnecessary */
}
a {
display: flex; /* new; nested flex container */
flex: 1; /* new */
align-items: center; /* new; vertically center text */
background: orange;
/* display: table-cell; <-- remove; unnecessary */
/* vertical-align: middle; <-- remove; unnecessary */
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="container">
<div class="item">
<div class="item-inner">
<a>Button</a>
</div>
</div>
<div class="item">
<div class="item-inner">
<a>Button</a>
</div>
</div>
<div class="item">
<div class="item-inner">
<a>Button</a>
</div>
</div>
</div></code></pre>
</div>
</div>
</p>
<h2><a href="http://jsfiddle.net/y8mboo2s/3/" rel="noreferrer">jsFiddle</a></h2>
|
8,582,344 |
Does C# have IsNullOrEmpty for List/IEnumerable?
|
<p>I know generally empty List is more prefer than NULL. But I am going to return NULL, for mainly two reasons</p>
<ol>
<li>I have to check and handle null values explicitly, avoiding bugs and attacks.</li>
<li>It is easy to perform <code>??</code> operation afterwards to get a return value.</li>
</ol>
<p>For strings, we have IsNullOrEmpty. Is there anything <strong>from C# itself</strong> doing the same thing for List or IEnumerable?</p>
| 8,582,374 | 11 | 2 | null |
2011-12-20 21:41:30.26 UTC
| 14 |
2022-06-02 21:05:54.36 UTC
|
2015-07-23 23:32:50.52 UTC
| null | 2,751,851 | null | 939,713 | null | 1 | 72 |
c#|ienumerable|isnullorempty
| 90,313 |
<p>nothing baked into the framework, but it's a pretty straight forward extension method.</p>
<p><a href="http://danielvaughan.org/posts/.net/collections/2010/04/18/IEnumerable-IsNullOrEmpty/" rel="noreferrer">See here</a></p>
<pre><code>/// <summary>
/// Determines whether the collection is null or contains no elements.
/// </summary>
/// <typeparam name="T">The IEnumerable type.</typeparam>
/// <param name="enumerable">The enumerable, which may be null or empty.</param>
/// <returns>
/// <c>true</c> if the IEnumerable is null or empty; otherwise, <c>false</c>.
/// </returns>
public static bool IsNullOrEmpty<T>(this IEnumerable<T> enumerable)
{
if (enumerable == null)
{
return true;
}
/* If this is a list, use the Count property for efficiency.
* The Count property is O(1) while IEnumerable.Count() is O(N). */
var collection = enumerable as ICollection<T>;
if (collection != null)
{
return collection.Count < 1;
}
return !enumerable.Any();
}
</code></pre>
<p>Daniel Vaughan takes the extra step of casting to ICollection (where possible) for performance reasons. Something I would not have thought to do.</p>
|
8,474,104 |
Android Fragment lifecycle over orientation changes
|
<p>Using the compatibility package to target 2.2 using Fragments.</p>
<p>After recoding an activity to use fragments in an app I could not get the orientation changes/state management working so I've created a small test app with a single FragmentActivity and a single Fragment.</p>
<p>The logs from the orientation changes are weird, with multiple calls to the fragments OnCreateView.</p>
<p>I'm obviously missing something - like detatching the fragment and reattaching it rather than creating a new instance, but I can't see any documentation which would indicate where I'm going wrong.</p>
<p>Can anyone shed some light on what I'm doing wrong here please.
Thanks</p>
<p>The log is as follows after orientation changes.</p>
<pre><code>Initial creation
12-04 11:57:15.808: D/FragmentTest.FragmentTestActivity(3143): onCreate
12-04 11:57:15.945: D/FragmentTest.FragmentOne(3143): OnCreateView
12-04 11:57:16.081: D/FragmentTest.FragmentOne(3143): OnCreateView->SavedInstanceState null
Orientation Change 1
12-04 11:57:39.031: D/FragmentTest.FragmentOne(3143): onSaveInstanceState
12-04 11:57:39.031: D/FragmentTest.FragmentTestActivity(3143): onCreate
12-04 11:57:39.031: D/FragmentTest.FragmentOne(3143): OnCreateView
12-04 11:57:39.031: D/FragmentTest.FragmentOne(3143): OnCreateView->SavedInstanceState not null
12-04 11:57:39.031: D/FragmentTest.FragmentOne(3143): OnCreateView
12-04 11:57:39.167: D/FragmentTest.FragmentOne(3143): OnCreateView->SavedInstanceState null
Orientation Change 2
12-04 11:58:32.162: D/FragmentTest.FragmentOne(3143): onSaveInstanceState
12-04 11:58:32.162: D/FragmentTest.FragmentOne(3143): onSaveInstanceState
12-04 11:58:32.361: D/FragmentTest.FragmentTestActivity(3143): onCreate
12-04 11:58:32.361: D/FragmentTest.FragmentOne(3143): OnCreateView
12-04 11:58:32.361: D/FragmentTest.FragmentOne(3143): OnCreateView->SavedInstanceState not null
12-04 11:58:32.361: D/FragmentTest.FragmentOne(3143): OnCreateView
12-04 11:58:32.361: D/FragmentTest.FragmentOne(3143): OnCreateView->SavedInstanceState not null
12-04 11:58:32.498: D/FragmentTest.FragmentOne(3143): OnCreateView
12-04 11:58:32.498: D/FragmentTest.FragmentOne(3143): OnCreateView->SavedInstanceState null
</code></pre>
<p>Main Activity (FragmentActivity)</p>
<pre><code>public class FragmentTestActivity extends FragmentActivity {
/** Called when the activity is first created. */
private static final String TAG = "FragmentTest.FragmentTestActivity";
FragmentManager mFragmentManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(TAG, "onCreate");
mFragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
FragmentOne fragment = new FragmentOne();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
</code></pre>
<p>And the fragment</p>
<pre><code>public class FragmentOne extends Fragment {
private static final String TAG = "FragmentTest.FragmentOne";
EditText mEditText;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d(TAG, "OnCreateView");
View v = inflater.inflate(R.layout.fragmentonelayout, container, false);
// Retrieve the text editor, and restore the last saved state if needed.
mEditText = (EditText)v.findViewById(R.id.editText1);
if (savedInstanceState != null) {
Log.d(TAG, "OnCreateView->SavedInstanceState not null");
mEditText.setText(savedInstanceState.getCharSequence("text"));
}
else {
Log.d(TAG,"OnCreateView->SavedInstanceState null");
}
return v;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.d(TAG, "FragmentOne.onSaveInstanceState");
// Remember the current text, to restore if we later restart.
outState.putCharSequence("text", mEditText.getText());
}
</code></pre>
<p>Manifest</p>
<pre><code><uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".activities.FragmentTestActivity"
android:configChanges="orientation">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</code></pre>
| 8,678,705 | 7 | 2 | null |
2011-12-12 12:10:46.467 UTC
| 56 |
2017-03-22 12:32:56.76 UTC
|
2013-09-18 13:41:41.263 UTC
| null | 422,060 | null | 633,280 | null | 1 | 126 |
android|android-activity|android-fragments|orientation
| 103,577 |
<p>You're layering your Fragments one on top of the other.</p>
<p>When a config change occurs the old Fragment adds itself to the new Activity when it's recreated. This is a massive pain in the rear most of the time.</p>
<p>You can stop errors occurring by using the same Fragment rather than recreating a new one. Simply add this code:</p>
<pre><code>if (savedInstanceState == null) {
// only create fragment if activity is started for the first time
mFragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
FragmentOne fragment = new FragmentOne();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
} else {
// do nothing - fragment is recreated automatically
}
</code></pre>
<p>Be warned though: problems will occur if you try and access Activity Views from inside the Fragment as the lifecycles will subtly change. (Getting Views from a parent Activity from a Fragment isn't easy).</p>
|
6,985,222 |
how to clear whole database in Rails seeds.rb
|
<p>What is the best way to accomplish this? As for now I'm using:</p>
<pre><code>Role.delete_all
User.delete_all
...
</code></pre>
<p>but how to clear habtm talbes? Like roles_users</p>
<h2>Updated Answer</h2>
<p>I think ream88 response answers my question most precisely, but probably the bestidea is to follow coreyward suggestion to use separate rake tasks and leave seeds.rb only for seeding data.</p>
<p>This is updated answer from ream88 which doesn't delete <code>schema_migrations</code> table.</p>
<pre><code>ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.tables.each do |table|
# MySQL
ActiveRecord::Base.connection.execute("TRUNCATE #{table}") unless table == "schema_migrations"
# SQLite
# ActiveRecord::Base.connection.execute("DELETE FROM #{table}") unless table == "schema_migrations"
end
</code></pre>
<p>Thanks a lot for help!</p>
| 6,985,839 | 3 | 0 | null |
2011-08-08 16:25:18.5 UTC
| 11 |
2016-09-25 09:13:10.393 UTC
|
2011-08-09 14:10:47.283 UTC
| null | 229,695 | null | 229,695 | null | 1 | 26 |
ruby-on-rails
| 24,345 |
<p>I definitely agree with @coreyward's answer, but if you really want to clear all tables inside your <code>seeds.rb</code> file, this snippet will do the job:</p>
<pre><code>ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.tables.each do |table|
next if table == 'schema_migrations'
# MySQL and PostgreSQL
ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
# SQLite
# ActiveRecord::Base.connection.execute("DELETE FROM #{table}")
end
</code></pre>
|
6,796,974 |
Force Download an Image Using Javascript
|
<p>I want to know if there is any way to make a script using Javascript/jQuery to download (open a download dialog) a image so the browser won't just show it.</p>
| 6,799,284 | 4 | 3 | null |
2011-07-22 22:57:54.807 UTC
| 15 |
2016-12-09 03:31:50.803 UTC
|
2014-12-29 21:27:53.483 UTC
| null | 87,015 | null | 126,353 | null | 1 | 19 |
javascript|jquery|file-io|force-download
| 101,444 |
<p>You need to use server-side scripting for this. <a href="https://stackoverflow.com/search?q=force%20download%20script">Search on stackoverflow</a>.</p>
<p>Alternately, your server might allow you to alter headers dynamically via configuration.</p>
<h3>Apache solution with mod_headers</h3>
<p>Place your downloadable images in a directory. Inside this directory, create a <code>.htaccess</code> file with the following contents:</p>
<pre class="lang-none prettyprint-override"><code>SetEnvIf Request_URI "([^/]+\.jpg)$" REQUESTED_IMAGE_BASENAME=$1
SetEnvIf Request_URI "([^/]+\.png)$" REQUESTED_IMAGE_BASENAME=$1
Header set Content-Disposition "attachment; filename=\"%{REQUESTED_IMAGE_BASENAME}e\"" env=REQUESTED_IMAGE_BASENAME
</code></pre>
<p>Test Request:</p>
<pre class="lang-none prettyprint-override"><code>HEAD /test/Water%20lilies.jpg HTTP/1.1
Host: localhost
</code></pre>
<p>Test Response:</p>
<pre class="lang-none prettyprint-override"><code>HTTP/1.1 200 OK
Date: Sat, 23 Jul 2011 09:03:52 GMT
Server: Apache/2.2.17 (Win32)
Last-Modified: Thu, 23 Aug 2001 14:00:00 GMT
ETag: "26000000017df3-14752-38c32e813d800"
Accept-Ranges: bytes
Content-Length: 83794
Content-Disposition: attachment; filename="Water lilies.jpg"
Content-Type: image/jpeg
</code></pre>
<h3>HTML5 Solution</h3>
<p>You can <a href="http://www.w3.org/TR/html5/links.html#downloading-resources" rel="noreferrer">use the HTML5 <code>download</code> attribute on anchors</a>:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><p>Example 1<br>
<a href="http://dummyimage.com/600x400/000/fff.png" download>Download this image</a></p>
<p>Example 2<br>
<a href="http://dummyimage.com/600x400/000/fff.png" download="alternate-filename.png"><img
src="http://dummyimage.com/150x100/000/fff.png"></a></p></code></pre>
</div>
</div>
</p>
|
23,665,056 |
AngularJS : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource
|
<p>here is my code :</p>
<pre><code>angular.module('option')
.factory('optionListService', ['$resource', function($resource) {
return $resource(HOST+'option/action/:id', {}, {
'get': {method:'GET'},
'save': {method:'POST'},
'query': {method:'GET', isArray:true},
'remove': {method:'DELETE'},
'delete': {method:'DELETE'}
});
}]);
</code></pre>
<p>and this work for GET requests and not for POST !</p>
<p>I'm using Apache as a server and configured it with : </p>
<pre><code><Limit GET HEAD POST PUT DELETE OPTIONS>
Order Allow,Deny
Allow from all
</Limit>
Header set Access-Control-Allow-Origin "*"
</code></pre>
<p>and in my angularjs I include in config of module app:</p>
<pre><code>delete $httpProvider.defaults.headers.common['X-Requested-With'];
delete $httpProvider.defaults.headers.post['Content-type'];
</code></pre>
<p>but the request POST still not working !!</p>
<p>I hope that someone can give any idea.</p>
| 23,665,430 | 4 | 3 | null |
2014-05-14 21:01:59.74 UTC
| 15 |
2017-07-02 08:01:46.733 UTC
| null | null | null | null | 2,822,643 | null | 1 | 17 |
apache|angularjs
| 60,001 |
<p>Add those headers on the server side:</p>
<pre><code>Access-Control-Request-Headers: X-Requested-With, accept, content-type
Access-Control-Allow-Methods: GET, POST
</code></pre>
<p>If still not working post the details of the preflight <code>OPTIONS</code> request which the browser is sending.</p>
<p><strong>Why is this required?</strong></p>
<p>If it is not a simple request (e.g. GET or POST of form data) the browser sends a preflight HTTP <code>OPTIONS</code>request to the server to check if CORS is allowed. This request contains some <code>Access-Control-Request</code> headers (can differ based on the specific request):</p>
<pre><code>Access-Control-Request-Headers: accept, content-type
Access-Control-Request-Method: POST
</code></pre>
<p>Now it is important that the server references the same <code>Access-Control-Allow</code> header in the response: </p>
<pre><code>Access-Control-Allow-Headers: accept, content-type
Access-Control-Allow-Methods: POST
Access-Control-Allow-Origin: *
</code></pre>
<p>Otherwise the request is rejected by the browser.</p>
<p>@ilyas : finaly after 3hours of reseach I sovelved this problem </p>
<pre><code>//Part added by ilyas :
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
//End of part.
</code></pre>
<p>I hope this help others.</p>
|
18,351,198 |
What are the uses of the exec command in shell scripts?
|
<p>Can anyone explain what are the uses of the exec command in shell scripting with simple examples?</p>
| 18,351,547 | 2 | 2 | null |
2013-08-21 07:22:49.933 UTC
| 110 |
2017-03-19 20:40:38.68 UTC
|
2014-11-24 16:51:00.613 UTC
| null | 33,204 | null | 2,400,564 | null | 1 | 284 |
shell|unix|exec
| 339,780 |
<p>The <code>exec</code> built-in command mirrors functions in the kernel, there are a family of them based on <code>execve</code>, which is usually called from C.</p>
<p><code>exec</code> replaces the current program in the current process, without <code>fork</code>ing a new process. It is not something you would use in every script you write, but it comes in handy on occasion. Here are some scenarios I have used it;</p>
<ol>
<li><p>We want the user to run a specific application program without access to the shell. We could change the sign-in program in /etc/passwd, but maybe we want environment setting to be used from start-up files. So, in (say) <code>.profile</code>, the last statement says something like:</p>
<pre><code> exec appln-program
</code></pre>
<p>so now there is no shell to go back to. Even if <code>appln-program</code> crashes, the end-user cannot get to a shell, because it is not there - the <code>exec</code> replaced it.</p></li>
<li><p>We want to use a different shell to the one in /etc/passwd. Stupid as it may seem, some sites do not allow users to alter their sign-in shell. One site I know had everyone start with <code>csh</code>, and everyone just put into their <code>.login</code> (csh start-up file) a call to <code>ksh</code>. While that worked, it left a stray <code>csh</code> process running, and the logout was two stage which could get confusing. So we changed it to <code>exec ksh</code> which just replaced the c-shell program with the korn shell, and made everything simpler (there are other issues with this, such as the fact that the <code>ksh</code> is not a login-shell).</p></li>
<li><p>Just to save processes. If we call <code>prog1 -> prog2 -> prog3 -> prog4</code> etc. and never go back, then make each call an exec. It saves resources (not much, admittedly, unless repeated) and makes shutdown simplier.</p></li>
</ol>
<p>You have obviously seen <code>exec</code> used somewhere, perhaps if you showed the code that's bugging you we could justify its use.</p>
<p><strong>Edit</strong>: I realised that my answer above is incomplete. There are <strong>two</strong> uses of <code>exec</code> in shells like <code>ksh</code> and <code>bash</code> - used for opening file descriptors. Here are some examples:</p>
<pre><code>exec 3< thisfile # open "thisfile" for reading on file descriptor 3
exec 4> thatfile # open "thatfile" for writing on file descriptor 4
exec 8<> tother # open "tother" for reading and writing on fd 8
exec 6>> other # open "other" for appending on file descriptor 6
exec 5<&0 # copy read file descriptor 0 onto file descriptor 5
exec 7>&4 # copy write file descriptor 4 onto 7
exec 3<&- # close the read file descriptor 3
exec 6>&- # close the write file descriptor 6
</code></pre>
<p>Note that spacing is very important here. If you place a space between the fd number and the redirection symbol then <code>exec</code> reverts to the original meaning:</p>
<pre><code> exec 3 < thisfile # oops, overwrite the current program with command "3"
</code></pre>
<p>There are several ways you can use these, on ksh use <code>read -u</code> or <code>print -u</code>, on <code>bash</code>, for example:</p>
<pre><code>read <&3
echo stuff >&4
</code></pre>
|
40,122,162 |
Entity Framework Core - Lazy Loading
|
<p>Bowing to my Visual Studios request, I started my latest project using Entity Framework Core (1.0.1)</p>
<p>So writing my database models as I always have using the 'virtual' specifier to enable lazy loading for a List. Though when loading the parent table it appears that the child list never loads.</p>
<p><strong>Parent Model</strong></p>
<pre><code>public class Events
{
[Key]
public int EventID { get; set; }
public string EventName { get; set; }
public virtual List<EventInclusions> EventInclusions { get; set; }
}
</code></pre>
<p><strong>Child Model</strong></p>
<pre><code>public class EventInclusions
{
[Key]
public int EventIncSubID { get; set; }
public string InclusionName { get; set; }
public string InclusionDesc { get; set; }
public Boolean InclusionActive { get; set; }
}
</code></pre>
<p>Adding new records to these tables seems to work as I am used to where I can nest the EventInclusions records as a List inside the Events record.</p>
<p>Though when I query this table</p>
<pre><code>_context.Events.Where(e => e.EventName == "Test")
</code></pre>
<p><strong>The Issue</strong></p>
<p>EventInclusions will return a null value regardless of the data behind the scenes.</p>
<p>After reading a bit I am getting the feeling this is a change between EF6 which I normally use and EF Core </p>
<p>I could use some help in either making a blanket Lazy Loading on statement or figuring out the new format for specifying Lazy Loading.</p>
<p>Caz</p>
| 40,143,716 | 7 | 6 | null |
2016-10-19 04:30:34.167 UTC
| 9 |
2019-09-10 22:05:55.15 UTC
|
2016-12-27 08:52:36.607 UTC
| null | 1,478,537 | null | 5,073,958 | null | 1 | 49 |
c#|entity-framework-core
| 68,113 |
<p>So it appears that EF Core does not currently support lazy loading. Its coming but may be a while off. </p>
<p>For now if anyone else comes across this problem and is struggling. Below is a demo of using <strong>Eager loading</strong> which is what for now you have to use.</p>
<p>Say before you had a person object and that object contained a List of Hats in another table.</p>
<p><strong>Rather than writing</strong> </p>
<pre><code>var person = _context.Person.Where(p=> p.id == id).ToList();
person.Hats.Where(h=> h.id == hat).ToList();
</code></pre>
<p><strong>You need to write</strong> </p>
<pre><code>var person = _context.Person.Include(p=> p.Hats).Where(p=> p.id == id).ToList();
</code></pre>
<p>And then <code>person.Hats.Where(h=> h.id == hat).ToList();</code> will work</p>
<p><strong>If you have multiple Lists - Chain the Includes</strong></p>
<pre><code>var person = _context.Person.Include(p=> p.Hats).Include(p=> p.Tickets)
.Include(p=> p.Smiles).Where(p=> p.id == id).ToList();
</code></pre>
<p>I kinda get why this method is safer, that your not loading huge data sets that could slow things down. But I hope they get Lazy loading back soon!!!</p>
<p>Caz </p>
|
5,282,242 |
Spring AOP: Getting parameters of the pointcut annotation
|
<p>Consider I have defined the following aspect:</p>
<pre><code>@Aspect
public class SampleAspect {
@Around(value="@annotation(sample.SampleAnnotation)")
public Object display(ProceedingJoinPoint joinPoint) throws Throwable {
// ...
}
}
</code></pre>
<p>and the annotation</p>
<pre><code>public @interface SampleAnnotation {
String value() default "defaultValue";
}
</code></pre>
<p>Is there a way to read the value parameter of the annotation SampleAnnotation in the display method if my aspect?</p>
<p>Thanks for your help,
erik</p>
| 5,296,145 | 2 | 1 | null |
2011-03-12 11:36:16.9 UTC
| 12 |
2019-08-13 17:39:30.36 UTC
| null | null | null | null | 164,165 | null | 1 | 28 |
spring|aop|spring-aop
| 27,095 |
<p>Change the advice signature to </p>
<pre><code>@Around(value="@annotation(sampleAnnotation)")
public Object display(ProceedingJoinPoint joinPoint, SampleAnnotation sampleAnnotation ) throws Throwable {
// ...
}
</code></pre>
<p>and you will have access to the value in the annotation.</p>
<p>See <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-ataspectj-advice-params-passing" rel="noreferrer">docs</a> for more info.</p>
|
975,982 |
User Defined Type (UDT) as parameter in public Sub in class module (VB6)
|
<p>I've tried to solve this problem, but can't find any solution. I have a UDT defined in a normal module, and wanted to use it as parameter in a <code>Public Sub</code> in a Class Module. I then get a compile error:</p>
<blockquote>
<p>Only public user defined types defined in public object modules can be used as parameters or return type for public procedures of class modules or as fields of public user defined types</p>
</blockquote>
<p>I then try to move my UDT in the class, declared as <code>Private</code>. I get this compile error:</p>
<blockquote>
<p>Private Enum and user defined types cannot be used as parameters or return types for public procedures, public data members, or fields of public user defined types.</p>
</blockquote>
<p>I finaly try to declare it as <code>Public</code> in the class, and get this compile error:</p>
<blockquote>
<p>Cannot define a Public user-defined type within a private object module.</p>
</blockquote>
<p>So is there any way to have a public UDT used as a parameter in a public sub in a class?</p>
| 978,983 | 7 | 0 | null |
2009-06-10 14:37:11.547 UTC
| 12 |
2018-01-03 18:24:55.887 UTC
|
2017-02-24 17:27:20.493 UTC
| null | 481,061 | null | 74,415 | null | 1 | 17 |
vba|vb6|user-defined-types
| 47,785 |
<blockquote>
<p>So is there any way to have a public
UDT used as a parameter in a public
sub in a class?</p>
</blockquote>
<p>In a word, no. The closest you can come with just Classic VB code would be to create a class that replicates the UDT and use that instead. There are definitely advantages there, but you're hosed if you need to pass that to, say, an API as well.</p>
<p>Another option is to define the UDT in a typelib. If you do that, it can be used as a parameter for a public method.</p>
|
1,254,366 |
Problem installing RMagick rubygem on Centos 5
|
<p>I'm having problems installing the RMagick rubygem on Centos 5. I've followed the steps detailed in <a href="http://rmagick.rubyforge.org/install2-linux.html" rel="noreferrer">http://rmagick.rubyforge.org/install2-linux.html</a> but when I try:</p>
<pre><code>sudo gem install rmagick
</code></pre>
<p>the result is:</p>
<pre><code>Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.11.0. Can't find Magick-config in /usr/bin:/bin
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/ruby
Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/rmagick-2.11.0 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.8/gems/rmagick-2.11.0/ext/RMagick/gem_make.out
</code></pre>
<p>The directory /usr/local/bin contains Magick-config but I haven't been able to get rubygems to look there. I tried the following but the result was the same:</p>
<pre><code>sudo gem install rmagick -- --with-opt-dir=/usr/local/bin
</code></pre>
<p>Any suggestions would be appreciated.</p>
| 1,257,925 | 7 | 0 | null |
2009-08-10 11:22:33.643 UTC
| 9 |
2013-02-01 06:33:39.667 UTC
| null | null | null | null | 2,167,959 | null | 1 | 17 |
rubygems|rmagick|centos5
| 23,669 |
<p>So I've finally managed to install version 1.15.17 of the rmagick rubygem! Here's what I did:</p>
<ol>
<li>Uninstalled ImageMagick 6.5.4-9 and the delegate libraries that I had installed from source</li>
<li><code>sudo yum install ImageMagick</code></li>
<li><code>sudo yum install ImageMagick-devel</code></li>
<li><code>curl -O http://www.zacharywhitley.com/linux/rpms/fedora/core/6/i386/msttcorefonts-2.0-1.noarch.rpm</code></li>
<li><code>sudo rpm -ivh msttcorefonts-2.0-1.noarch.rpm</code></li>
<li><code>ln -s /usr/share/fonts/msttcorefonts/ /usr/share/fonts/default/TrueType</code></li>
<li><code>sudo gem install rmagick -v 1.15.17 --no-rdoc --no-ri</code></li>
</ol>
<p>Blog entries from <a href="http://www.nofluffjuststuff.com/blog/david_bock/2008/04/installing_centos_5_imagemagick_and_rmagick.html" rel="noreferrer">David Bock</a> and <a href="http://willj.net/2007/04/23/getting-rmagick-working-on-fedora-core-6/" rel="noreferrer">Will</a> were invaluable.</p>
|
274,639 |
How To Create a Quick Minimal Firefox Extension?
|
<p>What the minimum basic setup required to begin developing a Firefox extension?</p>
| 384,933 | 7 | 3 | null |
2008-11-08 11:35:40.6 UTC
| 19 |
2014-07-23 01:03:21.803 UTC
|
2011-07-02 18:57:50.91 UTC
|
Balaji Sowmyanarayanan
| 188,760 |
labs
| 35,738 | null | 1 | 19 |
firefox|xul
| 4,609 |
<p>Step 1: Use the <a href="https://addons.mozilla.org/en-US/developers/tools/builder" rel="nofollow noreferrer">Add-on Builder</a> to generate all the necessary files.</p>
<p>Step 2: Extract the downloaded files into your development area.</p>
<p>Step 3: Create a text file in your profile's extensions folder named according to the em:id in the downloaded install.rdf file, put the full path to your extracted files in it then restart Firefox (delete the text file to uninstall if necesary).</p>
|
901,224 |
Listening for input without focus in Java
|
<p>I'm making a small program in Java using the Robot class. The program takes over the mouse. while in the course of debugging if it starts acting in a way that I don't want it's hard to quit the program, since I can't move the mouse over to the terminate button in eclipse, and I can't use hotkeys to hit it because the mouse is constant clicking in another window, giving that window focus instead. </p>
<p>What I'd like to do is just hook up a keylistener so that when I hit q I can quit the program, but the only way I know how to do this involves making a window, and that window needs focus to capture the input. Is there a way to listen for keyboard or mouse input from anywhere, regardless of what has focus?</p>
| 904,448 | 7 | 0 | null |
2009-05-23 09:44:37.187 UTC
| 9 |
2021-01-10 16:59:23.013 UTC
| null | null | null | null | 63,791 | null | 1 | 25 |
java|keylistener
| 40,267 |
<p>This is not a trivial problem and Java doesn't give you a way to do it elegantly. You can use a solution like banjollity suggested but even that won't work all the time if your errant mouse clicks open another fullsized window currently open in your taskbar for example. </p>
<p>The fact is, Java by default gives developers very little control over the OS. This is due to 2 main reasons: security (as citied by java documentation) and the fact that different operating systems handle events completely differently and making one unified model to represent all of these would probably not make a whole lot of sense. </p>
<p>So to answer your question, I imagine what you want is some kind of behaviour for your program where it listens for keypresses globally, not just in your application. Something like this will require that you access the functionality offered by your OS of choice, and to access it in Java you are going to need to do it through a Java Native Interface (JNI) layer. </p>
<p>So what you want to do is:</p>
<ol>
<li><p>Implement a program in C that will listen for global keypresses on your OS, if this OS is Windows than look for documentation on windows hooks which is well docuemented by Microsoft and MSDN on the web and other places. If your OS is Linux or Mac OS X then you will need to listen for global keypresses using the X11 development libraries. This can be done on an ubunutu linux distro according to a Howto that I wrote at <a href="http://ubuntuforums.org/showthread.php?t=864566" rel="noreferrer">http://ubuntuforums.org/showthread.php?t=864566</a></p></li>
<li><p>Hook up your C code to your Java code through JNI. This step is actually the easier step. Follow the procedure that I use in my tutorial at <a href="http://ubuntuforums.org/showthread.php?t=864566" rel="noreferrer">http://ubuntuforums.org/showthread.php?t=864566</a> under both windows and linux as the procedure for hooking up your C code to your Java code will be identical on both OSes. </p></li>
</ol>
<p>The important thing to remember is that its much easier to get your JNI code working if you first code and debug your C/C++ code and make sure that it is working. Then integrating it with Java is easy.</p>
|
385,912 |
Ruby: Object.to_a replacement
|
<p>I need to convert a passed in argument (single object or collection) to an Array. I don't know what the argument is. If it is an Array already, I want to leave it, otherwise create a one-element array from it. I'm looking to <strong>allow both <code>method(:objs => obj)</code> and <code>method(:objs => [obj1, obj2])</code></strong></p>
<p>This seems to be the best way (Array#to_a returns self):</p>
<pre><code>arg = arg.to_a
</code></pre>
<p>But the ruby docs say <strong><code>Object#to_a</code> will soon be obsolete</strong>. Is there convenient replacement?</p>
<p>Anything more succinct than this?</p>
<pre><code>arg = arg.respond_to?(:to_a) ? arg.to_a : [arg]
</code></pre>
| 386,705 | 7 | 0 | null |
2008-12-22 10:06:09.13 UTC
| 8 |
2011-07-22 18:12:53.523 UTC
|
2011-07-22 18:01:50.697 UTC
|
Daniel Beardsley
| 211,563 |
Daniel Beardsley
| 13,216 | null | 1 | 28 |
ruby
| 21,946 |
<p>Use the method <a href="http://www.ruby-doc.org/core/classes/Kernel.html#M005989" rel="noreferrer">Kernel#Array</a>:</p>
<pre><code>Array([1,2,3]) #=> [1, 2, 3]
Array(123) #=> [123]
</code></pre>
<p>Yes it may look like a class at first but this is actually a method that starts with a capital letter.</p>
|
539,797 |
How should I do integer division in Perl?
|
<p>What is a good way to <strong>always</strong> do integer division in Perl?</p>
<p>For example, I want:</p>
<pre><code>real / int = int
int / real = int
int / int = int
</code></pre>
| 539,805 | 7 | 0 | null |
2009-02-12 02:44:20.783 UTC
| 9 |
2022-02-17 00:24:08.993 UTC
|
2009-02-12 02:54:50.603 UTC
|
Rich B
| 5,640 |
Bryan Denny
| 396 | null | 1 | 63 |
perl|integer-division
| 120,169 |
<p>You can cast ints in Perl:</p>
<pre><code>int(5/1.5) = 3;
</code></pre>
|
125,341 |
How do you do Impersonation in .NET?
|
<p>Is there a simple out of the box way to impersonate a user in .NET?</p>
<p>So far I've been using <a href="http://www.codeproject.com/KB/cs/zetaimpersonator.aspx" rel="noreferrer">this class from code project</a> for all my impersonation requirements.</p>
<p>Is there a better way to do it by using .NET Framework?</p>
<p>I have a user credential set, (username, password, domain name) which represents the identity I need to impersonate.</p>
| 125,356 | 7 | 1 | null |
2008-09-24 03:55:09.147 UTC
| 109 |
2022-08-09 14:32:39.88 UTC
|
2012-10-11 14:47:56.437 UTC
|
b.ashwin
| 743 |
b.ashwin
| 1,909 | null | 1 | 149 |
c#|.net|impersonation
| 290,376 |
<p>Here is some good overview of .NET impersonation concepts.</p>
<ul>
<li><a href="https://web.archive.org/web/20150613031724/http://michiel.vanotegem.nl/2006/07/windowsimpersonationcontext-made-easy/" rel="noreferrer">Michiel van Otegem: WindowsImpersonationContext made easy</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/chf6fbt4.aspx" rel="noreferrer">WindowsIdentity.Impersonate Method (check out the code samples)</a></li>
</ul>
<p>Basically you will be leveraging these classes that are out of the box in the .NET framework:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/system.security.principal.windowsimpersonationcontext.aspx" rel="noreferrer">WindowsImpersonationContext</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.aspx" rel="noreferrer">WindowsIdentity</a></li>
</ul>
<p>The code can often get lengthy though and that is why you see many examples like the one you reference that try to simplify the process.</p>
|
568,657 |
Is it ever ok to store password in plain text in a php variable or php constant?
|
<p>As per question, is it safe to store passwords on php pages such as</p>
<pre><code>$password = 'pa$$w0rd';
</code></pre>
<p>If the users can't see it, it's safe, right?</p>
<p>EDIT:
Some people actually suggested using hash, however, there would be a problem with database server connection password, wouldn't it?</p>
| 568,681 | 8 | 0 | null |
2009-02-20 08:02:28.663 UTC
| 8 |
2010-12-01 14:47:56.677 UTC
|
2009-05-07 09:12:52.493 UTC
|
Hao Wooi Lim
| 31,728 |
Hao Wooi Lim
| 31,728 | null | 1 | 31 |
php|security|passwords
| 31,078 |
<p>The short answer is both No, and It Depends.</p>
<p>It's almost never a good idea to store passwords in plain text, especially in a web accessible location, if for <strong>no</strong> other reason than a simple server misconfiguration or an echo in the wrong place could expose it to the world.</p>
<p>If you MUST store a password, (which is possible) you could try to store it outside the webroot, eg
<code>/var/www/public_html/</code> Put your codez here<br>
<code>/var/www/includes/</code> Put your passwords here</p>
<p>Even better than that would be to have the system that you need the password for (eg a database wrapper ) return an object already instantiated. so rather than asking for <code>$databasepassword</code> you ask for a PDO object, and store your database classes outside the webroot.</p>
<p>The It Depends comes from what attack vectors would cause someone to have access to that password text, and would it require them to be already inside your filesystem, if so, you're probably screwed anyway.</p>
<p>Also, if its the password to your supa-secrit subscriber content, meh, all you've lost is some subscription fees, if its your database, you may have a problem, if it's your online banking details, um good for you. </p>
<p>How valuable is the thing the password is protecting? </p>
|
516,730 |
What does the Visual Studio "Any CPU" target mean?
|
<p>I have some confusion related to the .NET platform build options in Visual Studio 2008.</p>
<p>What is the "Any CPU" compilation target, and what sort of files does it generate? I examined the output executable of this "Any CPU" build and found that they are the x86 executables (who would not see that coming!). So, is there any difference between targeting executable to x86 vs. "Any CPU"?</p>
<p>Another thing that I noticed, is that managed C++ projects do not have this platform as an option. Why is that? Does that mean that my suspicion about "Any CPU" executables being plain 32-bit ones is right?</p>
| 516,740 | 8 | 3 | null |
2009-02-05 16:43:26.713 UTC
| 147 |
2021-05-26 08:29:44.807 UTC
|
2019-11-11 15:16:56.697 UTC
|
JPunyon
| 63,550 |
galets
| 14,395 | null | 1 | 557 |
.net|visual-studio-2008|build|64-bit
| 254,840 |
<p>An <strong>AnyCPU</strong> assembly will JIT to 64-bit code when loaded into a 64-bit process and 32 bit when loaded into a 32-bit process.</p>
<p>By limiting the CPU you would be saying: <em>There is something being used by the assembly (something likely
unmanaged) that requires 32 bits or 64 bits.</em></p>
|
1,236,148 |
HTML CSS How to stop a table cell from expanding
|
<p>I have a table which is built with the contents coming from a returned dataset. What I want to do is stop a 'description' cell from expanding over 280px wide, no matter what the content length (its s string). I have tried:</p>
<pre><code><td align="left" valign="top" style="overflow:hidden;" nowrap="nowrap" width="280px" >
</code></pre>
<p>But this doesn't seem to work. I don't want it to wrap, nor do I want anything over 280px to be displayed.</p>
| 1,236,163 | 8 | 0 | null |
2009-08-05 22:43:23.073 UTC
| 13 |
2021-03-18 08:36:30.47 UTC
|
2017-01-10 19:51:20.807 UTC
| null | 322,020 | null | 109,614 | null | 1 | 47 |
html|css
| 135,742 |
<p>It appears that your HTML syntax is incorrect for the table cell. Before you try the other idea below, confirm if this works or not... You can also try adding this to your table itself: table-layout:fixed.. .</p>
<pre><code><td style="overflow: hidden; width: 280px; text-align: left; valign: top; whitespace: nowrap;">
[content]
</td>
</code></pre>
<p><strong>New HTML</strong> </p>
<pre><code><td>
<div class="MyClass"">
[content]
</div>
</td>
</code></pre>
<p><strong>CSS Class:</strong></p>
<pre><code>.MyClass{
height: 280px;
width: 456px;
overflow: hidden;
white-space: nowrap;
}
</code></pre>
|
311,062 |
caching JavaScript files
|
<p>Which is the best method to make the browser use cached versions of js files (from the serverside)?</p>
| 312,696 | 8 | 0 | null |
2008-11-22 08:05:37.563 UTC
| 27 |
2021-09-30 08:08:31.66 UTC
|
2008-11-22 08:19:16.1 UTC
|
Ken
| 20,074 |
Vasil
| 7,883 | null | 1 | 55 |
javascript|http|caching
| 158,048 |
<p>Have a look at Yahoo! tips: <a href="https://developer.yahoo.com/performance/rules.html#expires" rel="nofollow noreferrer">https://developer.yahoo.com/performance/rules.html#expires</a>. </p>
<p>There are also tips by Google: <a href="https://developers.google.com/speed/docs/insights/LeverageBrowserCaching" rel="nofollow noreferrer">https://developers.google.com/speed/docs/insights/LeverageBrowserCaching</a></p>
|
437,897 |
What are unit testing and integration testing, and what other types of testing should I know about?
|
<p>I've seen other people mention several types of testing on Stack Overflow.</p>
<p>The ones I can recall are unit testing and integration testing. Especially unit testing is mentioned a lot. What exactly is unit testing? What is integration testing? What other important testing techniques should I be aware of? </p>
<p>Programming is not my profession, but I would like it to be some day;stuff about production etc is welcomed too.</p>
| 437,903 | 9 | 3 | null |
2009-01-13 03:43:31.087 UTC
| 27 |
2020-07-09 08:15:48.067 UTC
|
2009-01-13 06:10:29.447 UTC
|
Norman Ramsey
| 41,661 |
Daniel
| 51,133 | null | 1 | 44 |
unit-testing|testing|integration-testing
| 30,546 |
<p>Off the top of my head:</p>
<ul>
<li><strong>Unit testing</strong> in the sense of "testing the smallest isolatable unit of an application"; this is typically a method or a class, depending on scale.</li>
<li><strong>Integration testing</strong></li>
<li><strong>Feature testing</strong>: this may cut across units, and is the focus of TDD.</li>
<li><strong>Black-box testing</strong>: testing only the public interface with no knowledge of how the thing works.</li>
<li><strong>Glass-box testing</strong>: testing all parts of a thing with full knowledge of how it works.</li>
<li><strong>Regression testing</strong>: test-cases constructed to reproduce bugs, to ensure that they do not reappear later.</li>
<li><strong>Pointless testing</strong>: testing the same basic case more than one way, or testing things so trivial that they really do not need to be tested (like auto-generated getters and setters)</li>
</ul>
|
481,312 |
Why is design-by-contract not so popular compared to test-driven development?
|
<p>You may think this question is like <a href="https://stackoverflow.com/questions/394591/design-by-contract-and-test-driven-development">this</a> question asked on StackOverflow earlier. But I am trying to look at things differently.</p>
<p>In TDD, we write tests that include different conditions, criteria, verification code. If a class passes all these tests we are good to go. It is a way of making sure that the class actually does what it's supposed to do and nothing else.</p>
<p>If you follow <em>Bertrand Meyers</em>' book <em>Object Oriented Software Construction</em> word by word, the class itself has internal and external contracts, so that it only does what its supposed to do and nothing else. No external tests required because the to code to ensure contract is followed is the part of the class.</p>
<p>Quick example to make things clear</p>
<blockquote>
<p><strong>TDD</strong></p>
<ol>
<li><p>Create test to ensure that in all cases a value ranges from (0-100)</p></li>
<li><p>Create a class containing a method that passes the test.</p></li>
</ol>
<p><strong>DBC</strong></p>
<ol>
<li>Create a class, create a contract for that member <code>var</code> to range from (0-100), set contract for contract breach, define a method.</li>
</ol>
</blockquote>
<p>I personally like the DBC approach.</p>
<hr>
<p>Is there a reason why pure DBC is not so popular? Is it the languages or tools or being Agile or is it just me who likes to have code responsible for itself?</p>
<p>If you think I am not thinking right, I would be more than willing to learn.</p>
| 481,392 | 9 | 4 | null |
2009-01-26 20:57:44.09 UTC
| 18 |
2018-04-03 12:20:55.737 UTC
|
2017-07-29 15:19:59.727 UTC
| null | 3,924,118 |
Perpetualcoder
| 37,494 | null | 1 | 46 |
unit-testing|tdd|design-by-contract
| 13,337 |
<p>The main problem with DBC is that in the vast majority of cases, either the contract cannot be formally specified (at least not conveniently), or it cannot be checked with current static analysis tool. Until we get past this point for mainstream languages (not Eiffel), DBC will not give the kind of assurance that people need. </p>
<p>In TDD, tests are written by a human being based on the current natural-text specifications of the method that are (hopefully) well-documented. Thus, a human interprets correctness by writing the test and gets some assurance based on that interpretation.</p>
<p>If you read Sun's guide for writing JavaDocs, it says that the documentation should essentially lay out a contract sufficient to write a test plan. Hence, design by contract is not necessarily mutually exclusive with TDD. </p>
|
244,453 |
Best documentation for Boost:asio?
|
<p>The documentation available on the <a href="http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio.html" rel="noreferrer">boost website</a> is... limited.</p>
<p>From what I've been able to read, the general consensus is that it is simply difficult to find good documentation on the boost::asio library.</p>
<p>Is this really the case? If so, why?</p>
<p>Notes:</p>
<ul>
<li>I have already found the (non-boost) <a href="http://tenermerx.com/Asio/WebHome" rel="noreferrer">Asio website</a> - and the documentation looks to be identical to that on the boost website.</li>
<li>I know that Boost::asio is new! I'm looking for solutions not excuses.</li>
</ul>
<p>Edit:</p>
<ul>
<li>There is a <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2054.pdf" rel="noreferrer">proposal to add a networking library to standard library for TR2</a> written by the author of Boost:asio (Christopher Kohlhoff). While it isn't documentation for boost:asio, it does use it as a base for the TR2 proposal. Since the author put more effort into this document, I have found it to be somewhat helpful, if not as a reference, then at least as an overview. </li>
</ul>
| 244,583 | 9 | 0 | null |
2008-10-28 19:11:03.9 UTC
| 93 |
2019-04-15 18:58:51.027 UTC
|
2008-11-02 23:54:57.473 UTC
|
Head Geek
| 12,193 |
michalmocny
| 29,701 | null | 1 | 147 |
c++|boost|boost-asio
| 60,948 |
<p>First, I've been using Boost.Asio for quite a while already -- and I share your concern. To address your question:</p>
<ul>
<li>There really is very scarce documentation about Boost.Asio aside from the introduction and tutorial. I am not the author, but this is mostly because there are just too many things to document for something as low-level as an Asynchronous IO Library.</li>
<li>The examples give more away than the tutorials do. If you don't mind spending a little time looking at the different examples, I would think they should suffice to get you started. If you want to run away with it, then the reference documentation should help you a lot.</li>
<li>Ask around in the Boost Users and Boost Developers mailing list if you're really stuck or looking for specific guidance. I'm pretty sure a lot of people will be willing to address your concerns on the mailing lists.</li>
</ul>
<p>There are efforts (not part of Boost.Asio) to expose a lot of the functionality and possible alternative use cases. This at best is scattered around the web in blogs and other forms of non-packaged documentation.</p>
<p>One thing that is unclear and which will really need close coordination with the author and developers of the Boost.Asio library would be as far as extending and customizing it for a specific platform or adding specific new functionality. This should be improved though but the good thing is it's looking like Asio will be a reference implementation for a standard library technical report (for an asynchronous IO library in the STL) in the future.</p>
|
88,582 |
Structure of a PDF file?
|
<p>For a small project I have to parse pdf files and take a specific part of them (a simple chain of characters). I'd like to use python to do this and I've found several libraries that are capable of doing what I want in some ways.</p>
<p>But now after a few researches, I'm wondering what is the real structure of a pdf file, does anyone know if there is a spec or some explanations anywhere online? I've found a link on adobe but it seems that it's a dead link :(</p>
| 88,595 | 12 | 0 | null |
2008-09-17 23:11:33.757 UTC
| 45 |
2020-05-04 19:39:18.15 UTC
| null | null | null |
Valentin Jacquemin
| 11,544 | null | 1 | 81 |
pdf
| 114,887 |
<p>Here is a link to Adobe's reference material</p>
<p><a href="http://www.adobe.com/devnet/pdf/pdf_reference.html" rel="noreferrer">http://www.adobe.com/devnet/pdf/pdf_reference.html</a></p>
<p>You should know though that PDF is only about presentation, not structure. Parsing will not come easy.</p>
|
751,522 |
How to change identity column values programmatically?
|
<p>I have a MS SQL 2005 database with a table <code>Test</code> with column <code>ID</code>. <code>ID</code> is an identity column. </p>
<p>I have rows in this table and all of them have their corresponding ID auto incremented value.</p>
<p>Now I would like to change every ID in this table like this:</p>
<p><code>ID = ID + 1</code></p>
<p>But when I do this I get an error:</p>
<blockquote>
<p>Cannot update identity column 'ID'.</p>
</blockquote>
<p>I've tried this:</p>
<pre><code> ALTER TABLE Test NOCHECK CONSTRAINT ALL
set identity_insert ID ON
</code></pre>
<p>But this does not solve the problem.</p>
<p>I need to have identity set to this column, but I need to change values as well from time to time. So my question is how to accomplish this task.</p>
| 1,188,102 | 13 | 0 | null |
2009-04-15 12:43:47.93 UTC
| 27 |
2019-03-05 07:40:58.25 UTC
|
2019-03-05 07:40:58.25 UTC
| null | 10,877,860 | null | 38,940 | null | 1 | 160 |
sql-server|sql-server-2005|tsql|identity|sql-server-2005-express
| 324,187 |
<p>You need to </p>
<pre><code>set identity_insert YourTable ON
</code></pre>
<p>Then delete your row and reinsert it with different identity.</p>
<p>Once you have done the insert don't forget to turn identity_insert off</p>
<pre><code>set identity_insert YourTable OFF
</code></pre>
|
1,183,903 |
Regex using javascript to return just numbers
|
<p>If I have a string like "something12" or "something102", how would I use a regex in javascript to return just the number parts?</p>
| 1,183,906 | 13 | 0 | null |
2009-07-26 06:34:32.043 UTC
| 28 |
2021-01-12 08:56:17.23 UTC
|
2018-02-08 21:07:29.913 UTC
| null | 431,053 | null | 40,568 | null | 1 | 173 |
javascript|regex
| 295,192 |
<p>Regular expressions:</p>
<pre class="lang-js prettyprint-override"><code>var numberPattern = /\d+/g;
'something102asdfkj1948948'.match( numberPattern )
</code></pre>
<p>This would return an Array with two elements inside, '102' and '1948948'. Operate as you wish. If it doesn't match any it will return null.</p>
<p>To concatenate them:</p>
<pre class="lang-js prettyprint-override"><code>'something102asdfkj1948948'.match( numberPattern ).join('')
</code></pre>
<p>Assuming you're not dealing with complex decimals, this should suffice I suppose.</p>
|
331,536 |
Windows threading: _beginthread vs _beginthreadex vs CreateThread C++
|
<p>What's a better way to start a thread, <code>_beginthread</code>, <code>_beginthreadx</code> or <code>CreateThread</code>?</p>
<p>I'm trying to determine what are the advantages/disadvantages of <code>_beginthread</code>, <code>_beginthreadex</code> and <code>CreateThread</code>. All of these functions return a thread handle to a newly created thread, I already know that CreateThread provides a little extra information when an error occurs (it can be checked by calling <code>GetLastError</code>)... but what are some things I should consider when I'm using these functions?</p>
<p>I'm working with a windows application, so cross-platform compatibility is already out of the question.</p>
<p>I have gone through the msdn documentation and I just can't understand, for example, why anybody would decide to use _beginthread instead of CreateThread or vice versa.</p>
<p>Cheers!</p>
<p>Update:
OK, thanks for all the info, I've also read in a couple of places that I can't call <code>WaitForSingleObject()</code> if I used <code>_beginthread()</code>, but if I call <code>_endthread()</code> in the thread shouldn't that work? What's the deal there?</p>
| 331,567 | 17 | 1 | null |
2008-12-01 17:20:57.13 UTC
| 62 |
2020-08-08 09:50:47.23 UTC
|
2017-05-09 03:02:14.623 UTC
|
Kiril Gantchev
| 7,659,995 |
Kiril Gantchev
| 28,760 | null | 1 | 139 |
c++|c|multithreading|winapi
| 101,164 |
<p><code>CreateThread()</code> is a raw Win32 API call for creating another thread of control at the kernel level.</p>
<p><code>_beginthread()</code> & <code>_beginthreadex()</code> are C runtime library calls that call <code>CreateThread()</code> behind the scenes. Once <code>CreateThread()</code> has returned, <code>_beginthread/ex()</code> takes care of additional bookkeeping to make the C runtime library usable & consistent in the new thread.</p>
<p>In C++ you should almost certainly use <code>_beginthreadex()</code> unless you won't be linking to the C runtime library at all (aka MSVCRT*.dll/.lib).</p>
|
6,361,312 |
Negative regex for Perl string pattern match
|
<p>I have this regex:</p>
<pre><code>if($string =~ m/^(Clinton|[^Bush]|Reagan)/i)
{print "$string\n"};
</code></pre>
<p>I want to match with Clinton and Reagan, but not Bush.</p>
<p>It's not working.</p>
| 6,363,029 | 5 | 3 | null |
2011-06-15 16:50:13.123 UTC
| 27 |
2017-08-12 14:09:18.597 UTC
|
2017-08-12 14:09:18.597 UTC
| null | 63,550 | null | 120,457 | null | 1 | 51 |
regex|perl
| 161,005 |
<p>Sample text:</p>
<blockquote>
<p>Clinton said<br>
Bush used crayons<bR>
Reagan forgot<br></p>
</blockquote>
<p>Just omitting a Bush match:</p>
<pre><code>$ perl -ne 'print if /^(Clinton|Reagan)/' textfile
Clinton said
Reagan forgot
</code></pre>
<p>Or if you really want to specify:</p>
<pre><code>$ perl -ne 'print if /^(?!Bush)(Clinton|Reagan)/' textfile
Clinton said
Reagan forgot
</code></pre>
|
6,818,978 |
Dialect not getting set in hibernate
|
<p>I am using Hibernate 3 and MySQL5.5.</p>
<p>I am a newbie to hibernate and I am getting the below Exception</p>
<pre><code>Exception in thread "main" org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:106)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:152)
</code></pre>
<p>I have set the Dialect property in hibernate.cfg.xml file. I tried a lot of combinations </p>
<pre><code><property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="DIALECT">org.hibernate.dialect.MySQL5Dialect</property>
</code></pre>
<p>What is the actual property name ? Hibernate.dialect or only dialect ?
What can be possible property values ?</p>
<p>I am adding some more information, I used </p>
<pre><code><property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</code></pre>
<p>as suggested by below answers.</p>
<p>I am not even building any code just trying to create simple configuration:</p>
<pre><code>Configuration cfg = new Configuration().addClass(Employee.class);
sessionFactory = cfg.buildSessionFactory();
</code></pre>
<p>Below is the actual Configuration file</p>
<pre><code><?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root1234</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<!-- Mapping files will go here.... -->
</session-factory>
</hibernate-configuration>
</code></pre>
<p>I suspect the hibernate.cfg.xml is not being found ? I have placed it in the same package where the source code for Employee.class is there. Infact moving around this file causes the same error, so it is not actually found :-( Where to keep it ? This is a standalone Test program :-(</p>
| 6,819,137 | 6 | 3 | null |
2011-07-25 16:01:06.42 UTC
| 1 |
2015-12-09 00:19:55.74 UTC
|
2011-07-25 16:53:55.74 UTC
| null | 102,040 | null | 102,040 | null | 1 | 7 |
hibernate|dialect
| 57,008 |
<p>Either your first or second line should work. The second way, with just "dialect" is the way shown in the <a href="http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-xmlconfig">Hibernate reference</a>. If you're still getting that error, it suggests you may have something else going on. How are you building the SessionFactory? Are you sure it's finding your hibernate.cfg.xml?</p>
<p><strong>Edit:</strong> Based on your update, you aren't telling Hibernate to configure itself from the config file. You're building your own Configuration and using that. You need to pick one or the other. Either do it <a href="http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-programmatic">programmatically</a>, or do it <a href="http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-xmlconfig">via XML</a>.</p>
|
6,570,779 |
Why should I use applicative functors in functional programming?
|
<p>I'm new to Haskell, and I'm reading about functors and applicative functors. Ok, I understand functors and how I can use them, but I don't understand why <strong>applicative</strong> functors are useful and how I can use them in Haskell. Can you explain to me with a simple example why I need applicative functors?</p>
| 6,571,286 | 7 | 2 |
2012-05-24 22:51:15.51 UTC
|
2011-07-04 11:21:40.343 UTC
| 18 |
2017-04-27 03:50:53.363 UTC
|
2012-05-24 22:51:15.51 UTC
| null | 283,240 | null | 274,299 | null | 1 | 82 |
haskell|functional-programming|functor
| 18,107 |
<p><a href="http://www.soi.city.ac.uk/~ross/papers/Applicative.html" rel="noreferrer">Applicative functors</a> are a construction that provides the midpoint between functors and <a href="http://en.wikipedia.org/wiki/Monad_%28functional_programming%29" rel="noreferrer">monads</a>, and are therefore more widespread than monads, while more useful than functors. Normally you can just map a function over a functor. Applicative functors allow you to take a "normal" function (taking non-functorial arguments) use it to operate on several values that are in functor contexts. As a corollary, this gives you effectful programming without monads.</p>
<p>A nice, self-contained explanation fraught with examples can be found <a href="http://learnyouahaskell.com/functors-applicative-functors-and-monoids#applicative-functors" rel="noreferrer">here</a>. You can also read <a href="http://www.serpentine.com/blog/2008/02/06/the-basics-of-applicative-functors-put-to-practical-work/" rel="noreferrer">a practical parsing example</a> developed by Bryan O'Sullivan, which requires no prior knowledge.</p>
|
6,761,415 |
How to set a cookie for another domain
|
<p>Say I have a website called <code>a.com</code>, and when a specific page of this site is loaded, say page link, I like to set a cookie for another site called <code>b.com</code>, then redirect the user to <code>b.com</code>. </p>
<p>I mean, on load of <code>a.com/link</code> I want to set a cookie for <code>b.com</code> and redirect user to <code>b.com</code>. </p>
<p>I tested it, and browser actually received the cookie from <code>a.com/link</code>, but it didn't send that cookie on the redirection request to <code>b.com</code>. Is it normal?</p>
<p>Can we set cookies for other domains?</p>
| 6,761,443 | 11 | 2 | null |
2011-07-20 11:51:12.557 UTC
| 52 |
2020-10-14 15:51:42.6 UTC
|
2016-07-26 06:18:30.9 UTC
| null | 4,273,915 | null | 851,784 | null | 1 | 215 |
javascript|cookies|redirect
| 286,498 |
<p>You cannot set cookies for another domain. Allowing this would present an enormous security flaw.</p>
<p>You need to get b.com to set the cookie. If a.com redirect the user to <code>b.com/setcookie.php?c=value</code></p>
<p>The setcookie script could contain the following to set the cookie and redirect to the correct page on b.com</p>
<pre><code><?php
setcookie('a', $_GET['c']);
header("Location: b.com/landingpage.php");
?>
</code></pre>
|
45,304,810 |
Angular Form validation on child components
|
<p>I've written a dynamic form in which there is a main part and sub parts based on a type that's selected in the main part (widget.type). Showing and hiding the sub parts is done with an ngSwitch.</p>
<p>HTML of the form looks like this:</p>
<pre><code><form class="widget-form cc-form" (ngSubmit)="saveChanges()" novalidate>
<div class="forms-group">
<label for="title" i18n="@@title">Titel</label>
<input class="form-control" id="title" name="title" type="text" [(ngModel)]="widget.title" required />
</div>
<div class="forms-group">
<label class="checkbox-label" for="show" i18n>
<input id="show" name="show" type="checkbox" [(ngModel)]="widget.show" /> <span>Titel tonen in app</span>
</label>
</div>
<div class="forms-group">
<label for="type" i18n="@@type">Type</label>
<select class="form-control" id="type" name="type" [(ngModel)]="widget.type" required>
<option value="text-widget" i18n="@@Text">Tekst</option>
<option value="tasklist-widget" i18n="@@Tasklists">Takenlijst</option>
<option value="image-widget" i18n="@@Text">Afbeelding(en)</option>
<option value="video-widget" i18n="@@Video">Youtube</option>
<option value="link-widget" i18n="@@Link">Link</option>
<option value="contacts-widget" i18n="@@Contacts">Contactpersonen</option>
<option value="attachment-widget" i18n="@@Attachments">Bijlage(n)</option>
</select>
</div>
<ng-container [ngSwitch]="widget.type">
<text-widget *ngSwitchCase="'text-widget'" [data]="widget"></text-widget>
<tasklist-widget *ngSwitchCase="'tasklist-widget'" [data]="widget"></tasklist-widget>
<image-widget *ngSwitchCase="'image-widget'" [data]="widget"></image-widget>
<video-widget *ngSwitchCase="'video-widget'" [data]="widget"></video-widget>
<link-widget *ngSwitchCase="'link-widget'" [data]="widget"></link-widget>
<contacts-widget *ngSwitchCase="'contacts-widget'" [data]="widget"></contacts-widget>
<attachment-widget *ngSwitchCase="'attachment-widget'" [data]="widget"></attachment-widget>
</ng-container>
</form>
</code></pre>
<p>Every widget is it's own component.</p>
<p>The problem is that the form validation only checks the inputs from the main part and disregards the sub part (widget components). How can I make sure the input fields from the widgets are included in the validation?</p>
<p>I tried adding an isValid() method to the widget components but I couldn't get the instances of the components, probably because they are used in an ngSwitch. @ContentChild, @ContentChildren, @ViewChild etc. all returned undefined.</p>
| 57,859,420 | 3 | 6 | null |
2017-07-25 13:28:12.49 UTC
| 9 |
2019-09-10 05:56:55.387 UTC
| null | null | null | null | 1,859,954 | null | 1 | 16 |
forms|angular|typescript|angular-components
| 21,116 |
<p>For future googlers,</p>
<p>I had a similar issue to this, albeit with fewer child components and after digging through @penleychan's aforementioned thread on the subject I found a little gem that solved this for me without the need to implement a custom directive.</p>
<pre><code>import { ControlContainer, NgForm } from '@angular/forms';
@Component({
....
viewProviders: [{ provide: ControlContainer, useExisting: NgForm }],
})
</code></pre>
<blockquote>
<p>This works for my nested form. Just needs to be added to components,
which ones directly contains inputs</p>
</blockquote>
<p><a href="https://github.com/angular/angular/issues/9600#issuecomment-522898551" rel="noreferrer">https://github.com/angular/angular/issues/9600#issuecomment-522898551</a></p>
|
15,929,686 |
How to decode unicode HTML by JavaScript?
|
<p>How to use JavaScript to decode from:</p>
<pre><code>\u003cb\u003estring\u003c/b\u003e
</code></pre>
<p>to</p>
<pre><code><b>string</b>
</code></pre>
<p>(I searched in internet, there are some site with same question, such as:
<a href="https://stackoverflow.com/questions/4692882/javascript-html-decoding">Javascript html decoding</a><br>
or
<a href="https://stackoverflow.com/questions/11366021/how-to-decode-html-entities">How to decode HTML entities</a><br>
but it <strong>dont have same encode fomat</strong>)<br>
Thank you very much!</p>
| 15,929,722 | 2 | 0 | null |
2013-04-10 15:08:19.83 UTC
| 8 |
2021-08-10 20:37:15.443 UTC
|
2017-05-23 12:02:03.663 UTC
| null | -1 | null | 1,560,697 | null | 1 | 12 |
javascript|unicode|decode
| 41,615 |
<pre><code>decodeURIComponent('\u003cb\u003estring\u003c/b\u003e');
// "<b>string</b>"
</code></pre>
<p>Edit - I would delete the above answer if I could.</p>
<p>The original question is a bit ambiguous.</p>
<p><code>console.log('\u003cb\u003estring\u003c/b\u003e');</code> will already yield <code><b>string</b></code></p>
<p>If the <code>\</code> characters are escaped, then a replacement method could be used to replace <code>\\</code> with just <code>\</code>, thus allowing the proper Unicode escape sequence.</p>
|
15,648,711 |
angular js adding two numbers issue
|
<p>I have this code using angular js:</p>
<pre><code><!DOCTYPE html >
<html>
<head>
<title>Untitled Page</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<script type="text/javascript">
function TodoCtrl($scope) {
$scope.total = function () {
return $scope.x + $scope.y;
};
}
</script>
</head>
<body>
<div ng-app>
<h2>Calculate</h2>
<div ng-controller="TodoCtrl">
<form>
<li>Number 1: <input type="text" ng-model="x" /> </li>
<li>Number 2: <input type="text" ng-model="y" /> </li>
<li>Total <input type="text" value="{{total()}}"/></li>
</form>
</div>
</div>
</body>
</html>
</code></pre>
<p>I am able to do multiplication, division and subtraction but for addition, the code just concatenates the x and y values (i.e. if x = 3 and y = 4, the total is 34 instead of being 7)</p>
<p>What am I doing wrong?</p>
| 15,648,744 | 7 | 0 | null |
2013-03-26 22:36:20.46 UTC
| null |
2017-03-13 10:14:57.657 UTC
| null | null | null | null | 1,238,850 | null | 1 | 15 |
javascript|angularjs
| 47,511 |
<p>If that is indeed the case then what is happening is the values that are being passed in for x and y are being treated as strings and concatenated. What you should do is convert them to numbers using <code>parseInt</code></p>
<pre><code>return parseInt($scope.x) + parseInt($scope.y);
</code></pre>
<p>or if you prefer brevity</p>
<pre><code>return $scope.x*1 + $scope.y*1;
</code></pre>
|
15,521,451 |
How to navigate in JSF? How to make URL reflect current page (and not previous one)
|
<p>I am currently learning JSF and was rather amazed and puzzled when I realized that whenever we use <code><h:form></code>, the standard behavior of JSF is to always show me the URL of the <em>previous</em> page in the browser, as opposed to the URL of the <em>current</em> page. </p>
<p>I understand that this has to do with the way JSF always posts a form to the same page and then just renders whatever page the controller gives it back to the browser which doesn't know the page location has changed.</p>
<p><strong>It seems like JSF has been around for long enough that there must be a clean, solid way to deal with this. If so, would you mind sharing?</strong> </p>
<p>I have found various workarounds, but sadly nothing that seems like a real solid solution.</p>
<ul>
<li>Simply accept that the URL is misleading.</li>
<li>Append <code>"?faces-redirect=true"</code> to the return value of <em>every</em> bean's action and then
<ul>
<li>figure out how to replace <code>@RequestScoped</code> with something else (Flash Scopes, CDI conversation, @SessionScoped, ...).</li>
<li>accept to have two HTTP round trips for every user action.</li>
</ul></li>
<li>Use some method (e.g. 3rd party library or custom code) to hide the page name in the URL, always using the same generic URL for every page.</li>
</ul>
<p>If <code>"?faces-redirect=true"</code> is as good as it gets, is there a way do configure an entire application to treat all requests this way?</p>
| 15,523,045 | 1 | 1 | null |
2013-03-20 10:51:13.17 UTC
| 51 |
2018-10-31 10:35:19.707 UTC
|
2015-01-30 09:08:01.65 UTC
| null | 157,882 | null | 1,290,182 | null | 1 | 59 |
jsf|url|redirect|navigation
| 48,478 |
<p>Indeed, JSF as being a form based application targeted MVC framework submits the POST form to the very same URL as where the page with the <code><h:form></code> is been requested form. You can confirm it by looking at the <code><form action></code> URL of the generated HTML output. This is in web development terms characterized as <em>postback</em>. A navigation on a postback does by default not cause a new request to the new URL, but instead loads the target page as content of the response. This is indeed confusing when you merely want page-to-page navigation.</p>
<p>Generally, the right approach as to navigation/redirection depends on the business requirements and the <a href="http://en.wikipedia.org/wiki/Idempotence" rel="noreferrer">idempotence</a> (read: "bookmarkability") of the request (note: for concrete code examples, see the "See also" links below).</p>
<ul>
<li><p>If the request is idempotent, just use a GET form/link instead of POST form (i.e. use <code><a></code>, <code><form></code>, <code><h:link></code> or <code><h:button></code> instead of <code><h:form></code> and <code><h:commandXxx></code>).<br />
For example, page-to-page navigation, Google-like search form, etc.</p>
</li>
<li><p>If the request is non-idempotent, just show results conditionally in the same view (i.e. return <code>null</code> or <code>void</code> from action method and make use of e.g. <code><h:message(s)></code> and/or <code>rendered</code>).<br />
For example, in-page data entry/edit, multi-step wizard, modal dialog, confirmation form, etc.</p>
</li>
<li><p>If the request is non-idempotent, but the target page is idempotent, just send a redirect after POST (i.e. return outcome with <code>?faces-redirect=true</code> from action method, or manually invoke <code>ExternalContext#redirect()</code>, or put <code><redirect/></code> in legacy XML navigation case).<br />
For example, showing list of all data after successful editing, redirect after login, etc.</p>
</li>
</ul>
<p>Note that pure page-to-page navigation is usually idempotent and this is where many JSF starters fail by abusing command links/buttons for that and then complain afterwards that URLs don't change. Also note that navigation cases are very rarely used in real world applications which are developed with respect to SEO/UX and this is where many JSF tutorials fail by letting the readers believe otherwise.</p>
<p>Also note that using POST is absolutely not "more secure" than GET because the request parameters aren't immediately visible in URL. They are still visible in HTTP request body and still manipulatable. So there's absolutely no reason to prefer POST for idempotent requests for the sake of "security". The real security is in using HTTPS instead of HTTP and checking in business service methods if currently logged-in user is allowed to query entity X, or to manipulate entity X, etc. A decent security framework offers annotations for this.</p>
<h3>See also:</h3>
<ul>
<li><a href="https://stackoverflow.com/questions/11277366">What is the difference between redirect and navigation/forward and when to use what?</a></li>
<li><a href="https://stackoverflow.com/questions/18037884">JSF implicit vs. explicit navigation</a></li>
<li><a href="https://stackoverflow.com/questions/30683584">What URL to use to link / navigate to other JSF pages</a></li>
<li><a href="https://stackoverflow.com/questions/13249844">Bookmarkability via View Parameters feature</a></li>
<li><a href="https://stackoverflow.com/questions/6377798">What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?</a></li>
<li><a href="https://stackoverflow.com/questions/4317684">When should I use h:outputLink instead of h:commandLink?</a></li>
<li><a href="https://stackoverflow.com/questions/8459903">Creating master-detail pages for entities, how to link them and which bean scope to choose</a></li>
<li><a href="https://stackoverflow.com/questions/17734230">Retaining GET request query string parameters on JSF form submit</a></li>
<li><a href="https://stackoverflow.com/questions/25694423">Pass an object between @ViewScoped beans without using GET params</a></li>
</ul>
|
15,952,663 |
Find the PID of a process that uses a port on Windows
|
<p>My service crash on startup with the classic:</p>
<pre><code>java.rmi.server.ExportException: Listen failed on port: 9999
</code></pre>
<p>How can I find the process for killing it?</p>
| 15,952,726 | 7 | 2 | null |
2013-04-11 15:21:17.447 UTC
| 66 |
2019-10-26 17:58:41.97 UTC
|
2019-04-06 16:52:15.053 UTC
| null | 63,550 | null | 2,135,045 | null | 1 | 135 |
port
| 344,621 |
<p>Just open a command shell and type (saying your port is 123456):</p>
<pre><code>netstat -a -n -o | find "123456"
</code></pre>
<p>You will see everything you need.</p>
<p>The headers are:</p>
<pre><code> Proto Local Address Foreign Address State PID
TCP 0.0.0.0:37 0.0.0.0:0 LISTENING 1111
</code></pre>
|
35,926,381 |
Change highlight text color in Visual Studio Code
|
<p>Right now, it is a faint gray overlay, which is hard to see. Any way to change the default color?</p>
<p><a href="https://i.stack.imgur.com/qmrOL.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/qmrOL.jpg" alt="enter image description here"></a></p>
| 35,929,462 | 8 | 5 | null |
2016-03-10 20:17:05.99 UTC
| 63 |
2021-07-02 09:31:28.643 UTC
| null | null | null | null | 2,128,937 | null | 1 | 213 |
visual-studio-code
| 122,549 |
<p><strong>Update</strong>
<a href="https://stackoverflow.com/a/43605752/285212">See @Jakub Zawiślak's answer for VScode 1.12+</a></p>
<hr>
<p><strong>Old answer</strong></p>
<p>Visual Studio Code calls this selection highlighting and unfortunately, I don't think the color is customizable currently. Themes can control the 'selection' color, but the 'selection highlight' color is hardcoded.</p>
<p>See this issue tracking a possible solution: <a href="https://github.com/Microsoft/vscode/issues/1636" rel="noreferrer">https://github.com/Microsoft/vscode/issues/1636</a></p>
<p>(As a side note, you can toggle this feature or/off with the <code>editor.selectionHighlight</code> setting.)</p>
|
10,577,374 |
Mysql command not found in OS X 10.7
|
<p>I cant get my mysql to start on os x 10.7. It is located in <code>/usr/local/mysql/bin/mysql</code></p>
<p>I get command not found when I type <code>mysql --version</code> in the terminal.</p>
<p>I tried this <a href="https://stackoverflow.com/questions/8195418/cant-access-mysql-from-command-line-mac">can't access mysql from command line mac</a> but still get command not found. I tried installing mysql with the dmg and i have tried to install it through homebrew and I cant get it to work. When I try to start mysql with homebrew I get <a href="https://stackoverflow.com/questions/10576743/mysql-wont-start/10576831#10576831">MySQL won't start</a></p>
<p>This is my <code>$PATH</code>:</p>
<blockquote>
<p>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/Users/Victoria/bin:/usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin</p>
</blockquote>
| 10,577,432 | 17 | 4 | null |
2012-05-14 03:59:56.63 UTC
| 77 |
2021-03-07 18:57:29.423 UTC
|
2017-05-23 11:47:24.983 UTC
| null | -1 | null | 1,022,672 | null | 1 | 198 |
mysql
| 478,878 |
<p>This is the problem with your $PATH: </p>
<p><code>/usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin</code>. </p>
<p><code>$PATH</code> is where the shell searches for command files. Folders to search in need to be separated with a colon. And so you want <code>/usr/local/mysql/bin/</code> in your path but instead it searches in <code>/usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin</code>, which probably doesn't exist. </p>
<p>Instead you want <code>${PATH}:/usr/local/mysql/bin</code>. </p>
<p>So do <code>export PATH=${PATH}:/usr/local/mysql/bin</code>. </p>
<p>If you want this to be run every time you open terminal put it in the file <code>.bash_profile</code>, which is run when Terminal opens.</p>
|
10,810,798 |
Cropping image with transparency in iPhone
|
<p>I am working on Jigsaw type of game where i have two images for masking,
I have implemented this code for masking</p>
<pre><code>- (UIImage*) maskImage:(UIImage *)image withMaskImage:(UIImage*)maskImage {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef maskImageRef = [maskImage CGImage];
CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL, maskImage.size.width, maskImage.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
if (mainViewContentContext==NULL)
return NULL;
CGFloat ratio = 0;
ratio = maskImage.size.width/ image.size.width;
if(ratio * image.size.height < maskImage.size.height) {
ratio = maskImage.size.height/ image.size.height;
}
CGRect rect1 = {{0, 0}, {maskImage.size.width, maskImage.size.height}};
CGRect rect2 = {{-((image.size.width*ratio)-maskImage.size.width)/2,-((image.size.height*ratio)-maskImage.size.height)/2},{image.size.width*ratio, image.size.height*ratio}};
CGContextClipToMask(mainViewContentContext, rect1, maskImageRef);
CGContextDrawImage(mainViewContentContext, rect2, image.CGImage);
CGImageRef newImage = CGBitmapContextCreateImage(mainViewContentContext);
CGContextRelease(mainViewContentContext);
UIImage *theImage = [UIImage imageWithCGImage:newImage];
CGImageRelease(newImage);
return theImage;
}
</code></pre>
<p><img src="https://i.stack.imgur.com/Jd7ji.png" alt="enter image description here"></p>
<p>+</p>
<p><img src="https://i.stack.imgur.com/QYttC.png" alt="enter image description here"></p>
<p>=</p>
<p>This is final result i got after masking.</p>
<p><img src="https://i.stack.imgur.com/34MA9.png" alt="enter image description here"></p>
<p>now i would like to crop image in piece like <img src="https://i.stack.imgur.com/e8YBT.png" alt="enter image description here"> and <img src="https://i.stack.imgur.com/6o2xd.png" alt="enter image description here"> and so on parametrically(crop an image by transparency).</p>
<p>if any one has implemented such code or any idea on this scenario please share.</p>
<p>Thanks.</p>
<p>I am using this line of code for as <strong>Guntis Treulands's</strong> suggestion </p>
<pre><code>int i=1;
for (int x=0; x<=212; x+=106) {
for (int y=0; y<318; y+=106) {
CGRect rect = CGRectMake(x, y, 106, 106);
CGRect rect2x = CGRectMake(x*2, y*2, 212, 212);
UIImage *orgImg = [UIImage imageNamed:@"cat@2x.png"];
UIImage *frmImg = [UIImage imageNamed:[NSString stringWithFormat:@"%d@2x.png",i]];
UIImage *cropImg = [self cropImage:orgImg withRect:rect2x];
UIImageView *tmpImg = [[UIImageView alloc] initWithFrame:rect];
[tmpImg setUserInteractionEnabled:YES];
[tmpImg setImage:[self maskImage:cropImg withMaskImage:frmImg]];
[self.view addSubview:tmpImg];
i++;
}
}
</code></pre>
<p>orgImg is original cat image, frmImg frame for holding individual piece, masked in photoshop and cropImg is 106x106 cropped image of original cat@2x.png. </p>
<p>my function for cropping is as following</p>
<pre><code>- (UIImage *) cropImage:(UIImage*)originalImage withRect:(CGRect)rect {
return [UIImage imageWithCGImage:CGImageCreateWithImageInRect([originalImage CGImage], rect)];
}
</code></pre>
| 10,846,014 | 1 | 5 | null |
2012-05-30 06:07:36.053 UTC
| 17 |
2015-02-23 13:21:43.017 UTC
|
2012-06-11 11:49:05.143 UTC
| null | 392,924 | null | 392,924 | null | 1 | 23 |
iphone|uiimage|transparency
| 5,656 |
<p><strong>UPDATE 2</strong></p>
<p>I became really curious to find a better way to create a Jigsaw puzzle, so I spent two weekends and created a demo project of <a href="https://github.com/GuntisTreulands/JigsawDemo" rel="noreferrer">Jigsaw puzzle</a>.</p>
<p>It contains:</p>
<ul>
<li>provide column/row count and it will generate necessary puzzle pieces with correct width/height. The more columns/rows - the smaller the width/height and outline/inline puzzle form.</li>
<li>each time generate randomly sides</li>
<li>can randomly position / rotate pieces at the beginning of launch</li>
<li>each piece can be rotated by tap, or by two fingers (like a real piece) - but once released, it will snap to 90/180/270/360 degrees</li>
<li>each piece can be moved if touched on its “touchable shape” boundary (which is mostly the - same visible puzzle shape, but WITHOUT inline shapes)</li>
</ul>
<p>Drawbacks:</p>
<ul>
<li>no checking if piece is in its right place</li>
<li>if more than 100 pieces - it starts to lag, because, when picking up a piece, it goes through all subviews until it finds correct piece.</li>
</ul>
<p><strong>UPDATE</strong></p>
<p>Thanks for updated question.</p>
<p>I managed to get this:</p>
<p><img src="https://i.stack.imgur.com/sKfy8.png" alt="enter image description here"></p>
<p>As you can see - jigsaw item is cropped correctly, and it is in square imageView <strong>(green color is UIImageView backgroundColor).</strong></p>
<p>So - what I did was:</p>
<pre><code>CGRect rect = CGRectMake(105, 0, 170, 170); //~ location on cat image where second Jigsaw item will be.
UIImage *originalCatImage = [UIImage imageNamed:@"cat.png"];//original cat image
UIImage *jigSawItemMask = [UIImage imageNamed:@"JigsawItemNo2.png"];//second jigsaw item mask (visible in my answer) (same width/height as cat image.)
UIImage *fullJigSawItemImage = [jigSawItemMask maskImage:originalCatImage];//masking - so that from full cat image would be visible second jigsaw item
UIImage *croppedJigSawItemImage = [self fullJigSawItemImage withRect:rect];//cropping so that we would get small image with jigsaw item centered in it.
</code></pre>
<p>For image masking I am using UIImage category function: (but you can probably use your masking function. But I'll post it anyways.)</p>
<pre><code>- (UIImage*) maskImage:(UIImage *)image
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
UIImage *maskImage = self;
CGImageRef maskImageRef = [maskImage CGImage];
// create a bitmap graphics context the size of the image
CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL, maskImage.size.width, maskImage.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
if (mainViewContentContext==NULL)
return NULL;
CGFloat ratio = 0;
ratio = maskImage.size.width/ image.size.width;
if(ratio * image.size.height < maskImage.size.height) {
ratio = maskImage.size.height/ image.size.height;
}
CGRect rect1 = {{0, 0}, {maskImage.size.width, maskImage.size.height}};
CGRect rect2 = {{-((image.size.width*ratio)-maskImage.size.width)/2 , -((image.size.height*ratio)-maskImage.size.height)/2}, {image.size.width*ratio, image.size.height*ratio}};
CGContextClipToMask(mainViewContentContext, rect1, maskImageRef);
CGContextDrawImage(mainViewContentContext, rect2, image.CGImage);
// Create CGImageRef of the main view bitmap content, and then
// release that bitmap context
CGImageRef newImage = CGBitmapContextCreateImage(mainViewContentContext);
CGContextRelease(mainViewContentContext);
UIImage *theImage = [UIImage imageWithCGImage:newImage];
CGImageRelease(newImage);
// return the image
return theImage;
}
</code></pre>
<p><strong>PREVIOUS ANSWER</strong></p>
<p>Can you prepare a mask for each piece? </p>
<p>For example, you have that frame image. Can you cut it in photoshop in 9 separate images, where in each image it would only show corresponding piece. (all the rest - delete).</p>
<p>Example - second piece mask: </p>
<p><img src="https://i.stack.imgur.com/YP84N.png" alt="enter image description here"></p>
<p>Then you use each of these newly created mask images on cat image - each piece will mask all image, but one peace. Thus you will have 9 piece images using 9 different masks.</p>
<p>For larger or different jigsaw frame - again, create separated image masks.</p>
<p>This is a basic solution, but not perfect, as you need to prepare each peace mask separately.</p>
<p>Hope it helps.. </p>
|
13,762,992 |
Log Structured Merge Tree in Hbase
|
<p>I am working on Hbase. I have query regarding how Hbase store the data in sorted order with LSM.</p>
<p>As per my understanding, Hbase use LSM Tree for data transfer in large scale data processing. when Data comes from client, it store in-memory sequentially first and than sort and store as B-Tree as Store file. Than it is merging the Store file with Disk B-Tree(of key). is it correct ? Am I missing something ?</p>
<ul>
<li><p>If Yes, than in cluster env. there are multiple RegionServers who take the client request. On that case, How all the Hlogs (of each regionServer) merge with disk B-Tree(as existing key spread across the all dataNode disk) ? </p></li>
<li><p>Is it like Hlog only merge the data with Hfile of same regionServer ?</p></li>
</ul>
| 13,763,821 | 2 | 0 | null |
2012-12-07 12:20:16.457 UTC
| 9 |
2017-02-22 11:10:38.813 UTC
|
2012-12-07 12:38:40.25 UTC
| null | 1,295,365 | null | 1,295,365 | null | 1 | 6 |
hadoop|hbase|hive|hdfs
| 14,622 |
<p>You can take a look at this two articles that describe exactly what you want</p>
<p><a href="http://blog.cloudera.com/blog/2012/06/hbase-io-hfile-input-output/" rel="noreferrer">http://blog.cloudera.com/blog/2012/06/hbase-io-hfile-input-output/</a></p>
<p><a href="http://blog.cloudera.com/blog/2012/06/hbase-write-path/" rel="noreferrer">http://blog.cloudera.com/blog/2012/06/hbase-write-path/</a></p>
<p>In brief:</p>
<ul>
<li>The client send data to the region server that is responsible to handle the key</li>
<li>(.META. contains key ranges for each region)</li>
<li>The user operation (e.g. put) is written to the Write-Ahead-Log (WAL, the HLog)</li>
<li>(The log is used just for "safety" if the region server crash the log is replayed to recover data not written to disk)</li>
<li>After writing to the log, data is also written to the MemStore</li>
<li>...once the memstore reach a threshold (conf property)</li>
<li>The memstore is flushed on disk, creating a single hfile</li>
<li>...when the number of hfiles grows too much (conf property) the compaction kicks in (merge)</li>
</ul>
<p>In terms of on disk data structure:
<a href="http://blog.cloudera.com/blog/2012/06/hbase-io-hfile-input-output/" rel="noreferrer">http://blog.cloudera.com/blog/2012/06/hbase-io-hfile-input-output/</a>
The article above cover the hfile format...
it's an append only format, and can be seen like a b+tree. (Keeping in mind that this b+tree cannot be modified in place)</p>
<p>The HLog is only used for "safety", once the data is written to the hfiles, the logs can be thrown away</p>
|
13,295,600 |
multiple one-to-many relations ResultSetExtractor
|
<p>Let's say I have an object with two different one-to-many relations. Much like:</p>
<p><code>Customer 1<->M Brands</code> and <code>Customer 1<->M Orders</code></p>
<p>And let's say that the my object <code>Customer</code> has two lists related to those two objects.</p>
<p>I've read this example:
<a href="http://forum.springsource.org/showthread.php?50617-rowmapper-with-one-to-many-query" rel="noreferrer">http://forum.springsource.org/showthread.php?50617-rowmapper-with-one-to-many-query</a>
which explains how to do it with a single one-to-many relationship. For your convenience here's the <code>ResultSetExtractor</code> override:</p>
<pre><code>private class MyObjectExtractor implements ResultSetExtractor{
public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
Map<Integer, MyObject> map = new HashMap<Integer, MyObject>();
MyObject myObject = null;
while (rs.next()) {
Integer id = rs.getInt("ID);
myObject = map.get(id);
if(myObject == null){
String description = rs,getString("Description");
myObject = new MyObject(id, description);
map.put(id, myObject);
}
MyFoo foo = new MyFoo(rs.getString("Foo"), rs.getString("Bar"));
myObject.add(myFoo);
}
return new ArrayList<MyObject>(map.values());;
}
}
</code></pre>
<p>I don't think it covers how to work with both. What would be the cleanest approach? Is there a simpler way than to iterate with conditions? Would sets be better off than lists in this case? </p>
| 13,583,889 | 4 | 8 | null |
2012-11-08 18:41:44.767 UTC
| 11 |
2012-11-28 07:11:14.87 UTC
| null | null | null | null | 930,928 | null | 1 | 8 |
java|spring|jdbc|jdbctemplate|spring-jdbc
| 30,230 |
<p>From your question, I assume that you have three tables; Customer, Brands, Orders. If you want to fetch the Brands and Orders properties of the Customer to your customer object, where there is no relationship between Brands and Orders, what I suggest is to use a UNION query. Something like this:</p>
<pre><code>TBL_CUSTOMER
------------
CUSTOMER_ID
CUSTOMER_ACCOUNT_NO
CUSTOMER_NAME
TBL_CUSTOMER_BRANDS
-------------------
CUSTOMER_BRAND_ID - UK
BRAND_NAME
CUSTOMER_ID - FK
TBL_ORDERS
-------------------
ORDER_ID - UK
CUSTOMER_ID - FK
</code></pre>
<p>Query:</p>
<pre><code>SELECT CUS.*, BRANDS.CUSTOMER_BRAND_ID COL_A, BRANDS.BRAND_NAME COL_B, 1 IS_BRAND FROM TBL_CUSTOMER CUS JOIN TBL_CUSTOMER_BRANDS BRANDS ON (CUS.CUSTOMER_ID = BRANDS.CUSTOMER_ID)
UNION ALL
SELECT CUS.*, ORDERS.ORDER_ID, '', 0 IS_BRAND FROM TBL_CUSTOMER CUS JOIN TBL_ORDERS ORDERS ON (CUS.CUSTOMER_ID = ORDERS.CUSTOMER_ID)
</code></pre>
<p>Your ResultSetExtractor will become:</p>
<pre><code>private class MyObjectExtractor implements ResultSetExtractor{
public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
Map<Long, Customer> map = new HashMap<Long, Customer>();
while (rs.next()) {
Long id = rs.getLong("CUSTOMER_ID");
Customer customer = map.get(id);
if(customer == null){
customer = new Customer();
customer.setId(id);
customer.setName(rs.getString("CUSTOMER_NAME"));
customer.setAccountNumber(rs.getLong("CUSTOMER_ACCOUNT_NO"));
map.put(id, customer);
}
int type = rs.getInt("IS_BRAND");
if(type == 1) {
List brandList = customer.getBrands();
if(brandsList == null) {
brandsList = new ArrayList<Brand>();
customer.setBrands(brandsList);
}
Brand brand = new Brand();
brand.setId(rs.getLong("COL_A"));
brand.setName(rs.getString("COL_B"));
brandsList.add(brand);
} else if(type == 0) {
List ordersList = customer.getOrders();
if(ordersList == null) {
ordersList = new ArrayList<Order>();
customer.setOrders(ordersList);
}
Order order = new Order();
order.setId(rs.getLong("COL_A"));
ordersList.add(order);
}
}
return new ArrayList<Customer>(map.values());
}
}
</code></pre>
|
13,614,157 |
Get text of selected items in a ListBox
|
<p>I'm trying to show the selected items of listBox1 in a Message Box here's the code:</p>
<pre><code>int index;
string item;
foreach (int i in listBox1 .SelectedIndices )
{
index = listBox1.SelectedIndex;
item = listBox1.Items[index].ToString ();
groupids = item;
MessageBox.Show(groupids);
}
</code></pre>
<p>The problem is that when I select more than one item
the message box shows the frist one I've selected and repeats the message
EX: if I selected 3 items the message will appear 3 times with the first item</p>
| 13,614,192 | 4 | 0 | null |
2012-11-28 20:52:07.22 UTC
| 3 |
2018-10-02 16:22:45.243 UTC
|
2012-11-28 20:54:04.313 UTC
| null | 27,414 | null | 1,849,107 | null | 1 | 10 |
c#|winforms
| 81,231 |
<p>The <code>i</code> in the foreach loop has the index you need. You're using <code>listBox1.SelectedIndex</code> which only has the first one. So item should be:</p>
<pre><code>item = listBox1.Items[i].ToString ();
</code></pre>
|
13,410,874 |
how to display background color in outlook 2010 html email?
|
<p>My problem is related to Microsoft Outlook 2010. Actually I want to publish my HTML newsletter in Outlook 2010, but the main problem which I am facing is styling problem it's not showing color and all when the newsletter is published in Outlook 2010. please help me out if you know how to set color and css style in Outlook. </p>
| 13,410,985 | 5 | 1 | null |
2012-11-16 05:14:17.94 UTC
| 6 |
2020-08-26 02:15:15.69 UTC
| null | null | null | null | 1,828,621 | null | 1 | 29 |
html|css|outlook-2010
| 66,075 |
<p>This method works across email clients:</p>
<pre><code><table bgcolor="#3399ff" style="background:#3399ff;"><tr><td>test</td></tr></table>
</code></pre>
|
13,325,519 |
jQuery: trigger a hover event from another element
|
<p>When you hover over one <code><div></code>, I want an <code><a></code> on a separate part of the page to be "hovered" on also.</p>
<pre><code><div class="initiator">
</div>
<div>
<a class="receiver href="#">Touch the div and I get hovered!</a>
</div>
</code></pre>
<p>I've tried this jQuery, but it doesn't trigger the <code><a></code>'s hover CSS. </p>
<pre><code>$(".initiator").hover(function(){
$(".receiver").hover();
console.log("div was hovered");
});
</code></pre>
| 13,325,647 | 4 | 1 | null |
2012-11-10 19:50:46.383 UTC
| 8 |
2014-12-26 20:30:24.027 UTC
| null | null | null | null | 1,001,938 | null | 1 | 32 |
javascript|jquery|html|hover|bind
| 79,184 |
<p>Try this:</p>
<pre><code>$('.initiator').on('mouseenter mouseleave', function(e) {
$('.receiver').trigger(e.type);
})
</code></pre>
<p>It will apply the same triggers for the receiver as the initiator receives for both mouseenter and mouseleave. Note that:</p>
<pre><code>.hover(over, out)
</code></pre>
<p>is just a high-level variant of:</p>
<pre><code>.on('mouseenter', over).on('mouseleave', out)
</code></pre>
<p>so using that information you can be more precise when binding and triggering mouse events.</p>
<p>As noted in the comment, you can also use:</p>
<pre><code>$('.initiator').hover(function(e) {
$('.receiver').trigger(e.type);
})
</code></pre>
<p>There are lots more to read here: <a href="http://api.jquery.com/hover/">http://api.jquery.com/hover/</a></p>
|
13,387,742 |
Compare two objects with .equals() and == operator
|
<p>I constructed a class with one <code>String</code> field. Then I created two objects and I have to compare them using <code>==</code> operator and <code>.equals()</code> too. Here's what I've done:</p>
<pre><code>public class MyClass {
String a;
public MyClass(String ab) {
a = ab;
}
public boolean equals(Object object2) {
if(a == object2) {
return true;
}
else return false;
}
public boolean equals2(Object object2) {
if(a.equals(object2)) {
return true;
}
else return false;
}
public static void main(String[] args) {
MyClass object1 = new MyClass("test");
MyClass object2 = new MyClass("test");
object1.equals(object2);
System.out.println(object1.equals(object2));
object1.equals2(object2);
System.out.println(object1.equals2(object2));
}
}
</code></pre>
<p>After compile it shows two times false as a result. Why is it false if the two objects have the same fields - "test"?</p>
| 13,387,787 | 16 | 4 | null |
2012-11-14 21:35:08.39 UTC
| 35 |
2022-07-23 14:43:28.517 UTC
|
2017-02-01 12:20:48.4 UTC
| null | 4,823,977 | null | 1,798,371 | null | 1 | 90 |
java|class|object|methods|equals
| 423,959 |
<p><code>==</code> compares object references, it checks to see if the two operands point to the same object (not <em>equivalent</em> objects, the <strong>same</strong> object).</p>
<p>If you want to compare strings (to see if they contain the same characters), you need to compare the strings using <code>equals</code>.</p>
<p>In your case, if two instances of <code>MyClass</code> really are considered equal if the strings match, then:</p>
<pre><code>public boolean equals(Object object2) {
return object2 instanceof MyClass && a.equals(((MyClass)object2).a);
}
</code></pre>
<p>...but usually if you are defining a class, there's more to equivalency than the equivalency of a single field (<code>a</code> in this case).</p>
<hr>
<p>Side note: If you override <code>equals</code>, you almost always need to override <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--" rel="noreferrer"><code>hashCode</code></a>. As it says in the <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-" rel="noreferrer"><code>equals</code> JavaDoc</a>:</p>
<blockquote>
<p>Note that it is generally necessary to override the <code>hashCode</code> method whenever this method is overridden, so as to maintain the general contract for the <code>hashCode</code> method, which states that equal objects must have equal hash codes.</p>
</blockquote>
|
13,604,720 |
SQL Server database restore error: specified cast is not valid. (SqlManagerUI)
|
<p>I am using SQL Server 2008 R2 Standard (version 10.50.1600.1) for my production website and
SQL Server Express edition with Advanced Services (v10.50.1600.1) for my localhost as a database.</p>
<p>Few days back my SQL Server crashed and I had to install a new 2008 R2 Express version on my localhost. It worked fine when I restored some older versions taken from Express edition but when I try to restore database from <code>.bak</code> file which is taken from production server it is causing the following error:</p>
<blockquote>
<p><em>Error: Specified cast is not valid. (SqlManagerUI)</em></p>
</blockquote>
<p>and when I try to restore the database using command </p>
<pre><code>Use Master
Go
RESTORE DATABASE Publications
FROM DISK = 'C:\Publications.bak'
WITH MOVE 'Publications' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.mdf',--adjust path
MOVE 'AlPublications_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.ldf'
</code></pre>
<p>It generates a different error </p>
<blockquote>
<p><em>Msg 3154, Level 16, State 4, Line 1<br>
The backup set holds a backup of a database other than the existing 'Publications' database.<br>
Msg 3013, Level 16, State 1, Line 1<br>
RESTORE DATABASE is terminating abnormally.</em></p>
</blockquote>
<p>I have cross checked the versions. They all seem matching to me as shown in the image below</p>
<p>Previously I was able to restore a database from standard version to express edition but now it fails. I deleted the database and tried to recreate it. That fails, too.</p>
<p>I am not sure what I am doing wrong. I would appreciate help in this regarding </p>
<p><strong>Issue was resolved</strong> as it seems .bak file was corrupt. When I tried it with a different file it worked.</p>
| 13,604,946 | 4 | 5 | null |
2012-11-28 12:07:02.16 UTC
| 8 |
2018-06-20 10:08:21.12 UTC
|
2014-09-24 06:02:35.037 UTC
| null | 1,122,748 | null | 1,122,748 | null | 1 | 93 |
sql-server|sql-server-2008|database-restore
| 435,911 |
<p>The GUI can be fickle at times. The error you got when using T-SQL is because you're trying to overwrite an existing database, but did not specify to overwrite/replace the existing database. The following might work:</p>
<pre><code>Use Master
Go
RESTORE DATABASE Publications
FROM DISK = 'C:\Publications_backup_2012_10_15_010004_5648316.bak'
WITH
MOVE 'Publications' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.mdf',--adjust path
MOVE 'Publications_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.ldf'
, REPLACE -- Add REPLACE to specify the existing database which should be overwritten.
</code></pre>
|
13,433,799 |
Why doesn't nodelist have forEach?
|
<p>I was working on a short script to change <code><abbr></code> elements' inner text, but found that <code>nodelist</code> does not have a <code>forEach</code> method. I know that <code>nodelist</code> doesn't inherit from <code>Array</code>, but doesn't it seem like <code>forEach</code> would be a useful method to have? Is there a particular implementation issue I am not aware of that prevents adding <code>forEach</code> to <code>nodelist</code>?</p>
<p>Note: I am aware that Dojo and jQuery both have <code>forEach</code> in some form for their nodelists. I cannot use either due to limitations.</p>
| 27,024,188 | 10 | 1 | null |
2012-11-17 19:05:47.697 UTC
| 28 |
2020-07-15 00:01:24.513 UTC
|
2016-12-25 09:17:47.077 UTC
| null | 24,468 | null | 871,980 | null | 1 | 105 |
javascript|arrays|dom|foreach
| 71,852 |
<h2>NodeList now has forEach() in all major browsers</h2>
<p>See <a href="https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach" rel="noreferrer">nodeList forEach() on MDN</a>.</p>
<h2>Original answer</h2>
<p>None of these answers explain <em>why</em> NodeList doesn't inherit from Array, thus allowing it to have <code>forEach</code> and all the rest.</p>
<p>The answer is found <a href="https://esdiscuss.org/topic/why-does-legacy-content-break-when-making-array-likes-real-arrays" rel="noreferrer">on this es-discuss thread</a>. In short, it breaks the web:</p>
<blockquote>
<p>The problem was code that incorrectly assumed instanceof to mean that the instance was an Array in combination with Array.prototype.concat.</p>
<p>There was a bug in Google's Closure Library which caused almost all Google's apps to fail due to this. The library was updated as soon as this was found but there might still be code out there that makes the same incorrect assumption in combination with concat.</p>
</blockquote>
<p>That is, some code did something like</p>
<pre><code>if (x instanceof Array) {
otherArray.concat(x);
} else {
doSomethingElseWith(x);
}
</code></pre>
<p>However, <code>concat</code> will treat "real" arrays (not instanceof Array) differently from other objects:</p>
<pre><code>[1, 2, 3].concat([4, 5, 6]) // [1, 2, 3, 4, 5, 6]
[1, 2, 3].concat(4) // [1, 2, 3, 4]
</code></pre>
<p>so that means that the above code broke when <code>x</code> was a NodeList, because before it went down the <code>doSomethingElseWith(x)</code> path, whereas afterward it went down the <code>otherArray.concat(x)</code> path, which did something weird since <code>x</code> wasn't a real array.</p>
<p>For some time there was a proposal for an <code>Elements</code> class that was a real subclass of Array, and would be used as "the new NodeList". However, that was <a href="https://github.com/whatwg/dom/commit/10b6cf1ba02806220d5461a3bdb7939728b73635" rel="noreferrer">removed from the DOM Standard</a>, at least for now, since it wasn't feasible to implement yet for a variety of technical and specification-related reasons.</p>
|
13,362,490 |
Difference between Lookup() and Dictionary(Of list())
|
<p>I'm trying to wrap my head around which data structures are the most efficient and when / where to use which ones.</p>
<p>Now, it could be that I simply just don't understand the structures well enough, but how is an <code>ILookup(of key, ...)</code> different from a <code>Dictionary(of key, list(of ...))</code>?</p>
<p>Also where would I want to use an <code>ILookup</code> and where would it be more efficient in terms of program speed / memory / data accessing, etc?</p>
| 13,362,570 | 6 | 1 | null |
2012-11-13 14:28:21.2 UTC
| 38 |
2018-05-03 12:52:39.513 UTC
|
2012-11-13 14:35:46.853 UTC
| null | 1,159,478 | null | 1,693,085 | null | 1 | 209 |
c#|.net|vb.net|linq
| 76,587 |
<p>Two significant differences:</p>
<ul>
<li><code>Lookup</code> is immutable. Yay :) (At least, I believe the concrete <code>Lookup</code> class is immutable, and the <code>ILookup</code> interface doesn't provide any mutating members. There <em>could</em> be other mutable implementations, of course.)</li>
<li>When you lookup a key which isn't present in a lookup, you get an empty sequence back instead of a <code>KeyNotFoundException</code>. (Hence there's no <code>TryGetValue</code>, AFAICR.)</li>
</ul>
<p>They're likely to be equivalent in efficiency - the lookup may well use a <code>Dictionary<TKey, GroupingImplementation<TValue>></code> behind the scenes, for example. Choose between them based on your requirements. Personally I find that the lookup is usually a better fit than a <code>Dictionary<TKey, List<TValue>></code>, mostly due to the first two points above.</p>
<p>Note that as an implementation detail, the concrete implementation of <code>IGrouping<,></code> which is used for the values implements <code>IList<TValue></code>, which means that it's efficient to use with <code>Count()</code>, <code>ElementAt()</code> etc.</p>
|
3,319,805 |
Detecting call state in iOS4
|
<p>I would like to know if there is a possibility to detect if the user is in call from an application that is currently in background.</p>
<p>Or, receive a notification when the call is ended if the call was initiated from my app.</p>
<p>Or, even more than that - is there a possibility to detect which app is in foreground?<br/>
I don't believe that this is possible but I had to try... ;-)</p>
<p>Any info will be appreciated.</p>
<p>Thank you.</p>
| 3,320,212 | 2 | 2 | null |
2010-07-23 15:42:29.197 UTC
| 14 |
2016-06-06 02:45:00.283 UTC
|
2012-01-24 12:35:53.86 UTC
| null | 113,079 | null | 246,119 | null | 1 | 10 |
iphone|ios4|core-telephony
| 14,619 |
<p>In <code>CTCallCenter</code>, there is a method, <code>callEventHandler</code> that you can pass a block that will get called when call events happen. In this block, you'll be passed a <code>CTCall</code> object, and can get the <code>callState</code>. So, you can get a notification when a call is initiated or ended, and handle it appropriately. You can't get which application initiated the call, but if you set an ivar when you make the call, you can tell that it's your application that made the call.</p>
<p>For example:</p>
<pre><code>CTCallCenter *callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call){
if (call.callState == CTCallStateDisconnected)
{
//handle disconnect
}
};
</code></pre>
<p>EDIT: Re-reading your question, you want these events while you are suspended, correct? I don't think that's possible.</p>
<p>From the <a href="http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Reference/CTCallCenter/Reference/Reference.html#//apple_ref/doc/uid/TP40009604" rel="noreferrer">docs</a>:</p>
<blockquote>
<p>If your application is active when a call event takes place, the system dispatches the event to your handler immediately. However, call events can also take place while your application is suspended. While it is suspended, your application does not receive call events. When your application resumes the active state, it receives a single call event for each call that changed state—no matter how many state changes the call experienced while your application was suspended. The single call event sent to your handler, upon your application returning to the active state, describes the call’s state at that time.</p>
</blockquote>
|
3,352,741 |
Fortran assignment on declaration and SAVE attribute gotcha
|
<p>In fortran 95, if you assign a variable at declaration</p>
<pre><code>integer :: var = 0
</code></pre>
<p>it is equivalent to</p>
<pre><code>integer, save :: var = 0
</code></pre>
<p>and the variable is therefore preserved after routine execution (is equivalent to <code>static</code> in C speak) and does not get reinitialized when called again. What is the rationale/technical issue behind such (IMHO dangerous) behavior ?</p>
| 3,353,485 | 2 | 3 | null |
2010-07-28 12:21:19.91 UTC
| 10 |
2010-07-28 16:10:35.153 UTC
| null | null | null | null | 78,374 | null | 1 | 21 |
fortran
| 5,744 |
<p>I don't think that there is some rationale behind such behavior.</p>
<p>But as far as I know, Stefano, you used wrong terminology. In your code <strong>there is no assignment statement</strong> only variable (var) initialization using initialization expression (0).</p>
<pre><code>integer :: var = 0 ! type declaration & initialization
integer :: var ! type declaration
var = 0 ! assignment
</code></pre>
<p>So it seems that it was just committee design decision. If we have such expression (with equality sign in type declaration statement) it is initialization not assignment. And initialization takes place only once during program (and not procedures) execution.</p>
<p>However there might be some historical reasons for such decision. Take a look at <a href="http://www.rhinocerus.net/forum/lang-fortran/92384-initialization-local-variables.html" rel="noreferrer">this</a> thread.</p>
<p>Today such behavior is dangerous because many other widely used languages follows another conventions about initialization/assignment.</p>
|
3,585,533 |
Cucumber and Capybara, clicking a non-link or button element
|
<p>I am trying to test an inplace editor using Cucumber/Capybara/Selenium stack, but my problem is that the editor is activated by clicking a div and not a link or button. I can not seem to figure out how to get Capybara to do this. Is there a way of doing this?</p>
| 3,889,673 | 2 | 0 | null |
2010-08-27 15:08:32.297 UTC
| 12 |
2018-03-16 15:36:51.76 UTC
| null | null | null | null | 134,482 | null | 1 | 46 |
selenium|cucumber|integration-testing|webdriver|capybara
| 17,112 |
<p>You can click on an element via <a href="http://rdoc.info/github/jnicklas/capybara/master/Capybara/Node/Element#click-instance_method" rel="noreferrer"><code>Capybara::Element.click</code></a>. I add the following for this in my <code>web_steps.rb</code> to click on divs.</p>
<pre><code>When /^(?:|I )click within "([^"]*)"$/ do |selector|
find(selector).click
end
</code></pre>
<p>There is also <a href="http://rdoc.info/github/jnicklas/capybara/master/Capybara/Node/Element#trigger-instance_method" rel="noreferrer"><code>Element.trigger('mouseover')</code></a> which appears to enable hover albeit not working with Selenium.</p>
<p>It is also very likely you will need to decorate your feature/scenario with Capybara's provided <code>@javascript</code> tag.</p>
|
3,599,318 |
Hibernate query.list() method is returning empty list instead of null value
|
<p>When there are no rows, both <code>query.list()</code> and <code>criteria.list()</code> are returning <em>empty</em> list instead of a <code>null</code> value.</p>
<p>What is the reason behind this?</p>
| 3,599,343 | 2 | 1 | null |
2010-08-30 09:48:17.513 UTC
| 9 |
2020-02-20 18:18:32.63 UTC
|
2020-02-20 18:18:32.63 UTC
| null | 814,702 | null | 324,900 | null | 1 | 51 |
java|hibernate|collections|nullpointerexception|return-value
| 51,320 |
<p>The reason is not to force null checks in client code, in consistency with <a href="http://www.amazon.co.uk/Effective-Java-Second-Joshua-Bloch/dp/0321356683" rel="noreferrer">Effective Java 2nd Edition</a>, Item 43: <strong>Return empty arrays or collections, not nulls</strong>.</p>
<p>This makes the client code simpler and less error-prone (and most likely the method implementation as well).</p>
<blockquote>
<p>The null-return idiom is likely a holdover from the C programming language, in
which array lengths are returned separately from actual arrays. In C, there is no
advantage to allocating an array if zero is returned as the length.</p>
</blockquote>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.