qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
170,061
|
<pre><code> <DataTemplate x:Key="Genre_DataTemplate">
<RadioButton GroupName="One" Content="{Binding...
</DataTemplate>
</code></pre>
<p>Above code is the ItemTemplate of my ItemsControl, I want all the Radiobuttons instantiated should behave as if it is in a group, I know the reason because the generated RadioButtons are not adjacent in the visualtree.</p>
<p>Any solution or workaround to group them together?. GroupName property also doesn't have any effect here. </p>
<p>[Update] I am trying this in Silverlight</p>
|
[
{
"answer_id": 170643,
"author": "ligaz",
"author_id": 6409,
"author_profile": "https://Stackoverflow.com/users/6409",
"pm_score": 2,
"selected": false,
"text": "<Page xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n <Grid>\n <Grid.Resources>\n <XmlDataProvider x:Key=\"flickrdata\" Source=\"http://api.flickr.com/services/feeds/photos_public.gne?tags=flower&lang=en-us&format=rss_200\">\n <XmlDataProvider.XmlNamespaceManager>\n <XmlNamespaceMappingCollection>\n <XmlNamespaceMapping Prefix=\"media\" Uri=\"http://search.yahoo.com/mrss/\"/>\n </XmlNamespaceMappingCollection>\n </XmlDataProvider.XmlNamespaceManager>\n </XmlDataProvider>\n <DataTemplate x:Key=\"itemTemplate\">\n <RadioButton GroupName=\"One\">\n <Image Width=\"75\" Height=\"75\" Source=\"{Binding Mode=OneWay, XPath=media:thumbnail/@url}\"/>\n </RadioButton>\n </DataTemplate>\n <ControlTemplate x:Key=\"controlTemplate\" TargetType=\"{x:Type ItemsControl}\">\n <WrapPanel IsItemsHost=\"True\" Orientation=\"Horizontal\"/>\n </ControlTemplate>\n </Grid.Resources>\n <ItemsControl\n Width=\"375\"\n ItemsSource=\"{Binding Mode=Default, Source={StaticResource flickrdata}, XPath=/rss/channel/item}\"\n ItemTemplate=\"{StaticResource itemTemplate}\"\n Template=\"{StaticResource controlTemplate}\">\n </ItemsControl>\n </Grid>\n\n</Page>\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8091/"
] |
170,064
|
<p>SQL Server profiler is great for profiling SQL Server performance for web apps. However, when I'm testing my webapp I'd like a summary of database hits/duration <strong>per page</strong>.</p>
<p>Does anybody know of any utilities for giving you this kind of information?</p>
|
[
{
"answer_id": 170643,
"author": "ligaz",
"author_id": 6409,
"author_profile": "https://Stackoverflow.com/users/6409",
"pm_score": 2,
"selected": false,
"text": "<Page xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n <Grid>\n <Grid.Resources>\n <XmlDataProvider x:Key=\"flickrdata\" Source=\"http://api.flickr.com/services/feeds/photos_public.gne?tags=flower&lang=en-us&format=rss_200\">\n <XmlDataProvider.XmlNamespaceManager>\n <XmlNamespaceMappingCollection>\n <XmlNamespaceMapping Prefix=\"media\" Uri=\"http://search.yahoo.com/mrss/\"/>\n </XmlNamespaceMappingCollection>\n </XmlDataProvider.XmlNamespaceManager>\n </XmlDataProvider>\n <DataTemplate x:Key=\"itemTemplate\">\n <RadioButton GroupName=\"One\">\n <Image Width=\"75\" Height=\"75\" Source=\"{Binding Mode=OneWay, XPath=media:thumbnail/@url}\"/>\n </RadioButton>\n </DataTemplate>\n <ControlTemplate x:Key=\"controlTemplate\" TargetType=\"{x:Type ItemsControl}\">\n <WrapPanel IsItemsHost=\"True\" Orientation=\"Horizontal\"/>\n </ControlTemplate>\n </Grid.Resources>\n <ItemsControl\n Width=\"375\"\n ItemsSource=\"{Binding Mode=Default, Source={StaticResource flickrdata}, XPath=/rss/channel/item}\"\n ItemTemplate=\"{StaticResource itemTemplate}\"\n Template=\"{StaticResource controlTemplate}\">\n </ItemsControl>\n </Grid>\n\n</Page>\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25088/"
] |
170,070
|
<p>What criteria should I use to decide whether I write VBA code like this:</p>
<pre><code>Set xmlDocument = New MSXML2.DOMDocument
</code></pre>
<p>or like this:</p>
<pre><code>Set xmlDocument = CreateObject("MSXML2.DOMDocument")
</code></pre>
<p>?</p>
|
[
{
"answer_id": 170084,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 5,
"selected": true,
"text": "Dim xmlDocument as MSXML2.DOMDocument\nSet xmlDocument = CreateObject(\"MSXML2.DOMDocument\")\n Dim xmlDocument as MSXML2.DOMDocument\nSet xmlDocument = New MSXML2.DOMDocument\n Dim xmlDocument as Object\nSet xmlDocument = CreateObject(\"MSXML2.DOMDocument\")\n"
},
{
"answer_id": 11130207,
"author": "JimmyPena",
"author_id": 190829,
"author_profile": "https://Stackoverflow.com/users/190829",
"pm_score": 3,
"selected": false,
"text": "Set xmlDocument = CreateObject(\"MSXML2.DOMDocument\") CreateObject Dim xmlDocument As MSXML2.DOMDocument\nSet xmlDocument = CreateObject(\"MSXML2.DOMDocument\") As Object Dim xmlDocument As MSXML2.DOMDocument\nSet xmlDocument = New MSXML2.DOMDocument"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4023/"
] |
170,078
|
<p>How do I set a variable to the result of select query without using a stored procedure? </p>
<hr>
<p>I want to do something like:
OOdate DATETIME</p>
<pre><code>SET OOdate = Select OO.Date
FROM OLAP.OutageHours as OO
WHERE OO.OutageID = 1
</code></pre>
<p>Then I want to use OOdate in this query:</p>
<pre><code>SELECT COUNT(FF.HALID) from Outages.FaultsInOutages as OFIO
INNER join Faults.Faults as FF ON FF.HALID = OFIO.HALID
WHERE CONVERT(VARCHAR(10),OO.Date,126) = CONVERT(VARCHAR(10),FF.FaultDate,126))
AND
OFIO.OutageID = 1
</code></pre>
|
[
{
"answer_id": 170082,
"author": "Luk",
"author_id": 5789,
"author_profile": "https://Stackoverflow.com/users/5789",
"pm_score": 1,
"selected": false,
"text": "(SELECT xxx in (SELECT yyy...)"
},
{
"answer_id": 170085,
"author": "JPrescottSanders",
"author_id": 19444,
"author_profile": "https://Stackoverflow.com/users/19444",
"pm_score": 2,
"selected": false,
"text": "declare @foo as nvarchar(25)\n\nselect @foo = 'bar'\n\nselect @foo\n"
},
{
"answer_id": 170090,
"author": "rslite",
"author_id": 15682,
"author_profile": "https://Stackoverflow.com/users/15682",
"pm_score": 6,
"selected": false,
"text": "SET @cnt = (SELECT COUNT(*) FROM User)\n SELECT @cnt = (COUNT(*) FROM User)\n DECLARE @OOdate DATETIME\n\nSET @OOdate = Select OO.Date from OLAP.OutageHours as OO where OO.OutageID = 1\n\nSelect COUNT(FF.HALID) \nfrom Outages.FaultsInOutages as OFIO \ninner join Faults.Faults as FF \n ON FF.HALID = OFIO.HALID \nWHERE @OODate = FF.FaultDate\n AND OFIO.OutageID = 1\n"
},
{
"answer_id": 170858,
"author": "Pittsburgh DBA",
"author_id": 10224,
"author_profile": "https://Stackoverflow.com/users/10224",
"pm_score": 2,
"selected": false,
"text": "CONVERT(...) = CONVERT(...)\n DECLARE @ooDate datetime\nSELECT @ooDate = OO.Date FROM OLAP.OutageHours AS OO where OO.OutageID = 1\n\nSELECT \n COUNT(FF.HALID)\nFROM\n Outages.FaultsInOutages AS OFIO \n INNER JOIN Faults.Faults as FF ON \n FF.HALID = OFIO.HALID \nWHERE\n FF.FaultDate >= @ooDate AND\n FF.FaultDate < DATEADD(day, 1, @ooDate) AND\n OFIO.OutageID = 1\n SELECT \n COUNT(FF.HALID)\nFROM\n Outages.FaultsInOutages AS OFIO \n INNER JOIN Faults.Faults as FF ON \n FF.HALID = OFIO.HALID \nWHERE\n CONVERT(varchar(10), FF.FaultDate, 126) = (SELECT CONVERT(varchar(10), OO.Date, 126) FROM OLAP.OutageHours AS OO where OO.OutageID = 1) AND\n OFIO.OutageID = 1\n"
},
{
"answer_id": 7663964,
"author": "Allisson Pereira",
"author_id": 973329,
"author_profile": "https://Stackoverflow.com/users/973329",
"pm_score": 4,
"selected": false,
"text": "\nuse Master\ngo\nDECLARE @MyVar bigint\nSET @myvar = (SELECT count(*) FROM spt_values);\nSELECT @myvar\n"
},
{
"answer_id": 13379691,
"author": "Siddhesh Bondre",
"author_id": 1823164,
"author_profile": "https://Stackoverflow.com/users/1823164",
"pm_score": 2,
"selected": false,
"text": "DECLARE @Result INT;\nSELECT @Result = COUNT(*)\nFROM TableName\nWHERE Condition\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170078",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21004/"
] |
170,097
|
<p>I've gone to <a href="http://sourceforge.net/project/showfiles.php?group_id=2435" rel="noreferrer">http://sourceforge.net/project/showfiles.php?group_id=2435</a>, downloaded the Automated MinGW Installer for MinGW 5.1.4 and at the same time the GNU Source-Level Debugger Release Candidate: GDB 6.8-3. I've then installed MinGW base tools into C:\MinGW. No problem so far.</p>
<p>However when I come to install the gdb debugger it has a lot of files and folders with the same names as some already installed but the files are different to those already installed. e.g C:\MinGW\include\bfd.h is 171 KB but gdb-6.8-mingw-3\include\bfd.h is 184 KB.</p>
<p>How do I add gdb to MinGW without breaking what's already installed?</p>
|
[
{
"answer_id": 25628827,
"author": "John",
"author_id": 532795,
"author_profile": "https://Stackoverflow.com/users/532795",
"pm_score": 6,
"selected": false,
"text": "mingw-get.exe install gdb\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25093/"
] |
170,140
|
<p>How do I add the Swedish interactive user, </p>
<pre><code>NT INSTANS\INTERAKTIV
</code></pre>
<p>or the English interactive user, </p>
<pre><code>NT AUTHORITY\INTERACTIVE
</code></pre>
<p>or any other localised user group with <strong>write</strong> permissions to a program folder's ACL?</p>
<p>Is this question actually "How do I use <strong>secureObject</strong>"? I cannot use the <strong>LockPermissions Table</strong> because I undestand inheritance is removed. <strong>secureObject</strong> permissions seem to require <strong>CreateDirectory</strong> rather than <strong>Directory</strong>... </p>
|
[
{
"answer_id": 170206,
"author": "Mihai Limbășan",
"author_id": 14444,
"author_profile": "https://Stackoverflow.com/users/14444",
"pm_score": 2,
"selected": false,
"text": "S-1-5-4"
},
{
"answer_id": 170759,
"author": "Paul Lalonde",
"author_id": 5782,
"author_profile": "https://Stackoverflow.com/users/5782",
"pm_score": 4,
"selected": true,
"text": "WIX_ACCOUNT_NETWORKSERVICE NT AUTHORITY\\INTERACTIVE <Directory ...>\n <Component ...>\n <CreateFolder>\n <PermissionEx User=\"[SID_INTERACTIVE]\" .../>\n </CreateFolder>\n </Component ...>\n</Directory ...>\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25092/"
] |
170,144
|
<p>Newbie WiX question: How do I<br>
1. Copy a single-use shell script to temp along with the installer<br>
e.g. </p>
<pre><code> <Binary Id='permissions.cmd' src='permissions.cmd'/>
</code></pre>
<p>2. Find and run that script at the end of the install.<br>
e.g. </p>
<pre><code><CustomAction Id='SetFolderPermissions' BinaryKey='permissions.cmd'
ExeCommand='permissions.cmd' Return='ignore'/>
<InstallExecuteSequence>
<Custom Action="SetFolderPermissions" Sequence='1'/>
</InstallExecuteSequence>
</code></pre>
<p>I think I have at least three problems: </p>
<ul>
<li>I can't find <strong>permissions.cmd</strong> to run it - do I need <strong>[TEMPDIR]permissions.cmd</strong> or something? </li>
<li>My <strong>Sequence</strong> comes too soon, before the program is installed.</li>
<li>I need <strong>cmd /c permissions.cmd</strong> somewhere in here, probably near <strong>ExeCommand</strong>?</li>
</ul>
<p>In this example <strong>permissions.cmd</strong> uses <strong>cacls.exe</strong> to add the interactive user with write permissions to the <strong>%ProgramFiles%\Vendor</strong> ACL. I could also use <strong>secureObject</strong> - that question is <strong><a href="https://stackoverflow.com/questions/170140/how-do-i-add-the-interactive-user-to-a-directory-in-a-localized-windows">"How do I add the interactive user to a directory in a localized Windows"?</a></strong> </p>
|
[
{
"answer_id": 170417,
"author": "CheGueVerra",
"author_id": 17787,
"author_profile": "https://Stackoverflow.com/users/17787",
"pm_score": 3,
"selected": false,
"text": "<CustomAction Id=\"CallCmd\" Value=\"[SystemFolder]cmd.exe\" />\n<CustomAction Id=\"RunCmd\" ExeCommand=\"/c permission.cmd\" />\n<InstallExecuteSequence>\n <Custom Action=\"CallCmd\" After=\"InstallInitialize\" />\n <Custom Action=\"RunCmd\" After=\"CallCmd\" />\n</InstallExecuteSequence>\n"
},
{
"answer_id": 199369,
"author": "Pavel Chuchuva",
"author_id": 14131,
"author_profile": "https://Stackoverflow.com/users/14131",
"pm_score": 2,
"selected": false,
"text": "<CreateFolder>\n <Permission User='INTERACTIVE' GenericRead='yes' GenericWrite='yes' \n GenericExecute='yes' Delete='yes' DeleteChild='yes' />\n <Permission User='Administrators' GenericAll='yes' />\n</CreateFolder>\n"
},
{
"answer_id": 201285,
"author": "nray",
"author_id": 25092,
"author_profile": "https://Stackoverflow.com/users/25092",
"pm_score": 2,
"selected": false,
"text": "<Wix xmlns=\"http://schemas.microsoft.com/wix/2003/01/wi\">\n<Fragment>\n <DirectoryRef Id=\"TARGETDIR\">\n <Directory Id='ProgramFilesFolder' Name='PFiles'>\n <Directory Id=\"directory0\" Name=\"MyApp\" LongName=\"My Application\">\n <Component Id=\"component0\" DiskId=\"1\" Guid=\"AABBCCDD-EEFF-1122-3344-556677889900\">\n\n <CreateFolder>\n <Permission User='INTERACTIVE' \n GenericRead='yes' \n GenericWrite='yes' \n GenericExecute='yes' \n Delete='yes' \n DeleteChild='yes' />\n <Permission User='Administrators' GenericAll='yes' />\n </CreateFolder>\n\n <File Id=\"file0\" Name=\"myapp.exe\" Vital=\"yes\" Source=\"myapp.exe\">\n <Shortcut Id=\"StartMenuIcon\" Directory=\"ProgramMenuFolder\" Name=\"MyApp\" LongName=\"My Application\" />\n </File>\n </Component>\n <Directory Id=\"directory1\" Name=\"SubDir\" LongName=\"Sub Directory 1\">\n <Component Id=\"component1\" DiskId=\"1\" Guid=\"A9B4D6FD-B67A-40b1-B518-A39F1D145FF8\">\n etc...\n etc...\n etc...\n </Component>\n </Directory>\n </Directory>\n </DirectoryRef>\n</Fragment>\n"
},
{
"answer_id": 228777,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "Execute=\"Deferred\" <Custom Action=\"CallCmd\" Execute=\"Deferred\" Before=\"InstallFinalize\" />\n"
},
{
"answer_id": 417937,
"author": "user14402",
"author_id": 14402,
"author_profile": "https://Stackoverflow.com/users/14402",
"pm_score": 3,
"selected": false,
"text": "<Directory Id=\"TARGETDIR\" Name=\"SourceDir\">\n <Directory Id=\"ProgramFilesFolder\" Name=\"PFiles\">\n <Directory Id=\"BaseDir\" Name=\"MyCo\">\n <Directory Id=\"INSTALLDIR\" Name=\"MyApp\" LongName=\"MyProd\">\n\n <!-- Create the folder, so that ACLs can be set to NetworkService -->\n <Component Id=\"TheDestFolder\" Guid=\"{333374B0-FFFF-4F9F-8CB1-D9737F658D51}\"\n DiskId=\"1\" KeyPath=\"yes\">\n <CreateFolder Directory=\"INSTALLDIR\">\n <Permission User=\"NetworkService\"\n Extended=\"yes\"\n Delete=\"yes\"\n GenericAll=\"yes\">\n </Permission>\n </CreateFolder>\n </Component>\n\n </Directory>\n </Directory>\n </Directory>\n</Directory>\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25092/"
] |
170,152
|
<p>I know that in the end it, can't be done.</p>
<p>But, what are the options to: </p>
<p> a) limit the options for persons to create multiple accounts,<br>
b) increase the chance of detecting multiple accounts / person </p>
<p>for a blog-like web service?<br>
(people can sign up for their own blog)</p>
<p><strong>Update:</strong><br>
I think the 'limit the options' has been answered nicely. (there is no reliable method, but we can raise the bar)<br>
However, I would still like to know what other options there are to detect multiple accounts?</p>
|
[
{
"answer_id": 170209,
"author": "joelhardi",
"author_id": 11438,
"author_profile": "https://Stackoverflow.com/users/11438",
"pm_score": 6,
"selected": true,
"text": "<a href>"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170152",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22674/"
] |
170,168
|
<p>I am looking for a template engine to use client side. I have been trying a few like jsRepeater and jQuery Templates. While they seem to work OK in FireFox they all seem to break down in IE7 when it comes down to rendering HTML tables.</p>
<p>I also took a look at MicrosoftAjaxTemplates.js (from <a href="http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16766" rel="noreferrer">http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16766</a>) but turns out that has the same problem.</p>
<p>Any advice on other templating engines to use?</p>
|
[
{
"answer_id": 1243366,
"author": "Tomasz Mazur",
"author_id": 152309,
"author_profile": "https://Stackoverflow.com/users/152309",
"pm_score": 4,
"selected": false,
"text": "data = {\n user: {\n login: \"tomek\",\n first_name: \"Thomas\",\n last_name: \"Mazur\",\n account: {\n status: \"active\",\n expires_at: \"2009-12-31\"\n }\n }\n}\n nano(\"<p>Hello {user.first_name} {user.last_name}! Your account is <strong>{user.account.status}</strong></p>\", data)\n <p>Hello Thomas Mazur! Your account is <strong>active</strong></p>\n"
},
{
"answer_id": 8057706,
"author": "molokoloco",
"author_id": 174449,
"author_profile": "https://Stackoverflow.com/users/174449",
"pm_score": 2,
"selected": false,
"text": "// LighTest TPL\n$.tpl = function(tpl, val) {\n for (var p in val)\n tpl = tpl.replace(new RegExp('({'+p+'})', 'g'), val[p] || '');\n return tpl;\n};\n// Routine...\nvar dataObj = [{id:1, title:'toto'}, {id:2, title:'tutu'}],\n tplHtml = '<div>N°{id} - {title}</div>',\n newHtml = '';\n$.each(dataObj, function(i, val) {\n newHtml += $.tpl(tplHtml, val);\n});\nvar $newHtml = $(newHtml).appendTo('body');\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19676/"
] |
170,180
|
<p>I want to loop over the elements of an HTML form, and store the values of the <input> fields in an object. The following code doesn't work, though:</p>
<pre><code>function config() {
$("#frmMain").children().map(function() {
var child = $("this");
if (child.is(":checkbox"))
this[child.attr("name")] = child.attr("checked");
if (child.is(":radio, checked"))
this[child.attr("name")] = child.val();
if (child.is(":text"))
this[child.attr("name")] = child.val();
return null;
});
</code></pre>
<p>Neither does the following (inspired by jobscry's answer):</p>
<pre><code>function config() {
$("#frmMain").children().each(function() {
var child = $("this");
alert(child.length);
if (child.is(":checkbox")) {
this[child.attr("name")] = child.attr("checked");
}
if (child.is(":radio, checked"))
this[child.attr("name")] = child.val();
if (child.is(":text"))
this[child.attr("name")] = child.val();
});
}
</code></pre>
<p>The alert always shows that <code>child.length == 0</code>. Manually selecting the elements works:</p>
<pre>
>>> $("#frmMain").children()
Object length=42
>>> $("#frmMain").children().filter(":checkbox")
Object length=3
</pre>
<p>Any hints on how to do the loop correctly?</p>
|
[
{
"answer_id": 170197,
"author": "imjoevasquez",
"author_id": 24630,
"author_profile": "https://Stackoverflow.com/users/24630",
"pm_score": 5,
"selected": false,
"text": "$('#formId').children().each(\n function(){\n //access to form element via $(this)\n }\n);\n"
},
{
"answer_id": 170257,
"author": "imjoevasquez",
"author_id": 24630,
"author_profile": "https://Stackoverflow.com/users/24630",
"pm_score": 6,
"selected": true,
"text": "var child = $(\"this\");\n var child = $(this);\n"
},
{
"answer_id": 170269,
"author": "hugoware",
"author_id": 17091,
"author_profile": "https://Stackoverflow.com/users/17091",
"pm_score": 4,
"selected": false,
"text": "$(\"#formID\").serialize()\n $.each($(\"input, select, textarea\"), function(i,v) {\n var theTag = v.tagName;\n var theElement = $(v);\n var theValue = theElement.val();\n});\n"
},
{
"answer_id": 170771,
"author": "SpoonMeiser",
"author_id": 1577190,
"author_profile": "https://Stackoverflow.com/users/1577190",
"pm_score": 2,
"selected": false,
"text": "var my_form = $('#form-id');\nvar data = {};\n\n$('input:not([type=checkbox]), input[type=checkbox]:selected, select, textarea', my_form).each(\n function() {\n var name = $(this).attr('name');\n var val = $(this).val();\n\n if (!data.hasOwnProperty(name)) {\n data[name] = new Array;\n }\n\n data[name].push(val);\n }\n);\n data"
},
{
"answer_id": 967093,
"author": "Peter",
"author_id": 97282,
"author_profile": "https://Stackoverflow.com/users/97282",
"pm_score": 0,
"selected": false,
"text": "$('#formId').children().each( \n function(){\n //access to form element via $(this)\n }\n);\n"
},
{
"answer_id": 14351766,
"author": "bicycle",
"author_id": 1160952,
"author_profile": "https://Stackoverflow.com/users/1160952",
"pm_score": 0,
"selected": false,
"text": "$(\"#formID input[type=text]\").each(function() {\nalert($(this).val());\n});\n"
},
{
"answer_id": 15646509,
"author": "Scottzozer",
"author_id": 1532793,
"author_profile": "https://Stackoverflow.com/users/1532793",
"pm_score": -1,
"selected": false,
"text": "$('form[name=formName]').find('input, textarea, select').each(function() {\n alert($(this).attr('name'));\n});\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25097/"
] |
170,186
|
<p>I was previously taught today how to set parameters in a SQL query in .NET in this answer (<a href="https://stackoverflow.com/questions/169359/improving-code-readability-for-sql-commands#169369">click</a>).</p>
<p>Using parameters with values are fine, but when I try to set a field in the database to null I'm unsuccessful. Either the method thinks I am not setting a valid parameter or not specifying a parameter.</p>
<p>e.g.</p>
<pre><code>Dim dc As New SqlCommand("UPDATE Activities SET [Limit] = @Limit WHERE [Activity] = @Activity", cn)
If actLimit.ToLower() = "unlimited" Then
' It's not nulling :(
dc.Parameters.Add(New SqlParameter("Limit", Nothing))
Else
dc.Parameters.Add(New SqlParameter("Limit", ProtectAgainstXSS(actLimit)))
End If
</code></pre>
<p>Is there something I'm missing? Am I doing it wrong?</p>
|
[
{
"answer_id": 170193,
"author": "Sklivvz",
"author_id": 7028,
"author_profile": "https://Stackoverflow.com/users/7028",
"pm_score": 2,
"selected": false,
"text": "DbNull.Value"
},
{
"answer_id": 170205,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 7,
"selected": true,
"text": " foreach (IDataParameter param in cmd.Parameters)\n {\n if (param.Value == null) param.Value = DBNull.Value;\n }\n"
},
{
"answer_id": 15796720,
"author": "Emile Cormier",
"author_id": 245265,
"author_profile": "https://Stackoverflow.com/users/245265",
"pm_score": 3,
"selected": false,
"text": "SqlParameterCollection null DBNull public static class ExtensionMethods\n{\n public static SqlParameter AddWithNullable<T>(this SqlParameterCollection parms,\n string parameterName, T? nullable) where T : struct\n {\n if (nullable.HasValue)\n return parms.AddWithValue(parameterName, nullable.Value);\n else\n return parms.AddWithValue(parameterName, DBNull.Value);\n }\n}\n string? optionalName = \"Bozo\";\ncmd.Parameters.AddWithNullable(\"@Name\", optionalName);\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20900/"
] |
170,192
|
<p>What is the minimal conventional directory structure for a Java web app? What do I need to put in a <code>build.xml</code> file to get ant to build it and make a WAR file?</p>
<p>My goal is to deploy a Wicket app to Tomcat without using an IDE. I want to do it with only ant and my favourite text editor.</p>
|
[
{
"answer_id": 170247,
"author": "Leigh Caldwell",
"author_id": 3267,
"author_profile": "https://Stackoverflow.com/users/3267",
"pm_score": 2,
"selected": false,
"text": "web/\nweb/WEB-INF/ (sometimes we use a conf/ dir at the top level but this is minimal)\nsrc/\nlib/\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
170,203
|
<p>This discussion started <a href="https://stackoverflow.com/questions/155084/flash-rendering-optimisation-tips-and-tricks">over here</a> but I thought it would be nice to have a definitive answer...</p>
<p>So let's say you have MovieClip on the Stage (or a UIComponent for the Flex audience) - what do you have to do to not make it so that the user can't see the object but also so that the AVM2 doesn't even factor it in when rendering the stage for the user?</p>
<p>I always thought the answer was to set <code>visible = false</code> but there is an argument out there that the object has to placed outside the boundaries of the Stage (like <code>x = 2000</code> which seems like a hack IMO). Does anyone know the real answer? </p>
<p><strong>EDIT:</strong> I imagine the need for having flash not render the item would be to help performance.</p>
|
[
{
"answer_id": 170629,
"author": "hasseg",
"author_id": 4111,
"author_profile": "https://Stackoverflow.com/users/4111",
"pm_score": 1,
"selected": false,
"text": "UIComponent"
},
{
"answer_id": 177317,
"author": "mikechambers",
"author_id": 10232,
"author_profile": "https://Stackoverflow.com/users/10232",
"pm_score": 2,
"selected": false,
"text": "var s:MovieClip = new MovieClip();\ns.lineStyle(1, 0xFFFFFF);\naddChild(s);//shows in moviea \nremoveChild(s);//removes from display list, but you still have a reference to it\n"
},
{
"answer_id": 177452,
"author": "fenomas",
"author_id": 10651,
"author_profile": "https://Stackoverflow.com/users/10651",
"pm_score": 2,
"selected": false,
"text": "visible = false; removeChild()"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3435/"
] |
170,223
|
<p>Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups. However, when inserting one must always check if the first index already exists in the hash. For example:</p>
<pre><code>h = Hash.new
h['x'] = Hash.new if not h.key?('x')
h['x']['y'] = value_to_insert
</code></pre>
<p>It would be preferable to do the following where the new Hash is created automatically:</p>
<pre><code>h = Hash.new
h['x']['y'] = value_to_insert
</code></pre>
<p>Similarly, when looking up a value where the first index doesn't already exist, it would be preferable if nil is returned rather than receiving an undefined method for '[]' error. </p>
<pre><code>looked_up_value = h['w']['z']
</code></pre>
<p>One could create a Hash wrapper class that has this behavior, but is there an existing a Ruby idiom for accomplishing this task?</p>
|
[
{
"answer_id": 170240,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 7,
"selected": true,
"text": "Hash.new h = Hash.new { |h, k| h[k] = Hash.new }\n hash = Hash.new(&(p = lambda{|h, k| h[k] = Hash.new(&p)}))\n"
},
{
"answer_id": 739520,
"author": "tadman",
"author_id": 87189,
"author_profile": "https://Stackoverflow.com/users/87189",
"pm_score": 2,
"selected": false,
"text": "((h ||= { })['w'] ||= { })['z']\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3533/"
] |
170,267
|
<p>I am trying to set myself up on a mac to learn Ruby on Rails, however I seem to be having some problems. If I try to run commands such as ./script/server, i get this: </p>
<blockquote>
<p>Rails requires RubyGems >= 0.9.4 (you have 0.9.2). Please <code>gem update --system</code> and try again.</p>
</blockquote>
<p>When I run "gem update.." I get this:</p>
<blockquote>
<p>Updating RubyGems...
Attempting remote update of rubygems-update
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /opt/local/lib/ruby/gems/1.8/cache/rubygems-update-1.3.0.gem</p>
</blockquote>
|
[
{
"answer_id": 45538928,
"author": "Cœur",
"author_id": 1033581,
"author_profile": "https://Stackoverflow.com/users/1033581",
"pm_score": 0,
"selected": false,
"text": "/usr/bin /usr/local/bin sudo gem update -n /usr/local/bin --system\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25106/"
] |
170,272
|
<p>I have a class like the following:</p>
<pre><code>public class DropDownControl<T, Key, Value> : BaseControl
where Key: IComparable
{
private IEnumerable<T> mEnumerator;
private Func<T, Key> mGetKey;
private Func<T, Value> mGetValue;
private Func<Key, bool> mIsKeyInCollection;
public DropDownControl(string name, IEnumerable<T> enumerator, Func<T, Key> getKey, Func<T, Value> getValue, Func<Key, bool> isKeyInCollection)
: base(name)
{
mEnumerator = enumerator;
mGetKey = getKey;
mGetValue = getValue;
mIsKeyInCollection = isKeyInCollection;
}
</code></pre>
<p>And I want to add a convenience function for Dictionaries (because they support all operations efficiently on their own).</p>
<p>But the problem is that such a constructor would only specify Key and Value but not T directly, but T is just KeyValuePair. Is there a way to tell the compiler for this constructor T is KeyValuePair, like:</p>
<pre><code>public DropDownControl<KeyValuePair<Key, Value>>(string name, IDictionary<Key, Value> dict) { ... }
</code></pre>
<p>Currently I use a static Create function as workaround, but I would like a direct constructor better.</p>
<pre><code>public static DropDownControl<KeyValuePair<DKey, DValue>, DKey, DValue> Create<DKey, DValue>(string name, IDictionary<DKey, DValue> dictionary)
where DKey: IComparable
{
return new DropDownControl<KeyValuePair<DKey, DValue>, DKey, DValue>(name, dictionary, kvp => kvp.Key, kvp => kvp.Value, key => dictionary.ContainsKey(key));
}
</code></pre>
|
[
{
"answer_id": 170279,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": true,
"text": "var control = DropDownControl.Create(name, dictionary);\n public static class DropDownControl\n{\n public static DropDownControl<KeyValuePair<TKey,TValue>, TKey, TValue>\n Create<TKey,TValue>(IDictionary<TKey, TValue> value, string name)\n where TKey : IComparable\n {\n return new DropDownControl<KeyValuePair<TKey, TValue>, TKey, TValue>\n (name, value, pair => pair.Key, pair => pair.Value,\n key => value.ContainsKey(key)\n );\n }\n}\n public class DropDownControl<TKey, TValue> :\n DropDownControl<KeyValuePair<TKey, TValue>, TKey, TValue>\n where TKey : IComparable\n{\n public DropDownControl(IDictionary<TKey, TValue> lookup, string name)\n : base(name, lookup, pair => pair.Key, pair => pair.Value,\n key => lookup.ContainsKey(key)) { }\n}\n"
},
{
"answer_id": 25409304,
"author": "supercat",
"author_id": 363751,
"author_profile": "https://Stackoverflow.com/users/363751",
"pm_score": 0,
"selected": false,
"text": "T KeyValuePair<TKey,TValue> T DropDownControl<TKey, TValue> : BaseControl Helper Helper HeldAs<TPair> DropDownControl<TKey,TValue> DropDownControl<TKey,TValue>.HeldAs<KeyValuePair<TKey,TValue>> Helper DropDownControl<TKey,TValue> DropDownControl<TKey,TValue>.HeldAs<actualStorageType> actualStorageType DropDownControl<TKey,TValue> this DropDownControl<TKey,TValue>.HeldAs<TStorage> Helper Helper this Helper"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21566/"
] |
170,294
|
<p>I'd like to be able to switch the sound output source in Mac OS X without any GUI interaction.</p>
<p>There are tools to do control the sound output, such as <a href="http://rogueamoeba.com/freebies/" rel="noreferrer">SoundSource</a> and an <a href="http://www.macosxhints.com/article.php?story=20050614171126634" rel="noreferrer">applescript to open the preferences dialog</a>.</p>
<p>What I am looking for is something that switches the preference instantly, like <a href="http://rogueamoeba.com/freebies/" rel="noreferrer">SoundSource</a> but it has to be scriptable. The goal is to switch between my digital and analog output with one keystroke. I have a <a href="http://www.blacktree.com/?quicksilver" rel="noreferrer">helper application</a> that will launch a program or applescript on one keypress. All I need now is the applescript or application that switches the sound source quickly without any user interaction.</p>
<p>I'm willing to write some Objective-C if that is what it takes, but I'm pretty much a newbie at Cocoa development.</p>
<p>Do you have a one-click solution or can point me to a good tutorial on controlling sound system preferences from a Cocoa App or command line?</p>
<p><strong>EDIT</strong>: I created a command-line application to do exactly this. You may download it at <a href="http://code.google.com/p/switchaudio-osx/downloads" rel="noreferrer">http://code.google.com/p/switchaudio-osx/downloads</a>. Source code is available on the project site as well.</p>
|
[
{
"answer_id": 170886,
"author": "Jens Ayton",
"author_id": 6443,
"author_profile": "https://Stackoverflow.com/users/6443",
"pm_score": 4,
"selected": true,
"text": "kAudioHardwarePropertyDefaultOutputDevice kAudioHardwarePropertyDefaultSystemOutputDevice AudioSystemObject AudioHardwareSetProperty()"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13850/"
] |
170,297
|
<p>Converting my current code project to TDD, I've noticed something.</p>
<pre><code>class Foo {
public event EventHandler Test;
public void SomeFunction() {
//snip...
Test(this, new EventArgs());
}
}
</code></pre>
<p>There are two dangers I can see when testing this code and relying on a code coverage tool to determine if you have enough tests.</p>
<ul>
<li>You should be testing if the <code>Test</code> event gets fired. Code coverage tools alone won't tell you if you forget this.</li>
<li>I'll get to the other in a second.</li>
</ul>
<p>To this end, I added an event handler to my startup function so that it looked like this:</p>
<pre><code>Foo test;
int eventCount;
[Startup] public void Init() {
test = new Foo();
// snip...
eventCount = 0;
test.Test += MyHandler;
}
void MyHandler(object sender, EventArgs e) { eventCount++; }
</code></pre>
<p>Now I can simply check <code>eventCount</code> to see how many times my event was called, if it was called. Pretty neat. Only now we've let through an insidious little bug that will never be caught by any test: namely, <code>SomeFunction()</code> doesn't check if the event has any handlers before trying to call it. This will cause a null dereference, which will never be caught by any of our tests because they all have an event handler attached by default. But again, a code coverage tool will still report full coverage.</p>
<p>This is just my "real world example" at hand, but it occurs to me that plenty more of these sorts of errors can slip through, even with 100% 'coverage' of your code, this still doesn't translate to 100% tested. Should we take the coverage reported by such a tool with a grain of salt when writing tests? Are there other sorts of tools that would catch these holes?</p>
|
[
{
"answer_id": 170396,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 2,
"selected": false,
"text": "void bar(Foo f) {\n if (f.isGreen()) accountForGreenness();\n if (f.isBig()) accountForBigness();\n finishBar(f);\n}\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170297",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
170,328
|
<p>I would like to execute a stored procedure within a stored procedure, e.g. </p>
<pre><code>EXEC SP1
BEGIN
EXEC SP2
END
</code></pre>
<p>But I only want <code>SP1</code> to finish after <code>SP2</code> has finished running so I need to find a way for <code>SP1</code> to wait for <code>SP2</code> to finish before <code>SP1</code> ends.</p>
<p><code>SP2</code> is being executed as part of <code>SP1</code> so I have something like:</p>
<pre><code>CREATE PROCEDURE SP1
AS
BEGIN
EXECUTE SP2
END
</code></pre>
|
[
{
"answer_id": 170333,
"author": "PeteT",
"author_id": 16989,
"author_profile": "https://Stackoverflow.com/users/16989",
"pm_score": 2,
"selected": false,
"text": "exec dbo.sp1\nexec dbo.sp2\n"
},
{
"answer_id": 170359,
"author": "mattruma",
"author_id": 1768,
"author_profile": "https://Stackoverflow.com/users/1768",
"pm_score": 4,
"selected": false,
"text": "ALTER PROCEDURE [dbo].[AssetLibrary_AssetDelete]\n(\n @AssetID AS uniqueidentifier\n)\nAS\n\nSET NOCOUNT ON\n\nSET TRANSACTION ISOLATION LEVEL READ COMMITTED\n\nEXEC AssetLibrary_AssetDeleteAttributes @AssetID\nEXEC AssetLibrary_AssetDeleteComponents @AssetID\nEXEC AssetLibrary_AssetDeleteAgreements @AssetID\nEXEC AssetLibrary_AssetDeleteMaintenance @AssetID\n\nDELETE FROM\n AssetLibrary_Asset\nWHERE\n AssetLibrary_Asset.AssetID = @AssetID\n\nRETURN (@@ERROR)\n"
},
{
"answer_id": 170361,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 5,
"selected": false,
"text": "CREATE PROCEDURE SP1 AS\n EXEC SP2\n PRINT 'Done'\n"
},
{
"answer_id": 12914162,
"author": "Jom George",
"author_id": 1053355,
"author_profile": "https://Stackoverflow.com/users/1053355",
"pm_score": 4,
"selected": false,
"text": "Create Proc SP1\n(\n @ID int,\n @Name varchar(40)\n -- etc parameter list, If you don't have any parameter then no need to pass.\n )\n\n AS\n BEGIN\n\n -- Here we have some opereations\n\n -- If there is any Error Before Executing SP2 then SP will stop executing.\n\n Exec SP2 @ID,@Name,@SomeID OUTPUT \n\n -- ,etc some other parameter also we can use OutPut parameters like \n\n -- @SomeID is useful for some other operations for condition checking insertion etc.\n\n -- If you have any Error in you SP2 then also it will stop executing.\n\n -- If you want to do any other operation after executing SP2 that we can do here.\n\nEND\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170328",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21004/"
] |
170,337
|
<p>I'm having trouble wrapping my head around this. Right now I have some models that looks kind of like this:</p>
<pre><code> def Review(models.Model)
...fields...
overall_score = models.FloatField(blank=True)
def Score(models.Model)
review = models.ForeignKey(Review)
question = models.TextField()
grade = models.IntegerField()
</code></pre>
<p>A Review is has several "scores", the overall_score is the average of the scores. When a review or a score is saved, I need to recalculate the overall_score average. Right now I'm using a overridden save method. Would there be any benefits to using Django's signal dispatcher?</p>
|
[
{
"answer_id": 171703,
"author": "Jonny Buchanan",
"author_id": 6760,
"author_profile": "https://Stackoverflow.com/users/6760",
"pm_score": 8,
"selected": true,
"text": "save pre_save pre_save pre_delete save delete"
},
{
"answer_id": 52272689,
"author": "valex",
"author_id": 3940470,
"author_profile": "https://Stackoverflow.com/users/3940470",
"pm_score": 2,
"selected": false,
"text": ".delete() QuerySet .update() QuerySet"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170337",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24630/"
] |
170,346
|
<p>Has someone ever measured performance of Sequential Guid vs. Standard Guid when used as Primary Keys inside a database?</p>
<hr>
<p>I do not see the need for unique keys to be guessable or not, passing them from a web UI or in some other part seems a bad practice by itself and I do not see, if you have security concerns, how using a guid can improve things (if this is the matter use a real random number generator using the proper crypto functions of the framework).<br/>
The other items are covered by my approach, a sequential guid can be generated from code without need for DB access (also if only for Windows) and it's unique in time and space.<br/>
And yes, question was posed with the intent of answering it, to give people that have choosen Guids for their PK a way to improve database usage (in my case has allowed the customers to sustain a much higher workload without having to change servers).<br/><br/>
It seems that security concerns are a lot, in this case do not use Sequential Guid or, better still, use standard Guid for PK that are passed back and forward from your UI and sequential guid for everything else. As always there is no absolute truth, I've edited also main answer to reflect this.</p>
|
[
{
"answer_id": 170363,
"author": "massimogentilini",
"author_id": 11673,
"author_profile": "https://Stackoverflow.com/users/11673",
"pm_score": 8,
"selected": true,
"text": "[DllImport(\"rpcrt4.dll\", SetLastError = true)]\nstatic extern int UuidCreateSequential(out Guid guid);\n\npublic static Guid SequentialGuid()\n{\n const int RPC_S_OK = 0;\n Guid g;\n if (UuidCreateSequential(out g) != RPC_S_OK)\n return Guid.NewGuid();\n else\n return g;\n}\n"
},
{
"answer_id": 170562,
"author": "Sklivvz",
"author_id": 7028,
"author_profile": "https://Stackoverflow.com/users/7028",
"pm_score": 2,
"selected": false,
"text": "NEWSEQUENTIALID()"
},
{
"answer_id": 1042719,
"author": "Bernhard Kircher",
"author_id": 128695,
"author_profile": "https://Stackoverflow.com/users/128695",
"pm_score": 5,
"selected": false,
"text": "[System.Runtime.InteropServices.DllImport(\"rpcrt4.dll\", SetLastError = true)]\nstatic extern int UuidCreateSequential(byte[] buffer);\n\nstatic Guid NewSequentialGuid() {\n\n byte[] raw = new byte[16];\n if (UuidCreateSequential(raw) != 0)\n throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error());\n\n byte[] fix = new byte[16];\n\n // reverse 0..3\n fix[0x0] = raw[0x3];\n fix[0x1] = raw[0x2];\n fix[0x2] = raw[0x1];\n fix[0x3] = raw[0x0];\n\n // reverse 4 & 5\n fix[0x4] = raw[0x5];\n fix[0x5] = raw[0x4];\n\n // reverse 6 & 7\n fix[0x6] = raw[0x7];\n fix[0x7] = raw[0x6];\n\n // all other are unchanged\n fix[0x8] = raw[0x8];\n fix[0x9] = raw[0x9];\n fix[0xA] = raw[0xA];\n fix[0xB] = raw[0xB];\n fix[0xC] = raw[0xC];\n fix[0xD] = raw[0xD];\n fix[0xE] = raw[0xE];\n fix[0xF] = raw[0xF];\n\n return new Guid(fix);\n}\n"
},
{
"answer_id": 19039390,
"author": "Dennis",
"author_id": 98177,
"author_profile": "https://Stackoverflow.com/users/98177",
"pm_score": 2,
"selected": false,
"text": "import java.util.Arrays;\nimport java.util.UUID;\nimport java.util.Base64; //Only avail in Java 8+\nimport java.util.Date;\n\nimport java.nio.ByteBuffer; \n\n private ByteBuffer babuffer = ByteBuffer.allocate( (Long.SIZE/8)*2 );\nprivate Base64.Encoder encoder = Base64.getUrlEncoder();\npublic String createId() {\n UUID uuid = java.util.UUID.randomUUID();\n return uuid2base64( uuid );\n}\n\n public String uuid2base64(UUID uuid){ \n\n Date date= new Date();\n int intFor32bits;\n synchronized(this){\n babuffer.putLong(0,uuid.getLeastSignificantBits() );\n babuffer.putLong(8,uuid.getMostSignificantBits() );\n\n long time=date.getTime();\n time=time >> 1; // makes it every 2 milliseconds\n intFor32bits = (int) time; // rolls over every 106 yers + 1 month from epoch\n babuffer.putInt( 0, intFor32bits);\n\n }\n //does this cause a memory leak?\n return encoder.encodeToString( babuffer.array() );\n }\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11673/"
] |
170,353
|
<p>I seem to only be able to write to the Apache error log via stderr. Anyone know of a more structured logging architecture that I could use from my python web project, like commons?</p>
|
[
{
"answer_id": 14752499,
"author": "Andrew",
"author_id": 383188,
"author_profile": "https://Stackoverflow.com/users/383188",
"pm_score": 2,
"selected": false,
"text": "def handler(req) :\n req.log_error('Hello apache')\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24039/"
] |
170,377
|
<p>I'm working on a java web-application, trying to be xml-friendly and writing my jsp files using the jspx/xml syntax. It took me hours of dissecting examples and configuration files to find out that with tomcat 5.5 files using the new syntax should end in .jspx, or tomcat won't translate tag libraries and stuff.</p>
<p>Both file extensions map to the same servlet in tomcat's configuration file, so I thought everything was fine with my .jsp files. Am I missing something?</p>
|
[
{
"answer_id": 176853,
"author": "Mads Hansen",
"author_id": 14419,
"author_profile": "https://Stackoverflow.com/users/14419",
"pm_score": 3,
"selected": true,
"text": "<jsp-property-group>\n <url-pattern>*.jsp</url-pattern>\n <is-xml>true</is-xml>\n</jsp-property-group>\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6069/"
] |
170,380
|
<p>Sample code that shows how to create threads using MFC declares the thread function as both static and <code>__cdecl</code>. Why is the latter required? Boost threads don't bother with this convention, so is it just an anachronism?</p>
<p>For example (MFC):</p>
<pre><code>static __cdecl UINT MyFunc(LPVOID pParam)
{
...
}
CWinThread* pThread = AfxBeginThread(MyFunc, ...);
</code></pre>
<p>Whereas Boost:</p>
<pre><code>static void func()
{
...
}
boost::thread t;
t.create(&func);
</code></pre>
<p>(the code samples might not be 100% correct as I am nowhere near an IDE).</p>
<p>What is the point of __cdecl? How does it help when creating threads?</p>
|
[
{
"answer_id": 170399,
"author": "bk1e",
"author_id": 8090,
"author_profile": "https://Stackoverflow.com/users/8090",
"pm_score": 2,
"selected": false,
"text": "AfxBeginThread() CWinThread* AfxBeginThread(\n AFX_THREADPROC pfnThreadProc,\n LPVOID pParam,\n int nPriority = THREAD_PRIORITY_NORMAL,\n UINT nStackSize = 0,\n DWORD dwCreateFlags = 0,\n LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL \n);\n AFX_THREADPROC UINT(AFX_CDECL*)(LPVOID) AfxBeginThread() __cdecl __stdcall __fastcall __thiscall boost::thread"
},
{
"answer_id": 214030,
"author": "Raindog",
"author_id": 29049,
"author_profile": "https://Stackoverflow.com/users/29049",
"pm_score": 1,
"selected": false,
"text": "#define WINAPI __stdcall\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9236/"
] |
170,394
|
<p>Where can I find a free, very quick, and reliable implementation of FFT in C#?</p>
<p>That can be used in a product? Or are there any restrictions?</p>
|
[
{
"answer_id": 7817663,
"author": "Gerry Beauregard",
"author_id": 992608,
"author_profile": "https://Stackoverflow.com/users/992608",
"pm_score": 4,
"selected": false,
"text": "/**\n * Performs an in-place complex FFT.\n *\n * Released under the MIT License\n *\n * Copyright (c) 2010 Gerald T. Beauregard\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\npublic class FFT2\n{\n // Element for linked list in which we store the\n // input/output data. We use a linked list because\n // for sequential access it's faster than array index.\n class FFTElement\n {\n public double re = 0.0; // Real component\n public double im = 0.0; // Imaginary component\n public FFTElement next; // Next element in linked list\n public uint revTgt; // Target position post bit-reversal\n }\n\n private uint m_logN = 0; // log2 of FFT size\n private uint m_N = 0; // FFT size\n private FFTElement[] m_X; // Vector of linked list elements\n\n /**\n *\n */\n public FFT2()\n {\n }\n\n /**\n * Initialize class to perform FFT of specified size.\n *\n * @param logN Log2 of FFT length. e.g. for 512 pt FFT, logN = 9.\n */\n public void init(\n uint logN )\n {\n m_logN = logN;\n m_N = (uint)(1 << (int)m_logN);\n\n // Allocate elements for linked list of complex numbers.\n m_X = new FFTElement[m_N];\n for (uint k = 0; k < m_N; k++)\n m_X[k] = new FFTElement();\n\n // Set up \"next\" pointers.\n for (uint k = 0; k < m_N-1; k++)\n m_X[k].next = m_X[k+1];\n\n // Specify target for bit reversal re-ordering.\n for (uint k = 0; k < m_N; k++ )\n m_X[k].revTgt = BitReverse(k,logN);\n }\n\n /**\n * Performs in-place complex FFT.\n *\n * @param xRe Real part of input/output\n * @param xIm Imaginary part of input/output\n * @param inverse If true, do an inverse FFT\n */\n public void run(\n double[] xRe,\n double[] xIm,\n bool inverse = false )\n {\n uint numFlies = m_N >> 1; // Number of butterflies per sub-FFT\n uint span = m_N >> 1; // Width of the butterfly\n uint spacing = m_N; // Distance between start of sub-FFTs\n uint wIndexStep = 1; // Increment for twiddle table index\n\n // Copy data into linked complex number objects\n // If it's an IFFT, we divide by N while we're at it\n FFTElement x = m_X[0];\n uint k = 0;\n double scale = inverse ? 1.0/m_N : 1.0;\n while (x != null)\n {\n x.re = scale*xRe[k];\n x.im = scale*xIm[k];\n x = x.next;\n k++;\n }\n\n // For each stage of the FFT\n for (uint stage = 0; stage < m_logN; stage++)\n {\n // Compute a multiplier factor for the \"twiddle factors\".\n // The twiddle factors are complex unit vectors spaced at\n // regular angular intervals. The angle by which the twiddle\n // factor advances depends on the FFT stage. In many FFT\n // implementations the twiddle factors are cached, but because\n // array lookup is relatively slow in C#, it's just\n // as fast to compute them on the fly.\n double wAngleInc = wIndexStep * 2.0*Math.PI/m_N;\n if (inverse == false)\n wAngleInc *= -1;\n double wMulRe = Math.Cos(wAngleInc);\n double wMulIm = Math.Sin(wAngleInc);\n\n for (uint start = 0; start < m_N; start += spacing)\n {\n FFTElement xTop = m_X[start];\n FFTElement xBot = m_X[start+span];\n\n double wRe = 1.0;\n double wIm = 0.0;\n\n // For each butterfly in this stage\n for (uint flyCount = 0; flyCount < numFlies; ++flyCount)\n {\n // Get the top & bottom values\n double xTopRe = xTop.re;\n double xTopIm = xTop.im;\n double xBotRe = xBot.re;\n double xBotIm = xBot.im;\n\n // Top branch of butterfly has addition\n xTop.re = xTopRe + xBotRe;\n xTop.im = xTopIm + xBotIm;\n\n // Bottom branch of butterly has subtraction,\n // followed by multiplication by twiddle factor\n xBotRe = xTopRe - xBotRe;\n xBotIm = xTopIm - xBotIm;\n xBot.re = xBotRe*wRe - xBotIm*wIm;\n xBot.im = xBotRe*wIm + xBotIm*wRe;\n\n // Advance butterfly to next top & bottom positions\n xTop = xTop.next;\n xBot = xBot.next;\n\n // Update the twiddle factor, via complex multiply\n // by unit vector with the appropriate angle\n // (wRe + j wIm) = (wRe + j wIm) x (wMulRe + j wMulIm)\n double tRe = wRe;\n wRe = wRe*wMulRe - wIm*wMulIm;\n wIm = tRe*wMulIm + wIm*wMulRe;\n }\n }\n\n numFlies >>= 1; // Divide by 2 by right shift\n span >>= 1;\n spacing >>= 1;\n wIndexStep <<= 1; // Multiply by 2 by left shift\n }\n\n // The algorithm leaves the result in a scrambled order.\n // Unscramble while copying values from the complex\n // linked list elements back to the input/output vectors.\n x = m_X[0];\n while (x != null)\n {\n uint target = x.revTgt;\n xRe[target] = x.re;\n xIm[target] = x.im;\n x = x.next;\n }\n }\n\n /**\n * Do bit reversal of specified number of places of an int\n * For example, 1101 bit-reversed is 1011\n *\n * @param x Number to be bit-reverse.\n * @param numBits Number of bits in the number.\n */\n private uint BitReverse(\n uint x,\n uint numBits)\n {\n uint y = 0;\n for (uint i = 0; i < numBits; i++)\n {\n y <<= 1;\n y |= x & 0x0001;\n x >>= 1;\n }\n return y;\n }\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4044/"
] |
170,405
|
<p>This might be a similar problem to my earlier two questions - see <a href="https://stackoverflow.com/questions/169934/any-scrubyt-command-that-clicks-a-link-returns-a-403-forbidden-error">here</a> and <a href="https://stackoverflow.com/questions/168868/how-to-get-next-page-link-with-scrubyt">here</a> but I'm trying to use the _detail command to automatically click the link so I can scrape the details page for each individual event.</p>
<p>The code I'm using is:</p>
<pre><code>require 'rubygems'
require 'scrubyt'
nuffield_data = Scrubyt::Extractor.define do
fetch 'http://www.nuffieldtheatre.co.uk/cn/events/event_listings.php'
event do
title 'The Coast of Mayo'
link_url
event_detail do
dates "1-4 October"
times "7:30pm"
end
end
next_page "Next Page", :limit => 20
end
nuffield_data.to_xml.write($stdout,1)
</code></pre>
<p>Is there any way to print out the URL that using the event_detail is trying to access? The error doesn't seem to give me the URL that gave the 404.</p>
<p><strong>Update:</strong> I think the link may be a relative link - could this be causing problems? Any ideas how to deal with that?</p>
|
[
{
"answer_id": 171145,
"author": "user6325",
"author_id": 6325,
"author_profile": "https://Stackoverflow.com/users/6325",
"pm_score": 1,
"selected": false,
"text": " sudo gem install ruby-debug\n\nThis will give you access to a nice ruby debugger, start the debugger by altering your script:\n\n require 'rubygems'\n require 'ruby-debug'\n Debugger.start\n Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)\n\n require 'scrubyt'\n\n nuffield_data = Scrubyt::Extractor.define do\n fetch 'http://www.nuffieldtheatre.co.uk/cn/events/event_listings.php'\n\n event do\n title 'The Coast of Mayo'\n link_url\n event_detail do\n dates \"1-4 October\"\n times \"7:30pm\"\n end\n end\n\n next_page \"Next Page\", :limit => 2\n\n end\n\n nuffield_data.to_xml.write($stdout,1)\n\nThen find out where scrubyt is throwing an exception - in this case:\n\n /Library/Ruby/Gems/1.8/gems/scrubyt-0.3.4/lib/scrubyt/core/navigation/fetch_action.rb:52:in `fetch'\n\nFind the scrubyt gem on your system, and add a rescue clause to the method in question so that the end of the method looks like this:\n\n if @@current_doc_protocol == 'file'\n @@hpricot_doc = Hpricot(PreFilterDocument.br_to_newline(open(@@current_doc_url).read))\n else\n @@hpricot_doc = Hpricot(PreFilterDocument.br_to_newline(@@mechanize_doc.body))\n store_host_name(self.get_current_doc_url) # in case we're on a new host\n end\n rescue\n debugger\n self # the self is here because debugger doesn't like being at the end of a method\n end\n @@current_doc_url\n"
},
{
"answer_id": 1572228,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": true,
"text": " event do\n title 'The Coast of Mayo'\n link_url\n event_detail :resolve => 'http://www.nuffieldtheatre.co.uk/cn/events' do\n dates \"1-4 October\"\n times \"7:30pm\"\n end\n end\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170405",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1912/"
] |
170,415
|
<p>Do you know what may cause memory leaks in JavaScript?
I am interested in browsers: IE 7, FireFox 3, Safari 3</p>
|
[
{
"answer_id": 170447,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 5,
"selected": false,
"text": "function body_onload()\n{\n var elem = document.getElementById('someElementId');\n // do stuff with elem\n elem.onclick = function() {\n //Some code that doesn't need the elem variable\n }\n }\n var elem = null;\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24938/"
] |
170,426
|
<p>On a question of just performance, how does Python 3 compare to Python 2.x?</p>
|
[
{
"answer_id": 170521,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 3,
"selected": false,
"text": "except Exception1, Exception2"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1915/"
] |
170,440
|
<p>I have found that SP2 doesn't execute from within SP1 when SP1 is executed.</p>
<p>Below is the structure of SP1:</p>
<pre><code>ALTER PROCEDURE SP1 AS BEGIN
Declare c1 cursor....
open c1 fetch next from c1 ...
while @@fetch_status = 0 Begin
...
Fetch Next from c1 end
close c1
deallocate c1
exec sp2
end
</code></pre>
<hr>
<p>I see non of the PRINT statement outputs if they are printed in the 'Output window' in SQL Server 2005 management studio as the 'Output Window'is empty.</p>
|
[
{
"answer_id": 170449,
"author": "Sklivvz",
"author_id": 7028,
"author_profile": "https://Stackoverflow.com/users/7028",
"pm_score": 2,
"selected": false,
"text": "PRINT"
},
{
"answer_id": 219645,
"author": "Grzegorz Gierlik",
"author_id": 1483,
"author_profile": "https://Stackoverflow.com/users/1483",
"pm_score": 0,
"selected": false,
"text": "sp2 null null sp2 sp2 varchar VALUE sp2 V sp2 null null PRINT sp2"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170440",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21004/"
] |
170,452
|
<p><strong>I am using the term "Lexical Encoding" for my lack of a better one.</strong></p>
<p>A Word is arguably the fundamental unit of communication as opposed to a Letter. Unicode tries to assign a numeric value to each Letter of all known Alphabets. What is a Letter to one language, is a Glyph to another. Unicode 5.1 assigns more than 100,000 values to these Glyphs currently. Out of the approximately 180,000 Words being used in Modern English, it is said that with a vocabulary of about 2,000 Words, you should be able to converse in general terms. A "Lexical Encoding" would encode each Word not each Letter, and encapsulate them within a Sentence.</p>
<pre><code>// An simplified example of a "Lexical Encoding"
String sentence = "How are you today?";
int[] sentence = { 93, 22, 14, 330, QUERY };
</code></pre>
<p>In this example each Token in the String was encoded as an Integer. The Encoding Scheme here simply assigned an int value based on generalised statistical ranking of word usage, and assigned a constant to the question mark.</p>
<p>Ultimately, a Word has both a Spelling & Meaning though. Any "Lexical Encoding" would preserve the meaning and intent of the Sentence as a whole, and not be language specific. An English sentence would be encoded into <a href="https://stackoverflow.com/questions/170452/linguistics-lexical-encoding#174249">"...language-neutral atomic elements of meaning ..."</a> which could then be reconstituted into any language with a structured Syntactic Form and Grammatical Structure.</p>
<p>What are other examples of "Lexical Encoding" techniques?</p>
<hr>
<p>If you were interested in where the word-usage statistics come from :<br>
<a href="http://www.wordcount.org" rel="nofollow noreferrer">http://www.wordcount.org</a></p>
|
[
{
"answer_id": 192282,
"author": "Robert Elwell",
"author_id": 23102,
"author_profile": "https://Stackoverflow.com/users/23102",
"pm_score": 1,
"selected": false,
"text": "John: 1\nwent: 1\nto: 1\nthe: 2\nstore: 1\nhe: 1\nbought: 1\nbread: 2\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170452",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4857/"
] |
170,455
|
<p>I have a stored procedure that returns multiple tables. How can I execute and read both tables?</p>
<p>I have something like this:</p>
<pre>
<code>
SqlConnection conn = new SqlConnection(CONNECTION_STRING);
SqlCommand cmd = new SqlCommand("sp_mult_tables",conn);
cmd.CommandType = CommandType.StoredProcedure);
IDataReader rdr = cmd.ExecuteReader();
</code>
</pre>
<p>I'm not sure how to read it...whats the best way to handle this type of query, I am guessing I should read the data into a DataSet? How is the best way to do this?</p>
<p>Thanks.</p>
|
[
{
"answer_id": 170463,
"author": "Sklivvz",
"author_id": 7028,
"author_profile": "https://Stackoverflow.com/users/7028",
"pm_score": 4,
"selected": true,
"text": "using (SqlConnection conn = new SqlConnection(connection))\n{\n SqlDataAdapter adapter = new SqlDataAdapter();\n adapter.SelectCommand = new SqlCommand(query, conn);\n adapter.Fill(dataset);\n return dataset;\n}\n"
},
{
"answer_id": 653227,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": " For Each str As String In excelSheetNames\n da = New OleDbDataAdapter(\"select * from [\" & str & \"]\", MyConnection)\n da.Fill(DtSet, excelSheetNames(i))\n i += 1\n Next \n DataGridView1.DataSource = DtSet.Tables(0) \n\nEnd Sub\n Dim con As OleDbConnection = Nothing\n\n Dim dt As DataTable = Nothing\n\n Dim conStr As String = (\"Provider=Microsoft.Jet.OLEDB.4.0;\" & \"Data Source=\") + excelFileName & \";Extended Properties=Excel 8.0;\"\n\n con = New OleDbConnection(conStr)\n con.Open()\n dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)\n excelSheetNames = New String(dt.Rows.Count - 1) {}\n Dim i As Integer = 0\n\n For Each row As DataRow In dt.Rows\n excelSheetNames(i) = row(\"TABLE_NAME\").ToString()\n i += 1\n Next\nEnd Function\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] |
170,458
|
<p>In some asp tutorials, like <a href="https://web.archive.org/web/20211020111619/https://www.4guysfromrolla.com/webtech/050900-1.shtml" rel="nofollow noreferrer">this</a>, i observe the following pattern:</p>
<blockquote>
<p>Application.Lock</p>
<p>'do some things with the application object</p>
<p>Application.Unlock</p>
</blockquote>
<p>However, since web pages can have multiple instances, there is an obvious concurrency problem. So my questions are the following:</p>
<p>What if one page tries to lock while the object is already locked?</p>
<p>Is there a way to detect whether the application object is locked?</p>
<p>Is it better to just work on an unlocked application object or does that have other consequences?</p>
<p>What if there is only one action involving the application object? ~Is there a reason to lock/unlock in that case?</p>
|
[
{
"answer_id": 170489,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 2,
"selected": false,
"text": "Application(\"myCounter\") = Application(\"myCounter\") + 1\n Application.Lock\n\nApplication(\"myCounter\") = Application(\"myCounter\") + 1\n\nApplication.Unlock\n"
},
{
"answer_id": 170626,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 3,
"selected": true,
"text": "Lock Application.Unlock Server.ScriptTimeout <%@ Language=\"VBScript\" %> \n<% \n Application.Lock \n Application(\"PageCalls\") = Application(\"PageCalls\") + 1 \n Application(\"LastCall\") = Now() \n Application.Unlock \n%> \n\nThis page has been called <%= Application(\"PageCalls\") %> times.\n Lock"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24461/"
] |
170,466
|
<p>I need a programmatic way of creating a SQL Server ODBC Data Source. I can do this by directly accessing the Registry. It would be better if this could be done via an available (SQL Server/Windows) API to protect against changes in the registry keys or values with updated SQL Server drivers.</p>
<p><strong>Accepted Answer Note:</strong> Using SQLConfigDataSource abstracts the code from the details of Registry keys etc. so this is more robust. I was hoping, however, that SQL Server would have wrapped this with a higher level function which took strongly typed attributes (rather than a delimited string) and exposed it through the driver.</p>
|
[
{
"answer_id": 170490,
"author": "Matthew Murdoch",
"author_id": 4023,
"author_profile": "https://Stackoverflow.com/users/4023",
"pm_score": 0,
"selected": false,
"text": "HKLM\\SOFTWARE\\Microsoft\\ODBC\\ODBC.INI\\ODBC Data Sources\n HKCU\\Software\\ODBC\\ODBC.INI\\ODBC Data Sources\n Database - Name of default database to which to connect\nDescription - A description of the Data Source\nDriver - C:\\WINDOWS\\system32\\SQLSRV32.dll\nLastUser - Name of a database user (e.g. sa)\nServer - Hostname of machine on which database resides\n reg add \"HKCU\\Software\\ODBC\\ODBC.INI\\ODBC Data Sources\" \n /v ExampleDSN /t REG_SZ /d \"SQL Server\"\nreg add HKCU\\Software\\ODBC\\ExampleDSN \n /v Database /t REG_SZ /d ExampleDSN\nreg add HKCU\\Software\\ODBC\\ExampleDSN \n /v Description /t REG_SZ /d \"An Example Data Source\"\nreg add HKCU\\Software\\ODBC\\ExampleDSN\n /v Driver /t REG_SZ /d \"C:\\WINDOWS\\system32\\SQLSRV32.DLL\"\nreg add HKCU\\Software\\ODBC\\ExampleDSN\n /v LastUser /t REG_SZ /d sa\nreg add HKCU\\Software\\ODBC\\ExampleDSN\n /v Server /t REG_SZ /d localhost\n"
},
{
"answer_id": 170495,
"author": "Sergey Kornilov",
"author_id": 10969,
"author_profile": "https://Stackoverflow.com/users/10969",
"pm_score": 4,
"selected": true,
"text": "Const ODBC_ADD_DSN = 1 'user data source\nConst ODBC_ADD_SYS_DSN = 4 'system data source\n\nPrivate Declare Function SQLConfigDataSource Lib \"ODBCCP32.DLL\" (ByVal\nhwndParent As Long, ByVal fRequest As Long, ByVal lpszDriver As String, ByVal\nlpszAttributes As String) As Long\n\nstrDriver = \"SQL Server\"\nstrAttributes = \"DSN=Sample\" & Chr$(0) _\n& \"Database=Northwind\" & Chr$(0) _\n& \"Description= Sample Data Source\" & Chr$(0) _\n& \"Server=(local)\" & Chr$(0) _\n& \"Trusted_Connection=No\" & Chr$(0)\n\nSQLConfigDataSource(0, ODBC_ADD_SYS_DSN, strDriver, strAttributes)\n"
},
{
"answer_id": 171621,
"author": "Matthew Murdoch",
"author_id": 4023,
"author_profile": "https://Stackoverflow.com/users/4023",
"pm_score": 1,
"selected": false,
"text": "Imports System.Runtime.InteropServices\n <DllImport(\"ODBCCP32.DLL\")> Shared Function SQLConfigDataSource _\n(ByVal hwndParent As Integer, ByVal fRequest As Integer, _\n ByVal lpszDriver As String, _\n ByVal lpszAttributes As String) As Boolean\nEnd Function\n Const ODBC_ADD_DSN = 1 'User data source\nConst ODBC_ADD_SYS_DSN = 4 'System data source\n\nPublic Function CreateSqlServerDataSource\n Dim strDriver As String : strDriver = \"SQL Server\"\n Dim strAttributes As String : strAttributes = _\n \"DSN=Sample\" & Chr(0) & _\n \"Database=Northwind\" & Chr(0) & _\n \"Description= Sample Data Source\" & Chr(0) & _\n \"Server=(local)\" & Chr(0) & _\n \"Trusted_Connection=No\" & Chr(0)\n\n SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, strDriver, strAttributes)\nEnd Function\n"
},
{
"answer_id": 307265,
"author": "Mike",
"author_id": 1743,
"author_profile": "https://Stackoverflow.com/users/1743",
"pm_score": 0,
"selected": false,
"text": "using System.Runtime.InteropServices; \n\n private enum RequestFlags : int\n {\n\n ODBC_ADD_DSN = 1,\n ODBC_CONFIG_DSN = 2,\n ODBC_REMOVE_DSN = 3,\n ODBC_ADD_SYS_DSN = 4,\n ODBC_CONFIG_SYS_DSN = 5,\n ODBC_REMOVE_SYS_DSN = 6,\n ODBC_REMOVE_DEFAULT_DSN = 7\n\n }\n\n [DllImport(\"ODBCCP32.DLL\", CharSet = CharSet.Unicode, SetLastError = true)]\n private static extern bool SQLConfigDataSource(UInt32 hwndParent, RequestFlags fRequest, \n string lpszDriver, string lpszAttributes);\n\n public static void CreateDSN()\n {\n\n string strDrivername = \"SQL Server\";\n string strConfig = \"DSN=StackOverflow\\0\" +\n \"Database=Northwind\\0\" +\n \"Description=StackOverflow Sample\\0\" +\n \"Server=(local)\\0\" +\n \"Trusted_Connection=No\\0\";\n\n bool success = SQLConfigDataSource(0, RequestFlags.ODBC_ADD_SYS_DSN, strDrivername, strConfig);\n\n }\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170466",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4023/"
] |
170,467
|
<p>I want to experiment with GCC whole program optimizations. To do so I have to pass all C-files at once to the compiler frontend. However, I use makefiles to automate my build process, and I'm not an expert when it comes to makefile magic.</p>
<p>How should I modify the makefile if I want to compile (maybe even link) using just one call to GCC?</p>
<p>For reference - my makefile looks like this:</p>
<pre><code>LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32
CFLAGS = -Wall
OBJ = 64bitmath.o \
monotone.o \
node_sort.o \
planesweep.o \
triangulate.o \
prim_combine.o \
welding.o \
test.o \
main.o
%.o : %.c
gcc -c $(CFLAGS) $< -o $@
test: $(OBJ)
gcc -o $@ $^ $(CFLAGS) $(LIBS)
</code></pre>
|
[
{
"answer_id": 170472,
"author": "Alex B",
"author_id": 23643,
"author_profile": "https://Stackoverflow.com/users/23643",
"pm_score": 7,
"selected": true,
"text": "LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32\nCFLAGS = -Wall\n\n# Should be equivalent to your list of C files, if you don't build selectively\nSRC=$(wildcard *.c)\n\ntest: $(SRC)\n gcc -o $@ $^ $(CFLAGS) $(LIBS)\n"
},
{
"answer_id": 4074796,
"author": "Manas",
"author_id": 494275,
"author_profile": "https://Stackoverflow.com/users/494275",
"pm_score": 6,
"selected": false,
"text": "SRCS=$(wildcard *.c)\n\nOBJS=$(SRCS:.c=.o)\n\nall: $(OBJS)\n"
},
{
"answer_id": 21528397,
"author": "James McPherson",
"author_id": 2299087,
"author_profile": "https://Stackoverflow.com/users/2299087",
"pm_score": 2,
"selected": false,
"text": "LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32\nCFLAGS = -Wall\n\nOBJ = 64bitmath.o \\\n monotone.o \\\n node_sort.o \\\n planesweep.o \\\n triangulate.o \\\n prim_combine.o \\\n welding.o \\\n test.o \\\n main.o\n\nSRCS = $(OBJ:%.o=%.c)\n\ntest: $(SRCS)\n gcc -o $@ $(CFLAGS) $(LIBS) $(SRCS)\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15955/"
] |
170,479
|
<p>The problem is you can't tell the user how many characters are allowed in the field because the escaped value has more characters than the unescaped one.</p>
<p>I see a few solutions, but none looks very good:</p>
<ul>
<li>One whitelist for each field <em>(too much work and doesn't quite solve the problem)</em></li>
<li>One blacklist for each field <em>(same as above)</em></li>
<li>Use a field length that could hold the data even if all characters are escaped <em>(bad)</em></li>
<li>Uncap the size for the database field <em>(worse)</em></li>
<li>Save the data hex-unescaped and pass the responsibility entirely to output filtering <em>(not very good)</em></li>
<li>Let the user guess the maximum size <em>(worst)</em></li>
</ul>
<p>Are there other options? Is there a "best practice" for this case?</p>
<p>Sample code:</p>
<pre><code>$string = 'javascript:alert("hello!");';
echo strlen($string);
// outputs 27
$escaped_string = filter_var('javascript:alert("hello!");', FILTER_SANITIZE_ENCODED);
echo strlen($escaped_string);
// outputs 41
</code></pre>
<p>If the length of the database field is, say, 40, the escaped data will not fit.</p>
|
[
{
"answer_id": 170511,
"author": "Robert K",
"author_id": 24950,
"author_profile": "https://Stackoverflow.com/users/24950",
"pm_score": 0,
"selected": false,
"text": "HTMLSpecialChars()"
},
{
"answer_id": 170512,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 0,
"selected": false,
"text": "addSlashes()"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13211/"
] |
170,492
|
<p>What's the best way to create a non-NULL constraint in MySQL such that fieldA and fieldB can't both be NULL. I don't care if either one is NULL by itself, just as long as the other field has a non-NULL value. And if they both have non-NULL values, then it's even better.</p>
|
[
{
"answer_id": 170525,
"author": "Miquella",
"author_id": 16313,
"author_profile": "https://Stackoverflow.com/users/16313",
"pm_score": 2,
"selected": false,
"text": "ALTER TABLE tableName ADD CONSTRAINT constraintName CHECK ( (fieldA IS NOT NULL) OR (fieldB IS NOT NULL) );\n"
},
{
"answer_id": 170533,
"author": "Sklivvz",
"author_id": 7028,
"author_profile": "https://Stackoverflow.com/users/7028",
"pm_score": 2,
"selected": false,
"text": "ALTER TABLE `generic` \nADD CONSTRAINT myConstraint \nCHECK (\n `FieldA` IS NOT NULL OR \n `FieldB` IS NOT NULL\n) \n"
},
{
"answer_id": 170720,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 3,
"selected": false,
"text": "CREATE TABLE foo (\n FieldA INT,\n FieldB INT,\n FieldA_or_FieldB TINYINT NOT NULL;\n);\n\nDELIMITER //\nCREATE TRIGGER FieldABNotNull BEFORE INSERT ON foo\nFOR EACH ROW BEGIN\n IF (NEW.FieldA IS NULL AND NEW.FieldB IS NULL) THEN\n SET NEW.FieldA_or_FieldB = NULL;\n ELSE\n SET NEW.FieldA_or_FieldB = 1;\n END IF;\nEND//\n\nINSERT INTO foo (FieldA, FieldB) VALUES (NULL, 10); -- OK\nINSERT INTO foo (FieldA, FieldB) VALUES (10, NULL); -- OK\nINSERT INTO foo (FieldA, FieldB) VALUES (NULL, NULL); -- gives error\n"
},
{
"answer_id": 171224,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 3,
"selected": false,
"text": "COALESCE() COALESCE(a, b, c, d) IS NULL -- True if all are NULL\n\nCOALESCE(a, b, c, d) IS NOT NULL -- True if any one is not null\n"
},
{
"answer_id": 28775560,
"author": "Michael Platings",
"author_id": 2651243,
"author_profile": "https://Stackoverflow.com/users/2651243",
"pm_score": 4,
"selected": true,
"text": "CREATE TABLE foo (\n FieldA INT,\n FieldB INT\n);\n\nDELIMITER //\nCREATE TRIGGER InsertFieldABNotNull BEFORE INSERT ON foo\nFOR EACH ROW BEGIN\n IF (NEW.FieldA IS NULL AND NEW.FieldB IS NULL) THEN\n SIGNAL SQLSTATE '45000'\n SET MESSAGE_TEXT = '\\'FieldA\\' and \\'FieldB\\' cannot both be null';\n END IF;\nEND//\nCREATE TRIGGER UpdateFieldABNotNull BEFORE UPDATE ON foo\nFOR EACH ROW BEGIN\n IF (NEW.FieldA IS NULL AND NEW.FieldB IS NULL) THEN\n SIGNAL SQLSTATE '45000'\n SET MESSAGE_TEXT = '\\'FieldA\\' and \\'FieldB\\' cannot both be null';\n END IF;\nEND//\nDELIMITER ;\n\nINSERT INTO foo (FieldA, FieldB) VALUES (NULL, 10); -- OK\nINSERT INTO foo (FieldA, FieldB) VALUES (10, NULL); -- OK\nINSERT INTO foo (FieldA, FieldB) VALUES (NULL, NULL); -- gives error\nUPDATE foo SET FieldA = NULL; -- gives error\n"
},
{
"answer_id": 65395284,
"author": "CtC",
"author_id": 336888,
"author_profile": "https://Stackoverflow.com/users/336888",
"pm_score": 0,
"selected": false,
"text": "DROP TABLE IF EXISTS `error`;\n\nCREATE TABLE IF NOT EXISTS `error` (\n id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n left_id BIGINT UNSIGNED NULL,\n right_id BIGINT UNSIGNED NULL,\n left_or_right_id BIGINT UNSIGNED GENERATED ALWAYS AS (COALESCE(left_id, right_id)) NOT NULL,\n when_occurred TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n message_text LONGTEXT NOT NULL,\n INDEX id_index (id),\n INDEX when_occurred_index (when_occurred),\n INDEX left_id_index (left_id),\n INDEX right_id_index (right_id)\n);\n\nINSERT INTO `error` (left_id, right_id, message_text) VALUES (1, 1, 'Some random text.'); -- Ok.\nINSERT INTO `error` (left_id, right_id, message_text) VALUES (null, 1, 'Some random text.'); -- Ok.\nINSERT INTO `error` (left_id, right_id, message_text) VALUES (1, null, 'Some random text.'); -- Ok.\nINSERT INTO `error` (left_id, right_id, message_text) VALUES (null, null, 'Some random text.'); -- ER_BAD_NULL_ERROR: Column 'left_or_right_id' cannot be null\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12094/"
] |
170,500
|
<p>I've been trying to encode a relational algebra in Scala (which to my knowlege has one of the most advanced type systems) and just don't seem to find a way to get where I want.</p>
<p>As I'm not that experienced with the academic field of programming language design I don't really know what feature to look for.</p>
<p>So what language features would be needed, and what language has those features, to implement a statically verified relational algebra?</p>
<p>Some of the requirements:
A Tuple is a function mapping names from a statically defined set of valid names for the tuple in question to values of the type specified by the name. Lets call this name-type set the domain.</p>
<p>A Relation is a Set of Tuples with the same domain such that the range of any tuple is uniqe in the Set</p>
<p>So far the model can eaisly be modeled in Scala simply by</p>
<pre><code>trait Tuple
trait Relation[T<Tuple] extends Set[T]
</code></pre>
<p>The vals, vars and defs in Tuple is the name-type set defined above. But there should'n be two defs in Tuple with the same name. Also vars and impure defs should probably be restricted too.</p>
<p>Now for the tricky part:</p>
<p>A join of two relations is a relation where the domain of the tuples is the union of the domains from the operands tuples. Such that only tuples having the same ranges for the intersection of their domains is kept.</p>
<pre><code>def join(r1:Relation[T1],r2:Relation[T2]):Relation[T1 with T2]
</code></pre>
<p>should do the trick.</p>
<p>A projection of a Relation is a Relation where the domain of the tuples is a subset of the operands tuples domain.</p>
<pre><code>def project[T2](r:Relation[T],?1):Relation[T2>:T]
</code></pre>
<p>This is where I'm not sure if it's even possible to find a sollution. What do you think? What language features are needed to define project?</p>
<p>Implied above offcourse is that the API has to be usable. Layers and layers of boilerplate is not acceptable.</p>
|
[
{
"answer_id": 170648,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 3,
"selected": false,
"text": "A with B A with B A B A less B A P T P {F} where F in T P {$_1} where $_1 anonymous SELECT * $_1"
},
{
"answer_id": 180566,
"author": "John Nilsson",
"author_id": 24243,
"author_profile": "https://Stackoverflow.com/users/24243",
"pm_score": 0,
"selected": false,
"text": "[T<:Tuple](t:T) => P"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24243/"
] |
170,536
|
<p>How can I reset the <code>@@FETCH_STATUS</code> variable or set it to 0 in a stored procedure?</p>
<p>Also, can you bind FETCH_STATUS to a particular cursor?</p>
|
[
{
"answer_id": 3907063,
"author": "adopilot",
"author_id": 69433,
"author_profile": "https://Stackoverflow.com/users/69433",
"pm_score": 0,
"selected": false,
"text": "fetch next\nWhile @@fetch_Status = 0\nbegin\n\nif (my condition)\n break\nfetch next ;\n\nend \n"
},
{
"answer_id": 7411013,
"author": "mitul patel",
"author_id": 885208,
"author_profile": "https://Stackoverflow.com/users/885208",
"pm_score": 1,
"selected": false,
"text": "DECLARE @IDs int\nDECLARE MyCursor CURSOR FOR(SELECT ID FROM Table)\nOPEN MyCursor\nFETCH NEXT FROM MyCursor INTO @IDs\nWHILE @@FETCH_STATUS=0\nBEGIN\n --Do your work(First loop)\nFETCH NEXT FROM MyCursor INTO @IDs\nEND\nCLOSE MyCursor\n--Run the cursor again\nOPEN MyCursor\nFETCH NEXT FROM MyCursorINTO @IDs\nWHILE @@FETCH_STATUS=0\nBEGIN\n --Other work (Second loop)\n FETCH NEXT FROM MyCursor INTO @IDs\nEND\nCLOSE MyCursor\nDEALLOCATE MyCursor\n"
},
{
"answer_id": 24052464,
"author": "Christopher Keveny",
"author_id": 3203723,
"author_profile": "https://Stackoverflow.com/users/3203723",
"pm_score": 2,
"selected": false,
"text": "@@FETCH_STATUS DECLARE CURSOR FETCH NEXT @@FETCH_STATUS = -1 CLOSE DEALLOCATE CURSOR @@FETCH_STATUS = -1 @@FETCH_STATUS <> -1 CURSOR FIRST @@FETCH_STATUS 0 CURSOR SCROLL CURSOR USE transact_Sales;\n\nGO\n\nDECLARE @isOrderNumber INT;\nDECLARE @isOrderTotal MONEY;\nDECLARE test SCROLL CURSOR\nFOR\nSELECT Oi.order_num, SUM(Oi.quantity@item_price) FROM orderitems AS Oi GROUP BY order_num;\n\nOPEN test;\n\nWHILE @@FETCH_STATUS = 0\nBEGIN \nFETCH NEXT FROM test INTO @isOrderNumber, @isOrderTotal\nPRINT CAST(@isOrderNumber AS VARCHAR(20)) + ' '\n +CAST(@isOrderTotal AS VARCHAR(20)) + ' '\n +CAST(@@FETCH_STATUS AS VARCHAR(5))\nEND\nFETCH FIRST FROM test INTO @isOrderNumber, @isOrderTotal\n\nCLOSE test;\nDEALLOCATE test;\n 20005 149.87 0 \n20006 55.00 0 \n20007 1000.00 0 \n20008 125.00 0 \n20009 38.47 0 \n20009 38.47 -1\n"
},
{
"answer_id": 33156159,
"author": "chipfall",
"author_id": 4092051,
"author_profile": "https://Stackoverflow.com/users/4092051",
"pm_score": 1,
"selected": false,
"text": "WHILE (1 = 1) \nBEGIN\n FETCH NEXT FROM mycursor INTO @somevar\n IF (@@FETCH_STATUS <> 0) BREAK\n -- do stuff here\nEND\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21004/"
] |
170,554
|
<p>I want to save the objects I generated in a program. After restart the App should load automaticly all Objects in an Array. I want to write them in a file and parse them after restart. Are the other smarter possibilities than do it by hand?
Thank you</p>
|
[
{
"answer_id": 170667,
"author": "oxbow_lakes",
"author_id": 16853,
"author_profile": "https://Stackoverflow.com/users/16853",
"pm_score": 3,
"selected": true,
"text": "PersistentMap Serializable Map"
},
{
"answer_id": 173125,
"author": "Kevin Wong",
"author_id": 4792,
"author_profile": "https://Stackoverflow.com/users/4792",
"pm_score": 0,
"selected": false,
"text": "java.beans.XMLEncoder/XMLDecoder"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170554",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25128/"
] |
170,556
|
<p>This is related to the accepted answer for <a href="https://stackoverflow.com/questions/168486/whats-your-1-way-to-be-careful-with-a-live-database">What’s your #1 way to be careful with a live database</a>?</p>
<p>Suppose you create a temp table for backup purpose and make your changes in the original. The changes break the system and you want to restore the backup. In the meantime some other records have also changed in the original table (it is a live db). Now if you restore the backup, the system will be in an inconsistent state. </p>
<p>Whats the best way to tackle this</p>
|
[
{
"answer_id": 170588,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 2,
"selected": true,
"text": "SELECT * FROM faultyTable \nEXCEPT \nSELECT * FROM backupTable\n"
},
{
"answer_id": 170602,
"author": "Sklivvz",
"author_id": 7028,
"author_profile": "https://Stackoverflow.com/users/7028",
"pm_score": 1,
"selected": false,
"text": "BEGIN TRANSACTION\n\n-- SQL CODE\n COMMIT \n ROLLBACK\n"
},
{
"answer_id": 173561,
"author": "borjab",
"author_id": 16206,
"author_profile": "https://Stackoverflow.com/users/16206",
"pm_score": 0,
"selected": false,
"text": "Export (Your options) consistent = y\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170556",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9425/"
] |
170,578
|
<p>On some Microsoft Access queries, I get the following message: Operation must use an updatable query. (Error 3073). I work around it by using temporary tables, but I'm wondering if there's a better way. All the tables involved have a primary key. Here's the code:</p>
<pre><code>UPDATE CLOG SET CLOG.NEXTDUE = (
SELECT H1.paidthru
FROM CTRHIST as H1
WHERE H1.ACCT = clog.ACCT AND
H1.SEQNO = (
SELECT MAX(SEQNO)
FROM CTRHIST
WHERE CTRHIST.ACCT = Clog.ACCT AND
CTRHIST.AMTPAID > 0 AND
CTRHIST.DATEPAID < CLOG.UPDATED_ON
)
)
WHERE CLOG.NEXTDUE IS NULL;
</code></pre>
|
[
{
"answer_id": 173501,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 0,
"selected": false,
"text": "UPDATE UPDATE"
},
{
"answer_id": 8566753,
"author": "StoneJedi",
"author_id": 361870,
"author_profile": "https://Stackoverflow.com/users/361870",
"pm_score": 2,
"selected": false,
"text": "UPDATE TABLE1\nSET Field1 = \n(SELECT Table2.Field2\n FROM Table2\n WHERE Table2.UniqueIDColumn = Table1.UniqueIDColumn)\n"
},
{
"answer_id": 10525857,
"author": "Ray Brack",
"author_id": 1385884,
"author_profile": "https://Stackoverflow.com/users/1385884",
"pm_score": 3,
"selected": false,
"text": "update tbl_Lot_Valuation_Details as LVD\nset LVD.LGAName = (select LGA.LGA_NAME from tbl_Prop_LGA as LGA where LGA.LGA_CODE = LVD.LGCode)\nwhere LVD.LGAName is null;\n\nupdate tbl_LOT_VALUATION_DETAILS inner join tbl_prop_LGA on tbl_LOT_VALUATION_DETAILS.LGCode = tbl_prop_LGA.LGA_CODE \nset tbl_LOT_VALUATION_DETAILS.LGAName = [tbl_Prop_LGA].[LGA_NAME]\nwhere tbl_LOT_VALUATION_DETAILS.LGAName is null;\n update tbl_Lot_Valuation_Details as LVD\nset LVD.LGAName = dlookup(\"LGA_NAME\", \"tbl_Prop_LGA\", \"LGA_CODE=\"+LVD.LGCode)\nwhere LVD.LGAName is null;\n"
},
{
"answer_id": 11971211,
"author": "leeand00",
"author_id": 18149,
"author_profile": "https://Stackoverflow.com/users/18149",
"pm_score": 0,
"selected": false,
"text": "ODBC Data Source Administrator"
},
{
"answer_id": 15366755,
"author": "RSmith",
"author_id": 2161951,
"author_profile": "https://Stackoverflow.com/users/2161951",
"pm_score": 1,
"selected": false,
"text": " Dim updatingItems As Recordset\n Dim clientName As String\n Dim tableID As String\n Set updatingItems = CurrentDb.OpenRecordset(\"*insert SELECT SQL here*\");\", dbOpenDynaset)\n Do Until updatingItems .EOF\n clientName = updatingItems .Fields(\"strName\")\n tableID = updatingItems .Fields(\"ID\")\n DoCmd.RunSQL \"UPDATE *ONLY TABLE TO UPDATE* SET *TABLE*.strClientName= '\" & clientName & \"' WHERE (((*TABLE*.ID)=\" & tableID & \"))\"\n updatingItems.MoveNext\n Loop\n"
},
{
"answer_id": 20420899,
"author": "Rahul Uttarkar",
"author_id": 3016043,
"author_profile": "https://Stackoverflow.com/users/3016043",
"pm_score": 2,
"selected": false,
"text": " - Please check weather you have given Read-write permission to MS-Access database file.\n\n - The Database file where it is stored (say in Folder1) is read-only..? \n C:\\Program files"
},
{
"answer_id": 28725922,
"author": "iDevlop",
"author_id": 78522,
"author_profile": "https://Stackoverflow.com/users/78522",
"pm_score": 2,
"selected": false,
"text": "RecordsetType Dynaset (Inconsistent Updates)"
},
{
"answer_id": 67398263,
"author": "Max",
"author_id": 2760773,
"author_profile": "https://Stackoverflow.com/users/2760773",
"pm_score": 0,
"selected": false,
"text": "UPDATE DISTINCTROW CLOG SET CLOG.NEXTDUE \n"
},
{
"answer_id": 70593411,
"author": "Arthur Borges",
"author_id": 2604360,
"author_profile": "https://Stackoverflow.com/users/2604360",
"pm_score": 2,
"selected": false,
"text": "DLOOKUP(Field, SetOfRecords, Criteria)\n UPDATE tblTarifaDeCorretagem \n SET tblTarifaDeCorretagem.ValorCorretagem = \n [tblTarifaDeCorretagem].[TarifaParteFixa]+\n DLookUp(\n \"[ParteVariável]\",\n \"cstParteVariavelPorOrdem\",\n \"[IdTarifaDeCorretagem] = \" & [tblTarifaDeCorretagem].[IdTarifaDeCorretagem]\n );\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4873/"
] |
170,584
|
<p>I have read on Stack Overflow some people that have converting to C#2.0 to C#3, but is it really worth it?</p>
<p><strike>I have a project that is done at 75% before going in maintenance phase. I am asking to myself if it is worth it to switch to C#3.0?</strike></p>
<h3>Update:</h3>
<p>The project will have a web interface now so before entering the maintenance phase we have to develop the web part (all was done for internal purposes with Windows Forms). Most parts will be resused (back-end). Most people have said that it wasn't worth it in the past because it was already at 75%... but now do you still think it's not worth it?</p>
<h3>What have been done finally</h3>
<p>Finally since we are continuing the project with the web interface we will update to 3.5 for the new year. Thank you everybody for all your input.</p>
|
[
{
"answer_id": 171001,
"author": "benjismith",
"author_id": 22979,
"author_profile": "https://Stackoverflow.com/users/22979",
"pm_score": 2,
"selected": false,
"text": "var myDictionary = new Dictionary<String, String> {\n { \"key-1\", \"value-1\" },\n { \"key-2\", \"value-2\" },\n { \"key-3\", \"value-3\" },\n};\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170584",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13913/"
] |
170,600
|
<p>I realize that since UNIX sockets are platform-specific, there has to be some non-Java code involved. Specifically, we're interested in using JDBC to connect to a MySQL instance which only has UNIX domain sockets enabled. </p>
<p>It doesn't look like this is supported, but from what I've read it should be at least possible to write a SocketFactory for JDBC based on UNIX sockets <em>if</em> we can find a decent implementation of UNIX sockets for Java. </p>
<p>Has anyone tried this? Does anyone know of such an implementation?</p>
|
[
{
"answer_id": 855842,
"author": "GWLlosa",
"author_id": 18071,
"author_profile": "https://Stackoverflow.com/users/18071",
"pm_score": -1,
"selected": false,
"text": "import java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.ResultSet;\nimport java.sql.Statement;\n\nimport com.mysql.management.driverlaunched.ServerLauncherSocketFactory;\n\npublic class ConnectorMXJTestExample {\n public static void main(String[] args) throws Exception {\n String hostColonPort = \"localhost:3336\";\n\n String driver = com.mysql.jdbc.Driver.class.getName();\n String url = \"jdbc:mysql://\" + hostColonPort + \"/\" + \"?\"\n + \"socketFactory=\"\n + ServerLauncherSocketFactory.class.getName();\n String userName = \"root\";\n String password = \"\";\n\n Class.forName(driver);\n Connection conn = null;\n try {\n conn = DriverManager.getConnection(url, userName, password);\n Statement stmt = conn.createStatement();\n ResultSet rs = stmt.executeQuery(\"SELECT VERSION()\");\n rs.next();\n String version = rs.getString(1);\n rs.close();\n stmt.close();\n\n System.out.println(\"------------------------\");\n System.out.println(version);\n System.out.println(\"------------------------\");\n } finally {\n try {\n conn.close();\n } catch (Exception e) {\n e.printStackTrace();\n }\n ServerLauncherSocketFactory.shutdown(hostColonPort);\n }\n }\n}\n"
},
{
"answer_id": 40180646,
"author": "Robert",
"author_id": 7053934,
"author_profile": "https://Stackoverflow.com/users/7053934",
"pm_score": 2,
"selected": false,
"text": "jdbc:mariadb://localhost:3306/revmgt?localSocket=/var/run/mysqld/mysqld.sock"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21632/"
] |
170,601
|
<p>I have a somewhat messily-formatted Objective-C code base. Is there a way to have Xcode reformat an entire project to conform to a coding standard (i.e., properly indent, spaces v. tabs, etc.)? Are there other tools that might accomplish this?</p>
|
[
{
"answer_id": 170618,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 3,
"selected": false,
"text": "NAME\n indent - changes the appearance of a C program by inserting or deleting\n whitespace.\n\nSYNOPSIS\n indent [options] [input-files]\n\n indent [options] [single-input-file] [-o output-file]\n\n indent --version\n\nDESCRIPTION\n This man page is generated from the file indent.texinfo. This is Ediâ\n tion of \"The indent Manual\", for Indent Version , last updated .\n\n The indent program can be used to make code easier to read. It can\n also convert from one style of writing C to another.\n\n indent understands a substantial amount about the syntax of C, but it\n also attempts to cope with incomplete and misformed syntax.\n"
},
{
"answer_id": 170631,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 6,
"selected": true,
"text": "; { }"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1967/"
] |
170,606
|
<p>Publishing and/or collaborative applications often involve the sharing of access to resources. In a portal a user may be granted access to certain content as a member of a group or because of explicit access. The complete set of content could include public content, group membership content, and private user content. Or, with collaborative applications, we may want to pass along resources as part of a workflow or share custody of a document for editing purposes. </p>
<p>Since most applications store these resources in a database you typically create queries like 'Get all the documents that I can edit' or 'Get all the content I can see'. Where 'can edit' and 'can see' are the user's privileges.</p>
<p>I have two questions: </p>
<ol>
<li><p>It's quite easy to authorize the user once you've retrieved a resource, but how do you efficiently perform authorization on the list of available resources? And, </p></li>
<li><p>Can this kind of authorization be separated from the core of the application? Perhaps into a separate service? Once separated, how could you filter queries like 'Get me all the documents I can see with title like [SomeSearchTerm]'? It seems to me your separate system would have to copy over a lot of reference data.</p></li>
</ol>
|
[
{
"answer_id": 170620,
"author": "Sklivvz",
"author_id": 7028,
"author_profile": "https://Stackoverflow.com/users/7028",
"pm_score": 0,
"selected": false,
"text": "SELECT <fields> \nFROM Documents d \nINNER JOIN UserDocuments ud on ud.DocumentId = d.Id \nINNER JOIN Users u ON u.Id = ud.UserId\n"
},
{
"answer_id": 312031,
"author": "MiniQuark",
"author_id": 38626,
"author_profile": "https://Stackoverflow.com/users/38626",
"pm_score": 3,
"selected": false,
"text": "class DocumentController [...]\n filter_access_to :display, :require => :read\n def display\n ...\n end\nend\n <html> [...]\n <% permitted_to?(:create, :documents) do %>\n <%= link_to 'New', new_document_path %>\n <% end %>\n</html>\n role :document_author do\n has_permission.on :documents do\n to :manage\n if_attribute :author => is {user}\n end\nend\n Document.with_permissions_to(:update)\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170606",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
170,617
|
<p>This might sound like a little bit of a crazy question, but how can I find out (hopefully via an API/registry key) the install time and date of Windows?</p>
<p>The best I can come up with so far is to look at various files in C:\Windows and try to guess... but that's not exactly a nice solution.</p>
|
[
{
"answer_id": 170630,
"author": "Tommy",
"author_id": 20451,
"author_profile": "https://Stackoverflow.com/users/20451",
"pm_score": 8,
"selected": true,
"text": "regedit.exe HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\InstallDate\n"
},
{
"answer_id": 170634,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 8,
"selected": false,
"text": "systeminfo systeminfo | sls \"original\"\n system.ini (Get-Item \"C:\\Windows\\system.ini\").CreationTime\n systeminfo|find /i \"original\"\n find /i \"install\" ursprungligt ursprüngliches systeminfo|find \"Original\"\n PS > $os = get-wmiobject win32_operatingsystem\nPS > $os.ConvertToDateTime($os.InstallDate) -f \"MM/dd/yyyy\"\n PS > $path = 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion'\nPS > $id = get-itemproperty -path $path -name InstallDate\nPS > $d = get-date -year 1970 -month 1 -day 1 -hour 0 -minute 0 -second 0\n## add to hours (GMT offset)\n## to get the timezone offset programatically:\n## get-date -f zz\nPS > ($d.AddSeconds($id.InstallDate)).ToLocalTime().AddHours((get-date -f zz)) -f \"MM/dd/yyyy\"\n Dim dtmInstallDate As DateTime\nDim oSearcher As New ManagementObjectSearcher(\"SELECT * FROM Win32_OperatingSystem\")\nFor Each oMgmtObj As ManagementObject In oSearcher.Get\n dtmInstallDate =\n ManagementDateTimeConverter.ToDateTime(CStr(oMgmtO bj(\"InstallDate\")))\nNext\n ;Windows Install Date\n;\n$readreg = RegRead(\"HKLM\\SOFTWARE\\MICROSOFT\\WINDOWS NT\\CURRENTVERSION\\\", \"InstallDate\")\n$sNewDate = _DateAdd( 's',$readreg, \"1970/01/01 00:00:00\")\nMsgBox( 4096, \"\", \"Date: \" & $sNewDate )\nExit\n Function GetInstallDate: String;\nVar\n di: longint;\n buf: Array [ 0..3 ] Of byte;\nBegin\n Result := 'Unknown';\n With TRegistry.Create Do\n Begin\n RootKey := HKEY_LOCAL_MACHINE;\n LazyWrite := True;\n OpenKey ( '\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion', False );\n di := readbinarydata ( 'InstallDate', buf, sizeof ( buf ) );\n// Result := DateTimeToStr ( FileDateToDateTime ( buf [ 0 ] + buf [ 1 ] * 256 + buf [ 2 ] * 65535 + buf [ 3 ] * 16777216 ) );\nshowMessage(inttostr(di));\n Free;\n End;\nEnd;\n system.ini-file (PowerShell): (Get-Item \"C:\\Windows\\system.ini\").CreationTime\n"
},
{
"answer_id": 24686402,
"author": "user3827180",
"author_id": 3827180,
"author_profile": "https://Stackoverflow.com/users/3827180",
"pm_score": 4,
"selected": false,
"text": "systeminfo | Select-String \"Install Date:\"\n"
},
{
"answer_id": 26931322,
"author": "shailesh",
"author_id": 1180530,
"author_profile": "https://Stackoverflow.com/users/1180530",
"pm_score": 1,
"selected": false,
"text": "\"MSINFO32\""
},
{
"answer_id": 43284251,
"author": "Markus",
"author_id": 6008873,
"author_profile": "https://Stackoverflow.com/users/6008873",
"pm_score": 2,
"selected": false,
"text": " private static string RegistryInstallDate()\n {\n\n DateTime InstallDate = new DateTime(1970, 1, 1, 0, 0, 0); //NOT a unix timestamp 99% of online solutions incorrect identify this as!!!! \n ManagementObjectSearcher searcher = new ManagementObjectSearcher(\"SELECT * FROM Win32_Registry\");\n\n foreach (ManagementObject wmi_Windows in searcher.Get())\n {\n try\n {\n ///CultureInfo ci = CultureInfo.InvariantCulture;\n string installdate = wmi_Windows[\"InstallDate\"].ToString(); \n\n //InstallDate is in the UTC format (yyyymmddHHMMSS.xxxxxx±UUU) where critically\n // \n // xxxxxx is milliseconds and \n // ±UUU is number of minutes different from Greenwich Mean Time. \n\n if (installdate.Length==25)\n {\n string yyyymmddHHMMSS = installdate.Split('.')[0];\n string xxxxxxsUUU = installdate.Split('.')[1]; //±=s for sign\n\n int year = int.Parse(yyyymmddHHMMSS.Substring(0, 4));\n int month = int.Parse(yyyymmddHHMMSS.Substring(4, 2));\n int date = int.Parse(yyyymmddHHMMSS.Substring(4 + 2, 2));\n int hour = int.Parse(yyyymmddHHMMSS.Substring(4 + 2 + 2, 2));\n int mins = int.Parse(yyyymmddHHMMSS.Substring(4 + 2 + 2 + 2, 2));\n int secs = int.Parse(yyyymmddHHMMSS.Substring(4 + 2 + 2 + 2 + 2, 2));\n int msecs = int.Parse(xxxxxxsUUU.Substring(0, 6));\n\n double UTCoffsetinMins = double.Parse(xxxxxxsUUU.Substring(6, 4));\n TimeSpan UTCoffset = TimeSpan.FromMinutes(UTCoffsetinMins);\n\n InstallDate = new DateTime(year, month, date, hour, mins, secs, msecs) + UTCoffset; \n\n }\n break;\n }\n catch (Exception)\n {\n InstallDate = DateTime.Now; \n }\n }\n return String.Format(\"{0:ddd d-MMM-yyyy h:mm:ss tt}\", InstallDate); \n }\n"
},
{
"answer_id": 44539474,
"author": "Nikolay Kostov",
"author_id": 1862812,
"author_profile": "https://Stackoverflow.com/users/1862812",
"pm_score": 6,
"selected": false,
"text": "10/30/2015 04/14/2017 C:\\Windows C:\\ dir -Force C:\\ | sort -Property creationtime | select -Property name, creationtime -First 10\ndir -Force C:\\windows | sort -Property creationtime | select -Property name, creationtime -First 10\n"
},
{
"answer_id": 47336506,
"author": "Amit Gupta",
"author_id": 8953475,
"author_profile": "https://Stackoverflow.com/users/8953475",
"pm_score": 3,
"selected": false,
"text": "Computer\\HKEY_LOCAL_MACHINE\\SYSTEM\\Setup\\\n Computer\\HKEY_LOCAL_MACHINE\\SYSTEM\\Setup\\Source OS (Updated on xxxxxx).\"\n Computer\\HKEY_LOCAL_MACHINE\\SYSTEM\\Setup\\Source OS (Updated on xxxxxx)\"\n"
},
{
"answer_id": 48292921,
"author": "abdullahjavaid86",
"author_id": 6278648,
"author_profile": "https://Stackoverflow.com/users/6278648",
"pm_score": 0,
"selected": false,
"text": "cmd systeminfo | find /i \"Original\"\n"
},
{
"answer_id": 50725604,
"author": "MoonDogg",
"author_id": 1112104,
"author_profile": "https://Stackoverflow.com/users/1112104",
"pm_score": 3,
"selected": false,
"text": "dir /as /t:c c:\\pagefile.sys\n"
},
{
"answer_id": 57997512,
"author": "Bacon Bits",
"author_id": 696808,
"author_profile": "https://Stackoverflow.com/users/696808",
"pm_score": 0,
"selected": false,
"text": "Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\' -Name InstallDate |\n Select-Object -Property @{n='InstallDate';e={[DateTime]::new(1970,1,1,0,0,0,0,'UTC').AddSeconds($_.InstallDate).ToLocalTime()}}\n"
},
{
"answer_id": 58176279,
"author": "Future",
"author_id": 1318491,
"author_profile": "https://Stackoverflow.com/users/1318491",
"pm_score": 1,
"selected": false,
"text": "Get-ChildItem -Path HKLM:\\System\\Setup\\Source* | \n ForEach-Object {Get-ItemProperty -Path Registry::$_} | \n Select-Object ProductName, ReleaseID, CurrentBuild, @{n=\"Install Date\"; e={([DateTime]'1/1/1970').AddSeconds($_.InstallDate)}} | \n Sort-Object \"Install Date\"\n"
},
{
"answer_id": 58414733,
"author": "Nick Murtaugh",
"author_id": 12226919,
"author_profile": "https://Stackoverflow.com/users/12226919",
"pm_score": 2,
"selected": false,
"text": "(Get-CimInstance -Class Win32_OperatingSystem).InstallDate\n"
},
{
"answer_id": 64877416,
"author": "greatquux",
"author_id": 2332552,
"author_profile": "https://Stackoverflow.com/users/2332552",
"pm_score": 1,
"selected": false,
"text": "([DateTime](Get-Item -Force 'C:\\System Volume Information\\').CreationTime).ToString('MM/dd/yyyy')\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1849/"
] |
170,624
|
<p>Does anyone know how to resize images proportionally using JavaScript?</p>
<p>I have tried to modify the DOM by adding attributes <code>height</code> and <code>width</code> on the fly, but seems did not work on IE6.</p>
|
[
{
"answer_id": 170632,
"author": "Neall",
"author_id": 619,
"author_profile": "https://Stackoverflow.com/users/619",
"pm_score": 3,
"selected": false,
"text": "myimg = document.getElementById('myimg');\nmyimg.style.height = \"50px\";\nmyimg.style.width = \"50px\";\n myimg = document.getElementById('myimg');\nmyimg.height = myimg.height * 2;\nmyimg.width = myimg.width * 2;\n"
},
{
"answer_id": 170636,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 7,
"selected": true,
"text": "image.style.width = '50%'\nimage.style.height = 'auto'\n"
},
{
"answer_id": 170642,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 2,
"selected": false,
"text": "function Resize(imgId)\n{\n var img = document.getElementById(imgId);\n var w = img.width, h = img.height;\n w /= 2; h /= 2;\n img.width = w; img.height = h;\n}\n"
},
{
"answer_id": 170672,
"author": "Komang",
"author_id": 19463,
"author_profile": "https://Stackoverflow.com/users/19463",
"pm_score": 4,
"selected": false,
"text": "if($(this).width() > $(this).height()) { \n $(this).css('width',MaxPreviewDimension+'px');\n $(this).css('height','auto');\n} else {\n $(this).css('height',MaxPreviewDimension+'px');\n $(this).css('width','auto');\n}\n"
},
{
"answer_id": 1033576,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "function resize_image(image, w, h) {\n\n if (typeof(image) != 'object') image = document.getElementById(image);\n\n if (w == null || w == undefined)\n w = (h / image.clientHeight) * image.clientWidth;\n\n if (h == null || h == undefined)\n h = (w / image.clientWidth) * image.clientHeight;\n\n image.style['height'] = h + 'px';\n image.style['width'] = w + 'px';\n return;\n}\n"
},
{
"answer_id": 2404932,
"author": "Tim",
"author_id": 289181,
"author_profile": "https://Stackoverflow.com/users/289181",
"pm_score": 1,
"selected": false,
"text": "var scale=0.5;\n\nminWidth=50;\nminHeight=100;\n\nif($(\"#id img\").width()*scale>minWidth && $(\"#id img\").height()*scale >minHeight)\n{\n $(\"#id img\").width($(\"#id img\").width()*scale);\n $(\"#id img\").height($(\"#id img\").height()*scale);\n}\n"
},
{
"answer_id": 8922434,
"author": "vadivu",
"author_id": 1157915,
"author_profile": "https://Stackoverflow.com/users/1157915",
"pm_score": 1,
"selected": false,
"text": "<html>\n<body>\n<head>\n<script type=\"text/javascript\">\nfunction splitString()\n{\nvar myDimen=document.getElementById(\"dimen\").value;\nvar splitDimen = myDimen.split(\"*\");\ndocument.getElementById(\"myImage\").width=splitDimen[0];\ndocument.getElementById(\"myImage\").height=splitDimen[1];\n}\n</script>\n</head>\n\n<h2>Norwegian Mountain Trip</h2>\n<img border=\"0\" id=\"myImage\" src=\"...\" alt=\"Pulpit rock\" width=\"304\" height=\"228\" /><br>\n<input type=\"text\" id=\"dimen\" name=\"dimension\" />\n<input type=\"submit\" value=\"Submit\" Onclick =\"splitString()\"/>\n\n</body>\n</html>\n"
},
{
"answer_id": 9728249,
"author": "Dimitris Damilos",
"author_id": 979010,
"author_profile": "https://Stackoverflow.com/users/979010",
"pm_score": 2,
"selected": false,
"text": ".preview_image{\n width: 300px;\n height: auto;\n border: 0px;\n}\n"
},
{
"answer_id": 13938239,
"author": "equiman",
"author_id": 812915,
"author_profile": "https://Stackoverflow.com/users/812915",
"pm_score": 2,
"selected": false,
"text": "<head>\n <script type=\"text/javascript\">\n var CreateNewImage = function (url, value) {\n var img = new Image;\n img.src = url;\n img.width = img.width * (1 + (value / 100));\n img.height = img.height * (1 + (value / 100));\n\n var container = document.getElementById (\"container\");\n container.appendChild (img);\n }\n </script>\n</head>\n<body>\n <button onclick=\"CreateNewImage ('http://www.medellin.gov.co/transito/images_jq/imagen5.jpg', 40);\">Zoom +40%</button>\n <button onclick=\"CreateNewImage ('http://www.medellin.gov.co/transito/images_jq/imagen5.jpg', 60);\">Zoom +50%</button>\n <div id=\"container\"></div>\n</body>\n"
},
{
"answer_id": 17531399,
"author": "user2561474",
"author_id": 2561474,
"author_profile": "https://Stackoverflow.com/users/2561474",
"pm_score": 0,
"selected": false,
"text": "$(window).load(function() {\nmitad();doble();\n});\nfunction mitad(){ \n\n imag0.width=imag0.width/2;\n imag0.height=imag0.height/2;\n\n }\nfunction doble(){ \n imag0.width=imag0.width*2; \n imag0.height=imag0.height*2;}\n <img src=\"xxx.jpg\" name=\"imag0\">\n"
},
{
"answer_id": 19473880,
"author": "Jason J. Nathan",
"author_id": 382536,
"author_profile": "https://Stackoverflow.com/users/382536",
"pm_score": 3,
"selected": false,
"text": " /**\n * Conserve aspect ratio of the original region. Useful when shrinking/enlarging\n * images to fit into a certain area.\n *\n * @param {Number} srcWidth width of source image\n * @param {Number} srcHeight height of source image\n * @param {Number} maxWidth maximum available width\n * @param {Number} maxHeight maximum available height\n * @return {Object} { width, height }\n */\nfunction calculateAspectRatioFit(srcWidth, srcHeight, maxWidth, maxHeight) {\n\n var ratio = Math.min(maxWidth / srcWidth, maxHeight / srcHeight);\n\n return { width: srcWidth*ratio, height: srcHeight*ratio };\n }\n"
},
{
"answer_id": 22715667,
"author": "user246340",
"author_id": 3146056,
"author_profile": "https://Stackoverflow.com/users/3146056",
"pm_score": 2,
"selected": false,
"text": "function resizeImg(imgId) {\n var img = document.getElementById(imgId);\n var $img = $(img);\n var maxWidth = 110;\n var maxHeight = 100;\n var width = img.width;\n var height = img.height;\n var aspectW = width / maxWidth;\n var aspectH = height / maxHeight;\n\n if (aspectW > 1 || aspectH > 1) {\n if (aspectW > aspectH) {\n $img.width(maxWidth);\n $img.height(height / aspectW);\n }\n else {\n $img.height(maxHeight);\n $img.width(width / aspectH);\n }\n }\n}\n"
},
{
"answer_id": 31156020,
"author": "Weijing Jay Lin",
"author_id": 1257916,
"author_profile": "https://Stackoverflow.com/users/1257916",
"pm_score": 0,
"selected": false,
"text": "<div class=\"imgContainer\" style=\"height:100px; width:500px; overflow:hidden; background-color: black\">\n <img src=\"http://dev.isaacsonwebdevelopment.com/sites/development/files/views-slideshow-settings-jquery-cycle-custom-options-message.png\" id=\"imgCat\">\n</div>\n<script src=\"http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js\"></script>\n<script>\n $(window).load(function() {\n var heightRate =$(\"#imgCat\").height() / $(\"#imgCat\").parent(\".imgContainer\").height();\n var widthRate = $(\"#imgCat\").width() / $(\"#imgCat\").parent(\".imgContainer\").width();\n\n if (window.console) {\n console.log($(\"#imgCat\").height());\n console.log(heightRate);\n console.log(widthRate);\n console.log(heightRate > widthRate);\n }\n if (heightRate <= widthRate) {\n $(\"#imgCat\").height($(\"#imgCat\").parent(\".imgContainer\").height());\n } else {\n $(\"#imgCat\").width($(\"#imgCat\").parent(\".imgContainer\").width());\n }\n });\n</script>\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19463/"
] |
170,650
|
<p>I would like to update a Windows Forms application to provide the following features:</p>
<ul>
<li>spell checking</li>
<li>limited formatting of text: bold, italics, bulleted lists</li>
</ul>
<p>Ideally the formatted text could be accessed in a plain text way for reporting through tools that don't support the formatting, but could also be rendered as HTML for tools that support HTML tags when rendering text.</p>
<p>It seems to me that the WPF RichTextBox would provide this functionality. What is the best way to incorporate it? Would you suggest other alternatives?</p>
|
[
{
"answer_id": 173425,
"author": "rudigrobler",
"author_id": 5147,
"author_profile": "https://Stackoverflow.com/users/5147",
"pm_score": 2,
"selected": false,
"text": "<TextBox SpellCheck.IsEnabled=\"True\" />\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20625/"
] |
170,665
|
<p>Back in VB6, I wrote a few functions that would let me code without having to care about the difference between null and '' for strings, null and 0 for numbers, etc. Nothing kills my productivity more when coding than having to add special case code for dealing with data that might cause some irrelevant error; 9999/10000 if something I'm using as a number is null, then really I treat it as 0.</p>
<p>I'm now in C#, and the difference between VB6 and C# 2005 is quite extensive...so I don't really know where to start to write my new set of helper functions, or if I even need to do them at all.</p>
<p>So, I need to write a function that would accept a string, a database field, a request form/querysting field, ???, and then do whatever it could do to turn that into a Double, and return that to the calling procedure.</p>
<p>I'd also need to do this for shorts, int16, int32, long, everything else I could possibly care about.</p>
<p>Then I'd do this for strings. And Dates.</p>
<p>Is this a worthwhile pursuit? Is there something in the framework or C# that I can use instead? I really desire something that would allow me to use data inline in calling other functions, and not having to create temporary variables, etc.</p>
|
[
{
"answer_id": 170718,
"author": "Santiago Palladino",
"author_id": 12791,
"author_profile": "https://Stackoverflow.com/users/12791",
"pm_score": 3,
"selected": false,
"text": "public static string ValueOrDefault(this string str) \n{\n if (String.IsNullOrEmpty(str)) return MY_DEFAULT_VALUE;\n else return str;\n}\n"
},
{
"answer_id": 170731,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 6,
"selected": true,
"text": "public static T SafeConvert<T>(string s, T defaultValue)\n{\n if ( string.IsNullOrEmpty(s) )\n return defaultValue;\n return (T)Convert.ChangeType(s, typeof(T));\n}\n SafeConvert(null, 0.0) == 0.0;\nSafeConvert(\"\", 0.0) == 0.0;\nSafeConvert(\"0\", 0.0) == 0.0;\n 0 In32 0L Int64"
},
{
"answer_id": 40712599,
"author": "reza.cse08",
"author_id": 2597706,
"author_profile": "https://Stackoverflow.com/users/2597706",
"pm_score": 1,
"selected": false,
"text": "public static class SafeConverter\n{\n public static T SafeConvert<T>(object input, T defaultValue)\n {\n if (input == null)\n return defaultValue; //default(T);\n\n T result;\n try\n {\n result = (T)Convert.ChangeType(input.ToString(), typeof(T));\n }\n catch\n {\n result = defaultValue; //default(T);\n }\n return result;\n }\n} \n SafeConverter.SafeConvert<ushort>(null, 0);\nSafeConverter.SafeConvert<ushort>(\"\", 0);\nSafeConverter.SafeConvert<ushort>(\"null\", 0);\nSafeConverter.SafeConvert<ushort>(\"-1\", 0);\nSafeConverter.SafeConvert<ushort>(\"6\", 0);\nSafeConverter.SafeConvert<ushort>(-1, 0);\nSafeConverter.SafeConvert<ushort>(0, 0);\nSafeConverter.SafeConvert<ushort>(1, 0);\nSafeConverter.SafeConvert<ushort>(9, 0);\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/232/"
] |
170,686
|
<p>I am looking for a simple, clean, correct XML parser to use in my C++ project. Should I write my own?</p>
|
[
{
"answer_id": 2822072,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "class Address\n{ \n std::string name;\n std::vector<LONG64> number;\n time_t date;\n};\n Address soap_read_Address soap_write_Address Address *a = new Address();\na = ...;\nsoap ctx = soap_new();\nsoap_write_Address(ctx, a);\nsoap_end(ctx);\nsoap_free(ctx);`\n Address a"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25142/"
] |
170,689
|
<p>I've been trying to consider how Row Level Security could be implemented with the Entity Framework. The idea is to have a database agnostic means that would offer methods to restrict the rows coming from the ObjectContext.</p>
<p>Some of my inital ideas have involved modifying the partial classes created by the EDMGEN tool and that has offered some limited support. Users are still able to get around this solution by using their own eSQL statements and a QueryObject. </p>
<p>I've been looking for a comprehensive solution that would exist above the database providers so that it would remain agnostic.</p>
|
[
{
"answer_id": 35365393,
"author": "David Silva-Barrera",
"author_id": 5411172,
"author_profile": "https://Stackoverflow.com/users/5411172",
"pm_score": 0,
"selected": false,
"text": "Views WHERE Triggers Views select * from table"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15439/"
] |
170,697
|
<p>I'm changing my site to show friendly URLs like this:</p>
<pre><code>www.example.com/folder/topic
</code></pre>
<p>Works fine!</p>
<p>But when I add a parameter to the URL:</p>
<pre><code>www.example.com/folder/topic?page=2
</code></pre>
<p><code>$_GET</code> stops working. It doesn't recognise the parameter at all. Am I missing something? The parameter worked fine before using full URLs.</p>
|
[
{
"answer_id": 170714,
"author": "Zebra North",
"author_id": 17440,
"author_profile": "https://Stackoverflow.com/users/17440",
"pm_score": 3,
"selected": false,
"text": "[QSA] RewriteRule from to [QSA]"
},
{
"answer_id": 170717,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 0,
"selected": false,
"text": "print_r($_GET) www.example.com/folder/topic?page=2"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
170,730
|
<p>I've been working with sessions, MVC design and object oriented PHP. Where should I save or retrieve data from a session? I would like to retrieve it from within methods so I don't have to pass the data to the methods. Whats the best practice?</p>
|
[
{
"answer_id": 170949,
"author": "leek",
"author_id": 3765,
"author_profile": "https://Stackoverflow.com/users/3765",
"pm_score": 2,
"selected": false,
"text": "$_SESSION['Zend_Auth']['user'] = \"myusername\";\n $authNamespace = new Zend_Session_Namespace('Zend_Auth');\n$authNamespace->user = \"myusername\";\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25143/"
] |
170,787
|
<p>From <a href="http://support.microsoft.com/kb/317277" rel="nofollow noreferrer">http://support.microsoft.com/kb/317277</a>:
If Windows XP restarts because of a serious error, the Windows Error Reporting tool prompts you...</p>
<p>How can <em>my</em> app know that "Windows XP has restarted because of a serious error"?</p>
|
[
{
"answer_id": 170812,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 4,
"selected": true,
"text": "net stats workstation | find /i \"since\"\n Get-EventLog -list | Where-Object {$_.logdisplayname -eq \"System\"}\n Set colEvents = objWMIService.ExecQuery _\n (\"Select * from Win32_NTLogEvent Where LogFile = 'System' AND\n TimeWritten >= '\" _\n & dtmStartDate & \"' and TimeWritten < '\" & dtmEndDate & \"'\")\n Save Dump Win32_NTLogEvent strComputer = \".\"\nSet objWMIService = GetObject(\"winmgmts:\" _\n & \"{impersonationLevel=impersonate}!\\\\\" & strComputer & \"\\root\\cimv2\")\nSet colLoggedEvents = objWMIService.ExecQuery _\n (\"SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'System'\" _\n & \" AND SourceName = 'Save Dump'\")\nFor Each objEvent in colLoggedEvents\n Wscript.Echo \"Event date: \" & objEvent.TimeGenerated\n Wscript.Echo \"Description: \" & objEvent.Message\nNext\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1047/"
] |
170,791
|
<p>I'm creating a .net custom control and it should be able to load multiple text files. I have a public property named ListFiles with those properties set : </p>
<pre><code>
[Browsable(true), Category("Configuration"), Description("List of Files to Load")]
public string ListFiles
{
get { return m_oList; }
set { m_oList = value; }
}
</code></pre>
<p>Depending upon the type of object, (string, string[], List, ...), the property grid will allow the user to enter some data.. My goal would be to have a filtered openfiledialog in the Properties Grid of my component that would enable the user to choose multiple files and return it as an array or string (or something else...).</p>
<p>Sooo... Here's my question : <strong>How can I get an OpenFileDialog in a custom control's property grid?</strong></p>
<p>Thanks a lot!</p>
|
[
{
"answer_id": 2373374,
"author": "SerGiant",
"author_id": 285543,
"author_profile": "https://Stackoverflow.com/users/285543",
"pm_score": 4,
"selected": false,
"text": "[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]\n\npublic string SomeFilePath\n{\n get;\n set;\n}\n"
},
{
"answer_id": 56064211,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "using System.Windows.Forms;\nusing System.Windows.Forms.Design;\n\nnamespace YourNameSpace\n{\n class CustomFileBrowser : FileNameEditor\n {\n protected override void InitializeDialog(OpenFileDialog openFileDialog)\n {\n base.InitializeDialog(openFileDialog);\n openFileDialog.Title = \"Select Project File : \";\n openFileDialog.Filter = \"Project File (*.proj)|*.proj\"; ;\n }\n }\n\n}\n [Category(\"Settings\"), DisplayName(\"Project File:\")]\n [EditorAttribute(typeof(CustomFileBrowser), typeof(System.Drawing.Design.UITypeEditor))]\n public string Project_File { get; set; }\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25152/"
] |
170,824
|
<p>I want to use the Date::ABBR_MONTHS constant in my rails application. I see the Ruby stdlib documentation at <a href="http://www.ruby-doc.org/stdlib/" rel="nofollow noreferrer">http://www.ruby-doc.org/stdlib/</a> which does not seem to have this constant.
However, this constant is there at <a href="http://stdlib.rubyonrails.org/" rel="nofollow noreferrer">http://stdlib.rubyonrails.org/</a></p>
<p>What is the difference between these two libraries?</p>
<p>This constant is working on my unix deployment machine but not on my dev machine on windows. Can anybody explain whats going on?</p>
|
[
{
"answer_id": 171135,
"author": "Ryan Bigg",
"author_id": 15245,
"author_profile": "https://Stackoverflow.com/users/15245",
"pm_score": 3,
"selected": true,
"text": "ABBR_MONTHS"
},
{
"answer_id": 171990,
"author": "webmat",
"author_id": 6349,
"author_profile": "https://Stackoverflow.com/users/6349",
"pm_score": 1,
"selected": false,
"text": "require 'rubygems' #If not already done\nrequire 'activesupport'\nputs Date::Format::ABBR_MONTHS.inspect\n#=> {\"oct\"=>10, \"jul\"=>7, \"jan\"=>1, \"dec\"=>12, \"jun\"=>6, \"apr\"=>4, \"feb\"=>2, \"may\"=>5, \"sep\"=>9, \"aug\"=>8, \"mar\"=>3, \"nov\"=>11}\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17494/"
] |
170,825
|
<p>I need to serialize the System.Configuration.SettingsProperty and System.Configuration.SettingsPropertyValue class object through WCF.</p>
|
[
{
"answer_id": 170932,
"author": "Bob Nadler",
"author_id": 2514,
"author_profile": "https://Stackoverflow.com/users/2514",
"pm_score": 2,
"selected": false,
"text": "SettingsProvider Settings [SettingsProvider(typeof(CustomSettingsProvider))]\ninternal sealed partial class Settings { \n ...\n}\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16439/"
] |
170,850
|
<p>The application I am currently working on generates a lot of SQL inline queries. All generated SQL is then handed off to a database execution class. I want to write a parsing service for the data execution class that will take a query like this:</p>
<pre><code>SELECT field1, field2, field3 FROM tablename WHERE foo=1 AND bar="baz"
</code></pre>
<p>and turn it into something like this:</p>
<pre><code>SELECT field1, field2, field3 FROM tablename WHERE foo=@p1 AND bar=@p2 blah blah blah
</code></pre>
<p>Any thing already written that will accomplish this for me in c# or vb.net? This is intended as a stop gap prior to refactoring the DAL for this project.</p>
<p><strong>UPDATE:</strong> Guys I have a huge application that was ported from Classic ASP to ASP.NET with literally thousands of lines of inline SQL. The only saving grace is all of the generated sql is handed off to a data execution class. I want to capture the sql prior to execution and parameterize them on the fly as a stop gap to rewriting the whole app. </p>
|
[
{
"answer_id": 170917,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 0,
"selected": false,
"text": "command.CommandText = \"SELECT * FROM table WHERE key_field='?'\"\ncommand.Parameters.Append command.CreateParameter(, 8, , , \"value\") '8 is adBSTR value\nset rsTemp = command.Execute\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170850",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/303/"
] |
170,854
|
<p>I'm writing a game in Java, and I want the user to be able to provide input from both the command line and my GUI. Currently, I use this method to get input:<br></p>
<pre><code> static String getInput(){
System.out.println("Your move:");
Scanner sc = new Scanner(System.in);
return sc.nextLine();
}
</code></pre>
<p>I want to keep using this, but let a mousePressed event emulate the user actually typing in their input as well. It's not that efficient of a solution, but it makes sense in my application. So the question is: how do I simulate a user typing to System.in from the code side?</p>
|
[
{
"answer_id": 170881,
"author": "Jason Cohen",
"author_id": 4926,
"author_profile": "https://Stackoverflow.com/users/4926",
"pm_score": 0,
"selected": false,
"text": "public interface IGameInteraction\n{\n public String askForMove( String prompt );\n public boolean askAreYouSure( String prompt );\n}\n"
},
{
"answer_id": 171187,
"author": "McDowell",
"author_id": 304,
"author_profile": "https://Stackoverflow.com/users/304",
"pm_score": 2,
"selected": true,
"text": "public class GameInput {\n\n private Scanner scanner;\n\n /**CLI constructor*/\n public GameInput() {\n scanner = new Scanner(System.in);\n }\n\n /**GUI constructor*/\n public GameInput(PipedOutputStream out) throws IOException {\n InputStream in = new PipedInputStream(out);\n scanner = new Scanner(in);\n }\n\n public String getInput() {\n return scanner.nextLine();\n }\n\n public static void main(String[] args) throws IOException {\n GameInput gameInput;\n\n PipedOutputStream output = new PipedOutputStream();\n final PrintWriter writer = new PrintWriter(output);\n gameInput = new GameInput(output);\n\n final JTextField textField = new JTextField(30);\n final JButton button = new JButton(\"OK\");\n button.addActionListener(new ActionListener() {\n @Override\n public void actionPerformed(ActionEvent e) {\n String data = textField.getText();\n writer.println(data);\n writer.flush();\n }\n });\n\n JFrame frame = new JFrame();\n frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n frame.getContentPane().setLayout(new FlowLayout());\n frame.getContentPane().add(textField);\n frame.getContentPane().add(button);\n frame.pack();\n frame.setVisible(true);\n\n String data = gameInput.getInput();\n System.out.println(\"Input=\" + data);\n System.exit(0);\n }\n\n}\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10601/"
] |
170,900
|
<blockquote>
<p><strong>Edit</strong>: Now I need to solve this problem for real, I did a little more
investigation and came up with a
number of things to reduce duplicate
content. I posted detailed code
samples on my blog: <a href="http://blog.dantup.me.uk/2009/04/reducing-duplicate-content-with-aspnet.html" rel="nofollow noreferrer">Reducing
Duplicate Content with ASP.NET MVC</a></p>
</blockquote>
<p>First post - go easy if I've marked this up wrong or tagged it badly :P</p>
<p>In Microsoft's new ASP.NET MVC framework it seems there are two things that could cause your content to be served up at multiple URLs (something which Google penalize for and will cause your PageRank to be split across them):</p>
<ul>
<li>Case-insensitive URLs</li>
<li>Default URL</li>
</ul>
<p>You can set the default controller/action to serve up for requests to the root of your domain. Let's say we choose HomeController/Index. We end up with the following URLs serving up the same content:</p>
<ul>
<li><code>example.com/</code></li>
<li><code>example.com/Home/Index</code></li>
</ul>
<p>Now if people start linking to both of these then PageRank would be split. Google would also consider it duplicate content and penalize one of them to avoid duplicates in their results.</p>
<p>On top of this, the URLs are not case sensitive, so we actually get the same content for these URLs too:</p>
<ul>
<li><code>example.com/Home/Index</code></li>
<li><code>example.com/home/index</code></li>
<li><code>example.com/Home/index</code></li>
<li><code>example.com/home/Index</code></li>
<li>(the list goes on)</li>
</ul>
<p>So, the question... How do I avoid these penalties? I would like:</p>
<ul>
<li>All requests for the default action to be redirected (301 status) to the same URL</li>
<li>All URLs to be case sensitive</li>
</ul>
<p>Possible?</p>
|
[
{
"answer_id": 170955,
"author": "Danny Tuppeny",
"author_id": 25124,
"author_profile": "https://Stackoverflow.com/users/25124",
"pm_score": 3,
"selected": false,
"text": "public class LowercaseConstraint : IRouteConstraint\n{\n public bool Match(HttpContextBase httpContext, Route route,\n string parameterName, RouteValueDictionary values,\n RouteDirection routeDirection)\n {\n string value = (string)values[parameterName];\n\n return Equals(value, value.ToLower());\n }\n public static void RegisterRoutes(RouteCollection routes)\n{\n routes.IgnoreRoute(\"{resource}.axd/{*pathInfo}\");\n\n routes.MapRoute(\n \"Default\", // Route name\n \"{controller}/{action}/{id}\", // URL with parameters\n new { controller = \"home\", action = \"index\", id = \"\" },\n new { controller = new LowercaseConstraint(), action = new LowercaseConstraint() }\n );\n}\n"
},
{
"answer_id": 170983,
"author": "Gabe Sumner",
"author_id": 12689,
"author_profile": "https://Stackoverflow.com/users/12689",
"pm_score": 4,
"selected": false,
"text": "protected void Application_BeginRequest(Object sender, EventArgs e)\n{\n // If upper case letters are found in the URL, redirect to lower case URL.\n if (Regex.IsMatch(HttpContext.Current.Request.Url.ToString(), @\"[A-Z]\") == true)\n {\n string LowercaseURL = HttpContext.Current.Request.Url.ToString().ToLower();\n\n Response.Clear();\n Response.Status = \"301 Moved Permanently\";\n Response.AddHeader(\"Location\",LowercaseURL);\n Response.End();\n }\n}\n"
},
{
"answer_id": 11163678,
"author": "Timbo",
"author_id": 4310,
"author_profile": "https://Stackoverflow.com/users/4310",
"pm_score": 2,
"selected": false,
"text": "<link rel=\"canonical\" href=\"http://example.com/Home/Index\"/>\n"
},
{
"answer_id": 13245920,
"author": "Mahmoud Al-Qudsi",
"author_id": 17027,
"author_profile": "https://Stackoverflow.com/users/17027",
"pm_score": 1,
"selected": false,
"text": "canonical Seo.SeoRedirect(this);\n Index"
},
{
"answer_id": 35006464,
"author": "Asad Ali",
"author_id": 3395204,
"author_profile": "https://Stackoverflow.com/users/3395204",
"pm_score": 0,
"selected": false,
"text": " [Route(\"~/\")]\n public ActionResult Index(int? page)\n {\n var query = from p in db.Posts orderby p.post_date descending select p;\n var pageNumber = page ?? 1;\n ViewData[\"Posts\"] = query.ToPagedList(pageNumber, 7); \n return View();\n }\n [Route(\"about\")]\n public ActionResult About()\n {\n return View();\n }\n [Route(\"contact\")]\n public ActionResult Contact()\n {\n return View();\n }\n [Route(\"team\")]\n public ActionResult Team()\n {\n return View();\n }\n [Route(\"services\")]\n public ActionResult Services()\n {\n return View();\n }\n"
},
{
"answer_id": 41279532,
"author": "Anestis Kivranoglou",
"author_id": 850980,
"author_profile": "https://Stackoverflow.com/users/850980",
"pm_score": 3,
"selected": true,
"text": " public static void RegisterRoutes(RouteCollection routes)\n {\n routes.LowercaseUrls = true;\n routes.AppendTrailingSlash = false;\n }\n http://yourdomain.example/en https://yourClientIdAt.YourHostingPacket.example/ public static String GetCanonicalUrl(RouteData route,String host,string protocol)\n{\n //These rely on the convention that all your links will be lowercase!\n string actionName = route.Values[\"action\"].ToString().ToLower();\n string controllerName = route.Values[\"controller\"].ToString().ToLower();\n //If your app is multilanguage and your route contains a language parameter then lowercase it also to prevent EN/en/ etc....\n //string language = route.Values[\"language\"].ToString().ToLower();\n return String.Format(\"{0}://{1}/{2}/{3}/{4}\", protocol, host, language, controllerName, actionName);\n}\n"
},
{
"answer_id": 51666485,
"author": "Edwin Stoteler",
"author_id": 2074825,
"author_profile": "https://Stackoverflow.com/users/2074825",
"pm_score": 0,
"selected": false,
"text": "public class RedirectFilterAttribute : ActionFilterAttribute\n{\n public override void OnActionExecuting(ActionExecutingContext filterContext)\n {\n var url = filterContext.HttpContext.Request.Url;\n var urlWithoutQuery = url.GetLeftPart(UriPartial.Path);\n if (Regex.IsMatch(urlWithoutQuery, @\"[A-Z]\"))\n {\n string lowercaseURL = urlWithoutQuery.ToString().ToLower() + url.Query;\n filterContext.Result = new RedirectResult(lowercaseURL, permanent: true);\n }\n\n base.OnActionExecuting(filterContext);\n }\n}\n filters.Add(new RedirectFilterAttribute());\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170900",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25124/"
] |
170,907
|
<p>I have seen a few mentions of this idiom (including <a href="https://stackoverflow.com/questions/9033/hidden-features-of-c#9282">on SO</a>):</p>
<pre><code>// Deliberately empty subscriber
public event EventHandler AskQuestion = delegate {};
</code></pre>
<p>The upside is clear - it avoids the need to check for null before raising the event.</p>
<p><strong>However, I am keen to understand if there are any downsides.</strong> For example, is it something that is in widespread use and is transparent enough that it won't cause a maintenance headache? Is there any appreciable performance hit of the empty event subscriber call?</p>
|
[
{
"answer_id": 170979,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 3,
"selected": false,
"text": "internal static class Foo\n{\n internal static readonly EventHandler EmptyEvent = delegate { };\n}\npublic class Bar\n{\n public event EventHandler SomeEvent = Foo.EmptyEvent;\n}\n"
},
{
"answer_id": 171200,
"author": "Kent Boogaart",
"author_id": 5380,
"author_profile": "https://Stackoverflow.com/users/5380",
"pm_score": 5,
"selected": false,
"text": "For 50000000 iterations . . .\nNo null check (empty delegate attached): 530ms\nWith null check (no delegates attached): 249ms\nWith null check (with delegate attached): 452ms\n using System;\nusing System.Diagnostics;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n public event EventHandler<EventArgs> EventWithDelegate = delegate { };\n public event EventHandler<EventArgs> EventWithoutDelegate;\n\n static void Main(string[] args)\n {\n //warm up\n new Program().DoTimings(false);\n //do it for real\n new Program().DoTimings(true);\n\n Console.WriteLine(\"Done\");\n Console.ReadKey();\n }\n\n private void DoTimings(bool output)\n {\n const int iterations = 50000000;\n\n if (output)\n {\n Console.WriteLine(\"For {0} iterations . . .\", iterations);\n }\n\n //with anonymous delegate attached to avoid null checks\n var stopWatch = Stopwatch.StartNew();\n\n for (var i = 0; i < iterations; ++i)\n {\n RaiseWithAnonDelegate();\n }\n\n stopWatch.Stop();\n\n if (output)\n {\n Console.WriteLine(\"No null check (empty delegate attached): {0}ms\", stopWatch.ElapsedMilliseconds);\n }\n\n\n //without any delegates attached (null check required)\n stopWatch = Stopwatch.StartNew();\n\n for (var i = 0; i < iterations; ++i)\n {\n RaiseWithoutAnonDelegate();\n }\n\n stopWatch.Stop();\n\n if (output)\n {\n Console.WriteLine(\"With null check (no delegates attached): {0}ms\", stopWatch.ElapsedMilliseconds);\n }\n\n\n //attach delegate\n EventWithoutDelegate += delegate { };\n\n\n //with delegate attached (null check still performed)\n stopWatch = Stopwatch.StartNew();\n\n for (var i = 0; i < iterations; ++i)\n {\n RaiseWithoutAnonDelegate();\n }\n\n stopWatch.Stop();\n\n if (output)\n {\n Console.WriteLine(\"With null check (with delegate attached): {0}ms\", stopWatch.ElapsedMilliseconds);\n }\n }\n\n private void RaiseWithAnonDelegate()\n {\n EventWithDelegate(this, EventArgs.Empty);\n }\n\n private void RaiseWithoutAnonDelegate()\n {\n var handler = EventWithoutDelegate;\n\n if (handler != null)\n {\n handler(this, EventArgs.Empty);\n }\n }\n }\n}\n"
},
{
"answer_id": 264413,
"author": "Scott P",
"author_id": 33848,
"author_profile": "https://Stackoverflow.com/users/33848",
"pm_score": 2,
"selected": false,
"text": "MyEvent(this, EventArgs.Empty);\n try\n{\n MyEvent(this, EventArgs.Empty);\n}\ncatch\n{\n}\n // Usage\nEventHelper.Fire(MyEvent, this, EventArgs.Empty);\n\n\npublic static void Fire(EventHandler del, object sender, EventArgs e)\n{\n UnsafeFire(del, sender, e);\n}\nprivate static void UnsafeFire(Delegate del, params object[] args)\n{\n if (del == null)\n {\n return;\n }\n Delegate[] delegates = del.GetInvocationList();\n\n foreach (Delegate sink in delegates)\n {\n try\n {\n sink.DynamicInvoke(args);\n }\n catch\n { }\n }\n}\n"
},
{
"answer_id": 302879,
"author": "Judah Gabriel Himango",
"author_id": 536,
"author_profile": "https://Stackoverflow.com/users/536",
"pm_score": 6,
"selected": false,
"text": "public static void Raise(this EventHandler handler, object sender, EventArgs e)\n{\n if(handler != null)\n {\n handler(sender, e);\n }\n}\n // Works, even for null events.\nMyButtonClick.Raise(this, EventArgs.Empty);\n"
},
{
"answer_id": 4003195,
"author": "Thomas",
"author_id": 484949,
"author_profile": "https://Stackoverflow.com/users/484949",
"pm_score": -1,
"selected": false,
"text": "public class X\n{\n public delegate void MyDelegate();\n public MyDelegate MyFunnyCallback = delegate() { }\n\n public void DoSomething()\n {\n MyFunnyCallback();\n }\n}\n\n\nX x = new X();\n\nx.MyFunnyCallback = delegate() { Console.WriteLine(\"Howdie\"); }\n\nx.DoSomething(); // works fine\n\n// .. re-init x\nx.MyFunnyCallback = null;\n\n// .. continue\nx.DoSomething(); // crashes with an exception\n"
},
{
"answer_id": 31926525,
"author": "Sergey Kalinichenko",
"author_id": 335858,
"author_profile": "https://Stackoverflow.com/users/335858",
"pm_score": 2,
"selected": false,
"text": "delegateThatCouldBeNull?.Invoke(this, value);\n ?."
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1853/"
] |
170,909
|
<p>In C/C++, how would I turn a blocking socket into a non blocking socket in both WinSocks and *nix; so that select() would work correctly. You can use the pre-processor for the platform specific code.</p>
|
[
{
"answer_id": 170929,
"author": "hazzen",
"author_id": 5066,
"author_profile": "https://Stackoverflow.com/users/5066",
"pm_score": 4,
"selected": true,
"text": "fcntl(fd, F_SETFL, O_NONBLOCK);\n u_long on = 1;\nioctlsocket(fd, FIONBIO, &on);\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9418/"
] |
170,931
|
<p>I have a list of things (I'll call it L), an index(N) and a new thing(NEW). If I want to replace the thing in L at N with NEW, what is the best way to do this? Should I get the sublist up to N and from N to the end of the list and then glue together a new list from the first part, NEW, and the last part using list? Or is there a better way to do this?</p>
|
[
{
"answer_id": 170948,
"author": "hazzen",
"author_id": 5066,
"author_profile": "https://Stackoverflow.com/users/5066",
"pm_score": 3,
"selected": false,
"text": "(define (replace-nth list n elem)\n (cond\n ((null? list) ())\n ((eq? n 0) (cons elem (cdr list)))\n (#t (cons (car list) (replace-nth (cdr list) (- n 1) elem)))))\n"
},
{
"answer_id": 170993,
"author": "l0st3d",
"author_id": 5100,
"author_profile": "https://Stackoverflow.com/users/5100",
"pm_score": 5,
"selected": false,
"text": "(setf (nth N L) NEW)\n"
},
{
"answer_id": 171376,
"author": "Nathan Shively-Sanders",
"author_id": 7851,
"author_profile": "https://Stackoverflow.com/users/7851",
"pm_score": 2,
"selected": false,
"text": "(setq A (make-array 5) :initial-contents '(4 3 0 2 1))\n(setf (elt 2 A) 'not-a-number)\n elt elt setf make-array (defun replace1 (list n elem)\n (cond\n ((null list) ())\n ((= n 0) (cons elem list))\n (t (cons (car list) (replace1 (cdr list) (1- n) elem)))))\n"
},
{
"answer_id": 171504,
"author": "Mikael Jansson",
"author_id": 18753,
"author_profile": "https://Stackoverflow.com/users/18753",
"pm_score": 0,
"selected": false,
"text": "(loop for x in list do ...)"
},
{
"answer_id": 172113,
"author": "Dan Weinreb",
"author_id": 25275,
"author_profile": "https://Stackoverflow.com/users/25275",
"pm_score": 3,
"selected": false,
"text": "(setf (nth N L) T)\n"
},
{
"answer_id": 172146,
"author": "user25281",
"author_id": 25281,
"author_profile": "https://Stackoverflow.com/users/25281",
"pm_score": 2,
"selected": false,
"text": "(define (replace-nth list n elem)\n (cond \n ((null? list) ())\n ((eq? n 0) (cons elem list))\n (#t (cons(car list) (replace-nth (cdr list) (- n 1) elem)))))\n\n> (replace-nth (list 3 2 9 2) 2 8)\n(3 2 8 9 2)\n (define (replace-nth list n elem)\n (cond \n ((null? list) ())\n ((eq? n 0) (cons elem (cdr list)))\n (#t (cons(car list) (replace-nth (cdr list) (- n 1) elem)))))\n\n> (replace-nth (list 3 2 9 2) 2 8)\n(3 2 8 2)\n"
},
{
"answer_id": 185951,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "(replace L (list X) :start1 N)\n"
},
{
"answer_id": 4928303,
"author": "M L",
"author_id": 607367,
"author_profile": "https://Stackoverflow.com/users/607367",
"pm_score": -1,
"selected": false,
"text": "(defun replace-nth-from-list (list n elem) \n (cond \n ((null list) ()) \n (t (append (subseq list 0 n) elem (subseq list (+ 1 n)(length list))))))\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170931",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/85/"
] |
170,937
|
<p>I am thinking about making a website with some fairly intense JavaScript/canvas usage and I have been looking at <a href="http://ejohn.org/blog/processingjs/" rel="nofollow noreferrer">Processing.js</a> and it seems to me that it would make manipulating the canvas significantly easier. Does anyone know any reasons why I <strong>shouldn't</strong> use Processing.js? I understand that older browsers won't be able to use it, but for now that's ok.</p>
|
[
{
"answer_id": 171333,
"author": "Leo",
"author_id": 20689,
"author_profile": "https://Stackoverflow.com/users/20689",
"pm_score": 3,
"selected": true,
"text": "function line (x1, y1, x2, y2) {\n context.beginPath();\n context.moveTo(x1, y1);\n context.lineTo(x2, y2);\n context.closePath();\n context.stroke();\n};\n var p = Processing(\"canvas\")\np.stroke(255)\n\n////Draw lines...///\np.line(0,0,10,10)\np.line(10,10,20,10)\n//...and so on\np.line(100,100,200,200)\n////End lines////\n context.strokeStyle = \"#fff\";\ncontext.beginPath();\n\n////Draw lines...///\ncontext.moveTo(0, 0);\ncontext.lineTo(10, 10);\ncontext.lineTo(20, 10);\n//...so on\ncontext.lineTo(200, 200);\n////End lines...///\n\ncontext.closePath();\ncontext.stroke();\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12448/"
] |
170,938
|
<p>For PHP, what is the default time after which an HTTP request is deemed to have timed out? </p>
<p>I'm using the PECL HTTP extension to make HTTP requests. I can set a timeout limit when making a request, however I'd like to know what the default is if nothing is explicitly specified.</p>
<p>I've hunted through the PHP manual to no avail. I'd appreciate answers supported by evidence, such as a link to the relevant manual page, as opposed to speculative suggestions.</p>
<p>I'm keen to find out what the default timeout <em>actually</em> is not just what it <em>probably</em> is. I can guess it may <em>probably</em> be 30 seconds as this seems a reasonable value, however I can find nothing to confirm or deny this.</p>
|
[
{
"answer_id": 14536661,
"author": "user222758",
"author_id": 222758,
"author_profile": "https://Stackoverflow.com/users/222758",
"pm_score": 2,
"selected": false,
"text": "CURLOPT_TIMEOUT_MS CURLOPT_TIMEOUT CURLOPT_CONNECTTIMEOUT_MS CURLOPT_CONNECTTIMEOUT CURLOPT_DNS_CACHE_TIMEOUT"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5343/"
] |
170,950
|
<p>Let's say I have a database, and an RSS feed. I have to find out what is the new data from an RSS feed, that isn't already in the database. How would you go about approaching this problem?</p>
|
[
{
"answer_id": 170974,
"author": "Robert Rossney",
"author_id": 19403,
"author_profile": "https://Stackoverflow.com/users/19403",
"pm_score": 2,
"selected": false,
"text": "guid link guid link pubDate"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170950",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
170,956
|
<p>I want my Ruby program to do different things on a Mac than on Windows. How can I find out on which system my program is running?</p>
|
[
{
"answer_id": 170967,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 4,
"selected": false,
"text": "irb(main):002:0> require 'rbconfig'\n=> true\nirb(main):003:0> Config::CONFIG[\"arch\"]\n=> \"i686-linux\"\n irb(main):004:0> RUBY_PLATFORM\n=> \"i686-linux\"\n"
},
{
"answer_id": 171011,
"author": "Aaron Hinni",
"author_id": 12086,
"author_profile": "https://Stackoverflow.com/users/12086",
"pm_score": 7,
"selected": false,
"text": "RUBY_PLATFORM module OS\n def OS.windows?\n (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil\n end\n\n def OS.mac?\n (/darwin/ =~ RUBY_PLATFORM) != nil\n end\n\n def OS.unix?\n !OS.windows?\n end\n\n def OS.linux?\n OS.unix? and not OS.mac?\n end\n\n def OS.jruby?\n RUBY_ENGINE == 'jruby'\n end\nend\n"
},
{
"answer_id": 171236,
"author": "Ryan McGeary",
"author_id": 8985,
"author_profile": "https://Stackoverflow.com/users/8985",
"pm_score": 3,
"selected": false,
"text": "gem install launchy require 'launchy'\nLaunchy::Application.new.host_os_family # => :windows, :darwin, :nix, or :cygwin \n"
},
{
"answer_id": 12937724,
"author": "Pikachu",
"author_id": 356965,
"author_profile": "https://Stackoverflow.com/users/356965",
"pm_score": 2,
"selected": false,
"text": "require 'rbconfig'\ninclude Config\n\ncase CONFIG['host_os']\n when /mswin|windows/i\n # Windows\n when /linux|arch/i\n # Linux\n when /sunos|solaris/i\n # Solaris\n when /darwin/i\n #MAC OS X\n else\n # whatever\nend\n"
},
{
"answer_id": 19047549,
"author": "dimus",
"author_id": 23080,
"author_profile": "https://Stackoverflow.com/users/23080",
"pm_score": -1,
"selected": false,
"text": "is_unix = is_win = false\nFile::SEPARATOR == '/' ? is_unix = true : is_win = true\n"
},
{
"answer_id": 19411012,
"author": "jtzero",
"author_id": 237129,
"author_profile": "https://Stackoverflow.com/users/237129",
"pm_score": 5,
"selected": false,
"text": "irb(main):001:0> Gem::Platform.local\n=> #<Gem::Platform:0x151ea14 @cpu=\"x86\", @os=\"mingw32\", @version=nil>\nirb(main):002:0> Gem::Platform.local.os\n=> \"mingw32\"\n Gem::Platform.local.os == 'java'"
},
{
"answer_id": 34881562,
"author": "adamliesko",
"author_id": 1212336,
"author_profile": "https://Stackoverflow.com/users/1212336",
"pm_score": 2,
"selected": false,
"text": " def self.windows?\n return File.exist? \"c:/WINDOWS\" if RUBY_PLATFORM == 'java'\n RUBY_PLATFORM =~ /mingw32/ || RUBY_PLATFORM =~ /mswin32/\n end\n\n def self.linux?\n return File.exist? \"/usr\" if RUBY_PLATFORM == 'java'\n RUBY_PLATFORM =~ /linux/\n end\n\n def self.os\n return :linux if self.linux?\n return :windows if self.windows?\n nil\n end\n"
},
{
"answer_id": 40946277,
"author": "olleolleolle",
"author_id": 267348,
"author_profile": "https://Stackoverflow.com/users/267348",
"pm_score": 3,
"selected": false,
"text": "Gem.win_platform? def self.ant_script\n Gem.win_platform? ? 'ant.bat' : 'ant'\nend\n"
},
{
"answer_id": 55169109,
"author": "sondra.kinsey",
"author_id": 5389585,
"author_profile": "https://Stackoverflow.com/users/5389585",
"pm_score": 3,
"selected": false,
"text": "Gem::Platform.local.os Gem.win_platform? RbConfig::CONFIG[\"host_os\"] RbConfig::CONFIG[\"arch\"] RUBY_PLATFORM /cygwin|mswin|mingw|bccwin|wince|emx/ RUBY_ENGINE OS.mac? OS.posix? Platform::IMPL"
},
{
"answer_id": 71084392,
"author": "Dorian",
"author_id": 12544391,
"author_profile": "https://Stackoverflow.com/users/12544391",
"pm_score": 0,
"selected": false,
"text": "os # frozen_string_literal: true\nIMGKit.configure do |config|\n if OS.linux? && OS.host_cpu == \"x86_64\"\n config.wkhtmltoimage =\n Rails.root.join(\"bin\", \"wkhtmltoimage-linux-amd64\").to_s\n elsif OS.mac? && OS.host_cpu == \"x86_64\"\n config.wkhtmltoimage =\n Rails.root.join(\"bin\", \"wkhtmltoimage-macos-amd64\").to_s\n else\n puts OS.report\n abort \"You need to add a binary for wkhtmltoimage for your OS and CPU\"\n end\nend\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
170,961
|
<p>I tried committing files with CRLF-ending lines, but it failed.</p>
<p>I spent a whole work day on my Windows computer trying different strategies and was almost drawn to stop trying to use Git and instead try <a href="http://en.wikipedia.org/wiki/Mercurial" rel="noreferrer">Mercurial</a>.</p>
<p>How to properly handle CRLF line endings?</p>
|
[
{
"answer_id": 171447,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 4,
"selected": false,
"text": "core.autocrlf true core.safecrlf core.safecrlf"
},
{
"answer_id": 1112313,
"author": "Cory",
"author_id": 8207,
"author_profile": "https://Stackoverflow.com/users/8207",
"pm_score": 6,
"selected": false,
"text": "autocrlf=input core.autocrlf=true core.autocrlf=input core.autocrlf=false core.safecrlf"
},
{
"answer_id": 5320629,
"author": "Lance Cleveland",
"author_id": 661761,
"author_profile": "https://Stackoverflow.com/users/661761",
"pm_score": 4,
"selected": false,
"text": "core.autocrlf=false autocrlf = true"
},
{
"answer_id": 10855862,
"author": "Daniel Jomphe",
"author_id": 25167,
"author_profile": "https://Stackoverflow.com/users/25167",
"pm_score": 11,
"selected": true,
"text": ".gitattributes core.autocrlf .gitattributes # Auto detect text files and perform LF normalization\n* text=auto\n\n*.cs text diff=csharp\n*.java text diff=java\n*.html text diff=html\n*.css text\n*.js text\n*.sql text\n\n*.csproj text merge=union\n*.sln text merge=union eol=crlf\n\n*.docx diff=astextplain\n*.DOCX diff=astextplain\n\n# absolute paths are ok, as are globs\n/**/postinst* text eol=lf\n\n# paths that don't start with / are treated relative to the .gitattributes folder\nrelative/path/*.txt text eol=lf\n .gitattributes .gitattributes .gitattributes"
},
{
"answer_id": 11199598,
"author": "lukmdo",
"author_id": 212278,
"author_profile": "https://Stackoverflow.com/users/212278",
"pm_score": 6,
"selected": false,
"text": "find . -type f -not -path \"./.git/*\" -exec dos2unix {} \\;\ngit commit -a -m 'dos2unix conversion'\n core.autocrlf input true git config --global core.autocrlf input\n core.safecrlf true warn git config --global core.safecrlf true\n find . -type f -not -path \"./.git/*\" -exec dos2unix {} \\;\ngit commit -a -m 'dos2unix conversion'\n .gitattributes echo \"* text=auto\" > .gitattributes\ngit add .gitattributes\ngit commit -m 'adding .gitattributes for unified line-ending'\n"
},
{
"answer_id": 15527650,
"author": "John Rumpel",
"author_id": 1020719,
"author_profile": "https://Stackoverflow.com/users/1020719",
"pm_score": 3,
"selected": false,
"text": "[alias] lc = \"!f() { git status --porcelain \\\n | egrep -r \\\"^(\\?| ).\\*\\\\(.[a-zA-Z])*\\\" \\\n | cut -c 4- ; }; f \"\n unix2dos $(git lc)\n grep ... | egrep -r \"^(\\?| ).*\\.(txt|conf)\" | ...\n c2dos = \"!f() { unix2dos $(git lc) ; }; f \"\n git c2dos\n"
},
{
"answer_id": 35399093,
"author": "kiewic",
"author_id": 27211,
"author_profile": "https://Stackoverflow.com/users/27211",
"pm_score": 3,
"selected": false,
"text": ".gitattributes * text=auto\n LF core.eol LF CRLF Hello\\r\\nWorld\n Hello\\nWorld\n Hello\\r\\nWorld\n Hello\\nWorld\n git status text .gitattributes core.autocrlf git config --global core.autocrlf true LF CRLF autocrlf = input LF LF core.autocrlf = false LF CRLF autocrlf = input CRLF core.autocrlf = false"
},
{
"answer_id": 46347609,
"author": "Marinos An",
"author_id": 1555615,
"author_profile": "https://Stackoverflow.com/users/1555615",
"pm_score": 4,
"selected": false,
"text": "CRLF LF LF core.autocrlf core.autocrlf .git/ core.autocrlf core.autocrlf false: input: true core.autocrlf: true core.autocrlf: false core.autocrlf core.autocrlf=false git grep -I --files-with-matches --perl-regexp '\\r' HEAD --with-libpcre git.autocrlf=input .gitattributes *.java text !eol # Don't do auto-detection. Treat as text (don't set any eol rule. use client's)\n*.jpg -text # Don't do auto-detection. Treat as binary\n*.sh text eol=lf # Don't do auto-detection. Treat as text. Checkout and add with eol=lf\n*.bat text eol=crlf # Treat as text. Checkout and add with eol=crlf\n core.autocrlf=true core.autocrlf=input false --global git config core.autocrlf\ngit config --global core.autocrlf\ngit config --system core.autocrlf\ngit config --local core.autocrlf\ngit config --show-origin core.autocrlf\n git config --global core.autocrlf false *.bat *.sh .gitattributes git grep -I --files-with-matches --perl-regexp '\\r' HEAD git-bash --with-libpcre ./configure core.autocrlf=input .gitattributes core.autocrlf .gitattributes # Always checkout with LF\n*.sh text eol=lf\n# Always checkout with CRLF\n*.bat text eol=crlf\n .gitattributes -text *.zip *.jpg text !eol *.java *.html -text -diff -merge *.hugefile core.autocrlf .gitattributes git grep -I --files-with-matches --perl-regexp '\\r' HEAD .gitattributes .gitattributes anti-CRLF core.autocrlf=input .gitattributes * text=auto eol=lf .editorconfig"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170961",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25167/"
] |
170,962
|
<p>I notice sometimes with my parent/child objects or many-to-many relationships, I need to call either <code>SaveOrUpdate</code> or <code>Merge</code>. Usually, when I need to call <code>SaveOrUpdate</code>, the exception I get on calling <code>Merge</code> has to do with transient objects not being saved first.</p>
<p>Please explain the difference between the two.</p>
|
[
{
"answer_id": 171019,
"author": "Ryan Duffield",
"author_id": 2696,
"author_profile": "https://Stackoverflow.com/users/2696",
"pm_score": 3,
"selected": false,
"text": "merge() saveOrUpdate()"
},
{
"answer_id": 5551190,
"author": "Ricardo Peres",
"author_id": 239594,
"author_profile": "https://Stackoverflow.com/users/239594",
"pm_score": 2,
"selected": false,
"text": "SaveOrUpdateCopy() Merge()"
},
{
"answer_id": 21839532,
"author": "Quoc Truong",
"author_id": 3320836,
"author_profile": "https://Stackoverflow.com/users/3320836",
"pm_score": 1,
"selected": false,
"text": "cascade=\"merge\" SaveOrUpdate SaveOrUpdate"
},
{
"answer_id": 29743668,
"author": "Mohit Singh",
"author_id": 2455366,
"author_profile": "https://Stackoverflow.com/users/2455366",
"pm_score": 2,
"selected": false,
"text": "** Update()**\n ** Merge()**\n"
},
{
"answer_id": 35830729,
"author": "Deepak",
"author_id": 2569475,
"author_profile": "https://Stackoverflow.com/users/2569475",
"pm_score": -1,
"selected": false,
"text": "@Entity\n@Table(name=\"emp\")\npublic class Employee implements Serializable {\n private static final long serialVersionUID = 1L;\n @Id\n @GeneratedValue(strategy=GenerationType.AUTO)\n @Column(name=\"emp_id\")\n private int id;\n @Column(name=\"emp_name\")\n private String name;\n @Column(name=\"salary\")\n private int Salary;\n\n\n public String getName() {\n return name;\n }\n\n public void setName(String name) {\n this.name = name;\n }\n\n public int getSalary() {\n return Salary;\n }\n\n public void setSalary(int salary) {\n this.Salary = salary;\n }\n\n public int getId() {\n return id;\n }\n\n public void setId(int id) {\n this.id = id;\n }\n}\n\npublic enum HibernateUtil {\n INSTANCE;\n HibernateUtil(){\n buildSessionFactory();\n }\n private SessionFactory sessionFactory=null;\n\n public SessionFactory getSessionFactory() {\n return sessionFactory;\n }\n\n public void setSessionFactory(SessionFactory sessionFactory) {\n this.sessionFactory = sessionFactory;\n }\n\n private void buildSessionFactory() {\n Configuration configuration = new Configuration();\n\n configuration.addAnnotatedClass (TestRefresh_Merge.Employee.class);\n configuration.setProperty(\"connection.driver_class\",\"com.mysql.jdbc.Driver\");\n configuration.setProperty(\"hibernate.connection.url\", \"jdbc:mysql://localhost:3306/hibernate\"); \n configuration.setProperty(\"hibernate.connection.username\", \"root\"); \n configuration.setProperty(\"hibernate.connection.password\", \"root\");\n configuration.setProperty(\"dialect\", \"org.hibernate.dialect.MySQLDialect\");\n configuration.setProperty(\"hibernate.hbm2ddl.auto\", \"update\");\n configuration.setProperty(\"hibernate.show_sql\", \"true\");\n configuration.setProperty(\" hibernate.connection.pool_size\", \"10\");\n /* configuration.setProperty(\" hibernate.cache.use_second_level_cache\", \"true\");\n configuration.setProperty(\" hibernate.cache.use_query_cache\", \"true\");\n configuration.setProperty(\" cache.provider_class\", \"org.hibernate.cache.EhCacheProvider\");\n configuration.setProperty(\"hibernate.cache.region.factory_class\" ,\"org.hibernate.cache.ehcache.EhCacheRegionFactory\");\n */\n // configuration\n StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());\n sessionFactory = configuration.buildSessionFactory(builder.build());\n setSessionFactory(sessionFactory);\n }\n\n public static SessionFactory getSessionFactoryInstance(){\n return INSTANCE.getSessionFactory();\n }\n} \n\n\npublic class Main {\n public static void main(String[] args) {\n HibernateUtil util=HibernateUtil.INSTANCE;\n SessionFactory factory=util.getSessionFactory();\n //save(factory); \n retrieve(factory);\n }\n\n private static void retrieve(SessionFactory factory) {\n Session sessionOne=factory.openSession();\n\n Employee employee=(Employee)sessionOne.get(Employee.class, 5);\n\n sessionOne.close(); // detached Entity\n\n employee.setName(\"Deepak1\");\n\n Session sessionTwo=factory.openSession();\n\n Employee employee1=(Employee)sessionTwo.get(Employee.class, 5);\n sessionTwo.beginTransaction();\n sessionTwo.saveOrUpdate(employee); // it will throw exception\n\n //sessionTwo.merge(employee); // it will work\n\n sessionTwo.getTransaction().commit();\n\n sessionTwo.close();\n\n }\n\n private static void save(SessionFactory factory) {\n Session sessionOne=factory.openSession();\n Employee emp=new Employee();\n emp.setName(\"Abhi\");\n emp.setSalary(10000);\n sessionOne.beginTransaction();\n try{\n\n sessionOne.save(emp);\n sessionOne.getTransaction().commit();\n }catch(Exception e){\n e.printStackTrace();\n }finally{\n sessionOne.close();\n }\n\n }\n}\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6350/"
] |
170,964
|
<p>In my free time I started writing a small multiplayer game with a database backend. I was looking to separate player login information from other in game information (inventory, stats, and status) and a friend brought up this might not be the best idea.</p>
<p>Would it be better to lump everything together in one table?</p>
|
[
{
"answer_id": 173101,
"author": "terson",
"author_id": 22974,
"author_profile": "https://Stackoverflow.com/users/22974",
"pm_score": 2,
"selected": false,
"text": "CREATE TABLE players(\n id INTEGER NOT NULL,\n username VARCHAR2(32) NOT NULL,\n password VARCHAR2(32) NOT NULL,\n email VARCHAR2(160),\n character VARCHAR2(32) NOT NULL,\n status VARCHAR2(32),\n hitpoints INTEGER,\n\n CONSTRAINT pk_players PRIMARY KEY (uid)\n);\n -- track information on the player\nCREATE TABLE players(\n id INTEGER NOT NULL,\n username VARCHAR2(32) NOT NULL,\n password VARCHAR2(32) NOT NULL,\n email VARCHAR2(160),\n\n CONSTRAINT pk_players PRIMARY KEY (id)\n);\n\n-- track information on the character\nCREATE TABLE characters(\n id INTEGER NOT NULL,\n player_id INTEGER NOT NULL,\n character VARCHAR2(32) NOT NULL,\n status VARCHAR2(32),\n hitpoints INTEGER,\n\n CONSTRAINT pk_characters PRIMARY KEY (id)\n);\n-- foreign key reference\nALTER TABLE characters\n ADD CONSTRAINT characters__players\n FOREIGN KEY (player_id) REFERENCES players (id);\n"
},
{
"answer_id": 330953,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 0,
"selected": false,
"text": "CREATE TABLE Players (\n PlayerID int,\n PlayerName varchar(50),\n ...\n Quest1ID int,\n Quest2ID int,\n Quest3ID int,\n ...\n Quest10ID int,\n ...\n)\n CREATE TABLE Players (\n PlayerID int,\n PlayerName varchar(50),\n ...\n Quest1ID int,\n Quest2ID int,\n Quest3ID int,\n ...\n Quest25ID int,\n ...\n)\n CREATE TABLE Players (\n PlayerID int,\n PlayerName varchar(50),\n ...\n)\n\nCREATE TABLE PlayerQuests (\n PlayerID int,\n QuestID int\n)\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170964",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10357/"
] |
170,986
|
<p>What is the best method for adding options to a <code><select></code> from a JavaScript object using jQuery?</p>
<p>I'm looking for something that I don't need a plugin to do, but I would also be interested in the plugins that are out there.</p>
<p>This is what I did:</p>
<pre><code>selectValues = { "1": "test 1", "2": "test 2" };
for (key in selectValues) {
if (typeof (selectValues[key] == 'string') {
$('#mySelect').append('<option value="' + key + '">' + selectValues[key] + '</option>');
}
}
</code></pre>
<p><strong>A clean/simple solution:</strong></p>
<p>This is a cleaned up and simplified <a href="https://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-select-from-an-array-with-jquery/171007#171007">version of matdumsa's</a>:</p>
<pre><code>$.each(selectValues, function(key, value) {
$('#mySelect')
.append($('<option>', { value : key })
.text(value));
});
</code></pre>
<p>Changes from matdumsa's: (1) removed the close tag for the option inside append() and (2) moved the properties/attributes into an map as the second parameter of append().</p>
|
[
{
"answer_id": 171007,
"author": "matdumsa",
"author_id": 1775,
"author_profile": "https://Stackoverflow.com/users/1775",
"pm_score": 12,
"selected": true,
"text": "$.each(selectValues, function(key, value) { \n $('#mySelect')\n .append($(\"<option></option>\")\n .attr(\"value\", key)\n .text(value)); \n});\n"
},
{
"answer_id": 171515,
"author": "Komang",
"author_id": 19463,
"author_profile": "https://Stackoverflow.com/users/19463",
"pm_score": 4,
"selected": false,
"text": "$(data).each(function(){\n ... Collect items\n})\n $('#select_id').append(items); \n $('#select_id').html(items);\n"
},
{
"answer_id": 172170,
"author": "Nickolay",
"author_id": 1026,
"author_profile": "https://Stackoverflow.com/users/1026",
"pm_score": 5,
"selected": false,
"text": "Option $(new Option('myText', 'val')).appendTo('#mySelect');\n $(\"<option></option>\").attr(\"value\", \"val\").text(\"myText\")).appendTo('#mySelect');\n"
},
{
"answer_id": 1683041,
"author": "gpilotino",
"author_id": 21424,
"author_profile": "https://Stackoverflow.com/users/21424",
"pm_score": 8,
"selected": false,
"text": "var output = [];\n\n$.each(selectValues, function(key, value)\n{\n output.push('<option value=\"'+ key +'\">'+ value +'</option>');\n});\n\n$('#mySelect').html(output.join(''));\n"
},
{
"answer_id": 1699386,
"author": "Teej",
"author_id": 37532,
"author_profile": "https://Stackoverflow.com/users/37532",
"pm_score": 4,
"selected": false,
"text": " var output = [];\n var length = data.length;\n for(var i = 0; i < length; i++)\n {\n output[i++] = '<option value=\"' + data[i].start + '\">' + data[i].start + '</option>';\n }\n\n $('#choose_schedule').get(0).innerHTML = output.join('');\n"
},
{
"answer_id": 1940870,
"author": "m1sfit",
"author_id": 236141,
"author_profile": "https://Stackoverflow.com/users/236141",
"pm_score": 5,
"selected": false,
"text": "$.each(selectData, function(i, option)\n{\n $(\"<option/>\").val(option.id).text(option.title).appendTo(\"#selectBox\");\n});\n auxArr = [];\n$.each(selectData, function(i, option)\n{\n auxArr[i] = \"<option value='\" + option.id + \"'>\" + option.title + \"</option>\";\n});\n\n$('#selectBox').append(auxArr.join(''));\n"
},
{
"answer_id": 2206968,
"author": "H Sampat",
"author_id": 236817,
"author_profile": "https://Stackoverflow.com/users/236817",
"pm_score": 4,
"selected": false,
"text": "function populateDropdown(select, data) { \n select.html(''); \n $.each(data, function(id, option) { \n select.append($('<option></option>').val(option.value).html(option.name)); \n }); \n} \n"
},
{
"answer_id": 2516625,
"author": "willard macay",
"author_id": 301796,
"author_profile": "https://Stackoverflow.com/users/301796",
"pm_score": 4,
"selected": false,
"text": "$('#SelectId').html(\"<option value='0'>select</option><option value='1'>Laguna</option>\");\n"
},
{
"answer_id": 3155663,
"author": "ajevic",
"author_id": 380811,
"author_profile": "https://Stackoverflow.com/users/380811",
"pm_score": 8,
"selected": false,
"text": "var selectValues = {\n \"1\": \"test 1\",\n \"2\": \"test 2\"\n};\nvar $mySelect = $('#mySelect');\n//\n$.each(selectValues, function(key, value) {\n var $option = $(\"<option/>\", {\n value: key,\n text: value\n });\n $mySelect.append($option);\n}); <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script>\n<select id=\"mySelect\"></select>"
},
{
"answer_id": 3200774,
"author": "Nick Josevski",
"author_id": 75963,
"author_profile": "https://Stackoverflow.com/users/75963",
"pm_score": 4,
"selected": false,
"text": "<script src=\"Scripts/jquery.tmpl.js\" type=\"text/javascript\" />\n <script id=\"templateOptionItem\" type=\"text/html\">\n <option value=\\'{{= Value}}\\'>{{= Text}}</option>\n</script>\n var someData = [\n { Text: \"one\", Value: \"1\" },\n { Text: \"two\", Value: \"2\" },\n { Text: \"three\", Value: \"3\"}];\n\n$(\"#templateOptionItem\").render(someData).appendTo(\"#mySelect\");\n"
},
{
"answer_id": 3301440,
"author": "keios",
"author_id": 326212,
"author_profile": "https://Stackoverflow.com/users/326212",
"pm_score": 3,
"selected": false,
"text": "$('<option/>').attr(\"value\",\"someValue\").text(\"Option1\").appendTo(\"#my-select-id\");"
},
{
"answer_id": 3841556,
"author": "joshperry",
"author_id": 30587,
"author_profile": "https://Stackoverflow.com/users/30587",
"pm_score": 4,
"selected": false,
"text": "each selectValues append option Option Option option $('mySelect').append($.map(selectValues, (k, v) => new Option(k, v)))\n const newoption = (...args) => new Option(...args)\n map $('mySelect').append($.map(selectValues, newoption))\n append option apply $.fn.append.apply($('mySelect'), $.map(selectValues, (k, v) => $(\"<option/>\").val(k).text(v)));\n append $('mySelect').append($.map(selectValues, (k, v) => $(\"<option/>\").val(k).text(v)))\n"
},
{
"answer_id": 6194450,
"author": "Carl Hörberg",
"author_id": 80589,
"author_profile": "https://Stackoverflow.com/users/80589",
"pm_score": 7,
"selected": false,
"text": "var list = $(\"#selectList\");\n$.each(items, function(index, item) {\n list.append(new Option(item.text, item.value));\n});\n var list = document.getElementById(\"selectList\");\nfor(var i in items) {\n list.add(new Option(items[i].text, items[i].value));\n}\n"
},
{
"answer_id": 7445320,
"author": "Jack Holt",
"author_id": 284733,
"author_profile": "https://Stackoverflow.com/users/284733",
"pm_score": 4,
"selected": false,
"text": "var options;\n$.each(data, function(index, object) {\n options += '<option value=\"' + object.id + '\">' + object.stop + '</option>';\n});\n\n$('#selectMenu').html(options);\n"
},
{
"answer_id": 11833295,
"author": "DW333",
"author_id": 1373537,
"author_profile": "https://Stackoverflow.com/users/1373537",
"pm_score": 3,
"selected": false,
"text": "for (var i = 0; i < array.length; i++) {\n $('#clientsList').append($(\"<option></option>\").text(array[i].ClientName).val(array[i].ID));\n};\n"
},
{
"answer_id": 11890310,
"author": "LazyZebra",
"author_id": 1203203,
"author_profile": "https://Stackoverflow.com/users/1203203",
"pm_score": 3,
"selected": false,
"text": "innerHTML <option> value <option> $items = $dal->get_new_items(); // Gets data from the database\n$items_arr = array();\n$i = 0;\nforeach ($items as $item)\n{\n $first_name = $item->first_name;\n $last_name = $item->last_name;\n $date = $item->date;\n $show = $first_name . \" \" . $last_name . \", \" . $date;\n $request_id = $request->request_id;\n $items_arr[0][$i] = $show;\n $items_arr[1][$i] = $request_id;\n $i++;\n}\n\necho json_encode($items_arr);\n function ddl_items() {\n if (window.XMLHttpRequest) {\n // Code for Internet Explorer 7+, Firefox, Chrome, Opera, and Safari\n xmlhttp=new XMLHttpRequest();\n }\n else{\n // Code for Internet Explorer 6 and Internet Explorer 5\n xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");\n }\n\n xmlhttp.onreadystatechange=function() {\n if (xmlhttp.readyState==4 && xmlhttp.status==200) {\n var arr = JSON.parse(xmlhttp.responseText);\n var lstbx = document.getElementById('my_listbox');\n\n for (var i=0; i<arr.length; i++) {\n var option = new Option(arr[0][i], arr[1][i]);\n lstbx.options.add(option);\n }\n }\n };\n\n xmlhttp.open(\"GET\", \"Code/get_items.php?dummy_time=\" + new Date().getTime() + \"\", true);\n xmlhttp.send();\n }\n}\n"
},
{
"answer_id": 12527794,
"author": "Michail",
"author_id": 1688238,
"author_profile": "https://Stackoverflow.com/users/1688238",
"pm_score": 3,
"selected": false,
"text": "optionValues0 = {\"4321\": \"option 1\", \"1234\": \"option 2\"};\n optionValues0 = {\"1\": {id: \"4321\", value: \"option 1\"}, \"2\": {id: \"1234\", value: \"option 2\"}};\n $.each(optionValues0, function(order, object) {\n key = object.id;\n value = object.value;\n $('#mySelect').append($('<option>', { value : key }).text(value));\n}); \n"
},
{
"answer_id": 13569166,
"author": "Stuart.Sklinar",
"author_id": 664672,
"author_profile": "https://Stackoverflow.com/users/664672",
"pm_score": 3,
"selected": false,
"text": "var frag = document.createDocumentFragment();\n\nfor(item in data.Events)\n{\n var option = document.createElement(\"option\");\n\n option.setAttribute(\"value\", data.Events[item].Key);\n option.innerText = data.Events[item].Value;\n\n frag.appendChild(option);\n}\neventDrop.empty();\neventDrop.append(frag);\n"
},
{
"answer_id": 16058846,
"author": "mpapec",
"author_id": 223226,
"author_profile": "https://Stackoverflow.com/users/223226",
"pm_score": 5,
"selected": false,
"text": "$(\"#mySelect\").append(\n $.map(selectValues, function(v,k){\n\n return $(\"<option>\").val(k).text(v);\n })\n);\n $(\"#mySelect\").append(\n $.map(selectValues, (v,k) => $(\"<option>\").val(k).text(v))\n // $.map(selectValues, (v,k) => new Option(v, k)) // using plain JS\n);\n"
},
{
"answer_id": 16225464,
"author": "DiverseAndRemote.com",
"author_id": 1681414,
"author_profile": "https://Stackoverflow.com/users/1681414",
"pm_score": 3,
"selected": false,
"text": "var options = []; \n$.each(selectValues, function(key, value) {\n options.push($(\"<option/>\", {\n value: key,\n text: value\n }));\n});\n$('#mySelect').append(options);\n"
},
{
"answer_id": 19142863,
"author": "Christian Roman",
"author_id": 1935765,
"author_profile": "https://Stackoverflow.com/users/1935765",
"pm_score": 3,
"selected": false,
"text": "if (data.length != 0) {\n var opts = \"\";\n for (i in data)\n opts += \"<option value='\"+data[i][value]+\"'>\"+data[i][text]+\"</option>\";\n\n $(\"#myselect\").empty().append(opts);\n}\n"
},
{
"answer_id": 19323826,
"author": "Animism",
"author_id": 953529,
"author_profile": "https://Stackoverflow.com/users/953529",
"pm_score": 4,
"selected": false,
"text": "var options = $('#mySelect').get(0).options;\n$.each(selectValues, function(key, value) {\n options[options.length] = new Option(value, key);\n});\n"
},
{
"answer_id": 25720409,
"author": "MaxEcho",
"author_id": 2459296,
"author_profile": "https://Stackoverflow.com/users/2459296",
"pm_score": 3,
"selected": false,
"text": "$.each for $(\"#mySelect\").append(); resp [\n {\"id\":\"0001\", \"name\":\"Mr. P\"},\n {\"id\":\"0003\", \"name\":\"Mr. Q\"},\n {\"id\":\"0054\", \"name\":\"Mr. R\"},\n {\"id\":\"0061\", \"name\":\"Mr. S\"}\n]\n var option = \"\";\nfor (i=0; i<resp.length; i++) {\n option += \"<option value='\" + resp[i].id + \"'>\" + resp[i].name + \"</option>\";\n}\n$('#mySelect').html(option);\n"
},
{
"answer_id": 33005913,
"author": "Erick Asto Oblitas",
"author_id": 891823,
"author_profile": "https://Stackoverflow.com/users/891823",
"pm_score": 2,
"selected": false,
"text": "var outputConcatenation = [];\n\n$.each(selectValues, function(i, item) { \n outputConcatenation.push($(\"<option></option>\").attr(\"value\", item.key).attr(\"data-customdata\", item.customdata).text(item.text).prop(\"outerHTML\"));\n});\n\n$(\"#myselect\").html(outputConcatenation.join(''));\n"
},
{
"answer_id": 35182275,
"author": "Matt",
"author_id": 3691684,
"author_profile": "https://Stackoverflow.com/users/3691684",
"pm_score": 3,
"selected": false,
"text": "jQuery.fn.addOption = function (key, value) {\n $(this).append($('<option>', { value: key }).text(value));\n};\n $('select').addOption('0', 'None');\n"
},
{
"answer_id": 38672989,
"author": "M.J",
"author_id": 3867577,
"author_profile": "https://Stackoverflow.com/users/3867577",
"pm_score": 3,
"selected": false,
"text": "[{\n \"org_name\": \"Asset Management\"\n}, {\n \"org_name\": \"Debt Equity Foreign services\"\n}, {\n \"org_name\": \"Credit Services\"\n}]\n success: function(json) {\n var options = [];\n $('#org_category').html(''); // Set the Dropdown as Blank before new Data\n options.push('<option>-- Select Category --</option>');\n $.each(JSON.parse(json), function(i, item) {\n options.push($('<option/>',\n {\n value: item.org_name, text: item.org_name\n }));\n });\n $('#org_category').append(options); // Set the Values to Dropdown\n}\n"
},
{
"answer_id": 45019229,
"author": "Dr Fred",
"author_id": 468445,
"author_profile": "https://Stackoverflow.com/users/468445",
"pm_score": 2,
"selected": false,
"text": "$('#mySelect').html( $.map(selectValues, function(val, key){\n return '<option value=\"' + val + '\">'+ key + '</option>';\n}).join(''));\n"
},
{
"answer_id": 47016474,
"author": "Lokesh thakur",
"author_id": 6280146,
"author_profile": "https://Stackoverflow.com/users/6280146",
"pm_score": 2,
"selected": false,
"text": "$.each(selectValues, function(key, value) {\n $('#mySelect').append($(\"<option/>\", {\n value: key, text: value\n }));\n});\n"
},
{
"answer_id": 49560520,
"author": "Satyendra Yadav",
"author_id": 2488558,
"author_profile": "https://Stackoverflow.com/users/2488558",
"pm_score": 2,
"selected": false,
"text": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <title>append selectbox using jquery</title>\n <meta charset=\"utf-8\">\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n\n <script type=\"text/javascript\">\n function setprice(){\n var selectValues = { \"1\": \"test 1\", \"2\": \"test 2\" };\n $.each(selectValues, function(key, value) { \n $('#mySelect')\n .append($(\"<option></option>\")\n .attr(\"value\",key)\n .text(value)); \n});\n\n }\n </script>\n</head>\n<body onload=\"setprice();\">\n\n\n <select class=\"form-control\" id=\"mySelect\">\n <option>1</option>\n <option>2</option>\n <option>3</option>\n <option>4</option>\n </select>\n\n\n</body>\n</html>\n"
},
{
"answer_id": 49767243,
"author": "Du-Lacoste",
"author_id": 3600553,
"author_profile": "https://Stackoverflow.com/users/3600553",
"pm_score": 2,
"selected": false,
"text": "mySelect var options = $(\"#mySelect\");\n $.each(selectValues, function(val, text) {\n options.append(\n $('<option></option>').val(val).html(text)\n );\n });\n"
},
{
"answer_id": 51709593,
"author": "Mark Schultheiss",
"author_id": 125981,
"author_profile": "https://Stackoverflow.com/users/125981",
"pm_score": 1,
"selected": false,
"text": "multiple // objects as value/desc\nlet selectValues = {\n \"1\": \"test 1\",\n \"2\": \"test 2\",\n \"3\": \"test 3\",\n \"4\": \"test Four\"\n};\n//use div here as using \"select\" mucks up the original selected value in \"mySelect\"\nlet opts = $(\"<div />\");\nlet opt = {};\n$.each(selectValues, function(value, desc) {\n opts.append($('<option />').prop(\"value\", value).text(desc));\n});\nopts.find(\"option\").appendTo('#mySelect');\n\n// array of objects called \"options\" in an object\nlet selectValuesNew = {\n options: [{\n value: \"1\",\n description: \"2test 1\"\n },\n {\n value: \"2\",\n description: \"2test 2\",\n selected: true\n },\n {\n value: \"3\",\n description: \"2test 3\"\n },\n {\n value: \"4\",\n description: \"2test Four\"\n }\n ]\n};\n\n//use div here as using \"select\" mucks up the original selected value\nlet opts2 = $(\"<div />\");\nlet opt2 = {}; //only append after adding all options\n$.map(selectValuesNew.options, function(val, index) {\n opts2.append($('<option />')\n .prop(\"value\", val.value)\n .prop(\"selected\", val.selected)\n .text(val.description));\n});\nopts2.find(\"option\").appendTo('#mySelectNew'); <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script>\n<select id=\"mySelect\">\n <option value=\"\" selected=\"selected\">empty</option>\n</select>\n\n<select id=\"mySelectNew\" multiple=\"multiple\">\n <option value=\"\" selected=\"selected\">2empty</option>\n</select>"
},
{
"answer_id": 52196987,
"author": "shohan",
"author_id": 849525,
"author_profile": "https://Stackoverflow.com/users/849525",
"pm_score": 2,
"selected": false,
"text": "var options = [];\n$.each(selectValues, function(key, value) {\n options.push ($('<option>', { value : key })\n .text(value));\n});\n $('#mySelect').append(options);\n"
},
{
"answer_id": 54243637,
"author": "SU3",
"author_id": 2640636,
"author_profile": "https://Stackoverflow.com/users/2640636",
"pm_score": 1,
"selected": false,
"text": "append map $('#the_select').append(['a','b','c'].map(x => $('<option>').text(x)));\n reduce ['a','b','c'].reduce((s,x) => s.append($('<option>').text(x)), $('#the_select'));\n"
},
{
"answer_id": 60432313,
"author": "iEfimoff",
"author_id": 815846,
"author_profile": "https://Stackoverflow.com/users/815846",
"pm_score": 1,
"selected": false,
"text": "const selectValues = {\n \"1\": \"test 1\",\n \"2\": \"test 2\"\n}\nconst selectTest = document.getElementById('selectTest')\nObject.keys(selectValues).map(key => selectTest.add(new Option(selectValues[key], key))) <select id=\"selectTest\"></select>"
},
{
"answer_id": 63586377,
"author": "Kamil Kiełczewski",
"author_id": 860099,
"author_profile": "https://Stackoverflow.com/users/860099",
"pm_score": 2,
"selected": false,
"text": "mySelect.innerHTML+= `<option value=\"${key}\">${value}</option>`;\n let selectValues = { \"1\": \"test 1\", \"2\": \"test 2\" };\n\nfor(let key in selectValues) { \n mySelect.innerHTML+= `<option value=\"${key}\">${selectValues[key]}</option>`;\n} <select id=\"mySelect\">\n <option value=\"0\" selected=\"selected\">test 0</option>\n</select>"
},
{
"answer_id": 69671936,
"author": "kush",
"author_id": 9744514,
"author_profile": "https://Stackoverflow.com/users/9744514",
"pm_score": 2,
"selected": false,
"text": " $.each(response, function (index,value) {\n $('#unit')\n .append($(\"<option></option>\")\n .attr(\"value\", value.id)\n .text(value.title));\n });\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
170,997
|
<p>What is the best method for removing a table row with jQuery?</p>
|
[
{
"answer_id": 170998,
"author": "Darryl Hein",
"author_id": 5441,
"author_profile": "https://Stackoverflow.com/users/5441",
"pm_score": 3,
"selected": false,
"text": "$('#myTableRow').remove();\n"
},
{
"answer_id": 171006,
"author": "imjoevasquez",
"author_id": 24630,
"author_profile": "https://Stackoverflow.com/users/24630",
"pm_score": 10,
"selected": true,
"text": "$('#myTableRow').remove();\n id <tr id=\"myTableRow\"><td>blah</td></tr>\n id"
},
{
"answer_id": 171048,
"author": "ehm",
"author_id": 15214,
"author_profile": "https://Stackoverflow.com/users/15214",
"pm_score": 3,
"selected": false,
"text": "function removeRow(row) {\n $(row).remove();\n}\n\n<tr onmousedown=\"removeRow(this)\"><td>Foo</td></tr>\n"
},
{
"answer_id": 171293,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 7,
"selected": false,
"text": "$('#myTable tr').click(function(){\n $(this).remove();\n return false;\n});\n $(\"#MyTable\").on(\"click\", \"#DeleteButton\", function() {\n $(this).closest(\"tr\").remove();\n});\n"
},
{
"answer_id": 194144,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "$('tr').click(function()\n {\n $(this).remove();\n });\n"
},
{
"answer_id": 694124,
"author": "sluther",
"author_id": 48796,
"author_profile": "https://Stackoverflow.com/users/48796",
"pm_score": 6,
"selected": false,
"text": "$(\".delete\").live('click', function(event) {\n $(this).parent().parent().remove();\n});\n $(this).remove();\n $(this).parent().remove();\n $(\".delete\").live('click', function(event) {\n $(this).parent().remove();\n});\n"
},
{
"answer_id": 814573,
"author": "Uzbekjon",
"author_id": 52317,
"author_profile": "https://Stackoverflow.com/users/52317",
"pm_score": 3,
"selected": false,
"text": "<tr> $('#myTable tr:last').remove();"
},
{
"answer_id": 1789059,
"author": "Ian Lewis",
"author_id": 217696,
"author_profile": "https://Stackoverflow.com/users/217696",
"pm_score": 6,
"selected": false,
"text": "$($(this).closest(\"tr\"))\n $($(this).closest(\"tr\")).remove()\n $(this).closest('tr').remove();\n"
},
{
"answer_id": 2040059,
"author": "Thurein",
"author_id": 247816,
"author_profile": "https://Stackoverflow.com/users/247816",
"pm_score": 4,
"selected": false,
"text": "$(\"table td img.delete\").click(function () {\n $(this).parent().parent().parent().fadeTo(400, 0, function () { \n $(this).remove();\n });\n return false;\n});\n"
},
{
"answer_id": 4060925,
"author": "Tim Abell",
"author_id": 10245,
"author_profile": "https://Stackoverflow.com/users/10245",
"pm_score": 3,
"selected": false,
"text": "$(this).parents('tr').first().remove();\n <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n<head>\n <script type=\"text/javascript\" src=\"http://code.jquery.com/jquery-1.4.3.min.js\"></script>\n <script type=\"text/javascript\">\n $(document).ready(function() {\n $('.deleteRowButton').click(DeleteRow);\n });\n\n function DeleteRow()\n {\n $(this).parents('tr').first().remove();\n }\n </script>\n</head>\n<body>\n <table>\n <tr><td>foo</td>\n <td><a class=\"deleteRowButton\">delete row</a></td></tr>\n <tr><td>bar bar</td>\n <td><a class=\"deleteRowButton\">delete row</a></td></tr>\n <tr><td>bazmati</td>\n <td><a class=\"deleteRowButton\">delete row</a></td></tr>\n </table>\n</body>\n</html>\n"
},
{
"answer_id": 14286362,
"author": "silvster27",
"author_id": 1580848,
"author_profile": "https://Stackoverflow.com/users/1580848",
"pm_score": 2,
"selected": false,
"text": "function removeMyRow(docRowCount){\n $('table tr').eq(docRowCount).remove();\n}\n"
},
{
"answer_id": 16399034,
"author": "NoWar",
"author_id": 196919,
"author_profile": "https://Stackoverflow.com/users/196919",
"pm_score": 2,
"selected": false,
"text": "<tr>\n <td><span class=\"spanUser\" userid=\"123\"></span></td>\n <td><span class=\"spanUser\" userid=\"123\"></span></td>\n</tr>\n userid=\"123\" $(\".spanUser\").live(\"click\", function () {\n\n var span = $(this); \n var userid = $(this).attr('userid');\n\n var currentURL = window.location.protocol + '//' + window.location.host;\n var url = currentURL + \"/Account/DeleteUser/\" + userid;\n\n $.post(url, function (data) {\n if (data) {\n var tdTAG = span.parent(); // GET PARENT OF SPAN TAG\n var trTAG = tdTAG.parent(); // GET PARENT OF TD TAG\n trTAG.remove(); // DELETE TR TAG == DELETE AN ENTIRE TABLE ROW \n } else {\n alert('Sorry, there is some error.');\n }\n }); \n\n });\n TR"
},
{
"answer_id": 30362320,
"author": "Pichet Thantipiputpinyo",
"author_id": 3958230,
"author_profile": "https://Stackoverflow.com/users/3958230",
"pm_score": 2,
"selected": false,
"text": "empty() $(this).closest('tr').empty();\n"
},
{
"answer_id": 39039620,
"author": "SparkyUK2104",
"author_id": 2182404,
"author_profile": "https://Stackoverflow.com/users/2182404",
"pm_score": 1,
"selected": false,
"text": "$('#resultstbl tr[id=nameoftr]').remove();\n"
},
{
"answer_id": 46601235,
"author": "Kamuran Sönecek",
"author_id": 4766521,
"author_profile": "https://Stackoverflow.com/users/4766521",
"pm_score": 0,
"selected": false,
"text": "<tr category=\"petshop\" type=\"fish\"><td>little fish</td></tr>\n<tr category=\"petshop\" type=\"dog\"><td>little dog</td></tr>\n<tr category=\"toys\" type=\"lego\"><td>lego starwars</td></tr>\n const rowRemover = (category,type)=>{\n $(`tr[category=${category}][type=${type}]`).remove();\n}\n\nrowRemover('petshop','fish');\n"
},
{
"answer_id": 50610550,
"author": "ricks",
"author_id": 6460122,
"author_profile": "https://Stackoverflow.com/users/6460122",
"pm_score": 0,
"selected": false,
"text": "BootstrapTable.prototype.removeRow = function (params) {\n if (!params.hasOwnProperty('index')) {\n return;\n }\n\n var len = this.options.data.length;\n\n if ((params.index > len) || (params.index < 0)){\n return;\n }\n\n this.options.data.splice(params.index, 1);\n\n if (len === this.options.data.length) {\n return;\n }\n\n this.initSearch();\n this.initPagination();\n this.initBody(true);\n};\n var allowedMethods = [ 'removeRow' $(\"#your-table\").bootstrapTable('removeRow',{index:1});"
},
{
"answer_id": 58707171,
"author": "Ayu Anggraeni",
"author_id": 4108491,
"author_profile": "https://Stackoverflow.com/users/4108491",
"pm_score": 0,
"selected": false,
"text": " <table id='myTable' border='1'>\n <tr id='tr1'><td>Row1</td></tr>\n <tr id='tr2'><td>Row2</td></tr>\n <tr id='tr3'><td>Row3</td></tr>\n <tr id='tr4'><td>Row4</td></tr>\n <tr id='tr5'><td>Row5</td></tr>\n </table>\n\n//======REMOVE TABLE ROW=========\n//1. remove spesific row using its ID\n$('#tr1').remove();\n\n//2. remove spesific row using its order or index.\n//row index started from 0-n. Row1 index is 0, Row2 index is 1 and so on.\n$('#myTable').find('tr:eq(2)').remove();//removing Row3\n"
},
{
"answer_id": 72704280,
"author": "Saeid",
"author_id": 15356914,
"author_profile": "https://Stackoverflow.com/users/15356914",
"pm_score": 0,
"selected": false,
"text": "$(\"#your_tbody_tag\").empty();\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/170997",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
171,000
|
<p>I want to recreate the the update panel postback without using an update panel to do the postback. What is the generic method for doing this?</p>
<p>For example, on Stackoverflow, when you vote up or down on a question it does a postback to update the database and I would bet they didn't use an update panel.</p>
<p>What do I have?</p>
<p>I have a table with table data. When I click on the <code>td</code> item as a whole column, I want to do an update to the database and also update a gridview on the page itself. The gridview shows all the currently clicked items in the table because it was updated via "our method".</p>
<p>Looking for a good generic method I could use for a lot of async postbacks without update panel.</p>
|
[
{
"answer_id": 171418,
"author": "Dave Ward",
"author_id": 60,
"author_profile": "https://Stackoverflow.com/users/60",
"pm_score": 5,
"selected": true,
"text": "{\"Success\":true,\"NewScore\":1,\"Message\":\"\",\"LastVoteTypeId\":2}\n var voteResult = function(jClicked, postId, data) {\n if (data.Success) {\n jClicked.parent().find(\"span.vote-count-post\").text(data.NewScore);\n if (data.Message)\n showFadingNotification(jClicked, data.Message);\n }\n else {\n showNotification(jClicked, data.Message);\n reset(jClicked, jClicked);\n\n if (data.LastVoteTypeId) {\n selectPreviousVote(jClicked, data.LastVoteTypeId);\n }\n }\n};\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171000",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7644/"
] |
171,020
|
<p>I am setting up support for users to sign in with client certificates. Unfortunately IIS refuses to acknowledge any certificate not chained to an installed CA (<a href="http://support.microsoft.com/kb/257587" rel="nofollow noreferrer" title="Description of the Server Authentication Process During the SSL Handshake">see this article</a>).</p>
<p>As the feature is implemented only for users´ convenience, it would be great to allow any client certificate. Is there any way to accomplish this?</p>
<p>My server is running Windows Server 2003 and IIS 6, but the behaviour is no different on my IIS 7 running locally. If IIS 7 could be customized to support any client certificate, I would be able to change though (given no solution for IIS 6 is available).</p>
|
[
{
"answer_id": 171040,
"author": "Purfideas",
"author_id": 4615,
"author_profile": "https://Stackoverflow.com/users/4615",
"pm_score": 0,
"selected": false,
"text": "certmgr certmgr --add -c -m Trust <CA_cert_DER_fmt>\n"
},
{
"answer_id": 248199,
"author": "Chris Ballance",
"author_id": 1551,
"author_profile": "https://Stackoverflow.com/users/1551",
"pm_score": 1,
"selected": false,
"text": " public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy\n {\n public TrustAllCertificatePolicy() {}\n\n public bool CheckValidationResult(ServicePoint sp, X509Certificate cert,WebRequest req, int problem)\n {\n return true;\n }\n }\n System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20138/"
] |
171,027
|
<p>I'm using jQuery to add an additional row to a table as the last row.</p>
<p>I have done it this way:</p>
<pre><code>$('#myTable').append('<tr><td>my data</td><td>more data</td></tr>');
</code></pre>
<p>Are there limitations to what you can add to a table like this (such as inputs, selects, number of rows)? Is there a different way to do it?</p>
|
[
{
"answer_id": 171049,
"author": "Luke Bennett",
"author_id": 17602,
"author_profile": "https://Stackoverflow.com/users/17602",
"pm_score": 12,
"selected": true,
"text": "tbody <table id=\"myTable\">\n <tbody>\n <tr>...</tr>\n <tr>...</tr>\n </tbody>\n</table>\n <table id=\"myTable\">\n <tbody>\n <tr>...</tr>\n <tr>...</tr>\n </tbody>\n <tr>...</tr>\n</table>\n $('#myTable tr:last').after('<tr>...</tr><tr>...</tr>');\n after() tbody tbody tbody tr tbody table tbody tbody $('#myTable > tbody:last-child').append('<tr>...</tr><tr>...</tr>');\n"
},
{
"answer_id": 468240,
"author": "ChadT",
"author_id": 23300,
"author_profile": "https://Stackoverflow.com/users/23300",
"pm_score": 8,
"selected": false,
"text": "<tbody> <tfoot> <table>\n <tbody>\n <tr><td>Foo</td></tr>\n </tbody>\n <tfoot>\n <tr><td>footer information</td></tr>\n </tfoot>\n</table>\n <tbody> .append .after $(\"#myTable > tbody\").append(\"<tr><td>row content</td></tr>\");\n"
},
{
"answer_id": 602333,
"author": "Uzbekjon",
"author_id": 52317,
"author_profile": "https://Stackoverflow.com/users/52317",
"pm_score": 4,
"selected": false,
"text": "<tbody> // One table\naddTableRow($('#myTable'));\n// add table row to number of tables\naddTableRow($('.myTables'));\n"
},
{
"answer_id": 1278557,
"author": "Neil",
"author_id": 14193,
"author_profile": "https://Stackoverflow.com/users/14193",
"pm_score": 10,
"selected": false,
"text": "$(\"#tableID\").find('tbody')\n .append($('<tr>')\n .append($('<td>')\n .append($('<img>')\n .attr('src', 'img.png')\n .text('Image cell')\n )\n )\n );\n $('<some-tag>') attr text <tag>text</tag>"
},
{
"answer_id": 1521882,
"author": "Avron Olshewsky",
"author_id": 184553,
"author_profile": "https://Stackoverflow.com/users/184553",
"pm_score": 4,
"selected": false,
"text": "$('#traffic tbody').find('tr.trafficBody).filter(':nth-child(' + (column + 1) + ')').after(insertedhtml);\n <tr id=\"row1\"> ... </tr>\n<tr id=\"row2\"> ... </tr>\n<tr id=\"row3\"> ... </tr>\n $('#traffic tbody').find('tr.trafficBody' + idx).after(html);\n"
},
{
"answer_id": 2139639,
"author": "Nischal",
"author_id": 69542,
"author_profile": "https://Stackoverflow.com/users/69542",
"pm_score": 5,
"selected": false,
"text": "$(\"#tableId\").last().append(\"<tr><td>New row</td></tr>\");\n"
},
{
"answer_id": 4001130,
"author": "Curtor",
"author_id": 371783,
"author_profile": "https://Stackoverflow.com/users/371783",
"pm_score": 5,
"selected": false,
"text": "$('#myTable > tbody:first').append('<tr>...</tr><tr>...</tr>'); \n $('#myTable > tbody:last').append('<tr>...</tr><tr>...</tr>'); \n first last <table id=myTable>\n <tbody id=first>\n <tr><td>\n <table id=myNestedTable>\n <tbody id=last>\n </tbody>\n </table>\n </td></tr>\n </tbody>\n</table>\n"
},
{
"answer_id": 4457713,
"author": "Dominic",
"author_id": 544311,
"author_profile": "https://Stackoverflow.com/users/544311",
"pm_score": 4,
"selected": false,
"text": "...\n#templateRow {\n display:none;\n}\n...\n ...\n<tr id=\"templateRow\"> ... </tr>\n...\n\n$(\"#templateRow\").clone().removeAttr(\"id\").appendTo( $(\"#templateRow\").parent() );\n\n...\n"
},
{
"answer_id": 4764435,
"author": "Oshua",
"author_id": 585079,
"author_profile": "https://Stackoverflow.com/users/585079",
"pm_score": 4,
"selected": false,
"text": "function add_new_row(table, rowcontent) {\n if ($(table).length > 0) {\n if ($(table + ' > tbody').length == 0) $(table).append('<tbody />');\n ($(table + ' > tr').length > 0) ? $(table).children('tbody:last').children('tr:last').append(rowcontent): $(table).children('tbody:last').append(rowcontent);\n }\n}\n add_new_row('#myTable','<tr><td>my new row</td></tr>');\n"
},
{
"answer_id": 9627412,
"author": "Ricky Gummadi",
"author_id": 441914,
"author_profile": "https://Stackoverflow.com/users/441914",
"pm_score": 3,
"selected": false,
"text": "//Adds a new table row\n$.fn.addNewRow = function (rowId) {\n $(this).find('tbody').append('<tr id=\"' + rowId + '\"> </tr>');\n};\n $('#Table').addNewRow(id1);\n"
},
{
"answer_id": 10139399,
"author": "Pavel Shkleinik",
"author_id": 454137,
"author_profile": "https://Stackoverflow.com/users/454137",
"pm_score": 3,
"selected": false,
"text": "<table id=myTable>\n <tr><td></td></tr>\n <style=\"height=0px;\" tfoot></tfoot>\n</table>\n var footer = $(\"#mytable tfoot\")\nfooter.before(\"<tr><td></td></tr>\")\n"
},
{
"answer_id": 10226528,
"author": "Alexey Pavlov",
"author_id": 1343405,
"author_profile": "https://Stackoverflow.com/users/1343405",
"pm_score": 3,
"selected": false,
"text": "$('#myTable').append('<tr><td>my data</td><td>more data</td></tr>');\n TBODY THEAD TFOOT .append() <table class=\"t\"> <!-- table with THEAD, TBODY and TFOOT -->\n<thead>\n <tr><th>h1</th><th>h2</th></tr>\n</thead>\n<tbody>\n <tr><td>1</td><td>2</td></tr>\n</tbody>\n<tfoot>\n <tr><th>f1</th><th>f2</th></tr>\n</tfoot>\n</table><br>\n\n<table class=\"t\"> <!-- table with two TBODYs -->\n<thead>\n <tr><th>h1</th><th>h2</th></tr>\n</thead>\n<tbody>\n <tr><td>1</td><td>2</td></tr>\n</tbody>\n<tbody>\n <tr><td>3</td><td>4</td></tr>\n</tbody>\n<tfoot>\n <tr><th>f1</th><th>f2</th></tr>\n</tfoot>\n</table><br>\n\n<table class=\"t\"> <!-- table without TBODY -->\n<thead>\n <tr><th>h1</th><th>h2</th></tr>\n</thead>\n</table><br>\n\n<table class=\"t\"> <!-- table with TR not in TBODY -->\n <tr><td>1</td><td>2</td></tr>\n</table>\n<br>\n<table class=\"t\">\n</table>\n\n<script>\n$('.t').append('<tr><td>a</td><td>a</td></tr>');\n</script>\n a b 1 2 3 4 TBODY"
},
{
"answer_id": 10250911,
"author": "shashwat",
"author_id": 1306394,
"author_profile": "https://Stackoverflow.com/users/1306394",
"pm_score": 6,
"selected": false,
"text": "tableObject.insertRow(index)\n index insertRow() <html>\n <head>\n <script type=\"text/javascript\">\n function displayResult()\n {\n document.getElementById(\"myTable\").insertRow(-1).innerHTML = '<td>1</td><td>2</td>';\n }\n </script>\n </head>\n\n <body> \n <table id=\"myTable\" border=\"1\">\n <tr>\n <td>cell 1</td>\n <td>cell 2</td>\n </tr>\n <tr>\n <td>cell 3</td>\n <td>cell 4</td>\n </tr>\n </table>\n <br />\n <button type=\"button\" onclick=\"displayResult()\">Insert new row</button> \n </body>\n</html>\n"
},
{
"answer_id": 10904232,
"author": "Salman von Abbas",
"author_id": 362006,
"author_profile": "https://Stackoverflow.com/users/362006",
"pm_score": 8,
"selected": false,
"text": "append() prepend() before() after() <tr> <tbody> <tbody> $('#myTable').append('<tr><td>my data</td><td>more data</td></tr>');\n"
},
{
"answer_id": 15692808,
"author": "Whome",
"author_id": 185565,
"author_profile": "https://Stackoverflow.com/users/185565",
"pm_score": 3,
"selected": false,
"text": "<table id=\"properties\">\n<tbody>\n <tr>\n <th>Name</th>\n <th>Value</th>\n <th> </th>\n </tr>\n <tr>\n <td nowrap>key1</td>\n <td><input type=\"text\" name=\"property_key1\" value=\"value1\" size=\"70\"/></td>\n <td class=\"data_item_options\">\n <a class=\"buttonicon\" href=\"javascript:deleteRow()\" title=\"Delete row\" onClick=\"deleteRow(this); return false;\"></a>\n </td>\n </tr>\n</tbody>\n</table>\n\n<table id=\"properties_rowtemplate\" style=\"display:none\" data-counter=\"0\">\n<tr>\n <td><input type=\"text\" name=\"newproperty_name_\\${counter}\" value=\"\" size=\"35\"/></td>\n <td><input type=\"text\" name=\"newproperty_value_\\${counter}\" value=\"\" size=\"70\"/></td>\n <td><a class=\"buttonicon\" href=\"javascript:deleteRow()\" title=\"Delete row\" onClick=\"deleteRow(this); return false;\"></a></td>\n</tr>\n</table>\n<a class=\"action\" href=\"javascript:addRow()\" onclick=\"addRow('properties'); return false\" title=\"Add new row\">Add row</a><br/>\n<br/>\n\n- - - - \n// add row to html table, read html from row template\nfunction addRow(sTableId) {\n // find destination and template tables, find first <tr>\n // in template. Wrap inner html around <tr> tags.\n // Keep track of counter to give unique field names.\n var table = $(\"#\"+sTableId);\n var template = $(\"#\"+sTableId+\"_rowtemplate\");\n var htmlCode = \"<tr>\"+template.find(\"tr:first\").html()+\"</tr>\";\n var id = parseInt(template.data(\"counter\"),10)+1;\n template.data(\"counter\", id);\n htmlCode = htmlCode.replace(/\\${counter}/g, id);\n table.find(\"tbody:last\").append(htmlCode);\n}\n\n// delete <TR> row, childElem is any element inside row\nfunction deleteRow(childElem) {\n var row = $(childElem).closest(\"tr\"); // find <tr> parent\n row.remove();\n}\n"
},
{
"answer_id": 16646188,
"author": "Jaid07",
"author_id": 2392594,
"author_profile": "https://Stackoverflow.com/users/2392594",
"pm_score": 3,
"selected": false,
"text": "var r=$(\"#content_table\").length;\n $(\"#table_id\").eq(r-1).after(row_html);\n"
},
{
"answer_id": 18509890,
"author": "d.raev",
"author_id": 1621821,
"author_profile": "https://Stackoverflow.com/users/1621821",
"pm_score": 3,
"selected": false,
"text": "var ninja_row = $('#banner_holder').find('tr');\n\nif( $('#my_table tbody tr').length > 5){\n $('#my_table tbody tr').filter(':nth-child(5)').after(ninja_row);\n}else{\n $('#my_table tr:last').after(ninja_row);\n}\n <table id=\"banner_holder\" style=\"display:none;\"> \n <tr>\n <td colspan=\"3\">\n <div class=\"wide-banner\"></div>\n </td> \n </tr> \n</table>\n"
},
{
"answer_id": 19130296,
"author": "Praveena M",
"author_id": 976188,
"author_profile": "https://Stackoverflow.com/users/976188",
"pm_score": 3,
"selected": false,
"text": "oTable = $('#tblStateFeesSetup').dataTable({\n \"bScrollCollapse\": true,\n \"bJQueryUI\": true,\n ...\n ...\n //Custom Initializations.\n });\n\n//Data Row Template of the table.\nvar dataRowTemplate = {};\ndataRowTemplate.InvoiceID = '';\ndataRowTemplate.InvoiceDate = '';\ndataRowTemplate.IsOverRide = false;\ndataRowTemplate.AmountOfInvoice = '';\ndataRowTemplate.DateReceived = '';\ndataRowTemplate.AmountReceived = '';\ndataRowTemplate.CheckNumber = '';\n\n//Add dataRow to the table.\noTable.fnAddData(dataRowTemplate);\n"
},
{
"answer_id": 20718713,
"author": "Vivek S",
"author_id": 2961070,
"author_profile": "https://Stackoverflow.com/users/2961070",
"pm_score": 3,
"selected": false,
"text": "<tr id=\"tablerow\"></tr>\n\n$('#tablerow').append('<tr>...</tr><tr>...</tr>');\n"
},
{
"answer_id": 21473617,
"author": "SNEH PANDYA",
"author_id": 2565184,
"author_profile": "https://Stackoverflow.com/users/2565184",
"pm_score": 3,
"selected": false,
"text": "<div class=\"container\">\n <div class = \"row\">\n <div class = \"span9\">\n <div class = \"well\">\n <%= form_for (@replication) do |f| %>\n <table>\n <tr>\n <td>\n <%= f.label :SR_NO %>\n </td>\n <td>\n <%= f.text_field :sr_no , :id => \"txt_RegionName\" %>\n </td>\n </tr>\n <tr>\n <td>\n <%= f.label :Particular %>\n </td>\n <td>\n <%= f.text_area :particular , :id => \"txt_Region\" %>\n </td>\n </tr>\n <tr>\n <td>\n <%= f.label :Unit %>\n </td>\n <td>\n <%= f.text_field :unit ,:id => \"txt_Regio\" %>\n </td>\n </tr>\n <tr>\n\n <td> \n <%= f.label :Required_Quantity %>\n </td>\n <td>\n <%= f.text_field :quantity ,:id => \"txt_Regi\" %>\n </td>\n </tr>\n <tr>\n <td></td>\n <td>\n <table>\n <tr><td>\n <input type=\"button\" name=\"add\" id=\"btn_AddToList\" value=\"add\" class=\"btn btn-primary\" />\n </td><td><input type=\"button\" name=\"Done\" id=\"btn_AddToList1\" value=\"Done\" class=\"btn btn-success\" />\n </td></tr>\n </table>\n </td>\n </tr>\n </table>\n <% end %>\n <table id=\"lst_Regions\" style=\"width: 500px;\" border= \"2\" class=\"table table-striped table-bordered table-condensed\">\n <tr>\n <td>SR_NO</td>\n <td>Item Name</td>\n <td>Particular</td>\n <td>Cost</td>\n </tr>\n </table>\n <input type=\"button\" id= \"submit\" value=\"Submit Repication\" class=\"btn btn-success\" />\n </div>\n </div>\n </div>\n</div>\n $(document).ready(function() { \n $('#submit').prop('disabled', true);\n $('#btn_AddToList').click(function () {\n $('#submit').prop('disabled', true);\n var val = $('#txt_RegionName').val();\n var val2 = $('#txt_Region').val();\n var val3 = $('#txt_Regio').val();\n var val4 = $('#txt_Regi').val();\n $('#lst_Regions').append('<tr><td>' + val + '</td>' + '<td>' + val2 + '</td>' + '<td>' + val3 + '</td>' + '<td>' + val4 + '</td></tr>');\n $('#txt_RegionName').val('').focus();\n $('#txt_Region').val('');\n $('#txt_Regio').val('');\n $('#txt_Regi').val('');\n $('#btn_AddToList1').click(function () {\n $('#submit').prop('disabled', false).addclass('btn btn-warning');\n });\n });\n});\n"
},
{
"answer_id": 23592382,
"author": "GabrielOshiro",
"author_id": 604004,
"author_profile": "https://Stackoverflow.com/users/604004",
"pm_score": 3,
"selected": false,
"text": "<table id=\"tableID\">\n <tbody>\n </tbody>\n</table>\n // Reference to the table body\nvar body = $(\"#tableID\").find('tbody');\n\n// Create a new row element\nvar row = $('<tr>');\n\n// Create a new column element\nvar column = $('<td>');\n\n// Create a new image element\nvar image = $('<img>');\nimage.attr('src', 'img.png');\nimage.text('Image cell');\n\n// Append the image to the column element\ncolumn.append(image);\n// Append the column to the row element\nrow.append(column);\n// Append the row to the table body\nbody.append(row);\n"
},
{
"answer_id": 24490396,
"author": "sulest",
"author_id": 923036,
"author_profile": "https://Stackoverflow.com/users/923036",
"pm_score": 5,
"selected": false,
"text": "//Try to get tbody first with jquery children. works faster!\nvar tbody = $('#myTable').children('tbody');\n\n//Then if no tbody just select your table \nvar table = tbody.length ? tbody : $('#myTable');\n\n//Add row\ntable.append('<tr><td>hello></td></tr>');\n //Compose template string\nString.prototype.compose = (function (){\nvar re = /\\{{(.+?)\\}}/g;\nreturn function (o){\n return this.replace(re, function (_, k){\n return typeof o[k] != 'undefined' ? o[k] : '';\n });\n }\n}());\n var tbody = $('#myTable').children('tbody');\nvar table = tbody.length ? tbody : $('#myTable');\nvar row = '<tr>'+\n '<td>{{id}}</td>'+\n '<td>{{name}}</td>'+\n '<td>{{phone}}</td>'+\n'</tr>';\n\n\n//Add row\ntable.append(row.compose({\n 'id': 3,\n 'name': 'Lee',\n 'phone': '123 456 789'\n}));\n"
},
{
"answer_id": 30867236,
"author": "vipul sorathiya",
"author_id": 2613306,
"author_profile": "https://Stackoverflow.com/users/2613306",
"pm_score": 3,
"selected": false,
"text": "$('#yourTableId').append('<tr><td>your data1</td><td>your data2</td><td>your data3</td></tr>');\n"
},
{
"answer_id": 34113952,
"author": "Pankaj Garg",
"author_id": 1983761,
"author_profile": "https://Stackoverflow.com/users/1983761",
"pm_score": 4,
"selected": false,
"text": " // Create a row and append to table\n var row = $('<tr />', {})\n .appendTo(\"#table_id\");\n\n // Add columns to the row. <td> properties can be given in the JSON\n $('<td />', {\n 'text': 'column1'\n }).appendTo(row);\n\n $('<td />', {\n 'text': 'column2',\n 'style': 'min-width:100px;'\n }).appendTo(row);\n"
},
{
"answer_id": 34886037,
"author": "Jakir Hossain",
"author_id": 2497154,
"author_profile": "https://Stackoverflow.com/users/2497154",
"pm_score": 3,
"selected": false,
"text": "<table id=\"myTable\">\n <tbody>\n <tr>...</tr>\n <tr>...</tr>\n </tbody>\n <tr>...</tr>\n</table>\n document.getElementById(\"myTable\").insertRow(-1).innerHTML = '<tr>...</tr><tr>...</tr>';\n"
},
{
"answer_id": 40035413,
"author": "MEAbid",
"author_id": 5906922,
"author_profile": "https://Stackoverflow.com/users/5906922",
"pm_score": 3,
"selected": false,
"text": "<td> var table = $('#yourTableId');\nvar text = 'My Data in td';\nvar image = 'your/image.jpg'; \nvar tr = (\n '<tr>' +\n '<td>'+ text +'</td>'+\n '<td>'+ text +'</td>'+\n '<td>'+\n '<img src=\"' + image + '\" alt=\"yourImage\">'+\n '</td>'+\n '</tr>'\n);\n\n$('#yourTableId').append(tr);\n"
},
{
"answer_id": 42829537,
"author": "Sumon Sarker",
"author_id": 3278763,
"author_profile": "https://Stackoverflow.com/users/3278763",
"pm_score": 2,
"selected": false,
"text": "row <tr> $(\"#myTable > tbody\").prepend(\"<tr><td>my data</td><td>more data</td></tr>\");\n row <tr> $(\"#myTable > tbody\").append(\"<tr><td>my data</td><td>more data</td></tr>\");\n"
},
{
"answer_id": 43111147,
"author": "Prashant",
"author_id": 3288253,
"author_profile": "https://Stackoverflow.com/users/3288253",
"pm_score": 0,
"selected": false,
"text": "$(\"#myTable > tbody\").html($(\"#myTable > tbody\").html()+\"<tr><td>my data</td><td>more data</td></tr>\")\n"
},
{
"answer_id": 45204117,
"author": "Daniel Ortegón",
"author_id": 6830854,
"author_profile": "https://Stackoverflow.com/users/6830854",
"pm_score": 3,
"selected": false,
"text": "$('#myTable').append('<tr><td>'+data+'</td><td>'+other data+'</td>...</tr>');\n"
},
{
"answer_id": 46716018,
"author": "Anton vBR",
"author_id": 7386332,
"author_profile": "https://Stackoverflow.com/users/7386332",
"pm_score": 5,
"selected": false,
"text": "$('#tab').append($('<tr>')\n .append($('<td>').append(\"text1\"))\n .append($('<td>').append(\"text2\"))\n .append($('<td>').append(\"text3\"))\n .append($('<td>').append(\"text4\"))\n )\n $('#tab').append($('<tr>')\n .append($('<td>').append(\"text1\"))\n .append($('<td>').append(\"text2\"))\n .append($('<td>').append(\"text3\"))\n .append($('<td>').append(\"text4\"))\n) <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n\n<table id=\"tab\">\n <tr>\n <th>Firstname</th>\n <th>Lastname</th> \n <th>Age</th>\n <th>City</th>\n </tr>\n <tr>\n <td>Jill</td>\n <td>Smith</td> \n <td>50</td>\n <td>New York</td>\n </tr>\n</table>"
},
{
"answer_id": 51906541,
"author": "Hassan Sadeghi",
"author_id": 9881249,
"author_profile": "https://Stackoverflow.com/users/9881249",
"pm_score": -1,
"selected": false,
"text": "html table innerHTML or .html() IE9 .append(\"<tr></tr>\") pure javascript jQuery jQuery $.fn.addRow=function(index/*-1: add to end or any desired index*/, cellsCount/*optional*/){\n if(this[0].tagName.toLowerCase()!=\"table\") return null;\n var i=0, c, r = this[0].insertRow((index<0||index>this[0].rows.length)?this[0].rows.length:index);\n for(;i<cellsCount||0;i++) c = r.insertCell(); //you can use c for set its content or etc\n return $(r);\n};\n var addedRow = $(\"#myTable\").addRow(-1/*add to end*/, 2);\n"
},
{
"answer_id": 54541704,
"author": "Rizwan",
"author_id": 8625811,
"author_profile": "https://Stackoverflow.com/users/8625811",
"pm_score": 2,
"selected": false,
"text": "$('#myTable tr:last').after('<tr>...</tr><tr>...</tr>');\n $('#myTable tr').after('<tr>...</tr><tr>...</tr>');\n"
},
{
"answer_id": 55356405,
"author": "rajmobiapp",
"author_id": 6777209,
"author_profile": "https://Stackoverflow.com/users/6777209",
"pm_score": 3,
"selected": false,
"text": "$('<tr><td>3</td></tr><tr><td>4</td></tr>').appendTo(\"#myTable tbody\"); <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js\"></script>\n<table id=\"myTable\">\n <tbody>\n <tr><td>1</td></tr>\n <tr><td>2</td></tr>\n </tbody>\n</table>"
},
{
"answer_id": 56096496,
"author": "Hien Nguyen",
"author_id": 4964569,
"author_profile": "https://Stackoverflow.com/users/4964569",
"pm_score": 3,
"selected": false,
"text": ".after() interpolation function add(){\n let studentname = $(\"input[name='studentname']\").val();\n let studentmark = $(\"input[name='studentmark']\").val();\n\n $('#student tr:last').after(`<tr><td>${studentname}</td><td>${studentmark}</td></tr>`);\n}\n function add(){\nlet studentname = $(\"input[name='studentname']\").val();\nlet studentmark = $(\"input[name='studentmark']\").val();\n\n$('#student tr:last').after(`<tr><td>${studentname}</td><td>${studentmark}</td></tr>`);\n} <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n<!DOCTYPE html>\n<html>\n<head>\n<style>\ntable {\n font-family: arial, sans-serif;\n border-collapse: collapse;\n width: 100%;\n}\n\ntd, th {\n border: 1px solid #dddddd;\n text-align: left;\n padding: 8px;\n}\n\ntr:nth-child(even) {\n background-color: #dddddd;\n}\n</style>\n</head>\n<body>\n<form>\n<input type='text' name='studentname' />\n<input type='text' name='studentmark' />\n<input type='button' onclick=\"add()\" value=\"Add new\" />\n</form>\n<table id='student'>\n <thead>\n <th>Name</th>\n <th>Mark</th>\n </thead>\n</table>\n</body>\n</html>"
},
{
"answer_id": 59900721,
"author": "Hemant N. Karmur",
"author_id": 9578153,
"author_profile": "https://Stackoverflow.com/users/9578153",
"pm_score": 0,
"selected": false,
"text": "$('#yourtableid tr:last').after('<tr>...</tr><tr>...</tr>');\n $('#yourtableid tr:last').after('<tr><td>your data</td></tr>');\n let table = document.getElementById(\"tableId\");\n\nlet row = table.insertRow(1); // pass position where you want to add a new row\n\n\n//then add cells as you want with index\nlet cell0 = row.insertCell(0);\nlet cell1 = row.insertCell(1);\nlet cell2 = row.insertCell(2);\nlet cell3 = row.insertCell(3);\n\n\n//add value to added td cell\n cell0.innerHTML = \"your td content here\";\n cell1.innerHTML = \"your td content here\";\n cell2.innerHTML = \"your td content here\";\n cell3.innerHTML = \"your td content here\";\n"
},
{
"answer_id": 59965697,
"author": "Nikhil B",
"author_id": 12688471,
"author_profile": "https://Stackoverflow.com/users/12688471",
"pm_score": 0,
"selected": false,
"text": "<html> \n\n<head> \n <script src= \n \"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"> \n </script> \n\n <style> \n table { \n margin: 25px 0; \n width: 200px; \n } \n\n table th, table td { \n padding: 10px; \n text-align: center; \n } \n\n table, th, td { \n border: 1px solid; \n } \n </style> \n</head> \n\n<body> \n\n <b>Add table row in jQuery</b> \n\n <p> \n Click on the button below to \n add a row to the table \n </p> \n\n <button class=\"add-row\"> \n Add row \n </button> \n\n <table> \n <thead> \n <tr> \n <th>Rows</th> \n </tr> \n </thead> \n <tbody> \n <tr> \n <td>This is row 0</td> \n </tr> \n </tbody> \n </table> \n\n <!-- Script to add table row -->\n <script> \n let rowno = 1; \n $(document).ready(function () { \n $(\".add-row\").click(function () { \n rows = \"<tr><td>This is row \" \n + rowno + \"</td></tr>\"; \n tableBody = $(\"table tbody\"); \n tableBody.append(rows); \n rowno++; \n }); \n }); \n </script> \n</body> \n</html> \n"
},
{
"answer_id": 61783614,
"author": "Kamil Kiełczewski",
"author_id": 860099,
"author_profile": "https://Stackoverflow.com/users/860099",
"pm_score": 2,
"selected": false,
"text": "myTable.firstChild.innerHTML += '<tr><td>my data</td><td>more data</td></tr>'\n function add() {\n myTable.firstChild.innerHTML+=`<tr><td>date</td><td>${+new Date}</td></tr>`\n} td {border: 1px solid black;} <button onclick=\"add()\">Add</button><br>\n<table id=\"myTable\"><tbody></tbody> </table> <tbody> firstChild <tbody>"
},
{
"answer_id": 63764247,
"author": "Rinto George",
"author_id": 510754,
"author_profile": "https://Stackoverflow.com/users/510754",
"pm_score": 2,
"selected": false,
"text": "$('#mytable tr').last().after('<tr><td></td></tr>');\n"
},
{
"answer_id": 65975165,
"author": "Mark",
"author_id": 9885904,
"author_profile": "https://Stackoverflow.com/users/9885904",
"pm_score": 2,
"selected": false,
"text": "$(() => {\n $(\"<tr><td>my data</td><td>more data</td></tr>\").appendTo(\"tbody\");\n});\n $(() => {\n var t_data = $('<tr><td>my data</td><td>more data</td></tr>');\n t_data.appendTo('tbody');\n});\n"
},
{
"answer_id": 70849965,
"author": "mostafa toloo",
"author_id": 7950428,
"author_profile": "https://Stackoverflow.com/users/7950428",
"pm_score": 0,
"selected": false,
"text": "var html = $('#myTableBody').html();\nhtml += '<tr><td>my data</td><td>more data</td></tr>';\n$('#myTableBody').html(html);\n $('#myTableBody').html($('#myTableBody').html() + '<tr><td>my data</td><td>more data</td></tr>');\n"
},
{
"answer_id": 71934404,
"author": "Sahil Thummar",
"author_id": 14229690,
"author_profile": "https://Stackoverflow.com/users/14229690",
"pm_score": 2,
"selected": false,
"text": "// Using jQuery - append\n$('#myTable > tbody').append('<tr><td>3</td><td>Smith Patel</td></tr>');\n\n// Using jQuery - appendTo\n$('<tr><td>4</td><td>J. Thomson</td></tr>').appendTo(\"#myTable > tbody\");\n\n// Using jQuery - add html row\nlet tBodyHtml = $('#myTable > tbody').html();\ntBodyHtml += '<tr><td>5</td><td>Patel S.</td></tr>';\n$('#myTable > tbody').html(tBodyHtml);\n\n// Using jQuery - after\n$('#myTable > tbody tr:last').after('<tr><td>6</td><td>Angel Bruice</td></tr>');\n\n// Using JavaScript - insertRow\nconst tableBody = document.getElementById('myTable').getElementsByTagName('tbody')[0];\nconst newRow = tableBody.insertRow(tableBody.rows.length);\nnewRow.innerHTML = '<tr><td>7</td><td>K. Ashwin</td></tr>'; <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n<table id=\"myTable\">\n <thead>\n <tr>\n <th>Id</th>\n <th>Name</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>1</td>\n <td>John Smith</td>\n </tr>\n <tr>\n <td>2</td>\n <td>Tom Adam</td>\n </tr>\n </tbody>\n</table>"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
171,044
|
<p>I currently use my local web server to allow costumers to preview some applications and also to allow downloads of "nightly builds" of my open source library.</p>
<p>Problem is I changed my ISP and now my port 80 is blocked. </p>
<p>Altough I know I could easily change the port on the Apache server, I'd like to avoid that unless there's no alternative.</p>
<p>Do you know any third party service (free or paid) that would do a port forward to my website, making it transparent to someone accessing it?</p>
<p>One other idea I heard about was using mod rewrite from my current webhost to rewrite to my domain, but I'd also prefer not go this path. Besides that, do you know any .htaccess examples that actually work? I have tried this:</p>
<pre><code>RewriteEngine on
RewriteRule ^/(.*) http://www.example.com:8080/$1
</code></pre>
<p>But it doesn't seem to be working.</p>
|
[
{
"answer_id": 171185,
"author": "joelhardi",
"author_id": 11438,
"author_profile": "https://Stackoverflow.com/users/11438",
"pm_score": 2,
"selected": true,
"text": "RewriteRule ^(.*)$ http://mylocalserver.com:8080$1 [R]\n mylocalserver.com:8080 myaddress.com mylocalserver.com:8080"
},
{
"answer_id": 172961,
"author": "kolrie",
"author_id": 14540,
"author_profile": "https://Stackoverflow.com/users/14540",
"pm_score": 1,
"selected": false,
"text": "<VirtualHost *:80>\n ServerName mydomain.com\n ServerAlias www.mydomain.com *.mydomain.com\n RewriteEngine On\n RewriteCond %{HTTP_HOST} (.*)\\.mydomain\\.com [NC]\n RewriteRule (.*) http://mylocalserverdns.mydomain.com:8081/%1$1 [P]\n</VirtualHost>\n <VirtualHost *:8081>\n ServerName mylocalserverdns.mydomain.com\n\n ProxyPass /app1 http://127.0.0.1:8088\n ProxyPassReverse /app1 http://127.0.0.1:8088\n ProxyPassReverse /app1 http://mylocalserverdns.mydomain.com:8088/app1\n\n ProxyPass /app2 http://127.0.0.1:8089\n ProxyPassReverse /app2 http://127.0.0.1:8089\n ProxyPassReverse /app2 http://mylocalserverdns.mydomain.com:8089/app2\n</VirtualHost>\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171044",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14540/"
] |
171,074
|
<p>I'm trying to lightbox a page containing a SWF via the nifty AJAX feature in Facebox (for jQuery). The trouble is that the paths now work relative to the main index page, not the directory that houses the flash page. Here's a directory breakdown:</p>
<p>./<br />
- index.html (loads projects/projectName/index.html)<br />
+ js/<br />
+ jquery/<br />
- facebox.js<br />
- jquery.js<br />
+ swfobject/<br />
- swfobject.js<br />
+ projects<br />
+ projectName<br />
- index.html (works when viewed by itself with relative paths to JS)<br />
+ swf/<br /></p>
<p>Could anyone tell me if there's some way of preserving the scope of relative paths via jQuery (or any Javascript really)?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 171353,
"author": "RET",
"author_id": 14750,
"author_profile": "https://Stackoverflow.com/users/14750",
"pm_score": 0,
"selected": false,
"text": "index.html projectName .facebox()"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
171,112
|
<p>There are several web applications which allow you to send photos from your mobile phone and post them to web site/application. How do these work and what sort of technologies would one use to implement such a feature? Is it an MMS server or does one need to get into socket programming? For example, some applications provide you with an email address to email your photos to via mobile phone. I'm curious to know how these things work. I can somewhat figure out on my own how they work, but I would like to know this feature is normally implemented. </p>
<p>Thanks</p>
|
[
{
"answer_id": 171122,
"author": "roryf",
"author_id": 270,
"author_profile": "https://Stackoverflow.com/users/270",
"pm_score": 4,
"selected": true,
"text": "<input type=\"file\" />"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171112",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24059/"
] |
171,115
|
<p>I'm looking for a standard way to connect to databases in PHP. We've all been there - first start with some rudimentary code to connect/query/iterate/insert/disconnect, then the code grew as the program grew, and it ended up with a mess that's hardly reusable.</p>
<p>I know there are many PEAR, PECL, and other PHP libraries/classes out there that can fit my description - but which ones are maintained, used, and have proven to be bug-free and efficient?</p>
|
[
{
"answer_id": 171157,
"author": "Darryl Hein",
"author_id": 5441,
"author_profile": "https://Stackoverflow.com/users/5441",
"pm_score": 1,
"selected": false,
"text": "GetAll() GetAllKeyed() GetOne() INSERT UPDATE SELECT DELETE INSERT DELETE"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18406/"
] |
171,130
|
<p>So is there a way to initialize and start a command line Spring app without writing a main method. It seems like all such main methods have the same form</p>
<pre><code>public static void main(final String[] args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml", Boot.class);
FooService fooService = (FooService) ctx.getBean("fooService");
fooService.bar();
}
</code></pre>
<p>I suppose that's not complicated, but has someone found a way to provide a way to just specify the <code>context.xml</code> at the command line or, better yet, in a manifest file?</p>
<p>The goal here is to simplify the creation of spring applications as executable jars. I hope that I can specify some utility class as the <code>Main-Class</code> in the manifest. I suppose I would also need to specify the starting point for the app, a bean and a method on it where begins the process.</p>
|
[
{
"answer_id": 171198,
"author": "SaM",
"author_id": 883,
"author_profile": "https://Stackoverflow.com/users/883",
"pm_score": 3,
"selected": false,
"text": "java -jar myjar.jar context.xml <project>\n <modelVersion>4.0.0</modelVersion>\n <groupId>com.stackoverflow</groupId>\n <artifactId>stackoverflow-autostart-spring-app</artifactId>\n <version>0.1</version>\n\n <dependencies>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring</artifactId>\n <version>2.5.2</version>\n </dependency>\n </dependencies>\n <build>\n <plugins>\n <plugin>\n <artifactId>maven-jar-plugin</artifactId>\n <configuration>\n <archive>\n <manifest>\n <mainClass>com.stackoverflow.spring.autostart.Autostart</mainClass>\n </manifest>\n </archive>\n </configuration>\n </plugin>\n <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-shade-plugin</artifactId>\n <executions>\n <execution>\n <phase>package</phase>\n <goals>\n <goal>shade</goal>\n </goals>\n </execution>\n </executions>\n </plugin>\n </plugins>\n </build>\n</project>\n src/main/java context.xml src/main/resources pom.xml target\\stackoverflow-autostart-spring-app-0.1.jar mvn package"
},
{
"answer_id": 172132,
"author": "oxbow_lakes",
"author_id": 16853,
"author_profile": "https://Stackoverflow.com/users/16853",
"pm_score": 2,
"selected": false,
"text": "SpringMain xml properties java -cp myapp.jar util.SpringMain context.xml\n init-method"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171130",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4893/"
] |
171,173
|
<p>I'm trying to perform a bitwise NOT in SQL Server. I'd like to do something like this:</p>
<pre><code>update foo
set Sync = NOT @IsNew
</code></pre>
<p>Note: I started writing this and found out the answer to my own question before I finished. I still wanted to share with the community, since this piece of documentation was lacking on MSDN (until I added it to the Community Content there, too).</p>
|
[
{
"answer_id": 171193,
"author": "Jason Kresowaty",
"author_id": 14280,
"author_profile": "https://Stackoverflow.com/users/14280",
"pm_score": 8,
"selected": true,
"text": "update foo\nset Sync = ~@IsNew\n"
},
{
"answer_id": 18085572,
"author": "Oliver",
"author_id": 28828,
"author_profile": "https://Stackoverflow.com/users/28828",
"pm_score": 2,
"selected": false,
"text": "SELECT b, 1 - b\nFROM\n (SELECT cast(1 AS BIT) AS b\n UNION ALL\n SELECT cast(0 AS BIT) AS b) sampletable\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171173",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/73794/"
] |
171,196
|
<p>I've implemented a basic search for a research project. I'm trying to make the search more efficient by building a <a href="http://en.wikipedia.org/wiki/Suffix_tree" rel="noreferrer">suffix tree</a>. I'm interested in a C# implementation of the <a href="http://en.wikipedia.org/wiki/Ukkonen%27s_algorithm" rel="noreferrer">Ukkonen</a> algorith. I don't want to waste time rolling my own if such implementation exists.</p>
|
[
{
"answer_id": 18787996,
"author": "cdiggins",
"author_id": 184528,
"author_profile": "https://Stackoverflow.com/users/184528",
"pm_score": 2,
"selected": false,
"text": "O(N Log N) using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Linq;\nusing NUnit.Framework;\n\nnamespace FunStuff\n{\n public class SuffixTree\n {\n public class Node\n {\n public int Index = -1;\n public Dictionary<char, Node> Children = new Dictionary<char, Node>();\n }\n\n public Node Root = new Node();\n public String Text;\n\n public void InsertSuffix(string s, int from)\n { \n var cur = Root;\n for (int i = from; i < s.Length; ++i)\n {\n var c = s[i];\n if (!cur.Children.ContainsKey(c))\n {\n var n = new Node() {Index = from};\n cur.Children.Add(c, n);\n\n // Very slow assertion. \n Debug.Assert(Find(s.Substring(from)).Any());\n\n return;\n }\n cur = cur.Children[c];\n }\n Debug.Assert(false, \"It should never be possible to arrive at this case\");\n throw new Exception(\"Suffix tree corruption\");\n }\n\n private static IEnumerable<Node> VisitTree(Node n)\n {\n foreach (var n1 in n.Children.Values)\n foreach (var n2 in VisitTree(n1))\n yield return n2;\n yield return n;\n }\n\n public IEnumerable<int> Find(string s)\n {\n var n = FindNode(s);\n if (n == null) yield break;\n foreach (var n2 in VisitTree(n))\n yield return n2.Index;\n }\n\n private Node FindNode(string s)\n {\n var cur = Root;\n for (int i = 0; i < s.Length; ++i)\n {\n var c = s[i];\n if (!cur.Children.ContainsKey(c))\n {\n // We are at a leaf-node.\n // What we do here is check to see if the rest of the string is at this location. \n for (var j=i; j < s.Length; ++j)\n if (cur.Index + j >= Text.Length || Text[cur.Index + j] != s[j])\n return null;\n return cur;\n }\n cur = cur.Children[c];\n }\n return cur;\n }\n\n public SuffixTree(string s)\n {\n Text = s;\n for (var i = s.Length - 1; i >= 0; --i)\n InsertSuffix(s, i);\n Debug.Assert(VisitTree(Root).Count() - 1 == s.Length);\n }\n }\n\n [TestFixture]\n public class TestSuffixTree\n {\n [Test]\n public void TestBasics()\n {\n var s = \"banana\";\n var t = new SuffixTree(s);\n var results = t.Find(\"an\").ToArray();\n Assert.AreEqual(2, results.Length);\n Assert.AreEqual(1, results[0]);\n Assert.AreEqual(3, results[1]);\n }\n } \n}\n"
},
{
"answer_id": 46450867,
"author": "George Mamaladze",
"author_id": 836202,
"author_profile": "https://Stackoverflow.com/users/836202",
"pm_score": 4,
"selected": true,
"text": "using Gma.DataStructures.StringSearch;\n\n...\n\nvar trie = new UkkonenTrie<int>(3);\n//var trie = new SuffixTrie<int>(3);\n\ntrie.Add(\"hello\", 1);\ntrie.Add(\"world\", 2);\ntrie.Add(\"hell\", 3);\n\nvar result = trie.Retrieve(\"hel\");\n"
}
] |
2008/10/04
|
[
"https://Stackoverflow.com/questions/171196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23164/"
] |
171,205
|
<p>I've always been able to allocate 1400 megabytes for Java SE running on 32-bit Windows XP (Java 1.4, 1.5 and 1.6).</p>
<pre><code>java -Xmx1400m ...
</code></pre>
<p>Today I tried the same option on a new Windows XP machine using Java 1.5_16 and 1.6.0_07 and got the error:</p>
<pre><code>Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
</code></pre>
<p>Through trial and error it seems 1200 megabytes is the most I can allocate on this machine.</p>
<p>Any ideas why one machine would allow 1400 and another only 1200?</p>
<p>Edit: The machine has 4GB of RAM with about 3.5GB that Windows can recognize.</p>
|
[
{
"answer_id": 30807786,
"author": "Michael",
"author_id": 575766,
"author_profile": "https://Stackoverflow.com/users/575766",
"pm_score": 1,
"selected": false,
"text": " java -XX:+PrintFlagsFinal\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24396/"
] |
171,213
|
<p>I need to make sure that user can run only one instance of my program at a time.<br>
Which means, that I have to check programatically, whether the same program is already running, and quit in such case.</p>
<p>The first thing that came to my mind was to create a file somewhere, when the program starts. Then, each other instance of the program would check for this file and exit if it found it.<br>
The trouble is, that the program must always exit gracefully and be able to delete the file it created, for this to work.
In case of, say, power outage, the lock file remains in place and the program can't be started again.</p>
<p>To solve this, I decided to store the first program's process ID into the lock file and when another instance starts, it checks if the PID from the file is attached to some running process.<br>
If the file doesn't exist, is empty, or the PID doesn't correspond to any existing process, the program continues to run and writes its own PID to the file.</p>
<p>This seems to work quite fine - even after an unexpected shutdown, the chance that the (now obsolete) process ID will be associated with some other program, seems to be quite low.</p>
<p>But it still doesn't feel right (there <em>is</em> a chance of getting locked by some unrelated process) and working with process IDs seems to go beyond the standard C++ and probably isn't very portable either.</p>
<p>So, is there another (more clean and secure) way of doing this? Ideally one that would work with the ISO 98 C++ standard and on Windows and *nix alike.<br>
If it cannot be done platform-independently, Linux/Unix is a priority for me.</p>
|
[
{
"answer_id": 171220,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 6,
"selected": true,
"text": " #define APPLICATION_INSTANCE_MUTEX_NAME \"{BA49C45E-B29A-4359-A07C-51B65B5571AD}\"\n\n //Make sure at most one instance of the tool is running\n HANDLE hMutexOneInstance(::CreateMutex( NULL, TRUE, APPLICATION_INSTANCE_MUTEX_NAME));\n bool bAlreadyRunning((::GetLastError() == ERROR_ALREADY_EXISTS));\n if (hMutexOneInstance == NULL || bAlreadyRunning)\n {\n if(hMutexOneInstance)\n {\n ::ReleaseMutex(hMutexOneInstance);\n ::CloseHandle(hMutexOneInstance);\n }\n throw std::exception(\"The application is already running\");\n }\n FILE_SHARE_WRITE CreateFile flock"
},
{
"answer_id": 171222,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "/var/run *.pid flock()"
},
{
"answer_id": 171225,
"author": "jvasak",
"author_id": 5840,
"author_profile": "https://Stackoverflow.com/users/5840",
"pm_score": 0,
"selected": false,
"text": "kill -9"
},
{
"answer_id": 171231,
"author": "Ron Savage",
"author_id": 12476,
"author_profile": "https://Stackoverflow.com/users/12476",
"pm_score": 0,
"selected": false,
"text": " '*************************************************************************\n ' Sub: CheckForProcess()\n ' Author: Ron Savage\n ' Date: 10/31/2007\n '\n ' This routine checks for a running process of this app with the same\n ' command line parameters.\n '*************************************************************************\n Private Function CheckForProcess(ByVal processText As String) As Boolean\n Dim isRunning As Boolean = False\n Dim search As New ManagementObjectSearcher(\"SELECT * FROM Win32_process\")\n Dim info As ManagementObject\n Dim procName As String = \"\"\n Dim procId As String = \"\"\n Dim procCommandLine As String = \"\"\n\n For Each info In search.Get()\n If (IsNothing(info.Properties(\"Name\").Value)) Then procName = \"NULL\" Else procName = Split(info.Properties(\"Name\").Value.ToString, \".\")(0)\n If (IsNothing(info.Properties(\"ProcessId\").Value)) Then procId = \"NULL\" Else procId = info.Properties(\"ProcessId\").Value.ToString\n If (IsNothing(info.Properties(\"CommandLine\").Value)) Then procCommandLine = \"NULL\" Else procCommandLine = info.Properties(\"CommandLine\").Value.ToString\n\n If (Not procId.Equals(Me.processId) And procName.Equals(processName) And procCommandLine.Contains(processText)) Then\n isRunning = True\n End If\n Next\n\n Return (isRunning)\n End Function\n"
},
{
"answer_id": 42894972,
"author": "Alexandru Irimiea",
"author_id": 4806882,
"author_profile": "https://Stackoverflow.com/users/4806882",
"pm_score": 0,
"selected": false,
"text": "boost/interprocess/sync/named_mutex"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2239/"
] |
171,230
|
<p>I need to get access to the iTunes tags in an RSS feed using PHP. I've used simplepie before for podcast feeds, but I'm not sure how to get the iTunes tags using it. Is there a way to use simplepie to do it or is there a better way?</p>
<hr>
<p>Okay I tried Simple XML.</p>
<p>All this (the code below) seems to work</p>
<pre><code>$feed = simplexml_load_file('http://sbhosting.com/feed/');
$channel = $feed->channel;
$channel_itunes = $channel->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
$summary = $channel_itunes->summary;
$subtitle = $channel_itunes->subtitle;
$category = $channel_itunes->category;
$owner = $channel_itunes->owner->name;
</code></pre>
<p>Now I need to get the itunes categories. The seem to be represented in several ways.
In this case I get the follow XML:</p>
<pre><code><itunes:category text="Technology"/>
<itunes:category text="Technology">
<itunes:category text="Software How-To"/>
</itunes:category>
</code></pre>
<p>I would expect to be able to get the category with something like this:</p>
<pre><code>$category_text = $channel_itunes->category['text'];
</code></pre>
<p>But that does not seem to work.</p>
<p>I've seen other ways to represent the category that I really don't know who to get.</p>
<p>For example:</p>
<p>Technology
Business
Education</p>
<p>Is this a media thing or a itunes thing or both?</p>
<p>Thanks For Your Help.
G</p>
|
[
{
"answer_id": 171378,
"author": "ceejayoz",
"author_id": 1902010,
"author_profile": "https://Stackoverflow.com/users/1902010",
"pm_score": 2,
"selected": false,
"text": "get_item_tags()"
},
{
"answer_id": 382932,
"author": "Doug Kaye",
"author_id": 17307,
"author_profile": "https://Stackoverflow.com/users/17307",
"pm_score": 2,
"selected": true,
"text": "//$pie is a SimplePie object\n$iTunesCategories=$pie->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES,'category');\nif ($iTunesCategories) {\n foreach ($iTunesCategories as $iTunesCategory) {\n $category=$iTunesCategory['attribs']['']['text'];\n $subcat=$iTunesCategory['child'][\"http://www.itunes.com/dtds/podcast-1.0.dtd\"]['category'][0]['attribs']['']['text'];\n if ($subcat) {\n $category.=\":$subcat\";\n }\n //do something with $category\n }\n}\n"
},
{
"answer_id": 51608061,
"author": "Firegab",
"author_id": 1029870,
"author_profile": "https://Stackoverflow.com/users/1029870",
"pm_score": 1,
"selected": false,
"text": "$category_text = $channel_itunes->category['text'];\n $category_text = $channel_itunes->category->attributes()->text;\n"
},
{
"answer_id": 71047924,
"author": "shubham ralli",
"author_id": 14506610,
"author_profile": "https://Stackoverflow.com/users/14506610",
"pm_score": 0,
"selected": false,
"text": "<?php echo $feed_item->children('itunes', true)->image->attributes()->href;?>\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/457918/"
] |
171,251
|
<p>I need to be able to merge two (very simple) JavaScript objects at runtime. For example I'd like to:</p>
<pre><code>var obj1 = { food: 'pizza', car: 'ford' }
var obj2 = { animal: 'dog' }
obj1.merge(obj2);
//obj1 now has three properties: food, car, and animal
</code></pre>
<p>Is there a built in way to do this? I do not need recursion, and I do not need to merge functions, just methods on flat objects.</p>
|
[
{
"answer_id": 171256,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 13,
"selected": true,
"text": "let merged = {...obj1, ...obj2};\n merged obj1 obj2 obj2 obj1 /** There's no limit to the number of objects you can merge.\n * Later properties overwrite earlier properties with the same name. */\nconst allRules = {...obj1, ...obj2, ...obj3};\n /* For the case in question, you would do: */\nObject.assign(obj1, obj2);\n\n/** There's no limit to the number of objects you can merge.\n * All objects get merged into the first object. \n * Only the object in the first argument is mutated and returned.\n * Later properties overwrite earlier properties with the same name. */\nconst allRules = Object.assign({}, obj1, obj2, obj3, etc);\n for (var attrname in obj2) { obj1[attrname] = obj2[attrname]; }\n obj2 obj1 obj1 hasOwnProperty /**\n * Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1\n * @param obj1\n * @param obj2\n * @returns obj3 a new object based on obj1 and obj2\n */\nfunction merge_options(obj1,obj2){\n var obj3 = {};\n for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }\n for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }\n return obj3;\n}\n"
},
{
"answer_id": 171258,
"author": "ephemient",
"author_id": 20713,
"author_profile": "https://Stackoverflow.com/users/20713",
"pm_score": 4,
"selected": false,
"text": "Object.extend = function(destination,source) {\n for (var property in source)\n destination[property] = source[property];\n return destination;\n}\n obj1.extend(obj2)"
},
{
"answer_id": 171455,
"author": "Avdi",
"author_id": 20487,
"author_profile": "https://Stackoverflow.com/users/20487",
"pm_score": 10,
"selected": false,
"text": "// Merge options object into settings object\nvar settings = { validate: false, limit: 5, name: \"foo\" };\nvar options = { validate: true, name: \"bar\" };\njQuery.extend(settings, options);\n\n// Now the content of settings object is the following:\n// { validate: true, limit: 5, name: \"bar\" }\n settings var defaults = { validate: false, limit: 5, name: \"foo\" };\nvar options = { validate: true, name: \"bar\" };\n\n/* Merge defaults and options, without modifying defaults */\nvar settings = $.extend({}, defaults, options);\n\n// The content of settings variable is now the following:\n// {validate: true, limit: 5, name: \"bar\"}\n// The 'defaults' and 'options' variables remained the same.\n"
},
{
"answer_id": 383245,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 8,
"selected": false,
"text": "Object.prototype /*\n* Recursively merge properties of two objects \n*/\nfunction MergeRecursive(obj1, obj2) {\n\n for (var p in obj2) {\n try {\n // Property in destination object set; update its value.\n if ( obj2[p].constructor==Object ) {\n obj1[p] = MergeRecursive(obj1[p], obj2[p]);\n\n } else {\n obj1[p] = obj2[p];\n\n }\n\n } catch(e) {\n // Property in destination object not set; create it and set its value.\n obj1[p] = obj2[p];\n\n }\n }\n\n return obj1;\n}\n o1 = { a : 1,\n b : 2,\n c : {\n ca : 1,\n cb : 2,\n cc : {\n cca : 100,\n ccb : 200 } } };\n\no2 = { a : 10,\n c : {\n ca : 10,\n cb : 20, \n cc : {\n cca : 101,\n ccb : 202 } } };\n\no3 = MergeRecursive(o1, o2);\n o3 = { a : 10,\n b : 2,\n c : {\n ca : 10,\n cb : 20,\n cc : { \n cca : 101,\n ccb : 202 } } };\n"
},
{
"answer_id": 384432,
"author": "Christoph",
"author_id": 48015,
"author_profile": "https://Stackoverflow.com/users/48015",
"pm_score": 5,
"selected": false,
"text": "source.hasOwnProperty(property) for..in"
},
{
"answer_id": 642522,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "var obj1 = {food: 'pizza', car: 'ford'}\nvar obj2 = {animal: 'dog'}\n\nobj1 = Object.extend(obj1, obj2);\n"
},
{
"answer_id": 1214602,
"author": "philfreo",
"author_id": 137067,
"author_profile": "https://Stackoverflow.com/users/137067",
"pm_score": 3,
"selected": false,
"text": "Object.merge(obj1, obj2);\n"
},
{
"answer_id": 2344174,
"author": "Algy",
"author_id": 282303,
"author_profile": "https://Stackoverflow.com/users/282303",
"pm_score": 4,
"selected": false,
"text": "var obj1 = { food: 'pizza', car: 'ford' }\nvar obj2 = { animal: 'dog', car: 'chevy'}\nvar objMerge;\n\nobjMerge = JSON.stringify(obj1) + JSON.stringify(obj2);\n\n// {\"food\": \"pizza\",\"car\":\"ford\"}{\"animal\":\"dog\",\"car\":\"chevy\"}\n\nobjMerge = objMerge.replace(/\\}\\{/, \",\"); // \\_ replace with comma for valid JSON\n\nobjMerge = JSON.parse(objMerge); // { food: 'pizza', animal: 'dog', car: 'chevy'}\n// Of same keys in both objects, the last object's value is retained_/\n"
},
{
"answer_id": 5522973,
"author": "gossi",
"author_id": 483492,
"author_profile": "https://Stackoverflow.com/users/483492",
"pm_score": 4,
"selected": false,
"text": "Object.defineProperty(Object.prototype, \"merge\", {\n enumerable: false,\n value: function () {\n var override = true,\n dest = this,\n len = arguments.length,\n props, merge, i, from;\n\n if (typeof(arguments[arguments.length - 1]) === \"boolean\") {\n override = arguments[arguments.length - 1];\n len = arguments.length - 1;\n }\n\n for (i = 0; i < len; i++) {\n from = arguments[i];\n if (from != null) {\n Object.getOwnPropertyNames(from).forEach(function (name) {\n var descriptor;\n\n // nesting\n if ((typeof(dest[name]) === \"object\" || typeof(dest[name]) === \"undefined\")\n && typeof(from[name]) === \"object\") {\n\n // ensure proper types (Array rsp Object)\n if (typeof(dest[name]) === \"undefined\") {\n dest[name] = Array.isArray(from[name]) ? [] : {};\n }\n if (override) {\n if (!Array.isArray(dest[name]) && Array.isArray(from[name])) {\n dest[name] = [];\n }\n else if (Array.isArray(dest[name]) && !Array.isArray(from[name])) {\n dest[name] = {};\n }\n }\n dest[name].merge(from[name], override);\n } \n\n // flat properties\n else if ((name in dest && override) || !(name in dest)) {\n descriptor = Object.getOwnPropertyDescriptor(from, name);\n if (descriptor.configurable) {\n Object.defineProperty(dest, name, descriptor);\n }\n }\n });\n }\n }\n return this;\n }\n});\n function clone (obj) {\n return JSON.parse(JSON.stringify(obj));\n}\nvar obj = {\n name : \"trick\",\n value : \"value\"\n};\n\nvar mergeObj = {\n name : \"truck\",\n value2 : \"value2\"\n};\n\nvar mergeObj2 = {\n name : \"track\",\n value : \"mergeObj2\",\n value2 : \"value2-mergeObj2\",\n value3 : \"value3\"\n};\n\nassertTrue(\"Standard\", clone(obj).merge(mergeObj).equals({\n name : \"truck\",\n value : \"value\",\n value2 : \"value2\"\n}));\n\nassertTrue(\"Standard no Override\", clone(obj).merge(mergeObj, false).equals({\n name : \"trick\",\n value : \"value\",\n value2 : \"value2\"\n}));\n\nassertTrue(\"Multiple\", clone(obj).merge(mergeObj, mergeObj2).equals({\n name : \"track\",\n value : \"mergeObj2\",\n value2 : \"value2-mergeObj2\",\n value3 : \"value3\"\n}));\n\nassertTrue(\"Multiple no Override\", clone(obj).merge(mergeObj, mergeObj2, false).equals({\n name : \"trick\",\n value : \"value\",\n value2 : \"value2\",\n value3 : \"value3\"\n}));\n\nvar deep = {\n first : {\n name : \"trick\",\n val : \"value\"\n },\n second : {\n foo : \"bar\"\n }\n};\n\nvar deepMerge = {\n first : {\n name : \"track\",\n anotherVal : \"wohoo\"\n },\n second : {\n foo : \"baz\",\n bar : \"bam\"\n },\n v : \"on first layer\"\n};\n\nassertTrue(\"Deep merges\", clone(deep).merge(deepMerge).equals({\n first : {\n name : \"track\",\n val : \"value\",\n anotherVal : \"wohoo\"\n },\n second : {\n foo : \"baz\",\n bar : \"bam\"\n },\n v : \"on first layer\"\n}));\n\nassertTrue(\"Deep merges no override\", clone(deep).merge(deepMerge, false).equals({\n first : {\n name : \"trick\",\n val : \"value\",\n anotherVal : \"wohoo\"\n },\n second : {\n foo : \"bar\",\n bar : \"bam\"\n },\n v : \"on first layer\"\n}));\n\nvar obj1 = {a: 1, b: \"hello\"};\nobj1.merge({c: 3});\nassertTrue(obj1.equals({a: 1, b: \"hello\", c: 3}));\n\nobj1.merge({a: 2, b: \"mom\", d: \"new property\"}, false);\nassertTrue(obj1.equals({a: 1, b: \"hello\", c: 3, d: \"new property\"}));\n\nvar obj2 = {};\nobj2.merge({a: 1}, {b: 2}, {a: 3});\nassertTrue(obj2.equals({a: 3, b: 2}));\n\nvar a = [];\nvar b = [1, [2, 3], 4];\na.merge(b);\nassertEquals(1, a[0]);\nassertEquals([2, 3], a[1]);\nassertEquals(4, a[2]);\n\n\nvar o1 = {};\nvar o2 = {a: 1, b: {c: 2}};\nvar o3 = {d: 3};\no1.merge(o2, o3);\nassertTrue(o1.equals({a: 1, b: {c: 2}, d: 3}));\no1.b.c = 99;\nassertTrue(o2.equals({a: 1, b: {c: 2}}));\n\n// checking types with arrays and objects\nvar bo;\na = [];\nbo = [1, {0:2, 1:3}, 4];\nb = [1, [2, 3], 4];\n\na.merge(b);\nassertTrue(\"Array stays Array?\", Array.isArray(a[1]));\n\na = [];\na.merge(bo);\nassertTrue(\"Object stays Object?\", !Array.isArray(a[1]));\n\na = [];\na.merge(b);\na.merge(bo);\nassertTrue(\"Object overrides Array\", !Array.isArray(a[1]));\n\na = [];\na.merge(b);\na.merge(bo, false);\nassertTrue(\"Object does not override Array\", Array.isArray(a[1]));\n\na = [];\na.merge(bo);\na.merge(b);\nassertTrue(\"Array overrides Object\", Array.isArray(a[1]));\n\na = [];\na.merge(bo);\na.merge(b, false);\nassertTrue(\"Array does not override Object\", !Array.isArray(a[1]));\n"
},
{
"answer_id": 6548123,
"author": "antony",
"author_id": 753440,
"author_profile": "https://Stackoverflow.com/users/753440",
"pm_score": 1,
"selected": false,
"text": "Arguments function mergeObjects() (\n var tmpObj = {};\n\n for(var o in arguments) {\n for(var m in arguments[o]) {\n tmpObj[m] = arguments[o][m];\n }\n }\n return tmpObj;\n}\n"
},
{
"answer_id": 6635477,
"author": "RobKohr",
"author_id": 101909,
"author_profile": "https://Stackoverflow.com/users/101909",
"pm_score": 2,
"selected": false,
"text": "//Takes any number of objects and returns one merged object\nvar objectMerge = function(){\n var out = {};\n if(!arguments.length)\n return out;\n for(var i=0; i<arguments.length; i++) {\n for(var key in arguments[i]){\n out[key] = arguments[i][key];\n }\n }\n return out;\n}\n console.log(objectMerge({a:1, b:2}, {a:2, c:4}));\n { a: 2, b: 2, c: 4 }\n"
},
{
"answer_id": 6787677,
"author": "Mark",
"author_id": 491379,
"author_profile": "https://Stackoverflow.com/users/491379",
"pm_score": 3,
"selected": false,
"text": "var mergedObject = Ext.Object.merge(object1, object2)\n\n// Or shorter:\nvar mergedObject2 = Ext.merge(object1, object2)\n"
},
{
"answer_id": 7173308,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "from = arguments[i];\nObject.getOwnPropertyNames(from).forEach(function (name) {\n"
},
{
"answer_id": 7965071,
"author": "vsync",
"author_id": 104380,
"author_profile": "https://Stackoverflow.com/users/104380",
"pm_score": 2,
"selected": false,
"text": "function extend(o, o1, o2){\n if( !(o instanceof Object) ) o = {};\n\n copy(o, o1);\n if( o2 )\n copy(o, o2)\n\n function isObject(obj) {\n var type = Object.prototype.toString.call(obj);\n return obj === Object(obj) && type != '[object Array]' && type != '[object Function]';\n };\n\n function copy(a,b){\n // copy o2 to o\n for( var key in b )\n if( b.hasOwnProperty(key) ){\n if( isObject(b[key]) ){\n if( !isObject(a[key]) )\n a[key] = Object.assign({}, b[key]); \n else copy(a[key], b[key])\n }\n else\n a[key] = b[key];\n }\n }\n\n return o;\n};\n\n\nvar o1 = {a:{foo:1}, b:1},\n o2 = {a:{bar:2}, b:[1], c:()=>{}},\n newMerged = extend({}, o1, o2);\n \nconsole.log( newMerged )\nconsole.log( o1 )\nconsole.log( o2 )"
},
{
"answer_id": 8625261,
"author": "Emre Erkan",
"author_id": 84042,
"author_profile": "https://Stackoverflow.com/users/84042",
"pm_score": 6,
"selected": false,
"text": "var merge = function() {\n var obj = {},\n i = 0,\n il = arguments.length,\n key;\n for (; i < il; i++) {\n for (key in arguments[i]) {\n if (arguments[i].hasOwnProperty(key)) {\n obj[key] = arguments[i][key];\n }\n }\n }\n return obj;\n};\n var t1 = {\n key1: 1,\n key2: \"test\",\n key3: [5, 2, 76, 21]\n};\nvar t2 = {\n key1: {\n ik1: \"hello\",\n ik2: \"world\",\n ik3: 3\n }\n};\nvar t3 = {\n key2: 3,\n key3: {\n t1: 1,\n t2: 2,\n t3: {\n a1: 1,\n a2: 3,\n a4: [21, 3, 42, \"asd\"]\n }\n }\n};\n\nconsole.log(merge(t1, t2));\nconsole.log(merge(t1, t3));\nconsole.log(merge(t2, t3));\nconsole.log(merge(t1, t2, t3));\nconsole.log(merge({}, t1, { key1: 1 }));\n"
},
{
"answer_id": 8764974,
"author": "Snoozer Man",
"author_id": 1131084,
"author_profile": "https://Stackoverflow.com/users/1131084",
"pm_score": 3,
"selected": false,
"text": "function mergeRecursive() {\n\n // _mergeRecursive does the actual job with two arguments.\n var _mergeRecursive = function (dst, src) {\n if (isDOMNode(src) || typeof src !== 'object' || src === null) {\n return dst;\n }\n\n for (var p in src) {\n if (!src.hasOwnProperty(p))\n continue;\n if (src[p] === undefined)\n continue;\n if ( typeof src[p] !== 'object' || src[p] === null) {\n dst[p] = src[p];\n } else if (typeof dst[p]!=='object' || dst[p] === null) {\n dst[p] = _mergeRecursive(src[p].constructor===Array ? [] : {}, src[p]);\n } else {\n _mergeRecursive(dst[p], src[p]);\n }\n }\n return dst;\n }\n\n // Loop through arguments and merge them into the first argument.\n var out = arguments[0];\n if (typeof out !== 'object' || out === null)\n return out;\n for (var i = 1, il = arguments.length; i < il; i++) {\n _mergeRecursive(out, arguments[i]);\n }\n return out;\n}\n mergeRecursive(\n document.getElementById('mydiv'),\n {style: {border: '5px solid green', color: 'red'}},\n {innerHTML: 'Hello world!'});\n o = mergeRecursive({a:'a'}, [1,2,3], [undefined, null, [30,31]], {a:undefined, b:'b'});\n// o = {0:1, 1:null, 2:[30,31], a:'a', b:'b'}\n o = mergeRecursive({a:'a'}, 1, true, null, undefined, [1,2,3], 'bc', new String('de'));\n// o = {0:'d', 1:'e', 2:3, a:'a'}\n var a={}, b={b:'abc'}, c={c:'cde'}, o;\no = mergeRecursive(a, b, c);\n// o===a is true, o===b is false, o===c is false\n function mergeRecursive(obj1, obj2) {\n if (Array.isArray(obj2)) { return obj1.concat(obj2); }\n for (var p in obj2) {\n try {\n // Property in destination object set; update its value.\n if ( obj2[p].constructor==Object ) {\n obj1[p] = mergeRecursive(obj1[p], obj2[p]);\n } else if (Array.isArray(obj2[p])) {\n obj1[p] = obj1[p].concat(obj2[p]);\n } else {\n obj1[p] = obj2[p];\n }\n } catch(e) {\n // Property in destination object not set; create it and set its value.\n obj1[p] = obj2[p];\n }\n }\n return obj1;\n}\n"
},
{
"answer_id": 9199271,
"author": "Prabhakar Kasi",
"author_id": 465659,
"author_profile": "https://Stackoverflow.com/users/465659",
"pm_score": 1,
"selected": false,
"text": "Y.merge Y.merge(obj1, obj2, obj3....) \n"
},
{
"answer_id": 9348845,
"author": "Industrial",
"author_id": 198128,
"author_profile": "https://Stackoverflow.com/users/198128",
"pm_score": 7,
"selected": false,
"text": "underscore.js extend _.extend({name : 'moe'}, {age : 50});\n=> {name : 'moe', age : 50}\n"
},
{
"answer_id": 10236991,
"author": "Paweł Szczur",
"author_id": 436754,
"author_profile": "https://Stackoverflow.com/users/436754",
"pm_score": 4,
"selected": false,
"text": "goog.require('goog.object');\nvar a = {'a': 1, 'b': 2};\nvar b = {'b': 3, 'c': 4};\ngoog.object.extend(a, b);\n// Now object a == {'a': 1, 'b': 3, 'c': 4};\n var a = [1, 2];\nvar b = [3, 4];\ngoog.array.extend(a, b); // Extends array 'a'\ngoog.array.concat(a, b); // Returns concatenation of array 'a' and 'b'\n"
},
{
"answer_id": 10863292,
"author": "Michael Benin",
"author_id": 659696,
"author_profile": "https://Stackoverflow.com/users/659696",
"pm_score": -1,
"selected": false,
"text": "function extend()\n{ \n var o = {}; \n\n for (var i in arguments)\n { \n var s = arguments[i]; \n\n for (var i in s)\n { \n o[i] = s[i]; \n } \n } \n\n return o;\n}\n"
},
{
"answer_id": 12495197,
"author": "Andreas Linden",
"author_id": 412395,
"author_profile": "https://Stackoverflow.com/users/412395",
"pm_score": 5,
"selected": false,
"text": "to from to[n] is undefined var realMerge = function (to, from) {\n\n for (n in from) {\n\n if (typeof to[n] != 'object') {\n to[n] = from[n];\n } else if (typeof from[n] == 'object') {\n to[n] = realMerge(to[n], from[n]);\n }\n }\n return to;\n};\n var merged = realMerge(obj1, obj2);\n"
},
{
"answer_id": 12669852,
"author": "Aram Kocharyan",
"author_id": 549848,
"author_profile": "https://Stackoverflow.com/users/549848",
"pm_score": 0,
"selected": false,
"text": "obj def obj obj def function mergeObjs(def, obj) {\n if (typeof obj == 'undefined') {\n return def;\n } else if (typeof def == 'undefined') {\n return obj;\n }\n for (var i in obj) {\n if (obj[i] != null && obj[i].constructor == Object) {\n def[i] = mergeObjs(def[i], obj[i]);\n } else {\n def[i] = obj[i];\n }\n }\n return def;\n}\n\na = {x : {y : [123]}}\nb = {x : {z : 123}}\nconsole.log(mergeObjs(a, b));\n// {x: {y : [123], z : 123}}\n"
},
{
"answer_id": 12971555,
"author": "pagid",
"author_id": 116932,
"author_profile": "https://Stackoverflow.com/users/116932",
"pm_score": 2,
"selected": false,
"text": "function m(a,b,c){for(c in b)b.hasOwnProperty(c)&&((typeof a[c])[0]=='o'?m(a[c],b[c]):a[c]=b[c])}\n m(obj1,obj2);\n"
},
{
"answer_id": 13958020,
"author": "jleviaguirre",
"author_id": 922290,
"author_profile": "https://Stackoverflow.com/users/922290",
"pm_score": 0,
"selected": false,
"text": "A={a:1,b:function(){alert(9)}}\nB={a:2,c:3}\nA.merge = function(){for(var i in B){A[i]=B[i]}}\nA.merge()\n"
},
{
"answer_id": 16178864,
"author": "Paul Spaulding",
"author_id": 1720197,
"author_profile": "https://Stackoverflow.com/users/1720197",
"pm_score": 5,
"selected": false,
"text": "/*\n Recursively merge properties and return new object\n obj1 <- obj2 [ <- ... ]\n*/\nfunction merge () {\n var dst = {}\n ,src\n ,p\n ,args = [].splice.call(arguments, 0)\n ;\n\n while (args.length > 0) {\n src = args.splice(0, 1)[0];\n if (toString.call(src) == '[object Object]') {\n for (p in src) {\n if (src.hasOwnProperty(p)) {\n if (toString.call(src[p]) == '[object Object]') {\n dst[p] = merge(dst[p] || {}, src[p]);\n } else {\n dst[p] = src[p];\n }\n }\n }\n }\n }\n\n return dst;\n}\n a = {\n \"p1\": \"p1a\",\n \"p2\": [\n \"a\",\n \"b\",\n \"c\"\n ],\n \"p3\": true,\n \"p5\": null,\n \"p6\": {\n \"p61\": \"p61a\",\n \"p62\": \"p62a\",\n \"p63\": [\n \"aa\",\n \"bb\",\n \"cc\"\n ],\n \"p64\": {\n \"p641\": \"p641a\"\n }\n }\n};\n\nb = {\n \"p1\": \"p1b\",\n \"p2\": [\n \"d\",\n \"e\",\n \"f\"\n ],\n \"p3\": false,\n \"p4\": true,\n \"p6\": {\n \"p61\": \"p61b\",\n \"p64\": {\n \"p642\": \"p642b\"\n }\n }\n};\n\nc = {\n \"p1\": \"p1c\",\n \"p3\": null,\n \"p6\": {\n \"p62\": \"p62c\",\n \"p64\": {\n \"p643\": \"p641c\"\n }\n }\n};\n\nd = merge(a, b, c);\n\n\n/*\n d = {\n \"p1\": \"p1c\",\n \"p2\": [\n \"d\",\n \"e\",\n \"f\"\n ],\n \"p3\": null,\n \"p5\": null,\n \"p6\": {\n \"p61\": \"p61b\",\n \"p62\": \"p62c\",\n \"p63\": [\n \"aa\",\n \"bb\",\n \"cc\"\n ],\n \"p64\": {\n \"p641\": \"p641a\",\n \"p642\": \"p642b\",\n \"p643\": \"p641c\"\n }\n },\n \"p4\": true\n };\n*/\n"
},
{
"answer_id": 17932010,
"author": "Paul",
"author_id": 271554,
"author_profile": "https://Stackoverflow.com/users/271554",
"pm_score": 0,
"selected": false,
"text": "Object.prototype.merge = function(obj, override) {\n// Don't override by default\n\n for (var key in obj) {\n var n = obj[key];\n var t = this[key];\n this[key] = (override && t) ? n : t;\n };\n\n};\n var Mammal = function () {\n this.eyes = 2;\n this.thinking_brain = false;\n this.say = function () {\n console.log('screaming like a mammal')};\n}\n\nvar Human = function () {\n this.thinking_brain = true;\n this.say = function() {console.log('shouting like a human')};\n}\n\njohn = new Human();\n\n// Extend mammal, but do not override from mammal\njohn.merge(new Mammal());\njohn.say();\n\n// Extend mammal and override from mammal\njohn.merge(new Mammal(), true);\njohn.say();\n"
},
{
"answer_id": 17999073,
"author": "korywka",
"author_id": 643514,
"author_profile": "https://Stackoverflow.com/users/643514",
"pm_score": 2,
"selected": false,
"text": "function mergeObjects(defaults, settings) {\n Object.keys(defaults).forEach(function(key_default) {\n if (typeof settings[key_default] == \"undefined\") {\n settings[key_default] = defaults[key_default];\n } else if (isObject(defaults[key_default]) && isObject(settings[key_default])) {\n mergeObjects(defaults[key_default], settings[key_default]);\n }\n });\n\n function isObject(object) {\n return Object.prototype.toString.call(object) === '[object Object]';\n }\n\n return settings;\n}\n"
},
{
"answer_id": 20381012,
"author": "Egor Kloos",
"author_id": 220974,
"author_profile": "https://Stackoverflow.com/users/220974",
"pm_score": 1,
"selected": false,
"text": "function myPlugin( settings ){\n var defaults = {\n \"keyName\": [ \"string 1\", \"string 2\" ]\n }\n var options = Object.create( defaults );\n for (var key in settings) { options[key] = settings[key]; }\n}\nmyPlugin( { \"keyName\": [\"string 3\", \"string 4\" ] } );\n var newArray = options['keyName'].concat( options.__proto__['keyName'] );\n"
},
{
"answer_id": 21391558,
"author": "AndreasE",
"author_id": 326689,
"author_profile": "https://Stackoverflow.com/users/326689",
"pm_score": 6,
"selected": false,
"text": "// Merge the 'options' object into the 'settings' object\nvar settings = {validate: false, limit: 5, name: \"foo\"};\nvar options = {validate: true, name: \"bar\"};\nangular.extend(settings, options);\n"
},
{
"answer_id": 22422836,
"author": "devmao",
"author_id": 757082,
"author_profile": "https://Stackoverflow.com/users/757082",
"pm_score": 3,
"selected": false,
"text": "var arrayOfObjects = [ {a:1}, {b:2, c:3}, {d:4} ];\n_(arrayOfObjects).reduce(function(memo, o) { return _(memo).extend(o); });\n Object {a: 1, b: 2, c: 3, d: 4}\n"
},
{
"answer_id": 22948578,
"author": "Ryan Walls",
"author_id": 411229,
"author_profile": "https://Stackoverflow.com/users/411229",
"pm_score": 1,
"selected": false,
"text": "npm install node.extend\n var extend = require('node.extend');\nvar destObject = extend(true, {}, sourceObject);\n// Where sourceObject is the object whose properties will be copied into another.\n"
},
{
"answer_id": 24355704,
"author": "antitoxic",
"author_id": 339872,
"author_profile": "https://Stackoverflow.com/users/339872",
"pm_score": 4,
"selected": false,
"text": "deepmerge"
},
{
"answer_id": 26206246,
"author": "NanoWizard",
"author_id": 4019986,
"author_profile": "https://Stackoverflow.com/users/4019986",
"pm_score": 9,
"selected": false,
"text": "Object.assign Object.assign(obj1, obj2);\n"
},
{
"answer_id": 26360903,
"author": "Scdev",
"author_id": 3866023,
"author_profile": "https://Stackoverflow.com/users/3866023",
"pm_score": 0,
"selected": false,
"text": " function extendObjects() {\n\n var newObject = {};\n var overwriteValues = false;\n var overwriteObjects = false;\n\n for ( var indexArgument = 0; indexArgument < arguments.length; indexArgument++ ) {\n\n if ( typeof arguments[indexArgument] !== 'object' ) {\n\n if ( arguments[indexArgument] == 'overwriteValues_True' ) {\n\n overwriteValues = true; \n } else if ( arguments[indexArgument] == 'overwriteValues_False' ) {\n\n overwriteValues = false; \n } else if ( arguments[indexArgument] == 'overwriteObjects_True' ) {\n\n overwriteObjects = true; \n } else if ( arguments[indexArgument] == 'overwriteObjects_False' ) {\n\n overwriteObjects = false; \n }\n\n } else {\n\n extendObject( arguments[indexArgument], newObject, overwriteValues, overwriteObjects );\n }\n\n }\n\n function extendObject( object, extendedObject, overwriteValues, overwriteObjects ) {\n\n for ( var indexObject in object ) {\n\n if ( typeof object[indexObject] === 'object' ) {\n\n if ( typeof extendedObject[indexObject] === \"undefined\" || overwriteObjects ) {\n extendedObject[indexObject] = object[indexObject];\n }\n\n extendObject( object[indexObject], extendedObject[indexObject], overwriteValues, overwriteObjects );\n\n } else {\n\n if ( typeof extendedObject[indexObject] === \"undefined\" || overwriteValues ) {\n extendedObject[indexObject] = object[indexObject];\n }\n\n }\n\n } \n\n return extendedObject;\n\n }\n\n return newObject;\n }\n\n var object1 = { a : 1, b : 2, testArr : [888, { innArr : 1 }, 777 ], data : { e : 12, c : { lol : 1 }, rofl : { O : 3 } } };\n var object2 = { a : 6, b : 9, data : { a : 17, b : 18, e : 13, rofl : { O : 99, copter : { mao : 1 } } }, hexa : { tetra : 66 } };\n var object3 = { f : 13, g : 666, a : 333, data : { c : { xD : 45 } }, testArr : [888, { innArr : 3 }, 555 ] };\n\n var newExtendedObject = extendObjects( 'overwriteValues_False', 'overwriteObjects_False', object1, object2, object3 );\n {\"a\":1,\"b\":2,\"testArr\":[888,{\"innArr\":1},777],\"data\":{\"e\":12,\"c\":{\"lol\":1,\"xD\":45},\"rofl\":{\"O\":3,\"copter\":{\"mao\":1}},\"a\":17,\"b\":18},\"hexa\":{\"tetra\":66},\"f\":13,\"g\":666}\n"
},
{
"answer_id": 28227547,
"author": "appsmatics",
"author_id": 1285397,
"author_profile": "https://Stackoverflow.com/users/1285397",
"pm_score": 5,
"selected": false,
"text": "_.extend _.merge"
},
{
"answer_id": 29374455,
"author": "T.Todua",
"author_id": 2377343,
"author_profile": "https://Stackoverflow.com/users/2377343",
"pm_score": 0,
"selected": false,
"text": "function concat_collection(obj1, obj2) {\n var i;\n var arr = new Array();\n\n var len1 = obj1.length;\n for (i=0; i<len1; i++) {\n arr.push(obj1[i]);\n }\n\n var len2 = obj2.length;\n for (i=0; i<len2; i++) {\n arr.push(obj2[i]);\n }\n\n return arr;\n}\n\nvar ELEMENTS = concat_collection(A,B);\nfor(var i = 0; i < ELEMENTS.length; i++) {\n alert(ELEMENTS[i].value);\n}\n"
},
{
"answer_id": 29783305,
"author": "Etherealone",
"author_id": 1576556,
"author_profile": "https://Stackoverflow.com/users/1576556",
"pm_score": 2,
"selected": false,
"text": "var merge = function() {\n var il = arguments.length;\n\n for (var i = il - 1; i > 0; --i) {\n for (var key in arguments[i]) {\n if (arguments[i].hasOwnProperty(key)) {\n arguments[0][key] = arguments[i][key];\n }\n }\n }\n};\n"
},
{
"answer_id": 32305436,
"author": "Dinusha",
"author_id": 685091,
"author_profile": "https://Stackoverflow.com/users/685091",
"pm_score": 4,
"selected": false,
"text": "extend var obj1 = { val1: false, limit: 5, name: \"foo\" };\nvar obj2 = { val2: true, name: \"bar\" };\n\njQuery.extend(obj1, obj2);\n obj1 obj1 obj2"
},
{
"answer_id": 32800440,
"author": "Vikash Pandey",
"author_id": 2728855,
"author_profile": "https://Stackoverflow.com/users/2728855",
"pm_score": 0,
"selected": false,
"text": "// Dojo 1.7+ (AMD)\nrequire([\"dojo/_base/lang\"], function(lang){\n var a = { b:\"c\", d:\"e\" };\n lang.mixin(a, { d:\"f\", g:\"h\" });\n console.log(a); // b:c, d:f, g:h\n});\n\n// Dojo < 1.7\nvar a = { b:\"c\", d:\"e\" };\ndojo.mixin(a, { d:\"f\", g:\"h\" });\nconsole.log(a); // b:c, d:f, g:h\n"
},
{
"answer_id": 33122536,
"author": "Sherali Turdiyev",
"author_id": 4365315,
"author_profile": "https://Stackoverflow.com/users/4365315",
"pm_score": 1,
"selected": false,
"text": "var obj1 = { food: 'pizza', car: 'ford' };\nvar obj2 = { animal: 'dog' };\n\nvar result = mergeObjects([obj1, obj2]);\n\nconsole.log(result);\ndocument.write(\"result: <pre>\" + JSON.stringify(result, 0, 3) + \"</pre>\");\n\nfunction mergeObjects(objectArray) {\n if (objectArray.length) {\n var b = \"\", i = -1;\n while (objectArray[++i]) {\n var str = JSON.stringify(objectArray[i]);\n b += str.slice(1, str.length - 1);\n if (objectArray[i + 1]) b += \",\";\n }\n return JSON.parse(\"{\" + b + \"}\");\n }\n return {};\n}"
},
{
"answer_id": 33740232,
"author": "Reza Roshan",
"author_id": 3819714,
"author_profile": "https://Stackoverflow.com/users/3819714",
"pm_score": 4,
"selected": false,
"text": "var o1 = { a: 1 };\nvar o2 = { b: 2 };\nvar o3 = { c: 3 };\n\nvar obj = Object.assign(o1, o2, o3);\nconsole.log(obj); // { a: 1, b: 2, c: 3 }\nconsole.log(o1); // { a: 1, b: 2, c: 3 }, target object itself is changed.\n"
},
{
"answer_id": 34295099,
"author": "Eugene Tiurin",
"author_id": 2676500,
"author_profile": "https://Stackoverflow.com/users/2676500",
"pm_score": 5,
"selected": false,
"text": "Object.assign IE var clone = Object.assign({}, obj);\n if (!Object.assign) {\n Object.defineProperty(Object, 'assign', {\n enumerable: false,\n configurable: true,\n writable: true,\n value: function(target) {\n 'use strict';\n if (target === undefined || target === null) {\n throw new TypeError('Cannot convert first argument to object');\n }\n\n var to = Object(target);\n for (var i = 1; i < arguments.length; i++) {\n var nextSource = arguments[i];\n if (nextSource === undefined || nextSource === null) {\n continue;\n }\n nextSource = Object(nextSource);\n\n var keysArray = Object.keys(nextSource);\n for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {\n var nextKey = keysArray[nextIndex];\n var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);\n if (desc !== undefined && desc.enumerable) {\n to[nextKey] = nextSource[nextKey];\n }\n }\n }\n return to;\n }\n });\n}\n"
},
{
"answer_id": 34414372,
"author": "Raphaël",
"author_id": 2590861,
"author_profile": "https://Stackoverflow.com/users/2590861",
"pm_score": 3,
"selected": false,
"text": "_.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });\n// → { 'user': { 'name': 'barney', 'age': 36 } }\n"
},
{
"answer_id": 34533462,
"author": "Yaki Klein",
"author_id": 2859248,
"author_profile": "https://Stackoverflow.com/users/2859248",
"pm_score": 0,
"selected": false,
"text": "if (!Object.prototype.merge){\n Object.prototype.merge = function(obj){\n var self = this;\n Object.keys(obj).forEach(function(key){\n self[key] = obj[key]\n });\n }\n};\n merge function Objects obj1.merge(obj2); Error Object.keys"
},
{
"answer_id": 34717839,
"author": "Nishant Kumar",
"author_id": 430803,
"author_profile": "https://Stackoverflow.com/users/430803",
"pm_score": 0,
"selected": false,
"text": "function merge(to, from) {\n if (typeof to === 'object' && typeof from === 'object') {\n for (var pro in from) {\n if (from.hasOwnProperty(pro)) {\n to[pro] = from[pro];\n }\n }\n }\n else{\n throw \"Merge function can apply only on object\";\n }\n}\n"
},
{
"answer_id": 41407737,
"author": "trincot",
"author_id": 5459839,
"author_profile": "https://Stackoverflow.com/users/5459839",
"pm_score": -1,
"selected": false,
"text": "function deepMerge(a, b) {\n // If neither is an object, return one of them:\n if (Object(a) !== a && Object(b) !== b) return b || a;\n // Replace remaining primitive by empty object/array\n if (Object(a) !== a) a = Array.isArray(b) ? [] : {};\n if (Object(b) !== b) b = Array.isArray(a) ? [] : {};\n // Treat arrays differently:\n if (Array.isArray(a) && Array.isArray(b)) {\n // Merging arrays is interpreted as concatenation of their deep clones:\n return [...a.map(v => deepMerge(v)), ...b.map(v => deepMerge(v))];\n } else {\n // Get the keys that exist in either object\n var keys = new Set([...Object.keys(a),...Object.keys(b)]);\n // Recurse and assign to new object\n return Object.assign({}, ...Array.from(keys,\n key => ({ [key]: deepMerge(a[key], b[key]) }) ));\n }\n}\n\n// Sample data for demo:\nvar a = {\n groups: [{\n group: [{\n name: 'John',\n age: 12\n },{\n name: 'Mary',\n age: 20\n }],\n groupName: 'Pair'\n }],\n config: {\n color: 'blue',\n range: 'far'\n }\n};\n\n\nvar b = {\n groups: [{\n group: [{\n name: 'Bill',\n age: 15\n }],\n groupName: 'Loner'\n }],\n config: {\n range: 'close',\n strength: 'average'\n }\n};\n\nvar merged = deepMerge(a, b);\n\nconsole.log(merged); .as-console-wrapper { max-height: 100% !important; top: 0; }"
},
{
"answer_id": 41891156,
"author": "Jaime Asm",
"author_id": 5371458,
"author_profile": "https://Stackoverflow.com/users/5371458",
"pm_score": 6,
"selected": false,
"text": "const obj1 = { food: 'pizza', car: 'ford' };\nconst obj2 = { animal: 'dog' };\n\nconst obj3 = { ...obj1, ...obj2 };\nconsole.log(obj3);"
},
{
"answer_id": 42002014,
"author": "mitch3ls",
"author_id": 7497063,
"author_profile": "https://Stackoverflow.com/users/7497063",
"pm_score": -1,
"selected": false,
"text": "const objA = {\n attrA: 'hello',\n attrB: true\n}\n\nconst objB = {\n attrC: 2\n}\n\nconst mergedObj = {...objA, ...objB}\n"
},
{
"answer_id": 43526198,
"author": "Bekim Bacaj",
"author_id": 5896426,
"author_profile": "https://Stackoverflow.com/users/5896426",
"pm_score": 1,
"selected": false,
"text": "function Merge( ){\n var a = [].slice.call( arguments ), i = 0;\n while( a[i] )a[i] = JSON.stringify( a[i++] ).slice( 1,-1 );\n return JSON.parse( \"{\"+ a.join() +\"}\" );\n }\n var master = Merge( obj1, obj2, obj3, ...objn );\n Object.assign while ;\nvar obj1 = {a:1}, obj2 = {b:2}, obj3 = {c:3}\n;\nfunction Merge( ){\n var a = [].slice.call( arguments ), i = 0;\n while( a[i] )a[i] = JSON.stringify( a[i++] ).slice( 1,-1 );\n return JSON.parse( \"{\"+ a.join() +\"}\" );\n }\n;\nvar master = Merge( obj1, obj2, obj3 )\n;\nconsole.log( JSON.stringify( master ) )\n;"
},
{
"answer_id": 43595298,
"author": "toster-cx",
"author_id": 1895684,
"author_profile": "https://Stackoverflow.com/users/1895684",
"pm_score": 1,
"selected": false,
"text": "var merged = [obj1, obj2].reduce(function(a, o) { for(k in o) a[k] = o[k]; return a; }, {})\n"
},
{
"answer_id": 49394573,
"author": "Legends",
"author_id": 2581562,
"author_profile": "https://Stackoverflow.com/users/2581562",
"pm_score": 4,
"selected": false,
"text": "Object.assign ... var obj1 = { food: 'pizza', car: 'ford' }\nvar obj2 = { animal: 'dog', car: 'BMW' }\nvar obj3 = {a: \"A\"}\n\n\nvar mergedObj = Object.assign(obj1,obj2,obj3)\n // or using the Spread operator (...)\nvar mergedObj = {...obj1,...obj2,...obj3}\n\nconsole.log(mergedObj); obj2.car obj1.car"
},
{
"answer_id": 50122041,
"author": "Logan",
"author_id": 4612530,
"author_profile": "https://Stackoverflow.com/users/4612530",
"pm_score": 4,
"selected": false,
"text": "arguments function extend() {\n for (var o = {}, i = 0; i < arguments.length; i++) {\n // Uncomment to skip arguments that are not objects (to prevent errors)\n // if (arguments[i].constructor !== Object) continue;\n for (var k in arguments[i]) {\n if (arguments[i].hasOwnProperty(k)) {\n o[k] = arguments[i][k].constructor === Object\n ? extend(o[k] || {}, arguments[i][k])\n : arguments[i][k];\n }\n }\n }\n return o;\n}\n /**\n * Extend objects\n */\nfunction extend() {\n for (var o = {}, i = 0; i < arguments.length; i++) {\n for (var k in arguments[i]) {\n if (arguments[i].hasOwnProperty(k)) {\n o[k] = arguments[i][k].constructor === Object\n ? extend(o[k] || {}, arguments[i][k])\n : arguments[i][k];\n }\n }\n }\n return o;\n}\n\n/**\n * Example\n */\ndocument.write(JSON.stringify(extend({\n api: 1,\n params: {\n query: 'hello'\n }\n}, {\n params: {\n query: 'there'\n }\n})));\n// outputs {\"api\": 1, \"params\": {\"query\": \"there\"}}"
},
{
"answer_id": 50625180,
"author": "aircraft",
"author_id": 6523163,
"author_profile": "https://Stackoverflow.com/users/6523163",
"pm_score": 0,
"selected": false,
"text": "for-loop var obj1 = {\n id: '1',\n name: 'name'\n}\n\nvar obj2 = {\n c: 'c',\n d: 'd'\n}\n\nvar obj3 = {}\n\nfor (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }\nfor (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }\n\n\nconsole.log( obj1, obj2, obj3)"
},
{
"answer_id": 52377845,
"author": "Tính Ngô Quang",
"author_id": 2949104,
"author_profile": "https://Stackoverflow.com/users/2949104",
"pm_score": 3,
"selected": false,
"text": "var obj1 = { food: 'pizza', car: 'ford' }\nvar obj2 = { animal: 'dog' }\n\n// result\nresult: {food: \"pizza\", car: \"ford\", animal: \"dog\"}\n // Merge obj1 & obj2 to result\nvar result1 = $.extend( {}, obj1, obj2 );\n // Merge obj1 & obj2 to result\nvar result2 = _.merge( {}, obj1, obj2 );\n // Merge obj1 & obj2 to result\nvar result3 = _.extend( {}, obj1, obj2 );\n // Merge obj1 & obj2 to result\nvar result4 = Object.assign( {}, obj1, obj2 );\n obj1: { animal: 'dog' }\nobj2: { food: 'pizza', car: 'ford' }\nresult1: {food: \"pizza\", car: \"ford\", animal: \"dog\"}\nresult2: {food: \"pizza\", car: \"ford\", animal: \"dog\"}\nresult3: {food: \"pizza\", car: \"ford\", animal: \"dog\"}\nresult4: {food: \"pizza\", car: \"ford\", animal: \"dog\"}\n"
},
{
"answer_id": 53190239,
"author": "gildniy",
"author_id": 1992866,
"author_profile": "https://Stackoverflow.com/users/1992866",
"pm_score": 1,
"selected": false,
"text": "function extend(obj, src) {\n for (var key in src) {\n if (src.hasOwnProperty(key)) obj[key] = src[key];\n }\n return obj;\n}\n\n// example\nvar a = { foo: true }, b = { bar: false };\nvar c = extend(a, b);\n\nconsole.log(c);\n// { foo: true, bar: false }\n Object.keys function extend(obj, src) {\n Object.keys(src).forEach(function(key) { obj[key] = src[key]; });\n return obj;\n}\n"
},
{
"answer_id": 54234981,
"author": "Tejas Savaliya",
"author_id": 1794390,
"author_profile": "https://Stackoverflow.com/users/1794390",
"pm_score": 3,
"selected": false,
"text": "let obj1 = {a:1, b:2};\nlet obj2 = {c:3, d:4};\nlet merged = {...obj1, ...obj2};\nconsole.log(merged);"
},
{
"answer_id": 55156573,
"author": "Paweł Otto",
"author_id": 8553976,
"author_profile": "https://Stackoverflow.com/users/8553976",
"pm_score": 2,
"selected": false,
"text": ":object[] const merge = (...objects: object[]) => {\n return objects.reduce((prev, next) => {\n Object.keys(prev).forEach(key => {\n next[key] = { ...next[key], ...prev[key] }\n })\n return next\n })\n}\n"
},
{
"answer_id": 58370447,
"author": "akhtarvahid",
"author_id": 6544460,
"author_profile": "https://Stackoverflow.com/users/6544460",
"pm_score": 1,
"selected": false,
"text": "var o1 = { X: 10 };\nvar o2 = { Y: 20 };\nvar o3 = { Z: 30 };\nvar merge = Object.assign(o1, o2, o3);\nconsole.log(merge) // {X:10, Y:20, Z:30}\nconsole.log(o1) // {X:10, Y:20, Z:30}\n var o1 = { X: 10 };\nvar o2 = { Y: 20 };\nvar o3 = { Z: 30 };\n\nconsole.log('Does not modify original objects because target {}');\nvar merge = Object.assign({}, o1, o2, o3);\nconsole.log(merge); // { X: 10, Y: 20, Z: 30 }\nconsole.log(o1)\n\nconsole.log('Does not modify original objects')\nvar spreadMerge = {...o1, ...o2, ...o3};\nconsole.log(spreadMerge);\nconsole.log(o1);"
},
{
"answer_id": 58846559,
"author": "space97",
"author_id": 8474755,
"author_profile": "https://Stackoverflow.com/users/8474755",
"pm_score": 3,
"selected": false,
"text": "var obj1 = { food: 'pizza', car: 'ford' }\nvar obj2 = { animal: 'dog' }\n\nvar obj3 = { ...obj1, ...obj2 }\n {food: \"pizza\", car: \"ford\", animal: \"dog\"}\n var obj1 = { food: 'pizza', car: 'ford' }\nvar obj2 = { animal: 'dog' }\n\nvar obj3 = { ...obj1, ...obj2 }\n\nconsole.log(obj3);"
},
{
"answer_id": 59451912,
"author": "Deen John",
"author_id": 4227801,
"author_profile": "https://Stackoverflow.com/users/4227801",
"pm_score": 2,
"selected": false,
"text": "var obj = { name : \"Jacob\" , address : [\"America\"] }\nvar obj2 = { name : \"Shaun\" , address : [\"Honk Kong\"] }\n\nvar merged = Object.assign({} , obj,obj2 ); //shallow merge \nobj2.address[0] = \"new city\"\n var obj = { name : \"Jacob\" , address : [\"America\"] }\nvar obj2 = { name : \"Shaun\" , address : [\"Honk Kong\"] }\n\nvar result = Object.assign({} , JSON.parse(JSON.stringify(obj)),JSON.parse(JSON.stringify(obj2)) )\n\nobj2.address[0] = \"new city\"\n"
},
{
"answer_id": 59484681,
"author": "A.K.",
"author_id": 8471010,
"author_profile": "https://Stackoverflow.com/users/8471010",
"pm_score": 2,
"selected": false,
"text": "Object.assign var result = Object.assign(obj1, obj2);\n"
},
{
"answer_id": 59694616,
"author": "Soura Ghosh",
"author_id": 9229338,
"author_profile": "https://Stackoverflow.com/users/9229338",
"pm_score": 2,
"selected": false,
"text": "var obj1 = { food: 'pizza', car: 'ford' }\nvar obj2 = { animal: 'dog' }\nlet result = {...obj1,...obj2};\nconsole.log(result)\n\noutput { food: 'pizza', car: 'ford', animal: 'dog' }\n"
},
{
"answer_id": 64223261,
"author": "Piyush Rana",
"author_id": 12704323,
"author_profile": "https://Stackoverflow.com/users/12704323",
"pm_score": 1,
"selected": false,
"text": "Object.assign(targetObj, sourceObj);\n\ntargetObj = {...targetObj, ...sourceObj};\n"
},
{
"answer_id": 64438852,
"author": "kokhta shukvani",
"author_id": 14472371,
"author_profile": "https://Stackoverflow.com/users/14472371",
"pm_score": 2,
"selected": false,
"text": "Object.assign(TargetObject, Obj1, Obj2, ...);\n"
},
{
"answer_id": 66153732,
"author": "Mehadi Hassan",
"author_id": 9569557,
"author_profile": "https://Stackoverflow.com/users/9569557",
"pm_score": 0,
"selected": false,
"text": "// using spread ...\n let obj1 = {\n ...obj2\n };\n // using Object.assign() method\nlet obj1 = Object.assign({}, obj2);\n // using JSON\nlet obj1 = JSON.parse(JSON.stringify(obj2));\n"
},
{
"answer_id": 67690102,
"author": "Force Bolt",
"author_id": 15478252,
"author_profile": "https://Stackoverflow.com/users/15478252",
"pm_score": -1,
"selected": false,
"text": "let obj1 = { food: 'pizza', car: 'ford' }\nlet obj2 = { animal: 'dog' }\n\nconsole.log(jQuery.extend(obj1, obj2))\n"
},
{
"answer_id": 71985620,
"author": "dazzafact",
"author_id": 1163485,
"author_profile": "https://Stackoverflow.com/users/1163485",
"pm_score": 1,
"selected": false,
"text": "var t=merge({test:123},{mysecondTest:{blub:{test2:'string'},args:{'test':2}}})\nconsole.log(t);\n\nfunction merge(...args) {\n return Object.assign({}, ...args);\n}"
},
{
"answer_id": 72836059,
"author": "dunubh",
"author_id": 13182161,
"author_profile": "https://Stackoverflow.com/users/13182161",
"pm_score": 3,
"selected": false,
"text": "var firstObject = {\n key1 : 'value1',\n key2 : 'value2'\n};\n\nvar secondObject={\n ...firstObject,\n key3 : 'value3',\n key4 : 'value4',\n key5 : 'value5'\n}\nconsole.log(firstObject);\nconsole.log(secondObject);\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4541/"
] |
171,267
|
<p>Has anyone ever heard of a UNIX shell written in a reasonable language, like Python?</p>
|
[
{
"answer_id": 171294,
"author": "skymt",
"author_id": 18370,
"author_profile": "https://Stackoverflow.com/users/18370",
"pm_score": 6,
"selected": true,
"text": "(run/strings (find \".\" -name *.c -print))"
},
{
"answer_id": 171304,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "#! os shutil"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14739/"
] |
171,279
|
<p>How to I get the Fixnum returned by the following:</p>
<pre><code>"abc"[2]
</code></pre>
<p>Back into a character?</p>
|
[
{
"answer_id": 171282,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 5,
"selected": true,
"text": "n.chr\n"
},
{
"answer_id": 171410,
"author": "Grant Hutchins",
"author_id": 6304,
"author_profile": "https://Stackoverflow.com/users/6304",
"pm_score": 2,
"selected": false,
"text": "\"abc\"[2] chr \"abc\"[2,1]\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/117/"
] |
171,285
|
<p>Is there a way for me to add logging so that entering and exiting methods gets logged along with parameters automatically somehow for tracing purposes? How would I do so?</p>
<p>I am using Log4Net.</p>
|
[
{
"answer_id": 171339,
"author": "Jared",
"author_id": 7388,
"author_profile": "https://Stackoverflow.com/users/7388",
"pm_score": 3,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nusing System.Diagnostics;\n\nnamespace TracingSample\n{\n class Program\n {\n static void Main(string[] args)\n {\n DoSomething();\n }\n\n static void DoSomething()\n {\n LogEnter();\n\n Console.WriteLine(\"Executing DoSomething\");\n\n LogExit();\n }\n\n static void LogEnter()\n {\n StackTrace trace = new StackTrace();\n if (trace.FrameCount > 1)\n {\n string ns = trace.GetFrame(1).GetMethod().DeclaringType.Namespace;\n string typeName = trace.GetFrame(1).GetMethod().DeclaringType.Name;\n Console.WriteLine(\"Entering {0}.{1}.{2}\", ns, typeName, trace.GetFrame(1).GetMethod().Name);\n }\n }\n\n static void LogExit()\n {\n StackTrace trace = new StackTrace();\n if (trace.FrameCount > 1)\n {\n string ns = trace.GetFrame(1).GetMethod().DeclaringType.Namespace;\n string typeName = trace.GetFrame(1).GetMethod().DeclaringType.Name;\n Console.WriteLine(\"Exiting {0}.{1}.{2}\", ns, typeName, trace.GetFrame(1).GetMethod().Name);\n }\n }\n }\n}\n public abstract class BaseType\n{\n public void SomeFunction()\n {\n\n LogEnter();\n DoSomeFunction();\n LogExit();\n }\n\n public abstract void DoSomeFunction();\n}\n\npublic class SubType : BaseType\n{\n public override void DoSomeFunction()\n {\n // Implementation of SomeFunction logic here...\n }\n}\n"
},
{
"answer_id": 34779005,
"author": "Kyle Falconer",
"author_id": 940217,
"author_profile": "https://Stackoverflow.com/users/940217",
"pm_score": 0,
"selected": false,
"text": "private static void LogEnterExit(bool isEnter = true, params object[] args)\n{\n StackTrace trace = new StackTrace(true); // need `true` for getting file and line info\n if (trace.FrameCount > 2)\n {\n string ns = trace.GetFrame(2).GetMethod().DeclaringType.Namespace;\n string typeName = trace.GetFrame(2).GetMethod().DeclaringType.Name;\n string args_string = args.Length == 0 ? \"\" : \"\\narguments: [\" + args.Aggregate((current, next) => string.Format(\"{0},{1};\", current, next))+\"]\";\n Console.WriteLine(\"{0} {1}.{2}.{3}{4}\", isEnter ? \"Entering\" : \"Exiting\", ns, typeName, trace.GetFrame(2).GetMethod().Name, args_string );\n }\n}\n\nstatic void LogEnter(params object[] args)\n{\n LogEnterExit(true, args);\n}\n\nstatic void LogExit(params object[] args)\n{\n LogEnterExit(false, args);\n}\n static void DoSomething(string arg1)\n{\n LogEnter(arg1);\n Console.WriteLine(\"Executing DoSomething\");\n LogExit();\n}\n DoSomething arg1 Entering Program.DoSomething\narguments: [blah]\nExecuting DoSomething\nExiting Program.DoSomething\n"
},
{
"answer_id": 59547586,
"author": "Zamboni",
"author_id": 174682,
"author_profile": "https://Stackoverflow.com/users/174682",
"pm_score": 0,
"selected": false,
"text": "public void OnActionExecuting(ActionExecutingContext context) \n\npublic void OnActionExecuted(ActionExecutedContext context) \n\npublic async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) \n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15771/"
] |
171,289
|
<p>I'm writing a php script where I call </p>
<pre><code>$lines = file('base_list.txt');
</code></pre>
<p>to break a file up into an array. The file has over 100,000 lines in it, which should be 100,000 elements in the array, but when I run </p>
<pre><code>print_r($lines);
exit;
</code></pre>
<p>the array only contains 7280 elements. </p>
<p>So I'm curious, WTF? Is there a limit on the amount of keys an array can have? I'm running this locally on a dual-core 2.0Ghz with 2GB of RAM (Vista & IIS though); so I'm a little confused how a 4MB file could throw results like this. </p>
<p>Edit:
I have probably should have mentioned that I had previously set memory_limit to 512MB in php.ini as well. </p>
|
[
{
"answer_id": 171310,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 2,
"selected": false,
"text": "print_r memory_limit = 8M\n .htaccess php_value memory_limit 16M\n"
},
{
"answer_id": 171422,
"author": "Jay",
"author_id": 20840,
"author_profile": "https://Stackoverflow.com/users/20840",
"pm_score": 2,
"selected": false,
"text": "print_r() file() auto_detect_line_endings"
},
{
"answer_id": 171634,
"author": "phatduckk",
"author_id": 3896,
"author_profile": "https://Stackoverflow.com/users/3896",
"pm_score": 1,
"selected": false,
"text": "print_r() auto_detect_line_endings ini_set('auto_detect_line_endings', 1)"
},
{
"answer_id": 171648,
"author": "Christian Davén",
"author_id": 12534,
"author_profile": "https://Stackoverflow.com/users/12534",
"pm_score": 1,
"selected": false,
"text": "count print_r print_r"
},
{
"answer_id": 172615,
"author": "Eric Lamb",
"author_id": 538,
"author_profile": "https://Stackoverflow.com/users/538",
"pm_score": 3,
"selected": false,
"text": "echo count($lines);\n"
},
{
"answer_id": 408050,
"author": "matpie",
"author_id": 51021,
"author_profile": "https://Stackoverflow.com/users/51021",
"pm_score": 1,
"selected": false,
"text": "print_r foreach ($FileLines as $Line) echo $Line;\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171289",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/538/"
] |
171,292
|
<p>I just fell in love with NHibernate and the fluent interface. The latter enables very nice mappings with refactoring support (no more need for xml files).</p>
<p>But nobody is perfect, so I am missing the many-to-any mapping in fluent. Does anybody know if it is already there? If so, a simple line of code would be nice.</p>
<p>But to stick to the header of the question, is there any way to combine fluent and normal NHibernate mapping. </p>
<p>Currently I use the following lines for my test setup WITH fluent, and the second code block for my test WITHOUT fluent (with XML mappings). How can I tell fluent to use fluent IF AVAILABLE and XML otherwise...</p>
<pre><code> var cfg = new Configuration();
cfg.AddProperties(MsSqlConfiguration.MsSql2005.ConnectionString.Is(_testConnectionstring).ToProperties());
cfg.AddMappingsFromAssembly(typeof(CatMap).Assembly);
new SchemaExport(cfg).Create(true, true);
var persistenceModel = new PersistenceModel();
persistenceModel.addMappingsFromAssembly(typeof(CatMap).Assembly);
IDictionary<string, string> properties = MsSqlConfiguration.MsSql2005.UseOuterJoin().ShowSql().ConnectionString.Is(_testConnectionstring).ToProperties();
properties.Add("command_timeout", "340");
session = new SessionSource(properties, persistenceModel).CreateSession();
</code></pre>
<p>Without Fluent...</p>
<pre><code> config = new Configuration();
IDictionary props = new Hashtable();
props["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
props["dialect"] = "NHibernate.Dialect.MsSql2005Dialect";
props["connection.driver_class"] = "NHibernate.Driver.SqlClientDriver";
props["connection.connection_string"] = "Server=localhost;initial catalog=Debug;Integrated Security=SSPI";
props["show_sql"] = "true";
foreach (DictionaryEntry de in props)
{
config.SetProperty(de.Key.ToString(), de.Value.ToString());
}
config.AddAssembly(typeof(CatMap).Assembly);
SchemaExport se = new SchemaExport(config);
se.Create(true, true);
factory = config.BuildSessionFactory();
session = factory.OpenSession();
</code></pre>
<p>That's it...
Chris</p>
<p>PS: I really like this site, the GUI is perfect, and the quality of all articles is incredible. I think it will be huge :-) Have to register...</p>
|
[
{
"answer_id": 171310,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 2,
"selected": false,
"text": "print_r memory_limit = 8M\n .htaccess php_value memory_limit 16M\n"
},
{
"answer_id": 171422,
"author": "Jay",
"author_id": 20840,
"author_profile": "https://Stackoverflow.com/users/20840",
"pm_score": 2,
"selected": false,
"text": "print_r() file() auto_detect_line_endings"
},
{
"answer_id": 171634,
"author": "phatduckk",
"author_id": 3896,
"author_profile": "https://Stackoverflow.com/users/3896",
"pm_score": 1,
"selected": false,
"text": "print_r() auto_detect_line_endings ini_set('auto_detect_line_endings', 1)"
},
{
"answer_id": 171648,
"author": "Christian Davén",
"author_id": 12534,
"author_profile": "https://Stackoverflow.com/users/12534",
"pm_score": 1,
"selected": false,
"text": "count print_r print_r"
},
{
"answer_id": 172615,
"author": "Eric Lamb",
"author_id": 538,
"author_profile": "https://Stackoverflow.com/users/538",
"pm_score": 3,
"selected": false,
"text": "echo count($lines);\n"
},
{
"answer_id": 408050,
"author": "matpie",
"author_id": 51021,
"author_profile": "https://Stackoverflow.com/users/51021",
"pm_score": 1,
"selected": false,
"text": "print_r foreach ($FileLines as $Line) echo $Line;\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25206/"
] |
171,301
|
<pre><code>int x = n / 3; // <-- make this faster
// for instance
int a = n * 3; // <-- normal integer multiplication
int b = (n << 1) + n; // <-- potentially faster multiplication
</code></pre>
|
[
{
"answer_id": 171320,
"author": "KPexEA",
"author_id": 13676,
"author_profile": "https://Stackoverflow.com/users/13676",
"pm_score": 7,
"selected": true,
"text": "int a;\nint b;\n\na = some value;\nb = a / 3;\n"
},
{
"answer_id": 436535,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 3,
"selected": false,
"text": "y = x / 3\n static inline uint32_t divby3 (\n uint32_t divideMe\n) {\n return (uint32_t)(((uint64_t)0xAAAAAAABULL * divideMe) >> 33);\n}\n"
},
{
"answer_id": 859429,
"author": "Steve Hanov",
"author_id": 15947,
"author_profile": "https://Stackoverflow.com/users/15947",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n\nvoid main()\n{\n int n = 1000;\n int a,b;\n a = n >> 2;\n b = (a >> 2);\n a += b;\n b = (b >> 2);\n a += b;\n b = (b >> 2);\n a += b;\n b = (b >> 2);\n a += b;\n printf(\"a=%d\\n\", a);\n}\n"
},
{
"answer_id": 10673837,
"author": "Carlo V. Dango",
"author_id": 454017,
"author_profile": "https://Stackoverflow.com/users/454017",
"pm_score": 1,
"selected": false,
"text": "internal static List<int> Div3(int[] a)\n{\n int remainder = 0;\n var res = new List<int>();\n for (int i = 0; i < a.Length; i++)\n {\n var val = remainder + a[i];\n var div = val/3;\n\n remainder = 10*(val%3);\n if (div > 9)\n {\n res.Add(div/10);\n res.Add(div%10);\n }\n else\n res.Add(div);\n }\n if (res[0] == 0) res.RemoveAt(0);\n return res;\n}\n"
},
{
"answer_id": 16465488,
"author": "Albert Gonzalez",
"author_id": 2366902,
"author_profile": "https://Stackoverflow.com/users/2366902",
"pm_score": 0,
"selected": false,
"text": "uint8_t divideby3(uint8_t x)\n{\n uint8_t answer =0;\n do\n {\n x>>=1;\n answer+=x;\n x=-x;\n }while(x);\n return answer;\n}\n"
},
{
"answer_id": 17693129,
"author": "Luke",
"author_id": 2590208,
"author_profile": "https://Stackoverflow.com/users/2590208",
"pm_score": 0,
"selected": false,
"text": "uint8_t DivBy3LU(uint8_t u8Operand)\n{\n uint8_t ai8Div3 = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, ....];\n\n return ai8Div3[u8Operand];\n}\n"
},
{
"answer_id": 48482313,
"author": "Calmarius",
"author_id": 58805,
"author_profile": "https://Stackoverflow.com/users/58805",
"pm_score": 3,
"selected": false,
"text": "uint64_t divBy3(uint64_t x)\n{\n return x*12297829382473034411ULL;\n}\n 3*x + 2^64*y = 1"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1200558/"
] |
171,318
|
<p>I'm generating a ton of XML that is to be passed to an API as a post variable when a user click on a form button. I also want to be able to show the user the XML before hand.</p>
<p>The code is sorta like the following in structure:</p>
<pre><code><?php
$lots of = "php";
?>
<xml>
<morexml>
<?php
while(){
?>
<somegeneratedxml>
<?php } ?>
<lastofthexml>
<?php ?>
<html>
<pre>
The XML for the user to preview
</pre>
<form>
<input id="xml" value="theXMLagain" />
</form>
</html>
</code></pre>
<p>My XML is being generated with a few while loops and stuff. It then needs to be shown in the two places (the preview and the form value). </p>
<p>My question is. How do I capture the generated XML in a variable or whatever so I only have to generate it once and then just print it out as apposed to generating it inside the preview and then again inside the form value?</p>
|
[
{
"answer_id": 171325,
"author": "maxsilver",
"author_id": 1477,
"author_profile": "https://Stackoverflow.com/users/1477",
"pm_score": 4,
"selected": false,
"text": "ob_start(); \n// make your XML file\n\n$out1 = ob_get_contents();\n//$out1 now contains your XML\n"
},
{
"answer_id": 171327,
"author": "moo",
"author_id": 23107,
"author_profile": "https://Stackoverflow.com/users/23107",
"pm_score": 8,
"selected": true,
"text": "<?php ob_start(); ?>\n<xml/>\n<?php $xml = ob_get_clean(); ?>\n<input value=\"<?php echo $xml ?>\" />͏͏͏͏͏͏\n"
},
{
"answer_id": 172969,
"author": "mattoc",
"author_id": 10901,
"author_profile": "https://Stackoverflow.com/users/10901",
"pm_score": 2,
"selected": false,
"text": "<?php\n$string = <<<XMLDoc\n<?xml version='1.0'?>\n<doc>\n <title>XML Document</title>\n <lotsofxml/>\n <fruits>\nXMLDoc;\n\n$fruits = array('apple', 'banana', 'orange');\n\nforeach($fruits as $fruit) {\n $string .= \"\\n <fruit>\".$fruit.\"</fruit>\";\n}\n\n$string .= \"\\n </fruits>\n</doc>\";\n?>\n<html>\n<!-- Show XML as HTML with entities; saves having to view source -->\n<pre><?=str_replace(\"<\", \"<\", str_replace(\">\", \">\", $string))?></pre>\n<textarea rows=\"8\" cols=\"50\"><?=$string?></textarea>\n</html>\n"
},
{
"answer_id": 71257928,
"author": "David Wolf",
"author_id": 13765033,
"author_profile": "https://Stackoverflow.com/users/13765033",
"pm_score": 2,
"selected": false,
"text": "class Helper\n{\n /**\n * Capture output of a function with arguments and return it as a string.\n */\n public static function captureOutput(callable $callback, ...$args): string\n {\n ob_start();\n $callback(...$args);\n $output = ob_get_contents();\n ob_end_clean();\n return $output;\n }\n}\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171318",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/319/"
] |
171,326
|
<p>I have a bad habit of using the cursor keys of my keyboard to navigate source code. It's something I've done for 15 years and this of course means that my navigating speed is limited by the speed of the keyboard. On both Vista and OS X (I dual boot a MacBook), I have my key repeat rate turned all the way up. But in Visual Studio, and other apps, the rate is still much slower than I would prefer.</p>
<p>How can I make the key repeat rate faster in Visual Studio and other text editors?</p>
|
[
{
"answer_id": 171389,
"author": "Georgi",
"author_id": 13209,
"author_profile": "https://Stackoverflow.com/users/13209",
"pm_score": 2,
"selected": false,
"text": "ctrl-right: Go to the end of the previous/the next word (stated before)\nctrl-left: Go to the beginning of the previous/the word before (stated before)\nctrl-up: Go to the beginning of this paragraph\n (or to the next paragraph over this)\nctrl-down: Go to the end of this paragraph\n (or to the next paragraph after this)\nctrl-pos1: Go to the beginning of the file\nctrl-end: Go to the end of the file\n alt-esc: Get the actual application into the background\nctrl-esc: This is like pressing the \"start-button\" in Windows: You can\n navigate with arrow keys or shortcuts to start programs from here\nctrl-l: While using Firefox this accesses the URL-entry-field to simply\n type URLs (does not work on Stack Overflow :)\nctrl-tab,\nctrl-pageup\nctrl-pagedwn Navigate through tabs (even in your development environment)\n"
},
{
"answer_id": 171493,
"author": "Mikael Jansson",
"author_id": 18753,
"author_profile": "https://Stackoverflow.com/users/18753",
"pm_score": -1,
"selected": false,
"text": "bw () {} /? set incsearch 20j 3} 4w 40G"
},
{
"answer_id": 171520,
"author": "Jake",
"author_id": 24638,
"author_profile": "https://Stackoverflow.com/users/24638",
"pm_score": 3,
"selected": false,
"text": "HKEY_CURRENT_USER\\Control Panel\\Keyboard"
},
{
"answer_id": 429465,
"author": "hyperlogic",
"author_id": 1841,
"author_profile": "https://Stackoverflow.com/users/1841",
"pm_score": 6,
"selected": true,
"text": "open ~/Library/Preferences/.GlobalPreferences.plist\n"
},
{
"answer_id": 1052296,
"author": "exinocactus",
"author_id": 570056,
"author_profile": "https://Stackoverflow.com/users/570056",
"pm_score": 3,
"selected": false,
"text": "KeyRepeat InitialKeyRepeat Key Repeat Rate Delay Until Repeat Key Repeat Rate (KeyRepeat) Delay Until Repeat (InitialKeyRepeat)\n|--------------------------------| |----------------------|-----------------|\nslow (120) fast (2) off (30000) long (120) short (25)\n0.5 char/s 33 char/s \n ~/Library/Preferences/.GlobalPreferences.plist KeyRepeat = 1 --> 1/(1*15 ms) = 66.7 char/s\nInitialKeyRepeat = 15 --> 15*15 ms = 225 ms\n"
},
{
"answer_id": 3620627,
"author": "chuckf",
"author_id": 437196,
"author_profile": "https://Stackoverflow.com/users/437196",
"pm_score": 5,
"selected": false,
"text": "[HKEY_CURRENT_USER\\Control Panel\\Accessibility\\Keyboard Response]\n\"AutoRepeatDelay\"=\"250\"\n\"AutoRepeatRate\"=\"13\"\n\"BounceTime\"=\"0\"\n\"DelayBeforeAcceptance\"=\"0\"\n\"Flags\"=\"59\"\n"
},
{
"answer_id": 11056655,
"author": "Mud",
"author_id": 501459,
"author_profile": "https://Stackoverflow.com/users/501459",
"pm_score": 6,
"selected": false,
"text": "SystemParametersInfo(SPI_SETFILTERKEYS,...) keyrate <delay> <repeat> #include <windows.h>\n#include <stdlib.h>\n#include <stdio.h>\n\nBOOL parseDword(const char* in, DWORD* out)\n{\n char* end;\n long result = strtol(in, &end, 10);\n BOOL success = (errno == 0 && end != in);\n if (success)\n {\n *out = result;\n }\n return success;\n}\n\n\nint main(int argc, char* argv[])\n{\n FILTERKEYS keys = { sizeof(FILTERKEYS) };\n\n if (argc == 1)\n {\n puts (\"No parameters given: disabling.\");\n }\n else if (argc != 3)\n {\n puts (\"Usage: keyrate <delay ms> <repeat ms>\\nCall with no parameters to disable.\");\n return 0;\n }\n else if (parseDword(argv[1], &keys.iDelayMSec) \n && parseDword(argv[2], &keys.iRepeatMSec))\n {\n printf(\"Setting keyrate: delay: %d, rate: %d\\n\", (int) keys.iDelayMSec, (int) keys.iRepeatMSec);\n keys.dwFlags = FKF_FILTERKEYSON|FKF_AVAILABLE;\n }\n\n if (!SystemParametersInfo (SPI_SETFILTERKEYS, 0, (LPVOID) &keys, 0))\n {\n fprintf (stderr, \"System call failed.\\nUnable to set keyrate.\");\n }\n\n return 0;\n}\n"
},
{
"answer_id": 20934986,
"author": "It's Leto",
"author_id": 849644,
"author_profile": "https://Stackoverflow.com/users/849644",
"pm_score": 1,
"selected": false,
"text": "; ====================================================================\n; DeveloperTools - Autorepeat Key Script\n;\n; This script provides a mechanism to do key-autorepeat way faster\n; than the Windows OS would allow. There are some registry settings\n; in Windows to tweak the key-repeat-rate, but according to widely \n; spread user feedback, the registry-solution does not work on all \n; systems.\n;\n; See the \"Hotkeys\" section below. Currently (Version 1.0), there\n; are only the arrow keys mapped for faster autorepeat (including \n; the control and shift modifiers). Feel free to add your own \n; hotkeys.\n;\n; You need AutoHotkey (http://www.autohotkey.com) to run this script.\n; Tested compatibility: AutoHotkey_L, Version v1.1.08.01\n; \n; (AutoHotkey Copyright © 2004 - 2013 Chris Mallet and \n; others - not me!)\n;\n; @author Timo Rumland <timo.rumland ${at} gmail.com>, 2014-01-05\n; @version 1.0\n; @updated 2014-01-05\n; @license The MIT License (MIT)\n; (http://opensource.org/licenses/mit-license.php)\n; ====================================================================\n\n; ================\n; Script Settings\n; ================\n\n#NoEnv\n#SingleInstance force\nSendMode Input \nSetWorkingDir %A_ScriptDir%\n\n\n; Instantiate the DeveloperTools defined below the hotkey definitions\ndeveloperTools := new DeveloperTools()\n\n\n; ========\n; Hotkeys\n; ========\n\n ; -------------------\n ; AutoRepeat Hotkeys\n ; -------------------\n\n ~$UP::\n ~$DOWN::\n ~$LEFT::\n ~$RIGHT::\n DeveloperTools.startAutorepeatKeyTimer( \"\" )\n return\n\n ~$+UP::\n ~$+DOWN::\n ~$+LEFT::\n ~$+RIGHT::\n DeveloperTools.startAutorepeatKeyTimer( \"+\" )\n return\n\n ~$^UP::\n ~$^DOWN::\n ~$^LEFT::\n ~$^RIGHT::\n DeveloperTools.startAutorepeatKeyTimer( \"^\" )\n return\n\n ; -------------------------------------------------------\n ; Jump label used by the hotkeys above. This is how \n ; AutoHotkey provides \"threads\" or thread-like behavior.\n ; -------------------------------------------------------\n DeveloperTools_AutoRepeatKey:\n SetTimer , , Off\n DeveloperTools.startAutorepeatKey()\n return\n\n\n; ========\n; Classes\n; ========\n\n class DeveloperTools\n {\n ; Configurable by user\n autoRepeatDelayMs := 180\n autoRepeatRateMs := 40\n\n ; Used internally by the script\n repeatKey := \"\"\n repeatSendString := \"\"\n keyModifierBaseLength := 2\n\n ; -------------------------------------------------------------------------------\n ; Starts the autorepeat of the current captured hotkey (A_ThisHotKey). The given\n ; 'keyModifierString' is used for parsing the real key (without hotkey modifiers\n ; like \"~\" or \"$\").\n ; -------------------------------------------------------------------------------\n startAutorepeatKeyTimer( keyModifierString )\n {\n keyModifierLength := this.keyModifierBaseLength + StrLen( keyModifierString )\n\n this.repeatKey := SubStr( A_ThisHotkey, keyModifierLength + 1 )\n this.repeatSendString := keyModifierString . \"{\" . this.repeatKey . \"}\"\n\n SetTimer DeveloperTools_AutoRepeatKey, % this.autoRepeatDelayMs\n }\n\n ; ---------------------------------------------------------------------\n ; Starts the loop which repeats the key, resulting in a much faster \n ; autorepeat rate than Windows provides. Internally used by the script\n ; ---------------------------------------------------------------------\n startAutorepeatKey()\n {\n while ( GetKeyState( this.repeatKey, \"P\" ) )\n {\n Send % this.repeatSendString\n Sleep this.autoRepeatRateMs\n }\n }\n }\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/338/"
] |
171,332
|
<p>I'm trying to Unit Test a class that has many internal functions. These obviously need testing too, but my Tests project is seperate, mainly because it covers many small, related projects. What I have so far is:</p>
<pre><code>FieldInfo[] _fields =
typeof(ButtonedForm.TitleButton).GetFields(
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.DeclaredOnly);
Console.WriteLine("{0} fields:", _fields.Length);
foreach (FieldInfo fi in _fields)
{
Console.WriteLine(fi.Name);
}
</code></pre>
<p>This spits out all the private members nicely, but still doesn't display internals. I know this is possible, because when I was messing around with the autogenerated tests that Visual Studio can produce, it asked about something to do with displaying internals to the Test project. Well, now I'm using NUnit and really liking it, but how can I achieve the same thing with it?</p>
|
[
{
"answer_id": 171337,
"author": "Eric Schoonover",
"author_id": 3957,
"author_profile": "https://Stackoverflow.com/users/3957",
"pm_score": 6,
"selected": true,
"text": "InternalsVisibleTo"
},
{
"answer_id": 171338,
"author": "Ash",
"author_id": 5023,
"author_profile": "https://Stackoverflow.com/users/5023",
"pm_score": 3,
"selected": false,
"text": "[assembly: InternalsVisibleTo(\"AssemblyB\")]\n [assembly:InternalsVisibleTo(\"AssemblyB, PublicKey=32ab4ba45e0a69a1\")]\n"
},
{
"answer_id": 171585,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "GetMethods GetMembers InternalsVisibleTo"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
171,343
|
<p>I'm writing a quick Rails app and was wondering how I can validate the success an exec'd command. The two commands I'm running are and SVN update, and a cp from one directory to another.</p>
|
[
{
"answer_id": 171359,
"author": "Unixmonkey",
"author_id": 23915,
"author_profile": "https://Stackoverflow.com/users/23915",
"pm_score": -1,
"selected": false,
"text": "svn_start_version = IO.popen(\"svn info\").readlines[4]\n`svn update`\nsvn_end_version = IO.popen(\"svn info\").readlines[4]\nif svn_end_version > svn_start_version\n \"success\"\nend\n source_file_size = IO.popen(\"du file1\").readlines\n`cp file1 file2`\ndest_file_size = IO.popen(\"du file2\").readlines\nif dest_file_size == source_file_size\n \"success\"\nend\n"
},
{
"answer_id": 171374,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 2,
"selected": false,
"text": "system() true false $?"
},
{
"answer_id": 171377,
"author": "Gordon Wilson",
"author_id": 23071,
"author_profile": "https://Stackoverflow.com/users/23071",
"pm_score": 4,
"selected": true,
"text": "result = system(\"cp -r dir1 dir2\")\nif(result)\n#do the next thing\nelse\n# handle the error\n"
},
{
"answer_id": 171462,
"author": "Avdi",
"author_id": 20487,
"author_profile": "https://Stackoverflow.com/users/20487",
"pm_score": 1,
"selected": false,
"text": "exec exec exec $? system()"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171343",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15846/"
] |
171,345
|
<p>We're trying to analyse flow around circular cylinder and we have a set of Cp values that we got from wind tunnel experiment. Initially, we started off with a sample frequency of 20 Hz and tried to find the frequency of vortex shedding using FFT in matlab. We got a frequency of around 7 Hz. Next, we did the same experiment, but the only thing we changed was the sampling frequency- from 20 Hz to 200 Hz. We got the frequency of the vortex shedding to be around 70 Hz (this is where the peak is located in the graph). The graph doesn't change regardless of the Cp data that we enter. The only time the peak differs is when we change the sample frequency. It seems like the increase in the frequency of vortex shedding is proportional to the sample frequency and this doesn't seem to make sense at all. Any help regarding establishing a relation between sample frequency and vortex shedding frequency would be greatly appreaciated. </p>
|
[
{
"answer_id": 171758,
"author": "Will Robertson",
"author_id": 4161,
"author_profile": "https://Stackoverflow.com/users/4161",
"pm_score": 2,
"selected": false,
"text": "Fs = 100;\nTmax = 10;\ntime = 0:1/Fs:Tmax; \nomega = 2*pi*10; % 10 Hz\nsignal = 10*sin(omega*time) + rand(1,Tmax*Fs+1);\n\nNfft = 2^8;\n[Pxx,freq] = pwelch(signal,Nfft,[],[],Fs)\nplot(freq,Pxx)\n pwelch"
},
{
"answer_id": 176757,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": " % FFT Algorithm\n\nFs = 200; % Sampling frequency\nT = 1/Fs; % Sample time\nL = 65536; % Length of signal\nt = (0:L-1)*T; % Time vector\ny = data1; % Your CP values go in this vector\n\nNFFT = 2^nextpow2(L); % Next power of 2 from length of y\nY = fft(y,NFFT)/L;\nf = Fs/2*linspace(0,1,NFFT/2);\n\n% Plot single-sided amplitude spectrum.\nloglog(f,2*abs(Y(1:NFFT/2))) \ntitle(' y(t)')\nxlabel('Frequency (Hz)')\nylabel('|Y(f)|')\n"
},
{
"answer_id": 177448,
"author": "Will Robertson",
"author_id": 4161,
"author_profile": "https://Stackoverflow.com/users/4161",
"pm_score": 0,
"selected": false,
"text": "fft"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
171,352
|
<p>Is there an easy method to store a person's user settings in a sql 2000 database. Ideally all settings in one field so I don't keep having to edit the table every time I add a setting. I am thinking along the lines of serialize a settings class if anyone has an example.</p>
<p>The reason I don't want to use the built in .NET user settings stored in persistent storage is work uses super mandatory profiles so upon a users log off the settings are cleared which is a pain. I posted asking for any solutions to this previously but didn't get much of a response.</p>
|
[
{
"answer_id": 171467,
"author": "Jeffrey L Whitledge",
"author_id": 10174,
"author_profile": "https://Stackoverflow.com/users/10174",
"pm_score": 0,
"selected": false,
"text": "create table user_settings\n(\n user_id nvarchar(256) not null,\n keyword nvarchar(64) not null,\n constraint PK_user_settings primary key (user_id, keyword),\n value nvarchar(max) not null\n)\n public string GetUserSetting(string keyword, string defaultValue);\npublic void SetUserSetting(string keyword, string value);\n"
},
{
"answer_id": 171488,
"author": "Bob Nadler",
"author_id": 2514,
"author_profile": "https://Stackoverflow.com/users/2514",
"pm_score": 3,
"selected": true,
"text": "SettingsProvider Settings [SettingsProvider(typeof(CustomSettingsProvider))]\ninternal sealed partial class Settings { \n ...\n}\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16989/"
] |
171,366
|
<p>I am VERY new to ASP.NET. I come from a VB6 / ASP (classic) / SQL Server 2000 background. I am reading a lot about Visual Studio 2008 (have installed it and am poking around). I have read about "reflection" and would like someone to explain, as best as you can to an older developer of the technologies I've written above, what exactly Reflection is and why I would use it... I am having trouble getting my head around that. Thanks!</p>
|
[
{
"answer_id": 171385,
"author": "yfeldblum",
"author_id": 12349,
"author_profile": "https://Stackoverflow.com/users/12349",
"pm_score": 3,
"selected": true,
"text": "myobject.GetType().GetProperty(\"MyProperty\").SetValue(myobject, \"wicked!\", null)\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
171,399
|
<p>For intense number-crunching i'm considering using fixed point instead of floating point. Of course it'll matter how many bytes the fixed point type is in size, on what CPU it'll be running on, if i can use (for Intel) the MMX or SSE or whatever new things come up...</p>
<p>I'm wondering if these days when floating point runs faster than ever, is it ever worth considering fixed point? Are there general rules of thumb where we can say it'll matter by more than a few percent? What is the overview from 35,000 feet of numerical performance? (BTW, i'm assuming a general CPU as found in most computers, not DSP or specialized embedded systems.)</p>
|
[
{
"answer_id": 10783655,
"author": "Jav_Rock",
"author_id": 744859,
"author_profile": "https://Stackoverflow.com/users/744859",
"pm_score": 1,
"selected": false,
"text": "ARM"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/171399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10468/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.