qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
294,355 | <p>Does anyone know of a good YAML Parser for PHP? If so, what are the pros and cons of this library?</p>
| [
{
"answer_id": 854262,
"author": "drowe",
"author_id": 105563,
"author_profile": "https://Stackoverflow.com/users/105563",
"pm_score": 6,
"selected": false,
"text": "require_once \"spyc.php\";\n$data = Spyc::YAMLLoad($myfile);\n $yaml_str = Spyc::YAMLDump($myarray);\n"
},
{
"answer_id": 2446512,
"author": "takeshin",
"author_id": 234780,
"author_profile": "https://Stackoverflow.com/users/234780",
"pm_score": 2,
"selected": false,
"text": "sfYaml vendor"
},
{
"answer_id": 3691710,
"author": "NullUserException",
"author_id": 396458,
"author_profile": "https://Stackoverflow.com/users/396458",
"pm_score": 7,
"selected": false,
"text": "php-yaml 1.3.0 2016-09-24 YAML 1.1 [PHP 5]\nphp-yaml 2.0.0 2016-09-24 YAML 1.1 [PHP 7]\nsyck 0.9.3 2008-11-18 YAML 1.0\nsfYaml 3.3.5 2017-06-15 YAML 1.1, most of 1.2\nspyc 0.6.2 2017-02-24 YAML 1.1 \n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2327/"
] |
294,382 | <p>Is there any reason to prefer a <code>CharBuffer</code> to a <code>char[]</code> in the following:</p>
<pre><code>CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE);
while( in.read(buf) >= 0 ) {
out.append( buf.flip() );
buf.clear();
}
</code></pre>
<p>vs.</p>
<pre><code>char[] buf = new char[DEFAULT_BUFFER_SIZE];
int n;
while( (n = in.read(buf)) >= 0 ) {
out.write( buf, 0, n );
}
</code></pre>
<p>(where <code>in</code> is a <code>Reader</code> and <code>out</code> in a <code>Writer</code>)?</p>
| [
{
"answer_id": 294469,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 5,
"selected": true,
"text": "CharBuffer CharBuffer ByteBuffer"
},
{
"answer_id": 295190,
"author": "Ron Tuffin",
"author_id": 939,
"author_profile": "https://Stackoverflow.com/users/939",
"pm_score": 3,
"selected": false,
"text": "public class CharBufferScratchBox\n{\n public static void main(String[] args) throws Exception\n {\n // Some Setup Stuff\n String smallString =\n \"1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000\";\n\n StringBuilder stringBuilder = new StringBuilder();\n for (int i = 0; i < 1000; i++)\n {\n stringBuilder.append(smallString);\n }\n String string = stringBuilder.toString();\n int DEFAULT_BUFFER_SIZE = 1000;\n int ITTERATIONS = 10000;\n\n // char[]\n StringReader in1 = null;\n StringWriter out1 = null;\n Date start = new Date();\n for (int i = 0; i < ITTERATIONS; i++)\n {\n in1 = new StringReader(string);\n out1 = new StringWriter(string.length());\n\n char[] buf = new char[DEFAULT_BUFFER_SIZE];\n int n;\n while ((n = in1.read(buf)) >= 0)\n {\n out1.write(\n buf,\n 0,\n n);\n }\n }\n Date done = new Date();\n System.out.println(\"char[] : \" + (done.getTime() - start.getTime()));\n\n // CharBuffer\n StringReader in2 = null;\n StringWriter out2 = null;\n start = new Date();\n CharBuffer buff = CharBuffer.allocate(DEFAULT_BUFFER_SIZE);\n for (int i = 0; i < ITTERATIONS; i++)\n {\n in2 = new StringReader(string);\n out2 = new StringWriter(string.length());\n int n;\n while ((n = in2.read(buff)) >= 0)\n {\n out2.write(\n buff.array(),\n 0,\n n);\n buff.clear();\n }\n }\n done = new Date();\n System.out.println(\"CharBuffer: \" + (done.getTime() - start.getTime()));\n }\n}\n"
},
{
"answer_id": 304059,
"author": "James Schek",
"author_id": 17871,
"author_profile": "https://Stackoverflow.com/users/17871",
"pm_score": 2,
"selected": false,
"text": "char[] = 4139 ms\nCharBuffer = 4466 ms\nByteBuffer = 938 (direct) ms\n public static void main(String[] args) throws Exception {\n File f = getBytes(5000000);\n System.out.println(f.getAbsolutePath());\n try {\n System.gc();\n List<Main> impls = new java.util.ArrayList<Main>();\n impls.add(new CharArrayImpl());\n //impls.add(new CharArrayNoBuffImpl());\n impls.add(new CharBufferImpl());\n //impls.add(new CharBufferNoBuffImpl());\n impls.add(new ByteBufferDirectImpl());\n //impls.add(new CharBufferDirectImpl());\n for (int i = 0; i < 25; i++) {\n for (Main impl : impls) {\n test(f, impl);\n }\n System.out.println(\"-----\");\n if(i==0)\n continue; //reset profiler\n }\n System.gc();\n System.out.println(\"Finished\");\n return;\n } finally {\n f.delete();\n }\n}\nstatic int BUFFER_SIZE = 1000;\n\nstatic File getBytes(int size) throws IOException {\n File f = File.createTempFile(\"input\", \".txt\");\n FileWriter writer = new FileWriter(f);\n Random r = new Random();\n for (int i = 0; i < size; i++) {\n writer.write(Integer.toString(5));\n }\n writer.close();\n return f;\n}\n\nstatic void test(File f, Main impl) throws IOException {\n InputStream in = new FileInputStream(f);\n File fout = File.createTempFile(\"output\", \".txt\");\n try {\n OutputStream out = new FileOutputStream(fout, false);\n try {\n long start = System.currentTimeMillis();\n impl.runTest(in, out);\n long end = System.currentTimeMillis();\n System.out.println(impl.getClass().getName() + \" = \" + (end - start) + \"ms\");\n } finally {\n out.close();\n }\n } finally {\n fout.delete();\n in.close();\n }\n}\n\npublic abstract void runTest(InputStream ins, OutputStream outs) throws IOException;\n\npublic static class CharArrayImpl extends Main {\n\n char[] buff = new char[BUFFER_SIZE];\n\n public void runTest(InputStream ins, OutputStream outs) throws IOException {\n Reader in = new BufferedReader(new InputStreamReader(ins));\n Writer out = new BufferedWriter(new OutputStreamWriter(outs));\n int n;\n while ((n = in.read(buff)) >= 0) {\n out.write(buff, 0, n);\n }\n }\n}\n\npublic static class CharBufferImpl extends Main {\n\n CharBuffer buff = CharBuffer.allocate(BUFFER_SIZE);\n\n public void runTest(InputStream ins, OutputStream outs) throws IOException {\n Reader in = new BufferedReader(new InputStreamReader(ins));\n Writer out = new BufferedWriter(new OutputStreamWriter(outs));\n int n;\n while ((n = in.read(buff)) >= 0) {\n buff.flip();\n out.append(buff);\n buff.clear();\n }\n }\n}\n\npublic static class ByteBufferDirectImpl extends Main {\n\n ByteBuffer buff = ByteBuffer.allocateDirect(BUFFER_SIZE * 2);\n\n public void runTest(InputStream ins, OutputStream outs) throws IOException {\n ReadableByteChannel in = Channels.newChannel(ins);\n WritableByteChannel out = Channels.newChannel(outs);\n int n;\n while ((n = in.read(buff)) >= 0) {\n buff.flip();\n out.write(buff);\n buff.clear();\n }\n }\n}\n"
},
{
"answer_id": 540657,
"author": "akuhn",
"author_id": 24468,
"author_profile": "https://Stackoverflow.com/users/24468",
"pm_score": 1,
"selected": false,
"text": "CharBuffer #subsequence() capacity remaining"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1412/"
] |
294,443 | <p>I'm looking for a consistent way to structure my use of formatting strings throughout a large web application, and I'm looking for recommendations or best practices on which way to go.</p>
<p>Up until now I've had a static class that does some common formatting e.g.</p>
<p>Formatting.FormatCurrency</p>
<p>Formatting.FormatBookingReference</p>
<p>I'm not convinced that this is the way to go though, I'd prefer to use the standard way of formatting strings within .NET directly and use:</p>
<p>amount.ToString("c")</p>
<p>reference.ToString("000000")</p>
<p>Id use IFormattable and ICustomFormatter for some of our more complicated data structures, but I'm struggling what to do about the more simple existing objects that we need to format (in this case Int32 but also DateTime). </p>
<p>Do I simply define constants for "c" and "000000" and use them consistently around the whole web app or is there a more standard way to do it?</p>
| [
{
"answer_id": 294448,
"author": "GeekyMonkey",
"author_id": 29900,
"author_profile": "https://Stackoverflow.com/users/29900",
"pm_score": 5,
"selected": true,
"text": "public static class MyWebAppExtensions\n{\n public static string FormatCurrency(this decimal d)\n {\n return d.ToString(\"c\");\n }\n}\n Decimal d = 100.25;\nstring s = d.FormatCurrency();\n"
},
{
"answer_id": 294601,
"author": "Bryan Watts",
"author_id": 37815,
"author_profile": "https://Stackoverflow.com/users/37815",
"pm_score": 3,
"selected": false,
"text": "ToCurrencyString"
},
{
"answer_id": 294626,
"author": "Jonas Kongslund",
"author_id": 37548,
"author_profile": "https://Stackoverflow.com/users/37548",
"pm_score": 2,
"selected": false,
"text": "globalization resourceProviderFactoryType InitializeCulture protected override void InitializeCulture()\n{\n Thread.CurrentThread.CurrentCulture = ...;\n Thread.CurrentThread.CurrentUICulture = ...;\n\n Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = \"dd-MM-yyyy\";\n ...\n}\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5777/"
] |
294,444 | <p>I have long tables generated by datagrid control that go beyond the page width. I would like to convert that into separate table for each row or definition list where each field name is followed by field value.</p>
<p>How would I do that. </p>
| [
{
"answer_id": 294575,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": true,
"text": "$(document).ready(\n function() {\n\n var headers = $('tr:first').children();\n\n $('tr:not(:first)').each(\n\n function(i,row) {\n\n var cols = jQuery(row).children();\n\n var dl = jQuery('<dl></dl>');\n\n for (var i=0, len = headers.length; i < len; ++i) {\n var dt = jQuery('<dt>');\n dt.text( jQuery(headers[i]).text() );\n\n var dd = jQuery('<dd>');\n dd.text( jQuery(cols[i]).text() );\n\n dl.append(dt).append(dd);\n }\n $('body').append(dl);\n }\n );\n $('table').remove();\n }\n);\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35513/"
] |
294,465 | <p>DBD, and Oracle Masters:</p>
<p>I have a Perl web application that is behaving oddly. I am using it to read some stuff from an Oracle DB and report. I have version 11.1.0.6.0 of Oracle's Instant Client installed. I'm running on WinXP and have the PATH environment variable set to the instant client location. I have Apache2 for my webserver.</p>
<p>Here's the issue: when I run the app from a command line, it works without a hitch. However, when I run from <a href="http://127.0.0.1/cgi-bin/a.cgi" rel="nofollow noreferrer">http://127.0.0.1/cgi-bin/a.cgi</a>, I get the following DB access error:</p>
<blockquote>
<p><code>install_driver(Oracle) failed: Can't load 'C:/usr/lib/auto/DBD/Oracle/Oracle.dll' for module DBD::Oracle: load_file:The specified module could not be found at C:/usr/lib/DynaLoader.pm line 202. at (eval 9) line 3</code></p>
</blockquote>
<p>Intuition tells me it's a permission issue, but I'm not sure where to look further. Can anyone shed some light on this? I would much appreciate any help.</p>
<p>Thanks,
Saker Ghani</p>
| [
{
"answer_id": 294476,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 2,
"selected": false,
"text": "open"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
294,468 | <p>I am developing a system as an aid to musicians performing transcription. The aim is to perform automatic music transcription (it does not have to be perfect, as the user will correct glitches / mistakes later) on a single instrument monophonic recording. Does anyone here have experience in automatic music transcription? Or digital signal processing in general? Help from anyone is greatly appreciated no matter what your background.</p>
<p>So far I have investigated the use of the Fast Fourier Transform for pitch detection, and a number of tests in both MATLAB and my own Java test programs have shown it to be fast and accurate enough for my needs. Another element of the task that will need to be tackled is the display of the produced MIDI data in sheet music form, but this is something I am not concerned with right now.</p>
<p>In brief, what I am looking for is a good method for note onset detection, i.e. the position in the signal where a new note begins. As slow onsets can be quite difficult to detect properly, I will initially be using the system with piano recordings. This is also partially due to the fact I play piano and should be in a better position to obtain suitable recordings for testing. As stated above, early versions of this system will be used for simple monophonic recordings, possibly progressing later to more complex input depending on progress made in the coming weeks.</p>
| [
{
"answer_id": 294724,
"author": "MusiGenesis",
"author_id": 14606,
"author_profile": "https://Stackoverflow.com/users/14606",
"pm_score": 7,
"selected": true,
"text": "short threshold = 10000;\nfor (int i = 0; i < samples.Length; i++)\n{\n if ((short)Math.Abs(samples[i]) > threshold) \n {\n // here is one note onset point\n }\n}\n short threshold = 10000;\nint window_length = 100;\nint running_total = 0;\n// tally up the first window_length samples\nfor (int i = 0; i < window_length; i++)\n{\n running_total += samples[i];\n}\n// calculate moving average\nfor (int i = window_length; i < samples.Length; i++)\n{\n // remove oldest sample and add current\n running_total -= samples[i - window_length];\n running_total += samples[i];\n short moving_average = running_total / window_length;\n if (moving_average > threshold)\n {\n // here is one note onset point \n int onset_point = i - (window_length / 2);\n }\n}\n public void StaticCompress(short[] samples, float param)\n{\n for (int i = 0; i < samples.Length; i++)\n {\n int sign = (samples[i] < 0) ? -1 : 1;\n float norm = ABS(samples[i] / 32768); // NOT short.MaxValue\n norm = 1.0 - POW(1.0 - norm, param);\n samples[i] = 32768 * norm * sign;\n }\n}\n public void StaticCompress(short[] samples, double param)\n{\n for (int i = 0; i < samples.Length; i++)\n {\n Compress(ref samples[i], param);\n }\n}\n\npublic void Compress(ref short orig, double param)\n{\n double sign = 1;\n if (orig < 0)\n {\n sign = -1;\n }\n // 32768 is max abs value of a short. best practice is to pre-\n // normalize data or use peak value in place of 32768\n double norm = Math.Abs((double)orig / 32768.0);\n norm = 1.0 - Math.Pow(1.0 - norm, param);\n orig = (short)(32768.0 * norm * sign); // should round before cast,\n // but won't affect note onset detection\n}\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11650/"
] |
294,470 | <p>I need to set my process to run under 'nobody', I've found os.setuid(), but how do I find <code>uid</code> if I have <code>login</code>?</p>
<p>I've found out that uids are in /etc/passwd, but maybe there is a more pythonic way than scanning /etc/passwd. Anybody?</p>
| [
{
"answer_id": 294480,
"author": "TFKyle",
"author_id": 19208,
"author_profile": "https://Stackoverflow.com/users/19208",
"pm_score": 5,
"selected": true,
"text": "import pwd\npw = pwd.getpwnam(\"nobody\")\nuid = pw.pw_uid\n"
},
{
"answer_id": 294535,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 3,
"selected": false,
"text": "/etc/passwd /etc/passwd getpwent getgrent /etc/nsswitch.conf"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37141/"
] |
294,485 | <p>When I run my asp.net app I get the error</p>
<blockquote>
<p>The type ‘System.Web.UI.ScriptManager’ is ambiguous:</p>
</blockquote>
<p>I am having the same problem this person is having <a href="http://forums.asp.net/t/1313257.aspx" rel="nofollow noreferrer">http://forums.asp.net/t/1313257.aspx</a> , when I change the 1.0.61025.0 to 3.5 and re-compile It resets it to 1.0.61025.0</p>
<p>what I can I do to resolve this. I've been trying to get my app running for hours now.</p>
<p>Thanks</p>
<p>Edit ~ HELPPpppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp</p>
<p>I see 2 system.web.extensions in the GAC. I tried to remove with gacutil.exe /u system.web.ext
ensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft (R) .NET Global Assembly Cache Utility. Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.</p>
<p>Unknown option: Version=1.0.61025.0
what am I doing wrong.</p>
<p>Edit ~ MY SOLUTION</p>
<blockquote>
<p>I went to "Add Remove Programs" and un-installed the Ajax Web Extensions 2.0 version 1.0.61025.0 </p>
</blockquote>
| [
{
"answer_id": 8276727,
"author": "Tom",
"author_id": 1066632,
"author_profile": "https://Stackoverflow.com/users/1066632",
"pm_score": 1,
"selected": false,
"text": " <!-- <add assembly=\"System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\"/> -->\n <!-- <add assembly=\"System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\"/> -->\n <add assembly=\"System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\"/>\n <add assembly=\"System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\"/>\n C:> cd C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\bin\n C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\bin>gacutil /u \"System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\"\n gacutil /u /r \"System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\" FILEPATH C:\\WINDOWS\\system32\\msiexec.exe \"Windows Installer\"\n <%@ Assembly Name=\"System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\" %>\n <%@ Assembly Name=\"System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\" %>\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294485",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23667/"
] |
294,495 | <p>I'm trying to make semantic urls for search pages, but if someone use a search finished in dot, the .net engine return a 404. </p>
<p>The request don't even get to the routing engine, so i think its something related to security or something like that. </p>
<p>For example, the stackoverflow routes also don't work in these case:
<a href="https://stackoverflow.com/questions/tagged/etc."><a href="https://stackoverflow.com/questions/tagged/etc">https://stackoverflow.com/questions/tagged/etc</a>.</a></p>
| [
{
"answer_id": 2541677,
"author": "Aaron Maenpaa",
"author_id": 2603,
"author_profile": "https://Stackoverflow.com/users/2603",
"pm_score": 1,
"selected": false,
"text": "^(.*[^.])(\\.+)$ {R:1}"
},
{
"answer_id": 3542522,
"author": "bkaid",
"author_id": 265570,
"author_profile": "https://Stackoverflow.com/users/265570",
"pm_score": 6,
"selected": true,
"text": "<httpRuntime relaxedUrlToFileSystemMapping=\"true\" />\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27369/"
] |
294,502 | <p>I'm trying to convert Matt Berseth's '<a href="http://mattberseth.com/blog/2007/10/yui_style_yesno_confirm_dialog.html" rel="nofollow noreferrer">YUI Style Yes/No Confirm Dialog</a>' so I can use it with the jQuery blockUI plugin.</p>
<p>I have to admit I'm no CSS guru but I thought this would pretty easy even for me....except 10hrs later I'm at a loss as to why I can't get the blasted thing to work. </p>
<p>The problem is that I can't seem to get the 'confirmDialogue' DIV to centre on the page without some artifacts showing above it. Alternatively if I reset blockUI's CSS settings by doing....:</p>
<pre><code>$.blockUI.defaults.css = {};
</code></pre>
<p>.....I find that the DIV aligns left.</p>
<p>I've tried all sorts of stuff but CSS isn't my strong point being a server side app kinda guy :(</p>
<p>So if anyone out there who's a jQuery/blockUI/CSS wizard reading this...please can you have a go and let me know what I'm getting wrong?</p>
<p>Basically I followed the design template on Matt's blog and the HTML looks like the stuff below (the CSS is unchanged from Matt's sample). You can grab the png 'sprite' file from the complete sample project download at <a href="http://mattberseth2.com/downloads/yui_simpledialog.zip" rel="nofollow noreferrer">http://mattberseth2.com/downloads/yui_simpledialog.zip</a> - it's a .net project but I'm just trying to get this to work in a simple html file, so no .NET knowledge required.</p>
<p>Anyway any advice and guidance would be really really really useful. I'll even incentivise things buy promising to buy you lashings of beer if we ever meet :)</p>
<pre><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script type="text/javascript" src="script/jquery-1.2.6.js"></script>
<script type="text/javascript" src="script/jquery.blockUI.js"></script>
<style>
.modalpopup
{
font-family: arial,helvetica,clean,sans-serif;
font-size: small;
padding: 2px 3px;
display: block;
position: absolute;
}
.container
{
width: 300px;
border: solid 1px #808080;
border-width: 1px 0px;
}
.header
{
background: url(img/sprite.png) repeat-x 0px -200px;
color: #000;
border-color: #808080 #808080 #ccc;
border-style: solid;
border-width: 0px 1px 1px;
padding: 3px 10px;
}
.header .msg
{
font-weight: bold;
}
.body
{
background-color: #f2f2f2;
border-color: #808080;
border-style: solid;
border-width: 0px 1px;
padding-top: 10px;
padding-left: 10px;
padding-bottom: 30px;
}
.body .msg
{
background: url(img/sprite.png) no-repeat 0px -1150px;
float: left;
padding-left: 22px;
}
.footer
{
background-color: #f2f2f2;
border-color: #808080;
border-style: none solid;
border-width: 0px 1px;
text-align:right;
padding-bottom: 8px;
padding-right: 8px;
}
.close
{
right: 7px;
background: url(img/sprite.png) no-repeat 0px -300px;
width: 25px;
cursor: pointer;
position: absolute;
top: 7px;
height: 15px;
}
.modalBackground
{
background-color:Gray;
filter:alpha(opacity=50);
opacity:0.5;
}
</style>
</head>
<body>
<input id="triggerDialogue" name="triggerDialogue" type="button" value="Go" />
<div id="confirmDialogue"
class="modalpopup" style="display:none; text-align: center">
<div class="container">
<div class="header">
<span class="msg">Are you sure?</span>
<a onclick="return false;" class="close"
href="javascript: return false;"></a>
</div>
<div class="body">
<span class="msg">Do you want to continue?</span>
</div>
<div class="footer">
<input type="button" id="Button1" value="Yes" style="width:40px" />
<input type="button" id="Button2" value="No" style="width:40px" />
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#triggerDialogue').click(function() {
$.blockUI({ message: $('#confirmDialogue') });
});
});
</script>
</body>
</html>
</code></pre>
<p>@Owen - many thanks for that. I had to make a wee change in the .modalPopup CSS class in Matt's stylesheet to:</p>
<pre><code>position: fixed;
</code></pre>
<p>....and it works. Much appreciated. I really gotta sit down with my <a href="http://oreilly.com/catalog/9780596527334/" rel="nofollow noreferrer">O'Reilly CSS book</a> which I never get a chance to read some night....:)</p>
| [
{
"answer_id": 294534,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 4,
"selected": true,
"text": "#confirmDialogue #confirmDialogue {\n position: fixed; // absolutely position this element on the page\n height: 200px; // define your height/width so we can calculate with it after\n width: 300px;\n}\n $('#triggerDialogue').click(function() {\n // to position #confirmDialogue, we need the window height/width\n var msg = $('#confirmDialogue');\n var height = $(window).height();\n var width = $(document).width();\n\n msg.css({\n 'left' : width/2 - (msg.width() / 2), // half width - half element width\n 'top' : height/2 - (msg.height() / 2), // similar\n 'z-index' : 15, // make sure element is on top\n });\n\n // etc...\n});\n #confirmDialogue left top"
},
{
"answer_id": 5579772,
"author": "ben",
"author_id": 170768,
"author_profile": "https://Stackoverflow.com/users/170768",
"pm_score": 2,
"selected": false,
"text": "// default usage, this will block the screen and shows a 'please wait...' msg\n$.msg();\n\n// this will show a 'blah blah' msg\n$.msg({ content : 'blah blah' });\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294502",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419/"
] |
294,504 | <p>I am searching for an open-source implementation of an <a href="http://elinux.org/UPnP" rel="nofollow noreferrer">UPnP</a> client in Python, and more specifically of its <a href="http://en.wikipedia.org/wiki/Internet_Gateway_Device_Protocol" rel="nofollow noreferrer">Internet Gateway Device</a> (IGD) part.</p>
<p>For now, I have only been able to find UPnP Media Server implementations, in projects such as <a href="http://pymediaserver.sourceforge.net/" rel="nofollow noreferrer">PyMediaServer</a>, <a href="http://resnet.uoregon.edu/~gurney_j/jmpc/pymeds.html" rel="nofollow noreferrer">PyMedS</a>, <a href="http://brisa.garage.maemo.org/" rel="nofollow noreferrer">BRisa</a> or <a href="https://coherence.beebits.net/" rel="nofollow noreferrer">Coherence</a>.</p>
<p>I am sure I could use those code bases as a start, but the Media Server part will introduce unneeded complexity.</p>
<p>So can you recommend a client UPnP (and hopefully IGD) Python library? An alternative would be to dispatch calls to a C library such as <a href="http://miniupnp.free.fr/" rel="nofollow noreferrer">MiniUPnP</a>, but I would much prefer a pure Python implementation.</p>
<p>Update: an interesting, kind of related discussion of SSDP and UPnP is available on <a href="https://stackoverflow.com/questions/22321/remoting-server-auto-discovery-broadcast-or-not">StackOverflow</a>.</p>
| [
{
"answer_id": 298052,
"author": "oparisy",
"author_id": 38096,
"author_profile": "https://Stackoverflow.com/users/38096",
"pm_score": 4,
"selected": true,
"text": "testupnpigd.py"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294504",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38096/"
] |
294,517 | <p>I'm writing a script that pulls XML data from wowarmory.com, using PHP 5 and cURL:</p>
<pre><code>$url = "http://www.wowarmory.com";
$userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$url);
$str = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
$str .= "Accept-Language: en-us,en;q=0.5\r\n";
$str .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
$str .= "Keep-Alive: 300\r\n";
$str .= "Connection: keep-alive\r\n";
curl_setopt($ch, CURLOPT_HTTPHEADER, array($str));
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 3000);
$xml = curl_exec($ch);
</code></pre>
<p>When I run this from my hosted web server, I get the XML response as expected. But when running from my localhost web server, I get nothing.</p>
<p>I can get any other website via cURL from localhost ( yahoo.com, even worldofwarcraft.com ), but not wowarmory.com. So I know cURL is functioning properly.</p>
<p>I'm using the following versions of PHP and cURL:</p>
<p>Hosted Server:</p>
<ul>
<li>php 5.2.6</li>
<li>cURL libcurl/7.16.1 OpenSSL/0.9.7e zlib/1.2.3 </li>
</ul>
<p>Localhost:</p>
<ul>
<li>php 5.2.6</li>
<li>cURL libcurl/7.16.0 OpenSSL/0.9.8i zlib/1.2.3 </li>
</ul>
<p>Any ideas?</p>
<p>EDIT: Localhost is running Windows XP SP3. I can access wowarmory.com through a web browser. Tracert starts timing out at hop 13 ( from my location, obviously ):</p>
<pre><code>13 458 ms 529 ms 549 ms 0.so-6-0-0.BR1.LAX15.ALTER.NET [152.63.116.21]
14 476 ms 510 ms 488 ms 192.205.34.29
15 257 ms 279 ms 261 ms cr1.la2ca.ip.att.net [12.122.128.14]
16 242 ms 259 ms 249 ms gar5.la2ca.ip.att.net [12.122.128.25]
17 252 ms * 1691 ms 12.122.255.74
18 * 2361 ms 634 ms mdf001c7613r0003-gig-10-1.lax1.attens.net [12.129.193.242]
19 * * * Request timed out.
</code></pre>
<p>I'm not familiar with tcptraceroute, unfortunately. </p>
<p>The windows binary version of curl doesn't return anything for <a href="http://www.wowarmory.com/" rel="nofollow noreferrer">http://www.wowarmory.com/</a> but does for <a href="http://www.yahoo.com/" rel="nofollow noreferrer">http://www.yahoo.com/</a></p>
<p>I don't have wget available.</p>
<p>EDIT 2: I can access my localhosted website just fine. It's just the response from curl I don't receive. I'm running a pretty much default XAMPP install ( apache 2 on windows xp ). All of this works fine. </p>
| [
{
"answer_id": 294555,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 2,
"selected": false,
"text": "curl wget tcptraceroute tcptraceroute"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294517",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
294,520 | <p>I'm generating C++ code, and it seems like it's going to get very messy, even my simple generating classes already have tons of special cases. Here is the code as it stands now: <a href="http://github.com/alex/alex-s-language/tree/local%2Fcpp-generation/alexs_lang/cpp" rel="nofollow noreferrer">http://github.com/alex/alex-s-language/tree/local%2Fcpp-generation/alexs_lang/cpp</a> .</p>
| [
{
"answer_id": 294542,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "indent"
},
{
"answer_id": 294550,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "${thing}"
},
{
"answer_id": 9557837,
"author": "lurscher",
"author_id": 170521,
"author_profile": "https://Stackoverflow.com/users/170521",
"pm_score": 1,
"selected": false,
"text": "class MyFoo\n{\n\npublic:\n/*[[[cog\nimport myAOPDeclarators\nAOP = myAOPDeclarators.AOP\n\nAOP.declareAOPInterceptorMethod( 'invokeSomeStuff' , '(int param1, std::string param2)' )\n]]]*/\n//AOP wrapper\nvoid invokeSomeStuff_ImplementationAOP(int param1, std::string param2);\nvoid invokeSomeStuff(int param1, std::string param2) {\n sendAOPPreEvent( param1 , param2 , \"invokeSomeStuff\" );\n invokeSomeStuff_ImplementationAOP( param1 , param2);\n}\nvoid invokeSomeStuff_ImplementationAOP(int param1, std::string param2)\n//[[[end]]]\n{\n// ...invokeSomeStuff implementation, not automatically generated\n}\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294520",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37181/"
] |
294,543 | <p>I have a main table that I must get data from. I have a left outer join where the fields will match 40% of the time. And then I have another join where I need to match the data from table A with.</p>
<p>This is the SQL in pseudo code. This query won't work.</p>
<p>-- This is the part I want to do but doesn't work.
AND H.COL3 = A.STATE????</p>
<p>I am working with IBM DB2.</p>
<pre><code>SELECT DISTINCT
APP_NO as app_no,
A.STATE as state
...
... Fields
...
FROM
TABLE_A A
LEFT OUTER JOIN
TABLE_B HIST
ON
HIST.COL1 = A.COL1
, TABLE_C B
LEFT OUTER JOIN
TABLE_D H
ON
H.COL2 = B.COL2
-- This is the part I want to do but doesn't work.
AND
H.COL3 = A.STATE????
WHERE
A.BRANCH = 'Data'
</code></pre>
| [
{
"answer_id": 294588,
"author": "Mark",
"author_id": 26310,
"author_profile": "https://Stackoverflow.com/users/26310",
"pm_score": 5,
"selected": true,
"text": "FROM \n TABLE_A A LEFT OUTER JOIN TABLE_B HIST ON\n HIST.COL1 = A.COL1\n LEFT OUTER JOIN TABLE_D H ON \n H.COL3 = A.STATE\n LEFT OUTER JOIN TABLE_C B ON H.COL2 = B.COL2\nWHERE\n A.BRANCH = 'Data'\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294543",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10522/"
] |
294,545 | <p>I have a winforms projects and we use the command pattern. We are trying to clean up our directory structure and make it consistent.</p>
<p>We are trying to decide if we should have a root commands folder or not. What do you think is better for a directory structure?</p>
<p>Project<br>
--Commands<br>
----AddCommand<br>
----SubtractCommand<br>
----InsertCommand<br>
----DeleteCommand </p>
<p>or</p>
<p>Project<br>
--Calculation<br>
----AddCommand<br>
----SubtractCommand<br>
--Database<br>
----InsertCommand<br>
----DeleteCommand </p>
| [
{
"answer_id": 294561,
"author": "Nathan W",
"author_id": 6335,
"author_profile": "https://Stackoverflow.com/users/6335",
"pm_score": 0,
"selected": false,
"text": "Project\n-Commands\n--Calculation\n----AddCommand\n----SubtractCommand\n--Database\n----InsertCommand\n----DeleteCommand\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
294,553 | <p>I was just wondering if there is any difference between the two different new object initializers or is it just syntactic sugar. </p>
<p>So is:</p>
<pre><code>Dim _StreamReader as New Streamreader(mystream)
</code></pre>
<p>and different to:</p>
<pre><code>Dim _StreamReader as Streamreader = new streamreader(mystream)
</code></pre>
<p>Is there any difference under the hood? or are they both the same? Which one do you prefer to use?</p>
| [
{
"answer_id": 294568,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 5,
"selected": true,
"text": "As New As New Nothing"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6335/"
] |
294,558 | <p>I have an enumeration: <code>ENUM( 'alpha', 'beta', 'gamma', 'delta', 'omega' )</code></p>
<p>If I sort my table by this column I get them in the correct order defined above.</p>
<p>However, I can't find a way to select a subset of these, e.g. everything before delta. Using <code>WHERE status < 'delta'</code> only returns alpha and beta, not gamma. It seems MySQL uses a string comparison, not enum index comparison.</p>
<p>I could use the index numbers - i.e. <code>WHERE status < 4</code> - but it's a bit of a code smell (magic numbers) and may break if I insert new values into the enumeration.</p>
| [
{
"answer_id": 294603,
"author": "Kendrick Erickson",
"author_id": 37882,
"author_profile": "https://Stackoverflow.com/users/37882",
"pm_score": 2,
"selected": false,
"text": "FIELD(column, \"string1\", \"string2\", ...) ENUM SELECT * FROM `table` WHERE FIELD(`enum_column`, \"alpha\", \"delta\", \"et cetera\");\n FIND_IN_SET(\"needle\", \"hay,stack\")"
},
{
"answer_id": 296439,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": true,
"text": "ENUM"
},
{
"answer_id": 1557900,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "SELECT\nCONVERT(category USING utf8) as str_category \nFROM\nexample\nGROUP BY\nstr_category\nORDER BY \nstr_category\n"
},
{
"answer_id": 5512129,
"author": "felixlaumon",
"author_id": 387831,
"author_profile": "https://Stackoverflow.com/users/387831",
"pm_score": 3,
"selected": false,
"text": "status+0"
},
{
"answer_id": 25040832,
"author": "John Frickson",
"author_id": 1335722,
"author_profile": "https://Stackoverflow.com/users/1335722",
"pm_score": 0,
"selected": false,
"text": "CREATE fEnumIndex(_table VARCHAR(50), _col VARCHAR(50), _val VARCHAR(50))\nRETURNS INT DETERMINISTIC\nBEGIN\n DECLARE _lst VARCHAR(8192);\n DECLARE _ndx INT;\n\n SELECT REPLACE(REPLACE(REPLACE(COLUMN_TYPE,''', ''',','),'enum(',''),')','')\n FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND\n TABLE_NAME=_table AND COLUMN_NAME=_col INTO _lst;\n SET _ndx = FIND_IN_SET(_val, _lst);\n RETURN _ndx;\nEND\n SELECT * FROM MyTable WHERE Status < fEnumIndex('MyTable','Status','delta') ;\n SELECT REPLACE(REPLACE(REPLACE(COLUMN_TYPE,''', ''',','),'enum(',''),')','') COLUMN_TYPE ENUM( 'alpha', 'beta', 'gamma', 'delta', 'omega' ) 'alpha, beta, gamma, delta, omega' FIND_IN_SET(_val, _lst) REPLACE"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37947/"
] |
294,582 | <p>I'm currently considering the use of Reflection classes (ReflectionClass and ReflectionMethod mainly) in my own MVC web framework, because I need to automatically instanciate controller classes and invoke their methods without any required configuration ("convention over configuration" approach).</p>
<p>I'm concerned about performance, even though I think that database requests are likely to be bigger bottlenecks than the actual PHP code.</p>
<p>So, I'm wondering if anyone has any good or bad experience with PHP 5 Reflection from a performance point of view.</p>
<p>Besides, I'd be curious to know if any one of the popular PHP frameworks (CI, Cake, Symfony, etc.) actually use Reflection.</p>
| [
{
"answer_id": 409299,
"author": "codeassembly",
"author_id": 47537,
"author_profile": "https://Stackoverflow.com/users/47537",
"pm_score": 2,
"selected": false,
"text": "<?php\nrequire_once('sanitize.inc');\n\n/**\n * MVC Controller\n *\n * This Class implements MVC Controller part\n *\n * @package MVC\n * @subpackage Controller\n *\n */\nclass Controller {\n\n /**\n * Standard Controller constructor\n */\n static private $moduleName;\n static private $actionName;\n static private $params;\n\n /**\n * Don't allow construction of the controller (this is a singleton)\n *\n */\n private function __construct() {\n\n }\n\n /**\n * Don't allow cloning of the controller (this is a singleton)\n *\n */\n private function __clone() {\n\n }\n\n /**\n * Returns current module name\n *\n * @return string\n */\n function getModuleName() {\n return self :: $moduleName;\n }\n\n /**\n * Returns current module name\n *\n * @return string\n */\n function getActionName() {\n return self :: $actionName;\n }\n\n /**\n * Returns the subdomain of the request\n *\n * @return string\n */\n function getSubdomain() {\n return substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.'));\n }\n\n function getParameters($moduleName = false, $actionName = false) {\n if ($moduleName === false or ( $moduleName === self :: $moduleName and $actionName === self :: $actionName )) {\n return self :: $params;\n } else {\n if ($actionName === false) {\n return false;\n } else {\n @include_once ( FRAMEWORK_PATH . '/modules/' . $moduleName . '.php' );\n $method = new ReflectionMethod('mod_' . $moduleName, $actionName);\n foreach ($method->getParameters() as $parameter) {\n $parameters[$parameter->getName()] = null;\n }\n return $parameters;\n }\n }\n }\n\n /**\n * Redirect or direct to a action or default module action and parameters\n * it has the ability to http redirect to the specified action\n * internally used to direct to action\n *\n * @param string $moduleName\n * @param string $actionName\n * @param array $parameters\n * @param bool $http_redirect\n\n * @return bool\n */\n function redirect($moduleName, $actionName, $parameters = null, $http_redirect = false) {\n self :: $moduleName = $moduleName;\n self :: $actionName = $actionName;\n // We assume all will be ok\n $ok = true;\n\n @include_once ( PATH . '/modules/' . $moduleName . '.php' );\n\n // We check if the module's class really exists\n if (!class_exists('mod_' . $moduleName, false)) { // if the module does not exist route to module main\n @include_once ( PATH . '/modules/main.php' );\n $modClassName = 'mod_main';\n $module = new $modClassName();\n if (method_exists($module, $moduleName)) {\n self :: $moduleName = 'main';\n self :: $actionName = $moduleName;\n //$_PARAMS = explode( '/' , $_SERVER['REQUEST_URI'] );\n //unset($parameters[0]);\n //$parameters = array_slice($_PARAMS, 1, -1);\n $parameters = array_merge(array($actionName), $parameters); //add first parameter\n } else {\n $parameters = array($moduleName, $actionName) + $parameters;\n $actionName = 'index';\n $moduleName = 'main';\n self :: $moduleName = $moduleName;\n self :: $actionName = $actionName;\n }\n } else { //if the action does not exist route to action index\n @include_once ( PATH . '/modules/' . $moduleName . '.php' );\n $modClassName = 'mod_' . $moduleName;\n $module = new $modClassName();\n if (!method_exists($module, $actionName)) {\n $parameters = array_merge(array($actionName), $parameters); //add first parameter\n $actionName = 'index';\n }\n self :: $moduleName = $moduleName;\n self :: $actionName = $actionName;\n }\n if (empty($module)) {\n $modClassName = 'mod_' . self :: $moduleName;\n $module = new $modClassName();\n }\n\n $method = new ReflectionMethod('mod_' . self :: $moduleName, self :: $actionName);\n\n //sanitize and set method variables\n if (is_array($parameters)) {\n foreach ($method->getParameters() as $parameter) {\n $param = current($parameters);\n next($parameters);\n if ($parameter->isDefaultValueAvailable()) {\n if ($param !== false) {\n self :: $params[$parameter->getName()] = sanitizeOne(urldecode(trim($param)), $parameter->getDefaultValue());\n } else {\n self :: $params[$parameter->getName()] = null;\n }\n } else {\n if ($param !== false) {//check if variable is set, avoid notice\n self :: $params[$parameter->getName()] = sanitizeOne(urldecode(trim($param)), 'str');\n } else {\n self :: $params[$parameter->getName()] = null;\n }\n }\n }\n } else {\n foreach ($method->getParameters() as $parameter) {\n self :: $params[$parameter->getName()] = null;\n }\n }\n\n if ($http_redirect === false) {//no redirecting just call the action\n if (is_array(self :: $params)) {\n $method->invokeArgs($module, self :: $params);\n } else {\n $method->invoke($module);\n }\n } else {\n //generate the link to action\n if (is_array($parameters)) { // pass parameters\n $link = '/' . $moduleName . '/' . $actionName . '/' . implode('/', self :: $params);\n } else {\n $link = '/' . $moduleName . '/' . $actionName;\n }\n //redirect browser\n header('Location:' . $link);\n\n //if the browser does not support redirecting then provide a link to the action\n die('Your browser does not support redirect please click here <a href=\"' . $link . '\">' . $link . '</a>');\n }\n return $ok;\n }\n\n /**\n * Redirects to action contained within current module\n */\n function redirectAction($actionName, $parameters) {\n self :: $actionName = $actionName;\n call_user_func_array(array(&$this, $actionName), $parameters);\n }\n\n public function module($moduleName) {\n self :: redirect($moduleName, $actionName, $parameters, $http_redirect = false);\n }\n\n /**\n * Processes the client's REQUEST_URI and handles module loading/unloading and action calling\n *\n * @return bool\n */\n public function dispatch() {\n if ($_SERVER['REQUEST_URI'][strlen($_SERVER['REQUEST_URI']) - 1] !== '/') {\n $_SERVER['REQUEST_URI'] .= '/'; //add end slash for safety (if missing)\n }\n\n //$_SERVER['REQUEST_URI'] = @str_replace( BASE ,'', $_SERVER['REQUEST_URI']);\n // We divide the request into 'module' and 'action' and save paramaters into $_PARAMS\n if ($_SERVER['REQUEST_URI'] != '/') {\n $_PARAMS = explode('/', $_SERVER['REQUEST_URI']);\n\n $moduleName = $_PARAMS[1]; //get module name\n $actionName = $_PARAMS[2]; //get action\n unset($_PARAMS[count($_PARAMS) - 1]); //delete last\n unset($_PARAMS[0]);\n unset($_PARAMS[1]);\n unset($_PARAMS[2]);\n } else {\n $_PARAMS = null;\n }\n\n if (empty($actionName)) {\n $actionName = 'index'; //use default index action\n }\n\n if (empty($moduleName)) {\n $moduleName = 'main'; //use default main module\n }\n /* if (isset($_PARAMS))\n\n {\n\n $_PARAMS = array_slice($_PARAMS, 3, -1);//delete action and module from array and pass only parameters\n\n } */\n return self :: redirect($moduleName, $actionName, $_PARAMS);\n }\n}\n"
},
{
"answer_id": 929377,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "<?PHP\n\nclass test\n{\n static function f(){\n return;\n }\n}\n\n$s = microtime(true);\nfor ($i=0; $i<1000000; $i++)\n{\n test::f('x');\n}\necho ($a=microtime(true) - $s).\"\\n\";\n\n$s = microtime(true);\nfor ($i=0; $i<1000000; $i++)\n{\n $rm = new ReflectionMethod('test', 'f');\n $rm->invokeArgs(null, array('f'));\n}\n\necho ($b=microtime(true) - $s).\"\\n\";\n\necho 100/$a*$b;\n"
},
{
"answer_id": 14653854,
"author": "Alix Axel",
"author_id": 89771,
"author_profile": "https://Stackoverflow.com/users/89771",
"pm_score": 6,
"selected": false,
"text": "class foo {\n public static function bar() {\n return __METHOD__;\n }\n}\n\nfunction directCall() {\n return foo::bar($_SERVER['REQUEST_TIME']);\n}\n\nfunction variableCall() {\n return call_user_func(array('foo', 'bar'), $_SERVER['REQUEST_TIME']);\n}\n\nfunction reflectedCall() {\n return (new ReflectionMethod('foo', 'bar'))->invoke(null, $_SERVER['REQUEST_TIME']);\n}\n Array\n(\n [directCall] => 4.13348770\n [variableCall] => 6.82747173\n [reflectedCall] => 8.67534351\n)\n Array\n(\n [directCall] => 1.00000000\n [variableCall] => 1.67164707\n [reflectedCall] => 2.13174915\n)\n Benchmark() function Benchmark($callbacks, $iterations = 100, $relative = false)\n{\n set_time_limit(0);\n\n if (count($callbacks = array_filter((array) $callbacks, 'is_callable')) > 0)\n {\n $result = array_fill_keys($callbacks, 0);\n $arguments = array_slice(func_get_args(), 3);\n\n for ($i = 0; $i < $iterations; ++$i)\n {\n foreach ($result as $key => $value)\n {\n $value = microtime(true);\n call_user_func_array($key, $arguments);\n $result[$key] += microtime(true) - $value;\n }\n }\n\n asort($result, SORT_NUMERIC);\n\n foreach (array_reverse($result) as $key => $value)\n {\n if ($relative === true)\n {\n $value /= reset($result);\n }\n\n $result[$key] = number_format($value, 8, '.', '');\n }\n\n return $result;\n }\n\n return false;\n}\n"
},
{
"answer_id": 29847648,
"author": "WiR3D",
"author_id": 834280,
"author_profile": "https://Stackoverflow.com/users/834280",
"pm_score": 1,
"selected": false,
"text": "array (\n 'Direct' => '5.18932366',\n 'Variable' => '5.62969398',\n 'Reflective' => '6.59285069',\n 'User' => '7.40568614',\n)\n function Benchmark($callbacks, $iterations = 100, $relative = false)\n{\n set_time_limit(0);\n\n if (count($callbacks = array_filter((array) $callbacks, 'is_callable')) > 0)\n {\n $result = array_fill_keys(array_keys($callbacks), 0);\n $arguments = array_slice(func_get_args(), 3);\n\n for ($i = 0; $i < $iterations; ++$i)\n {\n foreach ($result as $key => $value)\n {\n $value = microtime(true); call_user_func_array($callbacks[$key], $arguments); $result[$key] += microtime(true) - $value;\n }\n }\n\n asort($result, SORT_NUMERIC);\n\n foreach (array_reverse($result) as $key => $value)\n {\n if ($relative === true)\n {\n $value /= reset($result);\n }\n\n $result[$key] = number_format($value, 8, '.', '');\n }\n\n return $result;\n }\n\n return false;\n}\n\nclass foo {\n public static function bar() {\n return __METHOD__;\n }\n}\n\nclass TesterDirect {\n public function test() {\n return foo::bar($_SERVER['REQUEST_TIME']);\n }\n}\n\nclass TesterVariable {\n private $class = 'foo';\n\n public function test() {\n $class = $this->class;\n\n return $class::bar($_SERVER['REQUEST_TIME']);\n }\n}\n\nclass TesterUser {\n private $method = array('foo', 'bar');\n\n public function test() {\n return call_user_func($this->method, $_SERVER['REQUEST_TIME']);\n }\n}\n\nclass TesterReflective {\n private $class = 'foo';\n private $reflectionMethod;\n\n public function __construct() {\n $this->reflectionMethod = new ReflectionMethod($this->class, 'bar');\n }\n\n public function test() {\n return $this->reflectionMethod->invoke(null, $_SERVER['REQUEST_TIME']);\n }\n}\n\n$testerDirect = new TesterDirect();\n$testerVariable = new TesterVariable();\n$testerUser = new TesterUser();\n$testerReflective = new TesterReflective();\n\nfputs(STDOUT, var_export(Benchmark(array(\n 'Direct' => array($testerDirect, 'test'),\n 'Variable' => array($testerVariable, 'test'),\n 'User' => array($testerUser, 'test'),\n 'Reflective' => array($testerReflective, 'test')\n), 10000000), true));\n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38072/"
] |
294,585 | <p>Sorry for the newb question. I'm still learning programming. So I'm using C++, and I need to do something like this:</p>
<pre><code>int n;
do {
n = get_data();
if(n != -1)
send(n);
} while(n != -1);
</code></pre>
<p>This is just a sketch. Anyway it doesn't feel real elegant. I have to have my test twice. I could just test once and set a flag, but that doesn't feel real elegant either since I have to check the flag twice. It just seems like there should be a way to do this more easily, since it's so easy what I want to do.</p>
| [
{
"answer_id": 294589,
"author": "Charlie",
"author_id": 18529,
"author_profile": "https://Stackoverflow.com/users/18529",
"pm_score": 4,
"selected": false,
"text": "int n;\nwhile(1) {\n n = get_data();\n if(n == -1)\n break;\n send(n);\n}\n"
},
{
"answer_id": 294591,
"author": "Eugene Yokota",
"author_id": 3827,
"author_profile": "https://Stackoverflow.com/users/3827",
"pm_score": 4,
"selected": false,
"text": "int n;\nwhile (-1 != (n = get_data())) {\n send(n);\n} // while\n"
},
{
"answer_id": 294602,
"author": "finnw",
"author_id": 12048,
"author_profile": "https://Stackoverflow.com/users/12048",
"pm_score": 2,
"selected": false,
"text": "int n;\nwhile(1) {\n n = get_data();\n if(n == -1)\n break;\n send(n);\n}\n break while((n = get_data()) != -1) { send(n); }\n int n;\nbool valid;\ndo {\n n = get_data();\n valid = n != -1;\n if(valid)\n send(n);\n} while(valid);\n n != -1"
},
{
"answer_id": 294781,
"author": "SCFrench",
"author_id": 4928,
"author_profile": "https://Stackoverflow.com/users/4928",
"pm_score": 4,
"selected": false,
"text": " int n;\n while (n = get_data(), n != -1)\n {\n send(n);\n }\n"
},
{
"answer_id": 294803,
"author": "Jonathan",
"author_id": 14850,
"author_profile": "https://Stackoverflow.com/users/14850",
"pm_score": 4,
"selected": false,
"text": "for (int n = get_data(); n != -1; n = get_data()) {\n send(n);\n}\n"
},
{
"answer_id": 298415,
"author": "lazyden",
"author_id": 38530,
"author_profile": "https://Stackoverflow.com/users/38530",
"pm_score": 0,
"selected": false,
"text": "goto int n;\ngoto inside; do {\n send(n);\ninside:\n n=get_data();\n} while(n!=-1);\n"
},
{
"answer_id": 298641,
"author": "plan9assembler",
"author_id": 1710672,
"author_profile": "https://Stackoverflow.com/users/1710672",
"pm_score": -1,
"selected": false,
"text": "int get_data()\n{\n ...\n}\n\nvoid _send(int )\n{\n ...\n}\n\nint send(int (*a) ())\n{\n int n = a();\n\n if (n == -1)\n return n;\n\n _send(n);\n return 1;\n}\n\nint main()\n{\n int (*fp)();\n fp = get_data;\n while ( send(fp)!= -1 );\n\n return 0;\n}\n"
},
{
"answer_id": 299223,
"author": "gsarkis",
"author_id": 36786,
"author_profile": "https://Stackoverflow.com/users/36786",
"pm_score": 1,
"selected": false,
"text": "int n;\nn = get_data();\nwhile (n != -1) {\n send(n);\n n = get_data();\n}\n"
},
{
"answer_id": 2315206,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 0,
"selected": false,
"text": "while True:\n n = get_data()\n if n == -1:\n break\n send(n)\n"
},
{
"answer_id": 5427734,
"author": "EvilTeach",
"author_id": 7734,
"author_profile": "https://Stackoverflow.com/users/7734",
"pm_score": 2,
"selected": false,
"text": "/* This is cleaner */ \nAGAIN:;\n int n = get_data();\n if (n != -1)\n {\n send(n);\n goto AGAIN;\n }\n\n\n/* This has some charm as well */ \nint n;\nwhile ((n = get_data()) != -1)\n send(n);\n/* and now i see that this is the top answer. Oh well */ \n"
}
] | 2008/11/16 | [
"https://Stackoverflow.com/questions/294585",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
294,607 | <p>I'm using django and when users go to www.website.com/ I want to point them to the index view.</p>
<p>Right now I'm doing this:</p>
<pre><code>(r'^$', 'ideas.idea.views.index'),
</code></pre>
<p>However, it's not working. I'm assuming my regular expression is wrong. Can anyone help me out? I've looked at python regular expressions but they didn't help me. </p>
| [
{
"answer_id": 294612,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": 3,
"selected": true,
"text": "urls.py"
},
{
"answer_id": 294656,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "urlpatterns += patterns('django.views.generic.simple',\n (r'', 'direct_to_template', {'template': 'index.html'}),\n)\n"
},
{
"answer_id": 16170740,
"author": "Fabio Nolasco",
"author_id": 2108737,
"author_profile": "https://Stackoverflow.com/users/2108737",
"pm_score": 2,
"selected": false,
"text": "urlpatterns = patterns('',\n url(r'', include('homepage.urls')),\n)\n urlpatterns = patterns('',\n url(r'\\?', include('homepage.urls')),\n)\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23695/"
] |
294,609 | <p>I'm interested in measuring and improving (where necessary) my team's SQL-92 skills. Can anyone recommend an appropriate on-line course and/or examination?</p>
<p>Ideally it would be vendor-neutral, but it could also be MSSQL/Oracle specific, as long as the proprietary bits were flagged as such.</p>
| [
{
"answer_id": 294612,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": 3,
"selected": true,
"text": "urls.py"
},
{
"answer_id": 294656,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "urlpatterns += patterns('django.views.generic.simple',\n (r'', 'direct_to_template', {'template': 'index.html'}),\n)\n"
},
{
"answer_id": 16170740,
"author": "Fabio Nolasco",
"author_id": 2108737,
"author_profile": "https://Stackoverflow.com/users/2108737",
"pm_score": 2,
"selected": false,
"text": "urlpatterns = patterns('',\n url(r'', include('homepage.urls')),\n)\n urlpatterns = patterns('',\n url(r'\\?', include('homepage.urls')),\n)\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10433/"
] |
294,611 | <p>What is the best way to block certain input keys from being used in a TextBox with out blocking special keystrokes such as <kbd>Ctrl</kbd>-<kbd>V</kbd>/<kbd>Ctrl</kbd>-<kbd>C</kbd>?</p>
<p>For example, only allowing the user to enter a subset of characters or numerics such as A or B or C and nothing else.</p>
| [
{
"answer_id": 294624,
"author": "Nathan Koop",
"author_id": 18821,
"author_profile": "https://Stackoverflow.com/users/18821",
"pm_score": 0,
"selected": false,
"text": " private void txtInput_TextChanged(object sender, EventArgs e)\n {\n if (txtInput.Text.ToUpper() == \"A\" || txtInput.Text.ToUpper() == \"B\")\n {\n //invalid entry logic here\n }\n }\n"
},
{
"answer_id": 294726,
"author": "Ed S.",
"author_id": 1053,
"author_profile": "https://Stackoverflow.com/users/1053",
"pm_score": 2,
"selected": false,
"text": "Regex regex = new Regex(\"[0-9]|\\b\"); \ne.Handled = !(regex.IsMatch(e.KeyChar.ToString()));\n"
},
{
"answer_id": 370374,
"author": "benPearce",
"author_id": 4490,
"author_profile": "https://Stackoverflow.com/users/4490",
"pm_score": 1,
"selected": false,
"text": "protected override bool ProcessCmdKey(ref Message msg, Keys keyData)\n{\n // check the key to see if it should be handled in the OnKeyPress method\n // the reasons for doing this check here is:\n // 1. The KeyDown event sees certain keypresses differently, e.g NumKeypad 1 is seen as a lowercase A\n // 2. The KeyPress event cannot see Modifer keys so cannot see Ctrl-C,Ctrl-V etc.\n // The functionality of the ProcessCmdKey has not changed, it is simply doing a precheck before the \n // KeyPress event runs\n switch (keyData)\n {\n case Keys.V | Keys.Control :\n case Keys.C | Keys.Control :\n case Keys.X | Keys.Control :\n case Keys.Back :\n case Keys.Delete :\n this._handleKey = true;\n break;\n default:\n this._handleKey = false;\n break;\n }\n return base.ProcessCmdKey(ref msg, keyData);\n}\n\n\nprotected override void OnKeyPress(KeyPressEventArgs e)\n{\n if (String.IsNullOrEmpty(this._ValidCharExpression))\n {\n this._handleKey = true;\n }\n else if (!this._handleKey)\n {\n // this is the final check to see if the key should be handled\n // checks the key code against a validation expression and handles the key if it matches\n // the expression should be in the form of a Regular Expression character class\n // e.g. [0-9\\.\\-] would allow decimal numbers and negative, this does not enforce order, just a set of valid characters\n // [A-Za-z0-9\\-_\\@\\.] would be all the valid characters for an email\n this._handleKey = Regex.Match(e.KeyChar.ToString(), this._ValidCharExpression).Success;\n }\n if (this._handleKey)\n {\n base.OnKeyPress(e);\n this._handleKey = false;\n }\n else\n {\n e.Handled = true;\n }\n \n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294611",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4490/"
] |
294,616 | <p>I am trying to resolve Euler Problem 18 -> <a href="http://projecteuler.net/index.php?section=problems&id=18" rel="nofollow noreferrer">http://projecteuler.net/index.php?section=problems&id=18</a></p>
<p>I am trying to do this with c++ (I am relearning it and euler problems make for good learning/searching material)</p>
<pre><code>#include <iostream>
using namespace std;
long long unsigned countNums(short,short,short array[][15],short,bool,bool);
int main(int argc,char **argv) {
long long unsigned max = 0;
long long unsigned sum;
short piramide[][15] = {{75,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{95,64,0,0,0,0,0,0,0,0,0,0,0,0,0},
{17,47,82,0,0,0,0,0,0,0,0,0,0,0,0},
{18,35,87,10,0,0,0,0,0,0,0,0,0,0,0},
{20,4,82,47,65,0,0,0,0,0,0,0,0,0,0},
{19,1,23,75,3,34,0,0,0,0,0,0,0,0,0},
{88,2,77,73,7,63,67,0,0,0,0,0,0,0,0},
{99,65,4 ,28,6,16,70,92,0,0,0,0,0,0,0},
{41,41,26,56,83,40,80,70,33,0,0,0,0,0,0},
{41,48,72,33,47,32,37,16,94,29,0,0,0,0,0},
{53,71,44,65,25,43,91,52,97,51,14,0,0,0,0},
{70,11,33,28,77,73,17,78,39,68,17,57,0,0,0},
{91,71,52,38,17,14,91,43,58,50,27,29,48,0,0},
{63,66,4,68,89,53,67,30,73,16,69,87,40,31,0},
{4,62,98,27,23,9,70,98,73,93,38,53,60,4,23}};
for (short i = 0;i<15;i++) {
for (short m=0;m<15;m++) {
if (piramide[i][m] == 0)
break;
sum = countNums(i,m,piramide,15,true,true);
if (sum > max)
max = sum;
sum = countNums(i,m,piramide,15,true,false);
if (sum > max)
max = sum;
sum = countNums(i,m,piramide,15,false,true);
if (sum > max)
max = sum;
sum = countNums(i,m,piramide,15,false,false);
if (sum > max)
max = sum;
}
}
cout << max;
return 0;
}
long long unsigned countNums(short start_x,short start_y,short array[][15],short size, bool goright,bool goright2) {
long long unsigned currentSum;
currentSum = array[start_x][start_y];
if (goright) { //go right
if ((start_x + 1) < size)
start_x++;
if ((start_y + 1) < size)
start_y++;
}
else //go down
if ((start_x + 1) < size)
start_x++;
if (goright2) { //still going right
for (short i = start_x, m = start_y;i< size && m < size;i++,m++) {
currentSum += array[i][m];
}
}
else { //still going down
for (short i = start_x;i<size;i++) {
currentSum += array[i][start_y];
}
}
return currentSum;
}
</code></pre>
<p>The countNums function is used to go either down or diagonally.
I have tested this function like so:</p>
<pre><code>short a = 0;
short b = 0;
cout << countNums(a,b,piramide,15,true,true) << endl;
cout << countNums(a,b,piramide,15,true,false) << endl;
cout << countNums(a,b,piramide,15,false,true) << endl;
cout << countNums(a,b,piramide,15,false,false) << endl;
return 0;
</code></pre>
<p>And it does work (I also changed the function a little so it would print every number it was going through) </p>
<p>But I still don't get the right result. This goes down and to the right and still goes right (adjacent numbers to the right), goes down and keeps going down (adjacent number to the left).
What am I doing wrong here, anyone?</p>
<hr>
<p>Alastair: It's simple</p>
<p>long long unsigned countNums(short start_x,short start_y,short array[][15],short size, bool goright,bool goright2);</p>
<p>start_x and start_y are the coords of the array
array is the reference to the array
size is just the size of the array (it's always 15)
goright is to know if I am going to go down and right or just down
goright2 is to know if I am going to continue to go down or going left</p>
| [
{
"answer_id": 294641,
"author": "Alastair",
"author_id": 31038,
"author_profile": "https://Stackoverflow.com/users/31038",
"pm_score": 3,
"selected": true,
"text": "countNums"
},
{
"answer_id": 294687,
"author": "baash05",
"author_id": 31325,
"author_profile": "https://Stackoverflow.com/users/31325",
"pm_score": 0,
"selected": false,
"text": "long long unsigned countNums(short x,\n short y,\n short array[][15],\n short size, \n bool goright,\n bool goright2) \n{\n long long unsigned currentSum;\n currentSum = array[x][y];\n\n if ((x + 1) < size) x++; //this happened in both your if cases\n\n if (goright && ((y + 1) < size) y++; \n\n if (goright2)\n { \n for (;x< size && y< size;x++,y++)\n currentSum += array[x][y]; \n\n }\n else \n {\n for (;x<size;x++) \n currentSum += array[x][y]; \n }\n return currentSum;\n }\n"
},
{
"answer_id": 294709,
"author": "waynecolvin",
"author_id": 35658,
"author_profile": "https://Stackoverflow.com/users/35658",
"pm_score": 0,
"selected": false,
"text": "&& <"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8715/"
] |
294,622 | <p>I'm getting an exception which says "Access Denied" when the users permissions are sufficient, how do I catch an exception and check for "Access Denied" so that I can show the user a friendlier "Sorry Access Denied" message?</p>
<p>Thanks
Beginner :-)</p>
| [
{
"answer_id": 294630,
"author": "Ed S.",
"author_id": 1053,
"author_profile": "https://Stackoverflow.com/users/1053",
"pm_score": 3,
"selected": false,
"text": "try\n{\n //error occurs\n}\ncatch (Exception ex)\n{\n MessageBox.show(ex.Message);\n}\n Try\n{\n //error occurs\n}\ncatch (AccessDeniedException ex)\n{\n MessageBox.show(ex.Message);\n}\ncatch (FieldAccessException)\n{\n\n}\n// etc...\n"
},
{
"answer_id": 294631,
"author": "Ed Marty",
"author_id": 36007,
"author_profile": "https://Stackoverflow.com/users/36007",
"pm_score": 4,
"selected": false,
"text": "try {\n ...\n} catch (SomeKindOfException ex) {\n MessageBox.Show(ex.Message);\n} catch (AccessDeniedException ex) {\n //Do something else\n}\n"
},
{
"answer_id": 294637,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 2,
"selected": false,
"text": "try\n{\n YourCommandWhichResultsInDeniedAccess();\n}\ncatch (AccessDeniedException)\n{\n MessageBox.Show('Access Denied');\n}\n try\n{\n YourCommandWhichResultsInDeniedAccess();\n}\ncatch (Exception e)\n{\n if (e.Message == 'Access Denied')\n {\n MessageBox.Show('Access Denied')\n }\n}\n"
},
{
"answer_id": 294642,
"author": "Brian H. Madsen",
"author_id": 33508,
"author_profile": "https://Stackoverflow.com/users/33508",
"pm_score": -1,
"selected": false,
"text": "try\n {\n // code here which throws exception\n }\n catch (Exception ex)\n {\n if (ex.Message.Contains(\"Access Denied\"))\n {\n MessageBox.Show(\"Sorry, Access Denied\", \"This is a polite error message\");\n }\n }\n"
},
{
"answer_id": 2797461,
"author": "Jeff Atwood",
"author_id": 1,
"author_profile": "https://Stackoverflow.com/users/1",
"pm_score": 4,
"selected": false,
"text": "string.ToLowerInvariant() throw try\n{\n int result = DoStuff(param);\n}\ncatch (System.IO.IOException ioex)\n{\n if (ioex.Message.ToLowerInvariant().Contains(\"find me\"))\n {\n .. do whatever ..\n }\n else\n {\n // no idea what just happened; we gotta crash\n throw;\n }\n}\n"
},
{
"answer_id": 36200016,
"author": "Arun Prasad E S",
"author_id": 5237614,
"author_profile": "https://Stackoverflow.com/users/5237614",
"pm_score": 0,
"selected": false,
"text": "try {\n drop_grup_head.SelectedValue = ds.Rows[0][\"group_head\"].ToString();\n }\n catch (Exception exce ) {\n if (exce.Message.ToLowerInvariant().Contains(\"does not exist in the list\")) {\n drop_grup_head.SelectedValue = \"0\";\n }\n }\n"
},
{
"answer_id": 47143083,
"author": "Tomas Kubes",
"author_id": 518530,
"author_profile": "https://Stackoverflow.com/users/518530",
"pm_score": 3,
"selected": false,
"text": "try\n{\n int result = DoStuff(param);\n}\ncatch (IOException ex) \nwhen (ex.Message.ToLowerInvariant().Contains(\"find me\")) \n{\n //.. do whatever ..\n}\n try\n{\n int result = DoStuff(param);\n}\ncatch (System.IO.IOException ex)\n{\n if (ex.Message.ToLowerInvariant().Contains(\"find me\"))\n {\n //.. do whatever ..\n }\n else\n {\n throw;\n }\n}\n"
},
{
"answer_id": 55675446,
"author": "Hesham Yassin",
"author_id": 2469134,
"author_profile": "https://Stackoverflow.com/users/2469134",
"pm_score": 1,
"selected": false,
"text": "try\n{\n // code here which throws exception\n}\ncatch (Exception ex) when(ex.Message.Contains(\"Access Denied\"))\n{\n MessageBox.Show(\"Sorry, Access Denied\", \"This is a polite error message\");\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294622",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
294,659 | <p>I made a couple of changes to my working application and started getting the following error at this line of code.</p>
<pre><code>Dim Deserializer As New Serialization.XmlSerializer(GetType(Groups))
</code></pre>
<p>And here is the error.</p>
<pre><code> BindingFailure was detected
Message: The assembly with display name 'FUSE.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null'
Message: The assembly with display name 'FUSE.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null'
=== Pre-bind state information ===
LOG: User = DOUG-VM\Doug
LOG: DisplayName = FUSE.XmlSerializers, Version=8.11.16.1, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL
(Fully-specified)
LOG: Appbase = file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\Laptop\Core Data\Data\Programming\Windows\DotNet\Work Projects\NOP\Official Apps\FUSE WPF\Fuse\bin\Debug\FUSE.vshost.exe.config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers/FUSE.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers.EXE.
LOG: Attempting download of new URL file:///E:/Laptop/Core Data/Data/Programming/Windows/DotNet/Work Projects/NOP/Official Apps/FUSE WPF/Fuse/bin/Debug/FUSE.XmlSerializers/FUSE.XmlSerializers.EXE.
</code></pre>
<p>What's going on?</p>
| [
{
"answer_id": 295239,
"author": "Kent Boogaart",
"author_id": 5380,
"author_profile": "https://Stackoverflow.com/users/5380",
"pm_score": 0,
"selected": false,
"text": "Groups Assembly.LoadFrom() Assembly.Load() Assembly.LoadFrom() AppDomain.AssemblyResolve"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6514/"
] |
294,660 | <p>What's a good algorithm to solve this problem?</p>
<p>I have three groups of people - group A, group B, and group C. There are the same number of people in each group. They each have a list of people in the other groups that they're willing to work with. I want to group all these people together in groups of 3 (one from A, one from B, and one from C) such that everyone in a group wants to work with the other people in their group. </p>
<p>How can I find these groups in a fast way? If there's no way to make everyone happy, then the algorithm should first make as many groups have three people who want to work with each other, and then make as many people in the other groups happy.</p>
<p>One final point: people agree on who they want to work with (if person x wants to work with person y, then y also wants to work with x). If you could also give a big-O of the running time of your algorithm, that'd be great!</p>
| [
{
"answer_id": 294970,
"author": "RexE",
"author_id": 38146,
"author_profile": "https://Stackoverflow.com/users/38146",
"pm_score": 3,
"selected": false,
"text": "M1 = |A| x |B| M1(a,b) = 1 M2 = |A| x |C| M2(a,c) = 1 M2 = |B| x |C| M3(b,c) = 1 X = |A| x |B| x |C| X(a,b,c) = 1 Sum[(all a, all b, all c) X(a,b,c)] Sum[(all j, k) X(a, j, k)] <= 1 Sum[(all i, k) X(i, b, k)] <= 1 Sum[(all i, j) X(i, j, c)] <= 1 X(a,b,c) <= M1(a,b)/3 + M2(a,c)/3 + M3(b,c)/3"
},
{
"answer_id": 67391545,
"author": "Eduardo Cuomo",
"author_id": 717267,
"author_profile": "https://Stackoverflow.com/users/717267",
"pm_score": 0,
"selected": false,
"text": "A: YXZ B: ZYX C: XZY \nX: BAC Y: CBA Z: ACB\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] |
294,661 | <p>I have a MySQL table that will only have one row. What should my statement be for the first time I insert to this row, and for subsequent updates? I tried an insert where the primary key equals 1, but this doesn't account for the first time around when no row exists yet.</p>
| [
{
"answer_id": 294671,
"author": "SoapBox",
"author_id": 36384,
"author_profile": "https://Stackoverflow.com/users/36384",
"pm_score": 4,
"selected": true,
"text": "INSERT INTO table(col1,col2,col3) VALUES(val1,val2,val3) ON DUPLICATE KEY UPDATE col1 = val1, col2 = val2, col3 = val3;\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
294,664 | <p>I also want to save the font size in my <code>.emacs</code> file.</p>
| [
{
"answer_id": 294685,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 5,
"selected": false,
"text": "default ;; my colour theme is whateveryouwant :)\n(require 'color-theme)\n(color-theme-initialize)\n(color-theme-whateveryouwant)\n\n(custom-set-faces\n ;; custom-set-faces was added by Custom.\n ;; If you edit it by hand, you could mess it up, so be careful.\n ;; Your init file should contain only one such instance.\n ;; If there is more than one, they won't work right.\n '(default ((t (:stipple nil :background \"white\" :foreground \"black\" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry \"unknown\" :family \"DejaVu Sans Mono\"))))\n '(font-lock-comment-face ((t (:foreground \"darkorange4\"))))\n '(font-lock-function-name-face ((t (:foreground \"navy\"))))\n '(font-lock-keyword-face ((t (:foreground \"red4\"))))\n '(font-lock-type-face ((t (:foreground \"black\"))))\n '(linum ((t (:inherit shadow :background \"gray95\"))))\n '(mode-line ((t (nil nil nil nil :background \"grey90\" (:line-width -1 :color nil :style released-button) \"black\" :box nil :width condensed :foundry \"unknown\" :family \"DejaVu Sans Mono\")))))\n"
},
{
"answer_id": 294733,
"author": "Chris Conway",
"author_id": 1412,
"author_profile": "https://Stackoverflow.com/users/1412",
"pm_score": 4,
"selected": false,
"text": ".emacs (defun fontify-frame (frame)\n (set-frame-parameter frame 'font \"Monospace-11\"))\n\n;; Fontify current frame\n(fontify-frame nil)\n;; Fontify any future frames\n(push 'fontify-frame after-make-frame-functions) \n \"Monospace-11\" M-x set-default-font Monospace Sans Serif"
},
{
"answer_id": 296316,
"author": "huaiyuan",
"author_id": 16240,
"author_profile": "https://Stackoverflow.com/users/16240",
"pm_score": 10,
"selected": true,
"text": "(set-face-attribute 'default nil :height 100)\n"
},
{
"answer_id": 16005887,
"author": "Matthew H",
"author_id": 284016,
"author_profile": "https://Stackoverflow.com/users/284016",
"pm_score": 2,
"selected": false,
"text": "CMD + CMD -"
},
{
"answer_id": 20730362,
"author": "bzimmerly",
"author_id": 3127245,
"author_profile": "https://Stackoverflow.com/users/3127245",
"pm_score": 3,
"selected": false,
"text": "(global-set-key [C-kp-add] 'text-scale-increase)\n\n(global-set-key [C-kp-subtract] 'text-scale-decrease)\n"
},
{
"answer_id": 21989454,
"author": "ravi404",
"author_id": 948301,
"author_profile": "https://Stackoverflow.com/users/948301",
"pm_score": 5,
"selected": false,
"text": "(set-default-font \"Monaco 14\")\n `C-+` increases font size\n`C--` Decreases font size\n"
},
{
"answer_id": 24809045,
"author": "Kevin Ushey",
"author_id": 1342082,
"author_profile": "https://Stackoverflow.com/users/1342082",
"pm_score": 3,
"selected": false,
"text": ";; font sizes\n(global-set-key (kbd \"s-=\")\n (lambda ()\n (interactive)\n (let ((old-face-attribute (face-attribute 'default :height)))\n (set-face-attribute 'default nil :height (+ old-face-attribute 10)))))\n\n(global-set-key (kbd \"s--\")\n (lambda ()\n (interactive)\n (let ((old-face-attribute (face-attribute 'default :height)))\n (set-face-attribute 'default nil :height (- old-face-attribute 10)))))\n text-scale-increase text-scale-decrease"
},
{
"answer_id": 30889204,
"author": "Leu_Grady",
"author_id": 3173715,
"author_profile": "https://Stackoverflow.com/users/3173715",
"pm_score": 1,
"selected": false,
"text": "f2 + + + + f2 - - - - f2 + - f2 0 (defhydra hydra-zoom (global-map \"<f2>\")\n \"zoom\"\n (\"<kp-add>\" text-scale-increase \"in\")\n (\"+\" text-scale-increase \"in\")\n (\"-\" text-scale-decrease \"out\")\n (\"<kp-subtract>\" text-scale-decrease \"out\")\n (\"0\" (text-scale-set 0) \"reset\")\n (\"<kp-0>\" (text-scale-set 0) \"reset\"))\n (global-set-key (kbd \"<C-wheel-up>\") 'text-scale-increase)\n(global-set-key (kbd \"<C-wheel-down>\") 'text-scale-decrease)\n"
},
{
"answer_id": 42605583,
"author": "7stud",
"author_id": 926143,
"author_profile": "https://Stackoverflow.com/users/926143",
"pm_score": 3,
"selected": false,
"text": "(set-face-attribute 'default nil :font \"Monaco-16\" )\n (set-face-attribute 'default nil :font FONT )\n\n(set-frame-font FONT nil t)\n FONT \"Monaco-16\" (set-face-attribute 'default nil :font \"Monaco-16\" )\n"
},
{
"answer_id": 50052751,
"author": "Ibrahim",
"author_id": 90551,
"author_profile": "https://Stackoverflow.com/users/90551",
"pm_score": 2,
"selected": false,
"text": "(defun set-font-size ()\n \"Set the font size.\"\n (interactive)\n (set-face-attribute\n 'default nil :height\n (string-to-number\n (read-string \"Font size: \" (number-to-string (face-attribute 'default :height nil))))))\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8661/"
] |
294,680 | <p>The application de-serializes a stream into dynamically allocated objects and then keeps base type pointers in a linked list (i.e. abstract factory). It's too slow. Profiling says all the time is spent in <code>operator new</code>.</p>
<p>Notes: The application already uses a custom memory allocator that does pooling. The compiler is VC++ 6.0 and the code uses the old RogueWave collections rather than the STL.</p>
<p>The only idea I have right now is to introduce Object Pooling. I'd maintain large collections of pre-allocated objects for each type and re-use them. But this will be a lot of work in this old code, and I'm not yet sure there's enough re-use that it would even help. I was hoping someone smarter than me has an idea.</p>
| [
{
"answer_id": 294735,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 0,
"selected": false,
"text": "char *alloc(POOL *pool, size_t size) {\n // if size is a parameter, and may be a non-multiple the max alignment \n // requirement on your system, and you want this to work in general:\n // size = (size + MAX_ALIGNMENT - 1) % ALIGNMENT;\n char *block = pool.current;\n char *next = block + size;\n if (next > pool.limit) throw std::bad_alloc();\n pool.current = next;\n return block;\n}\n\nvoid free(char *block) {\n return;\n}\n\nvoid freeAll(POOL *pool) {\n pool.current = pool.start;\n return;\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294680",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16161/"
] |
294,688 | <p>I have a specific scenario in mind, but I will ask this generally:</p>
<p><strong>Is there a way to make my mobile phone trigger an action on my computer?</strong> I am thinking that with a smart phone it must be possible to link the phone and the personal computer with bluetooth, and have some sort of small program running on my computer that will listen for incoming phone calls on the phone. When someone calls me, I want my mobile to simply submit the callers phone number to the personal computer, and then the personal computer will do its stuff from there. Then, I want to handle the call on the mobile phone as usual.</p>
<p><strong>Edit</strong>:<br></p>
<p>Updated this question! I am currently using the HTC Hero, and hopefully the Android SDK will make this more easy to accomplish.</p>
<p><strong>My specific scenario was:</strong><br></p>
<p>When my phone (Nokia N82) calls, i want to submit the callers <code>phonenumber</code> to a search <em>applet/application</em>, that will query <em>Microsoft Dynamics CRM</em> and see if a contact person or a company has that <code>phonenumber</code>, and if so, show the corresponding person or companys info on my screen. My preferred development platform is .NET Framework.</p>
| [
{
"answer_id": 565788,
"author": "funkybro",
"author_id": 64505,
"author_profile": "https://Stackoverflow.com/users/64505",
"pm_score": 3,
"selected": false,
"text": "+CLCC: 1,1,4,0,0,\"07xxxxxxxxx\",129\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29397/"
] |
294,699 | <p>I am using the following servlet-mapping in my <code>web.xml</code> file:</p>
<pre><code><servlet>
<servlet-name>PostController</servlet-name>
<servlet-class>com.webcodei.controller.PostController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PostController</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</code></pre>
<p>To do some kind of a search. ex: <pre><code> <a href="http://www.myweb.com/The" rel="nofollow noreferrer">http://www.myweb.com/The</a> search string here </code></pre></p>
<p>But the problem is that CSS, JS and Images are treated like a search request. </p>
<p><b>There are any patterns that strip out *.css, *.js, *.gif and etc, so the requests don't need to pass through my controller?</b></p>
<p>Thank you so much, bye bye!</p>
| [
{
"answer_id": 294708,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 2,
"selected": false,
"text": "/actions/* *.action *.do"
},
{
"answer_id": 294725,
"author": "Peter Bratton",
"author_id": 37856,
"author_profile": "https://Stackoverflow.com/users/37856",
"pm_score": 1,
"selected": false,
"text": " <servlet>\n <servlet-name>PostController</servlet-name>\n <servlet-class>com.webcodei.controller.PostController</servlet-class>\n </servlet>\n <servlet-mapping>\n <servlet-name>PostController</servlet-name>\n <url-pattern>/*.jsp</url-pattern>\n </servlet-mapping>\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37190/"
] |
294,700 | <p>How does the data go from the MVC to the browser and back again? Does it use Microsoft's own technology like ASMX or WCF or something completely different? </p>
<p>This sounds like MVC is using a ASMX Web Service they are using but I can't seem to find any documentation which gives the real answer. </p>
| [
{
"answer_id": 294792,
"author": "CVertex",
"author_id": 209,
"author_profile": "https://Stackoverflow.com/users/209",
"pm_score": 1,
"selected": false,
"text": "ActionResult MyAction() {\n return Json(new { success=false, for_lunch=\"mmm, chicken\"});\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294700",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10352/"
] |
294,705 | <p>I have two tables: articles and articletags</p>
<pre><code>articles: id, author, date_time, article_text
articletags: id, tag
(article.id == articletags.id in a many-to-many relationship)
</code></pre>
<p>I am after the last time that something was published under each tag. To put it another way, for every tag, look through all the articles it is related to and find the most recent and return that.</p>
<p>eg
articles:</p>
<pre><code>1, me, 12 Nov, Sometext
2, me, 13 Nov, Sometext
3, me, 14 Nov, Sometext
</code></pre>
<p>article tags</p>
<pre><code>1, foo
1, bar
2, foo
3, bar
</code></pre>
<p>I want to get back:</p>
<pre><code>foo, 13 Nov
bar, 14 Nov
</code></pre>
<p>I can get as far as an inner join and then am stumped. I dont think a DISTINCT clause is what I am after and I am not familiar enough for subqueries to know if that would help.</p>
<pre><code>SELECT date_time, tag
FROM articles, articletags
WHERE articles.id = articletags.id
</code></pre>
<p>Is this even possible?</p>
| [
{
"answer_id": 294713,
"author": "SoapBox",
"author_id": 36384,
"author_profile": "https://Stackoverflow.com/users/36384",
"pm_score": 0,
"selected": false,
"text": "SELECT date_time, tag \nFROM articles, articletags\nWHERE articles.id = articletags.id\nORDER BY date_time DESC\nGROUP BY tag\n"
},
{
"answer_id": 294716,
"author": "Gordon Bell",
"author_id": 16473,
"author_profile": "https://Stackoverflow.com/users/16473",
"pm_score": 3,
"selected": true,
"text": "select t.tag, max(a.date_time) as latest\nfrom articles a\ninner join articletags t\non t.id = a.id\ngroup by t.tag\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3431280/"
] |
294,712 | <p>I have a few model classes with basic one-to-many relationships. For example, a book has many recipes, and each recipe has many ingredients:</p>
<pre><code>class Book(models.Model):
name = models.CharField(max_length=64)
class Recipe(models.Model):
book = models.ForeignKey(Book)
name = models.CharField(max_length=64)
class Ingredient(models.Model):
text = models.CharField(max_length=128)
recipe = models.ForeignKey(Recipe)
</code></pre>
<p>I'd like a flat list of all ingredients in all recipes from a particular book. What's the best way to express this in Python?</p>
<p>If I was using LINQ, I might write something like this:</p>
<pre><code>var allIngredients = from recipe in book.Recipes
from ingredient in recipe.Ingredients
select ingredient;
</code></pre>
| [
{
"answer_id": 294717,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": 1,
"selected": false,
"text": "mybook = Book.objects.get(name=\"Jason's Cookbook\")\nfor recipe in mybook.recipe_set.all():\n print recipe.name\n for ingredient in recipe.ingredients:\n print ingredient.text\n mybook = Book.objects.get(name=\"Jason's Cookbook\")\ningredient_list = []\nfor recipe in mybook.recipe_set.all():\n for ingredient in recipe.ingredients:\n ingredient_list.append(ingredient)\n"
},
{
"answer_id": 294723,
"author": "Jason Anderson",
"author_id": 5142,
"author_profile": "https://Stackoverflow.com/users/5142",
"pm_score": 5,
"selected": true,
"text": "my_book = Book.objects.get(pk=1)\nall_ingredients = Ingredient.objects.filter(recipe__book=my_book)\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5142/"
] |
294,738 | <p>When I debug my ASP.NET web site code using the Microsoft debug symbol's for .NET .. I keep getting this silly 'result' for most of the variables when I'm debugging .NET framework code (which of course is provided by the Microsoft Symbol Server, which I told VS2008 to grab the info, from)</p>
<pre><code>Cannot obtain value of local or argument 'cookie' as
it is not available at this instruction pointer, possibly because
it has been optimized away.
</code></pre>
<p>It's like the code I'm using is using optimized, compiled code. If that's the case, can I tell it NOT to optimize? I'm in DEBUG configuration. It's very frustrating because I cannot debug .. cause I can't see/retrieve the values of local variables as I step through the code.</p>
<p>Any clues/thoughts?</p>
| [
{
"answer_id": 1518810,
"author": "Cameron MacFarland",
"author_id": 3820,
"author_profile": "https://Stackoverflow.com/users/3820",
"pm_score": 5,
"selected": true,
"text": "set COMPLUS_ZapDisable=1\ncd /d \"%ProgramFiles%\\Microsoft Visual Studio 9.0\\Common7\\ide\\\"\nstart devenv.exe\nexit\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30674/"
] |
294,741 | <p>I have read some PL SQL programming books, and they recommend me to group procedures, functions, cursors, and so on in a package. Packages provide modularity and information hiding, which is the OO design. However, I'm just familiar with stand alone procedures. Would anyone kindly provide some examples in code and how to call package from the client? I'm currently using ODP.NET as a data access in client application. Thank you.</p>
| [
{
"answer_id": 295974,
"author": "Jim Hudson",
"author_id": 8051,
"author_profile": "https://Stackoverflow.com/users/8051",
"pm_score": 1,
"selected": false,
"text": "create or replace procedure foo (i_something in varchar2) as\nbegin\n -- do some stuff;\nend foo;\n create or replace package my_package as\n procedure foo (i_something in varchar2);\nend;\n\ncreate or replace package body my_package as\n procedure foo (i_something in varchar2);\n begin\n -- do some stuff;\n end foo;\nend my_package;\n"
},
{
"answer_id": 297681,
"author": "bart",
"author_id": 19966,
"author_profile": "https://Stackoverflow.com/users/19966",
"pm_score": 2,
"selected": false,
"text": "create or replace package foo as\n a number; \n function test1(s1 in varchar2) return varchar2;\n procedure test2(i1 in integer);\nend;\n/\n\ncreate or replace package body foo as\n b number; -- internal only\n function internalfunc(s in varchar2) return varchar2;\n\n function test1(s1 in varchar2) return varchar2 is\n s varchar2(32000);\n -- variables ...\n begin\n -- code ...\n return internalfunc(s);\n end;\n\n procedure test2(i1 in integer) is\n -- variables ...\n begin\n -- code ... \n end;\n\n function internalfunc(s in varchar2) return varchar2 is\n begin\n return INITCAP(LOWER(s)); \n end;\n\nend;\n/\n foo.a foo.test1"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1602746/"
] |
294,748 | <p>I've got a TDbGrid in my project, and I'm trying to have an event go off every time I change the selected row. Any change in row already updates all the data-aware controls linked to the same DataSource, but there are other changes to be made too, that I need an event handler for.</p>
<p>I thought OnColEnter would work. According to the helpfile, it fires when:</p>
<ul>
<li><p>The user navigates to the cell using
the keyboard. For example, when the
user uses the Tab key, or the Home
key. </p></li>
<li><p>The user clicks the mouse button
down in the cell. </p></li>
<li><p>The SelectedField or SelectedIndex
property is set.</p></li>
</ul>
<p>Unfortunately, it does <em>not</em> fire when the user navigates using the keyboard while the dgRowSelect option is enabled, and there's no OnRowEnter. And the OnKeyDown event fires before the selection change has been made. I'm trying to simulate a data-aware version of a TListBox here, and I need something to replace the List Box's OnClick handler, which despite the name actually goes off anytime the selection is changed, whether through the mouse or the keyboard. Is there any way I can do that with a TDbGrid? If not, there's got to be some other grid control that will do it. Does anyone know what it is? (Preferably open source?)</p>
| [
{
"answer_id": 295727,
"author": "skamradt",
"author_id": 9217,
"author_profile": "https://Stackoverflow.com/users/9217",
"pm_score": 2,
"selected": false,
"text": "procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);\nbegin\n if fbLoading then exit;\n // rest of your code here\nend;\n\nprocedure TForm1.Form1Create(Sender:tObject);\nbegin\n fbLoading := true;\n // load your table here \n fbLoading := false; \nend;\n"
},
{
"answer_id": 296442,
"author": "Osama Al-Maadeed",
"author_id": 25544,
"author_profile": "https://Stackoverflow.com/users/25544",
"pm_score": 1,
"selected": false,
"text": "procedure TForm1.myAfterScroll(DataSet: TDataSet); \nbegin\n //do your thing here\n if oldAfterScroll<>nil then\n oldAfterScroll(DataSet);\nend;\n\nconstructor TForm1.Create(AOwner: TComponent);\nbegin\n oldAfterScroll:=DBGrid1.DataSet.OnAfterScroll;\n DBGrid1.DataSet.OnAfterScroll:=myAdrerScroll;\nend;\n\ndestructor TForm1.Free;\nbegin\n DBGrid1.DataSet.OnAfterScroll:=oldAfterScroll;\nend;\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32914/"
] |
294,766 | <p>I've explored python for several years, but now I'm slowly learning how to work with c. Using the <a href="http://www.python.org/doc/2.5.2/ext/intro.html" rel="nofollow noreferrer">python documentation</a>, I learned how to extend my python programs with some c, since this seemed like the logical way to start playing with it. My question now is how to distribute a program like this.</p>
<p>I suppose the heart of my question is how to compile things. I can do this easily on my own machine (gentoo), but a binary distribution like Ubuntu probably doesn't have a compiler available by default. Plus, I have a few friends who are mac users. My instinct says that I can't just compile with my own machine and then run it on another. Anyone know what I can do, or some online resources for learning things like this?</p>
| [
{
"answer_id": 294785,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "setup.py"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36312/"
] |
294,771 | <p>Please excuse my lack of knowledge... I know there is a lot of documentation on the internet related to this but I still don't understand.</p>
<p>My situation is this:</p>
<p>I have an XML file that I need import and eventually replace daily with.</p>
<pre><code> <item>
<model>AA311-Pink</model>
<title>1122</title>
<price>19.43</price>
<category>cat</category>
<loc>/AA311.html</loc>
<image>/aa311.jpg</image>
<description>Item Info</description>
<weight>0.45</weight>
<option_type>Color-Color</option_type>
<option_value>Pink-Pink</option_value>
<suggested_retail>51.50</suggested_retail>
<special_handling/>
<manufacturer>Tantus</manufacturer>
<manufacturer_code>VB5074 and VB5067</manufacturer_code>
<packaging>Retail Packaging</packaging>
<in_stock>Yes</in_stock>
<lastupdated>2008-11-05 16:35:56</lastupdated>
</code></pre>
<p>I need to change a handful of the column names automatically and import them into multiple tables in my database.</p>
<p>For instance,</p>
<pre><code> <item>
<products_model>AA315</products_model>
<products_name>name</products_name>
<price>19.43</price>
<category>cat</category>
<loc>/AA315.html</loc>
<products_image>aa315.jpg</products_image>
<products_description>info</products_description>
<products_weight>0.44</products_weight>
<option_type/>
<option_value/>
<products_price>51.50</products_price>
<special_handling/>
<manufactures_name>Tantus</manufactures_name>
<manufacturer_code>VA5104</manufacturer_code>
<packaging>Retail Packaging</packaging>
<products_status>Yes</products_status>
<products_last_modified>2008-11-05 16:35:27</products_last_modified>
</code></pre>
<p>And then import into MySQL DB</p>
<p>Columns:
products_weight, products_model, products_image, products_price, products_last_modified </p>
<p>import into table 'products'</p>
<p>Columns:
products_description, products_name</p>
<p>import into table 'product_description</p>
<p>Also what about the product_id that is automatically created? I can send SQL output of table structure.</p>
<p>I really apprecaite the help... I am willing to pay some if they are willing to create a fully automated procedure to import this file into my database; I am using Zen Cart to host my shopping cart.</p>
| [
{
"answer_id": 8916800,
"author": "Mário Rodrigues",
"author_id": 581256,
"author_profile": "https://Stackoverflow.com/users/581256",
"pm_score": 1,
"selected": false,
"text": "mysql> LOAD XML LOCAL INFILE 'items.xml'\n -> INTO TABLE item\n -> ROWS IDENTIFIED BY '<item>';\n"
},
{
"answer_id": 23471899,
"author": "Marty Staas",
"author_id": 3436982,
"author_profile": "https://Stackoverflow.com/users/3436982",
"pm_score": 0,
"selected": false,
"text": "SET @ins_text = CONCAT('INSERT INTO t1 (', ins_list, ') VALUES (', val_list, ')');\n SET @ins_text = CONCAT('INSERT INTO ', database_name, '.', table_name, ' (', ins_list, ') VALUES (', val_list, ')');\n call xmldump_load('<filename>', '<schema>', '<tablename>');\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294771",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
294,773 | <p>First of all, I'm kinda new to the barcode formats and what I do know, I've learned from Wikipedia.</p>
<p>We have some barcodes generated by an existing app that uses the Barcode.4NET library. The barcode is in Code 128A format. The code to generate them is pretty simple, looking something like this:</p>
<pre><code>// Create the barcode
Code128ABarcode c128A = new Code128ABarcode("045746201627080857");
</code></pre>
<p>No other parameters are set for it - after setting the data, we just get a GIF version of the barcode back from the library.</p>
<p>I'm working on a new app that is using iTextSharp for PDF generation and I figured that instead of using two libraries, I would use iTextSharp's barcode generation library since it supports Code128 barcodes. It has a few different variations of Code 128, but none of them are "Code 128A".</p>
<p>Here is what the code looks like for it:</p>
<pre><code>Barcode128 code128 = new Barcode128();
code128.CodeType = Barcode.CODE128;
code128.ChecksumText = true;
code128.GenerateChecksum = true;
code128.StartStopText = true;
code128.Code = "045746201627080857";
</code></pre>
<p>The image below shows the best I've accomplished so far.</p>
<p><img src="https://farm4.static.flickr.com/3187/3037044282_c6396bc09a.jpg" alt="alt text"></p>
<p>The image on top is generated by iTextSharp and the one on the bottom is generated by Barcode4Net. Obviously, they aren't the same (and not just in the size and the font - the barcoded data is pretty different).</p>
<p>Is anyone out there familiar enough with iTextSharp's (or iText itself) barcode components or with Code 128A barcodes to tell me how to make the iTextSharp one look exactly like the Barcode.4NET one?</p>
| [
{
"answer_id": 294790,
"author": "balexandre",
"author_id": 28004,
"author_profile": "https://Stackoverflow.com/users/28004",
"pm_score": 2,
"selected": false,
"text": "*045746201627080857*\n code128.StartStopText = true;\n Code128ABarcode c128A = new Code128ABarcode(\"*045746201627080857*\");\n http://www.bcgen.com/demo/linear-dbgs.aspx?D=045746201627080857&S=13&CS=1\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294773",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14894/"
] |
294,775 | <p>When working with window handles, is it <em>good</em> enough to use the plain <strong>IntPtr</strong> or should I subclass <strong>SafeHandle</strong>?</p>
<p>Are there any significant pros/cons?</p>
<p>Thanks.</p>
| [
{
"answer_id": 294866,
"author": "P Daddy",
"author_id": 36388,
"author_profile": "https://Stackoverflow.com/users/36388",
"pm_score": 2,
"selected": true,
"text": "SafeHandle SafeHandle Control Control Handle SafeHandle IsInvalid ReleaseHandle Control.Handle HandleRef"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294775",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15409/"
] |
294,779 | <p>I have a big list of global variables that each have their own setup function. My goal is to go through this list, call each item's setup function, and generate some stats on the data loaded in the matching variable. However, what I'm trying now isn't working and I need help to make my program call the setup functions. </p>
<p>The global variables and their setup functions are case-sensitive since this came from XML and is necessary for uniqueness.</p>
<p>The data looks something like this:</p>
<pre><code>'(ABCD ABC\d AB\c\d ...)
</code></pre>
<p>and the setup functions look like this:</p>
<pre><code>(defun setup_ABCD...
(defun setup_ABC\d...
</code></pre>
<p>I've tried concatenating them together and turning the resulting string into a function,
but this interferes with the namespace of the previously loaded setup function. Here's how I tried to implement that:</p>
<pre><code>(make-symbol (concatenate 'string "setup_" (symbol-name(first '(abc\d)))))
</code></pre>
<p>But using <code>funcall</code> on this doesn't work. How can I get a callable function from this?</p>
| [
{
"answer_id": 6791761,
"author": "Intrinsic",
"author_id": 260256,
"author_profile": "https://Stackoverflow.com/users/260256",
"pm_score": 0,
"selected": false,
"text": "(funcall (read-from-string (concatenate 'string \"setup_\" (symbol-name(first '(abc\\d)))))) \n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38132/"
] |
294,795 | <p>Wwhen I click the button on the popup to insert data to database, it does nothing, WHYYYYY?</p>
<pre><code><cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BehaviorID="popup" TargetControlID="cmdTrigger"
PopupControlID="pnlPopup" BackgroundCssClass="modalBackground"
OkControlID="btnOk" >
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalpopup" Style="display: none">
<div class="container">
<div class="header">
<asp:Label ID="Label1" runat="server" CssClass="msg" Text="Add a new Entry" />
<asp:LinkButton ID="LinkButton1" runat="server" CssClass="close" OnClientClick="$find('popup').hide(); return false;" />
</div>
<div class="body">
<asp:Label ID="Label2" runat="server" CssClass="msg" Text="Name" />
<asp:TextBox ID="txtName" runat="server" Width="346px"></asp:TextBox>
</div>
<div class="footer">
<asp:Button ID="btnOk" runat="server" Text="Save" Width="48px" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" Width="50px" OnClientClick="$find('popup').hide(); return false;" />
</div>
</div>
</asp:Panel>
</code></pre>
<p>The code on the btnOK is</p>
<p>a simple textbox1.text = txtName</p>
<p>I even tries setting a breakpoint, the button click event is not being executed. Any ideas?</p>
<p>Edit ~ Solution</p>
<blockquote>
<p>Follow <a href="http://forums.asp.net/t/1070213.aspx" rel="nofollow noreferrer">http://forums.asp.net/t/1070213.aspx</a></p>
</blockquote>
| [
{
"answer_id": 877703,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "CausesValidation=\"false\""
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294795",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23667/"
] |
294,802 | <p>What methods to use a database from Clojure are there?</p>
<p>I know from Clojure you can do anything you can with Java, but that means that I may end up using something overly complicated (like Hibernate) which clashes with Clojure simplicity. Any recommendations or comments?</p>
| [
{
"answer_id": 8007765,
"author": "mikera",
"author_id": 214010,
"author_profile": "https://Stackoverflow.com/users/214010",
"pm_score": 4,
"selected": false,
"text": "(select users\n (aggregate (count :*) :cnt)\n (where (or (> :visits 20)\n (< :last_login a-year-ago))))\n"
},
{
"answer_id": 28729394,
"author": "claj",
"author_id": 410012,
"author_profile": "https://Stackoverflow.com/users/410012",
"pm_score": 3,
"selected": false,
"text": "from group-by order-by OVER PARTITION BY .sql (raw-sql \"some('funky'::SYNTAX)\")"
},
{
"answer_id": 52634962,
"author": "Satyam Ramawat",
"author_id": 8979328,
"author_profile": "https://Stackoverflow.com/users/8979328",
"pm_score": 1,
"selected": false,
"text": " (ns clojureexercise.test\n (:require [clojure.java.jdbc :as sql])) ;;sql will alias used further in code to access java jdbc feature.\n (defn dbconnect []\n (def db{ \n :classname \"com.mysql.jdbc.Driver\" \n :subprotocol \"mysql\"\n :subname \"//127.0.0.1:3306/testdb\" ;;testdb is the name of database\n :user \"root\"\n :password \"password\"}))\n ;;Inserting Data into Database \n;;Table Name is patientinfo, consist columns {id, firstname, lastname, birthdate, gender}\n (defn insertdata []\n (sql/insert! db :patientinfo ;;used sql alias and db variable to insert data into table \n {:id 1 :firstname \"Satyam\" :lastname \"Ramawat\" \n :birthdate \"1/1/2018\" :gender \"Male\" }))\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6068/"
] |
294,822 | <p>I have a ComboBox bound to an ObservableCollection of decimals. What is the correct way to apply our currency converter to the items?</p>
<p>Edit:</p>
<p>a) I have an existing currency converter that I must use
b) .NET 3.0</p>
<p>Do I need to template the items?</p>
| [
{
"answer_id": 294830,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": 0,
"selected": false,
"text": "<TextBox Text=\"{Binding Path=Value, StringFormat=Amount: {0:C}}\"/>\n"
},
{
"answer_id": 294838,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 3,
"selected": false,
"text": "<ComboBox ItemStringFormat=\"c\">\n"
},
{
"answer_id": 294904,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 3,
"selected": true,
"text": "<Window.Resources>\n <my:CurrencyConverter x:Key=\"currencyConverter\" />\n\n <DataTemplate x:Key=\"thingTemplate\" DataType=\"{x:Type my:Thing}\">\n <TextBlock\n Text=\"{Binding Amount,Converter={StaticResource currencyConverter}}\" />\n </DataTemplate>\n</Window.Resources>\n\n<ComboBox\n ItemSource=\"... some list of Thing instances ...\"\n ItemTemplate=\"{StaticResource thingTemplate}\" />\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28074/"
] |
294,852 | <p>I find myself attached to a project to integerate an interpreter into an existing application. The language to be interpreted is a derivative of Lisp, with application-specific builtins. Individual 'programs' will be run batch-style in the application.</p>
<p>I'm surprised that over the years I've written a couple of compilers, and several data-language translators/parsers, but I've never actually written an interpreter before. The prototype is pretty far along, implemented as a syntax tree walker, in C++. I can probably influence the architecture beyond the prototype, but not the implementation language (C++). So, constraints:</p>
<ul>
<li>implementation will be in C++</li>
<li>parsing will probably be handled with a yacc/bison grammar (it is now)</li>
<li>suggestions of full VM/Interpreter ecologies like NekoVM and LLVM are probably not practical for this project. Self-contained is better, even if this sounds like NIH.</li>
</ul>
<p>What I'm really looking for is reading material on the fundamentals of implementing interpreters. I did some browsing of SO, and another site known as <a href="http://www.lambda-the-ultimate.org" rel="nofollow noreferrer">Lambda the Ultimate</a>, though they are more oriented toward programming language theory.</p>
<p>Some of the tidbits I've gathered so far:</p>
<ul>
<li><p><a href="https://rads.stackoverflow.com/amzn/click/com/0521545668" rel="nofollow noreferrer" rel="nofollow noreferrer">Lisp in Small Pieces</a>, by Christian Queinnec. The person recommending it said it "goes from the trivial interpreter to more advanced techniques and finishes presenting bytecode and 'Scheme to C' compilers."</p></li>
<li><p><a href="http://nekovm.org/" rel="nofollow noreferrer">NekoVM</a>. As I've mentioned above, I doubt that we'd be allowed to incorporate an entire VM framework to support this project.</p></li>
<li><p><a href="http://mitpress.mit.edu/sicp/full-text/book/book.html" rel="nofollow noreferrer">Structure and Interpretation of Computer Programs</a>. Originally I suggested that this might be overkill, but having worked through a healthy chunk, I agree with @JBF. Very informative, and mind-expanding.</p></li>
<li><p><a href="http://paulgraham.com/rootsoflisp.html" rel="nofollow noreferrer">On Lisp</a> by Paul Graham. I've read this, and while it is an informative introduction to Lisp principles, is not enough to jump-start constructing an interpreter.</p></li>
<li><p><a href="http://www.sidhe.org/~dan/presentations/Parrot_Implementation.pdf" rel="nofollow noreferrer">Parrot Implementation</a>. This seems like a fun read. Not sure it will provide me with the fundamentals.</p></li>
<li><p><a href="http://peter.michaux.ca/articles/scheme-from-scratch-introduction" rel="nofollow noreferrer">Scheme from Scratch</a>. Peter Michaux is attacking various implementations of Scheme, from a quick-and-dirty Scheme interpreter written in C (for use as a bootstrap in later projects) to compiled Scheme code. Very interesting so far.</p></li>
<li><p><a href="http://pragprog.com/book/tpdsl/language-implementation-patterns" rel="nofollow noreferrer">Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages</a>, recommended in the comment thread for <a href="https://stackoverflow.com/questions/2853412/books-on-creating-interpreted-languages">Books On Creating Interpreted Languages</a>. The book contains two chapters devoted to the practice of building interpreters, so I'm adding it to my reading queue.</p></li>
<li><em>New</em> (and yet <em>Old</em>, i.e. 1979): <a href="http://books.google.com/books?id=d6cpAQAAIAAJ&q=writing+interactive+compilers+and+interpreters&dq=writing+interactive+compilers+and+interpreters&hl=en&ei=FzorTsDzFIj0swOb_4XMCg&sa=X&oi=book_result&ct=result&resnum=1&ved=0CCkQ6AEwAA" rel="nofollow noreferrer">Writing Interactive Compilers and Interpreters</a> by P. J. Brown. This is long out of print, but is interesting in providing an outline of the various tasks associated with the implementation of a Basic interpreter. I've seen mixed reviews for this one but as it is cheap (I have it on order used for around $3.50) I'll give it a spin.</li>
</ul>
<p>So how about it? Is there a good book that takes the neophyte by the hand and shows how to build an interpreter in C/C++ for a Lisp-like language? Do you have a preference for syntax-tree walkers or bytecode interpreters?</p>
<p>To answer @JBF:</p>
<ul>
<li><p>the current prototype is an interpreter, and it makes sense to me as we're accepting a path to an arbitrary code file and executing it in our application environment. The builtins are used to affect our in-memory data representation.</p></li>
<li><p>it should not be hideously slow. The current tree walker seems acceptable.</p></li>
<li><p>The language is <em>based</em> on Lisp, but is not Lisp, so no standards compliance required.</p></li>
<li>As mentioned above, it's unlikely that we'll be allowed to add a full external VM/interpreter project to solve this problem.</li>
</ul>
<p>To the other posters, I'll be checking out your citations as well. Thanks, all!</p>
| [
{
"answer_id": 296157,
"author": "plinth",
"author_id": 20481,
"author_profile": "https://Stackoverflow.com/users/20481",
"pm_score": 3,
"selected": false,
"text": "ConsBoxFactory &GetConsBoxFactory() { return mConsFactory; }\nAtomFactory &GetAtomFactory() { return mAtomFactory; }\nEnvironment &GetEnvironment() { return mEnvironment; }\nt_ConsBox *Read(iostream &stm);\nt_ConsBox *Eval(t_ConsBox *box);\nvoid Print(basic_ostream<char> &stm, t_ConsBox *box);\nvoid RunProgram(char *program);\nvoid RunProgram(iostream &stm);\n t_ConsBox *ConsBoxFactory::Cadr(t_ConsBox *list)\n{\n return Car(Cdr(list));\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3778/"
] |
294,865 | <p>How do you convert a number to a string showing dollars and cents?</p>
<pre><code>eg:
123.45 => '$123.45'
123.456 => '$123.46'
123 => '$123.00'
.13 => '$0.13'
.1 => '$0.10'
0 => '$0.00'
</code></pre>
| [
{
"answer_id": 294868,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 3,
"selected": false,
"text": "printf(\"$%01.2f\", $money);\n"
},
{
"answer_id": 294871,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 7,
"selected": true,
"text": "echo money_format('$%i', 3.4); // echos '$3.40'\n $number = \"123.45\";\n $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY);\n return $formatter->formatCurrency($number, 'USD');\n"
},
{
"answer_id": 294879,
"author": "Darryl Hein",
"author_id": 5441,
"author_profile": "https://Stackoverflow.com/users/5441",
"pm_score": 6,
"selected": false,
"text": "'$' . number_format($money, 2);\n"
},
{
"answer_id": 21528231,
"author": "saadk",
"author_id": 2078007,
"author_profile": "https://Stackoverflow.com/users/2078007",
"pm_score": 4,
"selected": false,
"text": "money_format() number_format($money, 2,'.', ',')\n"
},
{
"answer_id": 53179621,
"author": "Frank Forte",
"author_id": 857113,
"author_profile": "https://Stackoverflow.com/users/857113",
"pm_score": 2,
"selected": false,
"text": "#windows\nextension=php_intl.dll\n\n#linux\nextension=php_intl.so\n $amount = 123.456;\n\n// for Canadian Dollars\n$currency = 'CAD';\n\n// for Canadian English\n$locale = 'en_CA';\n\n$fmt = new \\NumberFormatter( $locale, \\NumberFormatter::CURRENCY );\necho $fmt->formatCurrency($amount, $currency);\n"
},
{
"answer_id": 58315707,
"author": "asad saleem",
"author_id": 5122788,
"author_profile": "https://Stackoverflow.com/users/5122788",
"pm_score": 0,
"selected": false,
"text": "/* Just Do the following, */\n\necho money_format(\"%(#10n\",\"123.45\"); //Output $ 123.45\n\n/* If Negative Number -123.45 */\n\necho money_format(\"%(#10n\",\"-123.45\"); //Output ($ 123.45)\n"
},
{
"answer_id": 60348128,
"author": "Jon",
"author_id": 788445,
"author_profile": "https://Stackoverflow.com/users/788445",
"pm_score": 3,
"selected": false,
"text": "$f = new NumberFormatter(\"en\", NumberFormatter::CURRENCY);\n$f->formatCurrency(12345, \"USD\"); // Outputs \"$12,345.00\"\n '$' . number_format($money, 2);\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
294,875 | <p>What are some of the ways you have implemented models in the Zend Framework?</p>
<p>I have seen the basic <code>class User extends Zend_Db_Table_Abstract</code> and then putting calls to that in your controllers: </p>
<p><code>$foo = new User;</code></p>
<p><code>$foo->fetchAll()</code></p>
<p>but what about more sophisticated uses? The Quickstart section of the documentation offers such an example but I still feel like I'm not getting a "best use" example for models in Zend Framework. Any interesting implementations out there?</p>
<hr>
<p><strong>EDIT:</strong> I should clarify (in response to CMS's comment)... I know about doing more complicated selects. I was interested in overall approaches to the Model concept and concrete examples of how others have implemented them (basically, the stuff the manual leaves out and the stuff that basic how-to's gloss over) </p>
| [
{
"answer_id": 294896,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 1,
"selected": false,
"text": "Zend_Db_Table $select = $table->select();\n$select->from($table,\n array('COUNT(reported_by) as `count`', 'reported_by'))\n ->where('bug_status = ?', 'NEW')\n ->group('reported_by');\n"
},
{
"answer_id": 294914,
"author": "farzad",
"author_id": 9394,
"author_profile": "https://Stackoverflow.com/users/9394",
"pm_score": 1,
"selected": false,
"text": "public function __toString() {\n $data = $this->_name . ', ' . $this->_adderss . ', call: ' . $this->_phone;\n return $data;\n}\n"
},
{
"answer_id": 294936,
"author": "Barrett Conrad",
"author_id": 1227,
"author_profile": "https://Stackoverflow.com/users/1227",
"pm_score": 6,
"selected": true,
"text": "Zend_Db_Table_Abstract Zend_Db_Table_Row_Abstract Zend_Db_Table_Abstract Zend_Db_Table_Row_Abstract Zend_Db_Table_Abstract class Users extends Zend_Db_Table_Abstract {\n\n protected $_name = 'users';\n\n protected $_rowClass = 'User'; // <== THIS IS REALLY HELPFUL\n\n public function getById($id) {\n // RETURNS ONE INSTANCE OF 'User'\n }\n\n public function getActiveUsers() {\n // RETURNS MULTIPLE 'User' OBJECTS \n }\n\n}\n\nclass User extends Zend_Db_Table_Row_Abstract {\n\n public function setPassword() {\n // SET THE PASSWORD FOR A SINGLE ROW\n }\n\n}\n\n/* CONTROLLER */\npublic function setPasswordAction() {\n\n /* GET YOUR PARAMS */\n\n $users = new Users();\n\n $user = $users->getById($id);\n\n $user->setPassword($password);\n\n $user->save();\n}\n"
},
{
"answer_id": 295051,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 6,
"selected": false,
"text": "class MyModel extends Zend_Db_Table_Abstract\n{\n} \n class MyModel // extends nothing\n{\n protected $some_table;\n}\n"
},
{
"answer_id": 296892,
"author": "troelskn",
"author_id": 18180,
"author_profile": "https://Stackoverflow.com/users/18180",
"pm_score": 1,
"selected": false,
"text": "Zend_Db"
},
{
"answer_id": 495757,
"author": "lo_fye",
"author_id": 3407,
"author_profile": "https://Stackoverflow.com/users/3407",
"pm_score": 1,
"selected": false,
"text": "$derek = new User();\n$derek->setFirstName('Derek');\n$derek->save();\n $c = new Criteria();\n$c->add(UserPeer::FIRST_NAME, 'Derek');\n$dereks = UserPeer::doSelect($c);\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294875",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11252/"
] |
294,885 | <p>I have a table like this:</p>
<pre><code><table>
<tfoot>
<tr><td>footer</td></tr>
</tfoot>
<tbody>
<tr><td>Body 1</td></tr>
<tr><td>Body 1</td></tr>
<tr><td>Body 1</td></tr>
</tbody>
<tbody>
<tr><td>Body 2</td></tr>
<tr><td>Body 2</td></tr>
<tr><td>Body 2</td></tr>
</tbody>
<tbody>
<tr><td>Body 3</td></tr>
<tr><td>Body 3</td></tr>
<tr><td>Body 3</td></tr>
</tbody>
</table>
</code></pre>
<p>I'd like to put some spacing between each tbody element, but padding and margin have no effect. Any ideas?</p>
| [
{
"answer_id": 294886,
"author": "Dave Jensen",
"author_id": 35341,
"author_profile": "https://Stackoverflow.com/users/35341",
"pm_score": 7,
"selected": true,
"text": "<style>\ntable {\n border-collapse: collapse;\n}\n\ntable tbody {\n border-top: 15px solid white;\n}\n</style>\n\n<table>\n <tfoot>\n <tr><td>footer</td></tr>\n </tfoot>\n <tbody>\n <tr><td>Body 1</td></tr>\n <tr><td>Body 1</td></tr>\n <tr><td>Body 1</td></tr>\n </tbody>\n <tbody>\n <tr><td>Body 2</td></tr>\n <tr><td>Body 2</td></tr>\n <tr><td>Body 2</td></tr>\n </tbody>\n <tbody>\n <tr><td>Body 3</td></tr>\n <tr><td>Body 3</td></tr>\n <tr><td>Body 3</td></tr>\n </tbody>\n</table>\n"
},
{
"answer_id": 294925,
"author": "Dave Jensen",
"author_id": 35341,
"author_profile": "https://Stackoverflow.com/users/35341",
"pm_score": 3,
"selected": false,
"text": "<style>\ntable {\n border-collapse: collapse;\n}\n\ntd {\n border: 1px solid black;\n}\n\ntbody tr:first-child td {\n padding-top: 15px;\n}\n\n</style>\n\n<table>\n <tfoot>\n <tr><td>footer</td></tr>\n </tfoot>\n <tbody>\n <tr><td>Body 1</td></tr>\n <tr><td>Body 1</td></tr>\n <tr><td>Body 1</td></tr>\n </tbody>\n <tbody>\n <tr><td>Body 2</td></tr>\n <tr><td>Body 2</td></tr>\n <tr><td>Body 2</td></tr>\n </tbody>\n <tbody>\n <tr><td>Body 3</td></tr>\n <tr><td>Body 3</td></tr>\n <tr><td>Body 3</td></tr>\n </tbody>\n</table>\n"
},
{
"answer_id": 296352,
"author": "kevtrout",
"author_id": 1149,
"author_profile": "https://Stackoverflow.com/users/1149",
"pm_score": 5,
"selected": false,
"text": " .separator{\n height: 50px;\n }\n\n <table>\n <tr><td>Cell 1</td><td>Cell 2</td></tr>\n <tr><td>Cell 1</td><td>Cell 2</td></tr>\n <tr><td>Cell 1</td><td>Cell 2</td></tr>\n\n <tr class=\"separator\" colspan=\"2\"></tr>\n\n <tr><td>Cell 1</td><td>Cell 2</td></tr>\n <tr><td>Cell 1</td><td>Cell 2</td></tr>\n <tr><td>Cell 1</td><td>Cell 2</td></tr>\n\n <tr class=\"separator\" colspan=\"2\"></tr>\n\n tr><td>Cell 1</td><td>Cell 2</td></tr>\n <tr><td>Cell 1</td><td>Cell 2</td></tr>\n <tr><td>Cell 1</td><td>Cell 2</td></tr>\n </table>\n tr{\n height: 40px;\n}\n"
},
{
"answer_id": 708532,
"author": "Calvin",
"author_id": 86015,
"author_profile": "https://Stackoverflow.com/users/86015",
"pm_score": 2,
"selected": false,
"text": "<style>\ntbody {\n overflow: auto;\n border-top: 1px solid transparent;\n}\n</style>\n<table>\n <tfoot>\n <tr><td>footer</td></tr>\n </tfoot>\n <tbody>\n <tr><td>Body 1</td></tr>\n <tr><td>Body 1</td></tr>\n <tr><td>Body 1</td></tr>\n </tbody>\n <tbody>\n <tr><td>Body 2</td></tr>\n <tr><td>Body 2</td></tr>\n <tr><td>Body 2</td></tr>\n </tbody>\n <tbody>\n <tr><td>Body 3</td></tr>\n <tr><td>Body 3</td></tr>\n <tr><td>Body 3</td></tr>\n </tbody>\n</table>\n"
},
{
"answer_id": 708568,
"author": "Jason",
"author_id": 7173,
"author_profile": "https://Stackoverflow.com/users/7173",
"pm_score": 0,
"selected": false,
"text": "<tbody> <tbody> <td> table tbody.yourClass td {\n padding: 10px;\n}\n <table> \n<tbody>\n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n</tbody>\n<tbody class=\"yourClass\"> \n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n</tbody>\n<tbody>\n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n</tbody>\n</table>\n <tr> <td> table {\n border-collapse: collapse;\n}\n\ntr.yourClass td {\n padding: 10px;\n}\n <tr> tr.yourClass.topClass td {\n padding: 10px 0 0 0;\n}\n\ntr.yourClass.bottomClass td {\n padding: 0 0 10px 0;\n}\n <tr> <table> \n<tbody>\n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n<tr class=\"yourClass topClass\"><td>Text</td></tr>\n<tr class=\"yourClass\"><td>Text</td></tr>\n<tr class=\"yourClass bottomClass\"><td>Text</td></tr>\n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n<tr><td>Text</td></tr>\n</tbody>\n</table>\n"
},
{
"answer_id": 10762599,
"author": "MacNimble",
"author_id": 611864,
"author_profile": "https://Stackoverflow.com/users/611864",
"pm_score": 7,
"selected": false,
"text": "tbody::before\n{\n content: '';\n display: block;\n height: 15px;\n\n}\n"
},
{
"answer_id": 13895254,
"author": "OdraEncoded",
"author_id": 1660459,
"author_profile": "https://Stackoverflow.com/users/1660459",
"pm_score": 2,
"selected": false,
"text": "border-spacing <table>\n <thead>\n ...\n </head>\n <tbody>\n ...\n </tbody>\n <tbody>\n ...\n </tbody>\n <tfoot>\n ...\n </tfoot>\n</table>\n table {\n border-spacing: 0px 10px; /* h-spacing v-spacing */\n}\n"
},
{
"answer_id": 18793736,
"author": "Jereme",
"author_id": 2456799,
"author_profile": "https://Stackoverflow.com/users/2456799",
"pm_score": 0,
"selected": false,
"text": "<table class=\"tbl\">\n<tr></tr>\n<tr></tr>\n<tr></tr>\n<tr><td><div></div></td></tr>\n</table>\n .tbl tr td div {\n height:30px;\n margin-top:20px;\n}\n"
},
{
"answer_id": 23682569,
"author": "user007",
"author_id": 1983017,
"author_profile": "https://Stackoverflow.com/users/1983017",
"pm_score": 3,
"selected": false,
"text": "display block table tbody{\n display:block;\n margin-bottom:10px;\n border-radius: 5px;\n}\n"
},
{
"answer_id": 24696140,
"author": "Maarten",
"author_id": 3829126,
"author_profile": "https://Stackoverflow.com/users/3829126",
"pm_score": 2,
"selected": false,
"text": "// The first row will have a top padding\ntable tbody + tbody tr td {\n padding-top: 20px;\n}\n\n// The rest of the rows should not have a padding\ntable tbody + tbody tr + tr td {\n padding-top: 0px;\n}\n"
},
{
"answer_id": 32586906,
"author": "Nineoclick",
"author_id": 1817744,
"author_profile": "https://Stackoverflow.com/users/1817744",
"pm_score": 4,
"selected": false,
"text": "<tbody> ::before <td> rowspan <tbody> <tbody>\n <tr>\n <td>td 1</td>\n <td rowspan\"2\">td 2</td>\n <td>td 3</td>\n <td>td 4</td>\n </tr>\n <tr>\n <td>td 1</td>\n <td>td 2</td>\n <td>td 4</td>\n </tr>\n</tbody>\n ::before block tbody::before\n{\n content: '';\n display: block;\n height: 10px;\n}\n rowspan ::before table-row tbody::before\n{\n content: '';\n display: table-row;\n height: 10px;\n}\n"
},
{
"answer_id": 56080180,
"author": "Ian",
"author_id": 3063072,
"author_profile": "https://Stackoverflow.com/users/3063072",
"pm_score": 0,
"selected": false,
"text": "<br> </tbody> <table>\n <tbody>\n <tr>\n <td></td>\n </tr>\n <br>\n </tbody>\n <tbody>\n <tr>\n <td></td>\n </tr>\n </tbody>\n</table>\n"
},
{
"answer_id": 64592213,
"author": "user2182349",
"author_id": 2182349,
"author_profile": "https://Stackoverflow.com/users/2182349",
"pm_score": 0,
"selected": false,
"text": "table {\n border-collapse: collapse;\n table-layout: fixed;\n width: 50%;\n}\ntbody:before {\n content: \"\";\n display:block;\n border-top: 15px solid white;\n}\ntbody tr {\n border-color: #000;\n border-style: solid;\n}\ntbody tr:first-of-type{\n border-width: 2px 2px 0 2px;\n}\ntbody tr:nth-of-type(1n+2){\n border-width: 0 2px 0 2px;\n}\ntbody tr:last-of-type{\n border-width: 0 2px 2px 2px;\n}\ntbody tr:nth-child(odd) {\n background-color: #ccc;\n}\ntbody tr:hover {\n background-color: #eee;\n}\ntd {\n text-align: right;\n} <table>\n <tbody>\n <tr>\n <th colspan=\"3\">One</th>\n </tr>\n <tr>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n <tr>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n <tr>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n <tr>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n </tbody>\n <tbody>\n <tr>\n <th colspan=\"3\">Two</th>\n </tr>\n <tr>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n <tr>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n <tr>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n <tr>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n </tbody>\n</table>"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
294,890 | <p>This might be too opinionated a question, but looking for help!</p>
<p>I have been trying to refine my ASP.NET MVC program structure. I just started using it at preview 5 and it is my first foray into business application development -- so everyting is new!</p>
<p>At the controller level, I have a service object responsible for talking to the repository and taking care of all business logic. At the action level, I have an object that holds all view data -- user input and generated output -- that I'll call view object (is there a general term for this?). Unlike most examples I see, this object is not a database object, but an object specific to the view.</p>
<p>So now I want to add user validation. The problem is, I'm not sure where to put it. It makes the most sense to me to do it in the Service layer. The Service layer is responsible for all the business logic and validation is business logic. On the other hand, most validation frameworks that I see are for validating an object, which makes me think the view object should be validation aware. Finally, there are some validation methods that would require a database connection (checking if a user input field has a corresponding database record for example), and the view object has no concept of a database, only the Service.</p>
<p>So some options I see are:</p>
<ul>
<li>Do validation in the Service.Method on the parameters passed to the method.</li>
<li>Do validation in the view object before calling Service.Method.</li>
<li>Do validation in the view object but make the Service.Method require a view object reference so it is initiating the validation on the object.</li>
</ul>
<p>I'm sure there are more. I'm curious of how other people handle user input validation in the MVC sense. I've previously used the Enterprise Validation Block and liked being able to use stock validators for everything, but I'm not sure how to make it fit into a seperate view object and service layer. It would be easy if they (view object / service) were the same object, which is maybe what people do? Like I said, its all new to me and I'm looking for best practice / patterns.</p>
| [
{
"answer_id": 296084,
"author": "anonymous",
"author_id": 36602,
"author_profile": "https://Stackoverflow.com/users/36602",
"pm_score": 1,
"selected": false,
"text": "public static void SavePerson(Person person)\n{\n // make sure it meets some format requirement\n // in this case the object is responsible for validation and the service layer is the caller\n person.EnsureValid();\n\n // todo: action to verify username is unique by checking database\n // in this case the service layer is responsible for calling and implementing validation\n\n // todo: action to save to database\n}\n"
},
{
"answer_id": 1562675,
"author": "G-Wiz",
"author_id": 29805,
"author_profile": "https://Stackoverflow.com/users/29805",
"pm_score": 0,
"selected": false,
"text": "public class SomeProcessService \n{\n public Result Execute(int anAggregateID, int anotherAggregateID, string someData) \n {\n // validate input\n\n // if invalid, return failures\n\n // else \n // modify aggregates\n // using (transaction)\n // {\n // save aggregates\n // commit\n // }\n\n // return success\n }\n}\n public class SomeProcessService \n{\n public class Request : IValidateable\n {\n public int AggregateID {get;set;}\n public int AnotherAggregateID {get;set;}\n public string SomeData {get;set;}\n\n public Result Validate() \n {\n // validation\n }\n }\n\n public void Execute(Request request) \n {\n // validate input by calling request.Validate()\n\n // if invalid, throw new ValidationException(request)\n\n // else \n // modify aggregates\n // using (transaction)\n // {\n // save aggregates\n // commit\n // }\n\n // return success\n }\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36602/"
] |
294,905 | <p>Why does a System.Boolean take 4 bytes? It just stores one state, either <em>true</em> or <em>false</em>, which could be stored in less space than 4 bytes.</p>
| [
{
"answer_id": 294911,
"author": "arul",
"author_id": 15409,
"author_profile": "https://Stackoverflow.com/users/15409",
"pm_score": 2,
"selected": false,
"text": "Console.WriteLine( sizeof( System.Boolean ).ToString() );\n"
},
{
"answer_id": 294942,
"author": "P Daddy",
"author_id": 36388,
"author_profile": "https://Stackoverflow.com/users/36388",
"pm_score": 7,
"selected": true,
"text": "bool Nullable<bool> bool? bool Nullable<bool> bool bool Nullable<> BitVector32"
},
{
"answer_id": 21784918,
"author": "John Fairbanks",
"author_id": 500010,
"author_profile": "https://Stackoverflow.com/users/500010",
"pm_score": 0,
"selected": false,
"text": "long startMem = 0, stopMem = 0;\nDateTime startTime = DateTime.Now;\nprivate void StartMemoryUsage()\n{\n GC.Collect();\n GC.Collect();\n startMem = GC.GetTotalMemory(true);\n startTime = DateTime.Now;\n}\nprivate void StopMemoryUsage()\n{\n GC.Collect();\n GC.Collect();\n stopMem = GC.GetTotalMemory(true);\n\n Console.WriteLine(\"---> {0} sec. Using {1} KB.\", (DateTime.Now - startTime).TotalSeconds, ((stopMem - startMem) / 1000).ToString());\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19917/"
] |
294,917 | <p>I'm trying to create a newsletter standard for our org and having problems with Outlook rendering the text too large.</p>
<p>Here is the css section of the page</p>
<pre><code>body {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 75%;
background: url(http://www.blah.com/stuff.gif);
}
a {
color: #f24c22 !important;
}
a:visited {
color: #f24c22 !important;
}
a:hover {
color: #3d7ac5 !important;
}
table {
background: #ffffff;
}
h1 {
font-size: 1.3em;
}
h2 {
font-size: 1.2em;
color: #494949;
padding-top: 0 !important;
margin-top: 0 !important;
}
h3 {
font-size: 1.1em;
color: #12377c;
}
p {
padding-top: 0 !important;
margin-top: 0 !important;
color:#333333;
}
.style1 {color: #333333}
.style2 {color: #12377c}
.style3 {
font-size: smaller;
color: #666666;
}
</code></pre>
<p>Any suggestions why this might be caused?</p>
| [
{
"answer_id": 575878,
"author": "Esteban Küber",
"author_id": 34813,
"author_profile": "https://Stackoverflow.com/users/34813",
"pm_score": 3,
"selected": true,
"text": "main *{font-size: 12pt;} body style"
},
{
"answer_id": 1679306,
"author": "Dave Stewart",
"author_id": 203298,
"author_profile": "https://Stackoverflow.com/users/203298",
"pm_score": 0,
"selected": false,
"text": "<meta name=\"ProgId\" content=\"Word.Document\" />\n<meta name=\"Generator\" content=\"Microsoft Word 12\" />\n<meta name=\"Originator\" content=\"Microsoft Word 12\" />\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294917",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38149/"
] |
294,922 | <p>I have a winforms app and i want to keep track of every time a user clicks certain buttons, etc as well as other actions. What is the best way for me to keep track of this information and then put it together so i can run metrics on most used features, etc.</p>
<p>This is a winforms app and I have users around the world.</p>
| [
{
"answer_id": 294943,
"author": "arul",
"author_id": 15409,
"author_profile": "https://Stackoverflow.com/users/15409",
"pm_score": 0,
"selected": false,
"text": " // execute this method once all forms have been created\n public static void HookButtons()\n {\n foreach( Form f in Application.OpenForms )\n {\n EnumerateControls( f.Controls );\n }\n }\n\n public static void EnumerateControls( ICollection controls )\n {\n foreach( Control ctrl in controls )\n {\n if( ctrl.Controls.Count > 0 )\n {\n EnumerateControls( ctrl.Controls );\n }\n\n if( ctrl is ButtonBase )\n {\n ctrl.MouseClick +=new MouseEventHandler( ctrl_MouseClick );\n }\n }\n\n }\n\n static void ctrl_MouseClick( object sender, MouseEventArgs e )\n {\n ButtonBase clicked = ((ButtonBase)sender);\n\n // do something with the click information here\n }\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
294,927 | <p>Do you have to pass delete the same pointer that was returned by new, or can you pass it a pointer to one of the classes base types? For example:</p>
<pre><code>class Base
{
public:
virtual ~Base();
...
};
class IFoo
{
public:
virtual ~IFoo() {}
virtual void DoSomething() = 0;
};
class Bar : public Base, public IFoo
{
public:
virtual ~Bar();
void DoSomething();
...
};
Bar * pBar = new Bar;
IFoo * pFoo = pBar;
delete pFoo;
</code></pre>
<p>Of course this is greatly simplified. What I really want to do is create a container full of boost::shared_ptr and pass it to some code that will remove it from the container when it is finished. This code will know nothing of the implementation of Bar or Base, and will rely on the implied delete operator in the shared_ptr destructor to do the right thing.</p>
<p>Can this possibly work? My intuition says no, since the pointers will not have the same address. On the other hand, a dynamic_cast<Bar*> should work, so somewhere the compiler is storing enough information to figure it out.
<hr>
Thanks for the help, everybody who answered and commented. I already knew the importance of virtual destructors, as shown in my example; after seeing the answer I gave it a little thought, and realized the <i>whole reason</i> for a virtual destructor is this exact scenario. Thus it had to work. I was thrown by the absence of a visible means of converting the pointer back to the original. A little more thinking led me to believe there was an invisible means, and I theorized that the destructor was returning the true pointer for delete to release. Investigating the compiled code from Microsoft VC++ confirmed my suspicion when I saw this line in ~Base:</p>
<pre><code>mov eax, DWORD PTR _this$[ebp]
</code></pre>
<p>Tracing the assembler revealed that this was the pointer being passed to the delete function. Mystery solved.</p>
<p>I've fixed the example to add the virtual destructor to IFoo, it was a simple oversight. Thanks again to everyone who pointed it out.</p>
| [
{
"answer_id": 294932,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 7,
"selected": true,
"text": "Base IFoo operator delete"
},
{
"answer_id": 295048,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 2,
"selected": false,
"text": "shared_ptr shared_ptr shared_ptr shared_ptr<> shared_ptr<> shared_ptr<> shared_ptr<> shared_ptr shared_ptr shared_ptr IFoo IFoo IFoo shared_ptr<IFoo> Bar shared_ptr Bar*"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5987/"
] |
294,933 | <p>I have a couple of tables in a SQL 2008 server that I need to generate unique ID's for. I have looked at the "identity" column but the ID's really need to be unique and shared between all the tables. </p>
<p>So if I have say (5) five tables of the flavour "asset infrastructure" and I want to run with a unique ID between them as a combined group, I need some sort of generator that looks at all (5) five tables and issues the next ID which is not duplicated in any of those (5) five tales. </p>
<p>I know this could be done with some sort of stored procedure but I'm not sure how to go about it. Any ideas?</p>
| [
{
"answer_id": 294982,
"author": "Ian Varley",
"author_id": 37539,
"author_profile": "https://Stackoverflow.com/users/37539",
"pm_score": 2,
"selected": false,
"text": "CREATE PROCEDURE InsertAsset_Table1 (\n BEGIN TRANSACTION\n -- SELECT MIN INTEGER NOT ALREADY USED IN ANY OF THE FIVE TABLES\n -- INSERT INTO Table1 WITH THAT ID\n COMMIT TRANSACTION -- or roll back on error, etc.\n)\n"
},
{
"answer_id": 4784309,
"author": "cibis",
"author_id": 587768,
"author_profile": "https://Stackoverflow.com/users/587768",
"pm_score": 0,
"selected": false,
"text": "create table T1(ID int primary key identity(1,2), rownum varchar(64))\n\ncreate table T2(ID int primary key identity(2,2), rownum varchar(64))\n\ninsert into T1(rownum) values('row 1')\ninsert into T1(rownum) values('row 2')\ninsert into T1(rownum) values('row 3')\n\ninsert into T2(rownum) values('row 1')\ninsert into T2(rownum) values('row 2')\ninsert into T2(rownum) values('row 3')\n\nselect * from T1\n\nselect * from T2\n\ndrop table T1\ndrop table T2\n"
},
{
"answer_id": 8284253,
"author": "Mike Trader",
"author_id": 18749,
"author_profile": "https://Stackoverflow.com/users/18749",
"pm_score": 0,
"selected": false,
"text": "110,2455892,00000001\n120,2455892,00000002\n100,2455892,00000003\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6335/"
] |
294,949 | <p>I need to create an empty .mdb file, so that I can then run ADO commands on it (<em>not</em> ADO.NET). Is there a way to create an empty mdb using ADO?</p>
| [
{
"answer_id": 294959,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 3,
"selected": true,
"text": " string sADOProvider = \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\";\n\n ADOX.CatalogClass cat = new ADOX.CatalogClass();\n\n string sCreate = MainForm.sADOProvider + sFullPath;\n\n cat.Create(sCreate);\n\n // The point of this code is to unlock the access file after we\n // create it. You can tell it is unlocked if the .ldb file disappears.\n System.Runtime.InteropServices.Marshal.ReleaseComObject(cat);\n cat = null;\n GC.Collect();\n"
},
{
"answer_id": 294974,
"author": "Mark Nold",
"author_id": 4134,
"author_profile": "https://Stackoverflow.com/users/4134",
"pm_score": 0,
"selected": false,
"text": "Option Explicit\n\nSub CreateMDBEarlyBound()\n '' Remember to set your reference to \"Microsoft Access XX.0 Object Library\"\n Dim acApp As Access.Application\n\n Set acApp = New Access.Application\n acApp.NewCurrentDatabase (\"c:\\temp\\MyDB-early.mdb\")\n\n Set acApp = Nothing\n\nEnd Sub\n\n\nSub CreateMDBLateBound()\n\n Dim acApp As Object\n\n On Error Resume Next\n Set acApp = GetObject(, \"Access.Application\")\n On Error GoTo 0 '' turn off the resume next\n\n If acApp Is Nothing Then\n Set acApp = CreateObject(\"Access.Application\")\n End If\n\n acApp.NewCurrentDatabase \"c:\\temp\\MyDB-late.mdb\"\n Set acApp = Nothing\n\n\nEnd Sub\n"
},
{
"answer_id": 424082,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 0,
"selected": false,
"text": " Const sADOProvider As String = \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"\n\n Const sFullPath As String = \"C:\\DeleteMe.mdb\"\n\n Dim cat As ADOX.Catalog\n Set cat = New ADOX.Catalog\n\n Dim sCreate As String\n sCreate = sADOProvider & sFullPath\n\n cat.Create sCreate\n\n ' The point of this code is to unlock the access file after we\n ' create it. You can tell it is unlocked if the .ldb file disappears.\n Set cat.ActiveConnection = Nothing\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294949",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14902/"
] |
294,969 | <p>I am working on an application that will be used as an extensible framework for other applications.</p>
<p>One of the fundamental classes is called Node, and Nodes have Content. The SQL tables look like this:</p>
<p>TABLE Node ( NodeId int, .... etc )</p>
<p>TABLE NodeContentRelationship ( NodeId int, ContentType string, ContentId int)</p>
<p>It will be up to the developers extending the application to create their own content types.</p>
<p>Clearly this is bad from a relationship-database point of view as it is not possible to add a foreign key relationship to NodeContentRelationship.ContentId, even though it <em>is</em> a foreign key column.</p>
<p>However, the solution is quite simple and powerful so I am reluctant to change it.</p>
<p>What do you think - am I in for a world of pain down the track?</p>
| [
{
"answer_id": 294994,
"author": "yfeldblum",
"author_id": 12349,
"author_profile": "https://Stackoverflow.com/users/12349",
"pm_score": 3,
"selected": true,
"text": "NoteContentRelationship.ContentId Content AnimalContent CarContent"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21966/"
] |
294,976 | <p>As prescribed by Yahoo!, gzip'ng files would make your websites load faster. The problem? I don't know how :p</p>
| [
{
"answer_id": 295053,
"author": "amitkaz",
"author_id": 38100,
"author_profile": "https://Stackoverflow.com/users/38100",
"pm_score": 2,
"selected": false,
"text": "LoadModule deflate_module modules/mod_deflate.so\n AddOutputFilterByType DEFLATE text/css text/html application/x-javascript application/javascript\nBrowserMatch ^Mozilla/4 gzip-only-text/html\nBrowserMatch ^Mozilla/4\\.0[678] no-gzip\nBrowserMatch \\bMSIE !no-gzip !gzip-only-text/html\n"
},
{
"answer_id": 13054409,
"author": "Anthony Hatzopoulos",
"author_id": 881551,
"author_profile": "https://Stackoverflow.com/users/881551",
"pm_score": 0,
"selected": false,
"text": "iis lighthttpd nginx node Apache mod_deflate"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294976",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37532/"
] |
294,989 | <p>Can somebody tell me how to use the <em><code>printWhenExpression</code></em> of JasperReports?</p>
| [
{
"answer_id": 294999,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 4,
"selected": false,
"text": "$F{mesure} != \"PH\"\n($F{userfd4}).equals(\"1\") ? true : false \n cannot cast from boolean to Boolean ( $F{mesure}.startsWith(\"PH\") ? Boolean.TRUE:Boolean.FALSE ) \n($F{userfd4}).equals(\"1\") ? Boolean.TRUE : Boolean.FALSE \n boolean Boolean $F{fieldName}.equals(\"hello\") demo/samples/tableofcontents/reports/TocPart.jrxml <reportElement style=\"Sans_Bold\" positionType=\"Float\" x=\"50\" y=\"0\" width=\"100\" height=\"15\" isRemoveLineWhenBlank=\"true\" uuid=\"db8b68c6-4430-4199-8967-3ab5c077cb56\">\n <property name=\"local_mesure_unitx\" value=\"pixel\"/>\n <property name=\"com.jaspersoft.studio.unit.x\" value=\"px\"/>\n <printWhenExpression><![CDATA[$F{level} == 1]]></printWhenExpression>\n</reportElement>\n"
},
{
"answer_id": 302142,
"author": "Dónal",
"author_id": 2648,
"author_profile": "https://Stackoverflow.com/users/2648",
"pm_score": 3,
"selected": false,
"text": "$F{age} >= 18\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/294989",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
295,013 | <p>In the application that I am working on, the logging facility makes use of <code>sprintf</code> to format the text that gets written to file. So, something like:</p>
<pre><code>char buffer[512];
sprintf(buffer, ... );
</code></pre>
<p>This sometimes causes problems when the message that gets sent in becomes too big for the manually allocated buffer.</p>
<p>Is there a way to get <code>sprintf</code> behaviour without having to manually allocate memory like this? </p>
<p>EDIT: while <code>sprintf</code> is a C operation, I'm looking for C++ type solutions (if there are any!) for me to get this sort of behaviour...</p>
| [
{
"answer_id": 295018,
"author": "Artelius",
"author_id": 31945,
"author_profile": "https://Stackoverflow.com/users/31945",
"pm_score": 2,
"selected": false,
"text": "fprintf() malloc()"
},
{
"answer_id": 295023,
"author": "philant",
"author_id": 18804,
"author_profile": "https://Stackoverflow.com/users/18804",
"pm_score": 5,
"selected": true,
"text": "sprintf() snprintf() std::string ostringstream"
},
{
"answer_id": 295097,
"author": "flolo",
"author_id": 36472,
"author_profile": "https://Stackoverflow.com/users/36472",
"pm_score": 3,
"selected": false,
"text": "length = snprintf(NULL, ...);\nstr = malloc(length+1);\nsnprintf(str, ...);\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4368/"
] |
295,016 | <p>When using <code>call_user_func_array()</code> I want to pass a parameter by reference. How would I do this. For example</p>
<pre><code>function toBeCalled( &$parameter ) {
//...Do Something...
}
$changingVar = 'passThis';
$parameters = array( $changingVar );
call_user_func_array( 'toBeCalled', $parameters );
</code></pre>
| [
{
"answer_id": 295020,
"author": "Steven Oxley",
"author_id": 3831,
"author_profile": "https://Stackoverflow.com/users/3831",
"pm_score": 7,
"selected": true,
"text": "call_user_func_array() function toBeCalled( &$parameter ) {\n //...Do Something...\n}\n\n$changingVar = 'passThis';\n$parameters = array( &$changingVar );\ncall_user_func_array( 'toBeCalled', $parameters );\n call_user_func_array()"
},
{
"answer_id": 31972652,
"author": "Sophia_ES",
"author_id": 3080003,
"author_profile": "https://Stackoverflow.com/users/3080003",
"pm_score": 1,
"selected": false,
"text": "function toBeCalled( $par_ref ) {\n $parameter = $par_ref->parameter;\n //...Do Something...\n $par_ref->parameter = $parameter;\n}\n\n$changingVar = 'passThis';\n$parembed = new stdClass; // Creates an empty object\n$parembed->parameter = array( $changingVar );\ncall_user_func_array( 'toBeCalled', $parembed );\n"
},
{
"answer_id": 42122984,
"author": "Danny",
"author_id": 7536724,
"author_profile": "https://Stackoverflow.com/users/7536724",
"pm_score": 0,
"selected": false,
"text": "$a = 2;\n$a = toBeCalled($a);\necho $a //50\n\nfunction toBeCalled( &$par_ref ) {\n $parameter = &$par_ref;\n $parameter = $parameter*25;\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295016",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3831/"
] |
295,027 | <p>I am working on refactoring some old code and have found few structs containing zero length arrays (below). Warnings depressed by pragma, of course, but I've failed to create by "new" structures containing such structures (error 2233). Array 'byData' used as pointer, but why not to use pointer instead? or array of length 1? And of course, no comments were added to make me enjoy the process...
Any causes to use such thing? Any advice in refactoring those?</p>
<pre><code>struct someData
{
int nData;
BYTE byData[0];
}
</code></pre>
<p>NB It's C++, Windows XP, VS 2003</p>
| [
{
"answer_id": 296143,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 6,
"selected": true,
"text": "struct someData* mallocSomeData(int size)\n{\n struct someData* result = (struct someData*)malloc(sizeof(struct someData) + size * sizeof(BYTE));\n if (result)\n { result->nData = size;\n }\n return result;\n}\n"
},
{
"answer_id": 23775738,
"author": "Kaz",
"author_id": 1250772,
"author_profile": "https://Stackoverflow.com/users/1250772",
"pm_score": 4,
"selected": false,
"text": "struct someData\n{\n int nData;\n unsigned char byData[1];\n}\n sizeof struct someData byData offsetof(struct someData, byData);\n struct someData byData struct someData *psd = (struct someData *) malloc(offsetof(struct someData, byData) + 42);\n offsetof sizeof struct hack {\n unsigned long ul;\n char c;\n char foo[0]; /* assuming our compiler accepts this nonsense */\n};\n struct hack ul unsigned long sizeof (struct hack) offsetof(struct hack, foo) offsetof"
},
{
"answer_id": 48713532,
"author": "Mike Ruete",
"author_id": 9340257,
"author_profile": "https://Stackoverflow.com/users/9340257",
"pm_score": 2,
"selected": false,
"text": "struct foo\n{\n size_t count;\n int data[1];\n}\n\nsize_t foo_size_from_count(size_t count)\n{\n return offsetof(foo, data[count]);\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7003/"
] |
295,028 | <p>I have a very tricky situation (for my standards) in hand. I have a script that needs to read a script variable name from <a href="https://docs.python.org/2/library/configparser.html" rel="nofollow noreferrer">ConfigParser</a>. For example, I need to read</p>
<pre><code>self.post.id
</code></pre>
<p>from a .cfg file and use it as a variable in the script. How do I achieve this?</p>
<p>I suppose I was unclear in my query. The .cfg file looks something like:</p>
<pre><code>[head]
test: me
some variable : self.post.id
</code></pre>
<p>This self.post.id is to be replaced at the run time, taking values from the script.</p>
| [
{
"answer_id": 295038,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 4,
"selected": true,
"text": "[head]\nvar: self.post.id\n import ConfigParser\n\nclass Test:\n def __init__(self):\n self.post = TestPost(5)\n def getPost(self):\n config = ConfigParser.ConfigParser()\n config.read('/path/to/test.ini')\n newvar = config.get('head', 'var')\n print eval(newvar) \n\nclass TestPost:\n def __init__(self, id):\n self.id = id\n\ntest = Test()\ntest.getPost() # prints 5\n"
},
{
"answer_id": 295745,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 0,
"selected": false,
"text": "# Change this for some reason or another\nx = self.post.id # Standard Configuration \n# x = self.post.somethingElse # Another Configuration\n# x = self.post.yetAnotherCase # A third configuration\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295028",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2220518/"
] |
295,035 | <p>I have a sharepoint event handler which I want to activate for a single list, not all the lists in the site. How do I go about this?</p>
| [
{
"answer_id": 295090,
"author": "ashwnacharya",
"author_id": 1909,
"author_profile": "https://Stackoverflow.com/users/1909",
"pm_score": 3,
"selected": true,
"text": "string siteUrl = Console.ReadLine();\nSPSite site = new SPSite(siteUrl);\nSPWeb web = site.OpenWeb();\nstring listName = Console.ReadLine();\n\nSPList list = web.Lists[listName];\nstring assemblyName = \"Issue.EventHandler, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=89fde668234f6b1d\";\nstring className = \"Issue.EventHandler.IssueEventHandler\";\n\nlist.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assemblyName, className);\n"
},
{
"answer_id": 6597122,
"author": "akshit",
"author_id": 831661,
"author_profile": "https://Stackoverflow.com/users/831661",
"pm_score": 1,
"selected": false,
"text": "for (int i = 0; i < olist.EventReceivers.Count; i++) {\n olist.EventReceivers[i].Delete();\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1909/"
] |
295,042 | <p>Is there an issue with databinding in WPF when you bind to the current source (Path=".") and using a converter? The two way binding doesn't seem to work in this situation.</p>
<p>I know I could change the path, but I want to be able to pass the "Name" value to the converter.</p>
<p>I can't get the following example to work:</p>
<pre><code><Window x:Class="WpfTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:WpfTest"
Title="Window1" Height="600" Width="600">
<Window.Resources>
<l:Person x:Key="myDataSource" Name="Cam"/>
<l:TestConverter x:Key="converter" />
</Window.Resources>
<StackPanel>
<StackPanel.DataContext>
<Binding Source="{StaticResource myDataSource}"/>
</StackPanel.DataContext>
<TextBox>
<TextBox.Text>
<Binding
Path="."
UpdateSourceTrigger="PropertyChanged"
Converter="{StaticResource converter}"
ConverterParameter="Name"
/>
</TextBox.Text>
</TextBox>
<TextBlock Text="{Binding Path=Name}"/>
</StackPanel>
</Window>
class TestConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Reverse(value, parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Reverse(value, parameter);
}
private static object Reverse(object value, object parameter)
{
if (value == null)
throw new ArgumentNullException("value", "value is null.");
if (parameter == null)
throw new ArgumentNullException("parameter", "parameter is null.");
Person p = (Person)value;
if (parameter.ToString() == "Name")
{
StringBuilder sb = new StringBuilder();
for (int i = p.Name.Length - 1; i >= 0; i--)
{
sb.Append(p.Name[i]);
}
return sb.ToString();
}
throw new NotImplementedException();
}
}
public class Person:INotifyPropertyChanged
{
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
</code></pre>
| [
{
"answer_id": 295090,
"author": "ashwnacharya",
"author_id": 1909,
"author_profile": "https://Stackoverflow.com/users/1909",
"pm_score": 3,
"selected": true,
"text": "string siteUrl = Console.ReadLine();\nSPSite site = new SPSite(siteUrl);\nSPWeb web = site.OpenWeb();\nstring listName = Console.ReadLine();\n\nSPList list = web.Lists[listName];\nstring assemblyName = \"Issue.EventHandler, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=89fde668234f6b1d\";\nstring className = \"Issue.EventHandler.IssueEventHandler\";\n\nlist.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assemblyName, className);\n"
},
{
"answer_id": 6597122,
"author": "akshit",
"author_id": 831661,
"author_profile": "https://Stackoverflow.com/users/831661",
"pm_score": 1,
"selected": false,
"text": "for (int i = 0; i < olist.EventReceivers.Count; i++) {\n olist.EventReceivers[i].Delete();\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295042",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3820/"
] |
295,052 | <p>Ok I need to determine the system's OS from a Lua script, but Lua as such has no API for this, so I use os.getenv() and query enviromental variables. On Windows checking the enviromental variable "OS" gives me the name of the system's OS, but is there some variable that exists on both Windows and most flavors of Unix that can be checked?</p>
| [
{
"answer_id": 14425862,
"author": "mnicky",
"author_id": 626431,
"author_profile": "https://Stackoverflow.com/users/626431",
"pm_score": 5,
"selected": false,
"text": "package.config:sub(1,1) '\\\\' '/'"
},
{
"answer_id": 30960054,
"author": "Matías Hermosilla",
"author_id": 5032278,
"author_profile": "https://Stackoverflow.com/users/5032278",
"pm_score": 3,
"selected": false,
"text": "local BinaryFormat = package.cpath:match(\"%p[\\\\|/]?%p(%a+)\")\nif BinaryFormat == \"dll\" then\n function os.name()\n return \"Windows\"\n end\nelseif BinaryFormat == \"so\" then\n function os.name()\n return \"Linux\"\n end\nelseif BinaryFormat == \"dylib\" then\n function os.name()\n return \"MacOS\"\n end\nend\nBinaryFormat = nil\n"
},
{
"answer_id": 74073523,
"author": "Ramon0",
"author_id": 2805176,
"author_profile": "https://Stackoverflow.com/users/2805176",
"pm_score": 0,
"selected": false,
"text": "function MyScript:OS()\n return package.config:sub(1,1) == \"\\\\\" and \"win\" or \"unix\"\nend\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295052",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15124/"
] |
295,055 | <p>I'm learning xForms, but apparently not well enough because I can't figure out why <a href="http://www.logomachist.info/temp/fix_me.xhtml.xml" rel="nofollow noreferrer">this code</a> doesn't work. </p>
<p>It parses in FF2 w/ the xForms extension but does not render the form controls. IE7 and X-Smiles give me different problems, but I'm not sure if those problems are becaause of my xForms or because of something else- until I get it working in FF2 I can't really tell.</p>
| [
{
"answer_id": 874224,
"author": "Phil Booth",
"author_id": 47348,
"author_profile": "https://Stackoverflow.com/users/47348",
"pm_score": 3,
"selected": true,
"text": "model model model select1 repeat model instance bind model model model instance bind model model instance model model repeat bind repeat bind nodeset ref repeat <xf:bind nodeset=\"//want\" readonly=\"true()\" />\n setvalue repeat xforms-value-changed repeat setvalue xforms-value-changed model model head model body"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295055",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22885/"
] |
295,058 | <p>How do I convert a string to the variable name in <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" rel="noreferrer">Python</a>?</p>
<p>For example, if the program contains a object named <code>self.post</code> that contains a variable named, I want to do something like:</p>
<pre><code>somefunction("self.post.id") = |Value of self.post.id|
</code></pre>
| [
{
"answer_id": 295064,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 6,
"selected": true,
"text": "eval() print eval('self.post.id') # Prints the value of self.post.id\n"
},
{
"answer_id": 295113,
"author": "Geo",
"author_id": 31610,
"author_profile": "https://Stackoverflow.com/users/31610",
"pm_score": 5,
"selected": false,
"text": "print globals()[\"myvar\"]\n"
},
{
"answer_id": 296060,
"author": "Brian",
"author_id": 9493,
"author_profile": "https://Stackoverflow.com/users/9493",
"pm_score": 6,
"selected": false,
"text": "__import__(\"os\").system(\"Some nasty command like rm -rf /*\")\n varname = \"post\"\nvalue = getattr(self, varname) # Gets self.post\n value = setattr(self, varname, new_value)\n def getattr_qualified(obj, name):\n for attr in name.split(\".\"):\n obj = getattr(obj, attr)\n return obj\n\ndef setattr_qualified(obj, name, value):\n parts = name.split(\".\")\n for attr in parts[:-1]:\n obj = getattr(obj, attr)\n setattr(obj, parts[-1], value)\n"
},
{
"answer_id": 1732924,
"author": "gibson",
"author_id": 210857,
"author_profile": "https://Stackoverflow.com/users/210857",
"pm_score": 4,
"selected": false,
"text": ">>> wine = 'pinot_noir'\n>>> vars()[wine] = 'yum'\n>>> pinot_noir\n'yum'\n vars() locals()"
},
{
"answer_id": 71725960,
"author": "Supergamer",
"author_id": 14539774,
"author_profile": "https://Stackoverflow.com/users/14539774",
"pm_score": 0,
"selected": false,
"text": "var=\"variable name\"\ndef returnvar(string):\n exec(f\"\"\"global rtn\nrtn={string}\"\"\")\n return rtn\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2220518/"
] |
295,059 | <p>Is it possible to get the value from the first page to the second page, BUT without <code>FORM</code>?</p>
<p>Shall we use</p>
<pre><code>window.parent.document.getElementById("").value..
</code></pre>
<p>But this is working in <code>popup</code> window, but I need this for between two pages which redirecting from the first page to the second page.</p>
| [
{
"answer_id": 295541,
"author": "Tom",
"author_id": 26155,
"author_profile": "https://Stackoverflow.com/users/26155",
"pm_score": 0,
"selected": false,
"text": "site.com/index.php?info=value value <input type=\"text\" id=\"the_value\" />\n<a href=\"#\" onclick=\"return updateURL()\" id=\"the_link\">Click me</a>\n<script type=\"text/javascript\">\nfunction updateURL()\n{\n document.getElementById('the_link').href =\n 'site.com/index2.php?info=' +\n encodeURIComponent(document.getElementById('the_value'));\n return true;\n}\n</script>\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38172/"
] |
295,067 | <p>I am a COM object written in ATL that is used from a C++ application, and I want to pass an array of BYTEs between the two. My experience of COM/IDL so far is limited to passing simple types (BSTRs, LONGs, etc.).</p>
<p>Is there a relatively easy way to have the COM object pass an array to the caller? For example, I want to pass a raw image (TIFF) instead of messing with temporary files.</p>
| [
{
"answer_id": 295070,
"author": "jpoh",
"author_id": 4368,
"author_profile": "https://Stackoverflow.com/users/4368",
"pm_score": 0,
"selected": false,
"text": "[id(1), helpstring(\"LogCache\")] HRESULT LogCache([out,retval] VARIANT* logCache);\n safearray_t<bstr_t> m_logCache;\n ...\n if (m_logCache.size() > 1000)\n {\n m_logCache.pop_back();\n }\n\n m_logCache.push_front(Msg.str(), 0);\n\n\n variant_t LogCache()\n {\n if (!m_logCache.is_empty())\n {\n variant_t cache(m_logCache);\n return cache;\n }\n }\n"
},
{
"answer_id": 295080,
"author": "Aamir",
"author_id": 30341,
"author_profile": "https://Stackoverflow.com/users/30341",
"pm_score": 5,
"selected": true,
"text": "bool ArrayToVariant(CArray<BYTE, BYTE>& array, VARIANT& vtResult)\n{\nSAFEARRAY FAR* psarray;\nSAFEARRAYBOUND sabounds[1]; \n\nsabounds[0].lLbound=0;\nsabounds[0].cElements = (ULONG)array.GetSize();\n\nlong nLbound;\n\npsarray = SafeArrayCreate(VT_UI1, 1, sabounds);\nif(psarray == NULL)\n return false;\n\nfor(nLbound = 0; nLbound < (long)sabounds[0].cElements ; nLbound++){\n if(FAILED(SafeArrayPutElement(psarray, &nLbound, &array[nLbound]))){\n SafeArrayDestroy(psarray);\n return false;\n }\n}\n\nVariantFree(vtResult);\nvtResult.vt = VT_ARRAY|VT_UI1;\nvtResult.parray = psarray;\nreturn true;\n}\n"
},
{
"answer_id": 295083,
"author": "Dmitry Khalatov",
"author_id": 18174,
"author_profile": "https://Stackoverflow.com/users/18174",
"pm_score": -1,
"selected": false,
"text": "BYTE array[buffer_size];\n...\nBSTR toBePassed = SysAllocStringByteLen((OLECHAR*)array,length);\nYourCOMMethod(toBePassed);\nSysFreeString(toBePassed);\n BYTE* pData = (BYTE*)bstrPassed;\nDWORD dataLength = SysStringByteLen(bstrPassed);\n"
},
{
"answer_id": 298735,
"author": "Martin",
"author_id": 1529,
"author_profile": "https://Stackoverflow.com/users/1529",
"pm_score": 2,
"selected": false,
"text": "void Fx([in] long cItems, [in, size_is(cItems)] BYTE aItems[]);\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295067",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9236/"
] |
295,071 | <p>When we write in a Javascript expression : </p>
<pre><code>expression < <%=variableJsp%>
</code></pre>
<p>the double "<" seems to be a problem and the JSP is not interpreted ?</p>
<p>Is it a fault of the other servers that should not accept this type of expression ? Or WebSphere that bugs ?</p>
| [
{
"answer_id": 295074,
"author": "krosenvold",
"author_id": 23691,
"author_profile": "https://Stackoverflow.com/users/23691",
"pm_score": 0,
"selected": false,
"text": "expression < <%=variableJsp%>\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295071",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19281/"
] |
295,085 | <p>Is there a way to specify the font size for a class to be, say, 70% of the inherited font size?</p>
<p>I have a general "button" class that sets up my buttons with the appropriate borders, background, etc. I use it in multiple places, including one where the font size is fairly small and another where the font size is quite large.</p>
<pre><code><div style="font-size: 26px;">
Push this: <input class="button" type="submit" value="Go">
</div>
<div style="font-size: 10px;">
Push this too: <input class="button" type="submit" value="Go">
</div>
</code></pre>
<p>In both instances I'd like the button font-size to be about 70% of the font size of the span or div the button is in. </p>
<p>Can I do this with pure CSS?</p>
| [
{
"answer_id": 295087,
"author": "Jason Anderson",
"author_id": 5142,
"author_profile": "https://Stackoverflow.com/users/5142",
"pm_score": 2,
"selected": false,
"text": "font-size: 0.7em;\n"
},
{
"answer_id": 295093,
"author": "Will Kemp",
"author_id": 38177,
"author_profile": "https://Stackoverflow.com/users/38177",
"pm_score": 1,
"selected": false,
"text": "<input style=\"font-size: 70%\" class=\"button\" type=\"submit\" value=\"Go\">\n"
},
{
"answer_id": 295518,
"author": "Ola Tuvesson",
"author_id": 6903,
"author_profile": "https://Stackoverflow.com/users/6903",
"pm_score": 5,
"selected": true,
"text": "<style>\nsmall { font-size: .8em; }\nspan.tiny { font-size: .8em } \n</style>\n\n<small>This text is 80% of base size where as \n <span class=\"tiny\">this text is 80% of 80% (or 64%) of base size</span>\n</small> \n em rem html rem"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295085",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13055/"
] |
295,091 | <p>The ListChanged event for an IBindingList fires a type ListChangedType.ItemDeleted when items are deleted, perhaps by a user deleting a row in a datagrid control bound to the list. The problem is that the NewIndex into the list is invalid in this event, it's been deleted, and the item that was deleted is not available. There should be an ItemDeleting event, but I doubt they will ever fix this.</p>
| [
{
"answer_id": 295468,
"author": "Sunlight",
"author_id": 33650,
"author_profile": "https://Stackoverflow.com/users/33650",
"pm_score": 2,
"selected": false,
"text": "NewIndex ItemDeleting"
},
{
"answer_id": 2127342,
"author": "Adam Valpied",
"author_id": 257246,
"author_profile": "https://Stackoverflow.com/users/257246",
"pm_score": 4,
"selected": true,
"text": "BindingListBase<T> BindingList<T> BindingList<T> RemovedItem Public MustInherit Class BindingListBase(Of T)\n Inherits BindingList(Of T)\n\n Protected mRemovedItems As New List(Of T)\n\n Protected Overrides Sub ClearItems()\n MyBase.ClearItems()\n mRemovedItems.Clear()\n End Sub\n\n Protected Overrides Sub RemoveItem(ByVal index As Integer)\n Dim item As T = MyBase.Item(index)\n\n MyBase.RemoveItem(index)\n\n mRemovedItems.Add(item)\n End Sub\n\n Public ReadOnly Property RemovedItems as List(Of T)\n Get\n Return mRemovedItems\n End Get\n End Property\nEnd Class\n"
},
{
"answer_id": 21868936,
"author": "BenCamps",
"author_id": 1046117,
"author_profile": "https://Stackoverflow.com/users/1046117",
"pm_score": 2,
"selected": false,
"text": "public class ItemRemovedEventArgs : EventArgs\n{\n public Object Item { get; set; }\n\n public ItemRemovedEventArgs(Object item)\n {\n this.Item = item;\n }\n}\n\npublic delegate void ItemRmoveEventHandler(Object sender, ItemRemovedEventArgs e);\n\npublic class BindingListRedux<T> : BindingList<T>\n{\n public BindingListRedux() : base() { }\n\n public BindingListRedux(IList<T> list) : base(list) { }\n\n public event ItemRmoveEventHandler ItemRemoved;\n\n protected void OnItemRemoved(ItemRemovedEventArgs e)\n {\n if (ItemRemoved != null)\n {\n ItemRemoved(this, e);\n }\n }\n\n protected override void RemoveItem(int index)\n {\n Object item = base[index];\n base.RemoveItem(index);\n this.OnItemRemoved(new ItemRemovedEventArgs(item));\n }\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295091",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28343/"
] |
295,094 | <p>is there any known pattern/algorithm on how to perform sorting or filtering a list of records (from database) in the correct way? My current attempt involves usage of a form that provides some filtering and sorting options, and then append these criteria and sorting algorithm to my existing SQL. However, I find it can be easily abused that users may get results that they are not suppose to see. </p>
<p>The application that I am building is a scheduler where I store all the events in a database table. Then depending on user's level/role/privilege a different subset of data will be displayed. Therefore my query can be as complicated as </p>
<pre><code>SELECT *
FROM app_event._event_view
WHERE ((class_id = (SELECT class_id FROM app_event._ical_class WHERE name = 'PUBLIC') AND class_id != (SELECT class_id FROM app_event._ical_class WHERE name = 'PRIVATE') AND class_id != (SELECT class_id FROM app_event._ical_class WHERE name = 'CONFIDENTIAL')) OR user_id = '1')
AND calendar_id IN (SELECT calendar_id FROM app_event.calendar WHERE is_personal = 't')
AND calendar_id = (SELECT calendar_id FROM app_event.calendar WHERE name = 'personal')
AND state_id IN (1,2,3,4,5,6) AND EXTRACT(year FROM dtstart) = '2008'
AND EXTRACT(month FROM dtstart) = '11'
</code></pre>
<p>As I am more concern about serving the correct subset of information, performance is not a major concern at the moment (as the sql mentioned was generated by the script, clause by clause). I am thinking of turning all these complicated SQL statements to views, so there will be less chances that the SQL generated is inappropriate.</p>
| [
{
"answer_id": 295115,
"author": "Stein G. Strindhaug",
"author_id": 26115,
"author_profile": "https://Stackoverflow.com/users/26115",
"pm_score": 0,
"selected": false,
"text": "select from event where conditions AND event.privilegue <= user.privilegue\n"
},
{
"answer_id": 295129,
"author": "user38123",
"author_id": 38123,
"author_profile": "https://Stackoverflow.com/users/38123",
"pm_score": 0,
"selected": false,
"text": "SELECT * \nFROM app_event._event_view \nWHERE\n (\n :p_start_year is null or\n (state_id IN (1,2,3,4,5,6) AND EXTRACT(year FROM dtstart) = :p_start_year)\n )\n and\n (\n :p_date_start is null or\n AND EXTRACT(month FROM dtstart) = :p_date_start\n )\n"
},
{
"answer_id": 295657,
"author": "Ian Varley",
"author_id": 37539,
"author_profile": "https://Stackoverflow.com/users/37539",
"pm_score": 1,
"selected": false,
"text": "SELECT * \n FROM \n app_event._event_view EV\n INNER JOIN app_event.calendar C\n ON EV.calendar_id = C.calendar.id\n INNER JOIN app_event._ical_class IC\n ON C.class_id = EV.class_id\n WHERE \n C.is_personal = 't'\n AND C.name = 'personal'\n AND state_id IN (1,2,3,4,5,6) \n AND EXTRACT(year FROM dtstart) = '2008' \n AND EXTRACT(month FROM dtstart) = '11'\n AND (\n IC.name = 'PUBLIC' -- other two are redundant\n OR user_id = '1'\n )\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295094",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5742/"
] |
295,095 | <p>I have a textbox whose value I want to set based on the inner text of an anchor tag. In other words, when someone clicks on this anchor:</p>
<pre><code><a href="javascript:void();" class="clickable">Blah</a>
</code></pre>
<p>I want my textbox to populate with the text "Blah". Here is the code I am currently using:</p>
<pre><code><script type="text/javascript">
$(document).ready(function(){
$("a.clickable").click(function(event){
$("input#textbox").val($(this).html());
});
});
</script>
</code></pre>
<p>And in my html there is a list of anchor tags with the class "clickable" and one textbox with the id "textbox".</p>
<p>I've substituted the code above with code to just show a javascript alert with $(this).html() and it seems to show the correct value. I have also changed the $(this).html() to be a hardcoded string and it setes the textbox value correctly. But when I combine them the textbox simply clears out. What am I doing wrong?</p>
| [
{
"answer_id": 295099,
"author": "Falco Foxburr",
"author_id": 37266,
"author_profile": "https://Stackoverflow.com/users/37266",
"pm_score": 7,
"selected": true,
"text": "<a href=\"#\" class=\"clickable\">Blah</a>\n<input id=\"textbox\">\n<script type=\"text/javascript\">\n $(document).ready(function(){\n $(\"a.clickable\").click(function(event){\n event.preventDefault();\n $(\"input#textbox\").val($(this).html());\n }); \n });\n</script>\n"
},
{
"answer_id": 1666742,
"author": "max",
"author_id": 201597,
"author_profile": "https://Stackoverflow.com/users/201597",
"pm_score": 4,
"selected": false,
"text": "$(\"#textbox\").val('Blah');\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1574/"
] |
295,100 | <p>I am having a similar issue to <a href="https://stackoverflow.com/questions/28387/sql-server-2k5-memory-consumption">this person</a>. The primary difference being the application is NOT meant for a developer environment, and therefore I need to know how to optimize the space used by Sql Server (possibly per machine based on specs).</p>
<p>I was intrigued by <a href="https://stackoverflow.com/users/10795/ricardo-c">Ricardo C's</a> answer, particularly the following:</p>
<blockquote>
<p>Extracted fromt he SQL Server
documentation:</p>
<p>Maximum server memory (in MB)</p>
<p>Specifies the maximum amount of memory SQL Server can allocate when it
starts and while it runs. This
configuration option can be set to a
specific value if you know there are
multiple applications running at the
same time as SQL Server and you want
to guarantee that these applications
have sufficient memory to run. If
these other applications, such as Web
or e-mail servers, request memory only
as needed, then do not set the option,
because SQL Server will release memory
to them as needed. <strong>However,
applications often use whatever memory
is available when they start and do
not request more if needed</strong>. If an
application that behaves in this
manner runs on the same computer at
the same time as SQL Server, set the
option to a value that guarantees that
the memory required by the application
is not allocated by SQL Server.</p>
</blockquote>
<p>My question is: how does an application request memory from the OS when it needs it? Is this something built into compilation or something managed by the developer? The two primary apps running on this machine are Sql Server and the (fairly heavyweight) C# application I'm developing, and I'm almost certain we didn't specifically do anything in the realm of asking the OS for memory. Is there a correct/necessary way to do this?</p>
| [
{
"answer_id": 295367,
"author": "Matthew Schinckel",
"author_id": 188,
"author_profile": "https://Stackoverflow.com/users/188",
"pm_score": 0,
"selected": false,
"text": "[object alloc]; \n [[object alloc] init];\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295100",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8207/"
] |
295,101 | <p>I have a movie which is made up of a series of SWF files that read XML. Is there any way to burn it to a CD/DVD or at least convert it to a 'burnable' format such as AVI, MPEG, or ISO? Currently in order to burn it I have to so some funky screen capture stuff and recorded it to a DVD that way.</p>
| [
{
"answer_id": 3975666,
"author": "fish2000",
"author_id": 298171,
"author_profile": "https://Stackoverflow.com/users/298171",
"pm_score": 0,
"selected": false,
"text": "package ost.panda.map.core {\n\n/// ...\n\npublic dynamic class Signatories extends EventDispatcher {\n\n [Embed(source='../build/json/local_all.json',\n mimeType='application/octet-stream')]\n public static var rawSignatoryJSON:Class;\n\n public static function loadAll():void {\n loadFromJSON(JSON.deserialize(String(new rawSignatoryJSON())));\n }\n /// etc ...\n}\n\n} /// package\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
295,104 | <p>In C#, what makes a field different from a property, and when should a field be used instead of a property?</p>
| [
{
"answer_id": 295109,
"author": "Cory",
"author_id": 8207,
"author_profile": "https://Stackoverflow.com/users/8207",
"pm_score": 11,
"selected": true,
"text": "public class MyClass\n{\n // this is a field. It is private to your class and stores the actual data.\n private string _myField;\n\n // this is a property. When accessed it uses the underlying field,\n // but only exposes the contract, which will not be affected by the underlying field\n public string MyProperty\n {\n get\n {\n return _myField;\n }\n set\n {\n _myField = value;\n }\n }\n\n // This is an AutoProperty (C# 3.0 and higher) - which is a shorthand syntax\n // used to generate a private field for you\n public int AnotherProperty { get; set; } \n}\n"
},
{
"answer_id": 295140,
"author": "danswain",
"author_id": 30861,
"author_profile": "https://Stackoverflow.com/users/30861",
"pm_score": 8,
"selected": false,
"text": "public class Person\n{\n private string _name;\n\n public string Name\n {\n get\n {\n return _name;\n }\n set\n {\n _name = value;\n }\n }\n public int Age{get;set;} //AutoProperty generates private field for us\n}\n"
},
{
"answer_id": 295305,
"author": "Rune Grimstad",
"author_id": 30366,
"author_profile": "https://Stackoverflow.com/users/30366",
"pm_score": 4,
"selected": false,
"text": "Name get_Name() set_Name(string value)"
},
{
"answer_id": 1047593,
"author": "Moe Sisko",
"author_id": 70140,
"author_profile": "https://Stackoverflow.com/users/70140",
"pm_score": 3,
"selected": false,
"text": "get { return _afield; }\nset { _afield = value; }\n"
},
{
"answer_id": 1047641,
"author": "Jehof",
"author_id": 83039,
"author_profile": "https://Stackoverflow.com/users/83039",
"pm_score": 6,
"selected": false,
"text": "public class Person {\n private string _name;\n\n public event EventHandler NameChanging; \n public event EventHandler NameChanged;\n\n public string Name{\n get\n {\n return _name;\n }\n set\n {\n OnNameChanging();\n _name = value;\n OnNameChanged();\n }\n }\n\n private void OnNameChanging(){ \n NameChanging?.Invoke(this,EventArgs.Empty); \n }\n\n private void OnNameChanged(){\n NameChanged?.Invoke(this,EventArgs.Empty);\n }\n}\n"
},
{
"answer_id": 20822849,
"author": "Petryanu",
"author_id": 3001115,
"author_profile": "https://Stackoverflow.com/users/3001115",
"pm_score": 3,
"selected": false,
"text": "class Employee\n{\n // Private Fields for Employee\n private int id;\n private string name;\n\n //Property for id variable/field\n public int EmployeeId\n {\n get\n {\n return id;\n }\n set\n {\n id = value;\n }\n }\n\n //Property for name variable/field\n public string EmployeeName\n {\n get\n {\n return name;\n }\n set\n {\n name = value;\n }\n }\n}\n\nclass MyMain\n{\n public static void Main(string [] args)\n {\n Employee aEmployee = new Employee();\n aEmployee.EmployeeId = 101;\n aEmployee.EmployeeName = \"Sundaran S\";\n }\n}\n"
},
{
"answer_id": 26211245,
"author": "Sarath Subramanian",
"author_id": 3312636,
"author_profile": "https://Stackoverflow.com/users/3312636",
"pm_score": 6,
"selected": false,
"text": "Properties Field dataTable.Rows.Count dataTable.Columns[i].Caption DataTable dataTable.Rows.Count dataTable.Columns[i].Caption Field Properties public class DataTable\n{\n public class Rows\n { \n private string _count; \n\n // This Count will be accessable to us but have used only \"get\" ie, readonly\n public int Count\n {\n get\n {\n return _count;\n } \n }\n } \n\n public class Columns\n {\n private string _caption; \n\n // Used both \"get\" and \"set\" ie, readable and writable\n public string Caption\n {\n get\n {\n return _caption;\n }\n set\n {\n _caption = value;\n }\n } \n } \n}\n Button PropertyGrid Text Name Button Properties PropertyGrid PropertyGrid Field public class Button\n{\n private string _text; \n private string _name;\n private string _someProperty;\n\n public string Text\n {\n get\n {\n return _text;\n }\n set\n {\n _text = value;\n }\n } \n\n public string Name\n {\n get\n {\n return _name;\n }\n set\n {\n _name = value;\n }\n } \n\n [Browsable(false)]\n public string SomeProperty\n {\n get\n {\n return _someProperty;\n }\n set\n {\n _someProperty= value;\n }\n } \n PropertyGrid Name Text SomeProperty [Browsable(false)] public class Rows\n{ \n private string _count; \n\n\n public int Count\n {\n get\n {\n return CalculateNoOfRows();\n } \n } \n\n public int CalculateNoOfRows()\n {\n // Calculation here and finally set the value to _count\n return _count;\n }\n}\n Fields BindingSource Properties Field Property Property public string Name\n {\n // Can set debug mode inside get or set\n get\n {\n return _name;\n }\n set\n {\n _name = value;\n }\n }\n"
},
{
"answer_id": 31928150,
"author": "Vasim Shaikh",
"author_id": 5212418,
"author_profile": "https://Stackoverflow.com/users/5212418",
"pm_score": 3,
"selected": false,
"text": " class SomeClass\n {\n int numbera; //Field\n\n //Property \n public static int numbera { get; set;}\n\n }\n"
},
{
"answer_id": 32025538,
"author": "Joe Amenta",
"author_id": 1083771,
"author_profile": "https://Stackoverflow.com/users/1083771",
"pm_score": 3,
"selected": false,
"text": "public void TransformPoint(ref double x, ref double y);\n System.Windows.Point[] points = new Point[1000000];\nInitialize(points);\n for (int i = 0; i < points.Length; i++)\n{\n double x = points[i].X;\n double y = points[i].Y;\n TransformPoint(ref x, ref y);\n points[i].X = x;\n points[i].Y = y;\n}\n internal struct MyPoint\n{\n internal double X;\n internal double Y;\n}\n\n// ...\n\nMyPoint[] points = new MyPoint[1000000];\nInitialize(points);\n\n// ...\n\nfor (int i = 0; i < points.Length; i++)\n{\n TransformPoint(ref points[i].X, ref points[i].Y);\n}\n TransformPoint volatile volatile"
},
{
"answer_id": 35718340,
"author": "ahmed alkhatib",
"author_id": 4809440,
"author_profile": "https://Stackoverflow.com/users/4809440",
"pm_score": 2,
"selected": false,
"text": "Employee // A simple example\npublic class student\n{\n public int ID;\n public int passmark;\n public string name;\n}\n\npublic class Program\n{\n public static void Main(string[] args)\n {\n student s1 = new student();\n s1.ID = -101; // here ID can't be -ve\n s1.Name = null ; // here Name can't be null\n }\n}\n public class student\n{\n private int _ID;\n private int _passmark;\n private string_name ;\n // for id property\n public void SetID(int ID)\n {\n if(ID<=0)\n {\n throw new exception(\"student ID should be greater then 0\");\n }\n this._ID = ID;\n }\n public int getID()\n {\n return_ID;\n }\n}\npublic class programme\n{\n public static void main()\n {\n student s1 = new student ();\n s1.SetID(101);\n }\n // Like this we also can use for Name property\n public void SetName(string Name)\n {\n if(string.IsNullOrEmpty(Name))\n {\n throw new exeception(\"name can not be null\");\n }\n this._Name = Name;\n }\n public string GetName()\n {\n if( string.IsNullOrEmpty(This.Name))\n {\n return \"No Name\";\n }\n else\n {\n return this._name;\n }\n }\n // Like this we also can use for Passmark property\n public int Getpassmark()\n {\n return this._passmark;\n }\n}\n"
},
{
"answer_id": 41057448,
"author": "Tony Pinot",
"author_id": 7240339,
"author_profile": "https://Stackoverflow.com/users/7240339",
"pm_score": 2,
"selected": false,
"text": "public class MyClass\n{\n private int _id;\n public int ID { get { return _id; } }\n public MyClass(int id)\n {\n _id = id;\n }\n}\n public class MyClass\n{\n public int ID { get; private set; }\n public MyClass(int id)\n {\n ID = id;\n }\n}\n"
},
{
"answer_id": 41682082,
"author": "Django",
"author_id": 5230616,
"author_profile": "https://Stackoverflow.com/users/5230616",
"pm_score": 2,
"selected": false,
"text": "public string Name\n{\n get\n {\n return name;\n }\n protected set\n {\n name = value;\n }\n}\n"
},
{
"answer_id": 44551286,
"author": "Nayas Subramanian",
"author_id": 4315441,
"author_profile": "https://Stackoverflow.com/users/4315441",
"pm_score": 2,
"selected": false,
"text": " Using Getter and Setter\n\n // field\n private int _age;\n\n // setter\n public void set(int age){\n if (age <=0)\n throw new Exception();\n\n this._age = age;\n }\n\n // getter\n public int get (){\n return this._age;\n }\n\n Now using property we can do the same thing. In the value is a key word\n\n private int _age;\n\n public int Age{\n get{\n return this._age;\n }\n\n set{\n if (value <= 0)\n throw new Exception()\n }\n }\n public int Age{get;set;}\n public abstract class Person\n {\n public abstract string Name\n {\n get;\n set;\n }\n public abstract int Age\n {\n get;\n set;\n }\n }\n\n// overriden something like this\n// Declare a Name property of type string:\n public override string Name\n {\n get\n {\n return name;\n }\n set\n {\n name = value;\n }\n }\n public int MyProperty\n{\n get; private set;\n}\n private int myProperty;\npublic int MyProperty\n{\n get { return myProperty; }\n}\n"
},
{
"answer_id": 44762448,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "class Room {\n public string sectionOne;\n public string sectionTwo;\n}\n\nRoom r = new Room();\nr.sectionOne = \"enter\";\n class Room \n{\n private string sectionOne;\n private string sectionTwo;\n\n public string SectionOne \n {\n get \n {\n return sectionOne; \n }\n set \n { \n sectionOne = Check(value); \n }\n }\n}\n\nRoom r = new Room();\nr.SectionOne = \"enter\";\n"
},
{
"answer_id": 56773915,
"author": "Timmy_A",
"author_id": 3599970,
"author_profile": "https://Stackoverflow.com/users/3599970",
"pm_score": 5,
"selected": false,
"text": "PROPERTY_TYPE get();\n\nvoid set(PROPERTY_TYPE value);\n class PropertyEmulation\n{\n private string MSomeValue;\n\n public string GetSomeValue()\n {\n return(MSomeValue);\n }\n\n public void SetSomeValue(string value)\n {\n MSomeValue=value;\n }\n}\n class OneHundredFields\n{\n public int Field1;\n public int Field2;\n ...\n public int Field100;\n}\n\nOneHundredFields Instance=new OneHundredFields() // Variable 'Instance' consumes 100*sizeof(int) bytes of memory.\n\nclass OneHundredProperties\n{\n public int Property1\n {\n get\n {\n return(1000);\n }\n set\n {\n // Empty.\n }\n }\n\n public int Property2\n {\n get\n {\n return(1000);\n }\n set\n {\n // Empty.\n }\n }\n\n ...\n\n public int Property100\n {\n get\n {\n return(1000);\n }\n set\n {\n // Empty.\n }\n }\n}\n\nOneHundredProperties Instance=new OneHundredProperties() // !!!!! Variable 'Instance' consumes 0 bytes of memory. (In fact a some bytes are consumed becasue every object contais some auxiliarity data, but size doesn't depend on number of properties).\n class Name\n{\n public string FullName;\n public int YearOfBirth;\n public int Age;\n}\n\nName name=new Name();\n\nname.FullName=\"Tim Anderson\";\nname.YearOfBirth=1979;\nname.Age=40;\n readonly name.FullName=null;\nname.YearOfBirth=2200;\nname.Age=-140;\n Age YearOfBirth FullName class Name class Name\n{\n private string MFullName=\"\";\n private int MYearOfBirth;\n\n public string FullName\n {\n get\n {\n return(MFullName);\n }\n set\n {\n if (value==null)\n {\n throw(new InvalidOperationException(\"Error !\"));\n }\n\n MFullName=value;\n }\n }\n\n public int YearOfBirth\n {\n get\n {\n return(MYearOfBirth);\n }\n set\n {\n if (MYearOfBirth<1900 || MYearOfBirth>DateTime.Now.Year)\n {\n throw(new InvalidOperationException(\"Error !\"));\n }\n\n MYearOfBirth=value;\n }\n }\n\n public int Age\n {\n get\n {\n return(DateTime.Now.Year-MYearOfBirth);\n }\n }\n\n public string FullNameInUppercase\n {\n get\n {\n return(MFullName.ToUpper());\n }\n }\n}\n FullName YearOfBirth Age YearOfBirth FullNameInUppercase FullName DateTime class MyList\n{\n private string[] MBuffer;\n\n public MyList()\n {\n MBuffer=new string[100];\n }\n\n public string this[int Index]\n {\n get\n {\n return(MBuffer[Index]);\n }\n set\n {\n MBuffer[Index]=value;\n }\n }\n}\n\nMyList List=new MyList();\n\nList[10]=\"ABC\";\nConsole.WriteLine(List[10]);\n class AutoProps\n{\n public int Value1\n {\n get;\n set;\n }\n\n public int Value2\n {\n get;\n set;\n }\n}\n class AutoProps sizeof(Value1)+sizeof(Value2) internal class AutoProps\n{\n [CompilerGenerated]\n [DebuggerBrowsable(DebuggerBrowsableState.Never)]\n private int <Value1>k__BackingField;\n\n [CompilerGenerated]\n [DebuggerBrowsable(DebuggerBrowsableState.Never)]\n private int <Value2>k__BackingField;\n\n public int Value1\n {\n [CompilerGenerated]\n get\n {\n return <Value1>k__BackingField;\n }\n [CompilerGenerated]\n set\n {\n <Value1>k__BackingField = value;\n }\n }\n\n public int Value2\n {\n [CompilerGenerated]\n get\n {\n return <Value2>k__BackingField;\n }\n [CompilerGenerated]\n set\n {\n <Value2>k__BackingField = value;\n }\n }\n}\n"
},
{
"answer_id": 61340918,
"author": "suhail",
"author_id": 975236,
"author_profile": "https://Stackoverflow.com/users/975236",
"pm_score": 1,
"selected": false,
"text": "useMeId.Id=5 ---call the property of user control \"UseMe.ascx\"\n <%@ Register Src=~/\"UseMe.ascx\" TagPrefix=\"uc\" TagName=\"UseMe\" %>\n<uc:UseMe runat=\"Server\" id=\"useMeId\" />\n\nUseMe.ascx.cs\n\nprivate int currentId;\n\npublic int Id\n {\n get\n {\n return currentId;\n }\n set\n {\n currentId = value;\n LoadInitialData(currentId);\n }\n }\nPrivate void LoadinitialData(int currentIdParam)\n{\n//your action\n\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295104",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
295,110 | <p>I'm looking to use: </p>
<pre><code>#define
</code></pre>
<p>and</p>
<pre><code>#if
</code></pre>
<p>to allow me to simulate potentially absent hardware during unit tests. What are the rules for using the <code>#define</code> statements? </p>
<p>i.e. what is its default scope? can I change the scope of the directive?</p>
| [
{
"answer_id": 295162,
"author": "Ali Ersöz",
"author_id": 4215,
"author_profile": "https://Stackoverflow.com/users/4215",
"pm_score": 1,
"selected": false,
"text": "#define something\n... some code ...\n #if something\n ... some conditional code ...\n#else\n ... otherwise ...\n#endif\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1816/"
] |
295,112 | <p>How would I get the last item (or any specific item for that matter) in a simplexml object? Assume you don't know how many nodes there will be.</p>
<p>ex.</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/xsl.xml"?>
<obj
href="http://xml.foo.com/"
display="com.foo.bar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://obix.org/ns/schema/1.0"
>
<list name="data" of="HistoryRecord">
<obj>
<abstime name="timestamp" val="1876-11-10T00:00:00-08:00"></abstime>
<int name="energy_in_kwh" val="1234"></int>
<int name="energy_out_kwh" val="123456"></int>
</obj>
<obj>
<abstime name="timestamp" val="1876-11-10T00:15:00-08:00"></abstime>
<int name="energy_in_kwh" val="1335"></int>
<int name="energy_out_kwh" val="443321"></int>
</obj>
</list>
<int name="count" val="2"></int>
</obj>
</code></pre>
<p>And I want to grab the last <code><obj></obj></code> chunk (or even just part of it).</p>
| [
{
"answer_id": 295127,
"author": "Stein G. Strindhaug",
"author_id": 26115,
"author_profile": "https://Stackoverflow.com/users/26115",
"pm_score": 0,
"selected": false,
"text": "last()"
},
{
"answer_id": 295177,
"author": "DreamWerx",
"author_id": 15487,
"author_profile": "https://Stackoverflow.com/users/15487",
"pm_score": 0,
"selected": false,
"text": "<?php\n$s = simplexml_load_file('in.xml');\n$s->registerXPathNamespace('obix', 'http://obix.org/ns/schema/1.0');\n$items = $s->xpath('//obix:list');\n?>\n"
},
{
"answer_id": 295250,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 4,
"selected": true,
"text": "last() <?php \n$xml = simplexml_load_file('HistoryRecord.xml'); \n$xml->registerXPathNamespace('o', 'http://obix.org/ns/schema/1.0');\n\n$xpath = \"/o:obj/o:list/o:obj[last()]/o:int[@name = 'energy_in_kwh']\";\n$last_kwh = $xml->xpath($xpath); \n?> \n <obj> <int> \"energy_in_kwh\" \"http://obix.org/ns/schema/1.0\" [last()] [position() = last()]"
},
{
"answer_id": 295258,
"author": "Stefan Gehrig",
"author_id": 11354,
"author_profile": "https://Stackoverflow.com/users/11354",
"pm_score": 2,
"selected": false,
"text": "$xml='<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"/xsl.xml\"?>\n<obj href=\"http://xml.foo.com/\" display=\"com.foo.bar\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://obix.org/ns/schema/1.0\" >\n <list name=\"data\" of=\"HistoryRecord\">\n <obj>\n <abstime name=\"timestamp\" val=\"1876-11-10T00:00:00-08:00\"></abstime>\n <int name=\"energy_in_kwh\" val=\"1234\"></int>\n <int name=\"energy_out_kwh\" val=\"123456\"></int>\n </obj>\n <obj>\n <abstime name=\"timestamp\" val=\"1876-11-10T00:15:00-08:00\"></abstime>\n <int name=\"energy_in_kwh\" val=\"1335\"></int>\n <int name=\"energy_out_kwh\" val=\"443321\"></int>\n </obj>\n </list>\n <int name=\"count\" val=\"2\"></int>\n</obj>';\n$x=simplexml_load_string($xml);\n$x->registerXPathNamespace('obix', 'http://obix.org/ns/schema/1.0');\n$objects=$x->xpath('/obix:obj/obix:list/obix:obj[last()]');\nprint_r($objects);\n /bookstore/book[last()]"
},
{
"answer_id": 27154406,
"author": "Victor",
"author_id": 509235,
"author_profile": "https://Stackoverflow.com/users/509235",
"pm_score": 0,
"selected": false,
"text": " <?php \n $xml = simplexml_load_file('HistoryRecord.xml'); \n $lastObj = $xml->list->obj[$xml->list->obj->count()-1];\n $lastObj = $xml->list->obj[count($xml->list->obj)-1];\n end()"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295112",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11252/"
] |
295,114 | <p>Ok, I'm getting my version control processes in order for my web team.</p>
<p>I know ideally each user would have a full working copy of their code on their local machine.</p>
<p>Unfortunately for a lot of our web apps they have additional server specific DB or other system integration requirements that cannot be replicated on a user's workstation (i.e. some servers just wont install on XP, vista etc.)</p>
<p>I'm looking at setting up an area on one of my servers that acts as a working copy for each user but still resides on the network.</p>
<p>i.e.</p>
<pre><code>/SVRROOT/
- Dev1 Working Copy
- Dev2 Working Copy
- Dev3 Working Copy
</code></pre>
<p>This means that each user will have their own working space (as per SVN best practices) but it will reside on the network. </p>
<p>Does anyone see a problem with this model?</p>
| [
{
"answer_id": 55263128,
"author": "Cornelius Sicker",
"author_id": 2471067,
"author_profile": "https://Stackoverflow.com/users/2471067",
"pm_score": 0,
"selected": false,
"text": "TortoiseSVN"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22837/"
] |
295,120 | <p>I have a method in an interface that I want to deprecate with portable C++.
When I Googled for this all I got was a Microsoft specific solution; <a href="https://learn.microsoft.com/en-us/cpp/preprocessor/deprecated-c-cpp?view=vs-2017" rel="noreferrer"><code>#pragma deprecated</code></a> and <a href="https://learn.microsoft.com/en-us/cpp/cpp/deprecated-cpp?view=vs-2017" rel="noreferrer"><code>__declspec(deprecated)</code></a>.</p>
<p>A second prize solution would be to <code>ifdef</code> a MSVC and a GCC solution.</p>
| [
{
"answer_id": 295149,
"author": "Terje Mikal",
"author_id": 37570,
"author_profile": "https://Stackoverflow.com/users/37570",
"pm_score": 5,
"selected": false,
"text": "void myfunc() __attribute__ ((deprecated));\n"
},
{
"answer_id": 295229,
"author": "Michael Platings",
"author_id": 2651243,
"author_profile": "https://Stackoverflow.com/users/2651243",
"pm_score": 7,
"selected": false,
"text": "#ifdef __GNUC__\n#define DEPRECATED(func) func __attribute__ ((deprecated))\n#elif defined(_MSC_VER)\n#define DEPRECATED(func) __declspec(deprecated) func\n#else\n#pragma message(\"WARNING: You need to implement DEPRECATED for this compiler\")\n#define DEPRECATED(func) func\n#endif\n\n...\n\n//don't use me any more\nDEPRECATED(void OldFunc(int a, float b));\n\n//use me instead\nvoid NewFunc(int a, double b);\n std::pair<int, int>"
},
{
"answer_id": 21192071,
"author": "Joseph Mansfield",
"author_id": 150634,
"author_profile": "https://Stackoverflow.com/users/150634",
"pm_score": 9,
"selected": true,
"text": "[[deprecated]] deprecated foo [[deprecated]]\nvoid foo(int);\n [[deprecated(\"Replaced by bar, which has an improved interface\")]]\nvoid foo(int);\n"
},
{
"answer_id": 21265197,
"author": "Michael Platings",
"author_id": 2651243,
"author_profile": "https://Stackoverflow.com/users/2651243",
"pm_score": 6,
"selected": false,
"text": "#if defined(__GNUC__) || defined(__clang__)\n#define DEPRECATED __attribute__((deprecated))\n#elif defined(_MSC_VER)\n#define DEPRECATED __declspec(deprecated)\n#else\n#pragma message(\"WARNING: You need to implement DEPRECATED for this compiler\")\n#define DEPRECATED\n#endif\n\n//...\n\n//don't use me any more\nDEPRECATED void OldFunc(int a, float b);\n\n//use me instead\nvoid NewFunc(int a, double b);\n __declspec(deprecated) __attribute__((deprecated)) __attribute__((deprecated))"
},
{
"answer_id": 49037913,
"author": "nemequ",
"author_id": 501126,
"author_profile": "https://Stackoverflow.com/users/501126",
"pm_score": 4,
"selected": false,
"text": "[[deprecated]] [[deprecated(message)]] __attribute__((deprecated)) __attribute__((deprecated)) __attribute__((deprecated(message))) __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ __GNUC__ __GNUC_MINOR__ __declspec(deprecated) __declspec(deprecated(message)) [[gnu::deprecated]] __has_cpp_attribute(gnu::deprecated) #if defined(__cplusplus) && (__cplusplus >= 201402L)\n# define HEDLEY_DEPRECATED(since) [[deprecated(\"Since \" #since)]]\n# define HEDLEY_DEPRECATED_FOR(since, replacement) [[deprecated(\"Since \" #since \"; use \" #replacement)]]\n#elif \\\n HEDLEY_GCC_HAS_EXTENSION(attribute_deprecated_with_message,4,5,0) || \\\n HEDLEY_INTEL_VERSION_CHECK(16,0,0) || \\\n HEDLEY_ARM_VERSION_CHECK(5,6,0)\n# define HEDLEY_DEPRECATED(since) __attribute__((__deprecated__(\"Since \" #since)))\n# define HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__(\"Since \" #since \"; use \" #replacement)))\n#elif \\\n HEDLEY_GCC_HAS_ATTRIBUTE(deprcated,4,0,0) || \\\n HEDLEY_ARM_VERSION_CHECK(4,1,0)\n# define HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))\n# define HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))\n#elif HEDLEY_MSVC_VERSION_CHECK(14,0,0)\n# define HEDLEY_DEPRECATED(since) __declspec(deprecated(\"Since \" # since))\n# define HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated(\"Since \" #since \"; use \" #replacement))\n#elif HEDLEY_MSVC_VERSION_CHECK(13,10,0)\n# define HEDLEY_DEPRECATED(since) _declspec(deprecated)\n# define HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)\n#else\n# define HEDLEY_DEPRECATED(since)\n# define HEDLEY_DEPRECATED_FOR(since, replacement)\n#endif\n *_VERSION_CHECK *_HAS_ATTRIBUTE G_DEPRECATED G_DEPRECATED_FOR"
},
{
"answer_id": 57680802,
"author": "Contango",
"author_id": 107409,
"author_profile": "https://Stackoverflow.com/users/107409",
"pm_score": 1,
"selected": false,
"text": "__INTEL_COMPILER 1900 # if defined(__INTEL_COMPILER)\n# define DEPRECATED [[deprecated]]\n# endif\n [[deprecated]]"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295120",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8524/"
] |
295,123 | <p>I need to write a temporary Web-based graphical front-end for a custom server system. In this case performance and scalability aren't issues, since at most 10 people may check the system simultaneously. Also it should be PHP or Python (server) & JavaScript (client) (can't use Flex or Silverlight for very specific non-programming related issues).</p>
<p>So I know I could use YUI or jQuery, but was wondering if there is something even more high-level that would say allow me to write such a little project within a few hours of work, and get done with it. Basically I want to be as lazy as possible (this is throw-away code anyways) and get the job done in as little time as possible.</p>
<p>Any suggestions?</p>
| [
{
"answer_id": 41054529,
"author": "AxleWack",
"author_id": 2298585,
"author_profile": "https://Stackoverflow.com/users/2298585",
"pm_score": 0,
"selected": false,
"text": "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>jQuery UI Droppable - Default functionality</title>\n<link rel=\"stylesheet\" href=\"//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css\">\n<link rel=\"stylesheet\" href=\"/resources/demos/style.css\">\n<style>\n ul.listRoles {\n width: 300px;\n height: auto;\n padding: 5px;\n margin: 5px;\n list-style-type: none;\n border-radius: 5px;\n min-height: 70px;\n }\n\n ul.listRoles li {\n padding: 5px;\n margin: 10px;\n background-color: #ffff99;\n cursor: pointer;\n border: 1px solid Black;\n border-radius: 5px;\n }\n</style>\n<script src=\"https://code.jquery.com/jquery-1.12.4.js\"></script>\n<script src=\"https://code.jquery.com/ui/1.12.1/jquery-ui.js\"></script>\n<script>\n $(function () {\n $(\"#listDenyRoles, #listAllowRoles, #listAllowMoreRoles\").sortable({\n connectWith: \".listRoles\"\n }).disableSelection();\n });\n\n function submitNewRoles() {\n //Generate List of new allow roles\n var outputList = $(\"#listAllowRoles li\").map(function () { return $(this).html(); }).get().join(',');\n $(\"#GrantRoles\").val(outputList);\n $(\"#formAssignRoles\").submit();\n }\n</script>\n</head>\n<body>\n<div class=\"container body-content\">\n @RenderBody()\n <hr />\n <footer>\n <p>© @DateTime.Now.Year - My ASP.NET Application</p>\n </footer>\n </div>\n }\n</body>\n</html>\n @{\n ViewBag.Title = \"Home Page\";\n}\n\n<p>\n To GRANT a user a role, click and drag a role from the left Red box to the right Green box.<br />\n To DENY a user a role, click and drag a role from the right Green box to the left Red box.\n</p>\n\n@using (Html.BeginForm(\"AssignRoles\", \"UserAdmin\", FormMethod.Post, new { id = \"formAssignRoles\" }))\n{\n\n String[] AllRoles = ViewBag.AllRoles;\n String[] AllowRoles = ViewBag.AllowRoles;\n\n if (AllRoles == null) { AllRoles = new String[] { \"Test1\",\"Test2\",\"Test3\",\"Test4\", \"Test5\", \"Test6\", \"Test7\", \"Test8\", \"Test9\", \"Test10\", \"Test11\", \"Test12\", \"Test13\" }; }\n if (AllowRoles == null) { AllowRoles = new String[] { }; }\n\n @Html.ValidationSummary(true)\n <div class=\"jumbotron\">\n <fieldset>\n <legend>Drag and Drop Roles as required;</legend>\n @Html.Hidden(\"Username\", \"Username\")\n @Html.Hidden(\"GrantRoles\", \"\")\n\n <table>\n <tr>\n <th style=\"text-align: center\">\n Deny Roles\n </th>\n <th style=\"text-align: center\">\n Allow Roles\n </th>\n </tr>\n <tr>\n <td style=\"vertical-align: top\">\n <ul id=\"listDenyRoles\" class=\"listRoles\" style=\"background-color: #cc0000;\">\n @foreach (String role in AllRoles)\n {\n if (!AllowRoles.Contains(role))\n {\n\n <li>@role</li>\n }\n }\n </ul>\n </td>\n <td style=\"vertical-align: top\">\n\n <ul id=\"listAllowRoles\" class=\"listRoles\" style=\"background-color: #00cc00;\">\n @foreach (String hasRole in AllowRoles)\n {\n <li>@hasRole</li>\n }\n </ul>\n </td>\n <td style=\"vertical-align: top\">\n\n <ul id=\"listAllowMoreRoles\" class=\"listRoles\" style=\"background-color: #000000;\">\n @foreach (String hasRole in AllowRoles)\n {\n <li>@hasRole</li>\n }\n </ul>\n </td>\n </tr>\n </table>\n <p><input type=\"button\" onClick=\"submitNewRoles()\" value=\"Assign Roles\" /></p>\n </fieldset>\n\n\n </div>\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15124/"
] |
295,128 | <p>I have an app which consists of several different assemblies, one of which holds the various interfaces which the classes obey, and by which the classes communicate across assembly boundaries. There are several classes firing events, and several which are interested in these events. </p>
<p>My question is as follows: is it good practice to implement a central EventConsolidator of some kind? This would be highly coupled, as it would need to know every class (or at least interface) throwing an event, and every consumer of an event would need to have a reference to EventConsolidator in order to subscribe. </p>
<p>Currently I have the situation where class A knows class B (but not C), class B knows class C, etc. Then if C fires an event B needs to pick it up and fire its own event in order for A to respond. These kinds of chains can get quite long, and it may be that B is only interested in the event in order to pass it along. I don't want A to know about C though, as that would break encapsulation. </p>
<p>What is good practice in this situation? Centralise the events, or grin and bear it and define events in each intermediate class? Or what are the criteria by which to make the decision? Thanks!</p>
<p>Edit: <a href="https://stackoverflow.com/questions/217233/bubbling-up-events">Here</a> is another question asking essentially the same thing.</p>
| [
{
"answer_id": 295145,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "public event FooHandler Foo\n{\n add\n {\n c.Foo += value;\n }\n remove\n {\n c.Foo -= value;\n }\n}\n"
},
{
"answer_id": 295171,
"author": "Jonathan C Dickinson",
"author_id": 24064,
"author_profile": "https://Stackoverflow.com/users/24064",
"pm_score": 3,
"selected": false,
"text": "[Publish(\"foo://happened\")]\npublic event EventHandler<FooArgs> FooHappened;\n\n[Subscribe(\"foo://happened\")]\npublic void Foo_Happened(object sender, FooArgs args)\n{ }\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6091/"
] |
295,135 | <p>I have a string that I want to use as a filename, so I want to remove all characters that wouldn't be allowed in filenames, using Python.</p>
<p>I'd rather be strict than otherwise, so let's say I want to retain only letters, digits, and a small set of other characters like <code>"_-.() "</code>. What's the most elegant solution?</p>
<p>The filename needs to be valid on multiple operating systems (Windows, Linux and Mac OS) - it's an MP3 file in my library with the song title as the filename, and is shared and backed up between 3 machines.</p>
| [
{
"answer_id": 295146,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 7,
"selected": false,
"text": ">>> import string\n>>> valid_chars = \"-_.() %s%s\" % (string.ascii_letters, string.digits)\n>>> valid_chars\n'-_.() abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'\n>>> filename = \"This Is a (valid) - filename%$&$ .txt\"\n>>> ''.join(c for c in filename if c in valid_chars)\n'This Is a (valid) - filename .txt'\n"
},
{
"answer_id": 295147,
"author": "gx.",
"author_id": 21580,
"author_profile": "https://Stackoverflow.com/users/21580",
"pm_score": 3,
"selected": false,
"text": "import re\n\nstr = \"File!name?.txt\"\nf = open(os.path.join(\"/tmp\", re.sub('[^-a-zA-Z0-9_.() ]+', '', str))\n"
},
{
"answer_id": 295150,
"author": "Igal Serban",
"author_id": 25737,
"author_profile": "https://Stackoverflow.com/users/25737",
"pm_score": 7,
"selected": false,
"text": "import base64\nfile_name_string = base64.urlsafe_b64encode(your_string)\n"
},
{
"answer_id": 295152,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 7,
"selected": false,
"text": ">>> s\n'foo-bar#baz?qux@127/\\\\9]'\n>>> \"\".join(x for x in s if x.isalnum())\n'foobarbazqux1279'\n"
},
{
"answer_id": 295242,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 3,
"selected": false,
"text": ">>> import string\n>>> safechars = bytearray(('_-.()' + string.digits + string.ascii_letters).encode())\n>>> allchars = bytearray(range(0x100))\n>>> deletechars = bytearray(set(allchars) - set(safechars))\n>>> filename = u'#ab\\xa0c.$%.txt'\n>>> safe_filename = filename.encode('ascii', 'ignore').translate(None, deletechars).decode()\n>>> safe_filename\n'abc..txt'\n"
},
{
"answer_id": 295466,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 9,
"selected": true,
"text": "slugify() import unicodedata\nimport re\n\ndef slugify(value, allow_unicode=False):\n \"\"\"\n Taken from https://github.com/django/django/blob/master/django/utils/text.py\n Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated\n dashes to single dashes. Remove characters that aren't alphanumerics,\n underscores, or hyphens. Convert to lowercase. Also strip leading and\n trailing whitespace, dashes, and underscores.\n \"\"\"\n value = str(value)\n if allow_unicode:\n value = unicodedata.normalize('NFKC', value)\n else:\n value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')\n value = re.sub(r'[^\\w\\s-]', '', value.lower())\n return re.sub(r'[-\\s]+', '-', value).strip('-_')\n def slugify(value):\n \"\"\"\n Normalizes string, converts to lowercase, removes non-alpha characters,\n and converts spaces to hyphens.\n \"\"\"\n import unicodedata\n value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')\n value = unicode(re.sub('[^\\w\\s-]', '', value).strip().lower())\n value = unicode(re.sub('[-\\s]+', '-', value))\n # ...\n return value\n"
},
{
"answer_id": 295560,
"author": "bobince",
"author_id": 18936,
"author_profile": "https://Stackoverflow.com/users/18936",
"pm_score": 3,
"selected": false,
"text": "import re\nbadchars= re.compile(r'[^A-Za-z0-9_. ]+|^\\.|\\.$|^ | $|^$')\nbadnames= re.compile(r'(aux|com[1-9]|con|lpt[1-9]|prn)(\\.|$)')\n\ndef makeName(s):\n name= badchars.sub('_', s)\n if badnames.match(name):\n name= '_'+name\n return name\n"
},
{
"answer_id": 698714,
"author": "Sophie Gage",
"author_id": 37134,
"author_profile": "https://Stackoverflow.com/users/37134",
"pm_score": 4,
"selected": false,
"text": "import unicodedata\n\nvalidFilenameChars = \"-_.() %s%s\" % (string.ascii_letters, string.digits)\n\ndef removeDisallowedFilenameChars(filename):\n cleanedFilename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore')\n return ''.join(c for c in cleanedFilename if c in validFilenameChars)\n"
},
{
"answer_id": 1108783,
"author": "wires",
"author_id": 72787,
"author_profile": "https://Stackoverflow.com/users/72787",
"pm_score": 0,
"selected": false,
"text": "base64 import re\nt = re.compile(\"[a-zA-Z0-9.,_-]\")\nunsafe = \"abc∂éåß®∆˚˙©¬ñ√ƒµ©∆∫ø\"\nsafe = [ch for ch in unsafe if t.match(ch)]\n# => 'abc'\n base64 from random import choice\nfrom string import ascii_lowercase, ascii_uppercase, digits\nallowed_chr = ascii_lowercase + ascii_uppercase + digits\n\nsafe = ''.join([choice(allowed_chr) for _ in range(16)])\n# => 'CYQ4JDKE9JfcRzAZ'\n bobcat base64"
},
{
"answer_id": 10458710,
"author": "TankorSmash",
"author_id": 541208,
"author_profile": "https://Stackoverflow.com/users/541208",
"pm_score": 0,
"selected": false,
"text": "import string\nfor chr in your_string:\n if chr == ' ':\n your_string = your_string.replace(' ', '_')\n elif chr not in string.ascii_letters or chr not in string.digits:\n your_string = your_string.replace(chr, '')\n"
},
{
"answer_id": 10610768,
"author": "Rusty Rob",
"author_id": 632088,
"author_profile": "https://Stackoverflow.com/users/632088",
"pm_score": 1,
"selected": false,
"text": "{'helloworld': \n (\n {'/hello/world': 'helloworld', '/helloworld/': 'helloworld1'},\n 2)\n }\n"
},
{
"answer_id": 25808207,
"author": "makeroo",
"author_id": 907720,
"author_profile": "https://Stackoverflow.com/users/907720",
"pm_score": 2,
"selected": false,
"text": "# p3 code\ndef safePath (url):\n return ''.join(map(lambda ch: chr(ch) if ch in safePath.chars else '%%%02x' % ch, url.encode('utf-8')))\nsafePath.chars = set(map(lambda x: ord(x), '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-_ .'))\n"
},
{
"answer_id": 29942164,
"author": "Shoham",
"author_id": 1297578,
"author_profile": "https://Stackoverflow.com/users/1297578",
"pm_score": 6,
"selected": false,
"text": "pip install python-slugify\n >>> from slugify import slugify\n>>> txt = \"This\\ is/ a%#$ test ---\"\n>>> slugify(txt)\n'this-is-a-test'\n"
},
{
"answer_id": 38766141,
"author": "mnach",
"author_id": 3282927,
"author_profile": "https://Stackoverflow.com/users/3282927",
"pm_score": 4,
"selected": false,
"text": "valid_file_name = re.sub('[^\\w_.)( -]', '', any_string)\n"
},
{
"answer_id": 46590727,
"author": "therealmarv",
"author_id": 756056,
"author_profile": "https://Stackoverflow.com/users/756056",
"pm_score": 3,
"selected": false,
"text": "pip install python-slugify\n s = 'Very / Unsafe / file\\nname hähä \\n\\r .txt'\nclean_basename = slugify(os.path.splitext(s)[0])\nclean_extension = slugify(os.path.splitext(s)[1][1:])\nif clean_extension:\n clean_filename = '{}.{}'.format(clean_basename, clean_extension)\nelif clean_basename:\n clean_filename = clean_basename\nelse:\n clean_filename = 'none' # only unclean characters\n >>> clean_filename\n'very-unsafe-file-name-haha.txt'\n none"
},
{
"answer_id": 46801075,
"author": "cowlinator",
"author_id": 1698736,
"author_profile": "https://Stackoverflow.com/users/1698736",
"pm_score": 5,
"selected": false,
"text": "def get_valid_filename(s):\n s = str(s).strip().replace(' ', '_')\n return re.sub(r'(?u)[^-\\w.]', '', s)\n"
},
{
"answer_id": 55101759,
"author": "Tuncay Göncüoğlu",
"author_id": 1372570,
"author_profile": "https://Stackoverflow.com/users/1372570",
"pm_score": 3,
"selected": false,
"text": "def normalizefilename(fn):\n validchars = \"-_.() \"\n out = \"\"\n for c in fn:\n if str.isalpha(c) or str.isdigit(c) or (c in validchars):\n out += c\n else:\n out += \"_\"\n return out \n validchars if"
},
{
"answer_id": 55789246,
"author": "Jean-Robin Tremblay",
"author_id": 4720978,
"author_profile": "https://Stackoverflow.com/users/4720978",
"pm_score": 2,
"selected": false,
"text": "import string\nimport unicodedata\n\nvalidFilenameChars = \"-_.() %s%s\" % (string.ascii_letters, string.digits)\ndef removeDisallowedFilenameChars(filename):\n cleanedFilename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore')\n return ''.join(chr(c) for c in cleanedFilename if chr(c) in validFilenameChars)\n"
},
{
"answer_id": 60856137,
"author": "Stavros",
"author_id": 2309247,
"author_profile": "https://Stackoverflow.com/users/2309247",
"pm_score": 3,
"selected": false,
"text": "from pathvalidate import sanitize_filename\n\nfname = \"fi:l*e/p\\\"a?t>h|.t<xt\"\nprint(f\"{fname} -> {sanitize_filename(fname)}\\n\")\nfname = \"\\0_a*b:c<d>e%f/(g)h+i_0.txt\"\nprint(f\"{fname} -> {sanitize_filename(fname)}\\n\")\n fi:l*e/p\"a?t>h|.t<xt -> filepath.txt\n_a*b:c<d>e%f/(g)h+i_0.txt -> _abcde%f(g)h+i_0.txt\n"
},
{
"answer_id": 65360401,
"author": "ChaimG",
"author_id": 2529619,
"author_profile": "https://Stackoverflow.com/users/2529619",
"pm_score": 0,
"selected": false,
"text": "def txt2filename(txt, chr_set='normal'):\n \"\"\"Converts txt to a valid Windows/*nix filename with printable characters only.\n\n args:\n txt: The str to convert.\n chr_set: 'normal', 'universal', or 'inclusive'.\n 'universal': ' -.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'\n 'normal': Every printable character exept those disallowed on Windows/*nix.\n 'extended': All 'normal' characters plus the extended character ASCII codes 128-255\n \"\"\"\n\n FILLER = '-'\n\n # Step 1: Remove excluded characters.\n if chr_set == 'universal':\n # Lookups in a set are O(n) vs O(n * x) for a str.\n printables = set(' -.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')\n else:\n if chr_set == 'normal':\n max_chr = 127\n elif chr_set == 'extended':\n max_chr = 256\n else:\n raise ValueError(f'The chr_set argument may be normal, extended or universal; not {chr_set=}')\n EXCLUDED_CHRS = set(r'<>:\"/\\|?*') # Illegal characters in Windows filenames.\n EXCLUDED_CHRS.update(chr(127)) # DEL (non-printable).\n printables = set(chr(x)\n for x in range(32, max_chr)\n if chr(x) not in EXCLUDED_CHRS)\n result = ''.join(x if x in printables else FILLER # Allow printable characters only.\n for x in txt)\n\n # Step 2: Device names, '.', and '..' are invalid filenames in Windows.\n DEVICE_NAMES = 'CON,PRN,AUX,NUL,COM1,COM2,COM3,COM4,' \\\n 'COM5,COM6,COM7,COM8,COM9,LPT1,LPT2,' \\\n 'LPT3,LPT4,LPT5,LPT6,LPT7,LPT8,LPT9,' \\\n 'CONIN$,CONOUT$,..,.'.split() # This list is an O(n) operation.\n if result in DEVICE_NAMES:\n result = f'-{result}-'\n\n # Step 3: Maximum length of filename is 255 bytes in Windows and Linux (other *nix flavors may allow longer names).\n result = result[:255]\n\n # Step 4: Windows does not allow filenames to end with '.' or ' ' or begin with ' '.\n result = re.sub(r'^[. ]', FILLER, result)\n result = re.sub(r' $', FILLER, result)\n\n return result\n"
},
{
"answer_id": 66813197,
"author": "Alex",
"author_id": 15484549,
"author_profile": "https://Stackoverflow.com/users/15484549",
"pm_score": 2,
"selected": false,
"text": "regex_pattern > filename = \"This is a väryì' Strange File-Nömé.jpeg\"\n> pattern = re.compile(r'[^-a-zA-Z0-9.]+')\n> slugify(filename,regex_pattern=pattern) \n'this-is-a-varyi-strange-file-nome.jpeg'\n ALLOWED_CHARS_PATTERN_WITH_UPPERCASE slugify.py .() \\ lowercase=False > filename = \"This is a väryì' Strange File-Nömé.jpeg\"\n> pattern = re.compile(r'[^-a-zA-Z0-9.]+')\n> slugify(filename,regex_pattern=pattern, lowercase=False) \n'This-is-a-varyi-Strange-File-Nome.jpeg'\n"
},
{
"answer_id": 68083584,
"author": "RexBarker",
"author_id": 2800701,
"author_profile": "https://Stackoverflow.com/users/2800701",
"pm_score": 1,
"selected": false,
"text": "import re\n\ndef check_for_illegal_char(input_str):\n # remove illegal characters for Windows file names/paths \n # (illegal filenames are a superset (41) of the illegal path names (36))\n # this is according to windows blacklist obtained with Powershell\n # from: https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names/44750843#44750843\n #\n # PS> $enc = [system.Text.Encoding]::UTF8\n # PS> $FileNameInvalidChars = [System.IO.Path]::GetInvalidFileNameChars()\n # PS> $FileNameInvalidChars | foreach { $enc.GetBytes($_) } | Out-File -FilePath InvalidFileCharCodes.txt\n\n illegal = '\\u0022\\u003c\\u003e\\u007c\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008' + \\\n '\\u0009\\u000a\\u000b\\u000c\\u000d\\u000e\\u000f\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015' + \\\n '\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f\\u003a\\u002a\\u003f\\u005c\\u002f' \n\n output_str, _ = re.subn('['+illegal+']','_', input_str)\n output_str = output_str.replace('\\\\','_') # backslash cannot be handled by regex\n output_str = output_str.replace('..','_') # double dots are illegal too, or at least a bad idea \n output_str = output_str[:-1] if output_str[-1] == '.' else output_str # can't have end of line '.'\n\n if output_str != input_str:\n print(f\"The name '{input_str}' had invalid characters, \"\n f\"name was modified to '{output_str}'\")\n\n return output_str\n check_for_illegal_char('fas\\u0003\\u0004good\\\\..asd.') The name 'fas♥♦good\\..asd.' had invalid characters, name was modified to 'fas__good__asd'\n"
},
{
"answer_id": 74645904,
"author": "VengaVenga",
"author_id": 4798335,
"author_profile": "https://Stackoverflow.com/users/4798335",
"pm_score": 0,
"selected": false,
"text": "# util/files.py\n\nCHAR_MAX_LEN = 31\nCHAR_REPLACE = '_'\n\nILLEGAL_CHARS = [\n '#', # pound\n '%', # percent\n '&', # ampersand\n '{', # left curly bracket\n '}', # right curly bracket\n '\\\\', # back slash\n '<', # left angle bracket\n '>', # right angle bracket\n '*', # asterisk\n '?', # question mark\n '/', # forward slash\n ' ', # blank spaces\n '$', # dollar sign\n '!', # exclamation point\n \"'\", # single quotes\n '\"', # double quotes\n ':', # colon\n '@', # at sign\n '+', # plus sign\n '`', # backtick\n '|', # pipe\n '=', # equal sign\n]\n\n\ndef generate_filename(\n name, char_replace=CHAR_REPLACE, length=CHAR_MAX_LEN, \n illegal=ILLEGAL_CHARS, replace_dot=False):\n ''' return clean filename '''\n # init\n _elem = name.split('.')\n extension = _elem[-1].strip()\n _length = length - len(extension) - 1\n label = '.'.join(_elem[:-1]).strip()[:_length]\n filename = ''\n \n # replace '.' ?\n if replace_dot:\n label = label.replace('.', char_replace)\n \n # clean\n for char in label + '.' + extension:\n if char in illegal:\n char = char_replace\n filename += char \n \n return filename\n\n generate_filename('nucgae zutaäer..0.1.docx', replace_dot=False) generate_filename('nucgae zutaäer..0.1.docx', replace_dot=True)"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37134/"
] |
295,141 | <p>I have a List of custom object, which consist of a custom list.</p>
<pre><code>class person{
string name;
int age;
List<friend> allMyFriends;
}
class friend{
string name;
string address;
}
</code></pre>
<p>I'trying to bind a list of these objects to a GridView and the Grid should create for each friend a column and write the name in it. If some people have the same frined the grid shouldn't create a seperate column, but use the existing one. You know what I mean.
(The classes are just some sample classes to simplify my case)</p>
<p>Is there a way to dynamically customize the binding?</p>
<p>I can change the class definitions and so on, if they need to inherit from some interfaces or so on.</p>
<p>I googled a lot, but no example really seemed to cover this case.</p>
<p>Could the use of a objectSourceControl solve my problem in some way?</p>
<h3>Update:</h3>
<p>To give some more information:
In the end I have a list of persons, while each person in the list has a list of friends.</p>
<pre><code>List<person> allPerson = new List<person>();
// fill the list
Grid.DataSource = allPerson;
Grid.DataBind()
</code></pre>
<p>The table should have columns for each friend and the rows are the person. Where a person has a friend a cross (or whatever) needs to be placed in the grid.</p>
<pre><code>friend1 friend2
x peter
x x adam
</code></pre>
<p>At the moment a intercept the RowDataBound event and since the binding only creates the rows with the names and not the columns, because the only property on my person object is the name. Is there a way to force the binding to look through the List Property in the person objects and create a column for each of them.</p>
| [
{
"answer_id": 2059565,
"author": "Chris Porter",
"author_id": 13495,
"author_profile": "https://Stackoverflow.com/users/13495",
"pm_score": 3,
"selected": true,
"text": "public partial class _Default : System.Web.UI.Page\n{\n protected void Page_Load(object sender, EventArgs e)\n {\n // setup your person object with static data for testing\n List<person> allPerson = new List<person>()\n {\n new person() \n { \n name = \"Dan\", \n age = 21, \n allMyFriends = new List<friend>() { new friend(\"James\"), new friend(\"John\"), new friend(\"Matt\") } \n }, \n new person() \n { \n name = \"James\", \n age = 21, \n allMyFriends = new List<friend>() { new friend(\"Dan\"), new friend(\"Matt\"), new friend(\"Tom\") } \n }, \n new person() \n { \n name = \"John\", \n age = 21, \n allMyFriends = new List<friend>() { new friend(\"Dan\") } \n }, \n new person() \n { \n name = \"Matt\", \n age = 21, \n allMyFriends = new List<friend>() { new friend(\"Dan\"), new friend(\"James\") } \n }, \n new person() \n { \n name = \"Tom\", \n age = 21, \n allMyFriends = new List<friend>() { new friend(\"James\") } \n }\n };\n\n System.Data.DataTable dt = new System.Data.DataTable();\n dt.Columns.Add(\"Name\");\n dt.Columns.Add(\"Age\");\n\n foreach (person p in allPerson)\n {\n // step through each person and look at their friends\n foreach (friend f in p.allMyFriends)\n {\n // look to see if this friend has a column already\n if (!dt.Columns.Contains(f.name))\n {\n dt.Columns.Add(f.name);\n }\n }\n }\n\n foreach (person p in allPerson)\n {\n // create the datarow that represents the person\n System.Data.DataRow dr = dt.NewRow();\n dr[\"Name\"] = p.name;\n dr[\"Age\"] = p.age;\n\n // find the friends and mark them\n foreach (friend f in p.allMyFriends)\n {\n dr[f.name] = \"X\";\n }\n\n dt.Rows.Add(dr);\n }\n\n // fill the list\n this.Grid.DataSource = dt;\n this.Grid.DataBind();\n\n }\n}\n\npublic class person\n{\n public string name;\n public int age;\n public List<friend> allMyFriends = new List<friend>();\n}\n\npublic class friend\n{\n public string name;\n public string address;\n\n public friend()\n {\n\n }\n\n public friend(string name)\n {\n this.name = name;\n }\n\n public friend(string name, string address)\n {\n this.name = name;\n this.address = address;\n }\n}\n -------------------------------------------------\n| Name | Age | James | John | Matt | Dan | Tom |\n-------------------------------------------------\n| Dan | 21 | X | X | X | | |\n| James | 21 | | | X | X | X |\n| John | 21 | | | | X | |\n| Matt | 21 | X | | | X | |\n| Tom | 21 | X | | | | |\n------------------------------------------------- \n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36475/"
] |
295,161 | <p>If you try to launch a .NET 3.5 application on a Windows computer which does not have this version of the .NET framework installed, you get a <code>FileNotFoundException</code> for some system assemblies (for example System.Core 3.5.0.0).</p>
<p>Is it possible to catch this exception and tell the user to upgrade their .NET framework or is it thrown too early to handle it?</p>
| [
{
"answer_id": 295168,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "System.Core.dll"
},
{
"answer_id": 295173,
"author": "David Wengier",
"author_id": 489,
"author_profile": "https://Stackoverflow.com/users/489",
"pm_score": 2,
"selected": false,
"text": "try\n{\n Application.Run(new MainForm());\n}\ncatch (Exception ex)\n{ \n if (ex.MessageContains(\"Could not load file or assembly 'System.Core, Version=3.5.0.0\"))\n {\n MessageBox.Show(\"This product requires the Microsoft .NET Framework version 3.5, or greater, in order to run.\\n\\nPlease contact your System Administrator for more information.\");\n }\n}\n"
},
{
"answer_id": 295203,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 3,
"selected": true,
"text": "// [STAThread] here if winform\n[MethodImpl(MethodImplOptions.NoInlining)]\nstatic void Main() {\n try {\n MainCore();\n } catch (SomeException ex) {\n // TODO something simple but fun\n }\n}\n\nstatic void MainCore() { ... } // your app here...\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11963/"
] |
295,163 | <p>I have a program that is running a basic RMISecurityManager in all its threads. But I would like to do more control to several threads and set another SecurityManager specially for these threads.</p>
<p>How can I do that ? ...if this is possible !?</p>
<p>thank you by advance.</p>
<p>Edit : I have found my solution. <a href="https://stackoverflow.com/questions/290545/how-to-automatically-copy-data-to-new-rmi-threads#298148">See here</a> for more details.</p>
| [
{
"answer_id": 295396,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 3,
"selected": true,
"text": "java.security.AccessController.getContext doPrivileged ThreadGroup Subject AccessControlContext"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295163",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26465/"
] |
295,165 | <p>I have some special cells in my Excel workbooks which are managed by my Excel Add-in. I want to prevent users from changing content of those cells, but I also want to know, what value users wanted to enter to those cells. On the SheetChange event I can check what users entered to my special cells, but how do I determine the PREVIOUS value in those cells and REVERT user changes?</p>
<hr>
<p>It is not a solution for me. If I lock cell in Excel, it becomes read-only - user can not even try to enter anything to this cell - Excel popups warning dialog in this case. My problem is that I want to catch what user entered to my cell, do something with this value, and then revert cell content to original value.</p>
| [
{
"answer_id": 295212,
"author": "Mike Woodhouse",
"author_id": 1060,
"author_profile": "https://Stackoverflow.com/users/1060",
"pm_score": 3,
"selected": true,
"text": "Option Explicit\n\n' We are monitoring cell B2...\n\nPrivate initialB2Value As Variant ' holds the value for reinstatement when the user changes it\n\nPrivate Sub Worksheet_Activate()\n' record the value before the user makes any changes.\n' Could be a constant value, or you could use .Formula to ensure a calculation is not lost\n initialB2Value = Range(\"B2\").Value\n\nEnd Sub\n\nPrivate Sub Worksheet_Change(ByVal Target As Range)\n\nStatic alreadyChanging As Boolean \n' when we reset the cell, Worksheet_Change will fire again, so we'll use a flag\n' to tell us if we should care or not...\n\n If alreadyChanging Then ' change is because of this code, no need to process\n alreadyChanging = False\n Exit Sub\n End If\n\n If IsEmpty(Intersect(Target, Range(\"B2\"))) Then\n ' If the change is not happening to the range we are monitoring, ignore it\n Exit Sub\n End If\n\n ' Do something with the user's input here\n Debug.Print \"User input \" & Range(\"B2\").Value & \" into B2\"\n\n ' before we reset the value, flag that we are changing the value in code\n alreadyChanging = True\n\n ' now apply the old value\n Range(\"B2\").Value = initialB2Value\n\nEnd Sub\n"
},
{
"answer_id": 295552,
"author": "Fionnuala",
"author_id": 2548,
"author_profile": "https://Stackoverflow.com/users/2548",
"pm_score": 2,
"selected": false,
"text": "Option Explicit\nDim LastText As String\n\nPrivate Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _\n ByVal Target As Excel.Range)\n LastText = Target.Value\nEnd Sub\n\nPrivate Sub Workbook_SheetChange(ByVal Sh As Object, _\n ByVal Source As Range)\n Debug.Print LastText; Source\nEnd Sub\n"
},
{
"answer_id": 1585339,
"author": "Ernesto",
"author_id": 192056,
"author_profile": "https://Stackoverflow.com/users/192056",
"pm_score": 1,
"selected": false,
"text": "Application.Undo"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37266/"
] |
295,169 | <p>A program written in Visual C/C++ 2005/2008 might not compile with another compiler such as GNU C/C++ or vice-versa. For example when trying to reuse code, which uses windows.h, written for a particular compiler with another, what are the differences to be aware of?</p>
<p>Is there any information about how to produce code which is compatible with either one compiler or another e.g. with either GC/C++ or MSVC/C++? What problems will attempting to do this cause?</p>
<p>What about other compilers, such as LCC and Digital Mars?</p>
| [
{
"answer_id": 296552,
"author": "Max Lybbert",
"author_id": 10593,
"author_profile": "https://Stackoverflow.com/users/10593",
"pm_score": 1,
"selected": false,
"text": "typename template template typename"
},
{
"answer_id": 298041,
"author": "MattyT",
"author_id": 7405,
"author_profile": "https://Stackoverflow.com/users/7405",
"pm_score": 3,
"selected": false,
"text": "#ifndef _WIN32\n typedef short INT16;\n typedef unsigned short UINT16;\n typedef int INT32;\n typedef unsigned int UINT32;\n typedef unsigned char UCHAR;\n typedef unsigned long long UINT64;\n typedef long long INT64;\n typedef unsigned char BYTE;\n typedef unsigned short WORD;\n typedef unsigned long DWORD;\n typedef void * HANDLE;\n typedef long LONG;\n#endif\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25093/"
] |
295,182 | <p>I have a producer-consumer pattern working for one product. What is the best implementation when the producer produce many products? For example a DataBaseEvent, GuiEvent and ControlEvent that the consumer shall consume. The code below shows the pattern for one product (a DataBaseEvent). Should each event type be enqueued on an own queue or should the events inherit a base class that can be enqueued. Maybe there exist a better pattern when working with many event types?</p>
<pre><code>class DataBaseEventArgs : EventArgs
{
public string textToDB = "";
}
class Consumer
{
private Producer mProducer = new Producer();
private Queue<DataBaseEventArgs> mDataBaseEventQueue = new Queue<DataBaseEventArgs>();
private static EventWaitHandle mDataBaseEventWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
private Thread mDataBaseEventDequeueThread = null;
public Consumer()
{
mDataBaseEventDequeueThread = new Thread(DataBaseDequeueEvent);
mDataBaseEventDequeueThread.Start();
mProducer.mDataBaseEventHandler += WhenDataBaseEvent;
}
protected void DataBaseDequeueEvent()
{
while (true)
{
DataBaseEventArgs e;
lock (((ICollection)mDataBaseEventQueue).SyncRoot)
{
if (mDataBaseEventQueue.Count > 0)
{
e = mDataBaseEventQueue.Dequeue();
}
}
// WriteToDatabase(e.textToDB);
if (mDataBaseEventQueue.Count == 0)
{
mDataBaseEventWaitHandle.WaitOne(1000);
mDataBaseEventWaitHandle.Reset();
}
}
}
internal void WhenDataBaseEvent(object sender, DataBaseEventArgs e)
{
lock (((ICollection)mDataBaseEventQueue).SyncRoot)
{
mDataBaseEventQueue.Enqueue(e);
mDataBaseEventWaitHandle.Set();
}
}
}
class Producer
{
public event EventHandler<DataBaseEventArgs> mDataBaseEventHandler = null;
public void SendDataBaseEvent()
{
if (mDataBaseEventHandler != null)
{
DataBaseEventArgs e = new DataBaseEventArgs();
e.textToDB = "This text will be written to DB";
mDataBaseEventHandler(this, e);
}
}
}
</code></pre>
| [
{
"answer_id": 295189,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "while(true) {\n T item;\n lock(lockObj) {\n if(queue.Count == 0) { // empty\n Monitor.Wait(lockObj);\n continue; // ensure there is genuinely something to do\n }\n item = queue.Dequeue();\n }\n // TODO: process item\n}\n...\nvoid Add(T item) {\n lock(lockObj) {\n queue.Enqueue(item);\n if(queue.Count == 1) { // first\n Monitor.PulseAll(lockObj);\n }\n }\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36922/"
] |
295,195 | <p>The problem is simple:</p>
<p>Using bash, I want to add a directory to my PYTHONPATH for ease of script execution. Unfortunately, the directory I want to use has a : in it. So I try each of the following</p>
<pre><code>export PYTHONPATH=${PYTHONPATH}:/home/shane/mywebsite.com:3344/
export PYTHONPATH=${PYTHONPATH}:/home/shane/mywebsite.com\:3344/
export PYTHONPATH=${PYTHONPATH}:"/home/shane/mywebsite.com:3344/"
</code></pre>
<p>None of these work. Every time, the path is created as two separate directories on the path in python.
My question is, is it possible to do this for bash?
If so, what's the syntax required?</p>
| [
{
"answer_id": 295226,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 2,
"selected": false,
"text": "export PYTHONPATH=${PYTHONPATH}:\"/home/shane/mywebsite.com\\:3344/\"\n $ echo \"foo:\" \nfoo:\n$ echo \\:foo\n:foo\n$ echo \":foo\"\n:foo\n$ echo \"\\:foo\"\n\\:foo\n"
},
{
"answer_id": 295233,
"author": "Terje Mikal",
"author_id": 37570,
"author_profile": "https://Stackoverflow.com/users/37570",
"pm_score": 1,
"selected": false,
"text": "ln -s /home/shane/mywebsite.com\\:3344 /home/shane/mywebsite.3344\nexport PYTHONPATH=${PYTHONPATH}:/home/shane/mywebsite.3344\n"
},
{
"answer_id": 295276,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 5,
"selected": true,
"text": ": PYTHONPATH PATH :"
},
{
"answer_id": 41597591,
"author": "nmgeek",
"author_id": 2950621,
"author_profile": "https://Stackoverflow.com/users/2950621",
"pm_score": 2,
"selected": false,
"text": "C:/Python27/lib $ export PYTHONPATH=\"C:\\MYPATH1;C:\\MYPATH2\"\n$ python -i\nPython 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import sys\n>>> sys.path\n['', 'C:\\\\MYPATH1', 'C:\\\\MYPATH2', 'C:\\\\Windows\\\\system32\\\\python27.zip', 'C:\\\\Python27\\\\DLLs', 'C:\\\\Python27\\\\lib', 'C:\\\\Python27\\\\lib\\\\plat-win', 'C:\\\\Python27\\\\lib\\\\lib-tk', 'C:\\\\Python27', 'C:\\\\Python27\\\\lib\\\\site-packages', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\win32', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\win32\\\\lib', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\Pythonwin']\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295195",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10264/"
] |
295,200 | <p><em>Short:</em> how does modelbinding pass objects from view to controller?</p>
<p><em>Long:</em><br>
First, based on the parameters given by the user through a search form, some objects are retrieved from the database.
These objects are given meta data that are visible(but not defining) to the customer (e.g: naming and pricing of the objects differ from region to region).<br>
Later on in the site, the user can click links that should show details of these objects.
Because these meta data are important for displaying, but not defining, I need to get the previously altered object back in the controller.
When I use the default asp.net mvc modelbinding, the .ToString() method is used. This off course doesn't return a relevant string for recreating the complete object.<br>
I would have figured the ISerializable interface would be involved, but this is not so.
How should I go about to get the desired effect? I can't imagine I'm the first one to be faced with this question, so I guess I'm missing something somewhere...</p>
| [
{
"answer_id": 295489,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": true,
"text": "<%= Html.ActionLink( ViewData[\"CustomObject1\",\n \"Select\",\n new { TempDataKey = ViewData[\"CustomObject1_Key\"] }\n ) %>\n \n\npublic ActionResult Select()\n{\n Entity custObj = null;\n string objKey = Request.Params[\"TempDataKey\"];\n if (!string.IsNullOrEmpty(objKey))\n {\n custObj = (Entity)TempData[objKey];\n }\n\n ... continue processing\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295200",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
295,224 | <p>I just want to clarify one thing. This is not a question on which one is better, that part I leave to someone else to discuss. I don't care about it.
I've been asked this question on my job interview and I thought it might be useful to learn a bit more.</p>
<p>These are the ones I could come up with:</p>
<ul>
<li>Java is "platform independent". Well nowadays you could say there is the <a href="http://en.wikipedia.org/wiki/Mono_%28software%29" rel="noreferrer">Mono</a> project so C# could be considered too but
I believe it is a bit exaggerating. Why? Well, when a new release of Java is done it is simultaneously available on all platforms it supports, on the other hand how many features of C# 3.0 are still missing in the Mono implementation? Or is it really <a href="http://en.wikipedia.org/wiki/Common_Language_Runtime" rel="noreferrer">CLR</a> vs. <a href="http://en.wikipedia.org/wiki/JRE" rel="noreferrer">JRE</a> that we should compare here?</li>
<li>Java doesn't support events and delegates. As far as I know.</li>
<li>In Java all methods are virtual</li>
<li>Development tools: I believe there isn't such a tool yet as Visual Studio. Especially if you've worked with team editions you'll know what I mean.</li>
</ul>
<p>Please add others you think are relevant.</p>
<p>Update:
Just popped up my mind, Java doesn't have something like custom attributes on classes, methods etc. Or does it?</p>
| [
{
"answer_id": 295241,
"author": "bruno conde",
"author_id": 31136,
"author_profile": "https://Stackoverflow.com/users/31136",
"pm_score": 3,
"selected": false,
"text": "Foo<T> Foo<Object>"
},
{
"answer_id": 295248,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 9,
"selected": true,
"text": "using List<byte> byte[] ref out"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2921654/"
] |
295,234 | <p>I'm currently maintaining some flex code and noticed very many functions which are declared like:</p>
<pre><code>private function exampleFunc():void {
....
}
</code></pre>
<p>These functions are in the <em>global scope</em>, and aren't part of any specific class, so it's a bit unclear to me what effect declaring them as private would have. What restrictions does the "private" qualifier have for functions like this?</p>
| [
{
"answer_id": 295573,
"author": "mmattax",
"author_id": 1638,
"author_profile": "https://Stackoverflow.com/users/1638",
"pm_score": 3,
"selected": true,
"text": "\n<!-- FooBox.mxml -->\n<mx:Box xmlns:mx=\"http://www.macromedia.com/2003/mxml\">\n <mx:Script><![CDATA[\n private function foo():void {\n lbl.text = \"foo\";\n }\n public function bar():void {\n lbl.text = \"bar\";\n }\n ]]></mx:Sctipt>\n <mx:Label id=\"lbl\">\n</mx:Box>\n\n \n<mx:Application\n xmlns:mx=\"http://www.macromedia.com/2003/mxml\"\n xmlns:cc=\"controls.*\"\n>\n <mx:Script><![CDATA[\n private function init():void {\n fbox.foo(); // opps, this function is unaccessible.\n fbox.bar(); // this is ok...\n }\n ]]></mx:Sctipt>\n <cc:FooBox id=\"fbox\" />\n</mx:Application>\n \nApplication.application.bar(); \n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295234",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14302/"
] |
295,235 | <p>Recently I was trying to make a calendar application that will display the current year-month-date to the user. The problem is, if the user is gonna keep my application running even for the next day, how do I get notified ?? How shall I change the date displayed ? I don't wanna poll the current date to update it. Is this possible in c#. </p>
<p>Note: I tried out the <strong>SystemEvent.TimeChanged</strong> event, but it works only if the user manually changes the time / date from the control panel.</p>
| [
{
"answer_id": 4097497,
"author": "Case",
"author_id": 497238,
"author_profile": "https://Stackoverflow.com/users/497238",
"pm_score": 3,
"selected": false,
"text": "public void Main()\n{\n\n var T = new System.Timers.Timer();\n\n T.Elapsed += CallBackFunction;\n\n var D = (DateTime.Today.AddDays(1).Date - DateTime.Now);\n\n T.Interval = D.TotalMilliseconds;\n\n T.Start();\n\n}\n\nprivate void CallBackFunction(object sender, System.Timers.ElapsedEventArgs e)\n{\n\n (sender as System.Timers.Timer).Interval = (DateTime.Today.AddDays(1).Date - DateTime.Now).TotalMilliseconds;\n\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295235",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
295,251 | <p>I have tried, 'PreviousPage', 'PreviousPage.IsCrossPagePostBack' 'Page.previousPage', page.title</p>
<p>It causes the client to stop rendering the page after this line.</p>
<p>simple example</p>
<pre><code>protected void Page_Load(object sender, EventArgs e)
{
response.write("I can see this");
string test = PreviousPage.IsCrossPagePostBack.toString(); //Any page call Causes client rendering to freeze
response.write("But i cant see this");
System.Windows.Forms.MessageBox.Show("However i can see this,proving that the server is still running the code");
}
</code></pre>
<p>Anybody Please, any ideas? </p>
| [
{
"answer_id": 295253,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "MessageBox"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
295,257 | <p>How can I search for specific value in the registry keys?</p>
<p>For example I want to search for XXX in </p>
<pre><code>HKEY_CLASSES_ROOT\Installer\Products
</code></pre>
<p>any code sample in C# will be appreciated,</p>
<p>thanks</p>
| [
{
"answer_id": 295265,
"author": "Galwegian",
"author_id": 3201,
"author_profile": "https://Stackoverflow.com/users/3201",
"pm_score": 4,
"selected": false,
"text": "tlbimp \"C:\\Program Files\\Log Parser 2.2\\LogParser.dll\"\n/out:Interop.MSUtil.dll\n using System;\nusing System.Runtime.InteropServices;\nusing LogQuery = Interop.MSUtil.LogQueryClass;\nusing RegistryInputFormat = Interop.MSUtil.COMRegistryInputContextClass;\nusing RegRecordSet = Interop.MSUtil.ILogRecordset;\n\nclass Program\n{\npublic static void Main()\n{\nRegRecordSet rs = null;\ntry\n{\nLogQuery qry = new LogQuery();\nRegistryInputFormat registryFormat = new RegistryInputFormat();\nstring query = @\"SELECT Path from \\HKLM\\SOFTWARE\\Microsoft where\nValue='VisualStudio'\";\nrs = qry.Execute(query, registryFormat);\nfor(; !rs.atEnd(); rs.moveNext())\nConsole.WriteLine(rs.getRecord().toNativeString(\",\"));\n}\nfinally\n{\nrs.close();\n}\n}\n}\n"
},
{
"answer_id": 295762,
"author": "Arnout",
"author_id": 3496,
"author_profile": "https://Stackoverflow.com/users/3496",
"pm_score": 4,
"selected": false,
"text": "Microsoft.Win32.RegistryKey OpenSubKey GetSubKeyNames GetValue"
},
{
"answer_id": 64029279,
"author": "Caltor",
"author_id": 470014,
"author_profile": "https://Stackoverflow.com/users/470014",
"pm_score": 2,
"selected": false,
"text": "private string SearchKey(string keyname, string data, string valueToFind, string returnValue)\n{\n RegistryKey uninstallKey = Registry.LocalMachine.OpenSubKey(keyname);\n var programs = uninstallKey.GetSubKeyNames();\n\n foreach (var program in programs)\n {\n RegistryKey subkey = uninstallKey.OpenSubKey(program);\n if (string.Equals(valueToFind, subkey.GetValue(data, string.Empty).ToString(), StringComparison.CurrentCulture))\n {\n return subkey.GetValue(returnValue).ToString();\n }\n }\n\n return string.Empty;\n}\n // This code will find the version of Chrome (32 bit) installed\nstring version = this.SearchKey(\"SOFTWARE\\\\WOW6432Node\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall\", \"DisplayName\", \"Google Chrome\", \"DisplayVersion\");\n"
},
{
"answer_id": 64307246,
"author": "Larry Aultman",
"author_id": 3482406,
"author_profile": "https://Stackoverflow.com/users/3482406",
"pm_score": 0,
"selected": false,
"text": "using Microsoft.Win32;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace WinReg\n{\n public class WinRegistryUserFind\n {\n // Windows 10 apparently places Office/Azure AAD in the registry at this location\n // each login gets a unique key in the registry that ends with the aadrm.com and the values\n // are held in a key named Identities and the value we want is the Email data item.\n const string regKeyPath = \"SOFTWARE\\\\Classes\\\\Local Settings\\\\Software\\\\Microsoft\\\\MSIPC\";\n const string matchOnEnd = \"aadrm.com\";\n const string matchKey = \"Identities\";\n const string matchData = \"Email\";\n\n public static List<string> GetAADuserFromRegistry()\n {\n var usersFound = new List<string>();\n RegistryKey regKey = Registry.CurrentUser.OpenSubKey(regKeyPath);\n var programs = regKey.GetSubKeyNames();\n foreach (var program in programs)\n {\n RegistryKey subkey = regKey.OpenSubKey(program);\n if(subkey.Name.EndsWith(matchOnEnd))\n {\n var value = (subkey.OpenSubKey(matchKey) != null)? (string)subkey.OpenSubKey(matchKey).GetValue(matchData): string.Empty;\n if (string.IsNullOrEmpty(value)) continue;\n if((from user in usersFound where user == value select user).FirstOrDefault() == null)\n usersFound.Add(value) ;\n }\n }\n\n return usersFound;\n }\n }\n}\n"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
295,266 | <p>I'm trying to wrap my head around how to search for something that appears in the middle of a word / expression - something like searching for "LIKE %book% " - but in SQL Server (2005) full text catalog.</p>
<p>How can I do that? It almost appears as if both <code>CONTAINS</code> and <code>FREETEXT</code> really don't support wildcard at the <strong>beginning</strong> of a search expression - can that really be?</p>
<p>I would have imagined that <code>FREETEXT(*, "book")</code> would find anything with "book" inside, including "rebooked" or something like that. </p>
| [
{
"answer_id": 295289,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 4,
"selected": false,
"text": "CONTAINS(*, '\"book*\"')\n"
},
{
"answer_id": 295297,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 3,
"selected": false,
"text": "LIKE '%book%'"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
295,279 | <p>I'm talking about this:</p>
<p>If we have the letter 'A' which is 77 in decimal and 4D in Hex.
I am looking for the fastest way to get D.</p>
<p>I thought about two ways:</p>
<p>Given x is a byte.</p>
<ol>
<li><p><code>x << 4; x >> 4</code></p></li>
<li><p><code>x %= 16</code></p></li>
</ol>
<p>Any other ways? Which one is faster?</p>
| [
{
"answer_id": 295286,
"author": "arul",
"author_id": 15409,
"author_profile": "https://Stackoverflow.com/users/15409",
"pm_score": 2,
"selected": false,
"text": "x = (x & 0x0F);\n"
},
{
"answer_id": 295288,
"author": "Terje Mikal",
"author_id": 37570,
"author_profile": "https://Stackoverflow.com/users/37570",
"pm_score": 6,
"selected": true,
"text": "x &= 0x0f"
},
{
"answer_id": 295350,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 5,
"selected": false,
"text": "x &= 0x0f x <<= 4; x >>= 4 -O1 x %= 16"
}
] | 2008/11/17 | [
"https://Stackoverflow.com/questions/295279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.