qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
164,996
|
<p>Using C# in Visual Studio 2008 and stepping through a function in the debugger I get to the end of a function and am on the final curly brace } and about to return. Is there a way to find out what value the function is about to return?</p>
<p>This is necessary if the return value is calculated such as:</p>
<pre><code>return (x.Func() > y.Func());
</code></pre>
|
[
{
"answer_id": 165004,
"author": "MagicKat",
"author_id": 8505,
"author_profile": "https://Stackoverflow.com/users/8505",
"pm_score": 2,
"selected": false,
"text": "(x.Func() > y.Func())\n return ValueChangesAfterEveryCall();\n"
},
{
"answer_id": 165226,
"author": "Gabriel Isenberg",
"author_id": 1473493,
"author_profile": "https://Stackoverflow.com/users/1473493",
"pm_score": 1,
"selected": false,
"text": "int sumOfSomething = x.Func();\nint pendingSomethings = y.Func();\nreturn (sumOfSomething > pendingSomethings);\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/164996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1463/"
] |
165,025
|
<p>In ASP.NET, I am exporting some data to Excel by simply binding a DataSet to a GridView and then setting the ContentType to Excel.</p>
<p>My ASPX page is very simple and looks like this:</p>
<pre><code><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ExamExportReport.aspx.cs" Inherits="Cabi.CamCentral.Web.Pages.Utility.ExamExportReport" %>
<html>
<body>
<form id="form1" runat="server">
<asp:GridView
ID="gridExam"
AutoGenerateColumns="true"
runat="server">
</asp:GridView>
</form>
</body>
</html>
</code></pre>
<p>In the Page_Load method of the code behind, I am doing this:</p>
<pre><code>protected void Page_Load(object sender, EventArgs e)
{
BindGrid();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=ExamExport.xls");
}
</code></pre>
<p>Generally, everything works fine, and the Excel file pops up with the right data. The problem is that the Excel file always ends up with a blank first row right above the column headers. I just can't figure out what is causing this. Maybe it's something about the form tag? Maybe I need to add some styling or something to strip out padding or margins? I've tried a bunch of things but I just can't get rid of that dang first blank row. Has anyone else run into this? Any solutions?</p>
|
[
{
"answer_id": 165084,
"author": "azamsharp",
"author_id": 3797,
"author_profile": "https://Stackoverflow.com/users/3797",
"pm_score": 2,
"selected": false,
"text": "protected void Page_Load(object sender, EventArgs e)\n {\n if (!Page.IsPostBack)\n {\n BindData();\n }\n }\n\n private void BindData()\n {\n string connectionString = \"Server=localhost;Database=Northwind;Trusted_Connection=true\";\n SqlConnection myConnection = new SqlConnection(connectionString);\n SqlDataAdapter ad = new SqlDataAdapter(\"select * from products\", myConnection);\n DataSet ds = new DataSet();\n ad.Fill(ds);\n\n gvProducts.DataSource = ds;\n gvProducts.DataBind(); \n }\n\n protected void ExportGridView(object sender, EventArgs e)\n {\n Response.ClearContent();\n\n Response.AddHeader(\"content-disposition\", \"attachment; filename=MyExcelFile.xls\");\n\n Response.ContentType = \"application/excel\";\n\n StringWriter sw = new StringWriter();\n\n HtmlTextWriter htw = new HtmlTextWriter(sw);\n\n gvProducts.RenderControl(htw);\n\n Response.Write(sw.ToString());\n\n Response.End();\n }\n\n public override void VerifyRenderingInServerForm(Control control)\n {\n\n }\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/165025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1436/"
] |
165,042
|
<p>Does anyone happen to know if there is a token I can add to my csv for a certain field so Excel doesn't try to convert it to a date?</p>
<p>I'm trying to write a .csv file from my application and one of the values happens to look enough like a date that Excel is automatically converting it from text to a date. I've tried putting all of my text fields (including the one that looks like a date) within double quotes, but that has no effect.</p>
|
[
{
"answer_id": 165049,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": -1,
"selected": false,
"text": "25/12/2008 '25/12/2008"
},
{
"answer_id": 165052,
"author": "Jarod Elliott",
"author_id": 1061,
"author_profile": "https://Stackoverflow.com/users/1061",
"pm_score": 10,
"selected": true,
"text": "\"=\"\"2008-10-03\"\"\""
},
{
"answer_id": 5101939,
"author": "Abby",
"author_id": 631919,
"author_profile": "https://Stackoverflow.com/users/631919",
"pm_score": -1,
"selected": false,
"text": "SELECT CONCAT('\\'',NOW(),'\\''), firstname, lastname \nFROM your_table\nINTO OUTFILE 'export.csv' \nFIELDS TERMINATED BY ',' \nENCLOSED BY '\\\"' \nLINES TERMINATED BY '\\n'\n"
},
{
"answer_id": 6023847,
"author": "Andrew Ferk",
"author_id": 651983,
"author_profile": "https://Stackoverflow.com/users/651983",
"pm_score": 7,
"selected": false,
"text": "\"May 16, 2011\"\n \"=\"\"May 16, 2011\"\"\"\n"
},
{
"answer_id": 21900110,
"author": "Harry Duong",
"author_id": 3331408,
"author_profile": "https://Stackoverflow.com/users/3331408",
"pm_score": 2,
"selected": false,
"text": "Set objArgs = WScript.Arguments\n\nSet objFso = createobject(\"scripting.filesystemobject\")\n\ndim objTextFile\ndim arrStr ' an array to hold the text content\ndim sLine ' holding text to write to new file\n\n'Looping through all dropped file\nFor t = 0 to objArgs.Count - 1\n ' Input Path\n inPath = objFso.GetFile(wscript.arguments.item(t))\n\n ' OutPut Path\n outPath = replace(inPath, objFso.GetFileName(inPath), left(objFso.GetFileName(inPath), InStrRev(objFso.GetFileName(inPath),\".\") - 1) & \"_SPACE_ADDED.csv\")\n\n ' Read the file\n set objTextFile = objFso.OpenTextFile(inPath)\n\n\n 'Now Creating the file can overwrite exiting file\n set aNewFile = objFso.CreateTextFile(outPath, True) \n aNewFile.Close \n\n 'Open the file to appending data\n set aNewFile = objFso.OpenTextFile(outPath, 8) '2=Open for writing 8 for appending\n\n ' Reading data and writing it to new file\n Do while NOT objTextFile.AtEndOfStream\n arrStr = split(objTextFile.ReadLine,\",\")\n\n sLine = \"\" 'Clear previous data\n\n For i=lbound(arrStr) to ubound(arrStr)\n sLine = sLine + \" \" + arrStr(i) + \",\"\n Next\n\n 'Writing data to new file\n aNewFile.WriteLine left(sLine, len(sLine)-1) 'Get rid of that extra comma from the loop\n\n\n Loop\n\n 'Closing new file\n aNewFile.Close \n\nNext ' This is for next file\n\nset aNewFile=nothing\nset objFso = nothing\nset objArgs = nothing\n"
},
{
"answer_id": 23198122,
"author": "Colin Pear",
"author_id": 758503,
"author_profile": "https://Stackoverflow.com/users/758503",
"pm_score": 5,
"selected": false,
"text": "\"=\\\"\" + myVariable + \"\\\"\"\n"
},
{
"answer_id": 29693913,
"author": "flatbeat",
"author_id": 1821308,
"author_profile": "https://Stackoverflow.com/users/1821308",
"pm_score": 1,
"selected": false,
"text": "invoke-namedparameter $ex = New-Object -com \"Excel.Application\"\n$ex.visible = $true\n$csv = \"path\\to\\your\\csv.csv\"\nInvoke-NamedParameter ($ex.workbooks) \"opentext\" @{\"filename\"=$csv; \"Semicolon\"= $true}\n $ex = New-Object -com \"Excel.Application\"\n$ex.visible = $true;\n$csv = \"path\\to\\your\\csv.csv\";\n$ex.workbooks.add();\n$ex.activeWorkbook.activeSheet.Cells.NumberFormat = \"@\";\n$data = import-csv $csv -encoding utf8 -delimiter \";\"; \n$row = 1; \n$data | %{ $obj = $_; $col = 1; $_.psobject.properties.Name |%{if($row -eq1){$ex.ActiveWorkbook.activeSheet.Cells.item($row,$col).Value2= $_ };$ex.ActiveWorkbook.activeSheet.Cells.item($row+1,$col).Value2 =$obj.$_; $col++ }; $row++;}\n function csvToExcel($csv,$delimiter){\n $a = New-Object -com \"Excel.Application\"\n $a.visible = $true\n \n $a.workbooks.add()\n $a.activeWorkbook.activeSheet.Cells.NumberFormat = \"@\"\n $data = import-csv -delimiter $delimiter $csv; \n $array = ($data |ConvertTo-MultiArray).Value\n $starta = [int][char]'a' - 1\n if ($array.GetLength(1) -gt 26) {\n $col = [char]([int][math]::Floor($array.GetLength(1)/26) + $starta) + [char](($array.GetLength(1)%26) + $Starta)\n } else {\n $col = [char]($array.GetLength(1) + $starta)\n }\n $range = $a.activeWorkbook.activeSheet.Range(\"a1:\"+$col+\"\"+$array.GetLength(0))\n $range.value2 = $array;\n $range.Columns.AutoFit();\n $range.Rows.AutoFit();\n $range.Cells.HorizontalAlignment = -4131\n $range.Cells.VerticalAlignment = -4160\n}\n\n function ConvertTo-MultiArray {\n param(\n [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true)]\n [PSObject[]]$InputObject\n )\n BEGIN {\n $objects = @()\n [ref]$array = [ref]$null\n }\n Process {\n $objects += $InputObject\n }\n END {\n $properties = $objects[0].psobject.properties |%{$_.name}\n $array.Value = New-Object 'object[,]' ($objects.Count+1),$properties.count\n # i = row and j = column\n $j = 0\n $properties |%{\n $array.Value[0,$j] = $_.tostring()\n $j++\n }\n $i = 1\n $objects |% {\n $item = $_\n $j = 0\n $properties | % {\n if ($item.($_) -eq $null) {\n $array.value[$i,$j] = \"\"\n }\n else {\n $array.value[$i,$j] = $item.($_).tostring()\n }\n $j++\n }\n $i++\n }\n $array\n } \n} \ncsvToExcel \"storage_stats.csv\" \";\"\n"
},
{
"answer_id": 32627107,
"author": "Some_Guy",
"author_id": 4842964,
"author_profile": "https://Stackoverflow.com/users/4842964",
"pm_score": 3,
"selected": false,
"text": "Data > Get external data > From Text"
},
{
"answer_id": 34146312,
"author": "ChrisB",
"author_id": 5640342,
"author_profile": "https://Stackoverflow.com/users/5640342",
"pm_score": 3,
"selected": false,
"text": "012345,00198475\n \"=\"\"\"012345\",\"=\"\"\"00198475\"\n =\"012345\"\n"
},
{
"answer_id": 46266088,
"author": "LarsS",
"author_id": 7533100,
"author_profile": "https://Stackoverflow.com/users/7533100",
"pm_score": 0,
"selected": false,
"text": "Sub PasteAsText()\n' Created by Lars-Erik Sørbotten, 2017-09-17\nCall CreateSheetBackup\n \nColumns(ActiveCell.Column).NumberFormat = \"@\"\n \nDim DataObj As MSForms.DataObject\nSet DataObj = New MSForms.DataObject\nDataObj.GetFromClipboard\n\nActiveCell.PasteSpecial\n\nEnd Sub\n '"
},
{
"answer_id": 65814780,
"author": "Srikanth Josyula",
"author_id": 7862778,
"author_profile": "https://Stackoverflow.com/users/7862778",
"pm_score": 1,
"selected": false,
"text": "=(\"my_value\") =(\"04SEP2009\") 04SEP2009 09/04/2009"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/165042",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
165,043
|
<p>This is an excerpt of code from a class I am working with in Java (below). Obviously the code is defining a static variable named EPSILON with the data type double. What I don't understand is the "1E-14" part. What kind of number is that? What does it mean?</p>
<p>final double EPSILON = 1E-14;</p>
|
[
{
"answer_id": 165057,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 5,
"selected": true,
"text": "final double EPSILON = 0.00000000000001;\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/165043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
165,075
|
<p>I'd like to map a reference to an object instead of the object value with an HashTable</p>
<pre><code>configMapping.Add("HEADERS_PATH", Me.headers_path)
</code></pre>
<p>that way when I'm going to retrieve the value of "HEADERS_PATH" I'll be able to assign a value to Me.headers_path</p>
<p>something like the " & " operator in C</p>
|
[
{
"answer_id": 165091,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 3,
"selected": true,
"text": "public class Holder<T> {\n public T Value { get; set; }\n}\n\n...\n\nHolder<String> headerPath = new Holder<String>() { Value = \"this is a test\" };\nconfigMapping.Add(\"HEADERS_PATH\", headerPath);\n\n...\n\n((Holder<String>)configMapping[\"HEADERS_PATH\"]).Value = \"this is a new test\";\n\n// headerPath.Value == \"this is a new test\"\n"
},
{
"answer_id": 287996,
"author": "pipTheGeek",
"author_id": 28552,
"author_profile": "https://Stackoverflow.com/users/28552",
"pm_score": 1,
"selected": false,
"text": "public class Holder(Of T)\n public Value as T \nend class\n...\nDim headerPath as new Holder(Of String)\nheaderPath.Value = \"this is a test\"\nconfigMapping.Add(\"HEADERS_PATH\", headerPath)\n...\nDirectcast(configMapping[\"HEADERS_PATH\"]),Holder(Of String)).Value = \"this is a new test\"\n\n'headerPath.Value now equals \"this is a new test\"\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/165075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6367/"
] |
165,082
|
<p>I'm hand-maintaining an HTML document, and I'm looking for a way to automatically insert a link around text in a table. Let me illustrate:</p>
<pre><code><table><tr><td class="case">123456</td></tr></table>
</code></pre>
<p>I would like to automatically make every text in a TD with class "case" a link to that case in our bug tracking system (which, incidentally, is FogBugz).</p>
<p>So I'd like that "123456" to be changed to a link of this form:</p>
<pre><code><a href="http://bugs.example.com/fogbugz/default.php?123456">123456</a>
</code></pre>
<p>Is that possible? I've played with the :before and :after pseudo-elements, but there doesn't seem to be a way to repeat the case number.</p>
|
[
{
"answer_id": 165100,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 5,
"selected": true,
"text": "function makeCasesClickable(){\n var cells = document.getElementsByTagName('td')\n for (var i = 0, cell; cell = cells[i]; i++){\n if (cell.className != 'case') continue\n var caseId = cell.innerHTML\n cell.innerHTML = ''\n var link = document.createElement('a')\n link.href = 'http://bugs.example.com/fogbugz/default.php?' + caseId\n link.appendChild(document.createTextNode(caseId))\n cell.appendChild(link)\n }\n}\n onload = makeCasesClickable"
},
{
"answer_id": 165112,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 1,
"selected": false,
"text": "function case_link($id) {\n return '<a href=\"http://bugs.example.com/fogbuz/default.php?' . $id . '\">' . $id . '</a>';\n}\n <table><tr><td class=\"case\"><?php echo case_link('123456'); ?></td></tr></table>\n"
},
{
"answer_id": 165146,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 4,
"selected": false,
"text": "$('.case').each(function() {\n var link = $(this).html();\n $(this).contents().wrap('<a href=\"example.com/script.php?id='+link+'\"></a>');\n});\n"
},
{
"answer_id": 165155,
"author": "Vincent McNabb",
"author_id": 16299,
"author_profile": "https://Stackoverflow.com/users/16299",
"pm_score": 0,
"selected": false,
"text": "<head> <script type=\"text/javascript\" language=\"javascript\">\n function getElementsByClass (className) {\n var all = document.all ? document.all :\n document.getElementsByTagName('*');\n var elements = new Array();\n for (var i = 0; i < all.length; i++)\n if (all[i].className == className)\n elements[elements.length] = all[i];\n return elements;\n }\n\n function makeLinks(className, url) {\n nodes = getElementsByClass(className);\n for(var i = 0; i < nodes.length; i++) {\n node = nodes[i];\n text = node.innerHTML\n node.innerHTML = '<a href=\"' + url + text + '\">' + text + '</a>';\n }\n }\n</script>\n <body> <script type=\"text/javascript\" language=\"javascript\">\n makeLinks(\"case\", \"http://bugs.example.com/fogbugz/default.php?\");\n</script>\n"
},
{
"answer_id": 17301005,
"author": "piethh",
"author_id": 2520659,
"author_profile": "https://Stackoverflow.com/users/2520659",
"pm_score": -1,
"selected": false,
"text": " function linker($style_cont, $id_html){\n\n if (strpos($style_cont,'connect:') !== false) {\n\n $url;\n $id_final;\n $id_outer = '#'.$id_html;\n $id_loc = strpos($style_cont,$id_outer); \n\n $connect_loc = strpos($style_cont,'connect:', $id_loc);\n\n $next_single_quote = stripos($style_cont,\"'\", $connect_loc);\n $next_double_quote = stripos($style_cont,'\"', $connect_loc);\n\n if($connect_loc < $next_single_quote)\n { \n $link_start = $next_single_quote +1;\n $last_single_quote = stripos($style_cont, \"'\", $link_start);\n $link_end = $last_single_quote;\n $link_size = $link_end - $link_start;\n $url = substr($style_cont, $link_start, $link_size);\n }\n else\n {\n $link_start = $next_double_quote +1;\n $last_double_quote = stripos($style_cont, '\"', $link_start);\n $link_end = $last_double_quote;\n $link_size = $link_end - $link_start;\n $url = substr($style_cont, $link_start, $link_size); //link!\n }\n\n $connect_loc_rev = (strlen($style_cont) - $connect_loc) * -1;\n $id_start = strrpos($style_cont, '#', $connect_loc_rev);\n $id_end = strpos($style_cont,'{', $id_start);\n $id_size = $id_end - $id_start;\n $id_raw = substr($style_cont, $id_start, $id_size);\n $id_clean = rtrim($id_raw); //id!\n\n if (strpos($url,'http://') !== false) \n {\n $url_clean = $url;\n }\n else\n {\n $url_clean = 'http://'.$url;\n };\n\n if($id_clean[0] == '#')\n {\n $id_final = $id_clean;\n\n if($id_outer == $id_final)\n {\n echo '<a href=\"';\n echo $url_clean;\n echo '\" target=\"_blank\">';\n };\n };\n };\n};\n <a href='blah'> </a>"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/165082",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19207/"
] |
165,092
|
<p>Basically I wanted to do something like <code>git push mybranch to repo1, repo2, repo3</code></p>
<p>right now I'm just typing push many times, and if I'm in a hurry to the the pushing done, I just send them all to the background <code>git push repo1 & git push repo2 &</code></p>
<p>I'm just wondering if <code>git</code> natively supports what I want to do, or if maybe there's a clever script out there, or maybe a way to edit the local repo config file to say a branch should be pushed to multiple remotes.</p>
|
[
{
"answer_id": 165131,
"author": "Adam Franco",
"author_id": 15872,
"author_profile": "https://Stackoverflow.com/users/15872",
"pm_score": 3,
"selected": false,
"text": "#!/bin/sh\n#\n# An example hook script to prepare a packed repository for use over\n# dumb transports.\n#\n# To enable this hook, make this file executable by \"chmod +x post-update\".\n\n# Update static info that will be used by git clients accessing\n# the git directory over HTTP rather than the git protocol.\ngit-update-server-info\n\n# Copy git repository files to my web server for HTTP serving.\nrsync -av --delete -e ssh /home/afranco/repositories/public/ afranco@slug.middlebury.edu:/srv/www/htdocs/git/\n\n# Upload to github\ngit-push --mirror github \n"
},
{
"answer_id": 166043,
"author": "Aristotle Pagaltzis",
"author_id": 9410,
"author_profile": "https://Stackoverflow.com/users/9410",
"pm_score": 7,
"selected": true,
"text": "git remote .git/config [remote \"public\"]\n url = git@github.com:kch/inheritable_templates.git\n url = kch@homeserver:projects/inheritable_templates.git\n git push public"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/165092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13989/"
] |
165,101
|
<p>The following code:</p>
<pre><code>template <typename S, typename T>
struct foo {
void bar();
};
template <typename T>
void foo <int, T>::bar() {
}
</code></pre>
<p>gives me the error</p>
<pre><code>invalid use of incomplete type 'struct foo<int, T>'
declaration of 'struct foo<int, T>'
</code></pre>
<p>(I'm using gcc.) Is my syntax for partial specialization wrong? Note that if I remove the second argument:</p>
<pre><code>template <typename S>
struct foo {
void bar();
};
template <>
void foo <int>::bar() {
}
</code></pre>
<p>then it compiles correctly.</p>
|
[
{
"answer_id": 165153,
"author": "coppro",
"author_id": 16855,
"author_profile": "https://Stackoverflow.com/users/16855",
"pm_score": 7,
"selected": true,
"text": "template <typename U = T> struct Nested this->member"
},
{
"answer_id": 6238814,
"author": "Anonymous Coward",
"author_id": 784194,
"author_profile": "https://Stackoverflow.com/users/784194",
"pm_score": 3,
"selected": false,
"text": "template <class T, int N>\nstruct thingBase\n{\n //Data members and other stuff.\n};\n\ntemplate <class T, int N> struct thing : thingBase<T, N> {};\n\ntemplate <class T> struct thing<T, 42> : thingBase<T, 42>\n{\n thing(T * param1, wchar_t * param2)\n {\n //Special construction if N equals 42.\n }\n};\n"
},
{
"answer_id": 23738555,
"author": "Echsecutor",
"author_id": 3586021,
"author_profile": "https://Stackoverflow.com/users/3586021",
"pm_score": 3,
"selected": false,
"text": "/* The following circumvents the impossible partial specialization of \na member function \nactualClass<dataT,numericalT,1>::access\nas well as the non-nonsensical full specialisation of the possibly\nvery big actualClass. */\n\n//helper:\ntemplate <typename dataT, typename numericalT, unsigned int dataDim>\nclass specialised{\npublic:\n numericalT& access(dataT& x, const unsigned int index){return x[index];}\n};\n\n//partial specialisation:\ntemplate <typename dataT, typename numericalT>\nclass specialised<dataT,numericalT,1>{\npublic:\n numericalT& access(dataT& x, const unsigned int index){return x;}\n};\n\n//your actual class:\ntemplate <typename dataT, typename numericalT, unsigned int dataDim>\nclass actualClass{\nprivate:\n dataT x;\n specialised<dataT,numericalT,dataDim> accessor;\npublic:\n //... for(int i=0;i<dataDim;++i) ...accessor.access(x,i) ...\n};\n"
},
{
"answer_id": 62695743,
"author": "Nathan Phillips",
"author_id": 740378,
"author_profile": "https://Stackoverflow.com/users/740378",
"pm_score": 2,
"selected": false,
"text": "struct A\n{\n template<typename T>\n bool foo(T arg) { return true; }\n\n bool foo(int arg) { return false; }\n\n void bar()\n {\n bool test = foo(7); // Returns false\n }\n};\n"
},
{
"answer_id": 63540063,
"author": "Jonathan SIX",
"author_id": 12703286,
"author_profile": "https://Stackoverflow.com/users/12703286",
"pm_score": 1,
"selected": false,
"text": "template <size_t TSize>\nstruct A\n{\n void recursiveMethod();\n};\n\ntemplate <size_t TSize>\nvoid A<TSize>::recursiveMethod()\n{\n if constexpr (TSize == 1)\n {\n //[...] imple without subA\n }\n else\n {\n A<TSize - 1> subA;\n\n //[...] imple\n }\n}\n template <typename T>\nstruct A\n{\n void foo();\n};\n\ntemplate <typename T>\nvoid A<T>::foo()\n{\n if constexpr (std::is_arithmetic_v<T>)\n {\n std::cout << \"arithmetic\" << std::endl;\n }\n else\n {\n std::cout << \"other\" << std::endl;\n }\n}\n\n\nint main()\n{\n A<char*> a;\n a.foo();\n\n A<int> b;\n\n b.foo();\n}\n other\narithmetic\n"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/165101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/112/"
] |
165,102
|
<p>What's wrong with Linq to SQL?</p>
<p>Or - what about Linq to SQL would make it unsuitable for a project, either new or existing? I want to hear about why you would <strong>not</strong> choose Linq to SQL for a particular project - including what project parameters make it unsuitable.</p>
|
[
{
"answer_id": 165166,
"author": "jalbert",
"author_id": 1360388,
"author_profile": "https://Stackoverflow.com/users/1360388",
"pm_score": 2,
"selected": false,
"text": "System.Data.Linq.DataContext"
}
] |
2008/10/02
|
[
"https://Stackoverflow.com/questions/165102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16942/"
] |
165,135
|
<p>I've written a command line utility that detects which network interface is connected, and sets the staitc ip address and dns servers for it (by calling netsh). However, I can't seem to figure out how to set the dns search suffixes. netsh doesnt appear capable of doing that. How do I do that otherwise (WMI perhaps)?</p>
|
[
{
"answer_id": 64265537,
"author": "marsh-wiggle",
"author_id": 1574221,
"author_profile": "https://Stackoverflow.com/users/1574221",
"pm_score": 0,
"selected": false,
"text": "string searchList = \"\";\ntry \n{\n using (var reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(tcpSettingsSubKey))\n {\n searchList = (reg.GetValue(\"SearchList\") as string);\n }\n}\ncatch(Exception ex)\n{\n // something went wrong\n}\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2712/"
] |
165,140
|
<p>Does SubSonic.SqlQuery have a between/and for date ranges? If not, what would be the best way to get a range.</p>
|
[
{
"answer_id": 165234,
"author": "Forgotten Semicolon",
"author_id": 1960,
"author_profile": "https://Stackoverflow.com/users/1960",
"pm_score": 3,
"selected": true,
"text": "SqlQuery query = new SqlQuery().From(\"Table\")\n .WhereExpression(\"Column\")\n .IsBetweenAnd(\"1/1/2008\", \"12/31/2008\");\nDataSet dataSet = query.ExecuteDataSet(); // Or whatever output you need\n"
},
{
"answer_id": 185880,
"author": "aherrick",
"author_id": 20446,
"author_profile": "https://Stackoverflow.com/users/20446",
"pm_score": 2,
"selected": false,
"text": "\n TableCollection data = new TableCollection(); \n\nQuery q = Table.CreateQuery()\n .BETWEEN_AND(\"Column\", \"1/1/2008\", \"12/31/2008\");\n\n data.LoadAndCloseReader(q.ExecuteReader());\n\n// loop through collection\n\n\n Query q = Table.CreateQuery()\n .BETWEEN_AND(\"Column\", \"1/1/2008\", \"12/31/2008\");\n\n data.LoadAndCloseReader(q.ExecuteReader());\n\n// loop through collection\n "
},
{
"answer_id": 941125,
"author": "Yordan Georgiev",
"author_id": 65706,
"author_profile": "https://Stackoverflow.com/users/65706",
"pm_score": 0,
"selected": false,
"text": " SqlQuery query = new SqlQuery().From(\"Orders\")\n .WhereExpression(\"OrderDate\")\n .IsBetweenAnd(\"1996-07-02\", \"1996-07-08\");\n DataSet dataSet = query.ExecuteDataSet(); // Or whatever output you need\n\n #region PresentResultsReplaceResponseWriteWithConsole.WriteLineForConsoleApp\n\n DataTable dt = dataSet.Tables[0];\n Response.Write(\"<table>\");\n foreach ( DataRow dr in dt.Rows ) \n {\n Response.Write(\"<tr>\");\n for (int i = 0; i < dt.Columns.Count; i++)\n {\n Response.Write(\"<td>\");\n Response.Write(dr[i].ToString() + \" \");\n Response.Write(\"<td>\");\n } //eof for \n Response.Write(\"</br>\");\n Response.Write(\"</tr>\");\n\n\n }\n Response.Write(\"<table>\");\n #endregion PresentResultsReplaceResponseWriteWithConsole.WriteLineForConsoleApp\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13954/"
] |
165,170
|
<p>I want to display dates in the format: short day of week, short month, day of month without leading zero but including "th", "st", "nd", or "rd" suffix.</p>
<p>For example, the day this question was asked would display "Thu Oct 2nd".</p>
<p>I'm using Ruby 1.8.7, and <a href="http://ruby-doc.org/core/Time.html#method-i-strftime" rel="noreferrer">Time.strftime</a> just doesn't seem to do this. I'd prefer a standard library if one exists.</p>
|
[
{
"answer_id": 165202,
"author": "mwilliams",
"author_id": 23909,
"author_profile": "https://Stackoverflow.com/users/23909",
"pm_score": 7,
"selected": false,
"text": ">> 3.ordinalize\n=> \"3rd\"\n>> 2.ordinalize\n=> \"2nd\"\n>> 1.ordinalize\n=> \"1st\"\n"
},
{
"answer_id": 165213,
"author": "Bartosz Blimke",
"author_id": 18715,
"author_profile": "https://Stackoverflow.com/users/18715",
"pm_score": 9,
"selected": true,
"text": ">> time = Time.new\n=> Fri Oct 03 01:24:48 +0100 2008\n>> time.strftime(\"%a %b #{time.day.ordinalize}\")\n=> \"Fri Oct 3rd\"\n require 'active_support/core_ext/integer/inflections'\n"
},
{
"answer_id": 165225,
"author": "Jimmy Schementi",
"author_id": 5721,
"author_profile": "https://Stackoverflow.com/users/5721",
"pm_score": 4,
"selected": false,
"text": ">> require 'activesupport'\n=> []\n>> t = Time.now\n=> Thu Oct 02 17:28:37 -0700 2008\n>> formatted = \"#{t.strftime(\"%a %b\")} #{t.day.ordinalize}\"\n=> \"Thu Oct 2nd\"\n"
},
{
"answer_id": 165350,
"author": "Patrick McKenzie",
"author_id": 15046,
"author_profile": "https://Stackoverflow.com/users/15046",
"pm_score": 3,
"selected": false,
"text": "DateTime to_formatted_s Time::DATE_FORMATS d = DateTime.now #Examples were executed on October 3rd 2008\nTime::DATE_FORMATS[:weekday_month_ordinal] = \n lambda { |time| time.strftime(\"%a %b #{time.day.ordinalize}\") }\nd.to_formatted_s :weekday_month_ordinal #Fri Oct 3rd\n class DateTime\n\n Time::DATE_FORMATS[:weekday_month_ordinal] = \n lambda { |time| time.strftime(\"%a %b #{time.day.ordinalize}\") }\n\n def to_my_special_s\n to_formatted_s :weekday_month_ordinal\n end\nend\n\nDateTime.now.to_my_special_s #Fri Oct 3rd\n"
},
{
"answer_id": 433127,
"author": "Richard Hurt",
"author_id": 21512,
"author_profile": "https://Stackoverflow.com/users/21512",
"pm_score": 5,
"selected": false,
"text": "config/initializers date_format.rb Time::DATE_FORMATS.merge!(\n my_date: lambda { |time| time.strftime(\"%a, %b #{time.day.ordinalize}\") }\n)\n My Date: <%= h some_date.to_s(:my_date) %>\n Time::DATE_FORMATS.merge!(\n datetime_military: '%Y-%m-%d %H:%M',\n datetime: '%Y-%m-%d %I:%M%P',\n time: '%I:%M%P',\n time_military: '%H:%M%P',\n datetime_short: '%m/%d %I:%M',\n due_date: lambda { |time| time.strftime(\"%a, %b #{time.day.ordinalize}\") }\n)\n"
},
{
"answer_id": 52906913,
"author": "Joshua Pinter",
"author_id": 293280,
"author_profile": "https://Stackoverflow.com/users/293280",
"pm_score": 3,
"selected": false,
"text": "%o config/initializers/srtftime.rb module StrftimeOrdinal\n def self.included( base )\n base.class_eval do\n alias_method :old_strftime, :strftime\n def strftime( format )\n old_strftime format.gsub( \"%o\", day.ordinalize )\n end\n end\n end\nend\n\n[ Time, Date, DateTime ].each{ |c| c.send :include, StrftimeOrdinal }\n Time.new( 2018, 10, 2 ).strftime( \"%a %b %o\" )\n=> \"Tue Oct 2nd\"\n Date DateTime DateTime.new( 2018, 10, 2 ).strftime( \"%a %b %o\" )\n=> \"Tue Oct 2nd\"\n\nDate.new( 2018, 10, 2 ).strftime( \"%a %b %o\" )\n=> \"Tue Oct 2nd\"\n"
},
{
"answer_id": 54375658,
"author": "Olivier Lacan",
"author_id": 385622,
"author_profile": "https://Stackoverflow.com/users/385622",
"pm_score": 3,
"selected": false,
"text": "June 1st, 2018 Time.current.to_date.to_s(:long_ordinal)\n=> \"January 26th, 2019\"\n Date.current.to_s(:long_ordinal)\n=> \"January 26th, 2019\"\n Time.current.to_s(:long_ordinal)\n=> \"January 26th, 2019 04:21\"\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12887/"
] |
165,175
|
<p>I'm failing to understand exactly what the IF statement is doing, from what I can see it is checking if the variable <code>x</code> is equal to the int <code>0</code>. If this is <code>true</code> the ABSOLUTE value of the variable <code>y</code> is returned... this is when I lose the plot, why would the return statement then go on to include <code><= ESPILON</code>? Surely this means less than or equal to the value of epsilon? if so how is that working? If it doesn't mean that then what does it mean?</p>
<p>(JAVA CODE)</p>
<pre><code>final double EPSILON = 1E-14;
if (x == 0)
return Math.abs(y) <= EPSILON;
</code></pre>
|
[
{
"answer_id": 165180,
"author": "Airsource Ltd",
"author_id": 18017,
"author_profile": "https://Stackoverflow.com/users/18017",
"pm_score": 3,
"selected": false,
"text": "if(x == 0)\n{\n boolean ret = Math.abs(y) <= EPSILON;\n return ret;\n}\n int x = 3 + 4 * 5;\n"
},
{
"answer_id": 165185,
"author": "Stephen Wrighton",
"author_id": 7516,
"author_profile": "https://Stackoverflow.com/users/7516",
"pm_score": 1,
"selected": false,
"text": "if (x==0) {\n return MATH.abs(y) <= EPSILON;\n}\n"
},
{
"answer_id": 165186,
"author": "Jedidja",
"author_id": 9913,
"author_profile": "https://Stackoverflow.com/users/9913",
"pm_score": 3,
"selected": false,
"text": "Math.abs(y) <= EPSILON\n x != 0\n"
},
{
"answer_id": 166816,
"author": "Robin",
"author_id": 21925,
"author_profile": "https://Stackoverflow.com/users/21925",
"pm_score": 0,
"selected": false,
"text": "return (Math.abs(y) <= EPSILON);\n if (Math.abs(y) <= EPSILON)\n return true;\nelse\n return false;\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
165,188
|
<p>I have some c(++) code that uses sprintf to convert a uint_64 to a string. This needs to be portable to both linux and Solaris.</p>
<p>On linux we use %ju, but there does not appear to be any equivalent on Solaris. The closest I can find is %lu, but this produces incorrect output. Some sample code:</p>
<pre><code>#include <stdio.h>
#include <sys/types.h>
#ifdef SunOS
typedef uint64_t u_int64_t;
#endif
int main(int argc, char **argv) {
u_int64_t val = 123456789123L;
#ifdef SunOS
printf("%lu\n", val);
#else
printf("%ju\n", val);
#endif
}
</code></pre>
<p>On linux, the output is as expected; on Solaris 9 (don't ask), it's "28"</p>
<p>What can I use?</p>
|
[
{
"answer_id": 165199,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 0,
"selected": false,
"text": "%llu long long"
},
{
"answer_id": 165203,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 5,
"selected": true,
"text": "printf( \"%\" PRIu64 \"\\n\", val);\n"
},
{
"answer_id": 165204,
"author": "T Percival",
"author_id": 954,
"author_profile": "https://Stackoverflow.com/users/954",
"pm_score": 0,
"selected": false,
"text": "uint64_t stdint.h"
},
{
"answer_id": 165207,
"author": "coppro",
"author_id": 16855,
"author_profile": "https://Stackoverflow.com/users/16855",
"pm_score": 2,
"selected": false,
"text": "unsigned long long long long ULL L %llu long long"
},
{
"answer_id": 165238,
"author": "wnoise",
"author_id": 15464,
"author_profile": "https://Stackoverflow.com/users/15464",
"pm_score": 3,
"selected": false,
"text": "#include <inttypes.h>\n\nuint64_t big = ...;\nprintf(\"%\" PRIu64 \"\\n\", big);\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165188",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16977/"
] |
165,212
|
<p>How can I check the umask of a program which is currently running?</p>
<p>[update: another process, not the current process.]</p>
|
[
{
"answer_id": 165327,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": false,
"text": "umask mode_t\nread_umask (void)\n{\n mode_t mask = umask (0);\n umask (mask);\n return mask;\n}\n getumask getumask ->umask getumask"
},
{
"answer_id": 165718,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "(gdb) attach <your pid>\n...\n(gdb) call umask(0)\n[Switching to Thread -1217489200 (LWP 11037)]\n$1 = 18 # this is the umask\n(gdb) call umask(18) # reset umask\n$2 = 0\n(gdb) \n O22"
},
{
"answer_id": 38861278,
"author": "tbc0",
"author_id": 650264,
"author_profile": "https://Stackoverflow.com/users/650264",
"pm_score": 1,
"selected": false,
"text": "perl sudo gdb --pid=$(pgrep emacs) --batch -ex 'call/o umask(0)' -ex 'call umask($1)' 2> /dev/null | perl -ne 'print(\"$1\\n\")if(/^\\$1 = (\\d+)$/)'\n"
},
{
"answer_id": 43066791,
"author": "egmont",
"author_id": 4457671,
"author_profile": "https://Stackoverflow.com/users/4457671",
"pm_score": 4,
"selected": false,
"text": "/proc/<pid>/status"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/116/"
] |
165,231
|
<p>Although I played with it before, I'm finally starting to use <a href="http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard" rel="noreferrer">Dvorak (Simplified)</a> regularly. I've been in a steady relationship with Vim for several years now, and I'm trying to figure out the best way to remap the key bindings to suit my newfound Dvorak skills.</p>
<p>How do <em>you</em> remap Vim's key bindings to best work with Dvorak?</p>
<p>Explanations encouraged!</p>
|
[
{
"answer_id": 165252,
"author": "Adam Davis",
"author_id": 2915,
"author_profile": "https://Stackoverflow.com/users/2915",
"pm_score": 6,
"selected": true,
"text": "Dvorak it!\nno d h\nno h j\nno t k\nno n l\nno s :\nno S :\nno j d\nno l n\nno L N\nAdded benefits\nno - $\nno _ ^\nno N <C-w><C-w>\nno T <C-w><C-r>\nno H 8<Down>\nno T 8<Up>\nno D <C-w><C-r>\n <C-w><C-w> <C-w><C-r>"
},
{
"answer_id": 166064,
"author": "Aristotle Pagaltzis",
"author_id": 9410,
"author_profile": "https://Stackoverflow.com/users/9410",
"pm_score": 2,
"selected": false,
"text": "source :e $VIMRUNTIME/macros/dvorak\n"
},
{
"answer_id": 483885,
"author": "zcrar70",
"author_id": 59384,
"author_profile": "https://Stackoverflow.com/users/59384",
"pm_score": 3,
"selected": false,
"text": "\" dvorak remap\nnoremap h h\nnoremap t j\nnoremap n k\nnoremap s l\nnoremap l n\nnoremap L N\n\n\" easy access to beginning and end of line\nnoremap - $\nnoremap _ ^\n"
},
{
"answer_id": 3234552,
"author": "weakish",
"author_id": 222893,
"author_profile": "https://Stackoverflow.com/users/222893",
"pm_score": 2,
"selected": false,
"text": "noremap h h\nnoremap t j\nnoremap n k\nnoremap s l\nnoremap j t\nnoremap l n\nnoremap k s\nnoremap J T\nnoremap L N\nnoremap K S\nnoremap T J\nnoremap N L\nnoremap S K\n n (Next) -> l (Left) -- \"What's left?\" resembles \"What's next?\"\ns (Substitute) -> k (Kill then insert)\nt (jump Till) -> j (Jump till)\nN, S, T are similar.\n\nJ (Join lines) -> T (make lines Together)\nK (Keyword) -> S (Subject)\nL[count] (Line count) -> N (line Number)\n"
},
{
"answer_id": 14790810,
"author": "Gordon Gustafson",
"author_id": 89989,
"author_profile": "https://Stackoverflow.com/users/89989",
"pm_score": 1,
"selected": false,
"text": ":set keymap=dvorak\n :wq :%s/foo/bar/gc"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165231",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
165,253
|
<p>If I load the nextimg URL manually in the browser, it gives a new picture every time I reload. But this bit of code shows the same image every iteration of <code>draw()</code>.</p>
<p>How can I force myimg not to be cached?</p>
<pre><code><html>
<head>
<script type="text/javascript">
function draw(){
var canvas = document.getElementById('canv');
var ctx = canvas.getContext('2d');
var rx;
var ry;
var i;
myimg = new Image();
myimg.src = 'http://ohm:8080/cgi-bin/nextimg'
rx=Math.floor(Math.random()*100)*10
ry=Math.floor(Math.random()*100)*10
ctx.drawImage(myimg,rx,ry);
window.setTimeout('draw()',0);
}
</script>
</head>
<body onload="draw();">
<canvas id="canv" width="1024" height="1024"></canvas>
</body>
</html>
</code></pre>
|
[
{
"answer_id": 165256,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 5,
"selected": false,
"text": "var url = 'http://.../?' + escape(new Date())\n Math.random() escape(new Date())"
},
{
"answer_id": 165258,
"author": "Jonathan Lonowski",
"author_id": 15031,
"author_profile": "https://Stackoverflow.com/users/15031",
"pm_score": 3,
"selected": false,
"text": "[Image].src = 'image.png?' + (new Date()).getTime();\n"
},
{
"answer_id": 165310,
"author": "olliej",
"author_id": 784,
"author_profile": "https://Stackoverflow.com/users/784",
"pm_score": 4,
"selected": true,
"text": " var myimg = new Image();\n myimg.onload = function() {\n var rx=Math.floor(Math.random()*100)*10\n var ry=Math.floor(Math.random()*100)*10\n ctx.drawImage(myimg,rx,ry);\n window.setTimeout(draw,0);\n }\n myimg.src = 'http://ohm:8080/cgi-bin/nextimg'\n draw"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/116/"
] |
165,284
|
<p>I have a flowlayout panel and on a resize event, I resize all the controls inside the flowlayout panel so they fit the width of the (flowlayoutpanel - padding - scroll bar width). On some resizes, the scroll bar is not shown, hiding most of the controls outside the area of the flowlayoutpanel while on other resizes the scroll bar is shown.I have set the AutoScroll property on the flowlayoutpanel to true. This is all done using C#, but I have also encountered this problem in VB.net. </p>
<p>Is there a way to force the flowlayoutpanel to recalculate how the controls are laid out after I resize the controls in the resize event or some other way to fix this problem?</p>
|
[
{
"answer_id": 165891,
"author": "Alex Lyman",
"author_id": 5897,
"author_profile": "https://Stackoverflow.com/users/5897",
"pm_score": 4,
"selected": true,
"text": ".PerformLayout()"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1632/"
] |
165,316
|
<p>From the MSDN article on STAThread:</p>
<blockquote>
<p>Indicates that the COM threading model for an application is single-threaded apartment (STA).</p>
</blockquote>
<p>(For reference, that's <a href="http://msdn.microsoft.com/en-us/library/system.stathreadattribute.aspx" rel="noreferrer">the entire article</a>.)</p>
<p>Single-threaded apartment... OK, that went over my head. Also, I read somewhere that unless your application uses COM interop, this attribute actually does nothing at all. So what exactly does it do, and how does it affect multithreaded applications? Should multithreaded applications (which includes anything from anyone using <code>Timer</code>s to asynchronous method calls, not just threadpools and the like) use MTAThread, even if it's 'just to be safe'? What does STAThread and MTAThread actually do?</p>
|
[
{
"answer_id": 165351,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 2,
"selected": false,
"text": "CoInitialize"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
165,338
|
<p>I'm working in Visual Studio 2005 and have added a text file that needs to be parsed by right-clicking the project in the solution explorer and add --> new item. This places the .txt file to the project folder. The debug .exe file is in the /bin/debug folder. </p>
<p>How do I properly point to the txt file from code using relative paths that will properly resolve being two folders back, while also resolving to be in the same folder after the solution is published?</p>
|
[
{
"answer_id": 165353,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 2,
"selected": false,
"text": "xcopy \"$(ProjectDir)*.txt\" \"$(OutDir)\"\n $(ConfigurationName)\" $(ProjectDir)"
},
{
"answer_id": 166538,
"author": "Seth Petry-Johnson",
"author_id": 23632,
"author_profile": "https://Stackoverflow.com/users/23632",
"pm_score": 2,
"selected": false,
"text": "Assembly thisAssembly = Assembly.GetExecutingAssembly();\nStream stream = thisAssembly.GetManifestResourceStream(\"Namespace.Folder.Filename.Ext\");\nbyte[] data = new byte[stream.Length];\nstream.Read(data, 0, (int)stream.Length);\n"
},
{
"answer_id": 4399441,
"author": "Peter",
"author_id": 426361,
"author_profile": "https://Stackoverflow.com/users/426361",
"pm_score": 2,
"selected": false,
"text": "System.Reflection.Assembly.GetExecutingAssembly().Location + \"\\..\\\" + \"fileToRead.txt\"\n fileToRead.txt\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4856/"
] |
165,346
|
<p>I've been working on porting some of my Processing code over to regular Java in NetBeans. So far so well, most everything works great, except for when I go to use non-grayscale colors. </p>
<p>I have a script that draws a spiral pattern, and should vary the colors in the spiral based on a modulus check. The script seems to hang, however, and I can't really explain why.</p>
<p>If anyone has some experience with Processing and Java, and you could tell me where my mistake is, I'd really love to know.</p>
<p>For the sake of peer-review, here's my little program:</p>
<pre><code>package spirals;
import processing.core.*;
public class Main extends PApplet
{
float x, y;
int i = 1, dia = 1;
float angle = 0.0f, orbit = 0f;
float speed = 0.05f;
//color palette
int gray = 0x0444444;
int blue = 0x07cb5f7;
int pink = 0x0f77cb5;
int green = 0x0b5f77c;
public Main(){}
public static void main( String[] args )
{
PApplet.main( new String[] { "spirals.Main" } );
}
public void setup()
{
background( gray );
size( 400, 400 );
noStroke();
smooth();
}
public void draw()
{
if( i % 11 == 0 )
fill( green );
else if( i % 13 == 0 )
fill( blue );
else if( i % 17 == 0 )
fill( pink );
else
fill( gray );
orbit += 0.1f; //ever so slightly increase the orbit
angle += speed % ( width * height );
float sinval = sin( angle );
float cosval = cos( angle );
//calculate the (x, y) to produce an orbit
x = ( width / 2 ) + ( cosval * orbit );
y = ( height / 2 ) + ( sinval * orbit );
dia %= 11; //keep the diameter within bounds.
ellipse( x, y, dia, dia );
dia++;
i++;
}
}
</code></pre>
|
[
{
"answer_id": 170069,
"author": "extraneon",
"author_id": 24582,
"author_profile": "https://Stackoverflow.com/users/24582",
"pm_score": 3,
"selected": true,
"text": "public class Main extends PApplet\n{\n ...\n\n int currentColor = gray;\n\n public Main(){}\n\n ...\n\n public void draw()\n {\n if( i % 11 == 0 )\n currentColor = green;\n else if( i % 13 == 0 )\n currentColor = blue;\n else if( i % 17 == 0 )\n currentColor = pink;\n else {\n // Use current color\n } \n\n fill(currentColor);\n\n ...\n}\n else if ( i % 19 ) {\n currentColor = gray;\n }\n"
},
{
"answer_id": 221188,
"author": "razong",
"author_id": 29885,
"author_profile": "https://Stackoverflow.com/users/29885",
"pm_score": 0,
"selected": false,
"text": "stroke(255);\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13293/"
] |
165,355
|
<p>I'm trying to produce just the day number in a WPF text block, without leading zeroes and without extra space padding (which throws off the layout). The first produces the day number with a space, the second produces the entire date. According to the <a href="http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx" rel="nofollow noreferrer">docs</a>, 'd' should produce the day (1-31).</p>
<pre><code>string.Format("{0:d }", DateTime.Today);
string.Format("{0:d}", DateTime.Today);
</code></pre>
<p>UPDATE:Adding % is indeed the trick. Appropriate docs <a href="http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx#UsingSingleSpecifiers" rel="nofollow noreferrer">here</a>.</p>
|
[
{
"answer_id": 165382,
"author": "Jon Limjap",
"author_id": 372,
"author_profile": "https://Stackoverflow.com/users/372",
"pm_score": 0,
"selected": false,
"text": "{0:d} string.Format(\"{0}\", DateTime.Today.ToString(\"d \", CultureInfo.InvariantCulture));\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18482/"
] |
165,365
|
<p>I am having fickle of problem in Oracle 9i</p>
<p>select 1"FirstColumn" from dual;</p>
<p>Oracle throwing error while executing above query. ORA-03001: unimplemented feature in my Production server.</p>
<p>The Same query is working fine in my Validation server. Both servers are with Oracle 9i</p>
<p>Any one have Idea what's wrong...? Is this something configurable item in Oracle server.</p>
|
[
{
"answer_id": 165616,
"author": "Doug Porter",
"author_id": 4311,
"author_profile": "https://Stackoverflow.com/users/4311",
"pm_score": 1,
"selected": false,
"text": "select 1 as \"FirstColumn\" from dual;\n select * from v$version;\n"
},
{
"answer_id": 166288,
"author": "borjab",
"author_id": 16206,
"author_profile": "https://Stackoverflow.com/users/16206",
"pm_score": 2,
"selected": false,
"text": " SELECT 1 AS \"'FirstColumn'\" FROM dual;\n"
},
{
"answer_id": 167704,
"author": "Nick Pierpoint",
"author_id": 4003,
"author_profile": "https://Stackoverflow.com/users/4003",
"pm_score": 0,
"selected": false,
"text": "select 1\"FirstColumn\" from dual\n"
},
{
"answer_id": 175919,
"author": "Dylan",
"author_id": 4580,
"author_profile": "https://Stackoverflow.com/users/4580",
"pm_score": 0,
"selected": false,
"text": "SELECT 1 \"FirstColumn\" from dual;\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165365",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
165,401
|
<p>I'm looking for a way to validate the SQL schema on a production DB after updating an application version. If the application does not match the DB schema version, there should be a way to warn the user and list the changes needed.</p>
<p>Is there a tool or a framework (to use programatically) with built-in features to do that?
Or is there some simple algorithm to run this comparison?</p>
<blockquote>
<p><strong>Update:</strong> Red gate lists "from $395". Anything free? Or more foolproof than just keeping the version number?</p>
</blockquote>
|
[
{
"answer_id": 165411,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 0,
"selected": false,
"text": "CREATE TABLE version (\n version VARCHAR(255) NOT NULL\n)\nINSERT INTO version VALUES ('v1.0');\n"
},
{
"answer_id": 167208,
"author": "AJ.",
"author_id": 7211,
"author_profile": "https://Stackoverflow.com/users/7211",
"pm_score": 6,
"selected": true,
"text": "/* get list of objects in the database */\nSELECT name, \n type \nFROM sysobjects\nORDER BY type, name\n\n/* get list of columns in each table / parameters for each stored procedure */\nSELECT so.name, \n so.type, \n sc.name, \n sc.number, \n sc.colid, \n sc.status, \n sc.type, \n sc.length, \n sc.usertype , \n sc.scale \nFROM sysobjects so , \n syscolumns sc \nWHERE so.id = sc.id \nORDER BY so.type, so.name, sc.name\n\n/* get definition of each stored procedure */\nSELECT so.name, \n so.type, \n sc.number, \n sc.text \nFROM sysobjects so , \n syscomments sc \nWHERE so.id = sc.id \nORDER BY so.type, so.name, sc.number \n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1363/"
] |
165,402
|
<p>I need help on this following aspx code</p>
<p>aspx Code:</p>
<pre><code><asp:Label ID ="lblName" runat ="server" Text ="Name"></asp:Label>
<asp:TextBox ID ="txtName" runat ="server"></asp:TextBox>
</code></pre>
<p>Consider this is my aspx page content. I am going to populate the values for the TextBox only after the postback from server. But the label is also posting to the server (<code>runat="server"</code>) even though it's not necessary. Should I write my code like this to save time from server with less load.</p>
<p>Corrected Code:</p>
<pre><code><label id ="lblNames">Name</label>
<asp:TextBox ID ="txtName" runat ="server"></asp:TextBox>
</code></pre>
<p>Only my server control will send to the server for postback and not my HTML control which has a static value.</p>
<p>Please suggest whether this is the correct way of coding.</p>
|
[
{
"answer_id": 165409,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 3,
"selected": true,
"text": "runat='server' <label> lblNames"
},
{
"answer_id": 165469,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 0,
"selected": false,
"text": "<span>"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22162/"
] |
165,404
|
<p>I'm looking for some good references for learning how to model 2d physics in games. I am <strong>not</strong> looking for a library to do it for me - I want to think and learn, not blindly use someone else's work.</p>
<p>I've done a good bit of Googling, and while I've found a few tutorials on GameDev, etc., I find their tutorials hard to understand because they are either written poorly, or assume a level of mathematical understanding that I don't yet possess.</p>
<p>For specifics - I'm looking for how to model a top-down 2d game, sort of like a tank combat game - and I want to accurately model (among other things) acceleration and speed, heat buildup of 'components,' collisions between models and level boundaries, and missile-type weapons.</p>
<p>Websites, recommended books, blogs, code examples - all are welcome if they will aid understanding. I'm considering using C# and F# to build my game, so code examples in either of those languages would be great - but don't let language stop you from posting a good link. =)</p>
<p><strong>Edit</strong>: I don't mean that I don't understand math - it's more the case that I don't know what I need to know in order to understand the systems involved, and don't really know how to find the resources that will teach me in an understandable way.</p>
|
[
{
"answer_id": 168098,
"author": "Chris Smith",
"author_id": 322,
"author_profile": "https://Stackoverflow.com/users/322",
"pm_score": 2,
"selected": false,
"text": "let distance : float<meters> = gravity * 3.0<seconds>\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16942/"
] |
165,424
|
<p>I have a ListBox which until recently was displaying a flat list of items. I was able to use myList.ItemContainerGenerator.ConainerFromItem(thing) to retrieve the ListBoxItem hosting "thing" in the list.</p>
<p>This week I've modified the ListBox slightly in that the CollectionViewSource that it binds to for its items has grouping enabled. Now the items within the ListBox are grouped underneath nice headers.</p>
<p>However, since doing this, ItemContainerGenerator.ContainerFromItem has stopped working - it returns null even for items I know are in the ListBox. Heck - ContainerFromIndex(0) is returning null even when the ListBox is populated with many items!</p>
<p>How do I retrieve a ListBoxItem from a ListBox that's displaying grouped items?</p>
<p>Edit: Here's the XAML and code-behind for a trimmed-down example. This raises a NullReferenceException because ContainerFromIndex(1) is returning null even though there are four items in the list.</p>
<p>XAML:</p>
<pre><code><Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
Title="Window1">
<Window.Resources>
<XmlDataProvider x:Key="myTasks" XPath="Tasks/Task">
<x:XData>
<Tasks xmlns="">
<Task Name="Groceries" Type="Home"/>
<Task Name="Cleaning" Type="Home"/>
<Task Name="Coding" Type="Work"/>
<Task Name="Meetings" Type="Work"/>
</Tasks>
</x:XData>
</XmlDataProvider>
<CollectionViewSource x:Key="mySortedTasks" Source="{StaticResource myTasks}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="@Type" />
<scm:SortDescription PropertyName="@Name" />
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="@Type" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Window.Resources>
<ListBox
x:Name="listBox1"
ItemsSource="{Binding Source={StaticResource mySortedTasks}}"
DisplayMemberPath="@Name"
>
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
</Window>
</code></pre>
<p>CS:</p>
<pre><code>public Window1()
{
InitializeComponent();
listBox1.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
}
void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
{
if (listBox1.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
{
listBox1.ItemContainerGenerator.StatusChanged -= ItemContainerGenerator_StatusChanged;
var i = listBox1.ItemContainerGenerator.ContainerFromIndex(1) as ListBoxItem;
// select and keyboard-focus the second item
i.IsSelected = true;
i.Focus();
}
}
</code></pre>
|
[
{
"answer_id": 169123,
"author": "David Schmitt",
"author_id": 4918,
"author_profile": "https://Stackoverflow.com/users/4918",
"pm_score": 6,
"selected": true,
"text": "ItemsGenerator.StatusChanged void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)\n {\n if (listBox1.ItemContainerGenerator.Status\n == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)\n {\n listBox1.ItemContainerGenerator.StatusChanged\n -= ItemContainerGenerator_StatusChanged;\n Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Input,\n new Action(DelayedAction));\n }\n }\n\n void DelayedAction()\n {\n var i = listBox1.ItemContainerGenerator.ContainerFromIndex(1) as ListBoxItem;\n\n // select and keyboard-focus the second item\n i.IsSelected = true;\n i.Focus();\n }\n"
},
{
"answer_id": 23608785,
"author": "D.Kempkes",
"author_id": 2459350,
"author_profile": "https://Stackoverflow.com/users/2459350",
"pm_score": 2,
"selected": false,
"text": "public class ListBoxExtenders : DependencyObject\n{\n public static readonly DependencyProperty AutoScrollToCurrentItemProperty = DependencyProperty.RegisterAttached(\"AutoScrollToCurrentItem\", typeof(bool), typeof(ListBoxExtenders), new UIPropertyMetadata(default(bool), OnAutoScrollToCurrentItemChanged));\n\n public static bool GetAutoScrollToCurrentItem(DependencyObject obj)\n {\n return (bool)obj.GetValue(AutoScrollToSelectedItemProperty);\n }\n\n public static void SetAutoScrollToCurrentItem(DependencyObject obj, bool value)\n {\n obj.SetValue(AutoScrollToSelectedItemProperty, value);\n }\n\n public static void OnAutoScrollToCurrentItemChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)\n {\n var listBox = s as ListBox;\n if (listBox != null)\n {\n var listBoxItems = listBox.Items;\n if (listBoxItems != null)\n {\n var newValue = (bool)e.NewValue;\n\n var autoScrollToCurrentItemWorker = new EventHandler((s1, e2) => OnAutoScrollToCurrentItem(listBox, listBox.Items.CurrentPosition));\n\n if (newValue)\n listBoxItems.CurrentChanged += autoScrollToCurrentItemWorker;\n else\n listBoxItems.CurrentChanged -= autoScrollToCurrentItemWorker;\n }\n }\n }\n\n public static void OnAutoScrollToCurrentItem(ListBox listBox, int index)\n {\n if (listBox != null && listBox.Items != null && listBox.Items.Count > index && index >= 0)\n listBox.ScrollIntoView(listBox.Items[index]);\n }\n\n}\n <ListBox IsSynchronizedWithCurrentItem=\"True\" extenders:ListBoxExtenders.AutoScrollToCurrentItem=\"True\" ..../>\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165424",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/615/"
] |
165,443
|
<p>I have a "span" element inside a "table" "td" element. The span tag has a Title.</p>
<p>I want to get the title of that span tag and pull it out to make it the "mouseover" tip for the "td" element.</p>
<p>For example:</p>
<p>I want to turn this:</p>
<pre><code><td>
<a href="#"><span id="test" title="Acres for each province">Acres</span></a>
</td>
</code></pre>
<p>Into this:</p>
<pre><code><td onmouseover="tip(Acres for each province)">
<a href="#"><span id="test">Acres</span></a>
</td>
</code></pre>
<p><strong>EDIT:</strong> I don't think you guys understand. I am trying to put the onmouseover function into the "td" tag. I am NOT trying to put it into the "span" tag.</p>
|
[
{
"answer_id": 165449,
"author": "John Boker",
"author_id": 2847,
"author_profile": "https://Stackoverflow.com/users/2847",
"pm_score": 1,
"selected": false,
"text": "$(\"span#test\").mouseover( function () {\n tip($(this).attr(\"title\"));\n}\n"
},
{
"answer_id": 165450,
"author": "Nick Sergeant",
"author_id": 22468,
"author_profile": "https://Stackoverflow.com/users/22468",
"pm_score": -1,
"selected": false,
"text": "$('#test').attr('title')\n"
},
{
"answer_id": 165532,
"author": "Bob Somers",
"author_id": 1384,
"author_profile": "https://Stackoverflow.com/users/1384",
"pm_score": 4,
"selected": true,
"text": "$(\"td\").each(function()\n{\n $(this).mouseover(function()\n {\n tip($(this).children(\"span\").attr(\"title\"));\n });\n});\n"
},
{
"answer_id": 165536,
"author": "Ricky",
"author_id": 653,
"author_profile": "https://Stackoverflow.com/users/653",
"pm_score": 0,
"selected": false,
"text": "// get each span with id = test\n$(\"span#test\").each(function(){\n var $this = $(this);\n // attach to mouseover event of the grandparent (td)\n $this.parent().parent().mouseover( function () {\n tip($this.attr(\"title\"));\n }\n);\n"
},
{
"answer_id": 172374,
"author": "matdumsa",
"author_id": 1775,
"author_profile": "https://Stackoverflow.com/users/1775",
"pm_score": 0,
"selected": false,
"text": "$(\"#yourTable\").find(\"td\").over(function()\n { generateTip($(this).find(\"span:first\").attr(\"title\") }\n , function() { removeTip() }\n)\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7644/"
] |
165,445
|
<p>I have a function that includes a file based on the string that gets passed to it i.e. the action variable from the query string. I use this for filtering purposes etc so people can't include files they shouldn't be able to and if the file doesn't exist a default file is loaded instead.
The problem is that when the function runs and includes the file scope, is lost because the include ran inside a function. This becomes a problem because I use a global configuration file, then I use specific configuration files for each module on the site.
The way I'm doing it at the moment is defining the variables I want to be able to use as global and then adding them into the top of the filtering function.</p>
<p>Is there any easier way to do this, i.e. by preserving scope when a function call is made or is there such a thing as PHP macros?</p>
<p><strong>Edit:</strong> Would it be better to use extract($_GLOBALS); inside my function call instead?</p>
<p><strong>Edit 2:</strong>
For anyone that cared. I realised I was over thinking the problem altogether and that instead of using a function I should just use an include, duh! That way I can keep my scope and have my cake too.</p>
|
[
{
"answer_id": 165448,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 3,
"selected": false,
"text": "// myInclude.php\n$x = \"abc\";\n\n// -----------------------\n// myRegularFile.php\n\nfunction doInclude() {\n include 'myInclude.php';\n}\n$x = \"A default value\";\ndoInclude();\necho $x; // should be \"abc\", but actually prints \"A default value\"\n global doInclude() // myInclude.php\n$includedVars['x'] = \"abc\";\n$includedVars['y'] = \"def\";\n\n// ------------------\n// myRegularFile.php\nfunction doInclude() {\n global $includedVars;\n include 'myInclude.php';\n // perhaps filter out any \"unexpected\" variables here if you want\n}\n\ndoInclude();\nextract($includedVars);\necho $x; // \"abc\"\necho $y; // \"def\"\n global $x = \"foo\";\nfunction wrong() {\n echo $x;\n}\nfunction right() {\n global $x;\n echo $x;\n}\n\nwrong(); // undefined variable $x\nright(); // \"foo\"\n"
},
{
"answer_id": 165555,
"author": "Bob Somers",
"author_id": 1384,
"author_profile": "https://Stackoverflow.com/users/1384",
"pm_score": 0,
"selected": false,
"text": "define('MY_CONFIG_PATH', '/home/jschmoe/myfiles/config.inc.php');\n"
},
{
"answer_id": 165805,
"author": "Grey Panther",
"author_id": 1265,
"author_profile": "https://Stackoverflow.com/users/1265",
"pm_score": 0,
"selected": false,
"text": "function do_include($foo) {\n if (is_valid($foo))\n include $foo;\n}\n\ndo_include(@$_GET['foo']);\n if (is_valid(@$_GET['foo']))\n include $_GET['foo'];\n"
},
{
"answer_id": 165976,
"author": "Ken",
"author_id": 20074,
"author_profile": "https://Stackoverflow.com/users/20074",
"pm_score": 0,
"selected": false,
"text": "return array(\n 'foo'=>'bar',\n 'x'=>23,\n 'y'=>12\n);\n $config = require('config.php');\nvar_dump($config);\n"
},
{
"answer_id": 178018,
"author": "troelskn",
"author_id": 18180,
"author_profile": "https://Stackoverflow.com/users/18180",
"pm_score": 0,
"selected": false,
"text": "function doInclude($file, $args = array()) {\n extract($args);\n include($file);\n}\n doInclude get_defined_vars doInclude('test.template.php', get_defined_vars());\n"
},
{
"answer_id": 2657542,
"author": "outis",
"author_id": 90527,
"author_profile": "https://Stackoverflow.com/users/90527",
"pm_score": 0,
"selected": false,
"text": "//inc.php\nglobal $cfg;\n$cfg['foo'] = bar;\n\n//index.php\nfunction get_cfg($cfgFile) {\n if (valid_cfg_file($cfgFile)) {\n include_once($cfgFile);\n }\n}\n...\nget_cfg('inc.php');\necho \"cfg[foo]: $cfg[foo]\\n\";\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11753/"
] |
165,455
|
<p>Just wondering why people like case sensitivity in a programming language? I'm not trying to start a flame war just curious thats all.<br>
Personally I have never really liked it because I find my productivity goes down when ever I have tried a language that has case sensitivity, mind you I am slowly warming up/getting used to it now that I'm using C# and F# alot more then I used to.</p>
<p>So why do you like it?</p>
<p>Cheers </p>
|
[
{
"answer_id": 165472,
"author": "Kristopher Johnson",
"author_id": 1175,
"author_profile": "https://Stackoverflow.com/users/1175",
"pm_score": 6,
"selected": true,
"text": "Foo foo = ... // \"Foo\" is a type, \"foo\" is a variable with that type\n"
},
{
"answer_id": 165480,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "foo Foo FOO FooBar fooBar foo_bar FOO_BAR"
},
{
"answer_id": 165512,
"author": "Bryan M.",
"author_id": 4636,
"author_profile": "https://Stackoverflow.com/users/4636",
"pm_score": 2,
"selected": false,
"text": "class Doohickey {\n\n public void doSomethingWith(string things) {\n print(things);\n }\n}\n Class DOOHICKEY {\n Public Void dosomethingwith(string Things) {\n Print(things);\n }\n} \n"
},
{
"answer_id": 165671,
"author": "Sundar R",
"author_id": 8127,
"author_profile": "https://Stackoverflow.com/users/8127",
"pm_score": 1,
"selected": false,
"text": "a A (list 'a 'b 'c) \n (A B C)\n"
},
{
"answer_id": 165691,
"author": "Ryan Lundy",
"author_id": 5486,
"author_profile": "https://Stackoverflow.com/users/5486",
"pm_score": 2,
"selected": false,
"text": "dim a as string\n Dim a As String\n"
},
{
"answer_id": 1747632,
"author": "Marc Climent",
"author_id": 58791,
"author_profile": "https://Stackoverflow.com/users/58791",
"pm_score": 0,
"selected": false,
"text": "foo foo Foo FOO FOo"
},
{
"answer_id": 4684017,
"author": "idbrii",
"author_id": 79125,
"author_profile": "https://Stackoverflow.com/users/79125",
"pm_score": 2,
"selected": false,
"text": "expertSexChange != expertsExchange\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6335/"
] |
165,458
|
<p>Which is the most correct code?</p>
<pre><code>if (HttpContext.Current.Response.Cookies[authCookieName] != null) {
HttpContext.Current.Response.Cookies[authCookieName].Value = "New Value";
}
</code></pre>
<p>or </p>
<pre><code>if (HttpContext.Current != null)
if (HttpContext.Current.Response != null)
if (HttpContext.Current.Response.Cookies != null)
if (HttpContext.Current.Response.Cookies[authCookieName] != null)
HttpContext.Current.Response.Cookies[authCookieName].Value = "New Value";
</code></pre>
|
[
{
"answer_id": 165468,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 0,
"selected": false,
"text": "Current Response Cookies Cookies[authCookieName] null"
},
{
"answer_id": 165476,
"author": "John Boker",
"author_id": 2847,
"author_profile": "https://Stackoverflow.com/users/2847",
"pm_score": 2,
"selected": false,
"text": "if(HttpContext.Current != null && \n HttpContext.Current.Response != null && \n HttpContext.Current.Response.Cookies != null && \n HttpContext.Current.Response.Cookies[authCookieName] != null) \n{\n // do your thing\n}\n"
},
{
"answer_id": 165565,
"author": "KristoferA",
"author_id": 11241,
"author_profile": "https://Stackoverflow.com/users/11241",
"pm_score": 3,
"selected": false,
"text": "private bool CheckSuspendersAndBelt()\n{\n try\n {\n //ensure that true is true...\n if (true == true)\n {\n //...and that false is false...\n if (false == false)\n {\n //...and that true and false are not equal...\n if (false != true)\n {\n //don't proceed if we don't have at least one processor\n if (System.Environment.ProcessorCount > 0)\n {\n //and if there is no system directory then something is wrong\n if (System.Environment.SystemDirectory != null)\n {\n //hopefully the code is running under some version of the CLR...\n if (System.Environment.Version != null)\n {\n //we don't want to proceed if we're not in a process...\n if (System.Diagnostics.Process.GetCurrentProcess() != null)\n {\n //and code running without a thread would not be good...\n if (System.Threading.Thread.CurrentThread != null)\n {\n //finally, make sure instantiating an object really results in an object...\n if (typeof(System.Object) == (new System.Object()).GetType())\n {\n //good to go\n return true;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n return false;\n }\n catch\n {\n return false;\n }\n}\n"
},
{
"answer_id": 165702,
"author": "Gordon Bell",
"author_id": 16473,
"author_profile": "https://Stackoverflow.com/users/16473",
"pm_score": 1,
"selected": false,
"text": "if (HttpContext.Current.Response.Cookies[authCookieName] != null) {\n HttpContext.Current.Response.Cookies[authCookieName].Value = \"New Value\";\n}\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24395/"
] |
165,466
|
<p>I think this is best asked in the form of a simple example. The following chunk of SQL causes a <em>"DB-Library Error:20049 Severity:4 Message:Data-conversion resulted in overflow"</em> message, but how come? </p>
<pre><code>declare @a numeric(18,6), @b numeric(18,6), @c numeric(18,6)
select @a = 1.000000, @b = 1.000000, @c = 1.000000
select @a/(@b/@c)
go
</code></pre>
<p>How is this any different to:</p>
<pre><code>select 1.000000/(1.000000/1.000000)
go
</code></pre>
<p>which works fine?</p>
|
[
{
"answer_id": 171863,
"author": "John Rudy",
"author_id": 14048,
"author_profile": "https://Stackoverflow.com/users/14048",
"pm_score": 3,
"selected": true,
"text": "SET ARITHABORT NUMERIC_TRUNCATION OFF\n SET ARITHABORT NUMERIC_TRUNCATION ON\n"
},
{
"answer_id": 32738583,
"author": "dumle",
"author_id": 2116173,
"author_profile": "https://Stackoverflow.com/users/2116173",
"pm_score": 0,
"selected": false,
"text": "declare @a numeric(6,3)\n\nselect 0.000 as thenumber into #test --indirect declare\n\nselect @a = ( select thenumber + 100 from #test )\n\nupdate #test set thenumber = @a\n\nselect * from #test\n Arithmetic overflow during implicit conversion of NUMERIC value '100.000' to a NUMERIC field .\n select 000.000 as thenumber into #test --this solved it\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165466",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1030/"
] |
165,474
|
<p>I have seen member functions programed both inside of the class they belong to and outside of the class with a function prototype inside of the class. I have only ever programmed using the first method, but was wondering if it is better practice to use the other or just personal preference?</p>
|
[
{
"answer_id": 165510,
"author": "Andrew Stein",
"author_id": 13029,
"author_profile": "https://Stackoverflow.com/users/13029",
"pm_score": 2,
"selected": false,
"text": "int getFoo() const { return _foo; }\n"
},
{
"answer_id": 165956,
"author": "SmacL",
"author_id": 22564,
"author_profile": "https://Stackoverflow.com/users/22564",
"pm_score": 1,
"selected": false,
"text": "virtual int MyFunc() {} // Does nothing in base class, override if needed\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165474",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20229/"
] |
165,488
|
<p>I am trying to install the starling gem on my Windows machine. But, whenever I try to install it I get this error:</p>
<pre><code>Building native extensions. This could take a while...
ERROR: Error installing starling:
ERROR: Failed to build gem native extension.
c:/ruby/bin/ruby.exe extconf.rb install starling -- --srcdir= c:\ruby-1.8.7-p72
checking for windows.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--srcdir=.
--curdir
--ruby=c:/ruby/bin/ruby
Gem files will remain installed in c:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0
.12.2 for inspection.
Results logged to c:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.12.2/ext/gem_mak
e.out
</code></pre>
<p>What do I need to install to provide the <code>windows.h</code> header?</p>
|
[
{
"answer_id": 167250,
"author": "Charles Roper",
"author_id": 1944,
"author_profile": "https://Stackoverflow.com/users/1944",
"pm_score": 3,
"selected": false,
"text": "$ gem install eventmachine --version=0.12.0\nSuccessfully installed eventmachine-0.12.0-x86-mswin32\n1 gem installed\nInstalling ri documentation for eventmachine-0.12.0-x86-mswin32...\nInstalling RDoc documentation for eventmachine-0.12.0-x86-mswin32... $ gem install starling\nSuccessfully installed ZenTest-3.10.0\nSuccessfully installed memcache-client-1.5.0\nSuccessfully installed SyslogLogger-1.4.0\nSuccessfully installed starling-0.9.8\n4 gems installed\nInstalling ri documentation for ZenTest-3.10.0...\nInstalling ri documentation for memcache-client-1.5.0...\nInstalling ri documentation for SyslogLogger-1.4.0...\nInstalling ri documentation for starling-0.9.8...\nInstalling RDoc documentation for ZenTest-3.10.0...\nInstalling RDoc documentation for memcache-client-1.5.0...\nInstalling RDoc documentation for SyslogLogger-1.4.0...\nInstalling RDoc documentation for starling-0.9.8... gem update"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5004/"
] |
165,495
|
<p>How can I detect mouse clicks regardless of the window the mouse is in?</p>
<p>Perferabliy in python, but if someone can explain it in any langauge I might be able to figure it out.</p>
<p>I found this on microsoft's site:
<a href="http://msdn.microsoft.com/en-us/library/ms645533(VS.85).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms645533(VS.85).aspx</a></p>
<p>But I don't see how I can detect or pick up the notifications listed.</p>
<p>Tried using pygame's pygame.mouse.get_pos() function as follows:</p>
<pre><code>import pygame
pygame.init()
while True:
print pygame.mouse.get_pos()
</code></pre>
<p>This just returns 0,0.
I'm not familiar with pygame, is something missing?</p>
<p>In anycase I'd prefer a method without the need to install a 3rd party module.
(other than pywin32 <a href="http://sourceforge.net/projects/pywin32/" rel="noreferrer">http://sourceforge.net/projects/pywin32/</a> )</p>
|
[
{
"answer_id": 166054,
"author": "Zebra North",
"author_id": 17440,
"author_profile": "https://Stackoverflow.com/users/17440",
"pm_score": 2,
"selected": false,
"text": "WM_LBUTTONDBLCLK CS_DBLCLKS"
},
{
"answer_id": 166144,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 2,
"selected": false,
"text": "self.HookMessage(self.OnMouseMove,win32con.WM_MOUSEMOVE)\n"
},
{
"answer_id": 168996,
"author": "efotinis",
"author_id": 12320,
"author_profile": "https://Stackoverflow.com/users/12320",
"pm_score": 6,
"selected": true,
"text": "import pyHook\nimport pythoncom\n\ndef onclick(event):\n print event.Position\n return True\n\nhm = pyHook.HookManager()\nhm.SubscribeMouseAllButtonsDown(onclick)\nhm.HookMouse()\npythoncom.PumpMessages()\nhm.UnhookMouse()\n"
},
{
"answer_id": 41930485,
"author": "Markacho",
"author_id": 6274340,
"author_profile": "https://Stackoverflow.com/users/6274340",
"pm_score": 4,
"selected": false,
"text": "# Code to check if left or right mouse buttons were pressed\nimport win32api\nimport time\n\nstate_left = win32api.GetKeyState(0x01) # Left button down = 0 or 1. Button up = -127 or -128\nstate_right = win32api.GetKeyState(0x02) # Right button down = 0 or 1. Button up = -127 or -128\n\nwhile True:\n a = win32api.GetKeyState(0x01)\n b = win32api.GetKeyState(0x02)\n\n if a != state_left: # Button state changed\n state_left = a\n print(a)\n if a < 0:\n print('Left Button Pressed')\n else:\n print('Left Button Released')\n\n if b != state_right: # Button state changed\n state_right = b\n print(b)\n if b < 0:\n print('Right Button Pressed')\n else:\n print('Right Button Released')\n time.sleep(0.001)\n"
},
{
"answer_id": 46596592,
"author": "diligar",
"author_id": 3571147,
"author_profile": "https://Stackoverflow.com/users/3571147",
"pm_score": 3,
"selected": false,
"text": "ctypes import ctypes\nimport time\n\ndef DetectClick(button, watchtime = 5):\n '''Waits watchtime seconds. Returns True on click, False otherwise'''\n if button in (1, '1', 'l', 'L', 'left', 'Left', 'LEFT'):\n bnum = 0x01\n elif button in (2, '2', 'r', 'R', 'right', 'Right', 'RIGHT'):\n bnum = 0x02\n\n start = time.time()\n while 1:\n if ctypes.windll.user32.GetKeyState(bnum) not in [0, 1]:\n # ^ this returns either 0 or 1 when button is not being held down\n return True\n elif time.time() - start >= watchtime:\n break\n time.sleep(0.001)\n return False\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24718/"
] |
165,496
|
<p>So i have a piece of assembly that needs to call a function with the fastcall calling convention on windows, but gcc doesn't (afaict) support it. GCC does provide the regparm attribute but that expects the first 3 parameters to be passed in eax, edx and ecx, whereas fastcall expects the first two parameters to be passed in ecx and edx.</p>
<p>I'm merely trying to avoid effectively duplicating a few code paths, so this isn't exactly critical, but it would be great if it were avoidable.</p>
|
[
{
"answer_id": 165528,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "CALL"
},
{
"answer_id": 165529,
"author": "ephemient",
"author_id": 20713,
"author_profile": "https://Stackoverflow.com/users/20713",
"pm_score": 5,
"selected": true,
"text": "fastcall __attribute__((fastcall))"
},
{
"answer_id": 10253546,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "#if defined(__GNUC__)\n #define MSFASTCALL __fastcall\n #define GCCFASTCALL \n#elif defined(_MSC_VER)\n #define MSFASTCALL\n #define GCCFASTCALL __attribute__((fastcall))\n#endif\n\nint MSFASTCALL magic() GCCFASTCALL;\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/784/"
] |
165,539
|
<p>Can the iPhone SDK take advantage of the iPhone's proximity sensors? If so, why hasn't anyone taken advantage of them? I could picture a few decent uses.</p>
<p>For example, in a racing game, you could put your finger on the proximity sensor to go instead of taking up screen real-estate with your thumb. Of course though, if this was your only option, then iPod touch users wouldn't be able to use the application.</p>
<p>Does the proximity sensor tell how close you are, or just that something is in front of it?</p>
|
[
{
"answer_id": 168561,
"author": "benzado",
"author_id": 10947,
"author_profile": "https://Stackoverflow.com/users/10947",
"pm_score": 5,
"selected": true,
"text": "proximityState"
},
{
"answer_id": 1088382,
"author": "Brian",
"author_id": 113538,
"author_profile": "https://Stackoverflow.com/users/113538",
"pm_score": 2,
"selected": false,
"text": "UIDevice proximityMonitoringEnabled"
},
{
"answer_id": 1163268,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;\n"
},
{
"answer_id": 7542403,
"author": "Ben Flynn",
"author_id": 449161,
"author_profile": "https://Stackoverflow.com/users/449161",
"pm_score": 3,
"selected": false,
"text": "device = [UIDevice currentDevice];\n\n// Turn on proximity monitoring\n[device setProximityMonitoringEnabled:YES];\n\n// To determine if proximity monitoring is available, attempt to enable it.\n// If the value of the proximityMonitoringEnabled property remains NO, proximity\n// monitoring is not available.\n\n// Detect whether device supports proximity monitoring\nproxySupported = [device isProximityMonitoringEnabled];\n\n// Register for proximity notifications\n[notificationCenter addObserver:self selector:@selector(proximityChanged:) name:UIDeviceProximityStateDidChangeNotification object:device];\n // Returns a BOOL, YES if device is proximate\n[device proximityState];\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165539",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13009/"
] |
165,551
|
<p>I would like to know if there is an easy way to detect if the text on the clipboard is in ISO 8859 or UTF-8 ?</p>
<p>Here is my current code:</p>
<pre><code> COleDataObject obj;
if (obj.AttachClipboard())
{
if (obj.IsDataAvailable(CF_TEXT))
{
HGLOBAL hmem = obj.GetGlobalData(CF_TEXT);
CMemFile sf((BYTE*) ::GlobalLock(hmem),(UINT) ::GlobalSize(hmem));
CString buffer;
LPSTR str = buffer.GetBufferSetLength((int)::GlobalSize(hmem));
sf.Read(str,(UINT) ::GlobalSize(hmem));
::GlobalUnlock(hmem);
//this is my string class
s->SetEncoding(ENCODING_8BIT);
s->SetString(buffer);
}
}
}
</code></pre>
|
[
{
"answer_id": 165570,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 2,
"selected": false,
"text": "Unicode Byte1 Byte2 Byte3 Byte4\nU+000000-U+00007F 0xxxxxxx\nU+000080-U+0007FF 110xxxxx 10xxxxxx\nU+000800-U+00FFFF 1110xxxx 10xxxxxx 10xxxxxx\nU+010000-U+10FFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165551",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13676/"
] |
165,556
|
<p>I have Windows Vista MCML app, and I need to figure out the current name of the file playing.</p>
<p>The Media Center SDK alludes to using MediaMetadata["Title"] to get this information, unfortunately this does not work with playlists (.wpl) files as there is no method for getting the position in the playlist. </p>
|
[
{
"answer_id": 197616,
"author": "Jason Stevenson",
"author_id": 13368,
"author_profile": "https://Stackoverflow.com/users/13368",
"pm_score": 0,
"selected": false,
"text": "MediaContext.GetProperty(TrackTitle)\n <music-title duration = \"2000\" x=\"69\" y=\"29\" width=\"187\" height=\"20\"/>\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165556",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17174/"
] |
165,571
|
<p>I have a list of times in a database column (representing visits to a website).</p>
<p>I need to group them in intervals and then get a 'cumulative frequency' table of those dates.</p>
<p>For instance I might have:</p>
<pre><code>9:01
9:04
9:11
9:13
9:22
9:24
9:28
</code></pre>
<p>and i want to convert that into</p>
<pre><code>9:05 - 2
9:15 - 4
9:25 - 6
9:30 - 7
</code></pre>
<p>How can I do that? Can i even easily achieve this in SQL? I can quite easily do it in C#</p>
|
[
{
"answer_id": 165610,
"author": "ephemient",
"author_id": 20713,
"author_profile": "https://Stackoverflow.com/users/20713",
"pm_score": 1,
"selected": false,
"text": "periods SELECT periods.name, count(time)\n FROM periods, times\n WHERE period.start <= times.time\n AND times.time < period.end\n GROUP BY periods.name\n"
},
{
"answer_id": 165613,
"author": "Ron Savage",
"author_id": 12476,
"author_profile": "https://Stackoverflow.com/users/12476",
"pm_score": 2,
"selected": false,
"text": " create table #myDates\n (\n myDate datetime\n );\n go\n\n insert into #myDates values ('10/02/2008 09:01:23');\n insert into #myDates values ('10/02/2008 09:03:23');\n insert into #myDates values ('10/02/2008 09:05:23');\n insert into #myDates values ('10/02/2008 09:07:23');\n insert into #myDates values ('10/02/2008 09:11:23');\n insert into #myDates values ('10/02/2008 09:14:23');\n insert into #myDates values ('10/02/2008 09:19:23');\n insert into #myDates values ('10/02/2008 09:21:23');\n insert into #myDates values ('10/02/2008 09:21:23');\n insert into #myDates values ('10/02/2008 09:21:23');\n insert into #myDates values ('10/02/2008 09:21:23');\n insert into #myDates values ('10/02/2008 09:21:23');\n insert into #myDates values ('10/02/2008 09:26:23');\n insert into #myDates values ('10/02/2008 09:27:23');\n insert into #myDates values ('10/02/2008 09:29:23');\n go\n\n declare @interval int;\n set @interval = 10;\n\n select\n convert(varchar(5), dateadd(minute,@interval - datepart(minute, myDate) % @interval, myDate), 108) timeGroup,\n count(*)\n from\n #myDates\n group by\n convert(varchar(5), dateadd(minute,@interval - datepart(minute, myDate) % @interval, myDate), 108)\n\nretuns:\n\ntimeGroup \n--------- ----------- \n09:10 4 \n09:20 3 \n09:30 8 \n"
},
{
"answer_id": 165618,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 0,
"selected": false,
"text": "CREATE TABLE [dbo].[stackoverflow_165571](\n [visit] [datetime] NOT NULL\n) ON [PRIMARY]\nGO\n\n;WITH buckets AS (\n SELECT dateadd(mi, (1 + datediff(mi, 0, visit - 1 - dateadd(dd, 0, datediff(dd, 0, visit))) / 5) * 5, 0) AS visit_bucket\n ,COUNT(*) AS visit_count\n FROM stackoverflow_165571\n GROUP BY dateadd(mi, (1 + datediff(mi, 0, visit - 1 - dateadd(dd, 0, datediff(dd, 0, visit))) / 5) * 5, 0)\n)\nSELECT LEFT(CONVERT(varchar, l.visit_bucket, 8), 5) + ' - ' + CONVERT(varchar, SUM(r.visit_count))\nFROM buckets l\nLEFT JOIN buckets r\n ON r.visit_bucket <= l.visit_bucket\nGROUP BY l.visit_bucket\nORDER BY l.visit_bucket\n"
},
{
"answer_id": 165631,
"author": "ManiacZX",
"author_id": 18148,
"author_profile": "https://Stackoverflow.com/users/18148",
"pm_score": 1,
"selected": false,
"text": "time_entry.time_entry\n-----------------------\n2008-10-02 09:01:00.000\n2008-10-02 09:04:00.000\n2008-10-02 09:11:00.000\n2008-10-02 09:13:00.000\n2008-10-02 09:22:00.000\n2008-10-02 09:24:00.000\n2008-10-02 09:28:00.000\n\ntime_interval.time_end\n-----------------------\n2008-10-02 09:05:00.000\n2008-10-02 09:15:00.000\n2008-10-02 09:25:00.000\n2008-10-02 09:30:00.000\n\nSELECT \n ti.time_end, \n COUNT(*) AS 'interval_total' \nFROM time_interval ti\nINNER JOIN time_entry te\n ON te.time_entry < ti.time_end\nGROUP BY ti.time_end;\n\n\ntime_end interval_total\n----------------------- -------------\n2008-10-02 09:05:00.000 2\n2008-10-02 09:15:00.000 4\n2008-10-02 09:25:00.000 6\n2008-10-02 09:30:00.000 7\n SELECT \n ti.time_end, \n COUNT(*) AS 'interval_total' \nFROM time_interval ti\nINNER JOIN time_entry te\n ON te.time_entry >= ti.time_start\n AND te.time_entry < ti.time_end\nGROUP BY ti.time_end;\n"
},
{
"answer_id": 165638,
"author": "KristoferA",
"author_id": 11241,
"author_profile": "https://Stackoverflow.com/users/11241",
"pm_score": 3,
"selected": false,
"text": "create table accu_times (time_val datetime not null, constraint pk_accu_times primary key (time_val));\ngo\n\ninsert into accu_times values ('9:01');\ninsert into accu_times values ('9:05');\ninsert into accu_times values ('9:11');\ninsert into accu_times values ('9:13');\ninsert into accu_times values ('9:22');\ninsert into accu_times values ('9:24');\ninsert into accu_times values ('9:28'); \ngo\n\nselect rounded_time,\n (\n select count(*)\n from accu_times as at2\n where at2.time_val <= rt.rounded_time\n ) as accu_count\nfrom (\nselect distinct\n dateadd(minute, round((datepart(minute, at.time_val) + 2)*2, -1)/2,\n dateadd(hour, datepart(hour, at.time_val), 0)\n ) as rounded_time\nfrom accu_times as at\n) as rt\ngo\n\ndrop table accu_times\n rounded_time accu_count\n----------------------- -----------\n1900-01-01 09:05:00.000 2\n1900-01-01 09:15:00.000 4\n1900-01-01 09:25:00.000 6\n1900-01-01 09:30:00.000 7\n"
},
{
"answer_id": 166534,
"author": "dland",
"author_id": 18625,
"author_profile": "https://Stackoverflow.com/users/18625",
"pm_score": 2,
"selected": false,
"text": "select sec_to_time(floor(time_to_sec(d)/300)*300), count(*)\nfrom d\ngroup by sec_to_time(floor(time_to_sec(d)/300)*300)\n +----------+----------+\n| i | count(*) |\n+----------+----------+\n| 09:00:00 | 1 |\n| 09:05:00 | 3 |\n| 09:10:00 | 1 |\n| 09:15:00 | 1 |\n| 09:20:00 | 6 |\n| 09:25:00 | 2 |\n| 09:30:00 | 1 |\n+----------+----------+\n create table d (\n d datetime\n);\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24727/"
] |
165,595
|
<p>I have a Flex app that does a a fair amount of network traffic, it uses ExternalInterface to make some javascript calls (for SCORM), it loads XML files, images, video, audio and it has a series of modules that it could be loading at some point...</p>
<p>So the problem is - we now have a requirement where the user needs to run this content locally on a machine that is not connected to the internet (which means they can't connect to Adobe's site to change their security settings.) As you can imagine, when the user doubles clicks on the html page to launch this thing, they are greeted with a security warning that the swf is trying to communicate with another domain other than the one it's in. We can't wrap it in an exe or an AIR app so I unless there is some way to tweak some obscure security settings we may be hosed. Any idea's?</p>
|
[
{
"answer_id": 165680,
"author": "jdecuyper",
"author_id": 296,
"author_profile": "https://Stackoverflow.com/users/296",
"pm_score": -1,
"selected": false,
"text": "System.security.allowDomain(\"www.yourdomain.com\");\n"
},
{
"answer_id": 198038,
"author": "davr",
"author_id": 14569,
"author_profile": "https://Stackoverflow.com/users/14569",
"pm_score": 4,
"selected": true,
"text": "C:\\Program Files\\MyCompany\\CoolApp\nC:\\Program Files\\MyCompany\\OtherApp\\Main.swf\n System.security.sandboxType Security.sandboxType localTrusted"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3435/"
] |
165,603
|
<p>I was wondering if there was a way to get at the raw HTTP request data in PHP running on apache that doesn't involve using any additional extensions. I've seen the <a href="http://au2.php.net/http" rel="noreferrer">HTTP</a> functions in the manual, but I don't have the option of installing an extension in my environment.</p>
<p>While I can access the information from $_SERVER, I would like to see the raw request exactly as it was sent to the server. PHP munges the header names to suit its own array key style, for eg. Some-Test-Header becomes HTTP_X_SOME_TEST_HEADER. This is not what I need.</p>
|
[
{
"answer_id": 165623,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 4,
"selected": true,
"text": "$_SERVER print_r($_SERVER);\n foreach(getallheaders() as $key=>$value) {\n print $key.': '.$value.\"<br />\";\n}\n"
},
{
"answer_id": 165647,
"author": "Bretticus",
"author_id": 411075,
"author_profile": "https://Stackoverflow.com/users/411075",
"pm_score": 4,
"selected": false,
"text": "$raw_post = file_get_contents(\"php://input\"); \n"
},
{
"answer_id": 36272667,
"author": "tim",
"author_id": 1135440,
"author_profile": "https://Stackoverflow.com/users/1135440",
"pm_score": 2,
"selected": false,
"text": " $request = $_SERVER['SERVER_PROTOCOL'] .' '. $_SERVER['REQUEST_METHOD'] .' '. $_SERVER['REQUEST_URI'] . PHP_EOL;\n\n foreach (getallheaders() as $key => $value) {\n $request .= trim($key) .': '. trim($value) . PHP_EOL;\n }\n\n $request .= PHP_EOL . file_get_contents('php://input');\n\n echo $request;\n"
},
{
"answer_id": 70671519,
"author": "Sanjai Unnikrishnan",
"author_id": 7766293,
"author_profile": "https://Stackoverflow.com/users/7766293",
"pm_score": 0,
"selected": false,
"text": "GET /\nhost: domain.com;\nall-other-headers: <its-value>;\nrequest-content: <as-per-content-type>\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15004/"
] |
165,637
|
<p>Whenever I use the signal/slot editor dialog box, I have to choose from the existing list of slots. So the question is how do I create a custom named slot?</p>
|
[
{
"answer_id": 165921,
"author": "Pierre",
"author_id": 24449,
"author_profile": "https://Stackoverflow.com/users/24449",
"pm_score": 2,
"selected": false,
"text": "QPushButton QWidget"
},
{
"answer_id": 444608,
"author": "Henrik Hartz",
"author_id": 50830,
"author_profile": "https://Stackoverflow.com/users/50830",
"pm_score": 2,
"selected": false,
"text": "void on_objectName_signal() {\n// slot code here, where objectname is the Qt Designer object name\n// and the signal is the emission\n}\n"
},
{
"answer_id": 12794239,
"author": "James Dalton",
"author_id": 1248790,
"author_profile": "https://Stackoverflow.com/users/1248790",
"pm_score": 2,
"selected": false,
"text": "public slots:\n void example();\n void MainWindow::example() {\n <code>\n}\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24560/"
] |
165,648
|
<p>How can I display a calendar control (date picker) in Oracle forms 9/10?</p>
|
[
{
"answer_id": 165921,
"author": "Pierre",
"author_id": 24449,
"author_profile": "https://Stackoverflow.com/users/24449",
"pm_score": 2,
"selected": false,
"text": "QPushButton QWidget"
},
{
"answer_id": 444608,
"author": "Henrik Hartz",
"author_id": 50830,
"author_profile": "https://Stackoverflow.com/users/50830",
"pm_score": 2,
"selected": false,
"text": "void on_objectName_signal() {\n// slot code here, where objectname is the Qt Designer object name\n// and the signal is the emission\n}\n"
},
{
"answer_id": 12794239,
"author": "James Dalton",
"author_id": 1248790,
"author_profile": "https://Stackoverflow.com/users/1248790",
"pm_score": 2,
"selected": false,
"text": "public slots:\n void example();\n void MainWindow::example() {\n <code>\n}\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10557/"
] |
165,650
|
<p>I need to add a tooltip/alt to a "td" element inside of my tables with jquery.</p>
<p>Can someone help me out?</p>
<p>I tried:</p>
<pre><code>var tTip ="Hello world";
$(this).attr("onmouseover", tip(tTip));
</code></pre>
<p>where I have verified that I am using the "td" as "this".</p>
<p>**Edit:**I am able to capture the "td" element through using the "alert" command and it worked. So for some reason the "tip" function doesn't work. Anyone know why this would be?</p>
|
[
{
"answer_id": 165651,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 5,
"selected": false,
"text": "$(this).mouseover(function() {\n tip(tTip);\n});\n title <table id=\"myTable\">\n <tbody>\n <tr>\n <td title=\"Tip 1\">Cell 1</td>\n <td title=\"Tip 2\">Cell 2</td>\n </tr>\n </tbody>\n</table>\n $('#myTable td[title]')\n .hover(function() {\n showTooltip($(this));\n }, function() {\n hideTooltip();\n })\n;\n\nfunction showTooltip($el) {\n // insert code here to position your tooltip element (which i'll call $tip)\n $tip.html($el.attr('title'));\n}\nfunction hideTooltip() {\n $tip.hide();\n}\n"
},
{
"answer_id": 165654,
"author": "John Boker",
"author_id": 2847,
"author_profile": "https://Stackoverflow.com/users/2847",
"pm_score": 1,
"selected": false,
"text": "var tTip =\"Hello world\";\n$(this).mouseover( function() { tip(tTip); });\n"
},
{
"answer_id": 2635582,
"author": "Avi",
"author_id": 316255,
"author_profile": "https://Stackoverflow.com/users/316255",
"pm_score": 1,
"selected": false,
"text": "$('#grdList tr td:nth-child(5)').each(function(i) {\n if (i > 0) { //skip header\n var sContent = $(this).text();\n $(this).attr(\"title\", $(this).html());\n if (sContent.length > 20) {\n $(this).text(sContent.substring(0,20) + '...');\n }\n }\n});\n"
},
{
"answer_id": 2635606,
"author": "Avi",
"author_id": 316255,
"author_profile": "https://Stackoverflow.com/users/316255",
"pm_score": 2,
"selected": false,
"text": "$('#grdList tr td:nth-child(5)').each(function(i) {\n if (i > 0) { //skip header\n var sContent = $(this).text();\n $(this).attr(\"title\", $(this).html());\n if (sContent.length > 20) {\n $(this).text(sContent.substring(0,20) + '...');\n }\n }\n});\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7644/"
] |
165,699
|
<p>I am analyzing a .dmp file that was created and I have a call stack which gives me a lot of info. But I'd like to double click on the call stack and have it bring me to the source code. </p>
<p>I can right click on the call stack and select symbol settings.. where I can put the location to the PDB. But there is no option for the source code directory.</p>
|
[
{
"answer_id": 169685,
"author": "Andy Stevenson",
"author_id": 9734,
"author_profile": "https://Stackoverflow.com/users/9734",
"pm_score": 2,
"selected": false,
"text": "http://msdl.microsoft.com/download/symbols\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3153/"
] |
165,713
|
<p>I need a function to return a suffix for days when displaying text like the "<code>th</code>" in "<code>Wednesday June 5th, 2008</code>".</p>
<p>It only need work for the numbers 1 through 31 (no error checking required) and English.</p>
|
[
{
"answer_id": 165714,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 3,
"selected": false,
"text": "char *makeDaySuffix (unsigned int day) {\n //if ((day < 1) || (day > 31)) return \"\";\n switch (day) {\n case 1: case 21: case 31: return \"st\";\n case 2: case 22: return \"nd\";\n case 3: case 23: return \"rd\";\n }\n return \"th\";\n}\n char *makeDaySuffix (unsigned int day) {\n static const char * const suffix[] = {\n \"st\",\"nd\",\"rd\",\"th\",\"th\",\"th\",\"th\",\"th\",\"th\",\"th\",\n \"th\",\"th\",\"th\",\"th\",\"th\",\"th\",\"th\",\"th\",\"th\",\"th\"\n \"st\",\"nd\",\"rd\",\"th\",\"th\",\"th\",\"th\",\"th\",\"th\",\"th\"\n \"st\"\n };\n //if ((day < 1) || (day > 31)) return \"\";\n return suffix[day-1];\n}\n"
},
{
"answer_id": 165745,
"author": "Adam Pierce",
"author_id": 5324,
"author_profile": "https://Stackoverflow.com/users/5324",
"pm_score": 4,
"selected": true,
"text": "static const char *daySuffixLookup[] = { \"th\",\"st\",\"nd\",\"rd\",\"th\",\n \"th\",\"th\",\"th\",\"th\",\"th\" };\n\nconst char *daySuffix(int n)\n{\n if(n % 100 >= 11 && n % 100 <= 13)\n return \"th\";\n\n return daySuffixLookup[n % 10];\n}\n"
},
{
"answer_id": 165882,
"author": "Milan Babuškov",
"author_id": 14690,
"author_profile": "https://Stackoverflow.com/users/14690",
"pm_score": 2,
"selected": false,
"text": "const char *getDaySuffix(int day) {\n if (day%100 > 10 && day%100 < 14)\n return \"th\";\n switch (day%10) {\n case 1: return \"st\";\n case 2: return \"nd\";\n case 3: return \"rd\";\n default: return \"th\";\n };\n}\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14860/"
] |
165,719
|
<p>Could you please explain what the practical usage is for the <code>internal</code> keyword in C#?</p>
<p>I know that the <code>internal</code> modifier limits access to the current assembly, but when and in which circumstance should I use it?</p>
|
[
{
"answer_id": 165724,
"author": "yfeldblum",
"author_id": 12349,
"author_profile": "https://Stackoverflow.com/users/12349",
"pm_score": -1,
"selected": false,
"text": "public class DangerousClass {\n public void SafeMethod() { }\n internal void UpdateGlobalStateInSomeBizarreWay() { }\n}\n"
},
{
"answer_id": 165728,
"author": "Ash",
"author_id": 5023,
"author_profile": "https://Stackoverflow.com/users/5023",
"pm_score": 10,
"selected": true,
"text": "InternalsVisibleTo"
},
{
"answer_id": 166664,
"author": "Keith Williams",
"author_id": 20376,
"author_profile": "https://Stackoverflow.com/users/20376",
"pm_score": 2,
"selected": false,
"text": "Data.Client Biz.Client private Data.Client _client;\npublic int Id { get { return _client.Id; } set { _client.Id = value; } }\n internal Client(Data.Client client) {\n this._client = client;\n}\n internal"
},
{
"answer_id": 3016148,
"author": "Fredrik Mörk",
"author_id": 93623,
"author_profile": "https://Stackoverflow.com/users/93623",
"pm_score": 2,
"selected": false,
"text": "internal internal internal public private"
},
{
"answer_id": 3016160,
"author": "Matt Davis",
"author_id": 51170,
"author_profile": "https://Stackoverflow.com/users/51170",
"pm_score": 1,
"selected": false,
"text": "public internal Big_Important_Class internal internal"
},
{
"answer_id": 3019522,
"author": "Murad Mohd Zain",
"author_id": 362296,
"author_profile": "https://Stackoverflow.com/users/362296",
"pm_score": 3,
"selected": false,
"text": "// Assembly1.cs\n// compile with: /target:library\ninternal class BaseClass \n{\n public static int intM = 0;\n}\n\n// Assembly1_a.cs\n// compile with: /reference:Assembly1.dll\nclass TestAccess \n{\n static void Main()\n { \n BaseClass myBase = new BaseClass(); // CS0122\n }\n}\n // Assembly2.cs\n// compile with: /target:library\npublic class BaseClass \n{\n internal static int intM = 0;\n}\n\n// Assembly2_a.cs\n// compile with: /reference:Assembly1.dll\npublic class TestAccess \n{\n static void Main() \n { \n BaseClass myBase = new BaseClass(); // Ok.\n BaseClass.intM = 444; // CS0117\n }\n}\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11256/"
] |
165,720
|
<p>I'm looking for an easy way to debug RESTful services. For example, most webapps can be debugged using your average web browser. Unfortunately that same browser won't allow me to test HTTP PUT, DELETE, and to a certain degree even HTTP POST.</p>
<p>I am not looking to automate tests. I'd like to run new services through a quick sanity check, ideally without having to writing my own client.</p>
|
[
{
"answer_id": 166123,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 2,
"selected": false,
"text": "cURL"
},
{
"answer_id": 166269,
"author": "James Strachan",
"author_id": 2068211,
"author_profile": "https://Stackoverflow.com/users/2068211",
"pm_score": 0,
"selected": false,
"text": "clientConfig = new DefaultClientConfig();\nclient = Client.create(clientConfig);\n\nresource = client.resource(\"http://localhost:8080\");\n// lets get the XML as a String\nString text = resource(\"foo\").accept(\"application/xml\").get(String.class);\n"
},
{
"answer_id": 166842,
"author": "Avi Flax",
"author_id": 7012,
"author_profile": "https://Stackoverflow.com/users/7012",
"pm_score": 4,
"selected": false,
"text": "mailbox_post.cmd curl -v -X POST -u username -H 'Content-Type:application/xml' -d @mailbox_post.xml http://service/mailbox"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14731/"
] |
165,723
|
<p>I've noticed RAII has been getting lots of attention on Stackoverflow, but in my circles (mostly C++) RAII is so obvious its like asking what's a class or a destructor.</p>
<p>So I'm really curious if that's because I'm surrounded daily, by hard-core C++ programmers, and RAII just isn't that well known in general (including C++), or if all this questioning on Stackoverflow is due to the fact that I'm now in contact with programmers that didn't grow up with C++, and in other languages people just don't use/know about RAII?</p>
|
[
{
"answer_id": 165736,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 0,
"selected": false,
"text": "delete using IDisposable"
},
{
"answer_id": 165742,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 0,
"selected": false,
"text": "finally finally finally"
},
{
"answer_id": 165743,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 5,
"selected": true,
"text": "class StdioFile {\n FILE* file_;\n std::string mode_;\n\n static FILE* fcheck(FILE* stream) {\n if (!stream)\n throw std::runtime_error(\"Cannot open file\");\n return stream;\n }\n\n FILE* fdup() const {\n int dupfd(dup(fileno(file_)));\n if (dupfd == -1)\n throw std::runtime_error(\"Cannot dup file descriptor\");\n return fdopen(dupfd, mode_.c_str());\n }\n\npublic:\n StdioFile(char const* name, char const* mode)\n : file_(fcheck(fopen(name, mode))), mode_(mode)\n {\n }\n\n StdioFile(StdioFile const& rhs)\n : file_(fcheck(rhs.fdup())), mode_(rhs.mode_)\n {\n }\n\n ~StdioFile()\n {\n fclose(file_);\n }\n\n StdioFile& operator=(StdioFile const& rhs) {\n FILE* dupstr = fcheck(rhs.fdup());\n if (fclose(file_) == EOF) {\n fclose(dupstr); // XXX ignore failed close\n throw std::runtime_error(\"Cannot close stream\");\n }\n file_ = dupstr;\n return *this;\n }\n\n int\n read(std::vector<char>& buffer)\n {\n int result(fread(&buffer[0], 1, buffer.size(), file_));\n if (ferror(file_))\n throw std::runtime_error(strerror(errno));\n return result;\n }\n\n int\n write(std::vector<char> const& buffer)\n {\n int result(fwrite(&buffer[0], 1, buffer.size(), file_));\n if (ferror(file_))\n throw std::runtime_error(strerror(errno));\n return result;\n }\n};\n\nint\nmain(int argc, char** argv)\n{\n StdioFile file(argv[1], \"r\");\n std::vector<char> buffer(1024);\n while (int hasRead = file.read(buffer)) {\n // process hasRead bytes, then shift them off the buffer\n }\n}\n StdioFile try finally fclose main"
},
{
"answer_id": 165760,
"author": "wilhelmtell",
"author_id": 456,
"author_profile": "https://Stackoverflow.com/users/456",
"pm_score": 4,
"selected": false,
"text": "class OhMy {\npublic:\n OhMy() { p_ = new int[42]; jump(); } \n ~OhMy() { delete[] p_; }\n\nprivate:\n int* p_;\n\n void jump();\n};\n jump() p_ class Few {\npublic:\n Few() : v_(42) { jump(); } \n ~Few();\n\nprivate:\n std::vector<int> v_;\n\n void jump();\n};\n"
},
{
"answer_id": 165764,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 3,
"selected": false,
"text": "void someFunc()\n{\n StdioFile file(\"Plop\",\"r\");\n\n // use file\n}\n// File closed automatically even if this function exits via an exception.\n void someFunc()\n{\n // Assuming Java Like syntax;\n StdioFile file = new StdioFile(\"Plop\",\"r\");\n try\n {\n // use file\n }\n finally\n {\n // close file.\n file.close(); // \n // Using the finaliser is not enough as we can not garantee when\n // it will be called.\n }\n}\n"
},
{
"answer_id": 165991,
"author": "Pierre",
"author_id": 24449,
"author_profile": "https://Stackoverflow.com/users/24449",
"pm_score": 1,
"selected": false,
"text": "try {\n BufferedReader file = new BufferedReader(new FileReader(\"infilename\"));\n // do something with file\n}\nfinally {\n file.close();\n}\n File.open(\"foo.txt\") do | file |\n # do something with file\nend\n unwind-protect with-XXX (with-open-file (file \"foo.txt\")\n ;; do something with file\n)\n dynamic-wind with-XXXXX (with-input-from-file \"foo.txt\"\n (lambda ()\n ;; do something \n)\n try\n file = open(\"foo.txt\")\n # do something with file\nfinally:\n file.close()\n"
},
{
"answer_id": 166461,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 4,
"selected": false,
"text": "' WaitCursor.cls '\nPrivate m_OldCursor As MousePointerConstants\n\nPublic Sub Class_Inititialize()\n m_OldCursor = Screen.MousePointer\n Screen.MousePointer = vbHourGlass\nEnd Sub\n\nPublic Sub Class_Terminate()\n Screen.MousePointer = m_OldCursor\nEnd Sub\n Public Sub MyButton_Click()\n Dim WC As New WaitCursor\n\n ' … Time-consuming operation. '\nEnd Sub\n"
},
{
"answer_id": 168103,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 3,
"selected": false,
"text": "with open(\"foo.txt\", \"w\") as f:\n f.write(\"abc\")\n f.close() closing(thing) from contextlib import contextmanager\n\n@contextmanager\ndef closing(thing):\n try:\n yield thing\n finally:\n thing.close()\n from __future__ import with_statement # required for python version < 2.6\nfrom contextlib import closing\nimport urllib\n\nwith closing(urllib.urlopen('http://www.python.org')) as page:\n for line in page:\n print line\n"
},
{
"answer_id": 396380,
"author": "jalf",
"author_id": 33213,
"author_profile": "https://Stackoverflow.com/users/33213",
"pm_score": 5,
"selected": false,
"text": "using T RAIIWrapper<T>(Func<DbConnection, T> f){\n using (var db = new DbConnection()){\n return f(db);\n }\n}\n"
},
{
"answer_id": 596577,
"author": "Daniel Earwicker",
"author_id": 27423,
"author_profile": "https://Stackoverflow.com/users/27423",
"pm_score": 2,
"selected": false,
"text": "(with-open-file (stream \"file.ext\" :direction :input)\n (do-something-with-stream stream))\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15124/"
] |
165,729
|
<p>The <code>end()</code> function in jQuery reverts the element set back to what it was before the last destructive change, so I can see how it's supposed to be used, but I've seen some code examples, eg: <a href="http://alistapart.com/articles/prettyaccessibleforms" rel="nofollow noreferrer">on alistapart</a> <em>(which were probably from older versions of jQuery - the article is from 2006)</em> which finished every statement off with <code>.end()</code>. eg:</p>
<pre><code>$( 'form.cmxform' ).hide().end();
</code></pre>
<ul>
<li>Does this have any effect?</li>
<li>Is it something I should also be doing?</li>
<li>What does the above code even return?</li>
</ul>
|
[
{
"answer_id": 165748,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 3,
"selected": false,
"text": "end() $('#myBox') $('#myBox').show ().children ('.myClass').hide ().end ().blink ();\n myBox $('form#login')\n // hide all the labels inside the form with the 'optional' class\n .find('label.optional').hide().end()\n // add a red border to any password fields in the form\n .find('input:password').css('border', '1px solid red').end()\n // add a submit handler to the form\n .submit(function(){\n return confirm('Are you sure you want to submit?');\n });\n"
},
{
"answer_id": 12859362,
"author": "Luca Rainone",
"author_id": 1049668,
"author_profile": "https://Stackoverflow.com/users/1049668",
"pm_score": 0,
"selected": false,
"text": "$('ul.first').find('.foo')\n .css('background-color', 'red')\n.end().find('.bar')\n .css('background-color', 'green')\n.end();\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
165,735
|
<p>I have a form showing progress messages as a fairly long process runs. It's a call to a web service so I can't really show a percentage complete figure on a progress bar meaningfully. (I don't particularly like the Marquee property of the progress bar)</p>
<p>I would like to show an animated GIF to give the process the feel of some activity (e.g. files flying from one computer to another like Windows copy process).</p>
<p>How do you do this?</p>
|
[
{
"answer_id": 4483452,
"author": "Aruch",
"author_id": 547747,
"author_profile": "https://Stackoverflow.com/users/547747",
"pm_score": 4,
"selected": false,
"text": " private void MyThreadRoutine()\n {\n this.Invoke(this.ShowProgressGifDelegate);\n //your long running process\n System.Threading.Thread.Sleep(5000);\n this.Invoke(this.HideProgressGifDelegate);\n }\n\n private void button1_Click(object sender, EventArgs e)\n {\n ThreadStart myThreadStart = new ThreadStart(MyThreadRoutine);\n Thread myThread = new Thread(myThreadStart);\n myThread.Start(); \n }\n"
},
{
"answer_id": 42102907,
"author": "M. Fawad Surosh",
"author_id": 4748475,
"author_profile": "https://Stackoverflow.com/users/4748475",
"pm_score": 0,
"selected": false,
"text": "private void btnCompare_Click(object sender, EventArgs e)\n{\n ThreadStart threadStart = new ThreadStart(Execution);\n Thread thread = new Thread(threadStart);\n thread.SetApartmentState(ApartmentState.STA);\n thread.Start();\n}\n private void Execution()\n{\n btnCompare.Invoke((MethodInvoker)delegate { pictureBox1.Visible = true; });\n Application.DoEvents();\n\n // Your main code comes here . . .\n\n btnCompare.Invoke((MethodInvoker)delegate { pictureBox1.Visible = false; });\n}\n private void ComparerForm_Load(object sender, EventArgs e)\n{\n pictureBox1.Visible = false;\n}\n"
},
{
"answer_id": 59123022,
"author": "Gehan Fernando",
"author_id": 1012111,
"author_profile": "https://Stackoverflow.com/users/1012111",
"pm_score": 1,
"selected": false,
"text": "Public Class Form1\n\n Private animatedimage As New Bitmap(\"C:\\MyData\\Search.gif\")\n Private currentlyanimating As Boolean = False\n\n Private Sub OnFrameChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)\n\n Me.Invalidate()\n\n End Sub\n\n Private Sub AnimateImage()\n\n If currentlyanimating = True Then\n ImageAnimator.Animate(animatedimage, AddressOf Me.OnFrameChanged)\n currentlyanimating = False\n End If\n\n End Sub\n\n Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)\n\n AnimateImage()\n ImageAnimator.UpdateFrames(animatedimage)\n e.Graphics.DrawImage(animatedimage, New Point((Me.Width / 4) + 40, (Me.Height / 4) + 40))\n\n End Sub\n\n Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load\n\n BtnStop.Enabled = False\n\n End Sub\n\n Private Sub BtnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStop.Click\n\n currentlyanimating = False\n ImageAnimator.StopAnimate(animatedimage, AddressOf Me.OnFrameChanged)\n BtnStart.Enabled = True\n BtnStop.Enabled = False\n\n End Sub\n\n Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click\n\n currentlyanimating = True\n AnimateImage()\n BtnStart.Enabled = False\n BtnStop.Enabled = True\n\n End Sub\n\nEnd Class\n"
},
{
"answer_id": 73899201,
"author": "Ameer Adel",
"author_id": 2332726,
"author_profile": "https://Stackoverflow.com/users/2332726",
"pm_score": 1,
"selected": false,
"text": "PictureBox.Image = Image.FromFile(\"location\"); // OR From base64 PictureBox.SizeMode = PictureBoxSizeMode.Zoom;"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165735",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5019/"
] |
165,767
|
<p>I need something like <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Set.html" rel="noreferrer">this</a>, a collection of elements which contains no duplicates of any element. Does Common Lisp, specifically SBCL, have any thing like this? </p>
|
[
{
"answer_id": 166273,
"author": "Tamelite",
"author_id": 24436,
"author_profile": "https://Stackoverflow.com/users/24436",
"pm_score": 2,
"selected": false,
"text": "(let ((set (list)))\n (pushnew 11 set)\n (pushnew 42 set)\n (pushnew 11 set) \n (print set) ; set={42,11}\n (setq set (delete 42 set))\n (print set)) ; set={11}\n (let ((set (list)))\n (pushnew \"foo\" set :test #'equal)\n (pushnew \"bar\" set :test #'equal)\n (pushnew \"foo\" set :test #'equal) ; EQUAL decides that \"foo\"=\"foo\"\n (print set)) ; set={\"bar\",\"foo\"}\n"
},
{
"answer_id": 166847,
"author": "Matt Curtis",
"author_id": 17221,
"author_profile": "https://Stackoverflow.com/users/17221",
"pm_score": 2,
"selected": false,
"text": "pushnew adjoin member member-if member-if-not intersection union set-difference set-exclusive-or subsetp"
},
{
"answer_id": 171511,
"author": "Mikael Jansson",
"author_id": 18753,
"author_profile": "https://Stackoverflow.com/users/18753",
"pm_score": 2,
"selected": false,
"text": "(let ((h (make-hash-table :test 'equalp))) ; if you're storing symbols\n (loop for i from 0 upto 20\n do (setf (gethash i h) (format nil \"Value ~A\" i)))\n (loop for i from 10 upto 30\n do (setf (gethash i h) (format nil \"~A eulaV\" i)))\n (loop for k being the hash-keys of h using (hash-value v)\n do (format t \"~A => ~A~%\" k v)))\n 0 => Value 0\n1 => Value 1\n...\n9 => Value 9\n10 => 10 eulaV\n11 => 11 eulaV\n...\n29 => 29 eulaV\n30 => 30 eulaV\n"
},
{
"answer_id": 238789,
"author": "zvoase",
"author_id": 31600,
"author_profile": "https://Stackoverflow.com/users/31600",
"pm_score": 0,
"selected": false,
"text": "(defun make-set (list-in &optional (list-out '()))\n (if (endp list-in)\n (nreverse list-out)\n (make-set\n (cdr list-in)\n (adjoin (car list-in) list-out :test 'equal))))\n adjoin pushnew"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/85/"
] |
165,779
|
<p>I've seen a couple questions around here like <a href="https://stackoverflow.com/questions/165720/how-to-debug-restful-services">How to debug RESTful services</a>, which mentions:</p>
<blockquote>
<p>Unfortunately that same browser won't allow me to test HTTP PUT, DELETE, and to a certain degree even HTTP POST.</p>
</blockquote>
<p>I've also heard that browsers support only GET and POST, from some other sources like:</p>
<ul>
<li><a href="http://www.packetizer.com/ws/rest.html" rel="noreferrer">http://www.packetizer.com/ws/rest.html</a></li>
<li><a href="http://www.mail-archive.com/jmeter-user@jakarta.apache.org/msg13518.html" rel="noreferrer">http://www.mail-archive.com/jmeter-user@jakarta.apache.org/msg13518.html</a></li>
<li><a href="http://www.xml.com/cs/user/view/cs_msg/1098" rel="noreferrer">http://www.xml.com/cs/user/view/cs_msg/1098</a></li>
</ul>
<p>However, a few quick tests in Firefox show that sending <code>PUT</code> and <code>DELETE</code> requests works as expected -- the <code>XMLHttpRequest</code> completes successfully, and the request shows up in the server logs with the right method. Is there some aspect to this I'm missing, such as cross-browser compatibility or non-obvious limitations?</p>
|
[
{
"answer_id": 166129,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 4,
"selected": false,
"text": "XMLHttpRequest XMLHttpRequest XMLHttpRequest XMLHttpRequest XMLHttpRequest XMLHttpRequest PUT DELETE"
},
{
"answer_id": 166158,
"author": "Vihung",
"author_id": 15452,
"author_profile": "https://Stackoverflow.com/users/15452",
"pm_score": 5,
"selected": false,
"text": "XMLHttpRequest XMLHttpRequest open() GET POST HEAD PUT DELETE"
},
{
"answer_id": 26897298,
"author": "Ciro Santilli OurBigBook.com",
"author_id": 895245,
"author_profile": "https://Stackoverflow.com/users/895245",
"pm_score": 5,
"selected": false,
"text": "_method _method <input type=\"hidden\" name=\"_method\" value=\"DELETE\">\n form_tag <form method=\"post\" _method"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3560/"
] |
165,783
|
<p>It seems pretty common to want to let your javascript know a particular dom node corresponds to a record in the database. So, how do you do it?</p>
<p>One way I've seen that's pretty common is to use a class for the type and an id for the id:</p>
<pre><code><div class="thing" id="5">
<script> myThing = select(".thing#5") </script>
</code></pre>
<p>There's a slight html standards issue with this though -- if you have more than one type of record on the page, you may end up duplicating IDs. But that doesn't do anything bad, does it?</p>
<p>An alternative is to use data attributes:</p>
<pre><code><div data-thing-id="5">
<script> myThing = select("[data-thing-id=5]") </script>
</code></pre>
<p>This gets around the duplicate IDs problem, but it does mean you have to deal with attributes instead of IDs, which is sometimes more difficult. What do you guys think?</p>
|
[
{
"answer_id": 165787,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 4,
"selected": false,
"text": "<div class=\"thing\" id=\"myapp-thing-5\"/>\n\n// Get thing on the page for a particular ID\nvar myThing = select(\"#myapp-thing-5\");\n\n// Get ID for the first thing on the page\nvar thing_id = /myapp-thing-(\\d+)/.exec ($('.thing')[0].id)[1];\n"
},
{
"answer_id": 165798,
"author": "Zack The Human",
"author_id": 18265,
"author_profile": "https://Stackoverflow.com/users/18265",
"pm_score": 2,
"selected": false,
"text": "<div class=\"thing myapp-thing-5\" />\n<div class=\"thing myapp-thing-668\" />\n<div class=\"thing myapp-thing-5\" />\n"
},
{
"answer_id": 165818,
"author": "keparo",
"author_id": 19468,
"author_profile": "https://Stackoverflow.com/users/19468",
"pm_score": 4,
"selected": false,
"text": "var whoKnows = document.getElementById('duplicateId');\n <div class=\"friend04\"/>\n<div class=\"featuredFriend04\" />\n <div class=\"friend friend04\" />\n<div class=\"featuredFriend friend04\" />\n <div class=\"friend objectId04\" />\n<div class=\"groupMember objectId04\" />\n <div class=\"friend objectId04\" />\n<div class=\"friend objectId04\" id=\"featured\" />\n"
},
{
"answer_id": 165893,
"author": "Peter Hilton",
"author_id": 2670,
"author_profile": "https://Stackoverflow.com/users/2670",
"pm_score": 5,
"selected": true,
"text": "<div class=\"thing\" id=\"5\">\n thing5 thing.5"
},
{
"answer_id": 165907,
"author": "Shadow2531",
"author_id": 1697,
"author_profile": "https://Stackoverflow.com/users/1697",
"pm_score": 1,
"selected": false,
"text": "\n<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <title></title>\n <script>\n window.addEventListener(\"DOMContentLoaded\", function() {\n var thing5 = document.evaluate('//*[@data-thing=\"5\"]', \n document, null, XPathResult.FIRST_ORDERED_NODE_TYPE ,null);\n alert(thing5.singleNodeValue.textContent);\n }, false);\n </script>\n </head>\n <body>\n <div data-thing=\"5\">test</div>\n </body>\n</html>\n"
},
{
"answer_id": 166072,
"author": "cllpse",
"author_id": 20946,
"author_profile": "https://Stackoverflow.com/users/20946",
"pm_score": 0,
"selected": false,
"text": "substring() class id"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2653/"
] |
165,790
|
<p>I'm used to coding Java Swing UIs, and in those if you have some properties that change, and you want your UI to update, you would implement the observer/observable pattern. In Java you do this normally by having your class maintain a list of listeners that it notifies of different events.</p>
<p>I've played with Objective-C on the Mac, and that has KVC and binding which seems to work very nicely, and requires less code. The iPhone SDK doesn't seem to have this functionality though, so my question is:
If I have a class that holds data that changes, what's the best way for me to register a UI component with that class so that it can be notified of changes in the data that it needs to display?</p>
|
[
{
"answer_id": 166062,
"author": "Chris Hanson",
"author_id": 714,
"author_profile": "https://Stackoverflow.com/users/714",
"pm_score": 6,
"selected": true,
"text": "-addObserver:forKeyPath:options:context: NSNotificationCenter userInfo"
},
{
"answer_id": 166724,
"author": "rustyshelf",
"author_id": 6044,
"author_profile": "https://Stackoverflow.com/users/6044",
"pm_score": 3,
"selected": false,
"text": "[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_handleWhateverChange) name:@\"whateverChange\" object:nil];\n [[NSNotificationCenter defaultCenter] postNotificationName:@\"whateverChange\" object:nil];\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6044/"
] |
165,796
|
<p>I must be getting daft, but I can't seem to find how to read old-fashioned ini files with VB 6.0. All I can seem to find is about reading from and writing to the registry. Can someone push me in the right direction? Mind you, I am not a programmer, just a hobbyist trying to have some harmless fun with his computer, so please don't be to harsh when you point out the bleedin' obvious.</p>
|
[
{
"answer_id": 166062,
"author": "Chris Hanson",
"author_id": 714,
"author_profile": "https://Stackoverflow.com/users/714",
"pm_score": 6,
"selected": true,
"text": "-addObserver:forKeyPath:options:context: NSNotificationCenter userInfo"
},
{
"answer_id": 166724,
"author": "rustyshelf",
"author_id": 6044,
"author_profile": "https://Stackoverflow.com/users/6044",
"pm_score": 3,
"selected": false,
"text": "[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_handleWhateverChange) name:@\"whateverChange\" object:nil];\n [[NSNotificationCenter defaultCenter] postNotificationName:@\"whateverChange\" object:nil];\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165796",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17382/"
] |
165,808
|
<p>I'm looking for very simple obfuscation (like encrypt and decrypt but not necessarily secure) functionality for some data. It's not mission critical. I need something to keep honest people honest, but something a little stronger than <a href="http://en.wikipedia.org/wiki/ROT13" rel="noreferrer">ROT13</a> or <a href="http://en.wikipedia.org/wiki/Base64" rel="noreferrer">Base64</a>.</p>
<p>I'd prefer something that is already included in the <a href="http://en.wikipedia.org/wiki/.NET_Framework" rel="noreferrer">.NET</a> framework 2.0, so I don't have to worry about any external dependencies.</p>
<p>I really don't want to have to mess around with public/private keys, etc. I don't know much about encryption, but I do know enough to know that anything I wrote would be less than worthless... In fact, I'd probably screw up the math and make it trivial to crack.</p>
|
[
{
"answer_id": 165826,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 1,
"selected": false,
"text": "System.Security.Cryptography TripleDESCryptoServiceProvider RijndaelManaged System.Security"
},
{
"answer_id": 165850,
"author": "ZeroBugBounce",
"author_id": 11314,
"author_profile": "https://Stackoverflow.com/users/11314",
"pm_score": 5,
"selected": false,
"text": "System.Security System.Security.Cryptography DESCryptoServiceProvider des = new DESCryptoServiceProvider();\ndes.GenerateKey();\nbyte[] key = des.Key; // save this!\n\nICryptoTransform encryptor = des.CreateEncryptor();\n// encrypt\nbyte[] enc = encryptor.TransformFinalBlock(new byte[] { 1, 2, 3, 4 }, 0, 4);\n\nICryptoTransform decryptor = des.CreateDecryptor();\n\n// decrypt\nbyte[] originalAgain = decryptor.TransformFinalBlock(enc, 0, enc.Length);\nDebug.Assert(originalAgain[0] == 1);\n"
},
{
"answer_id": 165869,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 3,
"selected": false,
"text": "deoxyribonucleicacid\nwhile (x>0) { x-- };\n 1111-2222-3333-4444-5555-6666-7777\ndeoxyribonucleicaciddeoxyribonucle\nwhile (x>0) { x-- };while (x>0) { \n"
},
{
"answer_id": 212707,
"author": "Mark Brittingham",
"author_id": 15592,
"author_profile": "https://Stackoverflow.com/users/15592",
"pm_score": 10,
"selected": true,
"text": "Key Vector using System;\nusing System.Data;\nusing System.Security.Cryptography;\nusing System.IO;\n\n\npublic class SimpleAES\n{\n // Change these keys\n private byte[] Key = __Replace_Me__({ 123, 217, 19, 11, 24, 26, 85, 45, 114, 184, 27, 162, 37, 112, 222, 209, 241, 24, 175, 144, 173, 53, 196, 29, 24, 26, 17, 218, 131, 236, 53, 209 });\n\n // a hardcoded IV should not be used for production AES-CBC code\n // IVs should be unpredictable per ciphertext\n private byte[] Vector = __Replace_Me__({ 146, 64, 191, 111, 23, 3, 113, 119, 231, 121, 2521, 112, 79, 32, 114, 156 });\n\n\n private ICryptoTransform EncryptorTransform, DecryptorTransform;\n private System.Text.UTF8Encoding UTFEncoder;\n\n public SimpleAES()\n {\n //This is our encryption method\n RijndaelManaged rm = new RijndaelManaged();\n\n //Create an encryptor and a decryptor using our encryption method, key, and vector.\n EncryptorTransform = rm.CreateEncryptor(this.Key, this.Vector);\n DecryptorTransform = rm.CreateDecryptor(this.Key, this.Vector);\n\n //Used to translate bytes to text and vice versa\n UTFEncoder = new System.Text.UTF8Encoding();\n }\n\n /// -------------- Two Utility Methods (not used but may be useful) -----------\n /// Generates an encryption key.\n static public byte[] GenerateEncryptionKey()\n {\n //Generate a Key.\n RijndaelManaged rm = new RijndaelManaged();\n rm.GenerateKey();\n return rm.Key;\n }\n\n /// Generates a unique encryption vector\n static public byte[] GenerateEncryptionVector()\n {\n //Generate a Vector\n RijndaelManaged rm = new RijndaelManaged();\n rm.GenerateIV();\n return rm.IV;\n }\n\n\n /// ----------- The commonly used methods ------------------------------ \n /// Encrypt some text and return a string suitable for passing in a URL.\n public string EncryptToString(string TextValue)\n {\n return ByteArrToString(Encrypt(TextValue));\n }\n\n /// Encrypt some text and return an encrypted byte array.\n public byte[] Encrypt(string TextValue)\n {\n //Translates our text value into a byte array.\n Byte[] bytes = UTFEncoder.GetBytes(TextValue);\n\n //Used to stream the data in and out of the CryptoStream.\n MemoryStream memoryStream = new MemoryStream();\n\n /*\n * We will have to write the unencrypted bytes to the stream,\n * then read the encrypted result back from the stream.\n */\n #region Write the decrypted value to the encryption stream\n CryptoStream cs = new CryptoStream(memoryStream, EncryptorTransform, CryptoStreamMode.Write);\n cs.Write(bytes, 0, bytes.Length);\n cs.FlushFinalBlock();\n #endregion\n\n #region Read encrypted value back out of the stream\n memoryStream.Position = 0;\n byte[] encrypted = new byte[memoryStream.Length];\n memoryStream.Read(encrypted, 0, encrypted.Length);\n #endregion\n\n //Clean up.\n cs.Close();\n memoryStream.Close();\n\n return encrypted;\n }\n\n /// The other side: Decryption methods\n public string DecryptString(string EncryptedString)\n {\n return Decrypt(StrToByteArray(EncryptedString));\n }\n\n /// Decryption when working with byte arrays. \n public string Decrypt(byte[] EncryptedValue)\n {\n #region Write the encrypted value to the decryption stream\n MemoryStream encryptedStream = new MemoryStream();\n CryptoStream decryptStream = new CryptoStream(encryptedStream, DecryptorTransform, CryptoStreamMode.Write);\n decryptStream.Write(EncryptedValue, 0, EncryptedValue.Length);\n decryptStream.FlushFinalBlock();\n #endregion\n\n #region Read the decrypted value from the stream.\n encryptedStream.Position = 0;\n Byte[] decryptedBytes = new Byte[encryptedStream.Length];\n encryptedStream.Read(decryptedBytes, 0, decryptedBytes.Length);\n encryptedStream.Close();\n #endregion\n return UTFEncoder.GetString(decryptedBytes);\n }\n\n /// Convert a string to a byte array. NOTE: Normally we'd create a Byte Array from a string using an ASCII encoding (like so).\n // System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();\n // return encoding.GetBytes(str);\n // However, this results in character values that cannot be passed in a URL. So, instead, I just\n // lay out all of the byte values in a long string of numbers (three per - must pad numbers less than 100).\n public byte[] StrToByteArray(string str)\n {\n if (str.Length == 0)\n throw new Exception(\"Invalid string value in StrToByteArray\");\n\n byte val;\n byte[] byteArr = new byte[str.Length / 3];\n int i = 0;\n int j = 0;\n do\n {\n val = byte.Parse(str.Substring(i, 3));\n byteArr[j++] = val;\n i += 3;\n }\n while (i < str.Length);\n return byteArr;\n }\n\n // Same comment as above. Normally the conversion would use an ASCII encoding in the other direction:\n // System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();\n // return enc.GetString(byteArr); \n public string ByteArrToString(byte[] byteArr)\n {\n byte val;\n string tempStr = \"\";\n for (int i = 0; i <= byteArr.GetUpperBound(0); i++)\n {\n val = byteArr[i];\n if (val < (byte)10)\n tempStr += \"00\" + val.ToString();\n else if (val < (byte)100)\n tempStr += \"0\" + val.ToString();\n else\n tempStr += val.ToString();\n }\n return tempStr;\n }\n}\n"
},
{
"answer_id": 212742,
"author": "stalepretzel",
"author_id": 1615,
"author_profile": "https://Stackoverflow.com/users/1615",
"pm_score": 3,
"selected": false,
"text": "mypass mypassmypassmypass... mypassmypassmypass..."
},
{
"answer_id": 5081379,
"author": "Achilleterzo",
"author_id": 628738,
"author_profile": "https://Stackoverflow.com/users/628738",
"pm_score": 1,
"selected": false,
"text": "public string ByteArrToString(byte[] byteArr)\n{\n byte val;\n string tempStr = \"\";\n for (int i = 0; i <= byteArr.GetUpperBound(0); i++)\n {\n val = byteArr[i];\n if (val < (byte)10)\n tempStr += \"00\" + val.ToString();\n else if (val < (byte)100)\n tempStr += \"0\" + val.ToString();\n else\n tempStr += val.ToString();\n }\n return tempStr;\n}\n public string ByteArrToString(byte[] byteArr)\n {\n string temp = \"\";\n foreach (byte b in byteArr)\n temp += b.ToString().PadLeft(3, '0');\n return temp;\n }\n"
},
{
"answer_id": 5518092,
"author": "Mud",
"author_id": 501459,
"author_profile": "https://Stackoverflow.com/users/501459",
"pm_score": 8,
"selected": false,
"text": "johnsmith@gmail.com SimpleAES: \"096114178117140150104121138042115022037019164188092040214235183167012211175176167001017163166152\"\nSimplerAES: \"YHKydYyWaHmKKnMWJROkvFwo1uu3pwzTr7CnARGjppg%3d\"\n public class SimplerAES\n{\n private static byte[] key = __Replace_Me__({ 123, 217, 19, 11, 24, 26, 85, 45, 114, 184, 27, 162, 37, 112, 222, 209, 241, 24, 175, 144, 173, 53, 196, 29, 24, 26, 17, 218, 131, 236, 53, 209 });\n\n // a hardcoded IV should not be used for production AES-CBC code\n // IVs should be unpredictable per ciphertext\n private static byte[] vector = __Replace_Me_({ 146, 64, 191, 111, 23, 3, 113, 119, 231, 121, 221, 112, 79, 32, 114, 156 });\n\n private ICryptoTransform encryptor, decryptor;\n private UTF8Encoding encoder;\n\n public SimplerAES()\n {\n RijndaelManaged rm = new RijndaelManaged();\n encryptor = rm.CreateEncryptor(key, vector);\n decryptor = rm.CreateDecryptor(key, vector);\n encoder = new UTF8Encoding();\n }\n\n public string Encrypt(string unencrypted)\n {\n return Convert.ToBase64String(Encrypt(encoder.GetBytes(unencrypted)));\n }\n\n public string Decrypt(string encrypted)\n {\n return encoder.GetString(Decrypt(Convert.FromBase64String(encrypted)));\n }\n\n public byte[] Encrypt(byte[] buffer)\n {\n return Transform(buffer, encryptor);\n }\n\n public byte[] Decrypt(byte[] buffer)\n {\n return Transform(buffer, decryptor);\n }\n\n protected byte[] Transform(byte[] buffer, ICryptoTransform transform)\n {\n MemoryStream stream = new MemoryStream();\n using (CryptoStream cs = new CryptoStream(stream, transform, CryptoStreamMode.Write))\n {\n cs.Write(buffer, 0, buffer.Length);\n }\n return stream.ToArray();\n }\n}\n"
},
{
"answer_id": 7314406,
"author": "Simon",
"author_id": 53158,
"author_profile": "https://Stackoverflow.com/users/53158",
"pm_score": 4,
"selected": false,
"text": "[TestFixture]\npublic class RijndaelHelperTests\n{\n [Test]\n public void UseCase()\n {\n //These two values should not be hard coded in your code.\n byte[] key = {251, 9, 67, 117, 237, 158, 138, 150, 255, 97, 103, 128, 183, 65, 76, 161, 7, 79, 244, 225, 146, 180, 51, 123, 118, 167, 45, 10, 184, 181, 202, 190};\n byte[] vector = {214, 11, 221, 108, 210, 71, 14, 15, 151, 57, 241, 174, 177, 142, 115, 137};\n\n using (var rijndaelHelper = new RijndaelHelper(key, vector))\n {\n var encrypt = rijndaelHelper.Encrypt(\"StringToEncrypt\");\n var decrypt = rijndaelHelper.Decrypt(encrypt);\n Assert.AreEqual(\"StringToEncrypt\", decrypt);\n }\n }\n}\n\npublic class RijndaelHelper : IDisposable\n{\n Rijndael rijndael;\n UTF8Encoding encoding;\n\n public RijndaelHelper(byte[] key, byte[] vector)\n {\n encoding = new UTF8Encoding();\n rijndael = Rijndael.Create();\n rijndael.Key = key;\n rijndael.IV = vector;\n }\n\n public byte[] Encrypt(string valueToEncrypt)\n {\n var bytes = encoding.GetBytes(valueToEncrypt);\n using (var encryptor = rijndael.CreateEncryptor())\n using (var stream = new MemoryStream())\n using (var crypto = new CryptoStream(stream, encryptor, CryptoStreamMode.Write))\n {\n crypto.Write(bytes, 0, bytes.Length);\n crypto.FlushFinalBlock();\n stream.Position = 0;\n var encrypted = new byte[stream.Length];\n stream.Read(encrypted, 0, encrypted.Length);\n return encrypted;\n }\n }\n\n public string Decrypt(byte[] encryptedValue)\n {\n using (var decryptor = rijndael.CreateDecryptor())\n using (var stream = new MemoryStream())\n using (var crypto = new CryptoStream(stream, decryptor, CryptoStreamMode.Write))\n {\n crypto.Write(encryptedValue, 0, encryptedValue.Length);\n crypto.FlushFinalBlock();\n stream.Position = 0;\n var decryptedBytes = new Byte[stream.Length];\n stream.Read(decryptedBytes, 0, decryptedBytes.Length);\n return encoding.GetString(decryptedBytes);\n }\n }\n\n public void Dispose()\n {\n if (rijndael != null)\n {\n rijndael.Dispose();\n }\n }\n}\n"
},
{
"answer_id": 26177005,
"author": "Andy C",
"author_id": 1638719,
"author_profile": "https://Stackoverflow.com/users/1638719",
"pm_score": 5,
"selected": false,
"text": "public class StringEncryption\n{\n private readonly Random random;\n private readonly byte[] key;\n private readonly RijndaelManaged rm;\n private readonly UTF8Encoding encoder;\n\n public StringEncryption()\n {\n this.random = new Random();\n this.rm = new RijndaelManaged();\n this.encoder = new UTF8Encoding();\n this.key = Convert.FromBase64String(\"Your+Secret+Static+Encryption+Key+Goes+Here=\");\n }\n\n public string Encrypt(string unencrypted)\n {\n var vector = new byte[16];\n this.random.NextBytes(vector);\n var cryptogram = vector.Concat(this.Encrypt(this.encoder.GetBytes(unencrypted), vector));\n return Convert.ToBase64String(cryptogram.ToArray());\n }\n\n public string Decrypt(string encrypted)\n {\n var cryptogram = Convert.FromBase64String(encrypted);\n if (cryptogram.Length < 17)\n {\n throw new ArgumentException(\"Not a valid encrypted string\", \"encrypted\");\n }\n\n var vector = cryptogram.Take(16).ToArray();\n var buffer = cryptogram.Skip(16).ToArray();\n return this.encoder.GetString(this.Decrypt(buffer, vector));\n }\n\n private byte[] Encrypt(byte[] buffer, byte[] vector)\n {\n var encryptor = this.rm.CreateEncryptor(this.key, vector);\n return this.Transform(buffer, encryptor);\n }\n\n private byte[] Decrypt(byte[] buffer, byte[] vector)\n {\n var decryptor = this.rm.CreateDecryptor(this.key, vector);\n return this.Transform(buffer, decryptor);\n }\n\n private byte[] Transform(byte[] buffer, ICryptoTransform transform)\n {\n var stream = new MemoryStream();\n using (var cs = new CryptoStream(stream, transform, CryptoStreamMode.Write))\n {\n cs.Write(buffer, 0, buffer.Length);\n }\n\n return stream.ToArray();\n }\n}\n [Test]\npublic void EncryptDecrypt()\n{\n // Arrange\n var subject = new StringEncryption();\n var originalString = \"Testing123!£$\";\n\n // Act\n var encryptedString1 = subject.Encrypt(originalString);\n var encryptedString2 = subject.Encrypt(originalString);\n var decryptedString1 = subject.Decrypt(encryptedString1);\n var decryptedString2 = subject.Decrypt(encryptedString2);\n\n // Assert\n Assert.AreEqual(originalString, decryptedString1, \"Decrypted string should match original string\");\n Assert.AreEqual(originalString, decryptedString2, \"Decrypted string should match original string\");\n Assert.AreNotEqual(originalString, encryptedString1, \"Encrypted string should not match original string\");\n Assert.AreNotEqual(encryptedString1, encryptedString2, \"String should never be encrypted the same twice\");\n}\n"
},
{
"answer_id": 26518496,
"author": "angularsen",
"author_id": 134761,
"author_profile": "https://Stackoverflow.com/users/134761",
"pm_score": 4,
"selected": false,
"text": "/// <summary>\n/// Simple encryption/decryption using a random initialization vector\n/// and prepending it to the crypto text.\n/// </summary>\n/// <remarks>Based on multiple answers in http://stackoverflow.com/questions/165808/simple-two-way-encryption-for-c-sharp </remarks>\npublic class SimpleAes : IDisposable\n{\n /// <summary>\n /// Initialization vector length in bytes.\n /// </summary>\n private const int IvBytes = 16;\n\n /// <summary>\n /// Must be exactly 16, 24 or 32 bytes long.\n /// </summary>\n private static readonly byte[] Key = Convert.FromBase64String(\"FILL ME WITH 24 (2 pad chars), 32 OR 44 (1 pad char) RANDOM CHARS\"); // Base64 has a blowup of four-thirds (33%)\n\n private readonly UTF8Encoding _encoder;\n private readonly ICryptoTransform _encryptor;\n private readonly RijndaelManaged _rijndael;\n\n public SimpleAes()\n {\n _rijndael = new RijndaelManaged {Key = Key};\n _rijndael.GenerateIV();\n _encryptor = _rijndael.CreateEncryptor();\n _encoder = new UTF8Encoding();\n }\n\n public string Decrypt(string encrypted)\n {\n return _encoder.GetString(Decrypt(Convert.FromBase64String(encrypted)));\n }\n\n public void Dispose()\n {\n _rijndael.Dispose();\n _encryptor.Dispose();\n }\n\n public string Encrypt(string unencrypted)\n {\n return Convert.ToBase64String(Encrypt(_encoder.GetBytes(unencrypted)));\n }\n\n private byte[] Decrypt(byte[] buffer)\n {\n // IV is prepended to cryptotext\n byte[] iv = buffer.Take(IvBytes).ToArray();\n using (ICryptoTransform decryptor = _rijndael.CreateDecryptor(_rijndael.Key, iv))\n {\n return decryptor.TransformFinalBlock(buffer, IvBytes, buffer.Length - IvBytes);\n }\n }\n\n private byte[] Encrypt(byte[] buffer)\n {\n // Prepend cryptotext with IV\n byte [] inputBuffer = _encryptor.TransformFinalBlock(buffer, 0, buffer.Length); \n return _rijndael.IV.Concat(inputBuffer).ToArray();\n }\n}\n"
},
{
"answer_id": 27877537,
"author": "Thunder",
"author_id": 232687,
"author_profile": "https://Stackoverflow.com/users/232687",
"pm_score": -1,
"selected": false,
"text": "string encrypted = \"Text\".Aggregate(\"\", (c, a) => c + (char) (a + 2));\n Console.WriteLine((\"Hello\").Aggregate(\"\", (c, a) => c + (char) (a + 1)));\n //Output is Ifmmp\n Console.WriteLine((\"Ifmmp\").Aggregate(\"\", (c, a) => c + (char)(a - 1)));\n //Output is Hello\n"
},
{
"answer_id": 33759739,
"author": "William",
"author_id": 907734,
"author_profile": "https://Stackoverflow.com/users/907734",
"pm_score": 3,
"selected": false,
"text": " // This will return an encrypted string based on the unencrypted parameter\n public static string Encrypt(this string DecryptedValue)\n {\n HttpServerUtility.UrlTokenEncode(MachineKey.Protect(Encoding.UTF8.GetBytes(DecryptedValue.Trim())));\n }\n\n // This will return an unencrypted string based on the parameter\n public static string Decrypt(this string EncryptedValue)\n {\n Encoding.UTF8.GetString(MachineKey.Unprotect(HttpServerUtility.UrlTokenDecode(EncryptedValue)));\n }\n"
},
{
"answer_id": 35345056,
"author": "Matt",
"author_id": 902630,
"author_profile": "https://Stackoverflow.com/users/902630",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.IO;\nusing System.Security.Cryptography;\n\nnamespace Aes_Example\n{\n class AesExample\n {\n public static void Main()\n {\n try\n {\n\n string original = \"Here is some data to encrypt!\";\n\n // Create a new instance of the Aes\n // class. This generates a new key and initialization \n // vector (IV).\n using (Aes myAes = Aes.Create())\n {\n\n // Encrypt the string to an array of bytes.\n byte[] encrypted = EncryptStringToBytes_Aes(original, myAes.Key, myAes.IV);\n\n // Decrypt the bytes to a string.\n string roundtrip = DecryptStringFromBytes_Aes(encrypted, myAes.Key, myAes.IV);\n\n //Display the original data and the decrypted data.\n Console.WriteLine(\"Original: {0}\", original);\n Console.WriteLine(\"Round Trip: {0}\", roundtrip);\n }\n\n }\n catch (Exception e)\n {\n Console.WriteLine(\"Error: {0}\", e.Message);\n }\n }\n static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key,byte[] IV)\n {\n // Check arguments.\n if (plainText == null || plainText.Length <= 0)\n throw new ArgumentNullException(\"plainText\");\n if (Key == null || Key.Length <= 0)\n throw new ArgumentNullException(\"Key\");\n if (IV == null || IV.Length <= 0)\n throw new ArgumentNullException(\"Key\");\n byte[] encrypted;\n // Create an Aes object\n // with the specified key and IV.\n using (Aes aesAlg = Aes.Create())\n {\n aesAlg.Key = Key;\n aesAlg.IV = IV;\n\n // Create a decrytor to perform the stream transform.\n ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);\n\n // Create the streams used for encryption.\n using (MemoryStream msEncrypt = new MemoryStream())\n {\n using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))\n {\n using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))\n {\n\n //Write all data to the stream.\n swEncrypt.Write(plainText);\n }\n encrypted = msEncrypt.ToArray();\n }\n }\n }\n\n\n // Return the encrypted bytes from the memory stream.\n return encrypted;\n\n }\n\n static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV)\n {\n // Check arguments.\n if (cipherText == null || cipherText.Length <= 0)\n throw new ArgumentNullException(\"cipherText\");\n if (Key == null || Key.Length <= 0)\n throw new ArgumentNullException(\"Key\");\n if (IV == null || IV.Length <= 0)\n throw new ArgumentNullException(\"Key\");\n\n // Declare the string used to hold\n // the decrypted text.\n string plaintext = null;\n\n // Create an Aes object\n // with the specified key and IV.\n using (Aes aesAlg = Aes.Create())\n {\n aesAlg.Key = Key;\n aesAlg.IV = IV;\n\n // Create a decrytor to perform the stream transform.\n ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);\n\n // Create the streams used for decryption.\n using (MemoryStream msDecrypt = new MemoryStream(cipherText))\n {\n using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))\n {\n using (StreamReader srDecrypt = new StreamReader(csDecrypt))\n {\n\n // Read the decrypted bytes from the decrypting stream\n // and place them in a string.\n plaintext = srDecrypt.ReadToEnd();\n }\n }\n }\n\n }\n\n return plaintext;\n\n }\n }\n}\n"
},
{
"answer_id": 42398918,
"author": "joym8",
"author_id": 1541224,
"author_profile": "https://Stackoverflow.com/users/1541224",
"pm_score": 0,
"selected": false,
"text": "Encrypt Decrypt RijndaelManaged /// <summary>\n/// Based on https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx\n/// Uses UTF8 Encoding\n/// http://security.stackexchange.com/a/90850\n/// </summary>\npublic class AnotherAES : IDisposable\n{\n private RijndaelManaged rijn;\n\n /// <summary>\n /// Initialize algo with key, block size, key size, padding mode and cipher mode to be known.\n /// </summary>\n /// <param name=\"key\">ASCII key to be used for encryption or decryption</param>\n /// <param name=\"blockSize\">block size to use for AES algorithm. 128, 192 or 256 bits</param>\n /// <param name=\"keySize\">key length to use for AES algorithm. 128, 192, or 256 bits</param>\n /// <param name=\"paddingMode\"></param>\n /// <param name=\"cipherMode\"></param>\n public AnotherAES(string key, int blockSize, int keySize, PaddingMode paddingMode, CipherMode cipherMode)\n {\n rijn = new RijndaelManaged();\n rijn.Key = Encoding.UTF8.GetBytes(key);\n rijn.BlockSize = blockSize;\n rijn.KeySize = keySize;\n rijn.Padding = paddingMode;\n rijn.Mode = cipherMode;\n }\n\n /// <summary>\n /// Initialize algo just with key\n /// Defaults for RijndaelManaged class: \n /// Block Size: 256 bits (32 bytes)\n /// Key Size: 128 bits (16 bytes)\n /// Padding Mode: PKCS7\n /// Cipher Mode: CBC\n /// </summary>\n /// <param name=\"key\"></param>\n public AnotherAES(string key)\n {\n rijn = new RijndaelManaged();\n byte[] keyArray = Encoding.UTF8.GetBytes(key);\n rijn.Key = keyArray;\n }\n\n /// <summary>\n /// Based on https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx\n /// Encrypt a string using RijndaelManaged encryptor.\n /// </summary>\n /// <param name=\"plainText\">string to be encrypted</param>\n /// <param name=\"IV\">initialization vector to be used by crypto algorithm</param>\n /// <returns></returns>\n public byte[] Encrypt(string plainText, byte[] IV)\n {\n if (rijn == null)\n throw new ArgumentNullException(\"Provider not initialized\");\n\n // Check arguments.\n if (plainText == null || plainText.Length <= 0)\n throw new ArgumentNullException(\"plainText cannot be null or empty\");\n if (IV == null || IV.Length <= 0)\n throw new ArgumentNullException(\"IV cannot be null or empty\");\n byte[] encrypted;\n\n // Create a decrytor to perform the stream transform.\n using (ICryptoTransform encryptor = rijn.CreateEncryptor(rijn.Key, IV))\n {\n // Create the streams used for encryption.\n using (MemoryStream msEncrypt = new MemoryStream())\n {\n using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))\n {\n using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))\n {\n //Write all data to the stream.\n swEncrypt.Write(plainText);\n }\n encrypted = msEncrypt.ToArray();\n }\n }\n }\n // Return the encrypted bytes from the memory stream.\n return encrypted;\n }//end EncryptStringToBytes\n\n /// <summary>\n /// Based on https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx\n /// </summary>\n /// <param name=\"cipherText\">bytes to be decrypted back to plaintext</param>\n /// <param name=\"IV\">initialization vector used to encrypt the bytes</param>\n /// <returns></returns>\n public string Decrypt(byte[] cipherText, byte[] IV)\n {\n if (rijn == null)\n throw new ArgumentNullException(\"Provider not initialized\");\n\n // Check arguments.\n if (cipherText == null || cipherText.Length <= 0)\n throw new ArgumentNullException(\"cipherText cannot be null or empty\");\n if (IV == null || IV.Length <= 0)\n throw new ArgumentNullException(\"IV cannot be null or empty\");\n\n // Declare the string used to hold the decrypted text.\n string plaintext = null;\n\n // Create a decrytor to perform the stream transform.\n using (ICryptoTransform decryptor = rijn.CreateDecryptor(rijn.Key, IV))\n {\n // Create the streams used for decryption.\n using (MemoryStream msDecrypt = new MemoryStream(cipherText))\n {\n using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))\n {\n using (StreamReader srDecrypt = new StreamReader(csDecrypt))\n {\n // Read the decrypted bytes from the decrypting stream and place them in a string.\n plaintext = srDecrypt.ReadToEnd();\n }\n }\n }\n }\n\n return plaintext;\n }//end DecryptStringFromBytes\n\n /// <summary>\n /// Generates a unique encryption vector using RijndaelManaged.GenerateIV() method\n /// </summary>\n /// <returns></returns>\n public byte[] GenerateEncryptionVector()\n {\n if (rijn == null)\n throw new ArgumentNullException(\"Provider not initialized\");\n\n //Generate a Vector\n rijn.GenerateIV();\n return rijn.IV;\n }//end GenerateEncryptionVector\n\n\n /// <summary>\n /// Based on https://stackoverflow.com/a/1344255\n /// Generate a unique string given number of bytes required.\n /// This string can be used as IV. IV byte size should be equal to cipher-block byte size. \n /// Allows seeing IV in plaintext so it can be passed along a url or some message.\n /// </summary>\n /// <param name=\"numBytes\"></param>\n /// <returns></returns>\n public static string GetUniqueString(int numBytes)\n {\n char[] chars = new char[62];\n chars = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\".ToCharArray();\n byte[] data = new byte[1];\n using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider())\n {\n data = new byte[numBytes];\n crypto.GetBytes(data);\n }\n StringBuilder result = new StringBuilder(numBytes);\n foreach (byte b in data)\n {\n result.Append(chars[b % (chars.Length)]);\n }\n return result.ToString();\n }//end GetUniqueKey()\n\n /// <summary>\n /// Converts a string to byte array. Useful when converting back hex string which was originally formed from bytes.\n /// </summary>\n /// <param name=\"hex\"></param>\n /// <returns></returns>\n public static byte[] StringToByteArray(String hex)\n {\n int NumberChars = hex.Length;\n byte[] bytes = new byte[NumberChars / 2];\n for (int i = 0; i < NumberChars; i += 2)\n bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);\n return bytes;\n }//end StringToByteArray\n\n /// <summary>\n /// Dispose RijndaelManaged object initialized in the constructor\n /// </summary>\n public void Dispose()\n {\n if (rijn != null)\n rijn.Dispose();\n }//end Dispose()\n}//end class\n class Program\n{\n string key;\n static void Main(string[] args)\n {\n Program p = new Program();\n\n //get 16 byte key (just demo - typically you will have a predetermined key)\n p.key = AnotherAES.GetUniqueString(16);\n\n string plainText = \"Hello World!\";\n\n //encrypt\n string hex = p.Encrypt(plainText);\n\n //decrypt\n string roundTrip = p.Decrypt(hex);\n\n Console.WriteLine(\"Round Trip: {0}\", roundTrip);\n }\n\n string Encrypt(string plainText)\n {\n Console.WriteLine(\"\\nSending (encrypt side)...\");\n Console.WriteLine(\"Plain Text: {0}\", plainText);\n Console.WriteLine(\"Key: {0}\", key);\n string hex = string.Empty;\n string ivString = AnotherAES.GetUniqueString(16);\n Console.WriteLine(\"IV: {0}\", ivString);\n using (AnotherAES aes = new AnotherAES(key))\n {\n //encrypting side\n byte[] IV = Encoding.UTF8.GetBytes(ivString);\n\n //get encrypted bytes (IV bytes prepended to cipher bytes)\n byte[] encryptedBytes = aes.Encrypt(plainText, IV);\n byte[] encryptedBytesWithIV = IV.Concat(encryptedBytes).ToArray();\n\n //get hex string to send with url\n //this hex has both IV and ciphertext\n hex = BitConverter.ToString(encryptedBytesWithIV).Replace(\"-\", \"\");\n Console.WriteLine(\"sending hex: {0}\", hex);\n }\n\n return hex;\n }\n\n string Decrypt(string hex)\n {\n Console.WriteLine(\"\\nReceiving (decrypt side)...\");\n Console.WriteLine(\"received hex: {0}\", hex);\n string roundTrip = string.Empty;\n Console.WriteLine(\"Key \" + key);\n using (AnotherAES aes = new AnotherAES(key))\n {\n //get bytes from url\n byte[] encryptedBytesWithIV = AnotherAES.StringToByteArray(hex);\n\n byte[] IV = encryptedBytesWithIV.Take(16).ToArray();\n\n Console.WriteLine(\"IV: {0}\", System.Text.Encoding.Default.GetString(IV));\n\n byte[] cipher = encryptedBytesWithIV.Skip(16).ToArray();\n\n roundTrip = aes.Decrypt(cipher, IV);\n }\n return roundTrip;\n }\n}\n"
},
{
"answer_id": 46711265,
"author": "Ashkan S",
"author_id": 6519111,
"author_profile": "https://Stackoverflow.com/users/6519111",
"pm_score": 3,
"selected": false,
"text": "public static class CryptoHelper\n{\n private const string Key = \"MyHashString\";\n private static TripleDESCryptoServiceProvider GetCryproProvider()\n {\n var md5 = new MD5CryptoServiceProvider();\n var key = md5.ComputeHash(Encoding.UTF8.GetBytes(Key));\n return new TripleDESCryptoServiceProvider() { Key = key, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 };\n }\n\n public static string Encrypt(string plainString)\n {\n var data = Encoding.UTF8.GetBytes(plainString);\n var tripleDes = GetCryproProvider();\n var transform = tripleDes.CreateEncryptor();\n var resultsByteArray = transform.TransformFinalBlock(data, 0, data.Length);\n return Convert.ToBase64String(resultsByteArray);\n }\n\n public static string Decrypt(string encryptedString)\n {\n var data = Convert.FromBase64String(encryptedString);\n var tripleDes = GetCryproProvider();\n var transform = tripleDes.CreateDecryptor();\n var resultsByteArray = transform.TransformFinalBlock(data, 0, data.Length);\n return Encoding.UTF8.GetString(resultsByteArray);\n }\n}\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165808",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/232/"
] |
165,811
|
<p>What are opinions on the design of a "performance assertion checking" system?</p>
<p>The idea is that a developer makes some assertions about his/her code and use these to test the evolution of the <strong>performance</strong> of the code. What is the experience with such a system?</p>
<p>My current block is "What's a better way to translate these assertions, written in a specified language (that are to be checked against specified logs or runtime instrumentation) into, say, CLR, or assembly or bytecode that could be executed?"</p>
<p>Currently I have written a parser that parses the specification and holds it in a data structure.</p>
|
[
{
"answer_id": 165871,
"author": "SmacL",
"author_id": 22564,
"author_profile": "https://Stackoverflow.com/users/22564",
"pm_score": 1,
"selected": false,
"text": "StartTest\nInitialiseCounter\n'\n'\nDo some testing\n'\n'\nCheckPoint\nGetElapsedTime\nCompare ElapsedTime with stored elapsed time from last run\nIf difference is outside tolerence log an error\n"
},
{
"answer_id": 166197,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 0,
"selected": false,
"text": "assert"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165811",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17382/"
] |
165,828
|
<p>I need to queue events and tasks for external systems in a reliable/transactional way. Using things like MSMQ or ActiveMQ look very seductive, but the transactional part becomes complicated (MSDTC, etc).</p>
<p>We could use the database (SQL Server 2005+, Oracle 9+) and achieve easier transactional support, but the queuing part becomes uglier.</p>
<p>Neither route seems all that great and is filled with nasty gotchas and edge cases.</p>
<p>Can someone offer some practical guidance in this matter?</p>
<p>Think: E/C/A or a scheduled task engine that wakes up every so often and see if there are any scheduled tasks that need running at this time (i.e. next-run-date has passed, but expiration-date has not yet been reached).</p>
|
[
{
"answer_id": 165876,
"author": "csmba",
"author_id": 350,
"author_profile": "https://Stackoverflow.com/users/350",
"pm_score": 4,
"selected": true,
"text": "SELECT TOP 1 @Id = callid\nFROM callqtbl WITH (READPAST, XLOCK)\nwhere 1=1 ORDER BY xx,yy\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10862/"
] |
165,883
|
<p>Suppose I have a class with some attributes. How is it best (in the Pythonic-OOP) sense to access these attributes ? Just like <code>obj.attr</code> ? Or perhaps write get accessors ?
What are the accepted naming styles for such things ?</p>
<p><strong>Edit:</strong>
Can you elaborate on the best-practices of naming attributes with a single or double leading underscore ? I see in most modules that a single underscore is used.</p>
<hr>
<p>If this question has already been asked (and I have a hunch it has, though searching didn't bring results), please point to it - and I will close this one.</p>
|
[
{
"answer_id": 165892,
"author": "monkut",
"author_id": 24718,
"author_profile": "https://Stackoverflow.com/users/24718",
"pm_score": 2,
"selected": false,
"text": ">>> class myclass:\n... x = 'hello'\n...\n>>>\n>>> class_inst = myclass()\n>>> class_inst.x\n'hello'\n>>> class_inst.x = 'world'\n>>> class_inst.x\n'world'\n >>> dir(class_inst)\n['__doc__', '__module__', 'x']\n"
},
{
"answer_id": 165901,
"author": "Vasil",
"author_id": 7883,
"author_profile": "https://Stackoverflow.com/users/7883",
"pm_score": -1,
"selected": false,
"text": "> __getattr__\n > __setattr__\n"
},
{
"answer_id": 165911,
"author": "willurd",
"author_id": 1943957,
"author_profile": "https://Stackoverflow.com/users/1943957",
"pm_score": 6,
"selected": true,
"text": ">>> class MyClass:\n... myAttribute = 0\n... \n>>> c = MyClass()\n>>> c.myAttribute \n0\n>>> c.myAttribute = 1\n>>> c.myAttribute\n1\n"
},
{
"answer_id": 166073,
"author": "Anders Waldenborg",
"author_id": 24082,
"author_profile": "https://Stackoverflow.com/users/24082",
"pm_score": 3,
"selected": false,
"text": "__add__"
},
{
"answer_id": 166098,
"author": "Thomas Wouters",
"author_id": 17624,
"author_profile": "https://Stackoverflow.com/users/17624",
"pm_score": 6,
"selected": false,
"text": ">>> class ClassA:\n... def __init__(self):\n... self._single = \"Single\"\n... self.__double = \"Double\"\n... def getSingle(self):\n... return self._single\n... def getDouble(self):\n... return self.__double\n... \n>>> class ClassB(ClassA):\n... def getSingle_B(self):\n... return self._single\n... def getDouble_B(self):\n... return self.__double\n... \n>>> a = ClassA()\n>>> b = ClassB()\n a._single b._single _single ClassA >>> a._single, b._single\n('Single', 'Single')\n>>> a.getSingle(), b.getSingle(), b.getSingle_B()\n('Single', 'Single', 'Single')\n __double a b >>> a.__double\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nAttributeError: ClassA instance has no attribute '__double'\n>>> b.__double\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nAttributeError: ClassB instance has no attribute '__double'\n ClassA >>> a.getDouble(), b.getDouble()\n('Double', 'Double')\n ClassB >>> b.getDouble_B()\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"<stdin>\", line 5, in getDouble_B\nAttributeError: ClassB instance has no attribute '_ClassB__double'\n __double ClassA self.__double self._ClassA__double ClassB ClassB __double ClassA __double >>> a._ClassA__double, b._ClassA__double\n('Double', 'Double')\n getattr()"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8206/"
] |
165,887
|
<p>What's the easiest way to compute the amount of working days since a date? VB.NET preferred, but C# is okay.</p>
<p>And by "working days", I mean all days excluding Saturday and Sunday. If the algorithm can also take into account a list of specific 'exclusion' dates that shouldn't count as working days, that would be gravy. </p>
<p>Thanks in advance for the contributed genius.</p>
|
[
{
"answer_id": 165902,
"author": "Andrew Kennan",
"author_id": 22506,
"author_profile": "https://Stackoverflow.com/users/22506",
"pm_score": 4,
"selected": false,
"text": "DateTime start = new DateTime(2008, 10, 3);\nDateTime end = new DateTime(2008, 12, 31);\nint workingDays = 0;\nwhile( start < end ) {\n if( start.DayOfWeek != DayOfWeek.Saturday\n && start.DayOfWeek != DayOfWeek.Sunday ) {\n workingDays++;\n }\n start = start.AddDays(1);\n}\n"
},
{
"answer_id": 165929,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 5,
"selected": true,
"text": "DateTime start = DateTime.Now;\nDateTime end = start.AddDays(9);\nIEnumerable<DateTime> holidays = new DateTime[0];\n\n// basic data\nint days = (int)(end - start).TotalDays;\nint weeks = days / 7;\n\n// check for a weekend in a partial week from start.\nif (7- (days % 7) <= (int)start.DayOfWeek)\n days--;\nif (7- (days % 7) <= (int)start.DayOfWeek)\n days--;\n\n// lose the weekends\ndays -= weeks * 2;\n\nforeach (DateTime dt in holidays)\n{\n if (dt > start && dt < end)\n days--;\n}\n"
},
{
"answer_id": 6914432,
"author": "Chris Betlach",
"author_id": 874937,
"author_profile": "https://Stackoverflow.com/users/874937",
"pm_score": 2,
"selected": false,
"text": "Function CalcBusinessDays(ByVal DStart As Date, ByVal DEnd As Date) As Decimal\n\n Dim Days As Decimal = DateDiff(DateInterval.Day, DStart, DEnd)\n Dim Weeks As Integer = Days / 7\n Dim BusinessDays As Decimal = Days - (Weeks * 2)\n Return BusinessDays\n Days = Nothing\n Weeks = Nothing\n BusinessDays = Nothing\n\nEnd Function\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17235/"
] |
165,931
|
<p>In a program I work on, I have a lot of code as follows:</p>
<pre><code>pthread_mutex_lock( &frame->mutex );
frame->variable = variable;
pthread_mutex_unlock( &frame->mutex );
</code></pre>
<p>This is clearly a waste of CPU cycles if the middle instruction can just be replaced with an atomic store. I know that gcc is quite capable of this, but I haven't been able to find much documentation on such simple thread-safe atomic operations. How would I replace this set of code with an atomic operation?</p>
<p>(I know that simple stores should theoretically be atomic, but I don't want to have to hope that the optimizer isn't screwing up their atomic-ness at some point in the process.)</p>
<p>Clarification: I do not need them to be strictly atomic; these variables are solely used for thread synchronization. That is, Thread B reads the value, checks if its correct, and if its not correct, it sleeps. So even if Thread A updates the value and Thread B doesn't realize its updated, that isn't a problem, since that just means Thread B sleeps when it didn't really need to, and when it wakes up, the value will be correct.</p>
|
[
{
"answer_id": 171110,
"author": "ephemient",
"author_id": 20713,
"author_profile": "https://Stackoverflow.com/users/20713",
"pm_score": 2,
"selected": false,
"text": "pthread_mutex_lock volatile volatile asm(\"\" : \"=m\" (variable));\nframe->variable = variable;\n variable"
},
{
"answer_id": 2202932,
"author": "erick2red",
"author_id": 253287,
"author_profile": "https://Stackoverflow.com/users/253287",
"pm_score": 0,
"selected": false,
"text": "'sig_atomic_t'"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165931",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11206/"
] |
165,938
|
<p>Is there a way to step through a .bat script? The thing is, I have a build script , which calls a lot of other scripts, and I would like to see what is the order in which they are called, so that I may know where exactly I have to go about and add my modifications.</p>
|
[
{
"answer_id": 165939,
"author": "jop",
"author_id": 11830,
"author_profile": "https://Stackoverflow.com/users/11830",
"pm_score": 2,
"selected": false,
"text": "echo pause"
},
{
"answer_id": 165942,
"author": "Eric Schoonover",
"author_id": 3957,
"author_profile": "https://Stackoverflow.com/users/3957",
"pm_score": 7,
"selected": true,
"text": "echo pause echo"
},
{
"answer_id": 62283214,
"author": "aschipfl",
"author_id": 5047996,
"author_profile": "https://Stackoverflow.com/users/5047996",
"pm_score": 2,
"selected": false,
"text": "cmd.exe"
},
{
"answer_id": 63363699,
"author": "Arpan Saini",
"author_id": 7353562,
"author_profile": "https://Stackoverflow.com/users/7353562",
"pm_score": 2,
"selected": false,
"text": "cmd \\k"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11234/"
] |
165,951
|
<p>Say I have a third party Application that does background work, but prints out all errors and messages to the console. This means, that currently, we have to keep a user logged on to the server, and restart the application (double-click) every time we reboot.</p>
<p><em>Not so very cool.</em></p>
<p>I was kind of sure, that there was an easy way to do this - a generic service wrapper, that can be configured with a log file for <code>stdout</code> and <code>stderr</code>.</p>
<p>I did check <code>svchost.exe</code>, but <a href="http://www.google.ch/url?sa=t&source=web&ct=res&cd=2&url=http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F314056&ei=38DlSPGDLYbS0gWaupyXCw&usg=AFQjCNFuvFUsrk_qf9ATt6N_Csh4dMJZnw&sig2=UZLsm65gFNCdsUqszVgHWQ" rel="noreferrer">according to this site</a>, its only for DLL stuff. Pity.</p>
<p><strong>EDIT:</strong> The application needs to be started from a batch file. FireDaemon seems to do the trick, but I think it is a bit overkill, for something that can be done in <10 lines of python code... Oh well, <em>Not Invented Here</em>...</p>
|
[
{
"answer_id": 165955,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 5,
"selected": true,
"text": "srvany.exe srvany.exe [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\MyService\\Parameters]\n\"Application\"=\"C:\\\\Windows\\\\System32\\\\cmd.exe\"\n\"AppParameters\"=\"/C C:\\\\My\\\\Batch\\\\Script.cmd\"\n\"AppDirectory\"=\"C:\\\\My\\\\Batch\"\n RegEdit"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2260/"
] |
165,975
|
<p>What is the most reliable and secure way to determine what page either sent, or called (via AJAX), the current page. I don't want to use the <code>$_SERVER['HTTP_REFERER']</code>, because of the (lack of) reliability, and I need the page being called to only come from requests originating on my site.<br /><br />
Edit: I am looking to verify that a script that preforms a series of actions is being called from a page on my website.</p>
|
[
{
"answer_id": 12609613,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "if (!empty($_SERVER['HTTP_REFERER'])) {\n header(\"Location: \" . $_SERVER['HTTP_REFERER']);\n} else {\n header(\"Location: index.php\");\n}\nexit;\n"
},
{
"answer_id": 13703882,
"author": "We0",
"author_id": 1852803,
"author_profile": "https://Stackoverflow.com/users/1852803",
"pm_score": 5,
"selected": false,
"text": "$token = uniqid(mt_rand(), TRUE);\n$_SESSION['token'] = $token;\n$url = \"http://example.com/index.php?token={$token}\";\n if(empty($_GET['token']) || $_GET['token'] !== $_SESSION['token'])\n{\n show_404();\n} \n\n//Continue with the rest of code\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165975",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/115/"
] |
165,987
|
<p>My division has been tasked with recording the morning presentation audio for future use, using the built-in Windows Sound Recorder. Because of human nature, we don't always remember to start it on time. </p>
<p>Windows doesn't have a built-in equivalent to the Unix <strong>cron</strong> function. Besides installing a new software program (which will take time, possibly cost money, and require IA certification), is there an easy way to automate the recording?</p>
<p>I'm not adverse to writing a simple Python script for it, but I haven't programmed for Windows before; I don't know the APIs or anything required for this type of program.</p>
<hr>
<p><strong>Edit</strong>
Thanks for the responses. I feel like an imbecile. I don't normally use Windows computers so I wasn't aware that Windows had the Task Scheduler.</p>
<p>However, when I tested it with the recorder program, all it did was open the program; it didn't actually start recording. How do I get it to actually start recording when it is opened?</p>
|
[
{
"answer_id": 166555,
"author": "Craig Norton",
"author_id": 24804,
"author_profile": "https://Stackoverflow.com/users/24804",
"pm_score": 3,
"selected": true,
"text": "set WshShell = WScript.CreateObject(\"WScript.Shell\") \nWScript.Sleep(100)\nWshShell.Run \"%SystemRoot%\\system32\\sndrec32.exe\" \nWScript.Sleep(100)\nWshShell.AppActivate \"Sound - Sound Recorder\" \nWScript.Sleep(100)\nWshShell.SendKeys \" \" \nWScript.Sleep(100)\n"
},
{
"answer_id": 169552,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 1,
"selected": false,
"text": "Run ( @SystemDir + \"\\sndrec32.exe\", \"workingdir\" )\nSleep(5000) ;five seconds\nWinActivate( \"Sound - Sound Recorder\" )\nSleep(100)\nSend( \" \" )\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/165987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18676/"
] |
166,004
|
<p>I am facing a performance issue on a multi-core (8+) architecture with software written in C++ / VistualStudio / WindowsXP.</p>
<p>Suddenly I realized that I have no idea of the performances of my L1 and L2 cache and CPU->to->Memory bandwidth.</p>
<p>I have tested several tools (including VTune, Glowcode, etc, etc) but all of them fails when tested on load in a multicore architecture (which is the very reason why I need them!).</p>
<p>Can you suggest any other tool which is not so fancy in doing graphs but can give me at least few indications of my cache/memory performances or can suggest snippets of code to manually instrument my application?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 166555,
"author": "Craig Norton",
"author_id": 24804,
"author_profile": "https://Stackoverflow.com/users/24804",
"pm_score": 3,
"selected": true,
"text": "set WshShell = WScript.CreateObject(\"WScript.Shell\") \nWScript.Sleep(100)\nWshShell.Run \"%SystemRoot%\\system32\\sndrec32.exe\" \nWScript.Sleep(100)\nWshShell.AppActivate \"Sound - Sound Recorder\" \nWScript.Sleep(100)\nWshShell.SendKeys \" \" \nWScript.Sleep(100)\n"
},
{
"answer_id": 169552,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 1,
"selected": false,
"text": "Run ( @SystemDir + \"\\sndrec32.exe\", \"workingdir\" )\nSleep(5000) ;five seconds\nWinActivate( \"Sound - Sound Recorder\" )\nSleep(100)\nSend( \" \" )\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20042/"
] |
166,023
|
<p>I'm supporting a site that still uses mixed ASP.NET and <a href="http://en.wikipedia.org/wiki/Active_Server_Pages" rel="nofollow noreferrer">ASP Classic</a>. The user receives a 'You are not authorized' error page while accessing certain ASP Classic page. I've checked her active directory account and she could access other pages in the said site. Can it be attributed to classic ASP or to IIS?</p>
|
[
{
"answer_id": 166891,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 3,
"selected": true,
"text": "Request.ServerVariables(\"AUTH_USER\")"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166023",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24755/"
] |
166,028
|
<p>I have been working in a web project(asp.net) for around six months. The final product is about to go live. The project uses SQL Server as the database. We have done performance testing with some large volumes of data, results show that performance degrades when data becomes too large, say 2 million rows (timeout issues, delayed reponses, etc). At first we were using fully normailized database, but now we made it partially normalized due to performance issues (to reduce joins). First of all, is it the right decision?
Plus what are the possible solutions when data size becomes very large, as the no. of clients increase in future? </p>
<p>I would like to add further:</p>
<ul>
<li>2 million rows are entity tables, tables resolving the relations have much larger rows.</li>
<li>Performance degrades when data + no. of users increases. </li>
<li>Denormalization was done after identifying the heavily used queries.</li>
<li>We are also using some heavy amount of xml columns and xquery. Can this be the cause?</li>
<li>A bit off the topic, some folks in my project say that dynamic sql query is faster than a stored procedure approach. They have done some kind of performance testing to prove their point. I think the opposite is true. Some of the heavily used queries are dynamicaly created where as most of other queries are encapsulated in stored procedures.</li>
</ul>
|
[
{
"answer_id": 166359,
"author": "Philippe Grondier",
"author_id": 11436,
"author_profile": "https://Stackoverflow.com/users/11436",
"pm_score": 4,
"selected": false,
"text": "DBASEIII"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166028",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965628/"
] |
166,033
|
<p>What is meant by ‘value semantics’, and what is meant by ‘implicit pointer semantics’?</p>
|
[
{
"answer_id": 166039,
"author": "David Pierre",
"author_id": 18296,
"author_profile": "https://Stackoverflow.com/users/18296",
"pm_score": 5,
"selected": true,
"text": "void foo(Bar * b) ...\n... b->bar() ...\n void foo(Bar b) ...\n... b.bar() ...\n"
},
{
"answer_id": 166041,
"author": "Andre Bossard",
"author_id": 21027,
"author_profile": "https://Stackoverflow.com/users/21027",
"pm_score": 1,
"selected": false,
"text": "implicit pointer semantics Pass-by-Value semantics"
},
{
"answer_id": 166048,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 4,
"selected": false,
"text": "int x = 1;\nint y = x;\nx = 2; // y remains the same!\n void f(int x) {\n x = 5;\n}\n\nint a = 1;\nf(a);\n// a is still 1\n int double boolean char class Foo {\n int x;\n\n public Foo(int x) { this.x = x; }\n}\n\nFoo a = new Foo(42);\nFoo b = a; // b and a share the same instance!\na.x = 32;\n//b.x is now also changed.\n String Integer void f(Foo foo) {\n foo.x = 42;\n}\n\nvoid g(Foo foo) {\n foo = new Foo(42);\n}\n\nFoo a = new Foo(23);\nf(a);\n// a.x is now 42!\n\nFoo b = new Foo(1);\ng(b);\n// b remains unchanged!\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22076/"
] |
166,044
|
<p>When writing a batch file to automate something on a Windows box, I've needed to pause its execution for several seconds (usually in a test/wait loop, waiting for a process to start). At the time, the best solution I could find uses ping (I kid you not) to achieve the desired effect. I've found a better write-up of it <a href="http://malektips.com/dos0017.html" rel="noreferrer">here</a>, which describes a callable "wait.bat", implemented as follows:</p>
<pre><code>@ping 127.0.0.1 -n 2 -w 1000 > nul
@ping 127.0.0.1 -n %1% -w 1000> nul
</code></pre>
<p>You can then include calls to wait.bat in your own batch file, passing in the number of seconds to sleep.</p>
<p><a href="http://malektips.com/xp_dos_0002.html" rel="noreferrer">Apparently the Windows 2003 Resource Kit provides a Unix-like sleep command</a> (at last!). In the meantime, for those of us still using Windows XP, Windows 2000 or (sadly) <a href="http://en.wikipedia.org/wiki/Windows_NT" rel="noreferrer">Windows NT</a>, is there a better way?</p>
<p>I modified the <code>sleep.py</code> script in the <a href="https://stackoverflow.com/questions/166044/sleeping-in-a-dos-batch-file#166290">accepted answer</a>, so that it defaults to one second if no arguments are passed on the command line:</p>
<pre class="lang-py prettyprint-override"><code>import time, sys
time.sleep(float(sys.argv[1]) if len(sys.argv) > 1 else 1)
</code></pre>
|
[
{
"answer_id": 166053,
"author": "Daren Thomas",
"author_id": 2260,
"author_profile": "https://Stackoverflow.com/users/2260",
"pm_score": 2,
"selected": false,
"text": "sleep cygwin.dll"
},
{
"answer_id": 166058,
"author": "Luk",
"author_id": 5789,
"author_profile": "https://Stackoverflow.com/users/5789",
"pm_score": 4,
"selected": false,
"text": "SLEEP.exe Usage: sleep time-to-sleep-in-seconds\n sleep [-m] time-to-sleep-in-milliseconds\n sleep [-c] commited-memory ratio (1%-100%)\n"
},
{
"answer_id": 166093,
"author": "John Sibly",
"author_id": 1078,
"author_profile": "https://Stackoverflow.com/users/1078",
"pm_score": 4,
"selected": false,
"text": "#include <tchar.h>\n#include <stdio.h>\n#include \"Windows.h\"\n\nint _tmain(int argc, _TCHAR* argv[])\n{\n if (argc == 2)\n {\n _tprintf(_T(\"Sleeping for %s ms\\n\"), argv[1]);\n Sleep(_tstoi(argv[1]));\n }\n else\n {\n _tprintf(_T(\"Wrong number of arguments.\\n\"));\n }\n return 0;\n}\n"
},
{
"answer_id": 166187,
"author": "Tooony",
"author_id": 23864,
"author_profile": "https://Stackoverflow.com/users/23864",
"pm_score": 2,
"selected": false,
"text": "sleep Sleep kernel32.dll private Declare Sub Sleep Lib \"kernel32\" Alias \"Sleep\" (byval dwMilliseconds as Long)\n [DllImport(\"kernel32.dll\")]\nstatic extern void Sleep(uint dwMilliseconds);\n sleep() Sleep()"
},
{
"answer_id": 166290,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 5,
"selected": true,
"text": "timeout import time, sys\n\ntime.sleep(float(sys.argv[1]))\n sleep sleep.py .PY"
},
{
"answer_id": 1092731,
"author": "Liam",
"author_id": 18333,
"author_profile": "https://Stackoverflow.com/users/18333",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading;\n\nnamespace sleep\n{\n class Program\n {\n static void Main(string[] args)\n {\n if (args.Length == 1)\n {\n double time = Double.Parse(args[0]);\n Thread.Sleep((int)(time*1000));\n }\n else\n {\n Console.WriteLine(\"Usage: sleep <seconds>\\nExample: sleep 10\");\n }\n }\n }\n}\n"
},
{
"answer_id": 1202058,
"author": "Peter Mortensen",
"author_id": 63550,
"author_profile": "https://Stackoverflow.com/users/63550",
"pm_score": 2,
"selected": false,
"text": "perl -e \"sleep 7\"\n usleep() nanosleep()"
},
{
"answer_id": 1304768,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 4,
"selected": false,
"text": "ping 127.0.0.1 -n 11 -w 1000 >nul: 2>nul:\n -w ping"
},
{
"answer_id": 1811248,
"author": "mlsteeves",
"author_id": 68034,
"author_profile": "https://Stackoverflow.com/users/68034",
"pm_score": 3,
"selected": false,
"text": "choice /d y /t 5 > nul\n"
},
{
"answer_id": 1811314,
"author": "Blake7",
"author_id": 184135,
"author_profile": "https://Stackoverflow.com/users/184135",
"pm_score": 3,
"selected": false,
"text": "if (WScript.Arguments.Count() == 1)\n WScript.Sleep(WScript.Arguments(0)*1000);\nelse\n WScript.Echo(\"Usage: cscript wait.js seconds\");\n"
},
{
"answer_id": 5437271,
"author": "Brent Stewart",
"author_id": 353186,
"author_profile": "https://Stackoverflow.com/users/353186",
"pm_score": 3,
"selected": false,
"text": "@ping 127.0.0.1 -n 11 -w 1000 > null\n"
},
{
"answer_id": 5438142,
"author": "Joey",
"author_id": 73070,
"author_profile": "https://Stackoverflow.com/users/73070",
"pm_score": 3,
"selected": false,
"text": "ping ping -n <numberofseconds+1> localhost >nul 2>&1\n ping -n 6 localhost >nul 2>&1\n timeout timeout 6 >nul\n"
},
{
"answer_id": 5483958,
"author": "Blorgbeard",
"author_id": 369,
"author_profile": "https://Stackoverflow.com/users/369",
"pm_score": 8,
"selected": false,
"text": "timeout c:\\> timeout /?\n\nTIMEOUT [/T] timeout [/NOBREAK]\n\nDescription:\n This utility accepts a timeout parameter to wait for the specified\n time period (in seconds) or until any key is pressed. It also\n accepts a parameter to ignore the key press.\n\nParameter List:\n /T timeout Specifies the number of seconds to wait.\n Valid range is -1 to 99999 seconds.\n\n /NOBREAK Ignore key presses and wait specified time.\n\n /? Displays this help message.\n\nNOTE: A timeout value of -1 means to wait indefinitely for a key press.\n\nExamples:\n TIMEOUT /?\n TIMEOUT /T 10\n TIMEOUT /T 300 /NOBREAK\n TIMEOUT /T -1\n C:\\>echo 1 | timeout /t 1 /nobreak\nERROR: Input redirection is not supported, exiting the process immediately.\n"
},
{
"answer_id": 5822491,
"author": "Chris Moschini",
"author_id": 176877,
"author_profile": "https://Stackoverflow.com/users/176877",
"pm_score": 1,
"selected": false,
"text": "choice /n /c y /d y /t 5 > NUL\n choice"
},
{
"answer_id": 6806192,
"author": "Aacini",
"author_id": 778560,
"author_profile": "https://Stackoverflow.com/users/778560",
"pm_score": 4,
"selected": false,
"text": "@ECHO OFF\nREM DELAY seconds\n\nREM GET ENDING SECOND\nFOR /F \"TOKENS=1-3 DELIMS=:.\" %%A IN (\"%TIME%\") DO SET /A H=%%A, M=1%%B%%100, S=1%%C%%100, ENDING=(H*60+M)*60+S+%1\n\nREM WAIT FOR SUCH A SECOND\n:WAIT\nFOR /F \"TOKENS=1-3 DELIMS=:.\" %%A IN (\"%TIME%\") DO SET /A H=%%A, M=1%%B%%100, S=1%%C%%100, CURRENT=(H*60+M)*60+S\nIF %CURRENT% LSS %ENDING% GOTO WAIT\n"
},
{
"answer_id": 6852798,
"author": "daniel",
"author_id": 866502,
"author_profile": "https://Stackoverflow.com/users/866502",
"pm_score": 4,
"selected": false,
"text": "ping -w -n ECHO Waiting 15 seconds\n\nPING 1.1.1.1 -n 1 -w 15000 > NUL\n or\nPING -n 15 -w 1000 127.1 >NUL\n"
},
{
"answer_id": 8775655,
"author": "Alex Robinson",
"author_id": 972805,
"author_profile": "https://Stackoverflow.com/users/972805",
"pm_score": 2,
"selected": false,
"text": "python -c \"import time;time.sleep(6.5)\"\n"
},
{
"answer_id": 14404448,
"author": "SuperKael",
"author_id": 1792474,
"author_profile": "https://Stackoverflow.com/users/1792474",
"pm_score": 2,
"selected": false,
"text": "@echo off\nset /a WAITTIME=%1+1\nPING 127.0.0.1 -n %WAITTIME% > nul\ngoto:eof\n CALL WAIT.bat <whole number of seconds without quotes>\n"
},
{
"answer_id": 14574706,
"author": "Hossy",
"author_id": 2020158,
"author_profile": "https://Stackoverflow.com/users/2020158",
"pm_score": 2,
"selected": false,
"text": "%TIME% H:MM:SS.CC :delay\nSET DELAYINPUT=%1\nSET /A DAYS=DELAYINPUT/8640000\nSET /A DELAYINPUT=DELAYINPUT-(DAYS*864000)\n\n::Get ending centisecond (10 milliseconds)\nFOR /F \"tokens=1-4 delims=:.\" %%A IN (\"%TIME%\") DO SET /A H=%%A, M=1%%B%%100, S=1%%C%%100, X=1%%D%%100, ENDING=((H*60+M)*60+S)*100+X+DELAYINPUT\nSET /A DAYS=DAYS+ENDING/8640000\nSET /A ENDING=ENDING-(DAYS*864000)\n\n::Wait for such a centisecond\n:delay_wait\nFOR /F \"tokens=1-4 delims=:.\" %%A IN (\"%TIME%\") DO SET /A H=%%A, M=1%%B%%100, S=1%%C%%100, X=1%%D%%100, CURRENT=((H*60+M)*60+S)*100+X\nIF DEFINED LASTCURRENT IF %CURRENT% LSS %LASTCURRENT% SET /A DAYS=DAYS-1\nSET LASTCURRENT=%CURRENT%\nIF %CURRENT% LSS %ENDING% GOTO delay_wait\nIF %DAYS% GTR 0 GOTO delay_wait\nGOTO :EOF\n"
},
{
"answer_id": 16803440,
"author": "Niall Connaughton",
"author_id": 114200,
"author_profile": "https://Stackoverflow.com/users/114200",
"pm_score": 3,
"selected": false,
"text": "powershell -command \"Start-Sleep -s 1\"\n powershell -command \"$sleepUntil = [DateTime]::Parse('%date% %time%').AddSeconds(5); $sleepDuration = $sleepUntil.Subtract((get-date)).TotalMilliseconds; start-sleep -m $sleepDuration\"\n"
},
{
"answer_id": 18644875,
"author": "djangofan",
"author_id": 118228,
"author_profile": "https://Stackoverflow.com/users/118228",
"pm_score": 0,
"selected": false,
"text": "@ECHO off\nSET TITLETEXT=Sleep\nTITLE %TITLETEXT%\nCALL :sleep 5\nGOTO :END\n:: Function Section\n:sleep ARG\nECHO Pausing...\nFOR /l %%a in (%~1,-1,1) DO (TITLE Script %TITLETEXT% -- time left^\n %%as&PING.exe -n 2 -w 1000 127.1>NUL)\nEXIT /B 0\n:: End of script\n:END\npause\n::this is EOF\n"
},
{
"answer_id": 20994851,
"author": "npocmaka",
"author_id": 388389,
"author_profile": "https://Stackoverflow.com/users/388389",
"pm_score": 0,
"selected": false,
"text": "W32TM w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:N >nul 2>&1\n typeperf \"\\System\\Processor Queue Length\" -si N -sc 1 >nul\n start \"\" /wait /min /realtime mshta \"javascript:setTimeout(function(){close();},5000)\"\n .net @if (@X)==(@Y) @end /* JScript comment\n@echo off\nsetlocal\n::del %~n0.exe /q /f\n::\n:: For precision better call this like\n:: call waitMS 500\n:: in order to skip compilation in case there's already built .exe\n:: as without pointed extension first the .exe will be called due to the ordering in PATEXT variable\n::\n::\nfor /f \"tokens=* delims=\" %%v in ('dir /b /s /a:-d /o:-n \"%SystemRoot%\\Microsoft.NET\\Framework\\*jsc.exe\"') do (\n set \"jsc=%%v\"\n)\n\nif not exist \"%~n0.exe\" (\n \"%jsc%\" /nologo /w:0 /out:\"%~n0.exe\" \"%~dpsfnx0\"\n)\n\n\n%~n0.exe %*\n\nendlocal & exit /b %errorlevel%\n\n\n*/\n\n\nimport System;\nimport System.Threading;\n\nvar arguments:String[] = Environment.GetCommandLineArgs();\nfunction printHelp(){\n Console.WriteLine(arguments[0]+\" N\");\n Console.WriteLine(\" N - milliseconds to wait\");\n Environment.Exit(0); \n}\n\nif(arguments.length<2){\n printHelp();\n}\n\ntry{\n var wait:Int32=Int32.Parse(arguments[1]);\n System.Threading.Thread.Sleep(wait);\n}catch(err){\n Console.WriteLine('Invalid Number passed');\n Environment.Exit(1);\n}\n"
},
{
"answer_id": 21252806,
"author": "EpicNinjaCheese",
"author_id": 3218259,
"author_profile": "https://Stackoverflow.com/users/3218259",
"pm_score": 1,
"selected": false,
"text": "echo WScript.sleep WScript.Arguments(0) >\"%cd%\\sleeper.vbs\"\n start /WAIT \"\" \"%cd%\\sleeper.vbs\" \"1000\"\n del /f /q \"%cd%\\sleeper.vbs\"\n echo WScript.sleep WScript.Arguments(0) >\"%cd%\\sleeper.vbs\"\nstart /WAIT \"\" \"%cd%\\sleeper.vbs\" \"1000\"\ndel /f /q \"%cd%\\sleeper.vbs\"\n"
},
{
"answer_id": 21433296,
"author": "Anonymous Coward",
"author_id": 3106507,
"author_profile": "https://Stackoverflow.com/users/3106507",
"pm_score": 0,
"selected": false,
"text": "/q sleepOrDelayExecution 500 dir \\ /s\n @echo off\nif \"%1\" == \"\" goto end\nif NOT %1 GTR 0 goto end\nsetlocal\nset sleepfn=\"%temp%\\sleep%random%.vbs\"\necho WScript.Sleep(%1) >%sleepfn%\nif NOT %sleepfn% == \"\" if NOT EXIST %sleepfn% goto end\ncscript %sleepfn% >nul\nif NOT %sleepfn% == \"\" if EXIST %sleepfn% del %sleepfn%\nfor /f \"usebackq tokens=1*\" %%i in (`echo %*`) DO @ set params=%%j\n%params%\n:end\n"
},
{
"answer_id": 21586700,
"author": "Tato",
"author_id": 3276779,
"author_profile": "https://Stackoverflow.com/users/3276779",
"pm_score": 2,
"selected": false,
"text": "timeout numbersofseconds /nobreak > nul\n"
},
{
"answer_id": 21941058,
"author": "mafu",
"author_id": 39590,
"author_profile": "https://Stackoverflow.com/users/39590",
"pm_score": 3,
"selected": false,
"text": "192.0.2.x ping 192.0.2.1 -n 1 -w 123 >nul 127.255.255.255"
},
{
"answer_id": 24022832,
"author": "mgthomas99",
"author_id": 3704301,
"author_profile": "https://Stackoverflow.com/users/3704301",
"pm_score": 3,
"selected": false,
"text": "timeout /t <seconds> <options>\n timeout /t 2 /nobreak >NUL\n /nobreak NUL timeout ping timeout timeout ping"
},
{
"answer_id": 24990713,
"author": "FluorescentGreen5",
"author_id": 3881189,
"author_profile": "https://Stackoverflow.com/users/3881189",
"pm_score": -1,
"selected": false,
"text": "ping -n X 127.0.0.1 > nul\n"
},
{
"answer_id": 41981822,
"author": "Andry",
"author_id": 2672125,
"author_profile": "https://Stackoverflow.com/users/2672125",
"pm_score": 1,
"selected": false,
"text": "@echo off\nsetlocal EnableDelayedExpansion \necho !TIME! & pathping localhost -n -q 1 -p %~1 2>&1 > nul & echo !TIME!\n > sleep 10\n17:01:33,57\n17:01:33,60\n\n> sleep 20\n17:03:56,54\n17:03:56,58\n\n> sleep 50\n17:04:30,80\n17:04:30,87\n\n> sleep 100\n17:07:06,12\n17:07:06,25\n\n> sleep 200\n17:07:08,42\n17:07:08,64\n\n> sleep 500\n17:07:11,05\n17:07:11,57\n\n> sleep 800\n17:07:18,98\n17:07:19,81\n\n> sleep 1000\n17:07:22,61\n17:07:23,62\n\n> sleep 1500\n17:07:27,55\n17:07:29,06\n"
},
{
"answer_id": 59511984,
"author": "nonopolarity",
"author_id": 325418,
"author_profile": "https://Stackoverflow.com/users/325418",
"pm_score": 1,
"selected": false,
"text": "node -e 'setTimeout(a => a, 5000)'\n"
},
{
"answer_id": 62525634,
"author": "Lumito",
"author_id": 13248902,
"author_profile": "https://Stackoverflow.com/users/13248902",
"pm_score": 2,
"selected": false,
"text": "TIMEOUT /NOBREAK 5 >NUL 2>NUL\n ping localhost -n 5 >NUL 2>NUL\n localhost -n ping 1.1.1.1 -n 5 >nul\n localhost 1.1.1.1 ping 127.0.0.1 -n 5 >nul\n ping [::1] -n 5 >nul\n localhost"
},
{
"answer_id": 71616409,
"author": "aakash4dev",
"author_id": 17576982,
"author_profile": "https://Stackoverflow.com/users/17576982",
"pm_score": 0,
"selected": false,
"text": "timeout timeout 10 cmd powershell"
},
{
"answer_id": 72579329,
"author": "Vopel",
"author_id": 11777065,
"author_profile": "https://Stackoverflow.com/users/11777065",
"pm_score": 0,
"selected": false,
"text": "@echo off\n:: turns off command-echoing\n\necho/Script will now wait for 2.5 seconds & echo/\n:: prints a line followed by a linebreak\n\ncall:sleep 2500\n:: waits for two-and-a-half seconds (2500 milliseconds)\n\necho/Done! Press any key to continue ... & pause >NUL\n:: prints a line and pauses\n\ngoto:EOF\n:: prevents the batch file from executing functions beyond this point\n\n\n::--FUNCTIONS--::\n\n:SLEEP\n:: call this function with the time to wait (in milliseconds)\n\nping 203.0.113.0 -n 1 -w \"%~1\" >NUL\n:: 203.0.113.0 = TEST-NET-3 reserved IP; -n = ping count; -w = timeout\n\ngoto:EOF\n:: ends the call subroutine\n ping 203.0.113.0 -n 1 -w >NUL"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166044",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2193/"
] |
166,051
|
<p>So most Java resources when speaking of packages mention a <code>com.yourcompany.project</code> setup. However, I do not work for a company, and don't have a website. Are there any naming conventions that are common? An email address, perhaps?</p>
|
[
{
"answer_id": 166069,
"author": "Stu Thompson",
"author_id": 2961,
"author_profile": "https://Stackoverflow.com/users/2961",
"pm_score": 5,
"selected": true,
"text": "import java.util.*;\nimport bernard.myProject.*;\nimport org.apache.commons.lang.*;\n"
},
{
"answer_id": 166294,
"author": "belugabob",
"author_id": 13397,
"author_profile": "https://Stackoverflow.com/users/13397",
"pm_score": 2,
"selected": false,
"text": "bernard.surname.net madeupname.net"
},
{
"answer_id": 169807,
"author": "Alan",
"author_id": 17205,
"author_profile": "https://Stackoverflow.com/users/17205",
"pm_score": 0,
"selected": false,
"text": "org.<myname>.*"
},
{
"answer_id": 190084,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 0,
"selected": false,
"text": "com.blah.blah.blah"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/61/"
] |
166,080
|
<p>Am working on sybase ASE 15. Looking for something like this</p>
<pre><code>Select * into #tmp exec my_stp;
</code></pre>
<p>my_stp returns 10 data rows with two columns in each row.</p>
|
[
{
"answer_id": 175830,
"author": "AdamH",
"author_id": 21081,
"author_profile": "https://Stackoverflow.com/users/21081",
"pm_score": 3,
"selected": false,
"text": "\n --You must use this whole script to recreate the sproc \n create table #mine\n (col1 varchar(3),\n col2 varchar(3))\n go\n create procedure my_stp\n as\n insert into #mine values(\"aaa\",\"aaa\")\n insert into #mine values(\"bbb\",\"bbb\")\n insert into #mine values(\"ccc\",\"ccc\")\n insert into #mine values(\"ccc\",\"ccc\")\n go\n drop table #mine\n go\n \ncreate table #mine\n(col1 varchar(3),\ncol2 varchar(3))\ngo\n\nexec my_stp\ngo\n\nselect * from #mine\ndrop table #mine\ngo\n"
},
{
"answer_id": 5570045,
"author": "Jakub Korab",
"author_id": 263052,
"author_profile": "https://Stackoverflow.com/users/263052",
"pm_score": 3,
"selected": false,
"text": "create procedure mydb.mylogin.sp_extractSomething (\n@timestamp datetime) as\nselect column_a, column_b\n from sometable\n where timestamp = @timestamp\n use tempdb\n create existing table myproxy_extractSomething (\ncolumn_a int not null, -- make sure that the types match up exactly!\ncolumn_b varchar(20) not null,\n_timestamp datetime null,\nprimary key (column_a)) external procedure at \"loopback.mydb.mylogin.sp_extractSomething\"\n declare @myTimestamp datetime\nset @myTimestamp = getdate()\n\nselect * \nfrom tempdb..myproxy_extractSomething\nwhere _timestamp = @myTimestamp\n create table #myTempExtract (\n column_a int not null, -- again, make sure that the types match up exactly\n column_b varchar(20) not null,\n primary key (column_a)\n)\n insert into #myTempExtract (column_a, column_b)\nselect column_a, column_b\n from tempdb..myproxy_extractSomething\n where _timestamp = @myTimestamp\n"
},
{
"answer_id": 25579964,
"author": "sankardevisharath",
"author_id": 3931743,
"author_profile": "https://Stackoverflow.com/users/3931743",
"pm_score": -1,
"selected": false,
"text": "CREATE VIEW My_view\n AS\n/*\n My_stp body\n*/\n\n\nThen select data from view \nSELECT * INTO #x FROM my_view\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21246/"
] |
166,083
|
<p>I have the following preprocessor divective:</p>
<pre><code>#ifndef NDEBUG
#define TRACE printf
#else
#define TRACE(...)
#endif
</code></pre>
<p>and example of usage is:</p>
<pre><code>TRACE("TRACE: some parameter = %i\n", param);
</code></pre>
<p>In C all works perfectly well when I build both debug and release versions, but in C++ compiler emits the following:</p>
<p>warning: invalid character in macro parameter name</p>
<p>error: badly punctuated parameter list in `#define'</p>
<p>and points these warning and error to the 'TRACE(...)' directive.</p>
<p>How to write this in C++ correctly?</p>
|
[
{
"answer_id": 166087,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 2,
"selected": true,
"text": "inline void TRACE(...) {}\n"
},
{
"answer_id": 166124,
"author": "MSalters",
"author_id": 15416,
"author_profile": "https://Stackoverflow.com/users/15416",
"pm_score": 2,
"selected": false,
"text": "#define TRACE false ||"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166083",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4378/"
] |
166,089
|
<p>I'm interested: What is C#'s analog of <code>std::pair</code> in C++? I found <code>System.Web.UI.Pair</code> class, but I'd prefer something template-based.</p>
<p>Thank you!</p>
|
[
{
"answer_id": 166094,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 10,
"selected": true,
"text": "Tuple<string, int> t = new Tuple<string, int>(\"Hello\", 4);\n System.Collections.Generic.KeyValuePair<K, V> public class Pair<T, U> {\n public Pair() {\n }\n\n public Pair(T first, U second) {\n this.First = first;\n this.Second = second;\n }\n\n public T First { get; set; }\n public U Second { get; set; }\n};\n Pair<String, int> pair = new Pair<String, int>(\"test\", 2);\nConsole.WriteLine(pair.First);\nConsole.WriteLine(pair.Second);\n test\n2\n Pair<Pair<String, int>, bool> pair = new Pair<Pair<String, int>, bool>();\npair.First = new Pair<String, int>();\npair.First.First = \"test\";\npair.First.Second = 12;\npair.Second = true;\n\nConsole.WriteLine(pair.First.First);\nConsole.WriteLine(pair.First.Second);\nConsole.WriteLine(pair.Second);\n test\n12\ntrue\n"
},
{
"answer_id": 166100,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 5,
"selected": false,
"text": "System.Collections.Generic.KeyValuePair<K, V> var x = new { First = \"x\", Second = 42 };\n"
},
{
"answer_id": 1226383,
"author": "Jay Walker",
"author_id": 61378,
"author_profile": "https://Stackoverflow.com/users/61378",
"pm_score": 7,
"selected": false,
"text": "System.Web.UI Pair System.ValueTuple //explicit Item typing\n(string Message, int SomeNumber) t = (\"Hello\", 4);\n//or using implicit typing \nvar t = (Message:\"Hello\", SomeNumber:4);\n\nConsole.WriteLine(\"{0} {1}\", t.Message, t.SomeNumber);\n Tuples Tuple<string, int> t = new Tuple<string, int>(\"Hello\", 4);\n"
},
{
"answer_id": 1615099,
"author": "Andrew Stein",
"author_id": 13029,
"author_profile": "https://Stackoverflow.com/users/13029",
"pm_score": 1,
"selected": false,
"text": " public override Boolean Equals(Object o)\n {\n Pair<T, U> that = o as Pair<T, U>;\n if (that == null)\n return false;\n else\n return this.First.Equals(that.First) && this.Second.Equals(that.Second);\n }\n public override Int32 GetHashCode()\n {\n return First.GetHashCode() ^ Second.GetHashCode();\n }\n"
},
{
"answer_id": 2063581,
"author": "Antony",
"author_id": 250661,
"author_profile": "https://Stackoverflow.com/users/250661",
"pm_score": 3,
"selected": false,
"text": "public class Pair<X, Y>\n{\n private X _x;\n private Y _y;\n\n public Pair(X first, Y second)\n {\n _x = first;\n _y = second;\n }\n\n public X first { get { return _x; } }\n\n public Y second { get { return _y; } }\n\n public override bool Equals(object obj)\n {\n if (obj == null)\n return false;\n if (obj == this)\n return true;\n Pair<X, Y> other = obj as Pair<X, Y>;\n if (other == null)\n return false;\n\n return\n (((first == null) && (other.first == null))\n || ((first != null) && first.Equals(other.first)))\n &&\n (((second == null) && (other.second == null))\n || ((second != null) && second.Equals(other.second)));\n }\n\n public override int GetHashCode()\n {\n int hashcode = 0;\n if (first != null)\n hashcode += first.GetHashCode();\n if (second != null)\n hashcode += second.GetHashCode();\n\n return hashcode;\n }\n}\n [TestClass]\npublic class PairTest\n{\n [TestMethod]\n public void pairTest()\n {\n string s = \"abc\";\n Pair<int, string> foo = new Pair<int, string>(10, s);\n Pair<int, string> bar = new Pair<int, string>(10, s);\n Pair<int, string> qux = new Pair<int, string>(20, s);\n Pair<int, int> aaa = new Pair<int, int>(10, 20);\n\n Assert.IsTrue(10 == foo.first);\n Assert.AreEqual(s, foo.second);\n Assert.AreEqual(foo, bar);\n Assert.IsTrue(foo.GetHashCode() == bar.GetHashCode());\n Assert.IsFalse(foo.Equals(qux));\n Assert.IsFalse(foo.Equals(null));\n Assert.IsFalse(foo.Equals(aaa));\n\n Pair<string, string> s1 = new Pair<string, string>(\"a\", \"b\");\n Pair<string, string> s2 = new Pair<string, string>(null, \"b\");\n Pair<string, string> s3 = new Pair<string, string>(\"a\", null);\n Pair<string, string> s4 = new Pair<string, string>(null, null);\n Assert.IsFalse(s1.Equals(s2));\n Assert.IsFalse(s1.Equals(s3));\n Assert.IsFalse(s1.Equals(s4));\n Assert.IsFalse(s2.Equals(s1));\n Assert.IsFalse(s3.Equals(s1));\n Assert.IsFalse(s2.Equals(s3));\n Assert.IsFalse(s4.Equals(s1));\n Assert.IsFalse(s1.Equals(s4));\n }\n}\n"
},
{
"answer_id": 5262467,
"author": "Serge Mikhailov",
"author_id": 653898,
"author_profile": "https://Stackoverflow.com/users/653898",
"pm_score": 2,
"selected": false,
"text": "System.Tuple<T1, T2> // pair is implicitly typed local variable (method scope)\nvar pair = System.Tuple.Create(\"Current century\", 21);\n"
},
{
"answer_id": 15183399,
"author": "parliament",
"author_id": 1267778,
"author_profile": "https://Stackoverflow.com/users/1267778",
"pm_score": 2,
"selected": false,
"text": "Tuple public class Statistic<T> : Tuple<string, T>\n{\n public Statistic(string name, T value) : base(name, value) { }\n public string Name { get { return this.Item1; } }\n public T Value { get { return this.Item2; } }\n}\n public class StatSummary{\n public Statistic<double> NetProfit { get; set; }\n public Statistic<int> NumberOfTrades { get; set; }\n\n public StatSummary(double totalNetProfit, int numberOfTrades)\n {\n this.TotalNetProfit = new Statistic<double>(\"Total Net Profit\", totalNetProfit);\n this.NumberOfTrades = new Statistic<int>(\"Number of Trades\", numberOfTrades);\n }\n}\n\nStatSummary summary = new StatSummary(750.50, 30);\nConsole.WriteLine(\"Name: \" + summary.NetProfit.Name + \" Value: \" + summary.NetProfit.Value);\nConsole.WriteLine(\"Name: \" + summary.NumberOfTrades.Value + \" Value: \" + summary.NumberOfTrades.Value);\n"
},
{
"answer_id": 43632362,
"author": "Pawel Gradecki",
"author_id": 7708157,
"author_profile": "https://Stackoverflow.com/users/7708157",
"pm_score": 3,
"selected": false,
"text": "Tuple<string, int> t = new Tuple<string, int>(\"Hello\", 4);\n t.Item1 t.Item2 (string message, int count) = (\"Hello\", 4);\n (var message, var count) = (\"Hello\", 4);\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11256/"
] |
166,099
|
<p>Starting new .NET projects always involves a bit of work. You have to create the solution, add projects for different tiers (Domain, DAL, Web, Test), set up references, solution structure, copy javascript files, css templates and master pages etc etc.</p>
<p>What I'd like is <strong>an easy way of cloning any given solution</strong>. </p>
<p>If you use copy/paste, the problem is that you need to then go through renaming namespaces, assembly names, solution names, GUIDs etc. </p>
<p>Is there a way of automating this?</p>
<p>Something like this would be great:</p>
<pre><code>solutionclone.exe --solution=c:\code\abc\template.sln --to=c:\code\xyz --newname=MySolution
</code></pre>
<p>I'm aware that Visual Studio has project templates, but I've not seen solution templates.</p>
|
[
{
"answer_id": 166135,
"author": "Andre Bossard",
"author_id": 21027,
"author_profile": "https://Stackoverflow.com/users/21027",
"pm_score": 2,
"selected": false,
"text": "text/plain"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1136215/"
] |
166,113
|
<p>If I want to call <code>Bar()</code> instead of <code>Foo()</code>, does <code>Bar()</code> return me a copy (additional overhead) of what Foo() returns, or it returns the same object which <code>Foo()</code> places on the temporary stack?</p>
<pre><code>vector<int> Foo(){
vector<int> result;
result.push_back(1);
return result;
}
vector<int> Bar(){
return Foo();
}
</code></pre>
|
[
{
"answer_id": 166116,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 2,
"selected": false,
"text": "vector<int> vector<int> Foo(){ \n004118D0 push ebp \n004118D1 mov ebp,esp \n004118D3 push 0FFFFFFFFh \n004118D5 push offset __ehhandler$?Foo@@YA?AV?$vector@HV?$allocator@H@std@@@std@@XZ (419207h) \n004118DA mov eax,dword ptr fs:[00000000h] \n004118E0 push eax \n004118E1 sub esp,0F4h \n004118E7 push ebx \n004118E8 push esi \n004118E9 push edi \n004118EA lea edi,[ebp-100h] \n004118F0 mov ecx,3Dh \n004118F5 mov eax,0CCCCCCCCh \n004118FA rep stos dword ptr es:[edi] \n004118FC mov eax,dword ptr [___security_cookie (41E098h)] \n00411901 xor eax,ebp \n00411903 push eax \n00411904 lea eax,[ebp-0Ch] \n00411907 mov dword ptr fs:[00000000h],eax \n0041190D mov dword ptr [ebp-0F0h],0 \n vector<int> result; \n00411917 lea ecx,[ebp-24h] \n0041191A call std::vector<int,std::allocator<int> >::vector<int,std::allocator<int> > (411050h) \n0041191F mov dword ptr [ebp-4],1 \n result.push_back(1); \n00411926 mov dword ptr [ebp-0FCh],1 \n00411930 lea eax,[ebp-0FCh] \n00411936 push eax \n00411937 lea ecx,[ebp-24h] \n0041193A call std::vector<int,std::allocator<int> >::push_back (41144Ch) \n return result; \n0041193F lea eax,[ebp-24h] \n00411942 push eax \n00411943 mov ecx,dword ptr [ebp+8] \n00411946 call std::vector<int,std::allocator<int> >::vector<int,std::allocator<int> > (41104Bh) \n0041194B mov ecx,dword ptr [ebp-0F0h] \n00411951 or ecx,1 \n00411954 mov dword ptr [ebp-0F0h],ecx \n0041195A mov byte ptr [ebp-4],0 \n0041195E lea ecx,[ebp-24h] \n00411961 call std::vector<int,std::allocator<int> >::~vector<int,std::allocator<int> > (411415h) \n00411966 mov eax,dword ptr [ebp+8] \n} \n vector<int> result; [ebp-24h] 00411917 lea ecx,[ebp-24h] \n0041191A call std::vector<int,std::allocator<int> >::vector<int,std::allocator<int> > (411050h)\n return result; [ebp+8] 00411943 mov ecx,dword ptr [ebp+8] \n00411946 call std::vector<int,std::allocator<int> >::vector<int,std::allocator<int> > (41104Bh) \n vector<int> result [ebp-24h] 0041195E lea ecx,[ebp-24h] \n00411961 call std::vector<int,std::allocator<int> >::~vector<int,std::allocator<int> > (411415h) \n vector<int> Foo(){ \n00401110 push 0FFFFFFFFh \n00401112 push offset __ehhandler$?Foo@@YA?AV?$vector@HV?$allocator@H@std@@@std@@XZ (401F89h) \n00401117 mov eax,dword ptr fs:[00000000h] \n0040111D push eax \n0040111E sub esp,14h \n00401121 push esi \n00401122 mov eax,dword ptr [___security_cookie (403018h)] \n00401127 xor eax,esp \n00401129 push eax \n0040112A lea eax,[esp+1Ch] \n0040112E mov dword ptr fs:[00000000h],eax \n00401134 mov esi,dword ptr [esp+2Ch] \n00401138 xor eax,eax \n0040113A mov dword ptr [esp+8],eax \n vector<int> result; \n0040113E mov dword ptr [esi+4],eax \n00401141 mov dword ptr [esi+8],eax \n00401144 mov dword ptr [esi+0Ch],eax \n result.push_back(1); \n return result; \n00401147 push eax \n00401148 mov dword ptr [esp+28h],eax \n0040114C mov ecx,1 \n00401151 push esi \n00401152 lea eax,[esp+14h] \n00401156 mov dword ptr [esp+10h],ecx \n0040115A mov dword ptr [esp+14h],ecx \n0040115E push eax \n0040115F lea ecx,[esp+1Ch] \n00401163 push ecx \n00401164 mov eax,esi \n00401166 call std::vector<int,std::allocator<int> >::insert (401200h) \n0040116B mov eax,esi \n} \n0040116D mov ecx,dword ptr [esp+1Ch] \n00401171 mov dword ptr fs:[0],ecx \n00401178 pop ecx \n00401179 pop esi \n0040117A add esp,20h \n0040117D ret\n vector<int> result Bar"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166113",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20646/"
] |
166,125
|
<p>I'm currently trying to pass a mono threaded program to multithread. This software do heavy usage of "refCounted" objects, which lead to some issues in multithread. I'm looking for some design pattern or something that might solve my problem.</p>
<p>The main problem is object deletion between thread, normally deletion only decrement the reference counting, and when refcount is equal to zero, then the object is deleted. This work well in monothread program, and allow some great performance improvement with copy of big object.</p>
<p>However, in multithread, two threads might want to delete the same object concurrently, as the object is protected by a mutex, only one thread delete the object and block the other one. But when it releases the mutex, then the other thread continue its execution with invalid (freed object), which lead to memory corruption.</p>
<p>Here is an example with this class RefCountedObject</p>
<pre><code>class RefCountedObject
{
public:
RefCountedObject()
: _refCount( new U32(1) )
{}
RefCountedObject( const RefCountedObject& obj )
: _refCount( obj._refCount )
{
ACE_Guard< ACE_Mutex > guard( _refCountMutex );
++(*_refCount);
}
~RefCountedObject()
{
Destroy();
}
RefCountedObject& operator=( const RefCountedObject& obj )
{
if( this != &obj )
{
Destroy();
ACE_Guard< ACE_Mutex > guard( _refCountMutex );
_refCount = obj._refCount;
++(*_refCount);
}
return *this;
}
private:
void Destroy()
{
ACE_Guard< ACE_Mutex > guard( _refCountMutex ); // thread2 are waiting here
--(*_refCount); // This cause a free memory write by the thread2
if( 0 == *_refCount )
delete _refCount;
}
private:
mutable U32* _refCount;
mutable ACE_Mutex _refCountMutex; // BAD: this mutex only protect the refCount pointer, not the refCount itself
};
</code></pre>
<p>Suppose that two threads want to delete the same RefCountedObject, both are in ~RefCountedObject and call Destroy(), the first thread has locked the mutex and the other one is waiting. After the deletion of the object by the first thread, the second will continue its execution and cause a free memory write.</p>
<p>Anyone has experience with a similar problem and found a solution ?</p>
<hr>
<p>Thanks all for your help, I realize my mistake:
The mutex is only protecting refCount pointer, not the refCount itself! I've created a RefCount class which is mutex protected. The mutex is now shared between all refCounted object.</p>
<p>Now all works fine.</p>
|
[
{
"answer_id": 166167,
"author": "grrussel",
"author_id": 8516,
"author_profile": "https://Stackoverflow.com/users/8516",
"pm_score": 0,
"selected": false,
"text": "ACE_Atomic_Op"
},
{
"answer_id": 166200,
"author": "tloach",
"author_id": 14092,
"author_profile": "https://Stackoverflow.com/users/14092",
"pm_score": 0,
"selected": false,
"text": "private:\n void Destroy()\n {\n ACE_Guard< ACE_Mutex > guard( _refCountMutex ); // thread2 are waiting here\n if (_refCount != 0) {\n --(*_refCount); // This cause a free memory write by the thread2\n if( 0 == *_refCount ) {\n delete _refCount;\n _refcount = 0;\n }\n }\n }\nprivate:\n mutable U32* _refCount;\n mutable ACE_Mutex _refCountMutex; private:\n void Destroy()\n {\n ACE_Guard< ACE_Mutex > guard( _refCountMutex ); // thread2 are waiting here\n if (_refCount != 0) {\n --(*_refCount); // This cause a free memory write by the thread2\n if( 0 == *_refCount ) {\n delete _refCount;\n _refcount = 0;\n }\n }\n }\nprivate:\n mutable U32* _refCount;\n mutable ACE_Mutex _refCountMutex;"
},
{
"answer_id": 166225,
"author": "Anthony Williams",
"author_id": 5597,
"author_profile": "https://Stackoverflow.com/users/5597",
"pm_score": 3,
"selected": true,
"text": "boost::shared_ptr atomic_load atomic_store atomic_exchange atomic_compare_exchange shared_ptr"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1578/"
] |
166,127
|
<p>I have a web page where I'd like to remap Ctrl+N to a different behavior. I followed YUI's example of register Key Listeners and my function is called but Firefox still creates a new browser window. Things seem to work fine on IE7. How do I stop the new window from showing up?</p>
<p>Example:</p>
<pre><code>var kl2 = new YAHOO.util.KeyListener(document, { ctrl:true, keys:78 },
{fn:function(event) {
YAHOO.util.Event.stopEvent(event); // Doesn't help
alert('Click');}});
kl2.enable();
</code></pre>
<p>It is possible to remove default behavior. Google Docs overrides Ctrl+S to save your document instead of bringing up Firefox's save dialog. I tried the example above with Ctrl+S but Firefox's save dialog still pops up. Since Google can stop the save dialog from coming up I'm sure there's a way to prevent most default keyboard shortcuts.</p>
|
[
{
"answer_id": 786261,
"author": "Tac-Tics",
"author_id": 92971,
"author_profile": "https://Stackoverflow.com/users/92971",
"pm_score": 4,
"selected": true,
"text": "function callback(type, args)\n{\n var event = args[1]; // the actual event object\n alert('Click');\n\n // like stopEvent, but the event still propogates to other YUI handlers\n YAHOO.util.Event.preventDefault(event);\n}\nvar kl2 = new YAHOO.util.KeyListener(document, { ctrl:true, keys:78 }, {fn:callback});\nkl2.enable();\n function ord(char)\n{\n return char.charCodeAt(0);\n}\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/680/"
] |
166,132
|
<p>I want to store the data returned by <code>$_SERVER["REMOTE_ADDR"]</code> in PHP into a DB field, pretty simple task, really. The problem is that I can't find any proper information about the maximum length of the <strong>textual representation</strong> of an IPv6 address, which is what a webserver provides through <code>$_SERVER["REMOTE_ADDR"]</code>. </p>
<p>I'm not interested in converting the textual representation into the 128 bits the address is usually encoded in, I just want to know how many characters maximum are needed to store any IPv6 address returned by <code>$_SERVER["REMOTE_ADDR"]</code>.</p>
|
[
{
"answer_id": 166157,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 11,
"selected": true,
"text": "0000:0000:0000:0000:0000:0000:0000:0000\n : . [::ffff:192.168.100.228] 0000:0000:0000:0000:0000:ffff:192.168.100.228\n [0000:0000:0000:0000:0000:ffff:c0a8:64e4]"
},
{
"answer_id": 20473371,
"author": "Yury",
"author_id": 685653,
"author_profile": "https://Stackoverflow.com/users/685653",
"pm_score": 7,
"selected": false,
"text": "INET6_ADDRSTRLEN <arpa/inet.h> man inet_ntop #define INET6_ADDRSTRLEN 46\n"
},
{
"answer_id": 42294147,
"author": "Simon_Weaver",
"author_id": 16940,
"author_profile": "https://Stackoverflow.com/users/16940",
"pm_score": 2,
"selected": false,
"text": "HTTP_X_FORWARDED_FOR"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10024/"
] |
166,134
|
<p>In PHP, which is quicker; using <code>include('somefile.php')</code> or querying a MySQL database with a simple <code>SELECT</code> query to get the same information?</p>
<p>For example, say you had a JavaScript autocomplete search field which needed 3,000 terms to match against. Is it quicker to read those terms in from another file using <code>include</code> or to read them from a MySQL database using a simple <code>SELECT</code> query?</p>
<p><strong>Edit:</strong> This is assuming that the database and the file I want to include are on the same local machine as my code.</p>
|
[
{
"answer_id": 166215,
"author": "Gravstar",
"author_id": 17381,
"author_profile": "https://Stackoverflow.com/users/17381",
"pm_score": 5,
"selected": true,
"text": "<?php\n\n start = microtime(true);\n\n include( 'somefile.php' );\n\n echo microtime(true)-start;\n\n?>\n <?php\n\n start = microtime(true);\n\n __put_here_your_mysql_statements_to_retrieve_the_file__\n\n echo microtime(true)-start;\n\n?>\n"
},
{
"answer_id": 166342,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "$query = $_GET['query'];\n$key = 'query' . $query;\nif (!$results = apc_fetch($key))\n{ \n $statement = $db->prepare(\"SELECT name FROM list WHERE name LIKE :query\");\n $statement->bindValue(':query', \"$query%\");\n $statement->execute();\n $results = $statement->fetchAll();\n apc_store($key, $results);\n}\n\necho json_encode($results);\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21709/"
] |
166,159
|
<p>I recall there is a difference between some methods/properties called directly on the <a href="http://msdn.microsoft.com/en-us/library/system.data.datatable(VS.71).aspx" rel="noreferrer">DataTable</a> class, and the identically named methods/properties on the <a href="http://msdn.microsoft.com/en-us/library/system.data.datatable.rows(VS.71).aspx" rel="noreferrer">DataTable.Rows</a> property. (Might have been the RowCount/Count property for which I read this.) The difference is one of them disregards <a href="http://msdn.microsoft.com/en-us/library/system.data.datarow.rowstate(VS.71).aspx" rel="noreferrer">DataRow.RowState</a>, and the other respects/uses it.</p>
<p>In this particular case I'm wondering about the difference between <a href="http://msdn.microsoft.com/en-us/library/system.data.datatable.clear(VS.71).aspx" rel="noreferrer">DataTable.Clear</a> and <a href="http://msdn.microsoft.com/en-us/library/system.data.datarowcollection.clear(VS.71).aspx" rel="noreferrer">DataTable.Rows.Clear</a>. I can imagine one of them actually removes all rows, and the other one just marks them as deleted.</p>
<p>So my question is, <strong>is there a difference between the two Clear methods, and if so what is the difference?</strong></p>
<p>(Oh, this is for .NET 1.1 btw, in case the semantics changed from one version to another.)</p>
|
[
{
"answer_id": 166190,
"author": "Jaymz",
"author_id": 24761,
"author_profile": "https://Stackoverflow.com/users/24761",
"pm_score": 2,
"selected": false,
"text": "datatable.clear datatable.rows.clear datatable.clear datatable.rows.clear datatable.clear datatable.reset datatable.reset datatable.clear datatable.clear datatable.reset"
},
{
"answer_id": 166241,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 2,
"selected": false,
"text": "var d = new DataTable();\nd.Columns.Add(\"Hello\", typeof(string));\nd.Clear();\nConsole.WriteLine(d.Columns.Count);\n"
},
{
"answer_id": 778232,
"author": "SLaks",
"author_id": 34397,
"author_profile": "https://Stackoverflow.com/users/34397",
"pm_score": 4,
"selected": true,
"text": "DataRowCollection.Clear DataTable.Clear DataTable.Clear DataTable.NewRow RecordManager.Clear clearAll DataTable.Clear internal void Clear(bool clearAll) { \n if (clearAll) {\n for(int record = 0; record < recordCapacity; ++record) { \n rows[record] = null;\n }\n int count = table.columnCollection.Count;\n for(int i = 0; i < count; ++i) { \n //\n\n DataColumn column = table.columnCollection[i]; \n for(int record = 0; record < recordCapacity; ++record) {\n column.FreeRecord(record); \n }\n }\n lastFreeRecord = 0;\n freeRecordList.Clear(); \n }\n else { // just clear attached rows \n freeRecordList.Capacity = freeRecordList.Count + table.Rows.Count; \n for(int record = 0; record < recordCapacity; ++record) {\n if (rows[record]!= null && rows[record].rowID != -1) { \n int tempRecord = record;\n FreeRecord(ref tempRecord);\n }\n } \n }\n } \n"
},
{
"answer_id": 8998641,
"author": "Himalaya Garg",
"author_id": 1129978,
"author_profile": "https://Stackoverflow.com/users/1129978",
"pm_score": -1,
"selected": false,
"text": "DataRow[] d_row = dt_result.Select(\"isfor_report='True'\");\nDataTable dt = dt_result.Clone(); \nforeach (DataRow dr in d_row)\n{\n dt.ImportRow(dr);\n}\ngv_view_result.DataSource = dt;\ngv_view_result.DataBind();\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5422/"
] |
166,160
|
<p>How can I scale the content of an iframe (in my example it is an HTML page, and is not a popup) in a page of my web site?</p>
<p>For example, I want to display the content that appears in the iframe at 80% of the original size.</p>
|
[
{
"answer_id": 166287,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": -1,
"selected": false,
"text": "font-size: 80%;"
},
{
"answer_id": 166343,
"author": "roenving",
"author_id": 23142,
"author_profile": "https://Stackoverflow.com/users/23142",
"pm_score": 3,
"selected": false,
"text": "html{\n zoom:0.4;\n}\n"
},
{
"answer_id": 2224816,
"author": "Kip",
"author_id": 18511,
"author_profile": "https://Stackoverflow.com/users/18511",
"pm_score": 6,
"selected": false,
"text": "<style>\n#wrap { width: 600px; height: 390px; padding: 0; overflow: hidden; }\n#frame { width: 800px; height: 520px; border: 1px solid black; }\n#frame { zoom: 0.75; -moz-transform: scale(0.75); -moz-transform-origin: 0 0; }\n</style>\n\n...\n\n<p>Some text before the frame</p>\n<div id=\"wrap\">\n<iframe id=\"frame\" src=\"test2.html\"></iframe>\n</div>\n<p>Some text after the frame</p>\n</body>\n wrap"
},
{
"answer_id": 3131624,
"author": "lxs",
"author_id": 304282,
"author_profile": "https://Stackoverflow.com/users/304282",
"pm_score": 8,
"selected": false,
"text": "<style>\n #wrap { width: 600px; height: 390px; padding: 0; overflow: hidden; }\n #frame { width: 800px; height: 520px; border: 1px solid black; }\n #frame {\n -ms-zoom: 0.75;\n -moz-transform: scale(0.75);\n -moz-transform-origin: 0 0;\n -o-transform: scale(0.75);\n -o-transform-origin: 0 0;\n -webkit-transform: scale(0.75);\n -webkit-transform-origin: 0 0;\n }\n</style>\n"
},
{
"answer_id": 7504903,
"author": "r3cgm",
"author_id": 943317,
"author_profile": "https://Stackoverflow.com/users/943317",
"pm_score": 3,
"selected": false,
"text": "zoom --webkit-transform zoom -ms-zoom --webkit-transform"
},
{
"answer_id": 11959481,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "-ms-zoom #wrap iframe zoom #frame #wrap {\n overflow: hidden;\n position: relative;\n width:800px;\n height:850px;\n -ms-zoom: 0.75;\n}\n"
},
{
"answer_id": 12588274,
"author": "Jon Fergus",
"author_id": 1544609,
"author_profile": "https://Stackoverflow.com/users/1544609",
"pm_score": 3,
"selected": false,
"text": "<style>\n #wrap { width: 1620px; height: 3500px; padding: 0; position:relative; left:-100px; top:0px; overflow: hidden; }\n #frame { width: 1620px; height: 3500px; position:relative; left:-65px; top:0px; }\n #frame { -ms-zoom: 0.7; -moz-transform: scale(0.7); -moz-transform-origin: 0px 0; -o-transform: scale(0.7); -o-transform-origin: 0 0; -webkit-transform: scale(0.7); -webkit-transform-origin: 0 0; }\n</style>\n<div id=\"wrap\">\n <iframe id=\"frame\" src=\"http://www.example.com\"></iframe>\n</div>\n"
},
{
"answer_id": 13380454,
"author": "Matthew Wilcoxson",
"author_id": 266375,
"author_profile": "https://Stackoverflow.com/users/266375",
"pm_score": 4,
"selected": false,
"text": "#frame { /* Example size! */\n height: 400px; /* original height */\n width: 100%; /* original width */\n}\n#frame {\n height: 500px; /* new height (400 * (1/0.8) ) */\n width: 125%; /* new width (100 * (1/0.8) )*/\n\n transform: scale(0.8); \n transform-origin: 0 0;\n}\n"
},
{
"answer_id": 13880714,
"author": "Mathias Asberg",
"author_id": 1055866,
"author_profile": "https://Stackoverflow.com/users/1055866",
"pm_score": 2,
"selected": false,
"text": "#frame { \noverflow: hidden;\nposition: relative;\nwidth:1044px;\nheight:1600px;\n-ms-zoom: 0.85;\n-moz-transform: scale(0.85);\n-moz-transform-origin: 0px 0;\n-o-transform: scale(0.85);\n-o-transform-origin: 0 0;\n-webkit-transform: scale(0.85);\n-webkit-transform-origin: 0 0; \n\n}\n"
},
{
"answer_id": 15592305,
"author": "Eric Sassaman",
"author_id": 765303,
"author_profile": "https://Stackoverflow.com/users/765303",
"pm_score": 5,
"selected": false,
"text": ".wrap\n{\n width: 320px;\n height: 192px;\n padding: 0;\n overflow: hidden;\n}\n\n.frame\n{\n width: 1280px;\n height: 786px;\n border: 0;\n\n -ms-transform: scale(0.25);\n -moz-transform: scale(0.25);\n -o-transform: scale(0.25);\n -webkit-transform: scale(0.25);\n transform: scale(0.25);\n\n -ms-transform-origin: 0 0;\n -moz-transform-origin: 0 0;\n -o-transform-origin: 0 0;\n -webkit-transform-origin: 0 0;\n transform-origin: 0 0;\n}\n .wrap\n{\n width: 1280px; /* same size as frame */\n height: 768px;\n -ms-zoom: 0.25; /* for IE 8 ONLY */\n}\n <div class=\"wrap\">\n <iframe class=\"frame\" src=\"http://time.is\"></iframe>\n</div>\n<div class=\"wrap\">\n <iframe class=\"frame\" src=\"http://apple.com\"></iframe>\n</div>\n"
},
{
"answer_id": 21711582,
"author": "user3298597",
"author_id": 3298597,
"author_profile": "https://Stackoverflow.com/users/3298597",
"pm_score": 3,
"selected": false,
"text": "function()\n{\n var _wrapWidth=$('#wrap').width();\n var _frameWidth=$($('#frame')[0].contentDocument).width();\n\n if(!this.contentLoaded)\n this.initialWidth=_frameWidth;\n this.contentLoaded=true;\n var frame=$('#frame')[0];\n\n var percent=_wrapWidth/this.initialWidth;\n\n frame.style.width=100.0/percent+\"%\";\n frame.style.height=100.0/percent+\"%\";\n\n frame.style.zoom=percent;\n frame.style.webkitTransform='scale('+percent+')';\n frame.style.webkitTransformOrigin='top left';\n frame.style.MozTransform='scale('+percent+')';\n frame.style.MozTransformOrigin='top left';\n frame.style.oTransform='scale('+percent+')';\n frame.style.oTransformOrigin='top left';\n };\n"
},
{
"answer_id": 35984409,
"author": "Graham",
"author_id": 6060213,
"author_profile": "https://Stackoverflow.com/users/6060213",
"pm_score": 2,
"selected": false,
"text": "<IFRAME ID=myframe SRC=.... ></IFRAME>\n\n<SCRIPT>\n window.onload = function(){document.getElementById('myframe').contentWindow.document.body.style = 'zoom:50%;';};\n</SCRIPT>\n"
},
{
"answer_id": 48490950,
"author": "MrP01",
"author_id": 5832850,
"author_profile": "https://Stackoverflow.com/users/5832850",
"pm_score": 5,
"selected": false,
"text": "<div class='wrap'>\n <iframe ...></iframe>\n</div>\n .wrap {\n width: 640px;\n height: 480px;\n overflow: hidden;\n}\n\niframe {\n width: 76.92% !important;\n height: 76.92% !important;\n -webkit-transform: scale(1.3);\n transform: scale(1.3);\n -webkit-transform-origin: 0 0;\n transform-origin: 0 0;\n}\n (1/scale_factor)"
},
{
"answer_id": 70929773,
"author": "Tofnet",
"author_id": 14521222,
"author_profile": "https://Stackoverflow.com/users/14521222",
"pm_score": 0,
"selected": false,
"text": " window.onload = function(){\n let ifElem = document.getElementById(\"iframe-id\");\n ifElem.contentWindow.document.documentElement.style.fontSize=\"80%\";\n }\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24765/"
] |
166,174
|
<p>I have a list of objects, each containing an Id, Code and Description.</p>
<p>I need to convert this list into a Hashtable, using <strong>Description</strong> as the key and <strong>Id</strong> as the value.</p>
<p>This is so the Hashtable can then be serialised to JSON.</p>
<p>Is there a way to convert from List<Object> to Hashtable without writing a loop to go through each item in the list?</p>
|
[
{
"answer_id": 166207,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 6,
"selected": true,
"text": "var dict = myList.Cast<Foo>().ToDictionary(o => o.Description, o => o.Id);\n"
},
{
"answer_id": 166251,
"author": "noocyte",
"author_id": 11220,
"author_profile": "https://Stackoverflow.com/users/11220",
"pm_score": 0,
"selected": false,
"text": "theList.ForEach(delegate(theObject obj) { dic.Add(obj.Id, obj.Description); });\n"
},
{
"answer_id": 166700,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": -1,
"selected": false,
"text": "System.Collections.ObjectModel.KeyedCollection<TKey, TItem>"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4734/"
] |
166,179
|
<p>I'm currently using the sun preverifier to preverify my MIDlet. I'm finding that it can be a bit slow, doesnt give any decent error messages and is only available as a windows exe.</p>
<p>Are there any better preverifiers around that will work cross platform (linux specifically)</p>
|
[
{
"answer_id": 166512,
"author": "JaanusSiim",
"author_id": 706,
"author_profile": "https://Stackoverflow.com/users/706",
"pm_score": 0,
"selected": false,
"text": "Proguard"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24072/"
] |
166,198
|
<p>I'm writing a little debug app for a bit of kit we're developing and I'd like to roll it out to a few users to see if they can provoke any crashes. Does anyone know a way of effectively wrapping a wxPython app to catch any and all unhandled exceptions that would cause the app to crash?</p>
<p>Ideally I'd want to capture all output (not just errors) and log it to a file. Any unhandled exceptions ought to log to the current file and then allow the exception to pass on as per usual (i.e. the logging process ought to be transparent).</p>
<p>I'm sure someone must have done something along these lines before, but I've not managed to turn up anything that looks useful via google.</p>
|
[
{
"answer_id": 166213,
"author": "Milan Babuškov",
"author_id": 14690,
"author_profile": "https://Stackoverflow.com/users/14690",
"pm_score": 1,
"selected": false,
"text": "void Application::HandleEvent(wxEvtHandler* handler, wxEventFunction func, wxEvent& event) const\n{\n try\n {\n wxAppConsole::HandleEvent(handler, func, event);\n }\n catch (const std::exception& e)\n {\n wxMessageBox(std2wx(e.what()), _(\"Unhandled Error\"),\n wxOK | wxICON_ERROR, wxGetTopLevelParent(wxGetActiveWindow()));\n }\n}\n"
},
{
"answer_id": 166246,
"author": "DzinX",
"author_id": 18745,
"author_profile": "https://Stackoverflow.com/users/18745",
"pm_score": 4,
"selected": true,
"text": "from __future__ import with_statement\n\nclass OutWrapper(object):\n def __init__(self, realOutput, logFileName):\n self._realOutput = realOutput\n self._logFileName = logFileName\n\n def _log(self, text):\n with open(self._logFileName, 'a') as logFile:\n logFile.write(text)\n\n def write(self, text):\n self._log(text)\n self._realOutput.write(text)\n import sys \nsys.stdout = OutWrapper(sys.stdout, r'c:\\temp\\log.txt')\n MainLoop raise try:\n app.MainLoop()\nexcept:\n exc_info = sys.exc_info()\n saveExcInfo(exc_info) # this method you have to write yourself\n raise\n"
},
{
"answer_id": 190233,
"author": "monopocalypse",
"author_id": 17142,
"author_profile": "https://Stackoverflow.com/users/17142",
"pm_score": 3,
"selected": false,
"text": "import sys\nimport traceback\n\ndef excepthook(type, value, tb):\n message = 'Uncaught exception:\\n'\n message += ''.join(traceback.format_exception(type, value, tb))\n log.write(message)\n\nsys.excepthook = excepthook\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15369/"
] |
166,210
|
<p>I'll regularly get an extract from a DB/2 database with dates and timestaps formatted like this:</p>
<pre><code>2002-01-15-00.00.00.000000
2008-01-05-12.36.05.190000
9999-12-31-24.00.00.000000
</code></pre>
<p>Is there an easier way to convert this into the Excel date format than decomposing with substrings?</p>
<pre><code>DB2date = DateValue(Left(a, 4) + "/" + Mid(a, 6, 2) + "/" + Mid(a, 9, 2))
</code></pre>
<p>thanks for your help!</p>
|
[
{
"answer_id": 166216,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 1,
"selected": false,
"text": "DB2string = \"2002-01-15-00.00.00.000000\";\nDB2date = DateValue(DB2string.SubString(0, 10).Replace('-', '/'));\n"
},
{
"answer_id": 166253,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 3,
"selected": true,
"text": "=DATE(INT(LEFT(A1,4)),INT(MID(A1,6,2)),INT(MID(A1,9,2)))\n dt= DateSerial(Int(Left$(dt$, 4), Int(Mid$(dt$, 6, 2)), Int(Mid$(dt$, 9, 2)))\n"
},
{
"answer_id": 166281,
"author": "Philippe Grondier",
"author_id": 11436,
"author_profile": "https://Stackoverflow.com/users/11436",
"pm_score": 1,
"selected": false,
"text": "dateValue() ? dateValue(\"2002-01-15\")\n\n 15/01/2002\n ? dateValue(left(\"2002-01-15-00.00.00.000000\",10))\n timeValue()"
},
{
"answer_id": 167497,
"author": "blairxy",
"author_id": 19478,
"author_profile": "https://Stackoverflow.com/users/19478",
"pm_score": 1,
"selected": false,
"text": "= DateValue(Mid(a, 1, 10)) + TimeValue(Mid(a, 12, 8))\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15296/"
] |
166,212
|
<p>I might be an exception here but I have never worked on a team with more than three developers and / or five people. Still we could manage to get the job done (somehow).</p>
<p>Is there a software development process which fits this "extreme" scenario? And, if you work as a standalone programmer is there something you can adapt to your daily life to make it more predicatable, coherent, documented and still get the job done?</p>
|
[
{
"answer_id": 598697,
"author": "MarkJ",
"author_id": 15639,
"author_profile": "https://Stackoverflow.com/users/15639",
"pm_score": 3,
"selected": false,
"text": " intellisense \n ||\n \\/\n code >>> compile >>>>> run >>>> success >>>> profit ;-)\n /\\ || || \n ^^ \\/ \\/\n ^^ errors errors \n ^^ \\\\ //\n ^^ \\\\ //\n ^^ google\n ^^ ||\n \\\\ \\/\n \\<<<<<<< copy N paste\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23297/"
] |
166,217
|
<p>I'm trying to create a named_scope that uses a join, but although the generated SQL looks right, the result are garbage. For example:</p>
<pre><code>class Clip < ActiveRecord::Base
named_scope :visible, {
:joins => "INNER JOIN series ON series.id = clips.owner_id INNER JOIN shows on shows.id = series.show_id",
:conditions=>"shows.visible = 1 AND clips.owner_type = 'Series' "
}
</code></pre>
<p>(A Clip is owned by a Series, a Series belongs to a Show, a Show can be visible or invisible).</p>
<p>Clip.all does:</p>
<pre><code>SELECT * FROM `clips`
</code></pre>
<p>Clip.visible.all does:</p>
<pre><code>SELECT * FROM `clips` INNER JOIN series ON series.id = clips.owner_id INNER JOIN shows on shows.id = series.show_id WHERE (shows.visible = 1 AND clips.owner_type = 'Series' )
</code></pre>
<p>This looks okay. But the resulting array of Clip models includes a Clip with an ID that's not in the database - it's picked up a show ID instead. Where am I going wrong?</p>
|
[
{
"answer_id": 166329,
"author": "Ben Scofield",
"author_id": 6478,
"author_profile": "https://Stackoverflow.com/users/6478",
"pm_score": 6,
"selected": true,
"text": "named_scope :visible, {\n :select => \"episodes.*\",\n :joins => \"INNER JOIN series ON series.id = clips.owner_id INNER JOIN shows on shows.id = series.show_id\", \n :conditions=>\"shows.visible = 1 AND clips.owner_type = 'Series' \"\n}\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166217",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18666/"
] |
166,220
|
<p>I have a project in subversion, which I'm developing using Eclipse. I did the original checkout from the svn repository from inside Eclipse. All was well for some weeks then for some unknown reason, Eclipse (specifically: subclipse in Ganymede) no longer recognizes my project as being under svn control. The team context-menu only shows the basic "apply patch" / "share this project" menu options. From the shell, I can still update the project using the svn command line tools, so I know that the svn credentials still work. Other projects under subversion in the same copy of Eclipse still work.</p>
<p>I realise that I can delete the local copy and check it out again, but I'd rather understand what has gone wrong - fix the problem, rather than mask the symptoms. Where does Eclipse store its knowledge of which projects are under version control? I looked at the <code>.project</code> file and the <code>.settings</code> directory, but couldn't see any obvious mention of svn nature or anything similar, even in the projects that are still working properly.</p>
|
[
{
"answer_id": 28626589,
"author": "Psychonaut",
"author_id": 906070,
"author_profile": "https://Stackoverflow.com/users/906070",
"pm_score": 0,
"selected": false,
"text": "maven.1424425443350 svn status maven.1424425443350"
},
{
"answer_id": 71846883,
"author": "el-teedee",
"author_id": 912046,
"author_profile": "https://Stackoverflow.com/users/912046",
"pm_score": 0,
"selected": false,
"text": "PROJECT/ BAK/ .svn BAK/ PROJECT/ .classpath .project"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166220",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6716/"
] |
166,221
|
<p>I would like to upload a file asynchronously with jQuery. </p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function () {
$("#uploadbutton").click(function () {
var filename = $("#file").val();
$.ajax({
type: "POST",
url: "addFile.do",
enctype: 'multipart/form-data',
data: {
file: filename
},
success: function () {
alert("Data Uploaded: ");
}
});
});
});</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<span>File</span>
<input type="file" id="file" name="file" size="10"/>
<input id="uploadbutton" type="button" value="Upload"/></code></pre>
</div>
</div>
</p>
<p>Instead of the file being uploaded, I am only getting the filename. What can I do to fix this problem?</p>
|
[
{
"answer_id": 166284,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 8,
"selected": false,
"text": "file"
},
{
"answer_id": 215476,
"author": "Darryl Hein",
"author_id": 5441,
"author_profile": "https://Stackoverflow.com/users/5441",
"pm_score": 5,
"selected": false,
"text": "<form>"
},
{
"answer_id": 309393,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 7,
"selected": false,
"text": "JavaScript $(document).ready(function() {\n $(\"#uploadbutton\").jsupload({\n action: \"addFile.do\",\n onComplete: function(response){\n alert( \"server response: \" + response);\n }\n });\n});\n"
},
{
"answer_id": 1275048,
"author": "wbharding",
"author_id": 153610,
"author_profile": "https://Stackoverflow.com/users/153610",
"pm_score": 5,
"selected": false,
"text": "remote_form_for <% remote_form_for(:image_form, \n :url => { :controller => \"blogs\", :action => :create_asset }, \n :html => { :method => :post, \n :id => 'uploadForm', :multipart => true }) \n do |f| %>\n Upload a file: <%= f.file_field :uploaded_data %>\n<% end %>\n $('#uploadForm input').change(function(){\n $(this).parent().ajaxSubmit({\n beforeSubmit: function(a,f,o) {\n o.dataType = 'json';\n },\n complete: function(XMLHttpRequest, textStatus) {\n // XMLHttpRequest.responseText will contain the URL of the uploaded image.\n // Put it in an image element you create, or do with it what you will.\n // For example, if you have an image elemtn with id \"my_image\", then\n // $('#my_image').attr('src', XMLHttpRequest.responseText);\n // Will set that image tag to display the uploaded image.\n },\n });\n});\n @image = Image.new(params[:image_form])\n @image.save\n render :text => @image.public_filename\n"
},
{
"answer_id": 6867400,
"author": "Jordan Feldstein",
"author_id": 311901,
"author_profile": "https://Stackoverflow.com/users/311901",
"pm_score": 6,
"selected": false,
"text": "<input type=\"file\"> $('#one-specific-file').ajaxfileupload({\n 'action': '/upload.php'\n});\n $('input[type=\"file\"]').ajaxfileupload({\n 'action': '/upload.php',\n 'params': {\n 'extra': 'info'\n },\n 'onComplete': function(response) {\n console.log('custom handler for file:');\n alert(JSON.stringify(response));\n },\n 'onStart': function() {\n if(weWantedTo) return false; // cancels upload\n },\n 'onCancel': function() {\n console.log('no file selected');\n }\n});\n"
},
{
"answer_id": 8758614,
"author": "olanod",
"author_id": 931340,
"author_profile": "https://Stackoverflow.com/users/931340",
"pm_score": 11,
"selected": false,
"text": "<form enctype=\"multipart/form-data\">\n <input name=\"file\" type=\"file\" />\n <input type=\"button\" value=\"Upload\" />\n</form>\n<progress></progress>\n .on('change') $(':file').on('change', function () {\n var file = this.files[0];\n\n if (file.size > 1024) {\n alert('max upload size is 1k');\n }\n\n // Also see .name, .type\n});\n $.ajax() $(':button').on('click', function () {\n $.ajax({\n // Your server script to process the upload\n url: 'upload.php',\n type: 'POST',\n\n // Form data\n data: new FormData($('form')[0]),\n\n // Tell jQuery not to process data or worry about content-type\n // You *must* include these options!\n cache: false,\n contentType: false,\n processData: false,\n\n // Custom XMLHttpRequest\n xhr: function () {\n var myXhr = $.ajaxSettings.xhr();\n if (myXhr.upload) {\n // For handling the progress of the upload\n myXhr.upload.addEventListener('progress', function (e) {\n if (e.lengthComputable) {\n $('progress').attr({\n value: e.loaded,\n max: e.total,\n });\n }\n }, false);\n }\n return myXhr;\n }\n });\n});\n"
},
{
"answer_id": 14520473,
"author": "Techie",
"author_id": 1263783,
"author_profile": "https://Stackoverflow.com/users/1263783",
"pm_score": 6,
"selected": false,
"text": "<input id=\"file\" type=\"file\" name=\"file\"/>\n<div id=\"response\"></div>\n jQuery('document').ready(function(){\n var input = document.getElementById(\"file\");\n var formdata = false;\n if (window.FormData) {\n formdata = new FormData();\n }\n input.addEventListener(\"change\", function (evt) {\n var i = 0, len = this.files.length, img, reader, file;\n\n for ( ; i < len; i++ ) {\n file = this.files[i];\n\n if (!!file.type.match(/image.*/)) {\n if ( window.FileReader ) {\n reader = new FileReader();\n reader.onloadend = function (e) {\n //showUploadedItem(e.target.result, file.fileName);\n };\n reader.readAsDataURL(file);\n }\n\n if (formdata) {\n formdata.append(\"image\", file);\n formdata.append(\"extra\",'extra-data');\n }\n\n if (formdata) {\n jQuery('div#response').html('<br /><img src=\"ajax-loader.gif\"/>');\n\n jQuery.ajax({\n url: \"upload.php\",\n type: \"POST\",\n data: formdata,\n processData: false,\n contentType: false,\n success: function (res) {\n jQuery('div#response').html(\"Successfully uploaded\");\n }\n });\n }\n }\n else\n {\n alert('Not a vaild image!');\n }\n }\n\n }, false);\n});\n div extra-data $_POST"
},
{
"answer_id": 14919756,
"author": "mpen",
"author_id": 65387,
"author_profile": "https://Stackoverflow.com/users/65387",
"pm_score": 6,
"selected": false,
"text": "var xhr = new XMLHttpRequest();\nxhr.upload.onprogress = function(e) {\n var percent = (e.position/ e.totalSize);\n // Render a pretty progress bar\n};\nxhr.onreadystatechange = function(e) {\n if(this.readyState === 4) {\n // Handle file upload complete\n }\n};\nxhr.open('POST', '/upload', true);\nxhr.setRequestHeader('X-FileName',file.name); // Pass the filename along\nxhr.send(file);\n"
},
{
"answer_id": 17131994,
"author": "farnoush resa",
"author_id": 2044399,
"author_profile": "https://Stackoverflow.com/users/2044399",
"pm_score": 5,
"selected": false,
"text": "$('#file_upload').uploadify({\n 'swf': '/public/js/uploadify.swf',\n 'uploader': '/Upload.ashx?formGuid=' + $('#formGuid').val(),\n 'cancelImg': '/public/images/uploadify-cancel.png',\n 'multi': true,\n 'onQueueComplete': function (queueData) {\n // ...\n },\n 'onUploadStart': function (file) {\n // ...\n }\n});\n $(document).ready(function () {\n $('#btn_Upload').live('click', AjaxFileUpload);\n});\n\nfunction AjaxFileUpload() {\n var fileInput = document.getElementById(\"#Uploader\");\n var file = fileInput.files[0];\n var fd = new FormData();\n fd.append(\"files\", file);\n var xhr = new XMLHttpRequest();\n xhr.open(\"POST\", 'Uploader.ashx');\n xhr.onreadystatechange = function () {\n if (xhr.readyState == 4) {\n alert('success');\n }\n else if (uploadResult == 'success')\n alert('error');\n };\n xhr.send(fd);\n}\n"
},
{
"answer_id": 17310042,
"author": "user1091949",
"author_id": 1091949,
"author_profile": "https://Stackoverflow.com/users/1091949",
"pm_score": 5,
"selected": false,
"text": "var uploader = new ss.SimpleUpload({\n button: $('#uploadBtn'), // upload button\n url: '/uploadhandler', // URL of server-side upload handler\n name: 'userfile', // parameter name of the uploaded file\n onSubmit: function() {\n this.setProgressBar( $('#progressBar') ); // designate elem as our progress bar\n },\n onComplete: function(file, response) {\n // do whatever after upload is finished\n }\n});\n"
},
{
"answer_id": 23606275,
"author": "Amit",
"author_id": 2396721,
"author_profile": "https://Stackoverflow.com/users/2396721",
"pm_score": 4,
"selected": false,
"text": "$(function() {\n $(\"#file_upload_1\").uploadify({\n height : 30,\n swf : '/uploadify/uploadify.swf',\n uploader : '/uploadify/uploadify.php',\n width : 120\n });\n});\n"
},
{
"answer_id": 24361311,
"author": "ashish",
"author_id": 1321613,
"author_profile": "https://Stackoverflow.com/users/1321613",
"pm_score": 4,
"selected": false,
"text": "<input id=\"upload\" name=\"upload\" type=\"file\" />\n function uploadFile(element) {\n \n $(element).fileupload({\n \n dataType: 'json',\n url: '../DocumentUpload/upload',\n autoUpload: true,\n add: function (e, data) { \n // write code for implementing, while selecting a file. \n // data represents the file data. \n //below code triggers the action in mvc controller\n data.formData =\n {\n files: data.files[0]\n };\n data.submit();\n },\n done: function (e, data) { \n // after file uploaded\n },\n progress: function (e, data) {\n \n // progress\n },\n fail: function (e, data) {\n \n //fail operation\n },\n stop: function () {\n \n code for cancel operation\n }\n });\n \n };\n $(document).ready(function()\n{\n uploadFile($('#upload'));\n\n});\n public class DocumentUploadController : Controller\n { \n \n [System.Web.Mvc.HttpPost]\n public JsonResult upload(ICollection<HttpPostedFileBase> files)\n {\n bool result = false;\n\n if (files != null || files.Count > 0)\n {\n try\n {\n foreach (HttpPostedFileBase file in files)\n {\n if (file.ContentLength == 0)\n throw new Exception(\"Zero length file!\"); \n else \n //code for saving a file\n\n }\n }\n catch (Exception)\n {\n result = false;\n }\n }\n\n\n return new JsonResult()\n {\n Data=result\n };\n\n\n }\n\n }\n"
},
{
"answer_id": 24373219,
"author": "tnt-rox",
"author_id": 913620,
"author_profile": "https://Stackoverflow.com/users/913620",
"pm_score": 3,
"selected": false,
"text": "var reader = new FileReader();\n\n reader.onload = function(readerEvt) {\n var binaryString = readerEvt.target.result;\n document.getElementById(\"base64textarea\").value = btoa(binaryString);\n };\n\n reader.readAsBinaryString(file);\n window.open(\"data:application/octet-stream;base64,\" + base64);\n"
},
{
"answer_id": 24422523,
"author": "ArtisticPhoenix",
"author_id": 3684882,
"author_profile": "https://Stackoverflow.com/users/3684882",
"pm_score": 6,
"selected": false,
"text": "<form target=\"iframe\" action=\"\" method=\"post\" enctype=\"multipart/form-data\">\n <input name=\"file\" type=\"file\" />\n <input type=\"button\" value=\"Upload\" />\n</form>\n\n<iframe name=\"iframe\" id=\"iframe\" style=\"display:none\" ></iframe>\n onLoad $('body').iDownloader({\n \"onComplete\" : function(){\n $('#uiBlocker').css('display', 'none'); //hide ui blocker on complete\n }\n });\n\n $('somebuttion').click( function(){\n $('#uiBlocker').css('display', 'block'); //block the UI\n $('body').iDownloader('download', 'htttp://example.com/location/of/download');\n });\n setcookie('iDownloader', true, time() + 30, \"/\");\n onComplete"
},
{
"answer_id": 25195443,
"author": "Zayn Ali",
"author_id": 2610720,
"author_profile": "https://Stackoverflow.com/users/2610720",
"pm_score": 6,
"selected": false,
"text": ".ajax() <form id=\"upload-form\">\n <div>\n <label for=\"file\">File:</label>\n <input type=\"file\" id=\"file\" name=\"file\" />\n <progress class=\"progress\" value=\"0\" max=\"100\"></progress>\n </div>\n <hr />\n <input type=\"submit\" value=\"Submit\" />\n</form>\n .progress { display: none; }\n $(document).ready(function(ev) {\n $(\"#upload-form\").on('submit', (function(ev) {\n ev.preventDefault();\n $.ajax({\n xhr: function() {\n var progress = $('.progress'),\n xhr = $.ajaxSettings.xhr();\n\n progress.show();\n\n xhr.upload.onprogress = function(ev) {\n if (ev.lengthComputable) {\n var percentComplete = parseInt((ev.loaded / ev.total) * 100);\n progress.val(percentComplete);\n if (percentComplete === 100) {\n progress.hide().val(0);\n }\n }\n };\n\n return xhr;\n },\n url: 'upload.php',\n type: 'POST',\n data: new FormData(this),\n contentType: false,\n cache: false,\n processData: false,\n success: function(data, status, xhr) {\n // ...\n },\n error: function(xhr, status, error) {\n // ...\n }\n });\n }));\n});\n"
},
{
"answer_id": 25487973,
"author": "404",
"author_id": 3614389,
"author_profile": "https://Stackoverflow.com/users/3614389",
"pm_score": 7,
"selected": false,
"text": "$.ajax() $.ajax({\n url: 'file/destination.html', \n type: 'POST',\n data: new FormData($('#formWithFiles')[0]), // The form with the file inputs.\n processData: false,\n contentType: false // Using FormData, no need to process data.\n}).done(function(){\n console.log(\"Success: Files sent!\");\n}).fail(function(){\n console.log(\"An error occurred, the files couldn't be sent!\");\n});\n $.ajax() $.ajax({\n url: 'file/destination.html', \n type: 'POST',\n // Set the transport to use (iframe means to use Bifröst)\n // and the expected data type (json in this case).\n dataType: 'iframe json', \n fileInputs: $('input[type=\"file\"]'), // The file inputs containing the files to send.\n data: { msg: 'Some extra data you might need.'}\n}).done(function(){\n console.log(\"Success: Files sent!\");\n}).fail(function(){\n console.log(\"An error occurred, the files couldn't be sent!\");\n});\n"
},
{
"answer_id": 31300228,
"author": "Allende",
"author_id": 462889,
"author_profile": "https://Stackoverflow.com/users/462889",
"pm_score": 3,
"selected": false,
"text": "<?php\nif (isset($_FILES['myFile'])) {\n // Example:\n move_uploaded_file($_FILES['myFile']['tmp_name'], \"uploads/\" . $_FILES['myFile']['name']);\n exit;\n}\n?><!DOCTYPE html>\n<html>\n<head>\n <title>dnd binary upload</title>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n <script type=\"text/javascript\">\n function sendFile(file) {\n var uri = \"/index.php\";\n var xhr = new XMLHttpRequest();\n var fd = new FormData();\n\n xhr.open(\"POST\", uri, true);\n xhr.onreadystatechange = function() {\n if (xhr.readyState == 4 && xhr.status == 200) {\n // Handle response.\n alert(xhr.responseText); // handle response.\n }\n };\n fd.append('myFile', file);\n // Initiate a multipart/form-data upload\n xhr.send(fd);\n }\n\n window.onload = function() {\n var dropzone = document.getElementById(\"dropzone\");\n dropzone.ondragover = dropzone.ondragenter = function(event) {\n event.stopPropagation();\n event.preventDefault();\n }\n\n dropzone.ondrop = function(event) {\n event.stopPropagation();\n event.preventDefault();\n\n var filesArray = event.dataTransfer.files;\n for (var i=0; i<filesArray.length; i++) {\n sendFile(filesArray[i]);\n }\n }\n }\n </script>\n</head>\n<body>\n <div>\n <div id=\"dropzone\" style=\"margin:30px; width:500px; height:300px; border:1px dotted grey;\">Drag & drop your file here...</div>\n </div>\n</body>\n</html>\n"
},
{
"answer_id": 31678000,
"author": "Vivek Aasaithambi",
"author_id": 2700880,
"author_profile": "https://Stackoverflow.com/users/2700880",
"pm_score": 4,
"selected": false,
"text": "var formData=new FormData();\nformData.append(\"fieldname\",\"value\");\nformData.append(\"image\",$('[name=\"filename\"]')[0].files[0]);\n\n$.ajax({\n url:\"page.php\",\n data:formData,\n type: 'POST',\n dataType:\"JSON\",\n cache: false,\n contentType: false,\n processData: false,\n success:function(data){ }\n});\n"
},
{
"answer_id": 33508768,
"author": "Erick Lanford Xenes",
"author_id": 5190625,
"author_profile": "https://Stackoverflow.com/users/5190625",
"pm_score": 4,
"selected": false,
"text": "<form enctype=\"multipart/form-data\"> \n\n <div class=\"form-group\">\n <label class=\"control-label col-md-2\" for=\"apta_Description\">Description</label>\n <div class=\"col-md-10\">\n <input class=\"form-control text-box single-line\" id=\"apta_Description\" name=\"apta_Description\" type=\"text\" value=\"\">\n </div>\n </div>\n\n <input name=\"file\" type=\"file\" />\n <input type=\"button\" value=\"Upload\" />\n</form>\n <script>\n\n $(':button').click(function () {\n var formData = new FormData($('form')[0]);\n $.ajax({\n url: '@Url.Action(\"Save\", \"Home\")', \n type: 'POST', \n success: completeHandler,\n data: formData,\n cache: false,\n contentType: false,\n processData: false\n });\n }); \n\n function completeHandler() {\n alert(\":)\");\n } \n</script>\n [HttpPost]\npublic ActionResult Save(string apta_Description, HttpPostedFileBase file)\n{\n [...]\n}\n"
},
{
"answer_id": 36314992,
"author": "Siddhartha Chowdhury",
"author_id": 4475433,
"author_profile": "https://Stackoverflow.com/users/4475433",
"pm_score": 5,
"selected": false,
"text": "<form id=\"upload_form\" enctype=\"multipart/form-data\" method=\"post\">\n <input type=\"file\" name=\"file1\" id=\"file1\"><br>\n <input type=\"button\" value=\"Upload File\" onclick=\"uploadFile()\">\n <progress id=\"progressBar\" value=\"0\" max=\"100\" style=\"width:300px;\"></progress>\n <h3 id=\"status\"></h3>\n <p id=\"loaded_n_total\"></p>\n</form>\n function _(el){\n return document.getElementById(el);\n}\nfunction uploadFile(){\n var file = _(\"file1\").files[0];\n // alert(file.name+\" | \"+file.size+\" | \"+file.type);\n var formdata = new FormData();\n formdata.append(\"file1\", file);\n var ajax = new XMLHttpRequest();\n ajax.upload.addEventListener(\"progress\", progressHandler, false);\n ajax.addEventListener(\"load\", completeHandler, false);\n ajax.addEventListener(\"error\", errorHandler, false);\n ajax.addEventListener(\"abort\", abortHandler, false);\n ajax.open(\"POST\", \"file_upload_parser.php\");\n ajax.send(formdata);\n}\nfunction progressHandler(event){\n _(\"loaded_n_total\").innerHTML = \"Uploaded \"+event.loaded+\" bytes of \"+event.total;\n var percent = (event.loaded / event.total) * 100;\n _(\"progressBar\").value = Math.round(percent);\n _(\"status\").innerHTML = Math.round(percent)+\"% uploaded... please wait\";\n}\nfunction completeHandler(event){\n _(\"status\").innerHTML = event.target.responseText;\n _(\"progressBar\").value = 0;\n}\nfunction errorHandler(event){\n _(\"status\").innerHTML = \"Upload Failed\";\n}\nfunction abortHandler(event){\n _(\"status\").innerHTML = \"Upload Aborted\";\n}\n <?php\n$fileName = $_FILES[\"file1\"][\"name\"]; // The file name\n$fileTmpLoc = $_FILES[\"file1\"][\"tmp_name\"]; // File in the PHP tmp folder\n$fileType = $_FILES[\"file1\"][\"type\"]; // The type of file it is\n$fileSize = $_FILES[\"file1\"][\"size\"]; // File size in bytes\n$fileErrorMsg = $_FILES[\"file1\"][\"error\"]; // 0 for false... and 1 for true\nif (!$fileTmpLoc) { // if file not chosen\n echo \"ERROR: Please browse for a file before clicking the upload button.\";\n exit();\n}\nif(move_uploaded_file($fileTmpLoc, \"test_uploads/$fileName\")){ // assuming the directory name 'test_uploads'\n echo \"$fileName upload is complete\";\n} else {\n echo \"move_uploaded_file function failed\";\n}\n?>\n"
},
{
"answer_id": 38450087,
"author": "Daniel Nyamasyo",
"author_id": 6579192,
"author_profile": "https://Stackoverflow.com/users/6579192",
"pm_score": 4,
"selected": false,
"text": "<from action=\"\" id=\"formContent\" method=\"post\" enctype=\"multipart/form-data\">\n <span>File</span>\n <input type=\"file\" id=\"file\" name=\"file\" size=\"10\"/>\n <input id=\"uploadbutton\" type=\"button\" value=\"Upload\"/>\n</form>\n $(document).ready(function () {\n $(\"#formContent\").submit(function(e){\n\n e.preventDefault();\n var formdata = new FormData(this);\n\n $.ajax({\n url: \"ajax_upload_image.php\",\n type: \"POST\",\n data: formdata,\n mimeTypes:\"multipart/form-data\",\n contentType: false,\n cache: false,\n processData: false,\n success: function(){\n\n alert(\"successfully submitted\");\n\n });\n });\n});\n"
},
{
"answer_id": 40037182,
"author": "MEAbid",
"author_id": 5906922,
"author_profile": "https://Stackoverflow.com/users/5906922",
"pm_score": 4,
"selected": false,
"text": "var $bar = $('.ProgressBar');\n$('.Form').ajaxForm({\n dataType: 'json',\n\n beforeSend: function(xhr) {\n var percentVal = '0%';\n $bar.width(percentVal);\n },\n\n uploadProgress: function(event, position, total, percentComplete) {\n var percentVal = percentComplete + '%';\n $bar.width(percentVal)\n },\n\n success: function(response) {\n // Response\n }\n});\n"
},
{
"answer_id": 48908672,
"author": "lat94",
"author_id": 7004017,
"author_profile": "https://Stackoverflow.com/users/7004017",
"pm_score": 2,
"selected": false,
"text": "$('#fileupload').fileupload({\n add: function (e, data) {\n var that = this;\n $.getJSON('/example/url', function (result) {\n data.formData = result; // e.g. {id: 123}\n $.blueimp.fileupload.prototype\n .options.add.call(that, e, data);\n });\n } \n});\n"
},
{
"answer_id": 49235322,
"author": "Alireza",
"author_id": 5423108,
"author_profile": "https://Stackoverflow.com/users/5423108",
"pm_score": 3,
"selected": false,
"text": "/upload const asyncFileUpload = () => {\n const fileInput = document.getElementById(\"file\");\n const file = fileInput.files[0];\n const uri = \"/upload\";\n const xhr = new XMLHttpRequest();\n xhr.upload.onprogress = e => {\n const percentage = e.loaded / e.total;\n console.log(percentage);\n };\n xhr.onreadystatechange = e => {\n if (xhr.readyState === 4 && xhr.status === 200) {\n console.log(\"file uploaded\");\n }\n };\n xhr.open(\"POST\", uri, true);\n xhr.setRequestHeader(\"X-FileName\", file.name);\n xhr.send(file);\n} <form>\n <span>File</span>\n <input type=\"file\" id=\"file\" name=\"file\" size=\"10\" />\n <input onclick=\"asyncFileUpload()\" id=\"upload\" type=\"button\" value=\"Upload\" />\n</form>"
},
{
"answer_id": 50446598,
"author": "BlackBeard",
"author_id": 5349542,
"author_profile": "https://Stackoverflow.com/users/5349542",
"pm_score": 3,
"selected": false,
"text": "function uploadButtonCLicked(){\n var input = document.querySelector('input[type=\"file\"]')\n\n fetch('/url', {\n method: 'POST',\n body: input.files[0]\n }).then(res => res.json()) // you can do something with response\n .catch(error => console.error('Error:', error))\n .then(response => console.log('Success:', response));\n} \n .then(..code to handle response..)"
},
{
"answer_id": 51894789,
"author": "Alister",
"author_id": 1432509,
"author_profile": "https://Stackoverflow.com/users/1432509",
"pm_score": 4,
"selected": false,
"text": "<input type=\"file\"> // The input DOM element // <input type=\"file\">\nconst inputElement = document.querySelector('input[type=file]');\n\n// Listen for a file submit from user\ninputElement.addEventListener('change', () => {\n const data = new FormData();\n data.append('file', inputElement.files[0]);\n data.append('imageName', 'flower');\n\n // You can then post it to your server.\n // Fetch can accept an object of type FormData on its body\n fetch('/uploadImage', {\n method: 'POST',\n body: data\n });\n});\n"
},
{
"answer_id": 52085124,
"author": "Joe Clinton",
"author_id": 10276599,
"author_profile": "https://Stackoverflow.com/users/10276599",
"pm_score": 2,
"selected": false,
"text": "<form method=\"post\" asp-action=\"Add\" enctype=\"multipart/form-data\">\n <input type=\"file\" multiple name=\"mediaUpload\" />\n <button type=\"submit\">Submit</button>\n</form>\n [HttpPost]\npublic async Task<IActionResult> Add(IFormFile[] mediaUpload)\n{\n //looping through all the files\n foreach (IFormFile file in mediaUpload)\n {\n //saving the files\n string path = Path.Combine(hostingEnvironment.WebRootPath, \"some-folder-path\"); \n using (var stream = new FileStream(path, FileMode.Create))\n {\n await file.CopyToAsync(stream);\n }\n }\n}\n private IHostingEnvironment hostingEnvironment;\npublic MediaController(IHostingEnvironment environment)\n{\n hostingEnvironment = environment;\n}\n"
},
{
"answer_id": 52663864,
"author": "Supun Kavinda",
"author_id": 9059939,
"author_profile": "https://Stackoverflow.com/users/9059939",
"pm_score": 3,
"selected": false,
"text": "<html>\n<head>\n <title>Image Upload with AJAX, PHP and MYSQL</title>\n</head>\n<body>\n<form onsubmit=\"submitForm(event);\">\n <input type=\"file\" name=\"image\" id=\"image-selecter\" accept=\"image/*\">\n <input type=\"submit\" name=\"submit\" value=\"Upload Image\">\n</form>\n<div id=\"uploading-text\" style=\"display:none;\">Uploading...</div>\n<img id=\"preview\">\n</body>\n</html>\n var previewImage = document.getElementById(\"preview\"), \n uploadingText = document.getElementById(\"uploading-text\");\n\nfunction submitForm(event) {\n // prevent default form submission\n event.preventDefault();\n uploadImage();\n}\n\nfunction uploadImage() {\n var imageSelecter = document.getElementById(\"image-selecter\"),\n file = imageSelecter.files[0];\n if (!file) \n return alert(\"Please select a file\");\n // clear the previous image\n previewImage.removeAttribute(\"src\");\n // show uploading text\n uploadingText.style.display = \"block\";\n // create form data and append the file\n var formData = new FormData();\n formData.append(\"image\", file);\n // do the ajax part\n var ajax = new XMLHttpRequest();\n ajax.onreadystatechange = function() {\n if (this.readyState === 4 && this.status === 200) {\n var json = JSON.parse(this.responseText);\n if (!json || json.status !== true) \n return uploadError(json.error);\n\n showImage(json.url);\n }\n }\n ajax.open(\"POST\", \"upload.php\", true);\n ajax.send(formData); // send the form data\n}\n <?php\n$host = 'localhost';\n$user = 'user';\n$password = 'password';\n$database = 'database';\n$mysqli = new mysqli($host, $user, $password, $database);\n\n\n try {\n if (empty($_FILES['image'])) {\n throw new Exception('Image file is missing');\n }\n $image = $_FILES['image'];\n // check INI error\n if ($image['error'] !== 0) {\n if ($image['error'] === 1) \n throw new Exception('Max upload size exceeded');\n\n throw new Exception('Image uploading error: INI Error');\n }\n // check if the file exists\n if (!file_exists($image['tmp_name']))\n throw new Exception('Image file is missing in the server');\n $maxFileSize = 2 * 10e6; // in bytes\n if ($image['size'] > $maxFileSize)\n throw new Exception('Max size limit exceeded'); \n // check if uploaded file is an image\n $imageData = getimagesize($image['tmp_name']);\n if (!$imageData) \n throw new Exception('Invalid image');\n $mimeType = $imageData['mime'];\n // validate mime type\n $allowedMimeTypes = ['image/jpeg', 'image/png', 'image/gif'];\n if (!in_array($mimeType, $allowedMimeTypes)) \n throw new Exception('Only JPEG, PNG and GIFs are allowed');\n\n // nice! it's a valid image\n // get file extension (ex: jpg, png) not (.jpg)\n $fileExtention = strtolower(pathinfo($image['name'] ,PATHINFO_EXTENSION));\n // create random name for your image\n $fileName = round(microtime(true)) . mt_rand() . '.' . $fileExtention; // anyfilename.jpg\n // Create the path starting from DOCUMENT ROOT of your website\n $path = '/examples/image-upload/images/' . $fileName;\n // file path in the computer - where to save it \n $destination = $_SERVER['DOCUMENT_ROOT'] . $path;\n\n if (!move_uploaded_file($image['tmp_name'], $destination))\n throw new Exception('Error in moving the uploaded file');\n\n // create the url\n $protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';\n $domain = $protocol . $_SERVER['SERVER_NAME'];\n $url = $domain . $path;\n $stmt = $mysqli -> prepare('INSERT INTO image_uploads (url) VALUES (?)');\n if (\n $stmt &&\n $stmt -> bind_param('s', $url) &&\n $stmt -> execute()\n ) {\n exit(\n json_encode(\n array(\n 'status' => true,\n 'url' => $url\n )\n )\n );\n } else \n throw new Exception('Error in saving into the database');\n\n} catch (Exception $e) {\n exit(json_encode(\n array (\n 'status' => false,\n 'error' => $e -> getMessage()\n )\n ));\n}\n"
},
{
"answer_id": 53300507,
"author": "Karthik Ravichandran",
"author_id": 6212857,
"author_profile": "https://Stackoverflow.com/users/6212857",
"pm_score": 3,
"selected": false,
"text": "var formData = new FormData();\nformData.append('parameter1', 'value1');\nformData.append('parameter2', 'value2'); \nformData.append('file', $('input[type=file]')[0].files[0]);\n\n$.ajax({\n url: 'post back url',\n data: formData,\n// other attributes of AJAX\n});\n"
},
{
"answer_id": 55573259,
"author": "Michael Wang",
"author_id": 10567845,
"author_profile": "https://Stackoverflow.com/users/10567845",
"pm_score": -1,
"selected": false,
"text": "async: false(true)\n"
},
{
"answer_id": 56901361,
"author": "Kamil Kiełczewski",
"author_id": 860099,
"author_profile": "https://Stackoverflow.com/users/860099",
"pm_score": 2,
"selected": false,
"text": "async function saveFile() \n{\n let formData = new FormData(); \n formData.append(\"file\", file.files[0]);\n await fetch('addFile.do', {method: \"POST\", body: formData}); \n alert(\"Data Uploaded: \");\n} <span>File</span>\n<input type=\"file\" id=\"file\" name=\"file\" size=\"10\"/>\n<input type=\"button\" value=\"Upload\" onclick=\"saveFile()\"/> content-type='multipart/form-data' filename async function saveFile(inp) \n{\n let user = { name:'john', age:34 };\n let formData = new FormData();\n let photo = inp.files[0]; \n \n formData.append(\"photo\", photo);\n formData.append(\"user\", JSON.stringify(user)); \n \n try {\n let r = await fetch('/upload/image', {method: \"POST\", body: formData}); \n console.log('HTTP response code:',r.status); \n alert('success');\n } catch(e) {\n console.log('Huston we have problem...:', e);\n }\n \n} <input type=\"file\" onchange=\"saveFile(this)\" >\n<br><br>\nBefore selecting the file Open chrome console > network tab to see the request details.\n<br><br>\n<small>Because in this example we send request to https://stacksnippets.net/upload/image the response code will be 404 ofcourse...</small>"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2138/"
] |
166,231
|
<p><a href="http://en.wikipedia.org/wiki/Tcl" rel="noreferrer">Tcl/Tk</a> is a simple way to script small GUIs.</p>
<p>Can anyone give a nice example with a <em>button</em> and a <em>text</em> widget. When the button is pressed should a shell command be executed and the output piped to the <em>text</em> widget.</p>
<p>If you have other nice and clean examples for useful tasks, please add them too.</p>
|
[
{
"answer_id": 166247,
"author": "epatel",
"author_id": 842,
"author_profile": "https://Stackoverflow.com/users/842",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/wish\n\nproc push_button {} {\n put_text\n .main see end\n}\n\nproc put_text {} {\n set f [ open \"| date\" r]\n while {[gets $f x] >= 0} {\n .main insert end \"$x\\n\" \n }\n catch {close $f}\n}\n\nbutton .but -text \"Push Me\" -command \"push_button\"\ntext .main -relief sunken -bd 2 -yscrollcommand \".scroll set\"\nscrollbar .scroll -command \".main yview\"\n\npack .but\npack .main -side left -fill y\npack .scroll -side right -fill y\n"
},
{
"answer_id": 166972,
"author": "erichui",
"author_id": 6034,
"author_profile": "https://Stackoverflow.com/users/6034",
"pm_score": 2,
"selected": false,
"text": ".main insert end \"$x\\n\"\n .main see end\n"
},
{
"answer_id": 172061,
"author": "Bryan Oakley",
"author_id": 7432,
"author_profile": "https://Stackoverflow.com/users/7432",
"pm_score": 5,
"selected": true,
"text": "package require Tk\n\nproc main {} {\n if {[lsearch -exact [font names] TkDefaultFont] == -1} {\n # older versions of Tk don't define this font, so pick something\n # suitable\n font create TkDefaultFont -family Helvetica -size 12\n }\n # in 8.5 we can use {*} but this will work in earlier versions\n eval font create TkBoldFont [font actual TkDefaultFont] -weight bold\n\n buildUI\n}\n\nproc buildUI {} {\n frame .toolbar\n scrollbar .vsb -command [list .t yview]\n text .t \\\n -width 80 -height 20 \\\n -yscrollcommand [list .vsb set] \\\n -highlightthickness 0\n .t tag configure command -font TkBoldFont\n .t tag configure error -font TkDefaultFont -foreground firebrick\n .t tag configure output -font TkDefaultFont -foreground black\n\n grid .toolbar -sticky nsew\n grid .t .vsb -sticky nsew\n grid rowconfigure . 1 -weight 1\n grid columnconfigure . 0 -weight 1\n\n set i 0\n foreach {label command} {\n date {date} \n uptime {uptime} \n ls {ls -l}\n } {\n button .b$i -text $label -command [list runCommand $command]\n pack .b$i -in .toolbar -side left\n incr i\n }\n}\n\nproc output {type text} {\n .t configure -state normal\n .t insert end $text $type \"\\n\"\n .t see end\n .t configure -state disabled\n}\n\nproc runCommand {cmd} {\n output command $cmd\n set f [open \"| $cmd\" r]\n fconfigure $f -blocking false\n fileevent $f readable [list handleFileEvent $f]\n}\n\nproc closePipe {f} {\n # turn blocking on so we can catch any errors\n fconfigure $f -blocking true\n if {[catch {close $f} err]} {\n output error $err\n }\n}\n\nproc handleFileEvent {f} {\n set status [catch { gets $f line } result]\n if { $status != 0 } {\n # unexpected error\n output error $result\n closePipe $f\n\n } elseif { $result >= 0 } {\n # we got some output\n output normal $line\n\n } elseif { [eof $f] } {\n # End of file\n closePipe $f\n\n } elseif { [fblocked $f] } {\n # Read blocked, so do nothing\n }\n}\n\n\nmain\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166231",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/842/"
] |
166,258
|
<p>Is there a way to configure an assembly in GAC? I want to add a custom configuration to my assembly with System.Configuration.</p>
<p>Mher</p>
|
[
{
"answer_id": 166826,
"author": "Chris Ballard",
"author_id": 18782,
"author_profile": "https://Stackoverflow.com/users/18782",
"pm_score": 0,
"selected": false,
"text": "Application Data Common Application Data"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
166,270
|
<p>Is it possible to use oracle instant client for application that use oraoledb driver for connecting to oracle 9i DB.</p>
|
[
{
"answer_id": 49946548,
"author": "Baumann",
"author_id": 1303378,
"author_profile": "https://Stackoverflow.com/users/1303378",
"pm_score": 2,
"selected": false,
"text": "install oledb c:\\oracle\\odac_12_1 odac true regsvr32 oraoledb12.dll"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22076/"
] |
166,298
|
<p>Is there any substantial difference between those two terms?. I understand that JDK stands for Java Development Kit that is a subset of SDK (Software Development Kit). But specifying Java SDK, it should mean the same as JDK.</p>
|
[
{
"answer_id": 66506764,
"author": "Kidus Tekeste",
"author_id": 6021740,
"author_profile": "https://Stackoverflow.com/users/6021740",
"pm_score": 0,
"selected": false,
"text": "write a java program run a java program contains Write Once(compile once) run anywhere.(WORA)"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/94303/"
] |
166,299
|
<p>I'm using the jQuery slideToggle function on a site to reveal 'more information' about something. When I trigger the slide, the content is gradually revealed, but is located to the right by about 100 pixels until the end of the animation when it suddenly jumps to the correct position. Going the other way, the content jumps right by the same amount just before it starts its 'hide' animation, then is gradually hidden.</p>
<p>Occurs on IE7/8, FF, Chrome.</p>
<p>Any ideas on how I would fix this?</p>
<p>Thanks in advance.</p>
|
[
{
"answer_id": 172362,
"author": "matdumsa",
"author_id": 1775,
"author_profile": "https://Stackoverflow.com/users/1775",
"pm_score": 2,
"selected": false,
"text": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n"
},
{
"answer_id": 450716,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "position: relative; width: 709px;"
},
{
"answer_id": 5286410,
"author": "Sparky",
"author_id": 594235,
"author_profile": "https://Stackoverflow.com/users/594235",
"pm_score": 2,
"selected": false,
"text": "<div> overflow:hidden; overflow:hidden; <div> <p> overflow:hidden; <div> div p ul div a div"
},
{
"answer_id": 6458245,
"author": "DanielBlazquez",
"author_id": 321480,
"author_profile": "https://Stackoverflow.com/users/321480",
"pm_score": 2,
"selected": false,
"text": "$('#slider').css('height', $('#slider').height() + 'px');\n"
},
{
"answer_id": 7435955,
"author": "Ben",
"author_id": 947530,
"author_profile": "https://Stackoverflow.com/users/947530",
"pm_score": 3,
"selected": false,
"text": "overflow: hidden; position: relative; \n"
},
{
"answer_id": 11127829,
"author": "MJohnson",
"author_id": 1470419,
"author_profile": "https://Stackoverflow.com/users/1470419",
"pm_score": 2,
"selected": false,
"text": ".slideToggle overflow:hidden position: relative"
},
{
"answer_id": 13070886,
"author": "Adarchy",
"author_id": 1720513,
"author_profile": "https://Stackoverflow.com/users/1720513",
"pm_score": 0,
"selected": false,
"text": "//this function is to avoid slideToggle jQuery jump bug.\n$.fn.slideShow = function(time,easing) { return $(this).animate({height:'show','margin-top':'show','margin-bottom':'show','padding-top':'show','padding-bottom':'show',opacity:1},time,easing); }\n$.fn.slideHide = function(time,easing) {return $(this).animate({height:'hide','margin-top':'hide','margin-bottom':'hide','padding-top':'hide','padding-bottom':'hide',opacity:0},time,easing); }\n $(this).slideShow(320,'easeOutQuart');\n$(this).slideHide(320,'easeOutQuart');\n"
},
{
"answer_id": 13872603,
"author": "Francisco Javier Arenas Ulloa",
"author_id": 1902981,
"author_profile": "https://Stackoverflow.com/users/1902981",
"pm_score": 1,
"selected": false,
"text": "<div class=\"details\">\n <div class=\"hidden\"> [your toggled info] </div>\n</div>\n .details{\n position:relative;\n}\n.hidden{\n display:none;\n}\n $('.hidden').slideToggle(\"slow\");\n"
},
{
"answer_id": 17746855,
"author": "rmorse",
"author_id": 459359,
"author_profile": "https://Stackoverflow.com/users/459359",
"pm_score": 1,
"selected": false,
"text": "<div> div position:relative"
},
{
"answer_id": 30946712,
"author": "Steven Brand",
"author_id": 4812196,
"author_profile": "https://Stackoverflow.com/users/4812196",
"pm_score": 1,
"selected": false,
"text": "-webkit-transform-origin: top;\n-moz-transform-origin: top;\n-ms-transform-origin: top;\n-o-transform-origin: top;\ntransform-origin: top;\n\n-webkit-transition: transform 0.26s ease;\n-moz-transition: transform 0.26s ease;\n-ms-transition: transform 0.26s ease;\n-o-transition: transform 0.26s ease;\ntransition: transform 0.26s ease;\ntransition: -webkit-transform 0.26s ease;\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166299",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/691/"
] |
166,321
|
<p>Is it possible to create a SQL query which will return one column which contains the dates from a given date range (e.g. all dates from last year till today). E.g.</p>
<pre><code>dat
----
2007-10-01
2007-10-02
2007-10-03
2007-10-04
...
</code></pre>
<p>I am wondering if this is possible as an alternative to creating a table which holds all those dates precalculated.</p>
<p><strong>Updated:</strong> I need a solution for MYSQL. I am not interested in any other DBs in this case.</p>
|
[
{
"answer_id": 166345,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 2,
"selected": false,
"text": "DECLARE @start datetime\nDECLARE @end datetime\nDECLARE @results TABLE\n(\n val datetime not null\n)\nset @start = '2008-10-01'\nset @end = getdate()\nwhile @start < @end\nbegin\n insert into @results values(@start)\n SELECT @start = DATEADD (d, 1, @start)\nend\nselect val from @results\n 2008-10-01 00:00:00.000\n2008-10-02 00:00:00.000\n2008-10-03 00:00:00.000\n"
},
{
"answer_id": 166652,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 2,
"selected": false,
"text": "CREATE TABLE dbo.Numbers \n( \n Number INT IDENTITY(1,1) PRIMARY KEY CLUSTERED \n) \n\nWHILE COALESCE(SCOPE_IDENTITY(), 0) <= 1024 \nBEGIN \n INSERT dbo.Numbers DEFAULT VALUES \nEND\n\nSELECT DATEADD(dd, Number, DATEADD(dd, 0, DATEDIFF(dd, 0, DATEADD(yy, -1, GETDATE())))) AS Date\nFROM Numbers\nWHERE Number BETWEEN 0 AND 366\n WITH DateRange(Date) AS\n(\n SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, DATEADD(yy, -1, GETDATE()))) AS Date\n UNION ALL\n SELECT DATEADD(day, 1, Date) AS Date\n FROM DateRange\n WHERE Date <= GETDATE()\n)\nSELECT Date \nFROM DateRange\nOPTION (MAXRECURSION 366)\n"
},
{
"answer_id": 167618,
"author": "Pittsburgh DBA",
"author_id": 10224,
"author_profile": "https://Stackoverflow.com/users/10224",
"pm_score": 2,
"selected": false,
"text": "SELECT\n ADDDATE('2007-01-01' INTERVAL SeqValue DAY) DateValue\nFROM\n(\nSELECT\n (HUNDREDS.SeqValue + TENS.SeqValue + ONES.SeqValue) SeqValue\nFROM\n (\n SELECT 0 SeqValue\n UNION ALL\n SELECT 1 SeqValue\n UNION ALL\n SELECT 2 SeqValue\n UNION ALL\n SELECT 3 SeqValue\n UNION ALL\n SELECT 4 SeqValue\n UNION ALL\n SELECT 5 SeqValue\n UNION ALL\n SELECT 6 SeqValue\n UNION ALL\n SELECT 7 SeqValue\n UNION ALL\n SELECT 8 SeqValue\n UNION ALL\n SELECT 9 SeqValue\n ) ONES\nCROSS JOIN\n (\n SELECT 0 SeqValue\n UNION ALL\n SELECT 10 SeqValue\n UNION ALL\n SELECT 20 SeqValue\n UNION ALL\n SELECT 30 SeqValue\n UNION ALL\n SELECT 40 SeqValue\n UNION ALL\n SELECT 50 SeqValue\n UNION ALL\n SELECT 60 SeqValue\n UNION ALL\n SELECT 70 SeqValue\n UNION ALL\n SELECT 80 SeqValue\n UNION ALL\n SELECT 90 SeqValue\n ) TENS\nCROSS JOIN\n (\n SELECT 0 SeqValue\n UNION ALL\n SELECT 100 SeqValue\n UNION ALL\n SELECT 200 SeqValue\n UNION ALL\n SELECT 300 SeqValue\n UNION ALL\n SELECT 400 SeqValue\n UNION ALL\n SELECT 500 SeqValue\n UNION ALL\n SELECT 600 SeqValue\n UNION ALL\n SELECT 700 SeqValue\n UNION ALL\n SELECT 800 SeqValue\n UNION ALL\n SELECT 900 SeqValue\n ) HUNDREDS\n) SEQ\nWHERE\n SEQ.SeqValue < = 366 AND\n ADDDATE('2007-01-01' INTERVAL SeqValue DAY) < ADDDATE('2007-01-01' INTERVAL 1 YEAR)\nORDER BY\n ADDDATE('2007-01-01' INTERVAL SeqValue DAY) ASC\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21672/"
] |
166,322
|
<p>what is the best way of displaying/using the revision number in a java webapp?</p>
<p>we just use ant to build our .war archive, no buildserver or such. i'd hope there was some kind if $ref that i could write in a resource file, but this is only updated when the file in question is committed. i need it globally.</p>
<p>what would you recommend? post-commit triggers that update certain files?
custom ant scripts? is there a more non-hacky way of doing this?
or it it better to have my own version number independent of svn.</p>
<p>edit: great suggestions! thanks a lot for the answers!</p>
|
[
{
"answer_id": 166328,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 1,
"selected": false,
"text": "$Id:$"
},
{
"answer_id": 167092,
"author": "serg10",
"author_id": 1853,
"author_profile": "https://Stackoverflow.com/users/1853",
"pm_score": 3,
"selected": true,
"text": "info rev"
},
{
"answer_id": 171010,
"author": "KeithB",
"author_id": 2298,
"author_profile": "https://Stackoverflow.com/users/2298",
"pm_score": 3,
"selected": false,
"text": "<target name=\"package\" depends=\"compile\" description=\"Package up the project as a jar\">\n<!-- Create the subversion version string -->\n<exec executable=\"svnversion\" failifexecutionfails=\"no\" outputproperty=\"version\">\n <arg value=\".\"/> \n <arg value=\"-n\"/>\n</exec>\n<!-- Create the time stamp -->\n<tstamp>\n <format property=\"timeAndDate\" pattern=\"HH:mm d-MMMM-yyyy\"/>\n</tstamp>\n\n<jar destfile=\"simfraserv.jar\">\n <manifest>\n <attribute name=\"Built-By\" value=\"${user.name} on ${time.date}\" />\n <attribute name=\"Implementation-Version\" value=\"${svn.version}\" />\n <attribute name=\"Implementation-Java\" value=\"${java.vendor} ${java.version}\" />\n <attribute name=\"Implementation-Build-OS\" value=\"${os.name} ${os.arch} ${os.version}\" />\n <attribute name=\"JVM-Version\" value=\"${common.sourcelevel}+\" /> \n </manifest>\n <fileset dir=\"bin\">\n <include name=\"**/*.class\"/>\n </fileset>\n <fileset dir=\"src\">\n <include name=\"**\"/>\n </fileset>\n</jar>\n</target>\n String version = this.getClass().getPackage().getImplementationVersion();\n"
},
{
"answer_id": 11437267,
"author": "Paulo Fidalgo",
"author_id": 1006863,
"author_profile": "https://Stackoverflow.com/users/1006863",
"pm_score": 2,
"selected": false,
"text": " <target name=\"version\">\n<exec executable=\"svn\" output=\"svninfo.xml\" failonerror=\"true\">\n <arg line=\"info --xml\" />\n</exec>\n<xmlproperty file=\"svninfo.xml\" collapseattributes=\"true\" />\n<echo message=\"SVN Revision: ${info.entry.commit.revision}\"/>\n<property name=\"revision\" value=\"${info.entry.commit.revision}\" />\n</target>\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16542/"
] |
166,330
|
<p>This is a nut I'm cracking these days</p>
<p>Application I'm working on has some advanced processing towards SQL. One of the operations selects various metadata on the objects in the current context from different tables, based on the item names in the collection. For this, a range of "select...from...where...in()" is executed, and to prevent malicious SQL code, Sql parameters are used for constructing the contents of the "in()" clause.</p>
<p>However, when the item collection for constructing the "in()" clause is larger than 2100 items, this fails due to the Sql Server limitation of max 2100 Sql parameters per query.</p>
<p>One approach I'm trying out now is creating a #temp table for storing all item names and then joining the table in the original query, instead of using "where in()". This has me scratching my head on how to populate the table with the item names stored in an Array in the .NET code. Surely, there has to be some bulk way to insert everything rather than issuing a separate "insert into" for each item?</p>
<p>Other than that, I'm very much interested in alternative approaches for solving this issue.</p>
<p>Thanks a lot</p>
|
[
{
"answer_id": 166348,
"author": "Torbjörn Gyllebring",
"author_id": 21182,
"author_profile": "https://Stackoverflow.com/users/21182",
"pm_score": 3,
"selected": false,
"text": "declare @wanted xml\nset @wanted = '<ids><id>1</id><id>2</id></ids>'\nselect * \nfrom (select 1 Id union all select 3) SourceTable \nwhere Id in(select Id.value('.', 'int') from @wanted.nodes('/ids/id') as Foo(Id))\n"
},
{
"answer_id": 166395,
"author": "Carl",
"author_id": 951280,
"author_profile": "https://Stackoverflow.com/users/951280",
"pm_score": 0,
"selected": false,
"text": " CREATE FUNCTION [dbo].[Split](\n @list ntext\n)\nRETURNS @tbl TABLE (listpos int IDENTITY(1, 1) NOT NULL,\n number int NOT NULL) \nAS\nBEGIN\n DECLARE @pos int,\n @textpos int,\n @chunklen smallint,\n @str nvarchar(4000),\n @tmpstr nvarchar(4000),\n @leftover nvarchar(4000)\n\n SET @textpos = 1\n SET @leftover = ''\n WHILE @textpos <= datalength(@list) / 2\n BEGIN\n SET @chunklen = 4000 - datalength(@leftover) / 2\n SET @tmpstr = ltrim(@leftover + substring(@list, @textpos, @chunklen))\n SET @textpos = @textpos + @chunklen\n\n SET @pos = charindex(',', @tmpstr)\n WHILE @pos > 0\n BEGIN\n SET @str = substring(@tmpstr, 1, @pos - 1)\n INSERT @tbl (number) VALUES(convert(int, @str))\n SET @tmpstr = ltrim(substring(@tmpstr, @pos + 1, len(@tmpstr)))\n SET @pos = charindex(',', @tmpstr)\n END\n\n SET @leftover = @tmpstr\n END\n\n IF ltrim(rtrim(@leftover)) <> ''\n INSERT @tbl (number) VALUES(convert(int, @leftover))\n\n RETURN\nEND\n select a.number from split('1,2,3') a inner join myothertable b on a.number = b.ID\n"
}
] |
2008/10/03
|
[
"https://Stackoverflow.com/questions/166330",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21692/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.