qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
261,580
|
<p>This declaration causes an overflow in VBA:</p>
<pre><code>Const OVERFLOWS As Long = 10 * 60 * 60
</code></pre>
<p>whereas setting the value directly is fine:</p>
<pre><code>Const COMPILES_OK As Long = 36000
</code></pre>
<p>How do you persuade VBA to treat literal integers as longs?</p>
<p>Thanks</p>
|
[
{
"answer_id": 261615,
"author": "xsl",
"author_id": 11387,
"author_profile": "https://Stackoverflow.com/users/11387",
"pm_score": 5,
"selected": true,
"text": "long & Const OVERFLOWS As Long = 10& * 60 * 60\n CLNG long"
},
{
"answer_id": 261680,
"author": "dbb",
"author_id": 25675,
"author_profile": "https://Stackoverflow.com/users/25675",
"pm_score": 2,
"selected": false,
"text": "Const OVERFLOWS As Long = CLNG(10) * 60 * 60\n Const OVERFLOWS As Single = CSNG(10) * 60 * 60\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1518/"
] |
261,591
|
<p>I'm currently writing a C# application that does a lot of digital signal processing, which involves a lot of small fine-tuned memory xfer operations. I wrote these routines using unsafe pointers and they seem to perform much better than I first thought. However, I want the app to be as fast as possible.</p>
<p>Would I get any performance benefit from rewriting these routines in C or C++ or should I stick to unsafe pointers? I'd like to know what unsafe pointers brings to the table in terms of performance, compared to C/C++.</p>
<p>EDIT: I'm not doing anything special inside these routines, just the normal DSP stuff: cache friendly data transfers from one array to the other with a lot of multiplications, additions, bit shiftings etc. in the way. I'd expect the C/C++ routines to look pretty much the same (if not identical) as their C# counterparts.</p>
<p>EDIT: Thanks a lot to everyone for all the clever answers. What I've learned is that I won't get any significant boost in performance just by doing a direct port, unless some sort of SSE optimization takes place. Assuming that all modern C/C++ compilers can take advantage of it I'm looking forward to give it a try. If someone is interested in the results just let me know and I'll post them somewhere. (May take a while though).</p>
|
[
{
"answer_id": 261819,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 3,
"selected": false,
"text": "for each n do t´[n] = h(g(f(t[n])))\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7839/"
] |
261,594
|
<p>In C# Is there a way of getting a finer granularity with SQL exceptions?</p>
<p>I'm aware that an aweful lot can go wrong but I want to deal with certain cases differently and parsing the Error message doesn't seem to be very elegant.</p>
<p>Also Are the error messages created by the framework or are they db specific?</p>
<p>For example If i have a primary key violation on INSERT is the error message going to always be:</p>
<p>Violation of PRIMARY KEY constraint 'PK_tblProduct'. Cannot insert duplicate key in object 'dbo.tblProduct'.</p>
<p>or is that SQLServer specific.</p>
<p><strong>Update</strong></p>
<p>I looks like I'm after the error number, any idea where I can get the various error numbers?</p>
<p>best I can do with a quick google is:
18456: Logon Failed
18488: Password Expired</p>
|
[
{
"answer_id": 261608,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": true,
"text": "SqlException .Number InfoMessage"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400/"
] |
261,599
|
<p>This code always works, even in different browsers:</p>
<pre><code>function fooCheck() {
alert(internalFoo()); // We are using internalFoo() here...
return internalFoo(); // And here, even though it has not been defined...
function internalFoo() { return true; } //...until here!
}
fooCheck();
</code></pre>
<p>I could not find a single reference to why it should work, though.
I first saw this in John Resig's presentation note, but it was only mentioned. There's no explanation there or anywhere for that matter.</p>
<p>Could someone please enlighten me?</p>
|
[
{
"answer_id": 261682,
"author": "bobince",
"author_id": 18936,
"author_profile": "https://Stackoverflow.com/users/18936",
"pm_score": 9,
"selected": true,
"text": "function function var internalFoo = function() { return true; };\n"
},
{
"answer_id": 262643,
"author": "Andrew Hedges",
"author_id": 11577,
"author_profile": "https://Stackoverflow.com/users/11577",
"pm_score": -1,
"selected": false,
"text": "foo if (test condition) {\n var foo;\n}\n"
},
{
"answer_id": 42266568,
"author": "Negin",
"author_id": 5611484,
"author_profile": "https://Stackoverflow.com/users/5611484",
"pm_score": 6,
"selected": false,
"text": "let lastName = function (family) {\n console.log(\"My last name is \" + family);\n};\nlet x = lastName(\"Lopez\");\n lastName = (family) => console.log(\"My last name is \" + family);\n\nx = lastName(\"Lopez\");\n function Name(name) {\n console.log(\"My cat's name is \" + name);\n}\nName(\"Chloe\");\n Name(\"Chloe\");\nfunction Name(name) {\n console.log(\"My cat's name is \" + name);\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21648/"
] |
261,601
|
<p>I need to hide a Windows form from the taskbar but I can't use <code>WS_EX_TOOLWINDOW</code> because I need the system menu and min/max buttons on the form's title bar. </p>
<p>If I switch the form to a tool window at runtime the form skinning is stuffed up. From searching on the Web I see that VB has a ShowInTaskbar property and I'm wondering if this would do what I want, and whether it can be implemented in Delphi 2006. Also this project is a COM server and has no MainForm, etc.</p>
|
[
{
"answer_id": 261619,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 1,
"selected": false,
"text": "procedure TForm1.FormCreate(Sender: TObject);\nbegin\n ShowWindow(Application.Handle, SW_HIDE);\n SetWindowLong(Application.Handle, GWL_EXSTYLE,\n GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);\n ShowWindow(Application.Handle, SW_SHOW);\nend;\n"
},
{
"answer_id": 261970,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "procedure TfrmWord2Site.CreateParams(var Params:TCreateParams);\nbegin\n inherited CreateParams(Params);\n Params.WndParent := <your owner form>.Handle;\n Params.ExStyle := Params.ExStyle and not WS_EX_APPWINDOW;\nend;\n"
},
{
"answer_id": 615898,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "ShowWindow(_window, SWHide);\n\nint style = GetWindowLong(_window, GWL_EXSTYLE);\nstyle |= WS_EX_TOOLWINDOW;\nSetWindowLong(_window, GWL_EXSTYLE, style);\n\nShowWindow(_window, SWShow);\n"
},
{
"answer_id": 5002667,
"author": "besKa88",
"author_id": 617618,
"author_profile": "https://Stackoverflow.com/users/617618",
"pm_score": 1,
"selected": false,
"text": "program prog; \n\nuses\nForms,\nUnit1 in 'Unit1.pas' {Form1};\n\nbegin\nApplication.Initialize;\n\n// this value is set to \"true\", but you shoud set it \"false\"\nApplication.MainFormOnTaskbar := false;\n\nApplication.CreateForm(TForm1, Form1);\nApplication.Run;\nend.\n procedure TForm1.FormShow(Sender: TObject);\n\nbegin\n\nShowWindow(Application.Handle, SW_HIDE);\n\nend;\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,622
|
<p>Is it possible to replace the standard broken image via CSS or using another technique? All my images are the same size and my have transparency.</p>
<p>I've tried to wrap all images with a div's background:</p>
<pre><code><div class="no_broken">
<img src="http://www.web.com/found.gif"/>
</div>
<div class="no_broken">
<img src="http://www.web.com/notfound.gif"/>
</div>
</code></pre>
<p>CSS:</p>
<pre><code>div.no_broken {
background-image: url(standard.gif);
}
div.no_broken, div.no_broken img {
width: 32px;
height: 32px;
display: block;
}
</code></pre>
<p>But this will display two images on top of each other if the IMG is transparent.</p>
|
[
{
"answer_id": 261651,
"author": "schnaader",
"author_id": 34065,
"author_profile": "https://Stackoverflow.com/users/34065",
"pm_score": 7,
"selected": true,
"text": "<img src=\"some.jpg\" onerror=\"this.src='alternative.jpg';\">\n"
},
{
"answer_id": 22946052,
"author": "broox",
"author_id": 446604,
"author_profile": "https://Stackoverflow.com/users/446604",
"pm_score": 3,
"selected": false,
"text": "$(document).ready(function () {\n $('.no_broken img').error(function () {\n $(this).addClass('broken');\n });\n});\n div.no_broken, div.no_broken img { \n width: 32px; \n height: 32px; \n display: block; \n}\n\ndiv.no_broken img.broken {\n background-image: url(standard.gif);\n content:\"\";\n}\n"
},
{
"answer_id": 31027662,
"author": "Dave Sumter",
"author_id": 706866,
"author_profile": "https://Stackoverflow.com/users/706866",
"pm_score": 2,
"selected": false,
"text": "function epic(c) {\n c.onerror='';\n c.src='alternative.jpg';\n};\n <img src='some.jpg' onerror='epic(this)'>\n"
},
{
"answer_id": 52968407,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 4,
"selected": false,
"text": "::before ::after img {\n position: relative;\n width: 200px;\n height: 200px;\n display: inline-block;\n vertical-align: text-bottom;\n}\n\n img::before {\n content: 'fall back';\n position: absolute;\n top: 0;\n left: 0;\n bottom: 0;\n right: 0;\n line-height: 200px;\n background-color: #fd0;\n color: currentColor;\n text-align: center;\n border-radius: 2px;\n display: block;\n width: 200px;\n height: 200px;\n overflow: hidden;\n } <img src=\"not-found\">\n<img src=\"https://via.placeholder.com/200\">"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261622",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28150/"
] |
261,625
|
<p>I am using ehCache to store larges amount of data.
This cache is accessed about 3 times every second and must be kept up to date.
I have a thread that runs which retrieves all the data i need for the cache from the database every minute into a different cache(different cachemanager also).
What i want to do is copy the contents of the data from the new cache into the cache which is being accessed every second in a quick, reliable and synchronized manner. (e.g. call a replace method passing in the existing cache, and the new cache and update the new cache quickly and safely)</p>
<p>Is there any way off hand to do this in ehCache?</p>
<p>Any help is greatly appreciated.</p>
<p>Thanks
Damien</p>
|
[
{
"answer_id": 261871,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 0,
"selected": false,
"text": "CacheFactory"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11612/"
] |
261,638
|
<p>I am developing a piece of software in Python that will be distributed to my employer's customers. My employer wants to limit the usage of the software with a time-restricted license file.</p>
<p>If we distribute the <code>.py</code> files or even <code>.pyc</code> files it will be easy to (decompile and) remove the code that checks the license file.</p>
<p>Another aspect is that my employer does not want the code to be read by our customers, fearing that the code may be stolen or at least the "novel ideas".</p>
<p>Is there a good way to handle this problem?</p>
|
[
{
"answer_id": 261797,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 3,
"selected": false,
"text": ".pyc #"
},
{
"answer_id": 30121460,
"author": "Lmwangi",
"author_id": 458878,
"author_profile": "https://Stackoverflow.com/users/458878",
"pm_score": 6,
"selected": false,
"text": "$ pyminifier --nonlatin --replacement-length=50 /tmp/tumult.py\n#!/usr/bin/env python3\nﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲמּ=ImportError\nﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ燱=print\nﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ=False\nﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ澨=object\ntry:\n import demiurgic\nexcept ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲמּ:\n ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ燱(\"Warning: You're not demiurgic. Actually, I think that's normal.\")\ntry:\n import mystificate\nexcept ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲמּ:\n ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ燱(\"Warning: Dark voodoo may be unreliable.\")\nﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲﺬ=ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ\nclass ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ(ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ澨):\n def __init__(self,*args,**kwargs):\n pass\n def ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ클(self,dactyl):\n ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ퐐=demiurgic.palpitation(dactyl)\n ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ=mystificate.dark_voodoo(ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ퐐)\n return ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ\n def ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ(self,whatever):\n ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ燱(whatever)\nif __name__==\"__main__\":\n ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ燱(\"Forming...\")\n ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲﺃ=ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ(\"epicaricacy\",\"perseverate\")\n ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲﺃ.ﺭ异ﭞﰣﺁں뻛嬭ﱌꝪﴹ뙫퉊ﳦﲣפּܟﺶﶨࠔﶻ䉊ﰸﭳᣲ(\"Codswallop\")\n# Created by pyminifier (https://github.com/liftoff/pyminifier)\n"
},
{
"answer_id": 49331350,
"author": "mvallebr",
"author_id": 1077695,
"author_profile": "https://Stackoverflow.com/users/1077695",
"pm_score": 4,
"selected": false,
"text": "import pyconcrete MODULE MODULE.pye MODULE.pye _pyconcrete.pyd _pyconcrete.pyd"
},
{
"answer_id": 54421461,
"author": "Artem",
"author_id": 1275924,
"author_profile": "https://Stackoverflow.com/users/1275924",
"pm_score": 1,
"selected": false,
"text": "pip install licensing pubKey = \"<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>\"\n\nres = Key.activate(token=\"WyIyNTU1IiwiRjdZZTB4RmtuTVcrQlNqcSszbmFMMHB3aWFJTlBsWW1Mbm9raVFyRyJd\",\\\n rsa_pub_key=pubKey,\\\n product_id=3349, key=\"ICVLD-VVSZR-ZTICT-YKGXL\", machine_code=Helpers.GetMachineCode())\n\nif res[0] == None not Helpers.IsOnRightMachine(res[0]):\n print(\"An error occured: {0}\".format(res[1]))\nelse:\n print(\"Success\")\n"
},
{
"answer_id": 59368824,
"author": "Mike",
"author_id": 9606141,
"author_profile": "https://Stackoverflow.com/users/9606141",
"pm_score": 2,
"selected": false,
"text": "python -m compileall"
},
{
"answer_id": 72767648,
"author": "Seyed Hossein Mirheydari",
"author_id": 12054364,
"author_profile": "https://Stackoverflow.com/users/12054364",
"pm_score": 2,
"selected": false,
"text": "Cython Nuitka Nuitka Cython .pyd .exe .pyc .pyc"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261638",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6759/"
] |
261,648
|
<p>I'm developing an application which has a lot of text and also different modules which can be included or not in every build.</p>
<p>For each saved project we generate automatically a report with all the details (i.e. description of algorithms used in that project and so on). Currently we embed all text as strings in the source code and we also support different languages through po and mo files.</p>
<p>The good points of the system is that it is very easy to dynamically generate documentation and report files.
The bad point is that having a lot of text in source code is ugly and the formatting (i.e. with html) is not comfortable, editing of the text is difficult, no easy spell check and terrible to translate.</p>
<p>So, the final question is: whould you rather embed documentation in code or write external documentation files (for example html) for different languages and parse them on runtime? Obviously the core text of the software, such us message boxes will stay in code anyway.</p>
<p>If it matters, I'm working in C++ with wxWidgets.</p>
|
[
{
"answer_id": 261720,
"author": "Adam",
"author_id": 1366,
"author_profile": "https://Stackoverflow.com/users/1366",
"pm_score": 1,
"selected": false,
"text": "#textId \"the actual text\"\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3373/"
] |
261,655
|
<p>I have a list of tuples like this:</p>
<pre><code>[
('a', 1),
('a', 2),
('a', 3),
('b', 1),
('b', 2),
('c', 1),
]
</code></pre>
<p>I want to iterate through this keying by the first item, so, for example, I could print something like this:</p>
<pre><code>a 1 2 3
b 1 2
c 1
</code></pre>
<p>How would I go about doing this without keeping an item to track whether the first item is the same as I loop around the tuples? This feels rather messy (plus I have to sort the list to start with)...</p>
|
[
{
"answer_id": 261665,
"author": "Ned Batchelder",
"author_id": 14343,
"author_profile": "https://Stackoverflow.com/users/14343",
"pm_score": 7,
"selected": true,
"text": "l = [\n('a', 1),\n('a', 2),\n('a', 3),\n('b', 1),\n('b', 2),\n('c', 1),\n]\n\nd = {}\nfor x, y in l:\n d.setdefault(x, []).append(y)\nprint d\n {'a': [1, 2, 3], 'c': [1], 'b': [1, 2]}\n"
},
{
"answer_id": 261677,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 5,
"selected": false,
"text": "from collections import defaultdict\n\nfq = defaultdict(list)\nfor n, v in myList:\n fq[n].append(v)\n \nprint(fq) # defaultdict(<type 'list'>, {'a': [1, 2, 3], 'c': [1], 'b': [1, 2]})\n"
},
{
"answer_id": 261766,
"author": "user7461",
"author_id": 7461,
"author_profile": "https://Stackoverflow.com/users/7461",
"pm_score": 4,
"selected": false,
"text": "from itertools import groupby\nl = [('a',1), ('a', 2),('a', 3),('b', 1),('b', 2),('c', 1),]\n[(label, [v for l,v in value]) for (label, value) in groupby(l, lambda x:x[0])]\n [('a', [1, 2, 3]), ('b', [1, 2]), ('c', [1])]\n groupby(l, lambda x:x[0]) ['a', [('a', 1), ...], c, [('c', 1)], ...]\n"
},
{
"answer_id": 1694768,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/env python\n\nfrom itertools import groupby\nfrom operator import itemgetter\n\nL = [\n('a', 1),\n('a', 2),\n('a', 3),\n('b', 1),\n('b', 2),\n('c', 1),\n]\n\nkey = itemgetter(0)\nL.sort(key=key) #NOTE: use `L.sort()` if you'd like second items to be sorted too\nfor k, group in groupby(L, key=key):\n print k, ' '.join(str(item[1]) for item in group)\n a 1 2 3\nb 1 2\nc 1\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18909/"
] |
261,660
|
<p>I have a <code>TreeView</code> windows forms control with an <code>ImageList</code>, and I want some of the nodes to display images, but the others to not have images.</p>
<p>I <em>don't</em> want a blank space where the image should be. I <em>don't</em> want an image that looks like the lines that the TreeView would draw if it didn't have an ImageList. How do I get it to draw images for some items and not others, without resorting to clumsy hacks like that?</p>
|
[
{
"answer_id": 262396,
"author": "Martin Brown",
"author_id": 20553,
"author_profile": "https://Stackoverflow.com/users/20553",
"pm_score": 4,
"selected": true,
"text": "ImageKey ImageIndex ImageIndex treeView.ImageKey = \"Value\";\nDebug.WriteLine(treeView.ImageIndex);\ntreeView.ImageKey = null;\nDebug.WriteLine(treeView.ImageIndex);\ntreeView.ImageIndex = -1;\nDebug.WriteLine(treeView.ImageIndex);\n -1\n0\n0\n"
},
{
"answer_id": 1009477,
"author": "John Fischer",
"author_id": 99573,
"author_profile": "https://Stackoverflow.com/users/99573",
"pm_score": 4,
"selected": false,
"text": "ImageIndex SelectedImageIndex ImageList TreeView TreeNode node1 = new TreeNode(string.Empty, 12, 12); // imageList1.Count = 5\n TreeNode TreeView TreeView"
},
{
"answer_id": 14668991,
"author": "user1887120",
"author_id": 1887120,
"author_profile": "https://Stackoverflow.com/users/1887120",
"pm_score": 2,
"selected": false,
"text": "TreeNode TreeView DrawMode OwnerDrawText DrawMode ImageIndex SelectedImageIndex yourImageListName.Images.Count DrawNode DrawNode if (e.Node.ImageIndex >= e.Node.TreeView.ImageList.Images.Count) // if there is no image\n{\n int imagewidths = e.Node.TreeView.ImageList.ImageSize.Width;\n int textheight = TextRenderer.MeasureText(e.Node.Text, e.Node.NodeFont).Height;\n int x = e.Node.Bounds.Left - 3 - imagewidths / 2;\n int y = (e.Bounds.Top + e.Bounds.Bottom) / 2+1;\n\n Point point = new Point(x - imagewidths/2, y - textheight/2); // the new location for the text to be drawn\n\n TextRenderer.DrawText(e.Graphics, e.Node.Text, e.Node.NodeFont, point, e.Node.ForeColor);\n}\nelse // drawn at the default location\n TextRenderer.DrawText(e.Graphics, e.Node.Text, e.Node.TreeView.Font, e.Bounds, e.Node.ForeColor);\n"
},
{
"answer_id": 20616195,
"author": "MtnManChris",
"author_id": 2133578,
"author_profile": "https://Stackoverflow.com/users/2133578",
"pm_score": 4,
"selected": false,
"text": "TreeView ImageList.Images.Count-1"
},
{
"answer_id": 31326820,
"author": "Rogerio Souza",
"author_id": 2820012,
"author_profile": "https://Stackoverflow.com/users/2820012",
"pm_score": 0,
"selected": false,
"text": "TreeView treeView = new TreeView();\ntreeView.ImageList.Images.Add(new Bitmap(1,1));\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15371/"
] |
261,663
|
<p>Is it possible to define an implicit conversion of enums in c#?</p>
<p>something that could achieve this?</p>
<pre><code>public enum MyEnum
{
one = 1, two = 2
}
MyEnum number = MyEnum.one;
long i = number;
</code></pre>
<p>If not, why not?</p>
|
[
{
"answer_id": 261676,
"author": "Ash",
"author_id": 31128,
"author_profile": "https://Stackoverflow.com/users/31128",
"pm_score": 2,
"selected": false,
"text": "public enum MyEnum : long\n{\n one = 1,\n two = 2,\n}\n\nMyEnum number = MyEnum.one;\nlong i = (long)number;\n zero = 0"
},
{
"answer_id": 261696,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 3,
"selected": false,
"text": "public class MyClass {\n\n public static implicit operator MyClass ( MyEnum input ) {\n //...\n }\n}\n\nMyClass m = MyEnum.One;\n"
},
{
"answer_id": 261708,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": false,
"text": "public enum MyEnum { A, B, C }\npublic static class MyEnumExt\n{\n public static int Value(this MyEnum foo) { return (int)foo; }\n static void Main()\n {\n MyEnum val = MyEnum.A;\n int i = val.Value();\n }\n}\n [Flags] bool IsFlagSet<T>(T value, T flag);"
},
{
"answer_id": 2949340,
"author": "Mark",
"author_id": 64084,
"author_profile": "https://Stackoverflow.com/users/64084",
"pm_score": 8,
"selected": true,
"text": "public sealed class AccountStatus\n{\n public static readonly AccountStatus Open = new AccountStatus(1);\n public static readonly AccountStatus Closed = new AccountStatus(2);\n\n public static readonly SortedList<byte, AccountStatus> Values = new SortedList<byte, AccountStatus>();\n private readonly byte Value;\n\n private AccountStatus(byte value)\n {\n this.Value = value;\n Values.Add(value, this);\n }\n\n\n public static implicit operator AccountStatus(byte value)\n {\n return Values[value];\n }\n\n public static implicit operator byte(AccountStatus value)\n {\n return value.Value;\n }\n}\n AccountStatus openedAccount = 1; // Works\n byte openedValue = AccountStatus.Open; // Works\n public sealed class AccountStatus : RichEnum<byte, AccountStatus>\n{\n public static readonly AccountStatus Open = new AccountStatus(1);\n public static readonly AccountStatus Closed = new AccountStatus(2);\n\n private AccountStatus(byte value) : base (value)\n {\n }\n\n public static implicit operator AccountStatus(byte value)\n {\n return Convert(value);\n }\n}\n using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Diagnostics;\nusing System.Linq;\nusing System.Reflection;\nusing System.Resources;\n\nnamespace Ethica\n{\n using Reflection;\n using Text;\n\n [DebuggerDisplay(\"{Value} ({Name})\")]\n public abstract class RichEnum<TValue, TDerived>\n : IEquatable<TDerived>,\n IComparable<TDerived>,\n IComparable, IComparer<TDerived>\n where TValue : struct , IComparable<TValue>, IEquatable<TValue>\n where TDerived : RichEnum<TValue, TDerived>\n {\n #region Backing Fields\n\n /// <summary>\n /// The value of the enum item\n /// </summary>\n public readonly TValue Value;\n\n /// <summary>\n /// The public field name, determined from reflection\n /// </summary>\n private string _name;\n\n /// <summary>\n /// The DescriptionAttribute, if any, linked to the declaring field\n /// </summary>\n private DescriptionAttribute _descriptionAttribute;\n\n /// <summary>\n /// Reverse lookup to convert values back to local instances\n /// </summary>\n private static SortedList<TValue, TDerived> _values;\n\n private static bool _isInitialized;\n\n\n #endregion\n\n #region Constructors\n\n protected RichEnum(TValue value)\n {\n if (_values == null)\n _values = new SortedList<TValue, TDerived>();\n this.Value = value;\n _values.Add(value, (TDerived)this);\n }\n\n #endregion\n\n #region Properties\n\n public string Name\n {\n get\n {\n CheckInitialized();\n return _name;\n }\n }\n\n public string Description\n {\n get\n {\n CheckInitialized();\n\n if (_descriptionAttribute != null)\n return _descriptionAttribute.Description;\n\n return _name;\n }\n }\n\n #endregion\n\n #region Initialization\n\n private static void CheckInitialized()\n {\n if (!_isInitialized)\n {\n ResourceManager _resources = new ResourceManager(typeof(TDerived).Name, typeof(TDerived).Assembly);\n\n var fields = typeof(TDerived)\n .GetFields(BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public)\n .Where(t => t.FieldType == typeof(TDerived));\n\n foreach (var field in fields)\n {\n\n TDerived instance = (TDerived)field.GetValue(null);\n instance._name = field.Name;\n instance._descriptionAttribute = field.GetAttribute<DescriptionAttribute>();\n\n var displayName = field.Name.ToPhrase();\n }\n _isInitialized = true;\n }\n }\n\n #endregion\n\n #region Conversion and Equality\n\n public static TDerived Convert(TValue value)\n {\n return _values[value];\n }\n\n public static bool TryConvert(TValue value, out TDerived result)\n {\n return _values.TryGetValue(value, out result);\n }\n\n public static implicit operator TValue(RichEnum<TValue, TDerived> value)\n {\n return value.Value;\n }\n\n public static implicit operator RichEnum<TValue, TDerived>(TValue value)\n {\n return _values[value];\n }\n\n public static implicit operator TDerived(RichEnum<TValue, TDerived> value)\n {\n return value;\n }\n\n public override string ToString()\n {\n return _name;\n }\n\n #endregion\n\n #region IEquatable<TDerived> Members\n\n public override bool Equals(object obj)\n {\n if (obj != null)\n {\n if (obj is TValue)\n return Value.Equals((TValue)obj);\n\n if (obj is TDerived)\n return Value.Equals(((TDerived)obj).Value);\n }\n return false;\n }\n\n bool IEquatable<TDerived>.Equals(TDerived other)\n {\n return Value.Equals(other.Value);\n }\n\n\n public override int GetHashCode()\n {\n return Value.GetHashCode();\n }\n\n #endregion\n\n #region IComparable Members\n\n int IComparable<TDerived>.CompareTo(TDerived other)\n {\n return Value.CompareTo(other.Value);\n }\n\n int IComparable.CompareTo(object obj)\n {\n if (obj != null)\n {\n if (obj is TValue)\n return Value.CompareTo((TValue)obj);\n\n if (obj is TDerived)\n return Value.CompareTo(((TDerived)obj).Value);\n }\n return -1;\n }\n\n int IComparer<TDerived>.Compare(TDerived x, TDerived y)\n {\n return (x == null) ? -1 :\n (y == null) ? 1 :\n x.Value.CompareTo(y.Value);\n }\n\n #endregion\n\n public static IEnumerable<TDerived> Values\n {\n get\n {\n return _values.Values;\n }\n }\n\n public static TDerived Parse(string name)\n {\n foreach (TDerived value in _values.Values)\n if (0 == string.Compare(value.Name, name, true) || 0 == string.Compare(value.DisplayName, name, true))\n return value;\n\n return null;\n }\n }\n}\n"
},
{
"answer_id": 5480173,
"author": "sehe",
"author_id": 85371,
"author_profile": "https://Stackoverflow.com/users/85371",
"pm_score": 4,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Diagnostics;\nusing System.Linq;\nusing System.Reflection;\nusing System.Resources;\n\nnamespace NMatrix\n{\n\n [DebuggerDisplay(\"{Value} ({Name})\")]\n public abstract class RichEnum<TValue, TDerived>\n : IEquatable<TDerived>,\n IComparable<TDerived>,\n IComparable, IComparer<TDerived>\n where TValue : struct, IComparable<TValue>, IEquatable<TValue>\n where TDerived : RichEnum<TValue, TDerived>\n {\n #region Backing Fields\n\n /// <summary>\n /// The value of the enum item\n /// </summary>\n public readonly TValue Value;\n\n /// <summary>\n /// The public field name, determined from reflection\n /// </summary>\n private string _name;\n\n /// <summary>\n /// The DescriptionAttribute, if any, linked to the declaring field\n /// </summary>\n private DescriptionAttribute _descriptionAttribute;\n\n /// <summary>\n /// Reverse lookup to convert values back to local instances\n /// </summary>\n private static readonly SortedList<TValue, TDerived> _values = new SortedList<TValue, TDerived>();\n\n #endregion\n\n #region Constructors\n\n protected RichEnum(TValue value)\n {\n this.Value = value;\n _values.Add(value, (TDerived)this);\n }\n\n #endregion\n\n #region Properties\n\n public string Name\n {\n get\n {\n return _name;\n }\n }\n\n public string Description\n {\n get\n {\n if (_descriptionAttribute != null)\n return _descriptionAttribute.Description;\n\n return _name;\n }\n }\n\n #endregion\n\n #region Initialization\n\n static RichEnum()\n {\n var fields = typeof(TDerived)\n .GetFields(BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public)\n .Where(t => t.FieldType == typeof(TDerived));\n\n foreach (var field in fields)\n {\n /*var dummy =*/ field.GetValue(null); // forces static initializer to run for TDerived\n\n TDerived instance = (TDerived)field.GetValue(null);\n instance._name = field.Name;\n instance._descriptionAttribute = field.GetCustomAttributes(true).OfType<DescriptionAttribute>().FirstOrDefault();\n }\n }\n\n #endregion\n\n #region Conversion and Equality\n\n public static TDerived Convert(TValue value)\n {\n return _values[value];\n }\n\n public static bool TryConvert(TValue value, out TDerived result)\n {\n return _values.TryGetValue(value, out result);\n }\n\n public static implicit operator TValue(RichEnum<TValue, TDerived> value)\n {\n return value.Value;\n }\n\n public static implicit operator RichEnum<TValue, TDerived>(TValue value)\n {\n return _values[value];\n }\n\n public static implicit operator TDerived(RichEnum<TValue, TDerived> value)\n {\n return value;\n }\n\n public override string ToString()\n {\n return _name;\n }\n\n #endregion\n\n #region IEquatable<TDerived> Members\n\n public override bool Equals(object obj)\n {\n if (obj != null)\n {\n if (obj is TValue)\n return Value.Equals((TValue)obj);\n\n if (obj is TDerived)\n return Value.Equals(((TDerived)obj).Value);\n }\n return false;\n }\n\n bool IEquatable<TDerived>.Equals(TDerived other)\n {\n return Value.Equals(other.Value);\n }\n\n\n public override int GetHashCode()\n {\n return Value.GetHashCode();\n }\n\n #endregion\n\n #region IComparable Members\n\n int IComparable<TDerived>.CompareTo(TDerived other)\n {\n return Value.CompareTo(other.Value);\n }\n\n int IComparable.CompareTo(object obj)\n {\n if (obj != null)\n {\n if (obj is TValue)\n return Value.CompareTo((TValue)obj);\n\n if (obj is TDerived)\n return Value.CompareTo(((TDerived)obj).Value);\n }\n return -1;\n }\n\n int IComparer<TDerived>.Compare(TDerived x, TDerived y)\n {\n return (x == null) ? -1 :\n (y == null) ? 1 :\n x.Value.CompareTo(y.Value);\n }\n\n #endregion\n\n public static IEnumerable<TDerived> Values\n {\n get\n {\n return _values.Values;\n }\n }\n\n public static TDerived Parse(string name)\n {\n foreach (TDerived value in Values)\n if (0 == string.Compare(value.Name, name, true))\n return value;\n\n return null;\n }\n }\n}\n using System.ComponentModel;\nusing System;\n\nnamespace NMatrix\n{ \n public sealed class MyEnum : RichEnum<int, MyEnum>\n {\n [Description(\"aap\")] public static readonly MyEnum my_aap = new MyEnum(63000);\n [Description(\"noot\")] public static readonly MyEnum my_noot = new MyEnum(63001);\n [Description(\"mies\")] public static readonly MyEnum my_mies = new MyEnum(63002);\n\n private MyEnum(int value) : base (value) { } \n public static implicit operator MyEnum(int value) { return Convert(value); }\n }\n\n public static class Program\n {\n public static void Main(string[] args)\n {\n foreach (var enumvalue in MyEnum.Values)\n Console.WriteLine(\"MyEnum {0}: {1} ({2})\", (int) enumvalue, enumvalue, enumvalue.Description);\n }\n }\n}\n [mono] ~/custom/demo @ gmcs test.cs richenum.cs && ./test.exe \nMyEnum 63000: my_aap (aap)\nMyEnum 63001: my_noot (noot)\nMyEnum 63002: my_mies (mies)\n"
},
{
"answer_id": 12901745,
"author": "Glenn Slayden",
"author_id": 147511,
"author_profile": "https://Stackoverflow.com/users/147511",
"pm_score": 5,
"selected": false,
"text": "struct PseudoEnum\n{\n public const int \n INPT = 0,\n CTXT = 1,\n OUTP = 2;\n};\n\n// ...\n\nvar arr = new String[3];\n\narr[PseudoEnum.CTXT] = \"can\";\narr[PseudoEnum.INPT] = \"use\";\narr[PseudoEnum.CTXT] = \"as\";\narr[PseudoEnum.CTXT] = \"array\";\narr[PseudoEnum.OUTP] = \"index\";\n"
},
{
"answer_id": 30395889,
"author": "BatteryBackupUnit",
"author_id": 684096,
"author_profile": "https://Stackoverflow.com/users/684096",
"pm_score": 1,
"selected": false,
"text": "public static TDervied MyEnumValue FieldInfo.GetValue(null) TDerived RichEnum<TValue, TDerived> TDerived.Name public abstract class RichEnum<TValue, TDerived> : EquatableBase<TDerived>\n where TValue : struct, IComparable<TValue>, IEquatable<TValue>\n where TDerived : RichEnum<TValue, TDerived>\n{\n // Enforcing that the field Name (´SomeEnum.SomeEnumValue´) is the same as its \n // instances ´SomeEnum.Name´ is done by the static initializer of this class.\n // Explanation of initialization sequence:\n // 1. the static initializer of ´RichEnum<TValue, TDerived>´ reflects TDervied and \n // creates a list of all ´public static TDervied´ fields:\n // ´EnumInstanceToNameMapping´\n // 2. the static initializer of ´TDerive´d assigns values to these fields\n // 3. The user is now able to access the values of a field.\n // Upon first access of ´TDervied.Name´ we search the list \n // ´EnumInstanceToNameMapping´ (created at step 1) for the field that holds\n // ´this´ instance of ´TDerived´.\n // We then get the Name for ´this´ from the FieldInfo\n private static readonly IReadOnlyCollection<EnumInstanceReflectionInfo> \n EnumInstanceToNameMapping = \n typeof(TDerived)\n .GetFields(BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public)\n .Where(t => t.FieldType == typeof(TDerived))\n .Select(fieldInfo => new EnumInstanceReflectionInfo(fieldInfo))\n .ToList();\n\n private static readonly SortedList<TValue, TDerived> Values =\n new SortedList<TValue, TDerived>();\n\n public readonly TValue Value;\n\n private readonly Lazy<string> _name;\n\n protected RichEnum(TValue value)\n {\n Value = value;\n\n // SortedList doesn't allow duplicates so we don't need to do\n // duplicate checking ourselves\n Values.Add(value, (TDerived)this);\n\n _name = new Lazy<string>(\n () => EnumInstanceToNameMapping\n .First(x => ReferenceEquals(this, x.Instance))\n .Name);\n }\n\n public string Name\n {\n get { return _name.Value; }\n }\n\n public static implicit operator TValue(RichEnum<TValue, TDerived> richEnum)\n {\n return richEnum.Value;\n }\n\n public static TDerived Convert(TValue value)\n {\n return Values[value];\n }\n\n protected override bool Equals(TDerived other)\n {\n return Value.Equals(other.Value);\n }\n\n protected override int ComputeHashCode()\n {\n return Value.GetHashCode();\n }\n\n private class EnumInstanceReflectionInfo\n {\n private readonly FieldInfo _field;\n private readonly Lazy<TDerived> _instance;\n\n public EnumInstanceReflectionInfo(FieldInfo field)\n {\n _field = field;\n _instance = new Lazy<TDerived>(() => (TDerived)field.GetValue(null));\n }\n\n public TDerived Instance\n {\n get { return _instance.Value; }\n }\n\n public string Name { get { return _field.Name; } }\n }\n}\n EquatableBase<T> public abstract class EquatableBase<T>\n where T : class \n{\n public override bool Equals(object obj)\n {\n if (this == obj)\n {\n return true;\n }\n\n T other = obj as T;\n if (other == null)\n {\n return false;\n }\n\n return Equals(other);\n }\n\n protected abstract bool Equals(T other);\n\n public override int GetHashCode()\n {\n unchecked\n {\n return ComputeHashCode();\n }\n }\n\n protected abstract int ComputeHashCode();\n}\n RichEnum"
},
{
"answer_id": 39141171,
"author": "adminSoftDK",
"author_id": 3173203,
"author_profile": "https://Stackoverflow.com/users/3173203",
"pm_score": 2,
"selected": false,
"text": "struct Day\n{\n readonly int day;\n\n public static readonly Day Monday = 0;\n public static readonly Day Tuesday = 1;\n public static readonly Day Wednesday = 2;\n public static readonly Day Thursday = 3;\n public static readonly Day Friday = 4;\n public static readonly Day Saturday = 5;\n public static readonly Day Sunday = 6;\n\n private Day(int day)\n {\n this.day = day;\n }\n\n public static implicit operator int(Day value)\n {\n return value.day;\n }\n\n public static implicit operator Day(int value)\n {\n return new Day(value);\n }\n}\n"
},
{
"answer_id": 51978313,
"author": "Steven Ventura",
"author_id": 7015392,
"author_profile": "https://Stackoverflow.com/users/7015392",
"pm_score": 3,
"selected": false,
"text": "enum VKeys : ushort\n{\na = 1,\nb = 2,\nc = 3\n}\n// the goal is to index the array using predefined constants\nint[] array = new int[500];\nvar x = array[VKeys.VK_LSHIFT]; \n public static class VKeys\n{\npublic const ushort\na = 1,\nb = 2, \nc = 3;\n}\n"
},
{
"answer_id": 59968873,
"author": "McKabue",
"author_id": 3563013,
"author_profile": "https://Stackoverflow.com/users/3563013",
"pm_score": 2,
"selected": false,
"text": "byte, sbyte, short, ushort, int, uint, long, or ulong public enum MyEnum\n{\n one = 1, two = 2\n}\n\nPrimitiveEnum number = MyEnum.one;\nlong i = number;\n using System;\n\nnamespace McKabue.Extentions.Utility.Enums\n{\n /// <summary>\n /// <see href=\"https://stackoverflow.com/q/261663/3563013\">\n /// Can we define implicit conversions of enums in c#?\n /// </see>\n /// </summary>\n public struct PrimitiveEnum\n {\n private Enum _enum;\n\n public PrimitiveEnum(Enum _enum)\n {\n this._enum = _enum;\n }\n\n public Enum Enum => _enum;\n\n\n public static implicit operator PrimitiveEnum(Enum _enum)\n {\n return new PrimitiveEnum(_enum);\n }\n\n public static implicit operator Enum(PrimitiveEnum primitiveEnum)\n {\n return primitiveEnum.Enum;\n }\n\n public static implicit operator byte(PrimitiveEnum primitiveEnum)\n {\n return Convert.ToByte(primitiveEnum.Enum);\n }\n\n public static implicit operator sbyte(PrimitiveEnum primitiveEnum)\n {\n return Convert.ToSByte(primitiveEnum.Enum);\n }\n\n public static implicit operator short(PrimitiveEnum primitiveEnum)\n {\n return Convert.ToInt16(primitiveEnum.Enum);\n }\n\n public static implicit operator ushort(PrimitiveEnum primitiveEnum)\n {\n return Convert.ToUInt16(primitiveEnum.Enum);\n }\n\n public static implicit operator int(PrimitiveEnum primitiveEnum)\n {\n return Convert.ToInt32(primitiveEnum.Enum);\n }\n\n public static implicit operator uint(PrimitiveEnum primitiveEnum)\n {\n return Convert.ToUInt32(primitiveEnum.Enum);\n }\n\n public static implicit operator long(PrimitiveEnum primitiveEnum)\n {\n return Convert.ToInt64(primitiveEnum.Enum);\n }\n\n public static implicit operator ulong(PrimitiveEnum primitiveEnum)\n {\n return Convert.ToUInt64(primitiveEnum.Enum);\n }\n }\n}\n"
},
{
"answer_id": 64711445,
"author": "Shpendicus",
"author_id": 12399245,
"author_profile": "https://Stackoverflow.com/users/12399245",
"pm_score": 0,
"selected": false,
"text": " _name = new Lazy<string>(\n () => EnumInstanceToNameMapping\n .First(x => ReferenceEquals(this, x.Instance))\n .Name);\n"
},
{
"answer_id": 69168216,
"author": "Prince Owen",
"author_id": 8058709,
"author_profile": "https://Stackoverflow.com/users/8058709",
"pm_score": 1,
"selected": false,
"text": "/// <summary>\n/// Based on https://datatracker.ietf.org/doc/html/rfc4346#appendix-A.1\n/// </summary>\n[DebuggerDisplay(\"{_value}\")]\npublic struct HandshakeContentType\n{\n #region Types\n public const byte ChangeCipher = 0x14;\n public const byte Alert = 0x15;\n public const byte Handshake = 0x16;\n public const byte ApplicationData = 0x17;\n #endregion\n\n byte _value;\n private HandshakeContentType(byte value)\n {\n _value = value;\n\n switch (_value)\n {\n case ChangeCipher:\n case Alert:\n case Handshake:\n case ApplicationData:\n break;\n\n default:\n throw new InvalidOperationException($\"An invalid handshake content type (${value}) was provided.\");\n }\n }\n\n #region Methods\n public static implicit operator byte(HandshakeContentType type) => type._value;\n public static implicit operator HandshakeContentType(byte b) => new HandshakeContentType(b);\n #endregion\n}\n struct switch"
},
{
"answer_id": 72005612,
"author": "RFBomb",
"author_id": 12135042,
"author_profile": "https://Stackoverflow.com/users/12135042",
"pm_score": 0,
"selected": false,
"text": "public enum DaysOfWeek\n{\n Sunday = 0,\n Monday = 1,\n Tuesday = 2,\n Wednesday = 3,\n Thursday = 4,\n Friday = 5,\n Saturday = 7,\n}\n\npublic struct Weekends\n{\n private Weekends(DaysOfWeek day){ Day = day; }\n public readonly DaysOfWeek Day;\n public static Weekends Sunday = new(DaysOfWeek.Sunday);\n public static Weekends Saturday = new(DaysOfWeek.Saturday);\n \n public static implicit operator DaysOfWeek(Weekends value) => value.Mode;\n\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17540/"
] |
261,683
|
<p>Does it mean that two threads can't change the underlying data simultaneously? Or does it mean that the given code segment will run with predictable results when multiple threads are executing that code segment?</p>
|
[
{
"answer_id": 261729,
"author": "Marcus Downing",
"author_id": 1000,
"author_profile": "https://Stackoverflow.com/users/1000",
"pm_score": 5,
"selected": false,
"text": "StringBuffer StringBuilder StringBuffer StringBuffer StringBuilder"
},
{
"answer_id": 262495,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 6,
"selected": false,
"text": "totalRequests = totalRequests + 1\nMOV EAX, [totalRequests] // load memory for tot Requests into register\nINC EAX // update register\nMOV [totalRequests], EAX // store updated value back to memory\n"
},
{
"answer_id": 14749438,
"author": "assylias",
"author_id": 829571,
"author_profile": "https://Stackoverflow.com/users/829571",
"pm_score": 3,
"selected": false,
"text": "counter.next()"
},
{
"answer_id": 37352787,
"author": "Ravindra babu",
"author_id": 4999394,
"author_profile": "https://Stackoverflow.com/users/4999394",
"pm_score": 3,
"selected": false,
"text": "synchronized volatile Thread.start() Thread.join() java.util.concurrent Runnable Executor ExecutorService Future Future.get() Lock.unlock, Semaphore.release, and CountDownLatch.countDown Lock.lock, Semaphore.acquire, Condition.await, and CountDownLatch.await Exchanger exchange() CyclicBarrier.await Phaser.awaitAdvance"
},
{
"answer_id": 56074242,
"author": "rghome",
"author_id": 3800782,
"author_profile": "https://Stackoverflow.com/users/3800782",
"pm_score": 3,
"selected": false,
"text": "class NonThreadSafe {\n\n private int count = 0;\n\n public boolean countTo10() {\n count = count + 1;\n return (count == 10);\n }\n countTo10"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6613/"
] |
261,709
|
<p>I have the following code:</p>
<pre><code>using System;
using System.Linq;
using System.Linq.Expressions;
public class Program
{
public static void Main()
{
Descendant d = new Descendant();
d.TestMethod();
}
}
public class Base
{
protected void FigureItOut<TClass, TMember>(Expression<Func<TClass, TMember>> expr)
{
}
}
public class Descendant : Base
{
public void TestMethod()
{
FigureItOut(c => c.Name);
}
public String Name { get; set; }
}
</code></pre>
<p>I get this compiler error message:</p>
<pre><code>The type arguments for method
'Base.FigureItOut<TClass,TMember>
(System.Linq.Expressions.Expression<System.Func<TClass,TMember>>)'
cannot be inferred from the usage. Try specifying the type arguments explicitly.
</code></pre>
<p>If I change the call to FigureItOut to this:</p>
<pre><code>FigureItOut((Descendant c) => c.Name);
</code></pre>
<p>Then it works. Is there a way to get the first example to compile by changing the base class instead?</p>
<p>I know that if I make the entire Base class generic, like this:</p>
<pre><code>public class Base<TDescendant>
{
protected void FigureItOut<TMember>(Expression<Func<TDescendant, TMember>> expr)
{
}
}
public class Descendant : Base<Descendant>
{
public void TestMethod()
{
FigureItOut(c => c.Name);
}
public String Name { get; set; }
}
</code></pre>
<p>Then it works, but I'd rather not do that, any other hacks that can be employed, perhaps on the method level (ie. change FigureItOut somehow).</p>
|
[
{
"answer_id": 261742,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "protected internal this. source this TClass public class Base\n{\n protected internal void FigureItOut<TClass, TMember>(Expression<Func<TClass, TMember>> expr)\n {\n Debug.WriteLine(\"Got to actual method\");\n }\n}\n\npublic static class BaseExt\n{\n public static void FigureItOut<TClass, TMember>(this TClass source, Expression<Func<TClass, TMember>> expr)\n where TClass : Base\n { // call the actual method\n Debug.WriteLine(\"Got to extension method\");\n source.FigureItOut(expr);\n }\n}\npublic class Descendant : Base\n{\n public void TestMethod()\n {\n this.FigureItOut(c => c.Name);\n }\n\n public String Name { get; set; }\n}\n internal protected static void FigureItOut<TClass, TMember>(TClass source, Expression<Func<TClass, TMember>> expr)\n{\n\n}\n\npublic void TestMethod()\n{\n FigureItOut(this, c => c.Name);\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261709",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/267/"
] |
261,717
|
<p>I have a query on my database as such:</p>
<pre><code>SELECT * FROM expenses WHERE user_id = ? AND dated_on = ?
</code></pre>
<p>I have added an index to the table on both the <code>user_id</code> and <code>dated_on</code> columns. When I inspect the indexes using <code>SHOW INDEXES FROM expenses</code>, there are two lines -- one with a <code>seq_in_index</code> value of 1, the other with a <code>seq_in_index</code> value of 2.</p>
<p>My question is, if I then submit a query which uses only one of the two WHERE clauses, e.g.:</p>
<pre><code>SELECT * FROM expenses WHERE user_id = ?
</code></pre>
<p>Is there any benefit to creating another index which solely indexes the <code>user_id</code> column, or will the <code>user_id</code>/<code>dated_on</code> index described above be used just as efficiently?</p>
<p>Finally, how about if use the query:</p>
<pre><code>SELECT * FROM expenses WHERE dated_on = ?
</code></pre>
<p>How does the <code>seq_in_index</code> value of 2 affect index use and performance in this situation?</p>
|
[
{
"answer_id": 261761,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 4,
"selected": true,
"text": "SELECT * FROM expenses WHERE user_id = ? SELECT * FROM expenses WHERE dated_on = ? WHERE A = ? AND B = ? WHERE A = ? AND C = ?"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1174/"
] |
261,721
|
<p>Do you know a way to organize boolean expressions in a database while allowing infinite nesting of the expressions?</p>
<p>Example:</p>
<pre><code>a = 1 AND (b = 1 OR b = 2)
</code></pre>
<p>The expression as a whole shouldn't be stored as varchar to preserve data integrity.</p>
|
[
{
"answer_id": 261770,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 2,
"selected": false,
"text": "a b Table Nodes\nid\ntype (Variable|Literal)\nname (nullable for literal)\nvalue\n\nTable Operators\nid\nname (=, AND, OR, NOT)\nleftNodeId\nrightNodeId\n"
},
{
"answer_id": 261990,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 2,
"selected": false,
"text": "BLOB varchar"
},
{
"answer_id": 58835705,
"author": "Julien",
"author_id": 2240780,
"author_profile": "https://Stackoverflow.com/users/2240780",
"pm_score": 1,
"selected": false,
"text": "a = 1 AND (b = 1 OR b = 2 OR b = 3)\n -------------------\n| Condition |\n-------------------\n| - id |\n| - value1 |\n| - value2 |\n| - operation |\n-------------------\n |(1)\n | --------------\n | | |\n | |(*) |\n------------------- |\n| ConditionGroup | |\n------------------- |\n| - id |--------\n| - groupType |\n| - condition |\n| - subConditionGroups\n-------------------\n value1 value2 operation b = 3 value1 = 'b' value2 = '3' operation = 'EQUALS' groupeType AND OR ConditionGroup ConditionGroup Condition ConditionGroup subConditionGroups condition"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,731
|
<p>I've got a large source tree (> 2 GB, WINCE build tree) that I would like to start managing with Subversion. Up to this point, 'versioning' has been managed through keeping multiple copies of the tree, and using Beyond Compare to find differences.</p>
<p>The last big stumbling block I see to using Subversion is that it modifies the file timestamp to be the commit time. This makes Beyond Compare comparisons much more time consuming, because you must do a binary compare to find changes.</p>
<p>I've looked at the <a href="http://svn.haxx.se/users/archive-2006-03/0949.shtml" rel="nofollow noreferrer">meta-data versioning</a> branch of the subversion source tree, but I would prefer to not try to merge that code from 2006 into the current svn source. </p>
<p>Thanks,</p>
<p>Dave</p>
|
[
{
"answer_id": 261836,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 3,
"selected": true,
"text": "use-commit-times\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5378/"
] |
261,735
|
<p>I'm looking for a dummy SQL statement that will work from a C# SQL connection to check for connectivity.</p>
<p>Basically I need to send a request to the database, I don't care what it returns I just want it to be successful if the database is still there and throw an exception if the database isn't.</p>
<p>The scenario I'm testing for is a loss of connectivity to the database, where the SQLConnections State property seems to still be "Open" but there is no connectivity.</p>
|
[
{
"answer_id": 261748,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 4,
"selected": true,
"text": "select * from sysibm.sysdummy1\n select * from dual\n"
},
{
"answer_id": 261771,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 3,
"selected": false,
"text": "Select 1\n"
},
{
"answer_id": 262172,
"author": "Michael Penza",
"author_id": 34196,
"author_profile": "https://Stackoverflow.com/users/34196",
"pm_score": 2,
"selected": false,
"text": "SELECT N'Test'\n"
},
{
"answer_id": 262640,
"author": "JosephStyons",
"author_id": 672,
"author_profile": "https://Stackoverflow.com/users/672",
"pm_score": 0,
"selected": false,
"text": "function IsConnValid(var Conn: TADOConnection; DBType: TDBType): boolean;\nvar\n qry : TADOQuery;\nbegin\n //gimme a connection, and i'll create a query, try to retrieve dummy data.\n //if retrieval works, return TRUE. otherwise, return FALSE.\n qry := TADOQuery.Create(nil);\n try\n qry.Connection := Conn;\n\n case DBType of\n //syntax for a dummy query varies by vendor.\n dbOracle : qry.Sql.Add('SELECT 1 FROM DUAL');\n dbSqlServer : qry.Sql.Add('SELECT 1');\n end; //case\n\n try\n qry.Open;\n //try to open the query.\n //if we lost the connection, we'll probably get an exception.\n Result := not(qry.Eof); //a working connection will NOT have EOF.\n qry.Close;\n except on e : exception do\n //if exception when we try to open the qry, then connection went bye-bye.\n Result := False;\n end; //try-except\n finally\n qry.Free;\n end; //try-finally\nend;\n"
},
{
"answer_id": 268998,
"author": "HAdes",
"author_id": 11989,
"author_profile": "https://Stackoverflow.com/users/11989",
"pm_score": 0,
"selected": false,
"text": "SqlConnection sqlConn;\n private bool dbConnectionExists() {\n try\n {\n sqlConn.ChangeDatabase(\"MyDBname\");\n return true;\n }\n catch\n {\n return false;\n }\n }\n\n private void button1_Click(object sender, EventArgs e)\n {\n if (dbConnectionExists())\n {\n // Connection ok so do something \n }\n }\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261735",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400/"
] |
261,738
|
<p>One of my co-workers has resigned and was made to leave the premises before checking in all of his code to TFS. I have access to the physical files. Is there a way for me to access his workspace and check in some of the changes that are still left unchecked in? From tfs I can see which files he has checked out but no way of seeing the exact changes unless very manually. </p>
|
[
{
"answer_id": 8878963,
"author": "granth",
"author_id": 11210,
"author_profile": "https://Stackoverflow.com/users/11210",
"pm_score": 4,
"selected": false,
"text": "tf workspace /collection:http://yourserver:8080/tfs/yourCollection WorkspaceName;domain\\CurrentWorkspaceOwner /permission:Public\n tf workspace /collection:http://yourserver:8080/tfs/yourCollection WorkspaceName;domain\\CurrentWorkspaceOwner /newowner:domain\\NewWorkspaceOwner\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32313/"
] |
261,752
|
<p>is it somehow possible to call a rails function or to access a rails object from within jQuery?
I'd like to do something like:</p>
<pre><code>jQuery(document).ready(function($) {
$('#mydiv').html("<%= @object.name %>");
});
</code></pre>
<p>OR</p>
<pre><code>jQuery(document).ready(function($) {
$('#mydiv').html("<%= render :partial => "contacts" %>");
});
</code></pre>
<p>At the moment I'm keeping all my jQuery stuff in my application.js, which is included in my layout. Oh yeah....and I'm not using Rails Edge.</p>
<p>Regards,</p>
<p>Sebastian</p>
|
[
{
"answer_id": 261913,
"author": "changelog",
"author_id": 5646,
"author_profile": "https://Stackoverflow.com/users/5646",
"pm_score": 3,
"selected": true,
"text": "<script type=\"text/javascript\">\n<%= yield :footerjs %>\n</script> <% content_for :footerjs do %>\njQuery(document).ready(function($) {\n$('#mydiv').html('<%= escape_javascript(render :partial => \"contacts\") %>');\n});\n<% end %>"
},
{
"answer_id": 261987,
"author": "Sebastian",
"author_id": 29909,
"author_profile": "https://Stackoverflow.com/users/29909",
"pm_score": 0,
"selected": false,
"text": "<%= yield :myjs %> <script type=\"text/javascript\">\n<%= yield :myjs %>\n</script>\n <% content_for :myjs do %>\njQuery(document).ready(function($) { alert('hello'); });\n<% end %>\n <head>\n...\n<%= javascript_include_tag 'jquery', 'application' %>\n<%= javascript_tag \"var AUTH_TOKEN = #{form_authenticity_token.inspect};\" if protect_against_forgery? %>\n<% yield :myjs %>\n</head>\n<body>\n...\n <%= yield :myjs %>"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29909/"
] |
261,780
|
<p>I'm trying to parse dates using the user's date preferences</p>
<pre><code>[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSDate *date = [ dateFormatter dateFromString:@"7/4/2008" ];
NSLog(@"string from date %@: %@ for locale %@", date, [dateFormatter stringFromDate:date], [[dateFormatter locale] localeIdentifier]);
</code></pre>
<p>When I set my region (in the International system preferences) to be United States, it prints:</p>
<pre><code>2008-08-14 20:20:31.117 Date Difference17226:10b string from date 2008-07-04 00:00:00 -0400: 7/4/08 for locale en_US
</code></pre>
<p>And when my region is United Kingdom, it prints:</p>
<pre><code>2008-08-14 20:19:23.441 Date Difference17199:10b string from date 2008-04-07 00:00:00 -0400: 07/04/2008 for locale en_GB
</code></pre>
<p>It looks like the NSDateFormatter is insensitive to the change of regions. Notice that the raw printing of the date is properly switching with the region, though.</p>
<p>What do I have to do to get the NSDateFormatter to respect the region setting? </p>
|
[
{
"answer_id": 263027,
"author": "Peter Hosey",
"author_id": 30461,
"author_profile": "https://Stackoverflow.com/users/30461",
"pm_score": 2,
"selected": false,
"text": "%@ NSLog"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261780",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14343/"
] |
261,783
|
<p>I am debugging some code and have encountered the following SQL query (simplified version):</p>
<pre><code>SELECT ads.*, location.county
FROM ads
LEFT JOIN location ON location.county = ads.county_id
WHERE ads.published = 1
AND ads.type = 13
AND ads.county_id = 2
OR ads.county_id = 5
OR ads.county_id = 7
OR ads.county_id = 9
</code></pre>
<p>I'm getting very strange results from the query and I think its because the first OR is negating the AND operators that are found before it.</p>
<p>This results in getting results back for ads of all types and not just for the type 13. </p>
<p>Each time the query is called there may be a differnt amount of county entities that need to be looked up.</p>
<p>Any help on the correct way to go about this would be appreciated. </p>
|
[
{
"answer_id": 261788,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 8,
"selected": true,
"text": "SELECT ads.*, location.county \nFROM ads\nLEFT JOIN location ON location.county = ads.county_id\nWHERE ads.published = 1 \nAND ads.type = 13\nAND\n(\n ads.county_id = 2\n OR ads.county_id = 5\n OR ads.county_id = 7\n OR ads.county_id = 9\n)\n SELECT ads.*, location.county \nFROM ads\nLEFT JOIN location ON location.county = ads.county_id\nWHERE ads.published = 1 \nAND ads.type = 13\nAND ads.county_id IN (2, 5, 7, 9)\n"
},
{
"answer_id": 261791,
"author": "Ned Batchelder",
"author_id": 14343,
"author_profile": "https://Stackoverflow.com/users/14343",
"pm_score": 5,
"selected": false,
"text": "SELECT ads.*, location.county \nFROM ads\nLEFT JOIN location ON location.county = ads.county_id\nWHERE ads.published = 1 \nAND ads.type = 13\nAND ads.county_id IN (2,5,7,9)\n"
},
{
"answer_id": 261794,
"author": "Ruben",
"author_id": 26919,
"author_profile": "https://Stackoverflow.com/users/26919",
"pm_score": 4,
"selected": false,
"text": "SELECT ads.*, location.county \n FROM ads\n LEFT JOIN location ON location.county = ads.county_id\n WHERE ads.published = 1 \n AND ads.type = 13\n AND ads.county_id IN (2,5,7,9)\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/319/"
] |
261,793
|
<p>i have a server - client application that runs on java 1.3; i want to change to java 1.6 step by step, meaning first few clients, than rest of the clients and finally server...
i was wondering could you direct me to some common problems that can come along and what should i look after?</p>
|
[
{
"answer_id": 261803,
"author": "Yuval",
"author_id": 2819,
"author_profile": "https://Stackoverflow.com/users/2819",
"pm_score": 2,
"selected": false,
"text": "enum assert"
},
{
"answer_id": 261814,
"author": "Mnementh",
"author_id": 21005,
"author_profile": "https://Stackoverflow.com/users/21005",
"pm_score": 5,
"selected": true,
"text": "-source javac -source 1.3"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15878/"
] |
261,801
|
<p>I have use IlMerge to merge all the dlls of my projects in one exe. I use a targets file which is referenced in the "import" of the main csproj.</p>
<p>The ExecCommand in the targets is:</p>
<pre><code> <Exec Command="&quot;$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe&quot; /out:@(MainAssembly) &quot;@(IntermediateAssembly)&quot; @(IlmergeAssemblies->'&quot;%(FullPath)&quot;', ' ')" />
</code></pre>
<p>This works. </p>
<p>But then I have a Setup Project, when it builds, it ignores the "import" and it doesn't merge the dlls. How can I use the targets file with the Setup Project?</p>
<p>I have tried writing this same code for Ilmerge in the Post-build event (in properties of the project) of the main project but it gives me error code 1.</p>
|
[
{
"answer_id": 271959,
"author": "netadictos",
"author_id": 31791,
"author_profile": "https://Stackoverflow.com/users/31791",
"pm_score": 2,
"selected": true,
"text": "<Project \n DefaultTargets=\"Build\" \n xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n\n <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSharp.targets\" />\n\n <Target Name=\"AfterBuild\">\n <CreateItem Include=\"@(ReferencePath)\" Condition=\"'%(CopyLocal)'=='true'\">\n <Output TaskParameter=\"Include\" ItemName=\"IlmergeAssemblies\"/>\n </CreateItem>\n\n <Message Text=\"MERGING: @(IlmergeAssemblies->'%(Filename)')\" Importance=\"High\" /> \n\n <Exec Command=\""$(ProgramFiles)\\Microsoft\\Ilmerge\\Ilmerge.exe" /out:@(MainAssembly) "@(IntermediateAssembly)" @(IlmergeAssemblies->'"%(FullPath)"', ' ') /log:ILMerge.log\" /> \n\n </Target>\n\n <Target Name=\"_CopyFilesMarkedCopyLocal\"/>\n\n</Project>\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261801",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31791/"
] |
261,807
|
<p>we have a old and dying dedicated server. we want a new one at a new datacenter. we have a bunch of sites using the current server and don't have control of all their DNS. is there an easy way to redirect all the traffic from xx.xx.xx.xx to zz.zz.zz.zz without updating DNS records?</p>
<p>Thanks.</p>
|
[
{
"answer_id": 261847,
"author": "kͩeͣmͮpͥ ͩ",
"author_id": 26479,
"author_profile": "https://Stackoverflow.com/users/26479",
"pm_score": -1,
"selected": false,
"text": "208.69.34.231 87.248.113.14 xx.xx.xx.xx zz.zz.zz.zz xx.xx.xx.xx client->xx.xx.xx.xx.->zz.zz.zz.zz zz.zz.zz.zz->xx.xx.xx.xx->client"
},
{
"answer_id": 261926,
"author": "Adam Liss",
"author_id": 29157,
"author_profile": "https://Stackoverflow.com/users/29157",
"pm_score": 3,
"selected": true,
"text": "IIS iptables iptables -t nat -I PREROUTING -p tcp -d $OLD_DEST_IP --dport $DEST_PORT -j DNAT --to $NEW_IP\n nat PREROUTING"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34133/"
] |
261,809
|
<p>If an interface inherits IEquatable the implementing class can define the behavior of the Equals method. Is it possible to define the behavior of == operations?</p>
<pre><code>public interface IFoo : IEquatable
{}
public class Foo : IFoo
{
// IEquatable.Equals
public bool Equals(IFoo other)
{
// Compare by value here...
}
}
</code></pre>
<p>To check that two IFoo references are equal by comparing their values: </p>
<pre><code>IFoo X = new Foo();
IFoo Y = new Foo();
if (X.Equals(Y))
{
// Do something
}
</code></pre>
<p>Is it possible to make <code>if (X == Y)</code> use the Equals method on Foo?</p>
|
[
{
"answer_id": 261838,
"author": "Luc Touraille",
"author_id": 20984,
"author_profile": "https://Stackoverflow.com/users/20984",
"pm_score": 0,
"selected": false,
"text": "abstract class IFoo : IEquatable<IFoo> \n{\n public static bool operator ==(IFoo i1, IFoo i2) { return i1.Equals(i2); }\n public static bool operator !=(IFoo i1, IFoo i2) { return !i1.Equals(i2); }\n public abstract bool Equals(IFoo other);\n}\n\nclass Foo : IFoo\n{\n public override bool Equals(IFoo other)\n {\n // Compare\n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261809",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11367/"
] |
261,815
|
<p>What is the upper limit for an autoincrement primary key in SQL Server?
What happens when an SQL Server autoincrement primary key reaches its upper limit?</p>
|
[
{
"answer_id": 261840,
"author": "Fred",
"author_id": 33630,
"author_profile": "https://Stackoverflow.com/users/33630",
"pm_score": 0,
"selected": false,
"text": "BIGINT Integer data from -2^63 through 2^63 - 1\n\nINT Integer data from -2^31 through 2^31 - 1\n\nSMALLINT Integer data from -2^15 through 2^15 - 1\n\nTINYINT Integer data from 0 through 255\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261815",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/407003/"
] |
261,829
|
<p>I have three closely related applications that are build from the same source code - let's say APP_A, APP_B, and APP_C. APP_C is a superset of APP_B which in turn is a superset of APP_A.</p>
<p>So far I've been using a preprocessor define to specify the application being built, which has worked like this.</p>
<pre><code>// File: app_defines.h
#define APP_A 0
#define APP_B 1
#define APP_C 2
</code></pre>
<p>My IDE build options then specify (for example)</p>
<pre><code>#define APPLICATION APP_B
</code></pre>
<p>... and in source code, I will have things like</p>
<pre><code>#include "app_defines.h"
#if APPLICATION >= APP_B
// extra features for APPB and APP_C
#endif
</code></pre>
<p>However, I shot myself in the foot this morning and wasted far to much time by simply omitting the line to #include "app_defines.h" from one file. Everything compiled fine, but the application crashed with AVs at startup.</p>
<p>I'd like to know what a better way of handling this would be. Previously, This would normally one of the few times when I'd consider #define could be used (in C++, anyway), but I still goofed up badly and the compiler didn't protect me. </p>
|
[
{
"answer_id": 261893,
"author": "Pieter",
"author_id": 5822,
"author_profile": "https://Stackoverflow.com/users/5822",
"pm_score": 1,
"selected": false,
"text": "namespace AppA {\n // application A specific\n}\n\nnamespace AppB {\n // application B specific\n}\n #if compiler_option_for_appA\n namespace Application = AppA;\n#elif compiler_option_for_appB\n namespace Application = AppB;\n#endif\n namespace Application\n{\n #if compiler_option_for_appA\n using namespace AppA;\n #elif compiler_option_for_appB\n using namespace AppB;\n #endif\n}\n"
},
{
"answer_id": 261953,
"author": "eli",
"author_id": 12893,
"author_profile": "https://Stackoverflow.com/users/12893",
"pm_score": 1,
"selected": false,
"text": "CommonApp ├───── AppExtender ├─ = containment\n ▲ ▲ ▲\n │ │ │ ▲ = ineritance\n AppA AppB AppC │\n // main_a.cpp\n \n CommonApp application;\n AppA appA;\n application.setExtender(&appA);\n application.run();\n \n // main_a.cpp\n \n CommonApp application;\n AppB appB;\n application.setExtender(&appB);\n application.run();\n"
},
{
"answer_id": 262031,
"author": "plinth",
"author_id": 20481,
"author_profile": "https://Stackoverflow.com/users/20481",
"pm_score": 4,
"selected": false,
"text": "#define APP_A 1\n#define APP_B 2\n\n#ifndef APP_CONFIG\n#error \"APP_CONFIG needs to be set\n#endif\n\n#if APP_CONFIG == APP_A\n#define APP_CONFIG_DEFINED\n// other defines\n#endif\n\n#if APP_CONFIG == APP_B\n#define APP_CONFIG_DEFINED\n// other defines\n#endif\n\n#ifndef APP_CONFIG_DEFINED\n#error \"Undefined configuration\"\n#endif\n"
},
{
"answer_id": 807378,
"author": "Hexagon",
"author_id": 88451,
"author_profile": "https://Stackoverflow.com/users/88451",
"pm_score": 0,
"selected": false,
"text": "#define APP_A 0\n#define APP_B 1\n#define APP_C 2\n #define APP_A() 0\n#define APP_B() 1\n#define APP_C() 2\n #if APPLICATION >= APP_B()\n// extra features for APPB and APP_C\n#endif\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1737/"
] |
261,845
|
<p>I want to use jQuery with asp.net webfoms. Do I need to get a special toolkit so the .net controls spit out friendly Control ID's?</p>
<p>Reason being, I don't want to write javascript referencing my html ID's like control_123_asdfcontrol_234.</p>
<p>Has this been addressed in version 3.5? (I remember reading you have to get some special dll that makes ID's friendly).</p>
|
[
{
"answer_id": 261857,
"author": "kͩeͣmͮpͥ ͩ",
"author_id": 26479,
"author_profile": "https://Stackoverflow.com/users/26479",
"pm_score": 3,
"selected": false,
"text": "myControlId = \"<%= myControl.ClientID %>\";"
},
{
"answer_id": 261917,
"author": "ullmark",
"author_id": 23044,
"author_profile": "https://Stackoverflow.com/users/23044",
"pm_score": 1,
"selected": false,
"text": "var myControlId; \n"
},
{
"answer_id": 262086,
"author": "Serhat Ozgel",
"author_id": 31505,
"author_profile": "https://Stackoverflow.com/users/31505",
"pm_score": 0,
"selected": false,
"text": "MyTextBox : Web.UI.TextBox\n{\n // This modifies the generated 'name' attribute\n override UniqueID { get { return ID; } }\n\n // This modifies the generated 'id' attribute\n override ClientID { get{ return ID; } }\n}\n"
},
{
"answer_id": 342508,
"author": "CMPalmer",
"author_id": 14894,
"author_profile": "https://Stackoverflow.com/users/14894",
"pm_score": 4,
"selected": false,
"text": "<asp:TextBox ID=\"txtExample\" runat=\"server\" />\n $(\"[id$=txtExample]\")\n $= $(\"[id$=txtExample]\").attr(\"id\")\n"
},
{
"answer_id": 46032389,
"author": "Naresh Kumar",
"author_id": 8504208,
"author_profile": "https://Stackoverflow.com/users/8504208",
"pm_score": 0,
"selected": false,
"text": "$get('myId')"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] |
261,867
|
<p>I'm unable to make a remote connection to an Oracle XE install (through TOAD / SQL Developer). Here's the deal.</p>
<p>I set up a new server (windows 2003). The goal was to make a new image with several applications preinstalled, Oracle XE being one of them. Got Oracle installed no problem, connected locally, remotely and had access to the web interface - the one found at <a href="http://127.0.0.1:8081/apex" rel="noreferrer">http://127.0.0.1:8081/apex</a> (Note: I changed the port of the web interface manually as we are running our Tomcat dev environment on 8080). </p>
<p>So, everything is going swimmingly, I create the image, wipe the machine and put the newly created image on there. Everything works except Oracle. After much digging, I update the tnsnames.ora file, add environment variables ORACLE_HOME and ORACLE_SID, so I can connect locally. <b>I still can't connect remotely and have completely lost access to the web interface. I've spent 2 days on google and I'm all out of ideas. Please HELP!</b></p>
|
[
{
"answer_id": 263673,
"author": "Gary Myers",
"author_id": 25714,
"author_profile": "https://Stackoverflow.com/users/25714",
"pm_score": 2,
"selected": false,
"text": "SQLPLUS / AS SYSDBA SQLPLUS user/pass@XE sqlplus user/pass@127.0.0.1:1521/XE\n sqlplus user/pass@box_a:1521/XE\n"
},
{
"answer_id": 19714307,
"author": "perlyking",
"author_id": 1073262,
"author_profile": "https://Stackoverflow.com/users/1073262",
"pm_score": 0,
"selected": false,
"text": "/etc/hosts /etc/interfaces 127.0.0.1 localhost\n127.0.1.1 fqdn.domain.com myhost\nsta.tic.ip.address fqdn.domain.com myhost\n lnsrctl status"
},
{
"answer_id": 36012150,
"author": "Esmaeil MIRZAEE",
"author_id": 4501494,
"author_profile": "https://Stackoverflow.com/users/4501494",
"pm_score": 0,
"selected": false,
"text": "http://localhost:8080/apex/"
},
{
"answer_id": 52917453,
"author": "Johann Horvat",
"author_id": 1233925,
"author_profile": "https://Stackoverflow.com/users/1233925",
"pm_score": 1,
"selected": false,
"text": "execute dbms_xdb.setListenerLocalAccess(l_access => FALSE);\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34142/"
] |
261,873
|
<p>Here is my problem. I have a website in ASP.NET / C# which receives some data via GET/POST</p>
<p>This is "user filled" data, but not through a web page, it's a software that contacts my server.</p>
<p>Problem is, this software is sending data encoded in ISO-8859-1 (so Café would be sent as Caf%e9 ) and the rest of my SW/DB is Unicode</p>
<p>Also the data gets completely mangled, making recovery of what has been sent impossible :/</p>
<p>What would be the best way to deal with this?</p>
<p>I tried setting Request.ContentEncoding (before reading), but no avail.</p>
|
[
{
"answer_id": 264658,
"author": "Georg",
"author_id": 30776,
"author_profile": "https://Stackoverflow.com/users/30776",
"pm_score": 1,
"selected": false,
"text": "<configuration>\n <system.web>\n <globalization\n fileEncoding=\"utf-8\"\n requestEncoding=\"utf-8\"\n responseEncoding=\"utf-8\"\n culture=\"en-US\"\n uiCulture=\"de-DE\"\n />\n </system.web>\n</configuration>\n"
},
{
"answer_id": 3333105,
"author": "Dorus",
"author_id": 402027,
"author_profile": "https://Stackoverflow.com/users/402027",
"pm_score": 2,
"selected": false,
"text": "<configuration>\n <system.web>\n <globalization requestEncoding=\"iso-8859-1\"/>\n </system.web>\n</configuration>\n Request[\"varName\"]\n HttpUtility.UrlDecode HttpUtility.UrlEncode"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261873",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,904
|
<p>I'm playing about with <a href="http://en.wikipedia.org/wiki/Lighttpd" rel="nofollow noreferrer">lighttpd</a> on a small virtual private server. I two domains pointing to the server. I am using the latest version of lighttpd and mod_evhost on Ubuntu 8.10.</p>
<ol>
<li><p>I'm trying to set up a rule such that if anyone requests <strong>domain.com</strong> or <strong>www.domain.com</strong> they get served from <em>/webroot/domain.com/www/</em></p></li>
<li><p>Similarly, if anyone requests <strong>sub.domain.com</strong> they get served from <em>/webroot/domain.com/sub/</em></p></li>
<li><p>If people requests <strong>fake.domain.com</strong> (where <em>/webroot/domain.com/fake/</em> does not exist) I would like them served from <em>/webroot/domain.com/www/</em></p></li>
</ol>
<p>The third requirement isn't quite so important, I can deal with people requesting subdomains that don't exist being served from the server document root of <em>/webroot/server.com/www/</em> even if they requested <strong>fake.domain.com</strong></p>
<p>I've included the relevant parts of my lighttpd.conf file below:</p>
<pre><code>server.document-root = "/webroot/server.com/www/"
// regex to match sub.domain.com
$HTTP["host"] =~ "\b[a-zA-Z]\w*\.\b[a-zA-Z]\w*\.\b[a-zA-Z]\w*" {
evhost.path-pattern = "/webroot/%0/%3/"
}
// regex to match domain.com
$HTTP["host"] =~ "\b[a-zA-Z]\w*\.\b[a-zA-Z]\w*" {
evhost.path-pattern = "/webroot/%0/www/"
}
</code></pre>
<p>So where am I going wrong? At the moment, all requests to <strong>*.domain.com</strong> and <strong>domain.com</strong> are being served from <em>/webroot/domain.com/www/</em></p>
<p>I'd appreciate any help you guys could offer and if I've left anything relevant out please tell me!</p>
<p>Cheers,
Rob</p>
|
[
{
"answer_id": 261940,
"author": "Anders",
"author_id": 25515,
"author_profile": "https://Stackoverflow.com/users/25515",
"pm_score": 1,
"selected": false,
"text": "^\\b([wW]{3}\\.)?[\\w\\d]*\\.com\\b$"
},
{
"answer_id": 261955,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 4,
"selected": true,
"text": "// regex to match sub.domain.com\n$HTTP[\"host\"] =~ \"^[^.]+\\.[^.]+\\.[^.]+$\" {\n evhost.path-pattern = \"/webroot/%0/%3/\" \n}\n\n// regex to match domain.com \n$HTTP[\"host\"] =~ \"^[^.]+\\.[^.]+$\" {\n evhost.path-pattern = \"/webroot/%0/www/\" \n}\n [^.]+ matches anything but a dot, 1..n times\n // default: route everything to \"www\"\n$HTTP[\"host\"] =~ \"([^.]+\\.)?domain\\.com$\" {\n evhost.path-pattern = \"/webroot/%0/www/\"\n}\n\n// specific regex overwrites \"path-pattern\" for valid sub-domains only\n$HTTP[\"host\"] =~ \"^(valid1|valid2|sub)\\.domain\\.com$\" {\n evhost.path-pattern = \"/webroot/%0/%3/\" \n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/135/"
] |
261,920
|
<p>Which method is preferred?</p>
<pre><code>Session.Remove("foo");
Session["foo"] = null;
</code></pre>
<p>Is there a difference?</p>
|
[
{
"answer_id": 261980,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 4,
"selected": false,
"text": "Session.Remove"
},
{
"answer_id": 262095,
"author": "Buu",
"author_id": 17815,
"author_profile": "https://Stackoverflow.com/users/17815",
"pm_score": 8,
"selected": true,
"text": "Session.Remove(key) Session[key] = null Session#Keys"
},
{
"answer_id": 262120,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "if(Session.ContainsKey[\"foo\"]) { return Session[\"foo\"]; }\n if(Session[\"foo\"] != null) { return Session[\"foo\"]; }\n"
},
{
"answer_id": 4133360,
"author": "JakubRi",
"author_id": 501835,
"author_profile": "https://Stackoverflow.com/users/501835",
"pm_score": 5,
"selected": false,
"text": "Session[\"key\"] = null Session[key] = null; - 0.82380000000000009 ms\nSession.Remove(key); - 59.960100000000004 ms\n Session[key] = null; - 1.5368000000000002 ms\nSession.Remove(key); - 0.6621 ms\n Session[key] = null; - 1.0432000000000001 ms\nSession.Remove(key); - 33.9502 ms\n Session.Clear();\n\nfor (int i = 0; i < 1000; i++)\n Session[i.ToString()] = new object();\n\nStopwatch sw1 = Stopwatch.StartNew();\nfor (int i = 0; i < 1000; i++)\n Session[i.ToString()] = null;\nsw1.Stop();\n\nSession.Clear();\n\nfor (int i = 0; i < 1000; i++)\n Session[i.ToString()] = new object();\n\nStopwatch sw2 = Stopwatch.StartNew();\nfor (int i = 0; i < 1000; i++)\n Session.Remove(i.ToString());\nsw2.Stop();\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261920",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2469/"
] |
261,924
|
<p>I'll simplify the problem as much as possible:</p>
<p>I have an oracle table:</p>
<pre><code>row_priority, col1, col2, col3
0, .1, 100, {null}
12, {null}, {null}, 3
24, .2, {null}, {null}
</code></pre>
<p>Desired result:</p>
<pre><code>col1, col2, col3
.2, 100, 3
</code></pre>
<p>So according to the priority of the row, it overrides previous row values, if given.</p>
<p>I'm attempting to work out a solution using analytical functions over the table, but it just isn't behaving...</p>
<p>I try:</p>
<pre><code>select last_value(col1 ignore nulls) over () col1,
last_value(col2 ignore nulls) over () col2,
last_value(col3 ignore nulls) over () col3
from (select * from THE_TABLE order by row_priority)
where rownum = 1
</code></pre>
<p>or the inverse:</p>
<pre><code>select first_value(col1 ignore nulls) over () col1,
first_value(col2 ignore nulls) over () col2,
first_value(col3 ignore nulls) over () col3
from (select * from THE_TABLE order by row_priority desc)
where rownum = 1
</code></pre>
<p>And neither seem to ignore nulls. Any hints?</p>
|
[
{
"answer_id": 261941,
"author": "Alan",
"author_id": 5878,
"author_profile": "https://Stackoverflow.com/users/5878",
"pm_score": -1,
"selected": false,
"text": "select first_value(coalesce(col1,0) ignore nulls) over () col1,\n first_value(coalesce(col2,0) ignore nulls) over () col2,\n first_value(coalesce(col3,0) ignore nulls) over () col3\nfrom THE_TABLE\n"
},
{
"answer_id": 261995,
"author": "ScottCher",
"author_id": 24179,
"author_profile": "https://Stackoverflow.com/users/24179",
"pm_score": 3,
"selected": true,
"text": "SELECT *\nFROM ( select last_value(col1 ignore nulls) over () col1,\n last_value(col2 ignore nulls) over () col2,\n last_value(col3 ignore nulls) over () col3\n from (select * from THE_TABLE ORDER BY ROW_PRIORITY)\n )\nWHERE ROWNUM = 1\n COL1 COL2 COL3\n------ ------- ----\n0.2 100 3\n"
},
{
"answer_id": 262815,
"author": "Dave Costa",
"author_id": 6568,
"author_profile": "https://Stackoverflow.com/users/6568",
"pm_score": -1,
"selected": false,
"text": "SELECT\n MAX(col1) KEEP (DENSE_RANK LAST ORDER BY row_priority),\n MAX(col2) KEEP (DENSE_RANK LAST ORDER BY row_priority),\n MAX(col3) KEEP (DENSE_RANK LAST ORDER BY row_priority)\nFROM the_table\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18941/"
] |
261,927
|
<p>I have been running Apache HTTPD in 64bit mode by stripping out the 32bit architecture from the binary (along with the ppc parts). I did this to make it more compatible for python and mysql.</p>
<p>However I have another machine that needs it to be run in 32bit mode (it has all four original architectures still in it). Is it possible to make sure that it is running in 32 bit mode and that anything compiled against it uses said mode.</p>
<p>Are my options limited to stripping it, or are there start up optiosn that I do not know about.</p>
|
[
{
"answer_id": 263200,
"author": "Dave Dribin",
"author_id": 26825,
"author_profile": "https://Stackoverflow.com/users/26825",
"pm_score": 3,
"selected": true,
"text": "arch(1) % arch -i386 -ppc /usr/sbin/httpd\n"
},
{
"answer_id": 726389,
"author": "Michael Cramer",
"author_id": 1496728,
"author_profile": "https://Stackoverflow.com/users/1496728",
"pm_score": 2,
"selected": false,
"text": "sudo lipo -thin i386 /usr/sbin/httpd -output /usr/sbin/httpd.i386\n sudo vi /System/Library/LaunchDaemons/org.apache.httpd.plist\n sudo apachectl restart\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3431280/"
] |
261,938
|
<p>If everything that can be accomplished in <a href="http://en.wikipedia.org/wiki/MXML" rel="nofollow noreferrer">MXML</a> can also be accomplished in ActionScript and many things are easier to accomplish in ActionScript (loops, conditionals, etc) why take the time to learn MXML?</p>
<p>The best reasons I have at this point are that the structure of the MXML nicely matches the visual hierarchy of the UI components and that the lines of code to initialize the UI are reduced. On the other hand real-world UIs are often dynamic, implemented as a simple static structure and then filled in dynamically based on runtime conditions (in which case UI updates are in ActionScript anyway). It would also be possible to reduce the <a href="http://en.wikipedia.org/wiki/Source_lines_of_code" rel="nofollow noreferrer">SLOC</a> needed for ActionScript with the creation of a few helper methods.</p>
|
[
{
"answer_id": 522572,
"author": "Matt Guest",
"author_id": 62230,
"author_profile": "https://Stackoverflow.com/users/62230",
"pm_score": 4,
"selected": false,
"text": "<mx:Panel xmlns:mx=\"http://www.adobe.com/2006/mxml\" layout=\"absolute\" width=\"290\" height=\"148\" title=\"Login\">\n <mx:Label text=\"User name:\" width=\"80\" textAlign=\"right\" y=\"8\" x=\"8\"/>\n <mx:Label text=\"Password:\" width=\"80\" textAlign=\"right\" y=\"38\" x=\"8\"/>\n <mx:TextInput id=\"txtUsername\" maxChars=\"20\" y=\"8\" x=\"90\"/>\n <mx:TextInput id=\"txtPassword\" displayAsPassword=\"true\" y=\"38\" x=\"90\" maxChars=\"20\"/>\n <mx:Button x=\"185\" y=\"68\" label=\"Login\" id=\"btnLogin\" click=\"doLogin()\"/>\n</mx:Panel>\n package\n{\n import flash.events.MouseEvent;\n\n import mx.containers.Panel;\n import mx.controls.Button;\n import mx.controls.Label;\n import mx.controls.TextInput;\n\n public class MyLoginPanel extends Panel\n {\n\n private var _unLabel:Label;\n private var _passLabel:Label;\n private var _txtUsername:TextInput;\n private var _txtPassword:TextInput;\n private var _btnLogin:Button;\n\n public function MyLoginPanel()\n {\n }\n\n override protected function createChildren():void\n {\n super.createChildren();\n\n this.width = 290;\n this.height = 148;\n this.title = \"Login\";\n this.layout = \"absolute\";\n\n _unLabel = new Label();\n _unLabel.text = \"User Name:\";\n _unLabel.width = 80;\n _unLabel.setStyle(\"textAlign\", \"right\");\n _unLabel.move(8, 8);\n this.addChild(_unLabel);\n\n _passLabel = new Label();\n _passLabel.text = \"Password:\";\n _passLabel.width = 80;\n _passLabel.setStyle(\"textAlign\", \"right\");\n _passLabel.move(8, 38);\n this.addChild(_passLabel);\n\n _txtUsername = new TextInput();\n _txtUsername.move(90, 8);\n this.addChild(_txtUsername);\n\n _txtPassword = new TextInput();\n _txtPassword.move(90, 38);\n _txtPassword.displayAsPassword = true;\n this.addChild(_txtPassword);\n\n _btnLogin = new Button();\n _btnLogin.label = \"Login\";\n _btnLogin.move(185, 68);\n _btnLogin.addEventListener(MouseEvent.CLICK, doLogin);\n this.addChild(_btnLogin);\n } \n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,963
|
<p>I just noticed that you can not use standard math operators on an <code>enum</code> such as <code>++</code> or <code>+=</code>.</p>
<p>So what is the best way to iterate through all of the values in a C++ <code>enum</code>?</p>
|
[
{
"answer_id": 261986,
"author": "andreas buykx",
"author_id": 19863,
"author_profile": "https://Stackoverflow.com/users/19863",
"pm_score": 9,
"selected": true,
"text": "enum Foo {\n One,\n Two,\n Three,\n Last\n};\n\nfor ( int fooInt = One; fooInt != Last; fooInt++ )\n{\n Foo foo = static_cast<Foo>(fooInt);\n // ...\n}\n Last Last enum Foo {\n One = 1,\n Two = 9,\n Three = 4,\n Last\n};\n switch ( foo )\n{\n case One:\n // ..\n break;\n case Two: // intentional fall-through\n case Three:\n // ..\n break;\n case Four:\n // ..\n break;\n default:\n assert( ! \"Invalid Foo enum value\" );\n break;\n}\n"
},
{
"answer_id": 262030,
"author": "João Augusto",
"author_id": 6909,
"author_profile": "https://Stackoverflow.com/users/6909",
"pm_score": 4,
"selected": false,
"text": "enum enumType \n{ \n A = 0,\n B,\n C,\n enumTypeEnd\n};\n\nfor(int i=0; i<enumTypeEnd; i++)\n{\n enumType eCurrent = (enumType) i; \n}\n vector<enumType> vEnums;\n"
},
{
"answer_id": 8452271,
"author": "Mikhail Semenov",
"author_id": 653772,
"author_profile": "https://Stackoverflow.com/users/653772",
"pm_score": 2,
"selected": false,
"text": "#define for_range(_type, _param, _A1, _B1) for (bool _ok = true; _ok;)\\\nfor (_type _start = _A1, _finish = _B1; _ok;)\\\n for (int _step = 2*(((int)_finish)>(int)_start)-1;_ok;)\\\n for (_type _param = _start; _ok ; \\\n (_param != _finish ? \\\n _param = static_cast<_type>(((int)_param)+_step) : _ok = false))\n enum Count { zero, one, two, three }; \n\n for_range (Count, c, zero, three)\n {\n cout << \"forward: \" << c << endl;\n }\n for_range (unsigned, i, 10,0)\n{\n cout << \"backwards i: \" << i << endl;\n}\n\n\nfor_range (char, c, 'z','a')\n{\n cout << c << endl;\n}\n unsigned p[4][5];\n\nfor_range (Count, i, zero,three)\n for_range(unsigned int, j, 4, 0)\n { \n p[i][j] = static_cast<unsigned>(i)+j;\n }\n"
},
{
"answer_id": 17077835,
"author": "Riot",
"author_id": 1678468,
"author_profile": "https://Stackoverflow.com/users/1678468",
"pm_score": 3,
"selected": false,
"text": "++ + int enum class myenumtype {\n MYENUM_FIRST,\n MYENUM_OTHER,\n MYENUM_LAST\n}\n\nfor(myenumtype myenum = myenumtype::MYENUM_FIRST;\n myenum != myenumtype::MYENUM_LAST;\n myenum = static_cast<myenumtype>(static_cast<int>(myenum) + 1)) {\n\n do_whatever(myenum)\n\n}\n"
},
{
"answer_id": 24982686,
"author": "Enzojz",
"author_id": 2040143,
"author_profile": "https://Stackoverflow.com/users/2040143",
"pm_score": 5,
"selected": false,
"text": "enum NodePosition { Primary = 0, Secondary = 1, Tertiary = 2, Quaternary = 3};\n\nconst NodePosition NodePositionVector[] = { Primary, Secondary, Tertiary, Quaternary };\n\nfor (NodePosition pos : NodePositionVector) {\n...\n}\n"
},
{
"answer_id": 26910769,
"author": "zdf",
"author_id": 1983409,
"author_profile": "https://Stackoverflow.com/users/1983409",
"pm_score": 6,
"selected": false,
"text": "#include <iostream>\n#include <algorithm>\n\nnamespace MyEnum\n{\n enum Type\n {\n a = 100,\n b = 220,\n c = -1\n };\n\n static const Type All[] = { a, b, c };\n}\n\nvoid fun( const MyEnum::Type e )\n{\n std::cout << e << std::endl;\n}\n\nint main()\n{\n // all\n for ( const auto e : MyEnum::All )\n fun( e );\n\n // some\n for ( const auto e : { MyEnum::a, MyEnum::b } )\n fun( e );\n\n // all\n std::for_each( std::begin( MyEnum::All ), std::end( MyEnum::All ), fun );\n\n return 0;\n}\n"
},
{
"answer_id": 31836401,
"author": "Francesco Chemolli",
"author_id": 2938538,
"author_profile": "https://Stackoverflow.com/users/2938538",
"pm_score": 5,
"selected": false,
"text": "enum class foo {\n one,\n two,\n three\n};\n #include <type_traits>\ntemplate < typename C, C beginVal, C endVal>\nclass Iterator {\n typedef typename std::underlying_type<C>::type val_t;\n int val;\npublic:\n Iterator(const C & f) : val(static_cast<val_t>(f)) {}\n Iterator() : val(static_cast<val_t>(beginVal)) {}\n Iterator operator++() {\n ++val;\n return *this;\n }\n C operator*() { return static_cast<C>(val); }\n Iterator begin() { return *this; } //default ctor is good\n Iterator end() {\n static const Iterator endIter=++Iterator(endVal); // cache it\n return endIter;\n }\n bool operator!=(const Iterator& i) { return val != i.val; }\n};\n typedef Iterator<foo, foo::one, foo::three> fooIterator;\n for (foo i : fooIterator() ) { //notice the parentheses!\n do_stuff(i);\n}\n"
},
{
"answer_id": 35386628,
"author": "user2407277",
"author_id": 2407277,
"author_profile": "https://Stackoverflow.com/users/2407277",
"pm_score": 1,
"selected": false,
"text": "#define inc_enum(i) ((decltype(i)) ((int)i + 1))\n\nenum enumtype { one, two, three, count};\nfor(enumtype i = one; i < count; i = inc_enum(i))\n{ \n dostuff(i); \n}\n typeof decltype"
},
{
"answer_id": 37520025,
"author": "Niels Holst",
"author_id": 2186676,
"author_profile": "https://Stackoverflow.com/users/2186676",
"pm_score": 2,
"selected": false,
"text": "enum Colour {Red, Green, Blue};\nconst Colour LastColour = Blue;\n\nColour co(0);\nwhile (true) {\n // do stuff with co\n // ...\n if (co == LastColour) break;\n co = Colour(co+1);\n}\n"
},
{
"answer_id": 38684696,
"author": "kcrossen",
"author_id": 1196801,
"author_profile": "https://Stackoverflow.com/users/1196801",
"pm_score": 0,
"selected": false,
"text": "Qt::Key shortcut_key = Qt::Key_0;\nfor (int idx = 0; etc...) {\n ....\n if (shortcut_key <= Qt::Key_9) {\n fileMenu->addAction(\"abc\", this, SLOT(onNewTab()),\n QKeySequence(Qt::CTRL + shortcut_key));\n shortcut_key = (Qt::Key) (shortcut_key + 1);\n }\n}\n"
},
{
"answer_id": 41718764,
"author": "Niki",
"author_id": 1894559,
"author_profile": "https://Stackoverflow.com/users/1894559",
"pm_score": 4,
"selected": false,
"text": " enum EMyEnum\n {\n E_First,\n E_Orange = E_First,\n E_Green,\n E_White,\n E_Blue,\n E_Last\n }\n\n for (EMyEnum i = E_First; i < E_Last; i = EMyEnum(i + 1))\n {}\n enum EAnimalCaps\n {\n E_None = 0,\n E_First = 0x1,\n E_CanFly = E_First,\n E_CanWalk = 0x2\n E_CanSwim = 0x4,\n E_Last\n }\n \n class MyAnimal\n {\n EAnimalCaps m_Caps;\n }\n\n class Frog\n {\n Frog() : \n m_Caps(EAnimalCaps(E_CanWalk | E_CanSwim))\n {}\n }\n\n for (EAnimalCaps= E_First; i < E_Last; i = EAnimalCaps(i << 1))\n {}\n"
},
{
"answer_id": 49296191,
"author": "mathreadler",
"author_id": 5108790,
"author_profile": "https://Stackoverflow.com/users/5108790",
"pm_score": -1,
"selected": false,
"text": "enum MyEnumType{Hay=12,Grass=42,Beer=39};\n int Array[] = {Hay,Grass,Beer,-1};\n\nfor (int h = 0; Array[h] != -1; h++){\n doStuff( (MyEnumType) Array[h] );\n}\n"
},
{
"answer_id": 53214460,
"author": "Ethan Bradford",
"author_id": 5277967,
"author_profile": "https://Stackoverflow.com/users/5277967",
"pm_score": 2,
"selected": false,
"text": "enum Bar {\n One = 1,\n Two,\n Three,\n End_Bar // Marker for end of enum; \n};\n\nfor (Bar foo = One; foo < End_Bar; foo = Bar(foo + 1))\n{\n // ...\n}\n"
},
{
"answer_id": 56332539,
"author": "Eponymous",
"author_id": 309334,
"author_profile": "https://Stackoverflow.com/users/309334",
"pm_score": 3,
"selected": false,
"text": "enum class A {\n a0=0, a3=3, a4=4\n};\nconstexpr std::array<A, 3> ALL_A {A::a0, A::a3, A::a4}; // constexpr is important here\n\nfor(A a: ALL_A) {\n if(a==A::a0 || a==A::a4) std::cout << static_cast<int>(a);\n}\n constexpr std::array g++ -O3 if"
},
{
"answer_id": 57023705,
"author": "marski",
"author_id": 10450868,
"author_profile": "https://Stackoverflow.com/users/10450868",
"pm_score": 3,
"selected": false,
"text": "enum Item { Man, Wolf, Goat, Cabbage }; // or enum class\n\nfor (auto item : {Wolf, Goat, Cabbage}) { // or Item::Wolf, ...\n // ...\n}\n"
},
{
"answer_id": 57068588,
"author": "Justin Moloney",
"author_id": 11795459,
"author_profile": "https://Stackoverflow.com/users/11795459",
"pm_score": 0,
"selected": false,
"text": "typedef enum{\n first = 2,\n second = 6,\n third = 17\n}MyEnum;\n\nstatic const int enumItems[] = {\n first,\n second,\n third\n}\n\nstatic const int EnumLength = sizeof(enumItems) / sizeof(int);\n\nfor(int i = 0; i < EnumLength; i++){\n //Do something with enumItems[i]\n}\n"
},
{
"answer_id": 58983366,
"author": "LAL",
"author_id": 2432790,
"author_profile": "https://Stackoverflow.com/users/2432790",
"pm_score": 1,
"selected": false,
"text": "operator++ enum enum #include <iostream>\nenum class Colors{red, green, blue};\nColors& operator++(Colors &c, int)\n{\n switch(c)\n {\n case Colors::red:\n return c=Colors::green;\n case Colors::green:\n return c=Colors::blue;\n case Colors::blue:\n return c=Colors::red; // managing overflow\n default:\n throw std::exception(); // or do anything else to manage the error...\n }\n}\n\nint main()\n{\n Colors c = Colors::red;\n // casting in int just for convenience of output. \n std::cout << (int)c++ << std::endl;\n std::cout << (int)c++ << std::endl;\n std::cout << (int)c++ << std::endl;\n std::cout << (int)c++ << std::endl;\n std::cout << (int)c++ << std::endl;\n return 0;\n}\n enum class enum enum class"
},
{
"answer_id": 63000998,
"author": "Ben",
"author_id": 874660,
"author_profile": "https://Stackoverflow.com/users/874660",
"pm_score": 0,
"selected": false,
"text": "// Common/EnumTools.h\n#pragma once\n\n#include <array>\n\nnamespace Common {\n\n// Here we forward-declare metafunction for mapping enums to their values.\n// Since C++<23 doesn't have reflection, you have to populate it yourself :-(\n// Usage: After declaring enum class E, add this overload in the namespace of E:\n// inline constexpr auto allValuesArray(const E&, Commob::EnumAllValuesTag) { return std::array{E::foo, E::bar}; }\n// Then `AllValues<NS::E>` will call `allValuesArray(NS::E{}, EnumAllValuesTag)` which will resolve\n// by ADL.\n// Just be sure to keep it sync'd with your enum!\n\n// Here's what you want to use in, e.g., loops: \"for (auto val : Common::AllValues<MyEnum>) {\"\n\nstruct EnumAllValuesTag {}; // So your allValuesArray function is clearly associated with this header.\n\ntemplate <typename Enum>\nstatic inline constexpr auto AllValues = allValuesArray(Enum{}, EnumAllValuesTag{});\n// ^ Just \"constexpr auto\" or \"constexpr std::array<Enum, allValuesArray(Enum{}, EnumAllValuesTag{}).size()>\" didn't work on all compilers I'm using, but this did.\n\n} // namespace Common\n #include \"Common/EnumTools.h\"\n\nnamespace MyNamespace {\n\nenum class MyEnum {\n foo,\n bar = 4,\n baz = 42,\n};\n\n// Making this not have to be in the `Common` namespace took some thinking,\n// but is a critical feature since otherwise there's no hope in keeping it sync'd with the enum.\ninline constexpr auto allValuesArray(const MyEnum&, Common::EnumAllValuesTag) {\n return std::array{ MyEnum::foo, MyEnum::bar, MyEnum::baz };\n}\n\n} // namespace MyNamespace\n for (const auto& e : Common::AllValues<MyNamespace::MyEnum>) { ... }\n namespace YourNS {\nusing E = MyNamespace::MyEnum;\n} // namespace YourNS\n\nfor (const auto& e : Common::AllValues<YourNS::E>) { ... }\n constexpr Common::AllValues<E> Common::AllDistinctValues<E> enum { foo = 0, bar = 0 }; switch enum allValuesArray"
},
{
"answer_id": 64147276,
"author": "Scott M",
"author_id": 4492824,
"author_profile": "https://Stackoverflow.com/users/4492824",
"pm_score": 1,
"selected": false,
"text": "//create a, b, c, d as 0, 5, 6, 7\n#define LIST x(a) x(b,=5) x(c) x(d)\n#define x(n, ...) n __VA_ARGS__,\nenum MyEnum {LIST}; //define the enum\n#undef x //needed\n#define x(n,...) n ,\nMyEnum myWalkableEnum[] {LIST}; //define an iterable list of enum values\n#undef x //neatness\n\nint main()\n{\n std::cout << d;\n for (auto z : myWalkableEnum)\n std::cout << z;\n}\n//outputs 70567\n"
},
{
"answer_id": 65834483,
"author": "SylvainD",
"author_id": 1104488,
"author_profile": "https://Stackoverflow.com/users/1104488",
"pm_score": -1,
"selected": false,
"text": " for (int i = MYTYPE_MIN; i <= MYTYPE_MAX; i++) {\n if (MYTYPE_IsValid(i)) {\n MYTYPE value = (MYTYPE)i;\n // DoStuff(value)\n } \n } \n \n"
},
{
"answer_id": 67659256,
"author": "Aryaman Gupta",
"author_id": 6381133,
"author_profile": "https://Stackoverflow.com/users/6381133",
"pm_score": 2,
"selected": false,
"text": "enum E {\n E1 = 4,\n E2 = 8,\n // ..\n En\n};\n\nconstexpr std::initializer_list<E> all_E = {E1, E2, /*..*/ En};\n for (auto e : all_E) {\n // Do job with e\n}\n"
},
{
"answer_id": 69774217,
"author": "Gabriel Staples",
"author_id": 4561887,
"author_profile": "https://Stackoverflow.com/users/4561887",
"pm_score": 2,
"selected": false,
"text": "enum enum class -Wall -Wextra -Werror switch switch default -Wall -Wextra -Werror enum typedef enum my_error_type_e \n{\n MY_ERROR_TYPE_SOMETHING_1 = 0,\n MY_ERROR_TYPE_SOMETHING_2,\n MY_ERROR_TYPE_SOMETHING_3,\n MY_ERROR_TYPE_SOMETHING_4,\n MY_ERROR_TYPE_SOMETHING_5,\n /// Not a valid value; this is the number of members in this enum\n MY_ERROR_TYPE_count,\n // helpers for iterating over the enum\n MY_ERROR_TYPE_begin = 0,\n MY_ERROR_TYPE_end = MY_ERROR_TYPE_count,\n} my_error_type_t;\n enum my_error_type_t \n{\n MY_ERROR_TYPE_SOMETHING_1 = 0,\n MY_ERROR_TYPE_SOMETHING_2,\n MY_ERROR_TYPE_SOMETHING_3,\n MY_ERROR_TYPE_SOMETHING_4,\n MY_ERROR_TYPE_SOMETHING_5,\n /// Not a valid value; this is the number of members in this enum\n MY_ERROR_TYPE_count,\n // helpers for iterating over the enum\n MY_ERROR_TYPE_begin = 0,\n MY_ERROR_TYPE_end = MY_ERROR_TYPE_count,\n};\n my_error_type++ my_error_type = (my_error_type_t)(my_error_type + 1) my_error_type + 1 int my_error_type = (my_error_type_t)((int)my_error_type + 1) for (my_error_type_t my_error_type = MY_ERROR_TYPE_begin; \n my_error_type < MY_ERROR_TYPE_end;\n my_error_type = (my_error_type_t)(my_error_type + 1)) \n{\n switch (my_error_type) \n {\n case MY_ERROR_TYPE_SOMETHING_1:\n break;\n case MY_ERROR_TYPE_SOMETHING_2:\n break;\n case MY_ERROR_TYPE_SOMETHING_3:\n break;\n case MY_ERROR_TYPE_SOMETHING_4:\n break;\n case MY_ERROR_TYPE_SOMETHING_5:\n break;\n case MY_ERROR_TYPE_count:\n // This case will never be reached.\n break;\n }\n}\n enum class enum class my_error_type_t\n{\n SOMETHING_1 = 0,\n SOMETHING_2,\n SOMETHING_3,\n SOMETHING_4,\n SOMETHING_5,\n /// Not a valid value; this is the number of members in this enum\n count,\n // helpers for iterating over the enum\n begin = 0,\n end = count,\n};\n (size_t) (int) enum class static_cast<my_error_type_t> (my_error_type_t) for (my_error_type_t my_error_type = my_error_type_t::begin; \n my_error_type < my_error_type_t::end;\n my_error_type = static_cast<my_error_type_t>((size_t)my_error_type + 1)) \n{\n switch (my_error_type) \n {\n case my_error_type_t::SOMETHING_1:\n break;\n case my_error_type_t::SOMETHING_2:\n break;\n case my_error_type_t::SOMETHING_3:\n break;\n case my_error_type_t::SOMETHING_4:\n break;\n case my_error_type_t::SOMETHING_5:\n break;\n case my_error_type_t::count:\n // This case will never be reached.\n break;\n }\n}\n enum class my_error_type_t:: enum class enum enum MY_ERROR_TYPE_ enum class enum class enum class enum class enum class enum -Wall -Wextra -Werror"
},
{
"answer_id": 70449757,
"author": "jaques-sam",
"author_id": 2522849,
"author_profile": "https://Stackoverflow.com/users/2522849",
"pm_score": 0,
"selected": false,
"text": "#include <functional>\n\n/// @brief Loop over all enum values where the last enum value is the invalid one\nvoid forEachAction(std::function<void(Enum)> &&doThis) {\n for (int value = 0; value = static_cast<int>(Enum::LastValue); ++value ) {\n doThis(static_cast<Enum>(value ));\n }\n}\n\n...\n\nforEachAction([this](Enum value) {\n ... // what you want to execute for every enum\n});\n"
},
{
"answer_id": 70492798,
"author": "nathanfranke",
"author_id": 7260220,
"author_profile": "https://Stackoverflow.com/users/7260220",
"pm_score": 2,
"selected": false,
"text": "int& #include <iostream>\n\nenum MyEnum\n{\n ONE,\n TWO,\n THREE,\n FOUR,\n};\n\nint main()\n{\n for (MyEnum v = MyEnum::ONE; v <= MyEnum::FOUR; ++(int&)v)\n {\n std::cout<<v<<std::endl;\n }\n\n return 0;\n}\n 0\n1\n2\n3\n"
},
{
"answer_id": 72368235,
"author": "void",
"author_id": 6919603,
"author_profile": "https://Stackoverflow.com/users/6919603",
"pm_score": 1,
"selected": false,
"text": "#define ITEM_LIST_MACRO Wolf, Goat, Cabbage\n\nenum Item { ITEM_LIST_MACRO }; // Define the enum\n\n// Now iterate through it\nfor (auto item : { ITEM_LIST_MACRO }) {\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1366/"
] |
261,978
|
<p>I have the following JavaScript code to pop up a window in Internet Explorer. The code is executed from a page within a Microsoft CRM modal dialog box. (RequestID is a string that is always the same in the test system - at the moment it contains "abcdefg" - without the quotes).</p>
<pre><code>var cancelUrl = "CancelRequest.aspx?RequestID=" + RequestID;
alert("About to open a window.\n\n" + cancelUrl);
window.open(cancelUrl);
alert("Window opened");
</code></pre>
<p>I expect to see a message telling me that I am about to open a window. I then expect to see a window open and get another message about the window having been opened. I don't really care about the order of the last two events; the alerts are there so I know the code has been executed.</p>
<p>I have two PCs and a virtual PC. All running IE7. On the Windows 2003 VPC, the messages and pop-up appear every time without fail.</p>
<p>On the Vista PC and WinXP PC, the messages appear but the pop-up only appears intermittently. (I think this may be the case on the Vista PC too).</p>
<p>All three have identical settings in IE. All have the IE pop-up blocker disabled and have no other pop-up blockers installed.</p>
<p>Can anyone shed any light on this?</p>
|
[
{
"answer_id": 262005,
"author": "zendar",
"author_id": 25732,
"author_profile": "https://Stackoverflow.com/users/25732",
"pm_score": 0,
"selected": false,
"text": "window.open() RequestId"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261978",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21862/"
] |
261,985
|
<p>I have the following </p>
<pre><code>var id='123';
newDiv.innerHTML = "<a href=\"#\" onclick=\" TestFunction('"+id+"', false);\"></a>";
</code></pre>
<p>Which renders <code><a href="#" onclick="return Testfunction('123',false);"></a></code> in my HTML.</p>
<p>The problem I have is that I wish to take the call to the method TestFunction, and use as a string parameter in my function StepTwo(string, boolean), which would ideally end up in live HTML as shown...</p>
<pre><code><a href="#" onclick="StepTwo("TestFunction('123',false)",true)"></a>
</code></pre>
<p>notice how the TestFunction is a string here (it is executed within StepTwo using eval).</p>
<p>I have tried to format my JS as by :</p>
<pre><code>newDiv.innerHTML = "<a href=\"#\" onclick=\"StepTwo(\"TestFunction('"+id+"', false);\",true)\"></a>";
</code></pre>
<p>but while this appears to me correct in my IDE, in the rendered HTML, it as garbelled beyond belief.</p>
<p>Would appreciate if anyone could point me in the right direction. Thanks!</p>
|
[
{
"answer_id": 261999,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 2,
"selected": false,
"text": "" \" \\\" NewDiv.innerHTML = \"<a href=\\\"#\\\" onclick=\\\"StepTwo("TestFunction('\"+id+\"', false);",true)\\\"></a>\"; eval()"
},
{
"answer_id": 262010,
"author": "Gareth",
"author_id": 31582,
"author_profile": "https://Stackoverflow.com/users/31582",
"pm_score": 0,
"selected": false,
"text": "<a href=\"#\" onclick=\"StepTwo(\"></a>\n \""
},
{
"answer_id": 262033,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 3,
"selected": false,
"text": "var mya = document.createElement(\"a\");\nmya.href=\"#\"; \nmya.onclick = function(){ \n StepTwo(function(){ \n TestFunction('123', false ); \n }, true ); \n};\nnewDiv.innerHTML = \"\"; \nnewDiv.appendChild(mya);\n jQuery(function($){ \n\n var container = $(\"#container\"); \n var link = document.createElement(\"a\"); /* faster than $(\"<a></a>\"); */\n $(link).attr(\"href\", \"Something ( or # )\" ); \n $(link).click( function(){ \n var doStepTwo = function()\n { \n TestFunction('123', true ); \n };\n StepTwo( doStepTwo, false ); /* StepTwo -> doStepTwo -> TestFunction() */\n });\n container.append(link); \n}); \n"
},
{
"answer_id": 262046,
"author": "Mauricio",
"author_id": 33913,
"author_profile": "https://Stackoverflow.com/users/33913",
"pm_score": 0,
"selected": false,
"text": "document.createElement <a href=\"#\" onclick=\"StepTwo('TestFunction(\\'123\\',false)',true)\"></a> " newDiv.innerHTML = \"<a href=\\\"#\\\" onclick=\\\"StepTwo('TestFunction(\\'\"+id+\"\\', false);\\',true)\\\"></a>\";\n \\' \\\\' <input type=\"text\" value=\"foo\"bar\"> <input type=\"text\" value=\"foo\">"
},
{
"answer_id": 262092,
"author": "Gene",
"author_id": 22673,
"author_profile": "https://Stackoverflow.com/users/22673",
"pm_score": 1,
"selected": false,
"text": "<a href=\"#\" onclick=\"StepTwo(TestFunction,['123',false],true)\"></a>\n function StepTwo(func,args,flag){\n //do what ever you do with the flag\n //instead of eval use the function.apply to call the function.\n func.apply(args);\n}\n"
},
{
"answer_id": 262151,
"author": "ngn",
"author_id": 23109,
"author_profile": "https://Stackoverflow.com/users/23109",
"pm_score": 0,
"selected": false,
"text": "<a href=\"#\" onclick=\"StepTwo('TestFunction(\\'123\\', false)', true)\">...</a>\n"
},
{
"answer_id": 38287467,
"author": "Hedzer",
"author_id": 3457733,
"author_profile": "https://Stackoverflow.com/users/3457733",
"pm_score": 0,
"selected": false,
"text": "var html = '<a href=\"#\\\" onclick=\" TestFunction(\\''+id+'\\', false);\"></a>';\neval('(function(div, html){div.innerHTML = html;})')(newDiv, html);\n eval div html var myNewMethod = eval('(function(div, html){div.innerHTML = html;})');\n var myNewMethod = function(div, html){div.innerHTML = html;}\n myNewMethod(newDiv, html); //where html had the string containing markup\n Function var feval = function(code) {\n return (new Function(code))();\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28871/"
] |
261,998
|
<p>I have a list of elements (the <em>X</em> in the following examples) displayed either in a row or in a column of an HTML table.</p>
<p>In HTML code point of view, I have either (horizontal display):</p>
<pre><code><table id="myTable">
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
...
</tr>
</table>
</code></pre>
<p>or (vertical display):</p>
<pre><code><table id="myTable">
<tr>
<td>A</td>
</tr>
<tr>
<td>B</td>
</tr>
<tr>
<td>C</td>
</tr>
...
</table>
</code></pre>
<p>This HTML code is generated by a JSF component (called <code><h:selectManyCheckboxes/></code>), and thus, I have no control on this HTML code.</p>
<p>However, I want to display my list of elements in 2 columns.
In others words, the HTML code of my table will be something like that:</p>
<pre><code><table id="myTable">
<tr>
<td>A</td>
<td>B</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
</tr>
...
</table>
</code></pre>
<p>How can I do that using jQuery?</p>
<p>Thanks in advance for your help.</p>
<p>ps: If you need to know, the X are in fact an input and a label, i.e.:</p>
<pre><code><td><input .../><label .../></td>
</code></pre>
|
[
{
"answer_id": 262083,
"author": "Prestaul",
"author_id": 5628,
"author_profile": "https://Stackoverflow.com/users/5628",
"pm_score": 1,
"selected": false,
"text": "$('#myTable tr').each(function() {\n $('<td/>').append( \n $(this).find('td input') \n ).appendTo(this);\n });\n"
},
{
"answer_id": 262093,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" >\n<head>\n <title>Example of restructuring tables</title>\n <script src=\"Scripts/jquery-1.2.6.commented.js\"></script>\n</head>\n<!--<body><table id=\"Table1\">\n <tr>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n <td>4</td>\n </tr>\n</table>-->\n<table id=\"myTable\">\n <tr>\n <td>1</td>\n </tr>\n <tr>\n <td>2</td>\n </tr>\n <tr>\n <td>3</td>\n </tr>\n <tr>\n <td>4</td>\n </tr>\n</table>\n<script type=\"text/javascript\">\n $(document).ready(function() {\n debugger;\n var tds = $(\"#myTable tr td\"); // gets all td elements in the table with id myTable\n var col1 = $(\"<tr></tr>\"); // holds our first row's columns\n var col2 = $(\"<tr></tr>\"); // holds our second row's columns\n var halfway = Math.ceil(tds.length / 2);\n // add the first half of our td's to the first row, the second half to the second\n for (var i = 0; i < tds.length; i++) {\n if (i < halfway)\n col1.append(tds[i]);\n else\n col2.append(tds[i]);\n }\n // clear out the clutter from the table\n $(\"#myTable\").children().remove();\n // add our two rows\n $(\"#myTable\").append(col1);\n $(\"#myTable\").append(col2);\n });\n</script>\n</body>\n</html>\n"
},
{
"answer_id": 262624,
"author": "Prestaul",
"author_id": 5628,
"author_profile": "https://Stackoverflow.com/users/5628",
"pm_score": 3,
"selected": true,
"text": "var idx = 1;\nvar row, next;\nwhile((row = $('#myTable tr:nth-child(' + idx++ + ')')).length) {\n if((next = $('#myTable tr:nth-child(' + idx + ')')).length) {\n row.append(next.find('td'));\n next.remove();\n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26457/"
] |
262,000
|
<p>What would be the best way to check that a <code>std::vector</code> is sorted? Is there something faster than a loop checking that <code>v[i]<=v[i+1]</code>? Is it faster/cleaner with iterators? Or is it actually better to just call <code>sort</code> every time (though the "v is already sorted" case is quite common)?</p>
<p>We can safely assume the vector only contains PODs, usually <code>float</code>s and sometimes <code>double</code>s and <code>int</code>s.</p>
<p>The size of the vector is non-trivial (usually a few thousands items) but not extreme (not gigabyte-sized).</p>
<ul>
<li>in some instances we'll sort the vector immediately afterwards, however there are other instances where we don't (it's an error case of our algorithm).</li>
<li>we already use a flag "IsSorted" whenever possible.</li>
</ul>
|
[
{
"answer_id": 262088,
"author": "ShreevatsaR",
"author_id": 4958,
"author_profile": "https://Stackoverflow.com/users/4958",
"pm_score": 5,
"selected": false,
"text": "std::is_sorted is_sorted(v.begin(), v.end())\n"
},
{
"answer_id": 262105,
"author": "endian",
"author_id": 25462,
"author_profile": "https://Stackoverflow.com/users/25462",
"pm_score": 3,
"selected": false,
"text": "vector<T>"
},
{
"answer_id": 262303,
"author": "Don Wakefield",
"author_id": 3778,
"author_profile": "https://Stackoverflow.com/users/3778",
"pm_score": 0,
"selected": false,
"text": "class ObjList {\npublic:\n ObjList() {};\n ~ObjList() {};\n\n bool isMember(const Item *);\n void add(const Item *, bool sort = false);\n\nprivate:\n\n unsigned int last_sorted_d;\n\n bool sorted_d;\n unsigned int count_d;\n Item *store_d;\n};\n"
},
{
"answer_id": 890566,
"author": "newacct",
"author_id": 86989,
"author_profile": "https://Stackoverflow.com/users/86989",
"pm_score": 4,
"selected": false,
"text": "std::adjacent_find(v.begin(), v.end(), std::greater<type>()) == v.end()\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262000",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20055/"
] |
262,012
|
<p>I'm just starting to pick up ASP.Net MVC and find myself writing a lot of <%= %> in the views. Intellisense does supply the closing %>, but I find that typing the introductory <%= to be burdensome (they are tough for me to type :-)).</p>
<p>I've dabbled around a bit with Rails and the NetBeans IDE where I was able to type:</p>
<pre><code>r<tab> - which would expand to <% %>
</code></pre>
<p>and</p>
<pre><code>re<tab> - which would expand to <%= %>
</code></pre>
<p>Can something similar be done in the Visual Studio 2008 IDE?</p>
|
[
{
"answer_id": 262262,
"author": "plinth",
"author_id": 20481,
"author_profile": "https://Stackoverflow.com/users/20481",
"pm_score": 0,
"selected": false,
"text": "Imports System\nImports EnvDTE\nImports EnvDTE80\nImports EnvDTE90\nImports System.Diagnostics\n\nPublic Module Module1\n\n Private Function GetUserName() As String\n GetUserName = System.Environment.UserName\n End Function\n\n Sub InjectChangeComment()\n ActiveDocument().Selection().Text = \"// \" + System.DateTime.Now.ToString(\"MM-dd-yy\") + \" \" + GetUserName() + vbTab + vbTab + vbTab\n End Sub\n\nEnd Module\n"
},
{
"answer_id": 262452,
"author": "Chris Bowen - MSFT",
"author_id": 33173,
"author_profile": "https://Stackoverflow.com/users/33173",
"pm_score": 2,
"selected": false,
"text": "<%= %> <?xml version=\"1.0\" encoding=\"utf-8\"?>\n<CodeSnippet Format=\"1.0.0\" xmlns=\"http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet\">\n <Header>\n <Title>ASP Server Tags</Title>\n <Author>Chris Bowen</Author>\n <Shortcut>asp</Shortcut>\n <Description>ASP.NET server escape characters, including equals</Description>\n <SnippetTypes>\n <SnippetType>SurroundsWith</SnippetType>\n <SnippetType>Expansion</SnippetType>\n </SnippetTypes>\n </Header>\n <Snippet>\n <Declarations>\n <Literal>\n <ID>code</ID>\n <Default>Code</Default>\n </Literal>\n </Declarations>\n <Code Language=\"csharp\">\n <![CDATA[<%= $code$ $selected$%>$end$]]>\n </Code>\n </Snippet>\n</CodeSnippet>\n"
},
{
"answer_id": 262453,
"author": "Brian Schmitt",
"author_id": 30492,
"author_profile": "https://Stackoverflow.com/users/30492",
"pm_score": 3,
"selected": true,
"text": "Public Sub WrapMVC()\n Try\n DTE.UndoContext.Open(\"Wrap MVC\")\n Dim OutText As String = \"\"\n Dim OutFormat As String = \"<%={0} %>\"\n DTE.ActiveDocument.Selection.Text = String.Format(OutFormat, ActiveWindowSelection)\n Finally\n DTE.UndoContext.Close()\n End Try\nEnd Sub\n Friend Function ActiveWindowSelection() As String\n If DTE.ActiveWindow.ObjectKind = EnvDTE.Constants.vsWindowKindOutput Then\n Return OutputWindowSelection()\n End If\n If DTE.ActiveWindow.ObjectKind = \"{57312C73-6202-49E9-B1E1-40EA1A6DC1F6}\" Then\n Return HTMLEditorSelection()\n End If\n Return SelectionText(DTE.ActiveWindow.Selection)\nEnd Function\n\nPrivate Function HTMLEditorSelection() As String\n Dim hw As EnvDTE.HTMLWindow = ActiveDocument.ActiveWindow.Object\n Dim tw As TextWindow = hw.CurrentTabObject\n Return SelectionText(tw.Selection)\nEnd Function\n\nPrivate Function OutputWindowSelection() As String\n Dim w As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)\n Dim ow As OutputWindow = w.Object\n Dim owp As OutputWindowPane = ow.OutputWindowPanes.Item(ow.ActivePane.Name)\n Return SelectionText(owp.TextDocument.Selection)\nEnd Function\n\nPrivate Function SelectionText(ByVal sel As EnvDTE.TextSelection) As String\n If sel Is Nothing Then\n Return \"\"\n End If\n If sel.Text.Length <= 2 Then\n SelectWord(sel)\n End If\n If sel.Text.Length <= 2 Then\n Return \"\"\n End If\n Return sel.Text\nEnd Function\n\nPrivate Sub SelectWord(ByVal sel As EnvDTE.TextSelection)\n Dim leftPos As Integer\n Dim line As Integer\n Dim pt As EnvDTE.EditPoint = sel.ActivePoint.CreateEditPoint()\n\n sel.WordLeft(True, 1)\n line = sel.TextRanges.Item(1).StartPoint.Line\n leftPos = sel.TextRanges.Item(1).StartPoint.LineCharOffset\n pt.MoveToLineAndOffset(line, leftPos)\n sel.MoveToPoint(pt)\n sel.WordRight(True, 1)\nEnd Sub\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7961/"
] |
262,015
|
<p>I need to modify a (xml-)file from Apache Ant. "loadfile" task allows to load the file's content in a property. But how to store the property's value back to a file after its (property) modification?</p>
<p>Of course I could write custom task to perform this operation but I would like to know if there's some existing implementation.</p>
|
[
{
"answer_id": 262064,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 5,
"selected": true,
"text": "<echo file=\"${fileName}\" message=\"${xmlProperty}\"/>\n"
},
{
"answer_id": 9478786,
"author": "Jarekczek",
"author_id": 772981,
"author_profile": "https://Stackoverflow.com/users/772981",
"pm_score": 3,
"selected": false,
"text": "<propertyfile file=\"my.properties\">\n <entry key=\"abc\" value=\"${abc}\"/>\n</propertyfile>\n echo echo"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15647/"
] |
262,022
|
<p>Is there a website I can create an HTML final four bracket?</p>
<p>Or is there just HTML out there that will create it automatically and I can just fill in the specifics?</p>
|
[
{
"answer_id": 262584,
"author": "Brad",
"author_id": 26130,
"author_profile": "https://Stackoverflow.com/users/26130",
"pm_score": 3,
"selected": false,
"text": "table.bracket {\n border-collapse: collapse;\n border: none;\n}\n\n.bracket td {\n vertical-align: middle;\n width: 40em;\n margin: 0;\n padding: 10px;\n}\n\n.bracket td p {\n border-bottom: solid 1px black;\n margin: 0;\n padding: 5px 5px 5px 5px;\n}\n\n.bracket th{\n text-align:center;\n}\n\n<table summary=\"Tournament Bracket\" class=\"bracket\">\n<tr>\n <th>National Semi-Finals<br>Saturday November 8th</th>\n <th>National Championship<br>Sunday November 9th</th>\n <th>NJCAA National Champion</th>\n</tr>\n<tr>\n <td><p>#1 Manchester CC (17-2-1)</p></td>\n <td rowspan=\"2\"><p></p></td>\n <td rowspan=\"4\"><p></p></td>\n</tr>\n<tr>\n <td><p>#4 Triton College (13-4-0)</p></td>\n</tr>\n<tr>\n <td><p>#2 Herkimer County CC (18-3-0)</p></td>\n <td rowspan=\"2\"><p></p></td>\n</tr>\n<tr>\n <td><p>#3 County College of Morris (17-3-0)</p></td>\n</tr>\n</table>\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26130/"
] |
262,024
|
<p>Is it possible to obtain the maximum column length for a VARCHAR, CHAR etc?</p>
|
[
{
"answer_id": 262060,
"author": "TcKs",
"author_id": 20382,
"author_profile": "https://Stackoverflow.com/users/20382",
"pm_score": 1,
"selected": false,
"text": "select max_length from sys.columns as c inner join sys.objects o on c.object_id = o.object_id where o.name = 'myTable' and c.name = 'myColumn'\n"
},
{
"answer_id": 561257,
"author": "ctrlalt3nd",
"author_id": 61545,
"author_profile": "https://Stackoverflow.com/users/61545",
"pm_score": 1,
"selected": false,
"text": "public static int GetLengthLimit(Type type, string field) //definition changed so we no longer need the object reference\n//Type type = obj.GetType(); //comment this line\n int i = GetLengthLimit(typeof(Pet), \"Name\");\n"
},
{
"answer_id": 3791089,
"author": "Keith Barrows",
"author_id": 86555,
"author_profile": "https://Stackoverflow.com/users/86555",
"pm_score": 1,
"selected": false,
"text": "public static int GetLengthLimit(Model.RIVFeedsEntities ent, string table, string field)\n{\n int maxLength = 0; // default value = we can't determine the length\n\n // Connect to the meta data...\n MetadataWorkspace mw = ent.MetadataWorkspace;\n\n // Force a read of the model (just in case)...\n // http://thedatafarm.com/blog/data-access/quick-trick-for-forcing-metadataworkspace-itemcollections-to-load/\n var q = ent.Clients;\n string n = q.ToTraceString();\n\n // Get the items (tables, views, etc)...\n var items = mw.GetItems<EntityType>(DataSpace.SSpace);\n foreach (var i in items)\n {\n if (i.Name.Equals(table, StringComparison.CurrentCultureIgnoreCase))\n {\n // wrapped in try/catch for other data types that don't have a MaxLength...\n try\n {\n string val = i.Properties[field].TypeUsage.Facets[\"MaxLength\"].Value.ToString();\n int.TryParse(val, out maxLength);\n }\n catch\n {\n maxLength = 0;\n }\n break;\n }\n }\n\n return maxLength;\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262024",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,025
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/176775/big-integers-in-c-sharp">Big integers in C#</a> </p>
</blockquote>
<p>I want to be able to process arbitrarily large numbers in C#.<br>
I can live with just integers. </p>
<p>Are there established algorithms for this kind of thing?<br>
Or is there a good 3rd-party library? </p>
<p>I might consider changing language if there really is no good way to do it in C#. </p>
<p>Thanks for any help / suggestions. </p>
|
[
{
"answer_id": 262041,
"author": "kͩeͣmͮpͥ ͩ",
"author_id": 26479,
"author_profile": "https://Stackoverflow.com/users/26479",
"pm_score": 1,
"selected": false,
"text": "long decimal long decimal"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7211/"
] |
262,026
|
<p>I have an application which get copied and run on client machines. The program is in the form of an Adobe Projector file. I want to write a process that checks when the program starts running whether or not the license is still active, and if not, delete the entire program. </p>
<p>The program itself knows the real date that it was installed, and since we install the program ourselves for the clients, we can ensure that at install time the date on the client's computer matches. Every time they start up the program, it compares the current date with the date they last ran the program. If today's date is after that date, it subtracts the number of elapsed dates from the number of days remaining. If the date is before the date it was last run, it penalizes the client by a constant number of days (this is to discourage the client from trying to reset the date on the computer and have their license never expire).</p>
<p>If they were to copy the entire directory over to a new machine, the installation date inside the program would not match the created date on any of the files in the directory, and it would treat this case like an expired license.</p>
<p>My question is this: is there a simple way to script this to run every time they start the application? We currently create a shortcut which could be pointed to a batch job, but what do you put in the batch job? Or is this approach for licensing completely wrong? People who buy this program will only buy time-limited licenses, and the program is run by copying and pasting a directory onto the target machine.</p>
|
[
{
"answer_id": 262041,
"author": "kͩeͣmͮpͥ ͩ",
"author_id": 26479,
"author_profile": "https://Stackoverflow.com/users/26479",
"pm_score": 1,
"selected": false,
"text": "long decimal long decimal"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262026",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23249/"
] |
262,036
|
<p>Just wondering where is best to put functionality in an MFC application that is triggered when the whole window is resized. I was thinking mainfrm but I couldn't seem to capture any OnSize messages... </p>
<p>Can someone tell me what I am doing wrong?</p>
|
[
{
"answer_id": 262260,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 3,
"selected": true,
"text": "WM_SIZE WM_WINDOWPOSCHANGED WM_SIZE"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18664/"
] |
262,043
|
<p>I am trying to do something like this:</p>
<pre><code>while @nrOfAuthlevels >= @myAuthLevel
begin
set @myAuthLevel = @myAuthLevel + 1
SELECT Role.name, Role.authorityLevel
FROM [dbo].[Role]
ORDER BY Role.authorityLevel
end
</code></pre>
<p>The result of this stored procedure shall be a table with all Role.authorityLevel below my own. But this generates several tables.</p>
|
[
{
"answer_id": 262057,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 1,
"selected": false,
"text": "create table #tmp (\n Name type,\n authorityLevel type\n)\n\nwhile @nrOfAuthlevels >= @myAuthLevel\nbegin\n set @myAuthLevel = @myAuthLevel + 1 \n insert into #tmp values(\n SELECT Role.name, Role.authorityLevel\n FROM [dbo].[Role]\n where ...\n )\nend\n"
},
{
"answer_id": 262058,
"author": "Stephen Wrighton",
"author_id": 7516,
"author_profile": "https://Stackoverflow.com/users/7516",
"pm_score": 3,
"selected": false,
"text": "SELECT Role.Name, Role.AuthorityLevel\n FROM dbo.Role\n WHERE Role.AuthorityLevel < @MyAuthLevel\n ORDER BY Role.AuthorityLevel\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,075
|
<p>The following doesn't work, but something like this is what I'm looking for.</p>
<pre><code>select *
from Products
where Description like (@SearchedDescription + %)
</code></pre>
<p>SSRS uses the @ operator in-front of a parameter to simulate an 'in', and I'm not finding a way to match up a string to a list of strings.</p>
|
[
{
"answer_id": 278959,
"author": "Pulsehead",
"author_id": 2156,
"author_profile": "https://Stackoverflow.com/users/2156",
"pm_score": 0,
"selected": false,
"text": "select * from Products where Description like (@SearchedDescription + '%')"
},
{
"answer_id": 296817,
"author": "Registered User",
"author_id": 38332,
"author_profile": "https://Stackoverflow.com/users/38332",
"pm_score": 3,
"selected": true,
"text": " SELECT name\n FROM master.dbo.sysobjects\n WHERE name LIKE @ReportParameter1\n sysallocunits\n sysaudacts\n sysasymkeys\n sysaltfiles\n DECLARE @DynamicSQL NVARCHAR(MAX) \n\n SET @DynamicSQL = \n 'SELECT name, id, xtype\n FROM dbo.sysobjects\n WHERE name LIKE ''' + @ReportParameter1 + '%''\n '\n\n EXEC (@DynamicSQL)\n"
},
{
"answer_id": 1686379,
"author": "Pradeep sharma",
"author_id": 204632,
"author_profile": "https://Stackoverflow.com/users/204632",
"pm_score": 0,
"selected": false,
"text": "select * \nfrom tsStudent \nwhere studentName like @SName+'%'\n"
},
{
"answer_id": 52488317,
"author": "Jeff Breadner",
"author_id": 4187907,
"author_profile": "https://Stackoverflow.com/users/4187907",
"pm_score": 0,
"selected": false,
"text": "=JOIN(@SearchedDedscription, \",\") ;with\nSearchTerms as (\n select distinct\n Value\n from \n string_split(@SearchedDescription, ',')\n)\nselect distinct\n *\nfrom\n Products\n inner join SearchTerms on\n Products.Description like SearchTerms.Value + '%'\n distinct"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26938/"
] |
262,090
|
<p>Calling all PHP gurus!</p>
<p>I understand that you can use getimagesize() to get the actual pixel height and width of an image in PHP. However, if you open an image in photoshop and look at the image size dialog, you notice that there is a resolution value that determines the print size of the image.</p>
<p>Given an arbitrary jpg image file, I need to use PHP to determine this resolution number. It appears that this information is stored in the jpg file somewhere, so how do I get to it?</p>
<p>One other requirement - I only have gdlib available to me. I need to do this without the use of other php libraries (imagemagick, etc.)</p>
<p>Thanks for the help!</p>
|
[
{
"answer_id": 262393,
"author": "Rafe",
"author_id": 27497,
"author_profile": "https://Stackoverflow.com/users/27497",
"pm_score": 2,
"selected": false,
"text": "<?php\n\ninclude_once(\"./JPEG.php\");\ninclude_once(\"./JFIF.php\");\n\n$image_header = get_jpeg_header_data(\"./myImage.jpg\");\n$image_info = get_JFIF($image_header);\n\nprint( \"XDensity:\" . $image_info['XDensity'] . \"<br />\");\nprint( \"YDensity:\" . $image_info['YDensity'] . \"<br />\");\n\n?>\n"
},
{
"answer_id": 7309802,
"author": "bleater",
"author_id": 316487,
"author_profile": "https://Stackoverflow.com/users/316487",
"pm_score": 3,
"selected": false,
"text": "function read_JFIF_dpi($filename)\n{\n $dpi = 0;\n $fp = @fopen($filename, r);\n if ($fp) {\n if (fseek($fp, 6) == 0) { // JFIF often (but not always) starts at offset 6.\n if (($bytes = fread($fp, 16)) !== false) { // JFIF header is 16 bytes.\n if (substr($bytes, 0, 4) == \"JFIF\") { // Make sure it is JFIF header.\n $JFIF_density_unit = ord($bytes[7]);\n $JFIF_X_density = ord($bytes[8])*256 + ord($bytes[9]); // Read big-endian unsigned short int.\n $JFIF_Y_density = ord($bytes[10])*256 + ord($bytes[11]); // Read big-endian unsigned short int.\n if ($JFIF_X_density == $JFIF_Y_density) { // Assuming we're only interested in JPEGs with square pixels.\n if ($JFIF_density_unit == 1) $dpi = $JFIF_X_density; // Inches.\n else if ($JFIF_density_unit == 2) $dpi = $JFIF_X_density * 2.54; // Centimeters.\n }\n }\n }\n }\n fclose($fp);\n }\n return ($dpi);\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27497/"
] |
262,106
|
<p>What happen when SQL Server 2005 happen to reach the maximum for an IDENTITY column? Does it start from the beginning and start refilling the gap? </p>
<p>What is the behavior of SQL Server 2005 when it happen?</p>
|
[
{
"answer_id": 262123,
"author": "xsl",
"author_id": 11387,
"author_profile": "https://Stackoverflow.com/users/11387",
"pm_score": 5,
"selected": true,
"text": "9,223,372,036,854,775,807 Msg 220, Level 16, State 2, Line 10\nArithmetic overflow error for data type tinyint, value = 256.\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24975/"
] |
262,108
|
<p>I am creating an application which displays some messages and its directions in the DataGridView. I would like to replace some columns content with pictures. For example I would like to replace number 0 which represents the incoming call with a green arrow (some .jpg image).</p>
<p>Does anyone know how this could be achieved?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 813815,
"author": "JJO",
"author_id": 99141,
"author_profile": "https://Stackoverflow.com/users/99141",
"pm_score": 2,
"selected": true,
"text": " private void messageInfoDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)\n {\n // Is this the correct column? (It's actually a DataGridViewImageColumn)\n if (messageInfoDataGridView.Columns[e.ColumnIndex] == messageSeverityDataGridViewTextBoxColumn)\n {\n // Get the row we're formatting\n DataGridViewRow row = messageInfoDataGridView.Rows[e.RowIndex];\n // Get the enum from the row.\n MessageSeverity severity = ((MessageInfo)row.DataBoundItem).MessageSeverity;\n Bitmap cellValueImage;\n // Map the enumerated type to an image...\n // SeverityImageMap is a Dictionary<MessageSeverity,Bitmap>.\n if (ReferenceTables.SeverityImageMap.ContainsKey(severity))\n cellValueImage = ReferenceTables.SeverityImageMap[severity];\n else\n cellValueImage = Resources.NoAction;\n\n // Set the event args.\n e.Value = cellValueImage;\n e.FormattingApplied = true;\n }\n }\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262108",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22996/"
] |
262,110
|
<p>Ok, the more I use LINQ, the more I like it! I recently found myself working in some legacy code at work. It is your classic DataSet and DataTable rich application. Well, when adding a bit of functionality I found myself <em>really</em> wanting to just query the rows of a DataTable for the results I was looking for.</p>
<p>Let me repeat that... instead of looping and adding to a temp collection, I just wanted to ask the Rows collection for what I needed. No looping, no temp variables, just give me what I want.</p>
<pre><code>var customerOrderIds = table.Rows.Cast<DataRow>()
.Where(x => (string)x["CUSTOMER_ID"] == customerId)
.Select(x => (string)x["CUSTOMER_ORDER_ID"])
.Distinct();
</code></pre>
<p><strong>My question is whether or not this is a good thing, or am getting carried away with LINQ?</strong> It does seem to me that this declarative style of pulling a subset of data out of a collection is a good thing and more readable in the end. But then again, maybe I'm just smitten :)</p>
|
[
{
"answer_id": 262167,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": true,
"text": "Field<> var customerOrderIds = table.Rows.Cast<DataRow>()\n .Where(x => x.Field<string>(\"CUSTOMER_ID\") == customerId)\n .Select(x => x.Field<string>(\"CUSTOMER_ORDER_ID\"))\n .Distinct();\n var customerOrderIds = (\n from row in table.Rows.Cast<DataRow>()\n where row.Field<string>(\"CUSTOMER_ID\") == customerId\n select row.Field<string>(\"CUSTOMER_ORDER_ID\")\n ).Distinct();\n DataTable"
},
{
"answer_id": 1245464,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "O(M+N) from x in Xs\nfrom y in Ys\n .Where(o => o == x)\nselect new\n{\n x,\n y\n}\n O(M*N)"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2595/"
] |
262,141
|
<p>I have a image button. I wanted to add a text "Search" on it. I am not able to add it because the "imagebutton" property in VS 2008 does not have text control in it. Can anyone tell me how to add text to a image button?? </p>
<pre><code> <asp:ImageButton ID="Searchbutton" runat="server" AlternateText="Search"
CssClass="bluebutton"
ImageUrl="../Graphics/bluebutton.gif" Width="110px"
onclick="Searchbutton_Click"/>
</code></pre>
|
[
{
"answer_id": 262171,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 5,
"selected": true,
"text": "<button runat=\"server\" \n style=\"background-image:url('/Content/Img/stackoverflow-logo-250.png')\" >\n your text here<br/>and some more<br/><br/> and some more ....\n </button>\n"
},
{
"answer_id": 262173,
"author": "Marek Blotny",
"author_id": 33744,
"author_profile": "https://Stackoverflow.com/users/33744",
"pm_score": 3,
"selected": false,
"text": "ImageButton Button"
},
{
"answer_id": 1658527,
"author": "Khanzor",
"author_id": 68268,
"author_profile": "https://Stackoverflow.com/users/68268",
"pm_score": 0,
"selected": false,
"text": "<style type=\"text/css\">\n .faux-button\n {\n cursor:pointer;\n }\n</style>\n\n<div class=\"faux-button\">\n <asp:ImageButton ID=\"ibtnAddUser\" \n runat=\"server\" \n ImageUrl=\"~/Images/add.gif\" \n AlternateText=\"Add a user image\" />\n <asp:Label ID=\"lblAddUser\" \n runat=\"server\" \n Text=\"Add User\" \n AssociatedControlID=\"imgClick\" />\n</div>\n"
},
{
"answer_id": 4429329,
"author": "Iman",
"author_id": 184572,
"author_profile": "https://Stackoverflow.com/users/184572",
"pm_score": 3,
"selected": false,
"text": "<asp:LinkButton \n CssClass=\"lnkSubmit\" \n ID=\"lnkButton\" \n runat=\"server\">SUBMIT</asp:LinkButton>\n\na.lnkSubmit:active\n{ \n margin:0px 0px 0px 0px;\n background:url(../../images/li_bg1.jpg) left center no-repeat;\n padding: 0em 1.2em;\n font: 8pt \"tahoma\";\n color: #336699;\n text-decoration: none;\n font-weight: normal;\n letter-spacing: 0px;\n"
},
{
"answer_id": 9173554,
"author": "Etherman",
"author_id": 1075062,
"author_profile": "https://Stackoverflow.com/users/1075062",
"pm_score": 0,
"selected": false,
"text": "<button> <img src=\"button_icon.png\" /> Caption Text </button>\n [DefaultProperty(\"Text\")]\n[DefaultEvent(\"Click\")]\n[ToolboxData(\"<{0}:ImgButton runat=server></{0}:ImgButton>\")]\npublic class ImgButton : WebControl, IPostBackEventHandler\n{\n #region Public Properties\n\n public enum ImgButtonStyle\n {\n Button,\n Anchor\n }\n\n [Bindable(true)]\n [Category(\"Appearance\")]\n [DefaultValue(\"\")]\n [Localizable(true)]\n public string Text\n {\n get\n {\n String s = (String)ViewState[\"Text\"];\n return ((s == null) ? String.Empty : s);\n }\n\n set\n {\n ViewState[\"Text\"] = value;\n }\n }\n [EditorAttribute(typeof(System.Web.UI.Design.ImageUrlEditor), typeof(UITypeEditor))]\n public string ImgSrc { get; set; }\n public string CommandName { get; set; }\n public string CommandArgument { get; set; }\n [EditorAttribute(typeof(System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]\n public string NavigateUrl { get; set; }\n public string OnClientClick { get; set; }\n public ImgButtonStyle RenderStyle { get; set; }\n [DefaultValue(true)]\n public bool UseSubmitBehavior { get; set; }\n [DefaultValue(true)]\n public bool CausesValidation { get; set; }\n public string ValidationGroup { get; set; }\n [DefaultValue(0)]\n public int Tag { get; set; }\n\n #endregion\n\n #region Constructor\n\n public ImgButton()\n {\n Text = \"Text\";\n ImgSrc = \"~/Masters/_default/img/action-help.png\";\n UseSubmitBehavior = true;\n CausesValidation = true;\n }\n\n #endregion\n\n #region Events\n\n // Defines the Click event.\n public event EventHandler Click;\n public event CommandEventHandler Command;\n\n protected virtual void OnClick(EventArgs e)\n {\n if (Click != null)\n {\n Click(this, e);\n }\n }\n\n protected virtual void OnCommand(CommandEventArgs e)\n {\n if (Command != null)\n {\n Command(this, e);\n }\n RaiseBubbleEvent(this, e);\n }\n\n public void RaisePostBackEvent(string eventArgument)\n {\n if (CausesValidation)\n {\n Page.Validate(ValidationGroup);\n if (!Page.IsValid) return;\n }\n OnClick(EventArgs.Empty);\n if (!String.IsNullOrEmpty(CommandName))\n OnCommand(new CommandEventArgs(CommandName, CommandArgument));\n }\n\n #endregion\n\n #region Rendering\n\n // Do not wrap in <span> tag\n public override void RenderBeginTag(HtmlTextWriter writer)\n {\n writer.Write(\"\");\n }\n\n protected override void RenderContents(HtmlTextWriter output)\n {\n string click;\n string disabled = (Enabled ? \"\" : \"disabled \");\n string type = (String.IsNullOrEmpty(NavigateUrl) && UseSubmitBehavior ? \"submit\" : \"button\");\n string imgsrc = ResolveUrl(ImgSrc ?? \"\");\n\n if (String.IsNullOrEmpty(NavigateUrl))\n click = Page.ClientScript.GetPostBackEventReference(this, \"\");\n else\n if (NavigateUrl != null)\n click = String.Format(\"location.href='{0}'\", ResolveUrl(NavigateUrl));\n else\n click = OnClientClick;\n\n switch (RenderStyle)\n {\n case ImgButtonStyle.Button:\n if (String.IsNullOrEmpty(NavigateUrl) && UseSubmitBehavior)\n {\n output.Write(String.Format(\n \"<button id=\\\"{0}\\\" {1}class=\\\"{2}\\\" type=\\\"{3}\\\" name=\\\"{4}\\\" title=\\\"{5}\\\"><img src=\\\"{6}\\\" alt=\\\"{5}\\\"/>{7}</button>\",\n ClientID,\n disabled,\n CssClass,\n type,\n UniqueID,\n ToolTip,\n imgsrc,\n Text\n ));\n }\n else\n {\n output.Write(String.Format(\n \"<button id=\\\"{0}\\\" {1}class=\\\"{2}\\\" type=\\\"{3}\\\" name=\\\"{4}\\\" onclick=\\\"javascript:{5}\\\" title=\\\"{6}\\\"><img src=\\\"{7}\\\" alt=\\\"{6}\\\"/>{8}</button>\",\n ClientID,\n disabled,\n CssClass,\n type,\n UniqueID,\n click,\n ToolTip,\n imgsrc,\n Text\n ));\n }\n break;\n\n case ImgButtonStyle.Anchor:\n output.Write(String.Format(\n \"<a id=\\\"{0}\\\" {1}class=\\\"{2}\\\" onclick=\\\"javascript:{3}\\\" title=\\\"{4}\\\"><img src=\\\"{5}\\\" alt=\\\"{4}\\\"/>{6}</a>\",\n ID,\n disabled,\n CssClass,\n click,\n ToolTip,\n imgsrc,\n Text\n ));\n break;\n }\n }\n\n public override void RenderEndTag(HtmlTextWriter writer)\n {\n writer.Write(\"\");\n }\n\n #endregion\n}\n button.icon\n{\n cursor: pointer;\n}\n\nbutton.icon img\n{\n margin: 0px;\n padding: 0px 5px 0px 5px;\n vertical-align: middle;\n}\n"
},
{
"answer_id": 45662886,
"author": "megabc123",
"author_id": 8458805,
"author_profile": "https://Stackoverflow.com/users/8458805",
"pm_score": 0,
"selected": false,
"text": "<asp:LinkButton id=\"download\" CssClass=\"btn btn-primary\" Text=\"Download\" OnCommand=\"OnButtonClick\" CommandName=\"Download\" runat=\"server\">\n <span aria-hidden=\"true\" class=\"glyphicon glyphicon-download-alt\"></span></asp:LinkButton>\n #MainContent_download:after{ \ncontent: \"Download\"; \npadding-left: 5px;\n"
},
{
"answer_id": 56633676,
"author": "nes",
"author_id": 4638823,
"author_profile": "https://Stackoverflow.com/users/4638823",
"pm_score": 0,
"selected": false,
"text": " <div style=\"padding: 5px; float: left;overflow: auto;height: auto;\">\n <asp:ImageButton ID=\"ImageButton2\" ImageUrl=\"./icons/search24.png\" ToolTip=\"Search\" runat=\"server\" />\n <p><asp:Label ID=\"Label7\" runat=\"server\" Text=\"Search\"></asp:Label></p>\n </div>\n style"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,143
|
<p>I have a html string held in memory after transforming to my desired template with XSLT. What is the best mechanism to the send this to the client printer? </p>
<p>In previous projects I have shamelessly cheated and created a print preview screen, which was essentially an ASPX page with white background that I then printed using <code>Window.print()</code>.</p>
<p>Cheers</p>
|
[
{
"answer_id": 262199,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": ".showwhenprinting {position:absolute; display:none;}\n@media print\n{\n .hidewhenprinting {position:absolute; display:none;}\n .showwhenprinting {position:relative; display:block;}\n}\n <div class=\"someclass hidewhenprinting\">Navigation Menu</div>\n<div class=\"someclass showwhenprinting\">Printed Page Title</div>\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262143",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11802/"
] |
262,150
|
<p>I have a page where my combo box has hundreds of elements which makes it very hard to pick the one item I want. Is there a good Javascript replacement that would do better than</p>
<pre><code><select id="field-component" name="field_component">
<option selected="selected">1</option><option>2</option>...
</select>
</code></pre>
<p>Is there something with "Intellisense"-like auto-complete?</p>
|
[
{
"answer_id": 263654,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 3,
"selected": false,
"text": "<input type=text list=listid>\n<datalist id=listid>\n <select><option>1<option>2</select>\n</datalist>\n"
},
{
"answer_id": 18116080,
"author": "David Schwartz",
"author_id": 399124,
"author_profile": "https://Stackoverflow.com/users/399124",
"pm_score": 0,
"selected": false,
"text": "typeahead.js"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6583/"
] |
262,156
|
<p>I try to get rounded corners on a UIImage, what I read so far, the easiest way is to use a mask images. For this I used code from TheElements iPhone Example and some image resize code I found. My problem is that resizedImage is always nil and I don't find the error...</p>
<pre><code>- (UIImage *)imageByScalingProportionallyToSize:(CGSize)targetSize
{
CGSize imageSize = [self size];
float width = imageSize.width;
float height = imageSize.height;
// scaleFactor will be the fraction that we'll
// use to adjust the size. For example, if we shrink
// an image by half, scaleFactor will be 0.5. the
// scaledWidth and scaledHeight will be the original,
// multiplied by the scaleFactor.
//
// IMPORTANT: the "targetHeight" is the size of the space
// we're drawing into. The "scaledHeight" is the height that
// the image actually is drawn at, once we take into
// account the ideal of maintaining proportions
float scaleFactor = 0.0;
float scaledWidth = targetSize.width;
float scaledHeight = targetSize.height;
CGPoint thumbnailPoint = CGPointMake(0,0);
// since not all images are square, we want to scale
// proportionately. To do this, we find the longest
// edge and use that as a guide.
if ( CGSizeEqualToSize(imageSize, targetSize) == NO )
{
// use the longeset edge as a guide. if the
// image is wider than tall, we'll figure out
// the scale factor by dividing it by the
// intended width. Otherwise, we'll use the
// height.
float widthFactor = targetSize.width / width;
float heightFactor = targetSize.height / height;
if ( widthFactor < heightFactor )
scaleFactor = widthFactor;
else
scaleFactor = heightFactor;
// ex: 500 * 0.5 = 250 (newWidth)
scaledWidth = width * scaleFactor;
scaledHeight = height * scaleFactor;
// center the thumbnail in the frame. if
// wider than tall, we need to adjust the
// vertical drawing point (y axis)
if ( widthFactor < heightFactor )
thumbnailPoint.y = (targetSize.height - scaledHeight) * 0.5;
else if ( widthFactor > heightFactor )
thumbnailPoint.x = (targetSize.width - scaledWidth) * 0.5;
}
CGContextRef mainViewContentContext;
CGColorSpaceRef colorSpace;
colorSpace = CGColorSpaceCreateDeviceRGB();
// create a bitmap graphics context the size of the image
mainViewContentContext = CGBitmapContextCreate (NULL, targetSize.width, targetSize.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
// free the rgb colorspace
CGColorSpaceRelease(colorSpace);
if (mainViewContentContext==NULL)
return NULL;
//CGContextSetFillColorWithColor(mainViewContentContext, [[UIColor whiteColor] CGColor]);
//CGContextFillRect(mainViewContentContext, CGRectMake(0, 0, targetSize.width, targetSize.height));
CGContextDrawImage(mainViewContentContext, CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledWidth, scaledHeight), self.CGImage);
// Create CGImageRef of the main view bitmap content, and then
// release that bitmap context
CGImageRef mainViewContentBitmapContext = CGBitmapContextCreateImage(mainViewContentContext);
CGContextRelease(mainViewContentContext);
CGImageRef maskImage = [[UIImage imageNamed:@"Mask.png"] CGImage];
CGImageRef resizedImage = CGImageCreateWithMask(mainViewContentBitmapContext, maskImage);
CGImageRelease(mainViewContentBitmapContext);
// convert the finished resized image to a UIImage
UIImage *theImage = [UIImage imageWithCGImage:resizedImage];
// image is retained by the property setting above, so we can
// release the original
CGImageRelease(resizedImage);
// return the image
return theImage;
}
</code></pre>
|
[
{
"answer_id": 262545,
"author": "Lounges",
"author_id": 8918,
"author_profile": "https://Stackoverflow.com/users/8918",
"pm_score": 0,
"selected": false,
"text": "- (void)drawRect:(CGRect)rect \n{\n // Drawing code\n [backgroundImage drawInRect:rect];\n [buttonOverlay drawInRect:rect]; \n}\n"
},
{
"answer_id": 262566,
"author": "wisequark",
"author_id": 33159,
"author_profile": "https://Stackoverflow.com/users/33159",
"pm_score": 3,
"selected": false,
"text": " - (void)drawRect:(CGRect)rect {\n CGContextRef context = UIGraphicsGetCurrentContext();\n CGContextBeginTransparencyLayerWithRect(context, self.frame, NULL);\n CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0); \n CGFloat roundRadius = (radius) ? radius : 12.0;\n CGFloat minx = CGRectGetMinX(self.frame), midx = CGRectGetMidX(self.frame), maxx = CGRectGetMaxX(self.frame);\n CGFloat miny = CGRectGetMinY(self.frame), midy = CGRectGetMidY(self.frame), maxy = CGRectGetMaxY(self.frame);\n\n // draw the arcs, handle paths\n CGContextMoveToPoint(context, minx, midy);\n CGContextAddArcToPoint(context, minx, miny, midx, miny, roundRadius);\n CGContextAddArcToPoint(context, maxx, miny, maxx, midy, roundRadius);\n CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, roundRadius);\n CGContextAddArcToPoint(context, minx, maxy, minx, midy, roundRadius);\n CGContextClosePath(context);\n CGContextDrawPath(context, kCGPathFill);\n CGContextEndTransparencyLayer(context);\n}\n"
},
{
"answer_id": 698800,
"author": "catlan",
"author_id": 23028,
"author_profile": "https://Stackoverflow.com/users/23028",
"pm_score": 5,
"selected": true,
"text": "CGContextRef mainViewContentContext;\nCGColorSpaceRef colorSpace;\n\ncolorSpace = CGColorSpaceCreateDeviceRGB();\n\n// create a bitmap graphics context the size of the image\nmainViewContentContext = CGBitmapContextCreate (NULL, targetSize.width, targetSize.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);\n\n// free the rgb colorspace\nCGColorSpaceRelease(colorSpace); \n\nif (mainViewContentContext==NULL)\n return NULL;\n\nCGImageRef maskImage = [[UIImage imageNamed:@\"mask.png\"] CGImage];\nCGContextClipToMask(mainViewContentContext, CGRectMake(0, 0, targetSize.width, targetSize.height), maskImage);\nCGContextDrawImage(mainViewContentContext, CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledWidth, scaledHeight), self.CGImage);\n\n\n// Create CGImageRef of the main view bitmap content, and then\n// release that bitmap context\nCGImageRef mainViewContentBitmapContext = CGBitmapContextCreateImage(mainViewContentContext);\nCGContextRelease(mainViewContentContext);\n\n// convert the finished resized image to a UIImage \nUIImage *theImage = [UIImage imageWithCGImage:mainViewContentBitmapContext];\n// image is retained by the property setting above, so we can \n// release the original\nCGImageRelease(mainViewContentBitmapContext);\n\n// return the image\nreturn theImage;\n"
},
{
"answer_id": 1834558,
"author": "jessecurry",
"author_id": 151792,
"author_profile": "https://Stackoverflow.com/users/151792",
"pm_score": 8,
"selected": false,
"text": "imageView.layer.cornerRadius = 5.0;\nimageView.layer.masksToBounds = YES;\n imageView.layer.borderColor = [UIColor lightGrayColor].CGColor;\nimageView.layer.borderWidth = 1.0;\n <QuartzCore/QuartzCore.h>"
},
{
"answer_id": 8206424,
"author": "epatel",
"author_id": 842,
"author_profile": "https://Stackoverflow.com/users/842",
"pm_score": 7,
"selected": false,
"text": "// Get your image somehow\nUIImage *image = [UIImage imageNamed:@\"image.jpg\"];\n\n// Begin a new image that will be the new image with the rounded corners \n// (here with the size of an UIImageView)\nUIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);\n\n// Add a clip before drawing anything, in the shape of an rounded rect\n[[UIBezierPath bezierPathWithRoundedRect:imageView.bounds \n cornerRadius:10.0] addClip];\n// Draw your image\n[image drawInRect:imageView.bounds];\n\n// Get the image, here setting the UIImageView image\nimageView.image = UIGraphicsGetImageFromCurrentImageContext();\n\n// Lets forget about that we were drawing\nUIGraphicsEndImageContext();\n"
},
{
"answer_id": 10619379,
"author": "Voda Ion",
"author_id": 1233416,
"author_profile": "https://Stackoverflow.com/users/1233416",
"pm_score": 2,
"selected": false,
"text": "static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth, float ovalHeight)\n{\n float fw, fh;\n if (ovalWidth == 0 || ovalHeight == 0) {\n CGContextAddRect(context, rect);\n return;\n }\n CGContextSaveGState(context);\n CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect));\n CGContextScaleCTM (context, ovalWidth, ovalHeight);\n fw = CGRectGetWidth (rect) / ovalWidth;\n fh = CGRectGetHeight (rect) / ovalHeight;\n CGContextMoveToPoint(context, fw, fh/2);\n CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);\n CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1);\n CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1);\n CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1);\n CGContextClosePath(context);\n CGContextRestoreGState(context);\n}\n\n+ (UIImage *)imageWithRoundCorner:(UIImage*)img andCornerSize:(CGSize)size\n{\n UIImage * newImage = nil;\n\n if( nil != img)\n {\n @autoreleasepool {\n int w = img.size.width;\n int h = img.size.height;\n\n CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();\n CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);\n\n CGContextBeginPath(context);\n CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);\n addRoundedRectToPath(context, rect, size.width, size.height);\n CGContextClosePath(context);\n CGContextClip(context);\n\n CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);\n\n CGImageRef imageMasked = CGBitmapContextCreateImage(context);\n CGContextRelease(context);\n CGColorSpaceRelease(colorSpace);\n [img release];\n\n newImage = [[UIImage imageWithCGImage:imageMasked] retain];\n CGImageRelease(imageMasked);\n\n }\n }\n\n return newImage;\n}\n"
},
{
"answer_id": 13836510,
"author": "Augustine P A",
"author_id": 889289,
"author_profile": "https://Stackoverflow.com/users/889289",
"pm_score": 1,
"selected": false,
"text": "+ (UIImage *)roundedRectImageFromImage:(UIImage *)image withRadious:(CGFloat)radious {\n\nif(radious == 0.0f)\n return image;\n\nif( image != nil) {\n\n CGFloat imageWidth = image.size.width;\n CGFloat imageHeight = image.size.height;\n\n CGRect rect = CGRectMake(0.0f, 0.0f, imageWidth, imageHeight);\n UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];\n const CGFloat scale = window.screen.scale;\n UIGraphicsBeginImageContextWithOptions(rect.size, NO, scale);\n\n CGContextRef context = UIGraphicsGetCurrentContext();\n\n CGContextBeginPath(context);\n CGContextSaveGState(context);\n CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect));\n CGContextScaleCTM (context, radious, radious);\n\n CGFloat rectWidth = CGRectGetWidth (rect)/radious;\n CGFloat rectHeight = CGRectGetHeight (rect)/radious;\n\n CGContextMoveToPoint(context, rectWidth, rectHeight/2.0f);\n CGContextAddArcToPoint(context, rectWidth, rectHeight, rectWidth/2.0f, rectHeight, radious);\n CGContextAddArcToPoint(context, 0.0f, rectHeight, 0.0f, rectHeight/2.0f, radious);\n CGContextAddArcToPoint(context, 0.0f, 0.0f, rectWidth/2.0f, 0.0f, radious);\n CGContextAddArcToPoint(context, rectWidth, 0.0f, rectWidth, rectHeight/2.0f, radious);\n CGContextRestoreGState(context);\n CGContextClosePath(context);\n CGContextClip(context);\n\n [image drawInRect:CGRectMake(0.0f, 0.0f, imageWidth, imageHeight)];\n\n UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();\n UIGraphicsEndImageContext();\n\n return newImage;\n}\n\nreturn nil;\n}\n"
},
{
"answer_id": 32303467,
"author": "Besi",
"author_id": 784318,
"author_profile": "https://Stackoverflow.com/users/784318",
"pm_score": 5,
"selected": false,
"text": "UIImage extension UIImage{\n var roundedImage: UIImage {\n let rect = CGRect(origin:CGPoint(x: 0, y: 0), size: self.size)\n UIGraphicsBeginImageContextWithOptions(self.size, false, 1)\n defer { \n // End context after returning to avoid memory leak\n UIGraphicsEndImageContext() \n }\n \n UIBezierPath(\n roundedRect: rect,\n cornerRadius: self.size.height\n ).addClip()\n self.drawInRect(rect)\n return UIGraphicsGetImageFromCurrentImageContext()\n }\n}\n"
},
{
"answer_id": 32308205,
"author": "user3182143",
"author_id": 3182143,
"author_profile": "https://Stackoverflow.com/users/3182143",
"pm_score": 0,
"selected": false,
"text": "Click project -Targets\n ->project\n ->BuildPhase\n ->Link Binary with Libraries\n ->Then click + symbol finally select from list and add it\n Click project -Targets\n ->Targets\n ->general\n ->Linked Frameworks and Libraries\n ->Then click + symbol finally select from list and add the QuartzCore framework\n #import <QuartzCore/QuartzCore.h> \n self.yourImageView.layer.cornerRadius = 5.0;\nself.yourImageView.layer.borderWidth = 1.0f;\nself.yourImageView.layer.borderColor = [UIColor blackColor].CGColor;\nself.yourImageView.layer.masksToBounds = YES;\n"
},
{
"answer_id": 42454084,
"author": "bartosss",
"author_id": 4867143,
"author_profile": "https://Stackoverflow.com/users/4867143",
"pm_score": 1,
"selected": false,
"text": "cell.messageImage.layer.cornerRadius = image.size.width / 2\ncell.messageImage.layer.masksToBounds = true\n"
},
{
"answer_id": 45053455,
"author": "Idan",
"author_id": 1071887,
"author_profile": "https://Stackoverflow.com/users/1071887",
"pm_score": 1,
"selected": false,
"text": "UIImageView *imageView;\n\nimageView.layer.cornerRadius = imageView.frame.size.width/2.0f;\nimageView.layer.masksToBounds = TRUE;\n"
},
{
"answer_id": 47518249,
"author": "Donsb",
"author_id": 9016470,
"author_profile": "https://Stackoverflow.com/users/9016470",
"pm_score": 0,
"selected": false,
"text": "import UIKit\n image.layer.cornerRadius = 20.0\n\nimage.layer.masksToBounds = true\n"
},
{
"answer_id": 51657994,
"author": "samwize",
"author_id": 242682,
"author_profile": "https://Stackoverflow.com/users/242682",
"pm_score": 4,
"selected": false,
"text": "extension UIImage {\n\n public func rounded(radius: CGFloat) -> UIImage {\n let rect = CGRect(origin: .zero, size: size)\n UIGraphicsBeginImageContextWithOptions(size, false, 0)\n UIBezierPath(roundedRect: rect, cornerRadius: radius).addClip()\n draw(in: rect)\n return UIGraphicsGetImageFromCurrentImageContext()!\n }\n\n}\n"
},
{
"answer_id": 52293534,
"author": "scrat84",
"author_id": 526410,
"author_profile": "https://Stackoverflow.com/users/526410",
"pm_score": 2,
"selected": false,
"text": "let imageView = UIImageView(image: UIImage(named: \"myImage\")) \nimageView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]\nimageView.layer.cornerRadius = 10.0\n"
},
{
"answer_id": 62862742,
"author": "maks_b",
"author_id": 13243912,
"author_profile": "https://Stackoverflow.com/users/13243912",
"pm_score": 1,
"selected": false,
"text": "UIGraphicsEndImageContext() extension UIImage {\n /**\n Rounds corners of UIImage\n - Parameter proportion: Proportion to minimum paramter (width or height)\n in order to have the same look of corner radius independetly\n from aspect ratio and actual size\n */\n func roundCorners(proportion: CGFloat) -> UIImage {\n let minValue = min(self.size.width, self.size.height)\n let radius = minValue/proportion\n \n let rect = CGRect(origin: CGPoint(x: 0, y: 0), size: self.size)\n UIGraphicsBeginImageContextWithOptions(self.size, false, 1)\n UIBezierPath(roundedRect: rect, cornerRadius: radius).addClip()\n self.draw(in: rect)\n let image = UIGraphicsGetImageFromCurrentImageContext() ?? self\n UIGraphicsEndImageContext()\n return image\n }\n}\n proportion image.roundCorners(proportion: 20)"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23028/"
] |
262,158
|
<p>The simple HTML below displays differently in Firefox and WebKit-based browsers (I checked in Safari, Chrome and iPhone).</p>
<p>In Firefox both border and text have the same color (<code>#880000</code>), but in Safari the text gets a bit lighter (as if it had some transparency applied to it).</p>
<p>Can I somehow fix this (remove this transparency in Safari)?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
input:disabled{
border:solid 1px #880000;
background-color:#ffffff;
color:#880000;
}
</style>
</head>
<body>
<form action="">
<input type="text" value="disabled input box" disabled="disabled"/>
</form>
</body>
</html></code></pre>
</div>
</div>
</p>
|
[
{
"answer_id": 262478,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n <title></title>\n <style type=\"text/css\">\n button:disabled{\n border:solid 1px #880000;\n background-color:#ffffff;\n color:#880000;\n }\n </style>\n</head>\n<body>\n <form action=\"\">\n <button type=\"button\" disabled=\"disabled\">disabled input box</button>\n </form>\n</body>\n</html>\n"
},
{
"answer_id": 263865,
"author": "Steve Perks",
"author_id": 16124,
"author_profile": "https://Stackoverflow.com/users/16124",
"pm_score": 3,
"selected": false,
"text": "opacity: 1!important;\n"
},
{
"answer_id": 263939,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 3,
"selected": false,
"text": "#440000"
},
{
"answer_id": 265706,
"author": "Serxipc",
"author_id": 34009,
"author_profile": "https://Stackoverflow.com/users/34009",
"pm_score": 2,
"selected": false,
"text": "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<title></title>\n<style type=\"text/css\">\nbutton.readonly{\n border:solid 1px #880000;\n background-color:#ffffff;\n color:#880000;\n}\n</style>\n</head>\n<body>\n<form action=\"\">\n <button type=\"button\" readonly=\"readonly\" class=\"readonly\">disabled input box</button>\n</form>\n</body>\n</html>\n"
},
{
"answer_id": 2951396,
"author": "conceptDawg",
"author_id": 34901,
"author_profile": "https://Stackoverflow.com/users/34901",
"pm_score": 2,
"selected": false,
"text": "input::-webkit-input-placeholder {\n color: #880000;\n}\n"
},
{
"answer_id": 4648315,
"author": "Kemo",
"author_id": 570015,
"author_profile": "https://Stackoverflow.com/users/570015",
"pm_score": 9,
"selected": true,
"text": "-webkit-text-fill-color: #880000;\nopacity: 1; /* required on iOS */\n"
},
{
"answer_id": 23511280,
"author": "lijinma",
"author_id": 1702174,
"author_profile": "https://Stackoverflow.com/users/1702174",
"pm_score": 6,
"selected": false,
"text": "-webkit-text-fill-color:#880000; /* Override iOS / Android font color change */\n-webkit-opacity:1; /* Override iOS opacity change affecting text & background color */\ncolor:#880000; /* Override IE font color change */\n"
},
{
"answer_id": 45209441,
"author": "vanduc1102",
"author_id": 1681903,
"author_profile": "https://Stackoverflow.com/users/1681903",
"pm_score": 3,
"selected": false,
"text": "-webkit-text-fill-color: rgba(0, 0, 0, 1);\n-webkit-opacity: 1;\nbackground: white;\n"
},
{
"answer_id": 55253186,
"author": "Freez",
"author_id": 4332533,
"author_profile": "https://Stackoverflow.com/users/4332533",
"pm_score": 2,
"selected": false,
"text": "-webkit-text-fill-color currentcolor color input[disabled] {\n -webkit-text-fill-color: currentcolor;\n}\n"
},
{
"answer_id": 55876580,
"author": "paulcol.",
"author_id": 1101480,
"author_profile": "https://Stackoverflow.com/users/1101480",
"pm_score": 4,
"selected": false,
"text": "input:disabled, textarea:disabled, input:disabled::placeholder, textarea:disabled::placeholder {\n -webkit-text-fill-color: currentcolor; /* 1. sets text fill to current `color` for safari */\n opacity: 1; /* 2. correct opacity on iOS */\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262158",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34187/"
] |
262,160
|
<p>I've got menu items that look like this</p>
<pre><code><ul>
<li>Item1<span class="context-trigger"></span></li>
<li>Item2<span class="context-trigger"></span></li>
<li>Item3<span class="context-trigger"></span></li>
</ul>
</code></pre>
<p>with CSS that turns the above into a horizontal menu, and JS that turns the [spans] into buttons that bring up contextual menus. Vaguely like this:</p>
<pre>
Item1^ Item2^ Item3^
</pre>
<p>If the menu gets too wide for the browser width, it wraps, which is what I want. The problem is that sometimes it's putting in line-breaks before the [spans]. I only want it to break between [li]s. Any ideas?</p>
|
[
{
"answer_id": 262193,
"author": "Huibert Gill",
"author_id": 1254442,
"author_profile": "https://Stackoverflow.com/users/1254442",
"pm_score": 5,
"selected": true,
"text": "white-space: nowrap;\n"
},
{
"answer_id": 262209,
"author": "patmortech",
"author_id": 19090,
"author_profile": "https://Stackoverflow.com/users/19090",
"pm_score": 2,
"selected": false,
"text": "li { white-space:nowrap; }\n"
},
{
"answer_id": 262235,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 0,
"selected": false,
"text": "<li>"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24197/"
] |
262,192
|
<p>In our project we have a large number (hundreds) of FLA files created by the artists in CS3, from which we compile SWFs to use in our Flex/AS3 application.</p>
<p>As part of a streamlined build/deploy system, it would be really handy to be able to automate publishing all these FLAs, and ideally deploying the SWFs too. I found some ways to do the batch publishing from CS3 using JSFL, but was surprised to discover CS3 doesn't apparently have any command-line functionality for this?</p>
<p>This is on a Linux system for what it's worth, I don't have experience with JSFL to know if you can run scripts from the command line somehow?</p>
<p><strong>note</strong>: I should have said "Linux is preferred"... I don't use Linux but our server/build PC is Linux... I didn't realise CS3 was not compatible so I guess we can do this part on Windows.</p>
|
[
{
"answer_id": 488306,
"author": "D. Starr",
"author_id": 1144394,
"author_profile": "https://Stackoverflow.com/users/1144394",
"pm_score": 3,
"selected": false,
"text": "\"c:\\program files\\macromedia\\flash 8\\flash.exe\" myscript.jsfl open myscript.jsfl var importFolder = fl.browseForFolderURL('Select a folder with existing FLA files');\nvar importFolderContents = FLfile.listFolder(importFolder);\nfor (i = 0; i <importFolderContents.length; i++) {\n file = importFolderContents[i];\n fl.openDocument(file); // and so on\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13220/"
] |
262,201
|
<p>How can I write a C++ function returning true if a real number is exactly representable with a double?</p>
<pre><code>bool isRepresentable( const char* realNumber )
{
bool answer = false;
// what goes here?
return answer;
}
</code></pre>
<p>Simple tests:</p>
<pre><code>assert( true==isRepresentable( "0.5" ) );
assert( false==isRepresentable( "0.1" ) );
</code></pre>
|
[
{
"answer_id": 262236,
"author": "Richard Poole",
"author_id": 26003,
"author_profile": "https://Stackoverflow.com/users/26003",
"pm_score": 0,
"selected": false,
"text": "bool isRepresentable(const char *realNumber)\n{\n double value = strtod(realNumber, NULL);\n\n char test[20];\n sprintf(test, \"%f\", value);\n\n return strcmp(realNumber, test) == 0;\n}\n"
},
{
"answer_id": 262314,
"author": "Mike G.",
"author_id": 18901,
"author_profile": "https://Stackoverflow.com/users/18901",
"pm_score": 3,
"selected": false,
"text": "#include <stdio.h>\n\nint main() {\n printf(\"%llx = %f\\n\",0.1,0.1);\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262201",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15485/"
] |
262,211
|
<p>GNU gcc 4.3 partially supports the upcoming c++0x standard: among the implemented features the rvalue reference. By means of the rvalue reference it should be possible to move a non-copyable object or return it from a function. </p>
<p>Are std::streams already movable <strong>by means of rvalue reference</strong> or does the current library implementation lack something?</p>
|
[
{
"answer_id": 263435,
"author": "Nicola Bonelli",
"author_id": 19630,
"author_profile": "https://Stackoverflow.com/users/19630",
"pm_score": 1,
"selected": false,
"text": "struct noncopyable\n{\n noncopyable()\n {}\n\n // move constructor\n noncopyable(noncopyable &&)\n {}\n\nprivate:\n noncopyable(const noncopyable &);\n noncopyable &operator=(const noncopyable &);\n};\n noncopyable factory()\n{\n noncopyable abc;\n return std::move(abc);\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19630/"
] |
262,215
|
<p>I have read about a technique involving writing to disk a rendered dynamic page and using that when it exists using mod_rewrite. I was thinking about cleaning out the cached version every X minutes using a cron job.</p>
<p>I was wondering if this was a viable option or if there were better alternatives that I am not aware of.</p>
<p>(Note that I'm on a shared machine and mod_cache is not an option.)</p>
|
[
{
"answer_id": 262345,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "php index.php > (location of static file)"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262215",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32141/"
] |
262,217
|
<p>How would you design a content voting mechanism that could be applied polymorphically to multiple models / classes. (in a ruby on rails context preferably, but others are fine)</p>
<p>Given that instances of these classes can be voted on:
- Article
- Question
- Product</p>
<p>Voters should not be required to register.</p>
<p>Best effort should be made to limit voters to one vote per object. (1 vote for a particular article and one vote for a particular question, etc.). I.e. use ip detection, cookies, etc.</p>
|
[
{
"answer_id": 268857,
"author": "Ian Terrell",
"author_id": 9269,
"author_profile": "https://Stackoverflow.com/users/9269",
"pm_score": 1,
"selected": false,
"text": "create_table :orders do |t|\n t.string :votable_type\n t.integer :votable_id\n t.integer :vote\n t.timestamps\nend\n acts_as_votable has_many :votes, :as => \"votable\"\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262217",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34210/"
] |
262,232
|
<p>I am trying to come up with the best data structure for use in a high throughput C++ server. The data structure will be used to store anything from a few to several million objects, and no sorting is required (though a unique sort key can be provided very cheaply).</p>
<p>The requirements are that it can support efficient insert, ideally O(1), moderately efficient removal, and efficient traversal. It doesn't need to support a find operation (other than might be needed for removal).</p>
<p>The twist is that it must be thread safe with respect to modifications while other threads are enumerating the data structure. This means that a simple red-black tree doesn't work, since one thread can't insert an element (and perform the necessary tree rotations) without messing up any cursors held by other threads.</p>
<p>It is <strong>not</strong> acceptable to use a read/write lock and defer the write operations until all readers have finished, since read operations may be long lived. It doesn't matter if inserts that happen while there is a reader are visible to that reader or not.</p>
<p>Memory footprint is also very important, and small is obviously better!</p>
<p>What suggestions are there?</p>
<p><strong>Response to comments:</strong></p>
<p>Thanks for the answers.</p>
<p>No, inserts cannot invalidate existing iterators. Iterators may or may not see the new insert, but they must see everything that they would have seen if the insert hadn't occurred.</p>
<p>Deletion is required, however due to higher level rules I can guarantee that a iterator will never be stopped on an item that is available for deletion.</p>
<p>Locking per node for a cursor would have too great an impact on performance. There may be a number of threads reading at once, and any kind of memory hot spot that multiple threads are using in a lock kills memory bandwidth (as we discovered the hard way!). Even a simple count of readers with multiple threads calling InterlockedIncrement fails to scale cleanly. </p>
<p>I agree a linked list is likely the best approach. Deletes are rare, so paying the memory penalty for the back pointers to support O(1) delete is costly and we may compute those separately on demand and since deletes tend to be batch operations.</p>
<p>Fortunately insertion into a linked list doesn't require any locking for readers, as long as the pointers are updated in the inserted node before the head pointer is changed.</p>
<p>The lock-copy-unlock idea is interesting. The amount of data involved is too large for this to work as the default for readers, but it could be used for writers when they collide with readers. A read/write lock would protect the whole structure, and the write would clone the data structure if it collides with a reader. Writes are much rarer than reads.</p>
|
[
{
"answer_id": 262564,
"author": "coppro",
"author_id": 16855,
"author_profile": "https://Stackoverflow.com/users/16855",
"pm_score": 3,
"selected": false,
"text": "std::list std::list"
},
{
"answer_id": 1678486,
"author": "Kiril",
"author_id": 28760,
"author_profile": "https://Stackoverflow.com/users/28760",
"pm_score": 1,
"selected": false,
"text": "1. High throughput. CHECK\n2. Thread safe. CHECK\n3. Efficient inserts happen in O(1). CHECK\n4. Efficient removal (with no data races or locks). CHECK\n5. VERY efficient traversal. CHECK\n6. Does not lock or wait. CHECK\n7. Easy on the memory. CHECK\n8. It is scalable (just increase the lock pool). CHECK\n protected static class Entry implements Map.Entry {\n protected final Object key;\n protected volatile Object value;\n protected final int hash;\n protected final Entry next;\n ...\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3631/"
] |
262,238
|
<p>I have a <code>contacts</code> table which contains fields such as <code>postcode</code>, <code>first name</code>, <code>last name</code>, <code>town</code>, <code>country</code>, <code>phone number</code> etc, all of which are defined as <code>VARCHAR(255)</code> even though none of these fields will ever come close to having 255 characters. (If you're wondering, it's this way because Ruby on Rails migrations map String fields to <code>VARCHAR(255)</code> by default and I never bothered to override it). </p>
<p>Since VARCHAR will only store the number of actual characters of the field (along with the field length), is there any distinct advantage (performance or otherwise) to using, say, <code>VARCHAR(16)</code> over <code>VARCHAR(255)</code>? </p>
<p>Additionally, most of these fields have indexes on them. Does a larger VARCHAR size on the field affect the size or performance of the index at all? </p>
<p>FYI I'm using MySQL 5.</p>
|
[
{
"answer_id": 262476,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 8,
"selected": true,
"text": "VARCHAR(255) CHAR(255) VARCHAR CHAR VARCHAR GROUP BY VARCHAR(255) VARCHAR(255) VARCHAR(255) VARCHAR VARCHAR VARCHAR"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262238",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1174/"
] |
262,249
|
<p>I have a debug app I've been writing which receives data from a C-based process via UDP. One of the strings sent to me contains a <code>°</code> character - <a href="http://en.wikipedia.org/wiki/Degree_symbol" rel="nofollow noreferrer">Unicode U+00B0</a> (which incidentally breaks the StackOverflow search function!). When my wxPython application tries to append that string to a text box I get a <code>UnicodeDecodeError</code>.</p>
<p>My first attempt to fix the issue simply caught that error (because the app apparently does send <em>some</em> bad messages. The problem is that the app also uses the character to report various temperatures around the unit and that's something we really need to log. Changing the source app is out of my control, so how can I detect and decode those symbols into something the <code>wxTextCtrl</code> can display?</p>
|
[
{
"answer_id": 262433,
"author": "pdc",
"author_id": 8925,
"author_profile": "https://Stackoverflow.com/users/8925",
"pm_score": 1,
"selected": false,
"text": "'123\\xB0' UnicodeDecodeError s = message.get_string()\n s = message.get_string().decode('ISO8859-1')\n get_string()"
},
{
"answer_id": 263330,
"author": "Toni Ruža",
"author_id": 6267,
"author_profile": "https://Stackoverflow.com/users/6267",
"pm_score": 3,
"selected": true,
"text": "decode #!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport wx\n\napp = wx.PySimpleApp()\napp.TopWindow = wx.Frame(None)\nfield = wx.TextCtrl(app.TopWindow)\nfield.Value += '°'.decode('ISO8859-1')\napp.TopWindow.Show()\napp.MainLoop()\n"
},
{
"answer_id": 13496753,
"author": "Jason Viers",
"author_id": 480667,
"author_profile": "https://Stackoverflow.com/users/480667",
"pm_score": 0,
"selected": false,
"text": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport wx\n\napp = wx.PySimpleApp()\napp.TopWindow = wx.Frame(None)\nfield = wx.TextCtrl(app.TopWindow)\n\nstring_data = '°'\nprint type(string_data)\n# this would error, as it tries to convert to unicode from ascii\n# field.Value += string_data\n\nunicode_data = unicode(string_data, 'utf-8')\nprint type(unicode_data)\nfield.Value += unicode_data\napp.TopWindow.Show()\napp.MainLoop()\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262249",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15369/"
] |
262,254
|
<p>How can I use CRTP in C++ to avoid the overhead of virtual member functions?</p>
|
[
{
"answer_id": 262276,
"author": "user23167",
"author_id": 23167,
"author_profile": "https://Stackoverflow.com/users/23167",
"pm_score": -1,
"selected": false,
"text": "template <class Derived> struct Base\n{\n void interface()\n {\n // ...\n static_cast<Derived*>(this)->implementation();\n // ...\n }\n\n static void static_func()\n {\n // ...\n Derived::static_sub_func();\n // ...\n }\n};\n\nstruct Derived : Base<Derived>\n{\n void implementation();\n static void static_sub_func();\n};\n"
},
{
"answer_id": 262984,
"author": "Dean Michael",
"author_id": 11274,
"author_profile": "https://Stackoverflow.com/users/11274",
"pm_score": 7,
"selected": false,
"text": "template <class Derived>\nstruct base {\n void foo() {\n static_cast<Derived *>(this)->foo();\n };\n};\n\nstruct my_type : base<my_type> {\n void foo(); // required to compile.\n};\n\nstruct your_type : base<your_type> {\n void foo(); // required to compile.\n};\n template <class T> // T is deduced at compile-time\nvoid bar(base<T> & obj) {\n obj.foo(); // will do static dispatch\n}\n\nstruct not_derived_from_base { }; // notice, not derived from base\n\n// ...\nmy_type my_instance;\nyour_type your_instance;\nnot_derived_from_base invalid_instance;\nbar(my_instance); // will call my_instance.foo()\nbar(your_instance); // will call your_instance.foo()\nbar(invalid_instance); // compile error, cannot deduce correct overload\n"
},
{
"answer_id": 65961084,
"author": "jisrael18",
"author_id": 15013600,
"author_profile": "https://Stackoverflow.com/users/15013600",
"pm_score": 1,
"selected": false,
"text": "#define SFINAE_DETECT(name, expr) \\\n template <typename T> \\\n using name##_t = decltype(expr); \\\n template <typename T, typename = void> \\\n struct has_##name : public std::false_type {}; \\\n template <typename T> \\\n struct has_##name<T, void_t<name##_t<T>>> : public std::true_type {};\n\n// detect CommonPrefix(string)\nSFINAE_DETECT(common_prefix,\n declval<T>().CommonPrefix(std::string()))\n has_complete<DerivedClass> DerivedClass Complete std::string std::true_type template <class Derived>\nstruct Base {\n std::string foo(bool);\n std::string foo(int);\n ...\n};\n\nstruct Derived : public Base<Derived>\n{\n std::string foo(int);\n};\n Derived foo bool bool int has_foo<Derived> std::true_type Derived::foo(int) template <template <class...> class Op, class... Types>\nstruct dispatcher;\n\ntemplate <template <class...> class Op, class T>\nstruct dispatcher<Op, T> : std::experimental::detected_t<Op, T> {};\n\ntemplate <template <class...> class Op, class T, class... Types>\nstruct dispatcher<Op, T, Types...>\n : std::experimental::detected_or_t<\n typename dispatcher<Op, Types...>::type, Op, T> {};\n\ntemplate <template <class...> class Op, class... Types>\nusing dispatcher_t = typename dispatcher<Op, Types...>::type;\n Op std::integral_constant template <class T>\nusing foo_op_b = std::integral_constant<std::string(T::*)(bool), &T::foo>;\n\ntemplate <class T>\nusing foo_op_i = std::integral_constant<std::string(T::*)(int), &T::foo>\n Op // Resolves to std::integral_constant<std::string(T::*)(bool), &Derived::foo>\nusing foo_bool_ic = dispatcher_t<foo_op_b, Derived, Defaults>;\n\n// Resolves to std::integral_constant<std::string(T::*)(int), &Defaults::foo>\nusing foo_int_ic = dispatcher_t<foo_op_i, Derived, Defaults>;\n #include <iostream>\n#include <experimental/type_traits>\n#include <string>\n\ntemplate <template <class...> class Op, class... Types>\nstruct dispatcher;\n\ntemplate <template <class...> class Op, class T>\nstruct dispatcher<Op, T> : std::experimental::detected_t<Op, T> {};\n\ntemplate <template <class...> class Op, class T, class... Types>\nstruct dispatcher<Op, T, Types...>\n : std::experimental::detected_or_t<\n typename dispatcher<Op, Types...>::type, Op, T> {};\n\ntemplate <template <class...> class Op, class... Types>\nusing dispatcher_t = typename dispatcher<Op, Types...>::type;\n\n\n// Used to deduce class type from a member function pointer\ntemplate <class R, class T, class... Args>\nauto method_cls(R(T::*)(Args...)) -> T;\n\n\nstruct Defaults {\n std::string foo(bool value) { return value ? \"true\" : \"false\"; }\n std::string foo(int value) { return value ? \"true\" : \"false\"; }\n\n // Ensure that the class is polymorphic so we can use dynamic_cast\n virtual ~Defaults() {};\n};\n\ntemplate <class Derived>\nstruct Base : Defaults {\n template <class T>\n using foo_op_b = std::integral_constant<std::string(T::*)(bool), &T::foo>;\n\n template <class T>\n using foo_op_i = std::integral_constant<std::string(T::*)(int), &T::foo>;\n\n std::string foo(bool value) {\n auto method = dispatcher_t<foo_op_b, Derived, Defaults>::value;\n auto *target = dynamic_cast<decltype(method_cls(method)) *>(this);\n return (target->*method)(value);\n }\n\n std::string foo(int value) {\n auto method = dispatcher_t<foo_op_i, Derived, Defaults>::value;\n auto *target = dynamic_cast<decltype(method_cls(method)) *>(this);\n return (target->*method)(value);\n }\n};\n\nstruct Derived : Base<Derived> {\n std::string foo(bool value) { return value ? \"TRUE\" : \"FALSE\"; }\n};\n\nint main() {\n Derived d;\n std::cout << dynamic_cast<Base<Derived> *>(&d)->foo(true) << std::endl; // TRUE\n std::cout << dynamic_cast<Base<Derived> *>(&d)->foo(1) << std::endl; // true\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,264
|
<p>I have a list of cities, states/provinces, and countries and I need to find their respective timezones easily. Specifically, I need to know which Windows TimeZone they map to. So far this has been a difficult process, because there's no easy way to pass a city to something and get a timezone back (a timezone being an offset and whether or not the timezone supports Daylight Savings Time). </p>
<p>The current flow is to use <a href="http://www.batchgeocode.com" rel="noreferrer">http://www.batchgeocode.com</a> to get the latitude/longitude of the city (which really calls a Yahoo service) and then call <a href="http://www.EarthTools.org" rel="noreferrer">http://www.EarthTools.org</a> to get a timezone letter, which maps to an offset. The problem is the yahoo service will sometimes return a bad longitude/latitude, and earthtools.org doesn't know a lot about DST info so mapping to the correct TimeZone Id is a tedious manual process.</p>
<p>I can't be the first person who has done this- does anybody know of a better way, or some list out there which has the info I need?</p>
<p>Thanks.</p>
|
[
{
"answer_id": 40160417,
"author": "Anestis Kivranoglou",
"author_id": 850980,
"author_profile": "https://Stackoverflow.com/users/850980",
"pm_score": 2,
"selected": false,
"text": "CountryName\n2LetterIsoCountryCode\n3LetterIsoCountryCode\nIANATimezones\nWindowsTimezones\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30881/"
] |
262,267
|
<p>How do I create a toolbar for Excel using an XLA document?</p>
|
[
{
"answer_id": 262319,
"author": "BradC",
"author_id": 21398,
"author_profile": "https://Stackoverflow.com/users/21398",
"pm_score": 3,
"selected": true,
"text": "Dim myBar As CommandBar, myButt As CommandBarControl \n\n'Delete the toolbar if it already exists'\nOn Error Resume Next \nCommandBars(\"My Toolbar\").Delete \nOn Error Goto 0\n\nSet myBar = CommandBars.Add(Name:=\"My Toolbar\", _\n Position:=msoBarFloating, Temporary:=True) \nmyBar.Visible = True \n\n ' Create a button with text on the bar and set some properties.'\nSet myButt = ComBar.Controls.Add(Type:=msoControlButton) \nWith myButt\n .Caption = \"Macro1\" \n .Style = msoButtonCaption \n .TooltipText = \"Run Macro1\" \n .OnAction = \"Macro1\" \nEnd With \n\n ' Create a button with an image on the bar and set some properties.'\nSet myButt = ComBar.Controls.Add(Type:=msoControlButton) \nWith myButt \n 'the faceId line will let you choose an icon'\n ' If you choose to use the faceId then the caption is not displayed'\n .FaceId = 1000 \n .Caption = \"Icon Button\" \n .TooltipText = \"Run Macro2\" \n .OnAction = \"Macro2\" \nEnd With \n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16794/"
] |
262,273
|
<p>In the iPhone is there a way I can use JavaScript to close the browser and return to the home screen? After the last page a wizard I am calling out to another iPhone app (ex: maps) and I do NOT what the user to come back to the browser screen when they are done. My backup plan is to have a "Complete" page but that is not the best experience for the client.</p>
|
[
{
"answer_id": 262356,
"author": "Anders",
"author_id": 25515,
"author_profile": "https://Stackoverflow.com/users/25515",
"pm_score": 0,
"selected": false,
"text": "javascript:self.close();\nwindow.close();\n window.opener='x';\nwindow.close();\n"
},
{
"answer_id": 262374,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 0,
"selected": false,
"text": "window.close()"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30099/"
] |
262,279
|
<p>Model Driven Software Development.</p>
<p>As I understand it it raises the abstraction level of the design to better reflect the domain the software will attempt to run in. That's alot to say in just one sentence.</p>
<p>The communication between the domain experts (customer) and the developers is crucial to make this methodology work. What I want to know is if there is a tool suite or set of best practices that will help in the initial thrust of MDSD? Once the domain is fleshed out what about mapping that model to an ORM (or whatever)? </p>
<p>I am just diving into the realm of MDSD and DSL so any constructive ideas or comments will be appriciated.</p>
|
[
{
"answer_id": 320332,
"author": "jbandi",
"author_id": 32749,
"author_profile": "https://Stackoverflow.com/users/32749",
"pm_score": 1,
"selected": false,
"text": "class Firm < ActiveRecord::Base\n has_many :clients\n has_one :account\n belongs_to :conglomorate\nend\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2894/"
] |
262,280
|
<p>When I get a reference to a <code>System.Diagnostics.Process</code>, how can I know if a process is currently running?</p>
|
[
{
"answer_id": 262291,
"author": "Patrick Desjardins",
"author_id": 13913,
"author_profile": "https://Stackoverflow.com/users/13913",
"pm_score": 9,
"selected": true,
"text": "Process[] pname = Process.GetProcessesByName(\"notepad\");\nif (pname.Length == 0)\n MessageBox.Show(\"nothing\");\nelse\n MessageBox.Show(\"run\");\n Process[] processlist = Process.GetProcesses();\nforeach(Process theprocess in processlist){\n Console.WriteLine(\"Process: {0} ID: {1}\", theprocess.ProcessName, theprocess.Id);\n}\n"
},
{
"answer_id": 262350,
"author": "Jeff Kotula",
"author_id": 1382162,
"author_profile": "https://Stackoverflow.com/users/1382162",
"pm_score": 1,
"selected": false,
"text": "Process.GetProcesses()"
},
{
"answer_id": 262487,
"author": "Coincoin",
"author_id": 42,
"author_profile": "https://Stackoverflow.com/users/42",
"pm_score": 4,
"selected": false,
"text": "void DisplayProcessStatus(Process process)\n{\n process.Refresh(); // Important\n\n\n if(process.HasExited)\n {\n Console.WriteLine(\"Exited.\");\n }\n else\n {\n Console.WriteLine(\"Running.\");\n } \n}\n void RegisterProcessExit(Process process)\n{\n // NOTE there will be a race condition with the caller here\n // how to fix it is left as an exercise\n process.Exited += process_Exited;\n}\n\nstatic void process_Exited(object sender, EventArgs e)\n{\n Console.WriteLine(\"Process has exited.\");\n}\n"
},
{
"answer_id": 268394,
"author": "reshefm",
"author_id": 30717,
"author_profile": "https://Stackoverflow.com/users/30717",
"pm_score": 5,
"selected": false,
"text": "public static class ProcessExtensions\n{\n public static bool IsRunning(this Process process)\n {\n if (process == null) \n throw new ArgumentNullException(\"process\");\n\n try\n {\n Process.GetProcessById(process.Id);\n }\n catch (ArgumentException)\n {\n return false;\n }\n return true;\n }\n}\n Process.GetProcessById(processId) ProcessManager.IsProcessRunning(processId) ArgumentException ProcessManager"
},
{
"answer_id": 13918804,
"author": "Jack Griffin",
"author_id": 1362643,
"author_profile": "https://Stackoverflow.com/users/1362643",
"pm_score": 0,
"selected": false,
"text": "private Process openApplication; \nprivate void btnOpenFile_Click(object sender, EventArgs e) { \n ...\n // copy current file to fileCache \n ... \n // open fileCache with proper application\n openApplication = System.Diagnostics.Process.Start( fileCache ); \n}\n ... \nopenApplication.Refresh(); \n\n// close application if it is still open \nif ( !openApplication.HasExited() ) {\n openApplication.Kill(); \n}\n\n// delete temporary file \nSystem.IO.File.Delete( fileCache );\n"
},
{
"answer_id": 17603535,
"author": "berkay",
"author_id": 2465932,
"author_profile": "https://Stackoverflow.com/users/2465932",
"pm_score": 0,
"selected": false,
"text": "string process = \"notepad\";\nif (Process.GetProcessesByName(process).Length > 0)\n{\n MessageBox.Show(\"Working\");\n}\nelse\n{\n MessageBox.Show(\"Not Working\");\n}\n"
},
{
"answer_id": 21482938,
"author": "Aelphaeis",
"author_id": 2656813,
"author_profile": "https://Stackoverflow.com/users/2656813",
"pm_score": 4,
"selected": false,
"text": " public static bool IsRunning(this Process process)\n {\n try {Process.GetProcessById(process.Id);}\n catch (InvalidOperationException) { return false; }\n catch (ArgumentException){return false;}\n return true;\n }\n"
},
{
"answer_id": 38234565,
"author": "guneysus",
"author_id": 1766716,
"author_profile": "https://Stackoverflow.com/users/1766716",
"pm_score": 4,
"selected": false,
"text": "public static class ProcessHelpers {\n public static bool IsRunning (string name) => Process.GetProcessesByName(name).Length > 0;\n}\n"
},
{
"answer_id": 55721450,
"author": "Latency",
"author_id": 878539,
"author_profile": "https://Stackoverflow.com/users/878539",
"pm_score": 0,
"selected": false,
"text": "var x = obj.GetType().GetProperty(\"Name\", BindingFlags.NonPublic | BindingFlags.Instance);\n HANDLE CreateToolhelp32Snapshot(\n DWORD dwFlags,\n DWORD th32ProcessID\n);\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262280",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30717/"
] |
262,330
|
<p>Is there a common or established algorithm for peer-nodes in a network to decide on a unique "network-channel" (or any other form of semi-secret identifier)?</p>
<p>The environment I'm working in is SecondLife. I am trying to figure out how to get many identical peer scripted objects to agree on a "channel" number which allows them to form a network, without interfering with other existing networks of the same kind of objects.</p>
<p>All objects get instantiated at roughly the same time, and have access to the (common) system time.</p>
<p>Approaches I've thought of:</p>
<ol>
<li><p>Time-of-instantiation based. Channel is derived (by md5) from the unix time. Problem is the "<strong>roughly</strong> the same time" part. They may get instantiated right on the cusp of a new second.</p></li>
<li><p>Random wait. Make objects wait a random amount, and announce a (randomly generated) channel number decided upon by the first one to wake. Problem is, the system has a low time granularity, and more than one object can wake before the announcement was processed.</p></li>
<li><p>Combine 1 and 2. Announce a high-res timestamp after waiting a random amount, and derive channel from the lowest announced timestamp.</p></li>
</ol>
<p>This has to be something smarter people than me have thought about. Any better way of doing this?</p>
|
[
{
"answer_id": 671632,
"author": "Domchi",
"author_id": 29192,
"author_profile": "https://Stackoverflow.com/users/29192",
"pm_score": 1,
"selected": false,
"text": "integer time = llGetUnixTime();\ninteger channel = time - (time % 1000);\n"
},
{
"answer_id": 1029730,
"author": "btubbs",
"author_id": 120871,
"author_profile": "https://Stackoverflow.com/users/120871",
"pm_score": 0,
"selected": false,
"text": "integer networkchannel = 3495293;\nllRezObject(\"myobject\", rezpos, rezvel, rezrot, networkchannel);\n on_rez(integer networkchannel)\n{\n llListen(networkchannel, \"\", NULL_KEY, \"\");\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262330",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,338
|
<p>In oracle, I want to create a delete sproc that returns an integer based on the outcome of the deletion.</p>
<p>this is what i have so far.</p>
<pre><code>create or replace
PROCEDURE Testing
(
iKey IN VARCHAR2
)
AS
BEGIN
delete from MyTable WHERE
TheKey = iKey;
END Testing;
</code></pre>
<p>i've tried putting a RETURNS INTEGER in but the sproc won't compile.</p>
|
[
{
"answer_id": 262370,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 4,
"selected": false,
"text": "CREATE OR REPLACE PROCEDURE test_proc (\n p_iKey IN VARCHAR2,\n p_retVal OUT INTEGER\n)\nAS\nBEGIN\n DELETE FROM myTable\n WHERE theKey = p_iKey;\n\n IF( SQL%ROWCOUNT >= 1 )\n THEN\n p_retVal := 1;\n ELSE\n p_retVal := 0;\n END IF;\nEND test_proc;\n"
},
{
"answer_id": 262384,
"author": "Jacob Schoen",
"author_id": 3340,
"author_profile": "https://Stackoverflow.com/users/3340",
"pm_score": 0,
"selected": false,
"text": "FUNCTION TESTING (iKEY IN VARCHAR2) RETURN NUMBER\nIS\n v_count NUMBER;\n yourNumber NUMBER;\nBEGIN\n\n SELECT COUNT(*) INTO v_count\n FROM MyTable\n WHERE TheKey = iKey;\n\n IF v_count > 0\n THEN\n DELETE FROM MyTable \n WHERE TheKey = iKey;\n\n SELECT COUNT(*) INTO v_count\n FROM MyTable\n WHERE TheKey = iKey;\n\n IF (v_count = 0)\n THEN\n yourNumber := 1; --means successful deletion\n END IF;\n ELSE\n yourNumber := 0; --means no items to delete\n END IF;\n return yourNumber;\n\n EXCEPTION\n WHEN OTHERS THEN\n RETURN -1; --means error was encountered\nEND TESTING;\n"
},
{
"answer_id": 262514,
"author": "stjohnroe",
"author_id": 2985,
"author_profile": "https://Stackoverflow.com/users/2985",
"pm_score": 3,
"selected": true,
"text": "create or replace\nFUNCTION Testing\n( \niKey IN VARCHAR2\n) RETURN INTEGER\n AS \n\nBEGIN\n delete from MyTable WHERE \n TheKey = iKey;\n\n RETURN SQL%ROWCOUNT;\n\nEND Testing;\n"
},
{
"answer_id": 270520,
"author": "user34850",
"author_id": 34850,
"author_profile": "https://Stackoverflow.com/users/34850",
"pm_score": 3,
"selected": false,
"text": "CREATE OR REPLACE PROCEDURE testing (iKey IN VARCHAR2, oRes OUT NUMBER)\nAS\nBEGIN\n DELETE FROM MyTable\n WHERE TheKey = iKey;\n\n oRes := SQL%ROWCOUNT;\nEND;\n DECLARE\n pRes NUMBER;\nBEGIN\n testing ('myspecialkey', pRes);\n DBMS_OUTPUT.put_line (pRes);\nEND;\n"
},
{
"answer_id": 20140863,
"author": "PG08 de Spurs",
"author_id": 3021003,
"author_profile": "https://Stackoverflow.com/users/3021003",
"pm_score": 0,
"selected": false,
"text": "SQL%ROWCOUNT row_count := row_count + SQL%ROWCOUNT;\n row_count := 0;"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21180/"
] |
262,339
|
<p>I'd like to use the ADO.NET Entity Framework for data access, extend its objects for my business logic, and bind those objects to controls in my UI.</p>
<p>As explained in <a href="https://stackoverflow.com/questions/260233/how-do-i-extend-adonet-entity-framework-objects-with-partial-classes">the answers to another question</a>, I cannot extend ADO.NET Entity Framework objects with partial classes and use my custom methods in LINQ queries.</p>
<p><a href="http://img221.imageshack.us/img221/7329/clientsq0.gif" rel="nofollow noreferrer">ADO.NET Entity Framework partial class http://img221.imageshack.us/img221/7329/clientsq0.gif</a></p>
<p>I don't want methods showing up in the Intellisense that are going to create run-time errors! How should I architect my application to avoid this problem?</p>
<p><a href="http://img83.imageshack.us/img83/1580/iswashingtongn0.gif" rel="nofollow noreferrer">VB.NET LINQ with custom method http://img83.imageshack.us/img83/1580/iswashingtongn0.gif</a></p>
<p>Do I need a data access Client class and also a business logic Client class? It seems like that will get confusing.</p>
|
[
{
"answer_id": 262375,
"author": "CubanX",
"author_id": 27555,
"author_profile": "https://Stackoverflow.com/users/27555",
"pm_score": 2,
"selected": false,
"text": "public class Location\n{\n public string City { get; set; }\n public string State { get; set; }\n}\n public static class LocationManager\n{\n public static bool IsWashington(this Location location)\n {\n return location.State == \"WA\";\n }\n}\n Location location = new Location { State = \"WA\" };\nLocationManager.IsWashington(location);\n Location location = new Location { State = \"WA\" };\nlocation.IsWashington();\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262339",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
262,341
|
<p>I have a requirement to allow a user of this ASP.NET web application to upload a specifically formatted Excel spreadsheet, fill arrays with data from the spreadsheet, and bind the arrays to a Oracle stored procedure for validation and insertion into the database. I must be able to read the data from the Excel spreadsheet without being able to save it to the web server's hard disk. This is the part I cannot figure out how to do. Here's a simple code example.</p>
<pre><code><%--ASP.NET Declarative--%>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Send File" OnClick="Button1_Click" />
// C# Code-Behind
protected void Button1_Click(object sender, EventArgs e) {
var postedFile = FileUpload1.PostedFile;
// ... Read file in memory and put in format to send to stored procedure ...
}
</code></pre>
<p>Can anyone help me with this? I appreciate anyone's consideration.</p>
<p>thx,<br />
gabe</p>
|
[
{
"answer_id": 262646,
"author": "hearn",
"author_id": 30096,
"author_profile": "https://Stackoverflow.com/users/30096",
"pm_score": 0,
"selected": false,
"text": "Workbook.Load(stream)"
},
{
"answer_id": 269515,
"author": "gabe",
"author_id": 34315,
"author_profile": "https://Stackoverflow.com/users/34315",
"pm_score": 3,
"selected": false,
"text": "System.Data.DataSet <%--ASP.NET Declarative--%>\n<asp:FileUpload ID=\"FileUpload1\" runat=\"server\" />\n<asp:Button ID=\"Button1\" runat=\"server\" Text=\"Send File\" OnClick=\"Button1_Click\" />\n<asp:GridView ID=\"GridView1\" runat=\"server\" />\n\n// C# Code-Behind\nprotected void Button1_Click(object sender, EventArgs e) {\n // the ExcelDataReader takes a System.IO.Stream object\n var excelReader = new ExcelDataReader(FileUpload1.FileContent);\n FileUpload1.FileContent.Close();\n\n DataSet wb = excelReader.WorkbookData;\n // get the first worksheet of the workbook\n DataTable dt = excelReader.WorkbookData.Tables[0];\n\n GridView1.DataSource = dt.AsDataView();\n GridView1.DataBind();\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,351
|
<p>I have several identical elements with different attributes that I'm accessing with SimpleXML:</p>
<pre><code><data>
<seg id="A1"/>
<seg id="A5"/>
<seg id="A12"/>
<seg id="A29"/>
<seg id="A30"/>
</data>
</code></pre>
<p>I need to remove a specific <strong>seg</strong> element, with an id of "A12", how can I do this? I've tried looping through the <strong>seg</strong> elements and <em>unset</em>ting the specific one, but this doesn't work, the elements remain.</p>
<pre><code>foreach($doc->seg as $seg)
{
if($seg['id'] == 'A12')
{
unset($seg);
}
}
</code></pre>
|
[
{
"answer_id": 262556,
"author": "Stefan Gehrig",
"author_id": 11354,
"author_profile": "https://Stackoverflow.com/users/11354",
"pm_score": 7,
"selected": true,
"text": "SimpleXMLElement DOMElement $data='<data>\n <seg id=\"A1\"/>\n <seg id=\"A5\"/>\n <seg id=\"A12\"/>\n <seg id=\"A29\"/>\n <seg id=\"A30\"/>\n</data>';\n$doc=new SimpleXMLElement($data);\nforeach($doc->seg as $seg)\n{\n if($seg['id'] == 'A12') {\n $dom=dom_import_simplexml($seg);\n $dom->parentNode->removeChild($dom);\n }\n}\necho $doc->asXml();\n <?xml version=\"1.0\"?>\n<data><seg id=\"A1\"/><seg id=\"A5\"/><seg id=\"A29\"/><seg id=\"A30\"/></data>\n $segs=$doc->xpath('//seq[@id=\"A12\"]');\nif (count($segs)>=1) {\n $seg=$segs[0];\n}\n// same deletion procedure as above\n"
},
{
"answer_id": 345872,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "$username = $_GET['delete_account'];\necho \"DELETING: \".$username;\n$xml = simplexml_load_file(\"users.xml\");\n\n$str = \"<?xml version=\\\"1.0\\\"?>\n<users>\";\nforeach($xml->children() as $child){\n if($child->getName() == \"user\") {\n if($username == $child['name']) {\n continue;\n } else {\n $str = $str.$child->asXML();\n }\n }\n}\n$str = $str.\"\n</users>\";\necho $str;\n\n$xml->asXML(\"users_backup.xml\");\n$myFile = \"users.xml\";\n$fh = fopen($myFile, 'w') or die(\"can't open file\");\nfwrite($fh, $str);\nfclose($fh);\n"
},
{
"answer_id": 394722,
"author": "datasn.io",
"author_id": 49318,
"author_profile": "https://Stackoverflow.com/users/49318",
"pm_score": 5,
"selected": false,
"text": "$str = <<<STR\n<a>\n <b>\n <c>\n </c>\n </b>\n</a>\nSTR;\n\n$xml = simplexml_load_string($str);\nunset($xml –> a –> b –> c); // this would remove node c\necho $xml –> asXML(); // xml document string without node c\n"
},
{
"answer_id": 1312071,
"author": "Urszula Karzelek",
"author_id": 63852,
"author_profile": "https://Stackoverflow.com/users/63852",
"pm_score": 0,
"selected": false,
"text": "function Myunset($node)\n{\n unsetChildren($node);\n $parent = $node->parentNode;\n unset($node);\n}\n\nfunction unsetChildren($node)\n{\n while (isset($node->firstChild))\n {\n unsetChildren($node->firstChild);\n unset($node->firstChild);\n }\n}\n Myunset($xml->channel->item[$i]);\n"
},
{
"answer_id": 1550728,
"author": "Ilari Kajaste",
"author_id": 115807,
"author_profile": "https://Stackoverflow.com/users/115807",
"pm_score": 0,
"selected": false,
"text": "unset() $target = false;\n$i = 0;\nforeach ($xml->seg as $s) {\n if ($s['id']=='A12') { $target = $i; break; }\n $i++;\n}\nif ($target !== false) {\n unset($xml->seg[$target]);\n}\n array_reverse($targets)"
},
{
"answer_id": 1737879,
"author": "Josh Davis",
"author_id": 74311,
"author_profile": "https://Stackoverflow.com/users/74311",
"pm_score": 2,
"selected": false,
"text": "// don't forget to include SimpleDOM.php\ninclude 'SimpleDOM.php';\n\n// use simpledom_load_string() instead of simplexml_load_string()\n$data = simpledom_load_string(\n '<data>\n <seg id=\"A1\"/>\n <seg id=\"A5\"/>\n <seg id=\"A12\"/>\n <seg id=\"A29\"/>\n <seg id=\"A30\"/>\n </data>'\n);\n\n// and there the magic happens\n$data->deleteNodes('//seg[@id=\"A5\"]');\n"
},
{
"answer_id": 1795569,
"author": "Witman",
"author_id": 218120,
"author_profile": "https://Stackoverflow.com/users/218120",
"pm_score": 3,
"selected": false,
"text": "//Load XML from file (or it could come from a POST, etc.)\n$xml = simplexml_load_file('fileName.xml');\n\n//Use XPath to find target node for removal\n$target = $xml->xpath(\"//seg[@id=$uniqueIdToDelete]\");\n\n//If target does not exist (already deleted by someone/thing else), halt\nif(!$target)\nreturn; //Returns null\n\n//Import simpleXml reference into Dom & do removal (removal occurs in simpleXML object)\n$domRef = dom_import_simplexml($target[0]); //Select position 0 in XPath array\n$domRef->parentNode->removeChild($domRef);\n\n//Format XML to save indented tree rather than one line and save\n$dom = new DOMDocument('1.0');\n$dom->preserveWhiteSpace = false;\n$dom->formatOutput = true;\n$dom->loadXML($xml->asXML());\n$dom->save('fileName.xml');\n"
},
{
"answer_id": 2437056,
"author": "posthy",
"author_id": 292772,
"author_profile": "https://Stackoverflow.com/users/292772",
"pm_score": -1,
"selected": false,
"text": "foreach($doc->seg as &$seg) \n{\n if($seg['id'] == 'A12')\n {\n unset($seg);\n }\n}\n"
},
{
"answer_id": 2461606,
"author": "joan16v",
"author_id": 295590,
"author_profile": "https://Stackoverflow.com/users/295590",
"pm_score": 1,
"selected": false,
"text": "simple_xml unset() $pos=$this->xml->getXMLUser();\n$i=0; $array_pos=array();\nforeach($this->xml->doc->users->usr[$pos]->u_cfg_root->profiles->profile as $profile) {\n if($profile->p_timestamp=='0') { $array_pos[]=$i; }\n $i++;\n}\n//print_r($array_pos);\nfor($i=0;$i<count($array_pos);$i++) {\n unset($this->xml->doc->users->usr[$pos]->u_cfg_root->profiles->profile[$array_pos[$i]]);\n}\n"
},
{
"answer_id": 3577996,
"author": "sunnyface45",
"author_id": 432165,
"author_profile": "https://Stackoverflow.com/users/432165",
"pm_score": 3,
"selected": false,
"text": "$data = '<data>\n<seg id=\"A1\"/>\n<seg id=\"A5\"/>\n<seg id=\"A12\"/>\n<seg id=\"A29\"/>\n<seg id=\"A30\"/></data>';\n\n$doc = new SimpleXMLElement($data);\n\n$segarr = $doc->seg;\n\n$count = count($segarr);\n\n$j = 0;\n\nfor ($i = 0; $i < $count; $i++) {\n\n if ($segarr[$j]['id'] == 'A12') {\n unset($segarr[$j]);\n $j = $j - 1;\n }\n $j = $j + 1;\n}\n\necho $doc->asXml();\n"
},
{
"answer_id": 3687592,
"author": "Michał Tatarynowicz",
"author_id": 49564,
"author_profile": "https://Stackoverflow.com/users/49564",
"pm_score": 2,
"selected": false,
"text": "class MyXML extends SimpleXMLElement {\n\n public function find($xpath) {\n $tmp = $this->xpath($xpath);\n return isset($tmp[0])? $tmp[0]: null;\n }\n\n public function remove() {\n $dom = dom_import_simplexml($this);\n return $dom->parentNode->removeChild($dom);\n }\n\n}\n\n// Example: removing the <bar> element with id = 1\n$foo = new MyXML('<foo><bar id=\"1\"/><bar id=\"2\"/></foo>');\n$foo->find('//bar[@id=\"1\"]')->remove();\nprint $foo->asXML(); // <foo><bar id=\"2\"/></foo>\n"
},
{
"answer_id": 16062633,
"author": "hakre",
"author_id": 367456,
"author_profile": "https://Stackoverflow.com/users/367456",
"pm_score": 6,
"selected": false,
"text": "unset() list($element) = $doc->xpath('/*/seg[@id=\"A12\"]');\n $element unset($element[0]);\n unset($element->{0});\n unset($doc->xpath('/*/seg[@id=\"A12\"]')[0][0]);\n <?php\n/**\n * Remove a child with a specific attribute, in SimpleXML for PHP\n * @link http://stackoverflow.com/a/16062633/367456\n */\n\n$data=<<<DATA\n<data>\n <seg id=\"A1\"/>\n <seg id=\"A5\"/>\n <seg id=\"A12\"/>\n <seg id=\"A29\"/>\n <seg id=\"A30\"/>\n</data>\nDATA;\n\n\n$doc = new SimpleXMLElement($data);\n\nunset($doc->xpath('seg[@id=\"A12\"]')[0]->{0});\n\n$doc->asXml('php://output');\n <?xml version=\"1.0\"?>\n<data>\n <seg id=\"A1\"/>\n <seg id=\"A5\"/>\n\n <seg id=\"A29\"/>\n <seg id=\"A30\"/>\n</data>\n"
},
{
"answer_id": 16691801,
"author": "Ben Yitzhaki",
"author_id": 1138430,
"author_profile": "https://Stackoverflow.com/users/1138430",
"pm_score": 0,
"selected": false,
"text": "unset($XML->xpath(\"NODESNAME[@id='test']\")[0]->{0});\n"
},
{
"answer_id": 17426636,
"author": "WoodrowShigeru",
"author_id": 2126442,
"author_profile": "https://Stackoverflow.com/users/2126442",
"pm_score": 0,
"selected": false,
"text": "$item = $xml->xpath(\"//seg[@id='A12']\");\n$page = $xml->xpath(\"/data\");\n$id = \"A12\";\n\nif ( count($item) && count($page) ) {\n $item = $item[0];\n $page = $page[0];\n\n // find the numerical index within ->children().\n $ch = $page->children();\n $ch_as_array = (array) $ch;\n\n if ( count($ch_as_array) && isset($ch_as_array['seg']) ) {\n $ch_as_array = $ch_as_array['seg'];\n $index_in_array = array_search($item, $ch_as_array);\n if ( ($index_in_array !== false)\n && ($index_in_array !== null)\n && isset($ch[$index_in_array])\n && ($ch[$index_in_array]['id'] == $id) ) {\n\n // delete it!\n unset($ch[$index_in_array]);\n\n echo \"<pre>\"; var_dump($xml); echo \"</pre>\";\n }\n } // end of ( if xml object successfully converted to array )\n} // end of ( valid item AND section )\n"
},
{
"answer_id": 34970296,
"author": "Daniele Orlando",
"author_id": 1750243,
"author_profile": "https://Stackoverflow.com/users/1750243",
"pm_score": 0,
"selected": false,
"text": "$doc = fluidify($doc);\n\n$doc->remove('//*[@id=\"A12\"]');\n //*[@id=\"A12\"] // * id A12 [@id=\"A12\"]"
},
{
"answer_id": 35887177,
"author": "Columbus",
"author_id": 1213292,
"author_profile": "https://Stackoverflow.com/users/1213292",
"pm_score": 0,
"selected": false,
"text": "for ( $i = 9999; $i > 10; $i--) {\n unset($xml->xpath('/rss/channel/item['. $i .']')[0]->{0});\n}\n for ( $i = 10; $i < 9999; $i ++ ) {\n unset($xml->xpath('/rss/channel/item[' . $i . ']')[0]->{0});\n}\n"
},
{
"answer_id": 39202726,
"author": "Krzysztof Przygoda",
"author_id": 2254935,
"author_profile": "https://Stackoverflow.com/users/2254935",
"pm_score": 2,
"selected": false,
"text": "SimpleXMLElement class SimpleXMLElementExtended extends SimpleXMLElement\n{ \n /**\n * Removes or keeps nodes with given attributes\n *\n * @param string $attributeName\n * @param array $attributeValues\n * @param bool $keep TRUE keeps nodes and removes the rest, FALSE removes nodes and keeps the rest \n * @return integer Number o affected nodes\n *\n * @example: $xml->o->filterAttribute('id', $products_ids); // Keeps only nodes with id attr in $products_ids\n * @see: http://stackoverflow.com/questions/17185959/simplexml-remove-nodes\n */\n public function filterAttribute($attributeName = '', $attributeValues = array(), $keepNodes = TRUE)\n { \n $nodesToRemove = array();\n\n foreach($this as $node)\n {\n $attributeValue = (string)$node[$attributeName];\n\n if ($keepNodes)\n {\n if (!in_array($attributeValue, $attributeValues)) $nodesToRemove[] = $node;\n }\n else\n { \n if (in_array($attributeValue, $attributeValues)) $nodesToRemove[] = $node;\n }\n }\n\n $result = count($nodesToRemove);\n\n foreach ($nodesToRemove as $node) {\n unset($node[0]);\n }\n\n return $result;\n }\n}\n $doc <seg id=\"A12\"/> $data='<data>\n <seg id=\"A1\"/>\n <seg id=\"A5\"/>\n <seg id=\"A12\"/>\n <seg id=\"A29\"/>\n <seg id=\"A30\"/>\n</data>';\n\n$doc=new SimpleXMLElementExtended($data);\n$doc->seg->filterAttribute('id', ['A12'], FALSE);\n <seg /> $doc->seg->filterAttribute('id', ['A1', 'A12', 'A29'], FALSE);\n <seg id=\"A5\"/> <seg id=\"A30\"/> $doc->seg->filterAttribute('id', ['A5', 'A30'], TRUE);\n"
},
{
"answer_id": 69392700,
"author": "Lev Zadumkin",
"author_id": 8972280,
"author_profile": "https://Stackoverflow.com/users/8972280",
"pm_score": 0,
"selected": false,
"text": "<rups>\n <rup id=\"1\">\n <profiles> ... </profiles>\n <sections>\n <section id=\"1.1\" num=\"Б1.В\" parent_id=\"\"/>\n <section id=\"1.1.1\" num=\"Б1.В.1\" parent_id=\"1.1\"/>\n ...\n <section id=\"1.1\" num=\"Б1.В\" parent_id=\"\"/>\n <section id=\"1.1.2\" num=\"Б1.В.2\" parent_id=\"1.1\"/>\n ...\n </sections>\n </rup>\n <rup id=\"2\">\n ...\n </rup>\n ...\n </rups>\n rups/rup[@id='1']/sections/section[@id='1.1'] $xml = simplexml_load_file('rup.xml');\nforeach ($xml->rup as $rup) {\n $r_s = [];\n $bads_r_s = 0;\n $sections = &$rup->sections->section;\n for ($i = count($sections)-1; $i >= 0; --$i) {\n if (in_array((string)$sections[$i]['id'], $r_s)) {\n $bads_r_s++;\n unset($sections[$i]);\n continue;\n }\n $r_s[] = (string)$sections[$i]['id'];\n }\n}\n$xml->saveXML('rup_checked.xml');\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33739/"
] |
262,361
|
<p>I've been trying to design a database schema for a side project but I havent been able to produce anything that I'm comfortable with. I'm using ASP.Net with LINQ for my data access:</p>
<p>I'm going to allow users to specify up to 10 "items" each with 2 numeric properties, and 1 referential property, the item name.</p>
<p>If I were to put this entry into 1 row, it would easily equal out to some 30+ columns (minimum), e.g.
item_1_name (ref)
item_1_weight
item_1_volume
item_2_name... etc...</p>
<p>And I can't simply turn these columns into referential tables as each property can essentially range from 1 to 400+.</p>
<p>I also figured that if a user only decides to put 1 item into their entry, the method of which I create the object for that data will be static as with LINQ I'd have to check whether the properties and whatnot are NULL and work accordingly. Also, if I ever wanted to increase the number of items allowed in an entry, it'd be a headache to work with.</p>
<p>The other option I've thought of is simply creating a row for each item and tying it with an entry id. So I'd essentially never have null entries, but my table would grow astronomically deep but not very wide, as there would only be some 5 odd columns.</p>
<p>Is there something I'm overlooking in my design/is there a much better and efficient way of doing this?</p>
<p>EDIT: When I say that it will grow astronomically, I mean it in this sense: A user can create an entry, and each entry will most likely have a group of items. So say they make 1 entry a day to the site, they could have 3 groups of items, with the max number of items (10), which would equate to 30 items for that sole entry. Make an entry everyday for a week at that rate and you could have 210 rows for that single user.</p>
|
[
{
"answer_id": 262412,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 3,
"selected": true,
"text": "CREATE TABLE Items (\n user_id INTEGER NOT NULL,\n item_id INTEGER NOT NULL DEFAULT 1,\n numeric_property1 INTEGER,\n numeric_property2 INTEGER,\n referential_property INTEGER,\n PRIMARY KEY (user_id, item_id),\n FOREIGN KEY (user_id) REFERENCES Users(user_id)\n ON DELETE CASCADE,\n FOREIGN KEY (item_id) REFERENCES num_items(item_id),\n FOREIGN KEY (referential_property) REFERENCES some_other_table(some_column)\n);\n num_items CREATE TABLE num_items (item_id INTEGER NOT NULL );\nINSERT INTO num_items (item_id) \n VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);\n COUNT() MIN() MAX() item_id entity_id item_id"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30816/"
] |
262,362
|
<p>On Ubuntu Linux with Gnome, running my Swing application by double clicking on the jar file in Gnomes file browser leads to errors because required libraries that are dynamically loaded via the Java Plugin Framework (residing in subdirectories) are not found.</p>
<p>The base libraries for the framework itself are resolved correctly, as stated in my executable jar's manifest file.
However, once the framework launches, no plugins (not even the one specifying my platform) are found.</p>
<p>Launching the application from the terminal via</p>
<pre>
java -jar myjar.jar
</pre>
<p>works like a charm, ad does running the application by double-clicking a shell-script.</p>
<p>However, I'd like to avoid a terminal window. (I'm a Windows person, maybe it won't annoy linux people as it does annoy those on windows.)</p>
<p>The problem is reproducible across several Linux systems.
Is there something I need to do so Java resolves the libraries correctly?</p>
|
[
{
"answer_id": 262600,
"author": "shyam",
"author_id": 7616,
"author_profile": "https://Stackoverflow.com/users/7616",
"pm_score": 0,
"selected": false,
"text": "Class-Path"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25141/"
] |
262,363
|
<p>I'm working on a stripes app that uses a bit of jQuery to make the UI more dynamic/usable.</p>
<p>I set up an Error Resolution, so if an error is thrown, the user is redirected to an error.jsp page.</p>
<p>However, if an error is thrown during a jQuery Ajax call, instead of redirecting to the error.jsp page, I get html printed to the page where the result of the call should have been instead.</p>
<p>How do I tell jQuery to redirect if an exception was thrown instead of printing to the page?</p>
<p>An example of the offending Ajax:</p>
<pre><code>$.post("SendStatusEmail.action",
{status: newstatus, id : id },
function(data) {
column.text(data);
column.addClass("redfont");
column.parent().fadeOut(3000, function(){column.parent().remove()});
</code></pre>
|
[
{
"answer_id": 262449,
"author": "Craig Stuntz",
"author_id": 7714,
"author_profile": "https://Stackoverflow.com/users/7714",
"pm_score": 3,
"selected": true,
"text": "$(document).ajaxError(function(event, XMLHttpRequest, ajaxOptions, thrownError) {\n // redirect here.\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31172/"
] |
262,367
|
<p>In my spring application context file, I have something like:</p>
<pre><code><util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.String">
<entry key="some_key" value="some value" />
<entry key="some_key_2" value="some value" />
</util:map>
</code></pre>
<p>In java class, the implementation looks like:</p>
<pre><code>private Map<String, String> someMap = new HashMap<String, String>();
someMap = (HashMap<String, String>)getApplicationContext().getBean("someMap");
</code></pre>
<p>In Eclipse, I see a warning that says:</p>
<p><strong>Type safety: Unchecked cast from Object to HashMap<String,String></strong></p>
<p>What went wrong?</p>
|
[
{
"answer_id": 262416,
"author": "MetroidFan2002",
"author_id": 8026,
"author_profile": "https://Stackoverflow.com/users/8026",
"pm_score": 9,
"selected": true,
"text": "HashMap private Map<String, String> someMap = (HashMap<String, String>)getApplicationContext().getBean(\"someMap\");\n HashMap HashMap if(getApplicationContext().getBean(\"someMap\") instanceof HashMap) {\n private Map<String, String> someMap = (HashMap<String, String>)getApplicationContext().getBean(\"someMap\");\n}\n getBean Object HashMap HashMap<String, String> HashMap<Object, Object> HashMap<String, String> HashMap<Date, Calendar> String value = map.get(\"thisString\"); ClassCastException"
},
{
"answer_id": 262417,
"author": "David M. Karr",
"author_id": 10508,
"author_profile": "https://Stackoverflow.com/users/10508",
"pm_score": 5,
"selected": false,
"text": "@SuppressWarnings (value=\"unchecked\")\n"
},
{
"answer_id": 262418,
"author": "David Nehme",
"author_id": 14167,
"author_profile": "https://Stackoverflow.com/users/14167",
"pm_score": 3,
"selected": false,
"text": "someMap=getApplicationContext().getBean<HashMap<String, String>>(\"someMap\");\n"
},
{
"answer_id": 262539,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 9,
"selected": false,
"text": "HashMap<String,String> HashMap<Foo,Bar> Foo Bar @SuppressWarnings(\"unchecked\")"
},
{
"answer_id": 13387897,
"author": "Larry Landry",
"author_id": 1469526,
"author_profile": "https://Stackoverflow.com/users/1469526",
"pm_score": 7,
"selected": false,
"text": "List<Object> List<String> List<Integer> List<String> strList = (List<String>) someFunction();\nString s = strList.get(0);\n List<?> strList = (List<?>) someFunction();\nString s = (String) strList.get(0);\n"
},
{
"answer_id": 36603684,
"author": "Rabbit",
"author_id": 1412805,
"author_profile": "https://Stackoverflow.com/users/1412805",
"pm_score": 3,
"selected": false,
"text": "private Map<String, String> someMap = new HashMap<String, String>();\n public class StringMap extends HashMap<String, String>()\n{\n // Override constructors\n}\n someMap = (StringMap) getApplicationContext().getBean(\"someMap\");\n"
},
{
"answer_id": 40162894,
"author": "Jeremy",
"author_id": 160811,
"author_profile": "https://Stackoverflow.com/users/160811",
"pm_score": 2,
"selected": false,
"text": "@SupressWarnings(\"unchecked\") @SuppressWarnings(\"unchecked\")\npublic static List<String> getFooStrings(Map<String, List<String>> ctx) {\n return (List<String>) ctx.get(\"foos\");\n}\n"
},
{
"answer_id": 41186419,
"author": "Andy",
"author_id": 2353713,
"author_profile": "https://Stackoverflow.com/users/2353713",
"pm_score": 2,
"selected": false,
"text": "Map<String, Object> myInput = (Map<String, Object>) myRequest.get(); Map<?, ?> tempMap = (Map<?, ?>) myRequest.get(); Map<String, Object> myInput=new HashMap<>(myInputObj.size());\n for(Map.Entry<?, ?> entry :myInputObj.entrySet()){\n myInput.put((String)entry.getKey(),entry.getValue()); \n }\n"
},
{
"answer_id": 52061219,
"author": "ochakov",
"author_id": 2210454,
"author_profile": "https://Stackoverflow.com/users/2210454",
"pm_score": 2,
"selected": false,
"text": "class MyMap extends HashMap<String, String> {};\nsomeMap = (MyMap)getApplicationContext().getBean(\"someMap\");\n"
},
{
"answer_id": 57462703,
"author": "davidxxx",
"author_id": 270371,
"author_profile": "https://Stackoverflow.com/users/270371",
"pm_score": 2,
"selected": false,
"text": "Map<String,String> someMap = (Map<String,String>)getApplicationContext().getBean(\"someMap\"); Object Object getBean(String name) throws BeansException;\n <T> T getBean(String name, Class<T> requiredType) throws BeansException;\n Map<String,String> someMap = app.getBean(Map.class,\"someMap\");\n Map Map<String, String> <T> T getBean(String name, Class<T> requiredType) throws BeansException; BeanFactory @Configuration\npublic class MyConfiguration{\n\n @Bean\n public Map<String, String> someMap() {\n Map<String, String> someMap = new HashMap();\n someMap.put(\"some_key\", \"some value\");\n someMap.put(\"some_key_2\", \"some value\");\n return someMap;\n }\n}\n @Autowired\n@Qualifier(\"someMap\")\nMap<String, String> someMap;\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262367",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37740/"
] |
262,376
|
<p>After "check-in" of a <code>.docx</code> file to <code>SharePoint</code> and editing it the <code>RevNum</code> property is set to <code>2</code>.</p>
<p>This does not make sense, can someone explain why this is?</p>
|
[
{
"answer_id": 262416,
"author": "MetroidFan2002",
"author_id": 8026,
"author_profile": "https://Stackoverflow.com/users/8026",
"pm_score": 9,
"selected": true,
"text": "HashMap private Map<String, String> someMap = (HashMap<String, String>)getApplicationContext().getBean(\"someMap\");\n HashMap HashMap if(getApplicationContext().getBean(\"someMap\") instanceof HashMap) {\n private Map<String, String> someMap = (HashMap<String, String>)getApplicationContext().getBean(\"someMap\");\n}\n getBean Object HashMap HashMap<String, String> HashMap<Object, Object> HashMap<String, String> HashMap<Date, Calendar> String value = map.get(\"thisString\"); ClassCastException"
},
{
"answer_id": 262417,
"author": "David M. Karr",
"author_id": 10508,
"author_profile": "https://Stackoverflow.com/users/10508",
"pm_score": 5,
"selected": false,
"text": "@SuppressWarnings (value=\"unchecked\")\n"
},
{
"answer_id": 262418,
"author": "David Nehme",
"author_id": 14167,
"author_profile": "https://Stackoverflow.com/users/14167",
"pm_score": 3,
"selected": false,
"text": "someMap=getApplicationContext().getBean<HashMap<String, String>>(\"someMap\");\n"
},
{
"answer_id": 262539,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 9,
"selected": false,
"text": "HashMap<String,String> HashMap<Foo,Bar> Foo Bar @SuppressWarnings(\"unchecked\")"
},
{
"answer_id": 13387897,
"author": "Larry Landry",
"author_id": 1469526,
"author_profile": "https://Stackoverflow.com/users/1469526",
"pm_score": 7,
"selected": false,
"text": "List<Object> List<String> List<Integer> List<String> strList = (List<String>) someFunction();\nString s = strList.get(0);\n List<?> strList = (List<?>) someFunction();\nString s = (String) strList.get(0);\n"
},
{
"answer_id": 36603684,
"author": "Rabbit",
"author_id": 1412805,
"author_profile": "https://Stackoverflow.com/users/1412805",
"pm_score": 3,
"selected": false,
"text": "private Map<String, String> someMap = new HashMap<String, String>();\n public class StringMap extends HashMap<String, String>()\n{\n // Override constructors\n}\n someMap = (StringMap) getApplicationContext().getBean(\"someMap\");\n"
},
{
"answer_id": 40162894,
"author": "Jeremy",
"author_id": 160811,
"author_profile": "https://Stackoverflow.com/users/160811",
"pm_score": 2,
"selected": false,
"text": "@SupressWarnings(\"unchecked\") @SuppressWarnings(\"unchecked\")\npublic static List<String> getFooStrings(Map<String, List<String>> ctx) {\n return (List<String>) ctx.get(\"foos\");\n}\n"
},
{
"answer_id": 41186419,
"author": "Andy",
"author_id": 2353713,
"author_profile": "https://Stackoverflow.com/users/2353713",
"pm_score": 2,
"selected": false,
"text": "Map<String, Object> myInput = (Map<String, Object>) myRequest.get(); Map<?, ?> tempMap = (Map<?, ?>) myRequest.get(); Map<String, Object> myInput=new HashMap<>(myInputObj.size());\n for(Map.Entry<?, ?> entry :myInputObj.entrySet()){\n myInput.put((String)entry.getKey(),entry.getValue()); \n }\n"
},
{
"answer_id": 52061219,
"author": "ochakov",
"author_id": 2210454,
"author_profile": "https://Stackoverflow.com/users/2210454",
"pm_score": 2,
"selected": false,
"text": "class MyMap extends HashMap<String, String> {};\nsomeMap = (MyMap)getApplicationContext().getBean(\"someMap\");\n"
},
{
"answer_id": 57462703,
"author": "davidxxx",
"author_id": 270371,
"author_profile": "https://Stackoverflow.com/users/270371",
"pm_score": 2,
"selected": false,
"text": "Map<String,String> someMap = (Map<String,String>)getApplicationContext().getBean(\"someMap\"); Object Object getBean(String name) throws BeansException;\n <T> T getBean(String name, Class<T> requiredType) throws BeansException;\n Map<String,String> someMap = app.getBean(Map.class,\"someMap\");\n Map Map<String, String> <T> T getBean(String name, Class<T> requiredType) throws BeansException; BeanFactory @Configuration\npublic class MyConfiguration{\n\n @Bean\n public Map<String, String> someMap() {\n Map<String, String> someMap = new HashMap();\n someMap.put(\"some_key\", \"some value\");\n someMap.put(\"some_key_2\", \"some value\");\n return someMap;\n }\n}\n @Autowired\n@Qualifier(\"someMap\")\nMap<String, String> someMap;\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,379
|
<p>I've been trying to understand the strict aliasing rules as they apply to the char pointer.</p>
<p><a href="http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html#cast_to_char_pointer" rel="nofollow noreferrer">Here</a> this is stated:</p>
<blockquote>
<p>It is always presumed that a char* may refer to an alias of any object.</p>
</blockquote>
<p>Ok so in the context of socket code, I can do this:</p>
<pre><code>struct SocketMsg
{
int a;
int b;
};
int main(int argc, char** argv)
{
// Some code...
SocketMsg msgToSend;
msgToSend.a = 0;
msgToSend.b = 1;
send(socket, (char*)(&msgToSend), sizeof(msgToSend);
};
</code></pre>
<p>But then there's this statement</p>
<blockquote>
<p>The converse is not true. Casting a char* to a pointer of any type other than a char* and dereferencing it is usually in violation of the strict aliasing rule. </p>
</blockquote>
<p>Does this mean that when I recv a char array, I can't reinterpret cast to a struct when I know the structure of the message:</p>
<pre><code>struct SocketMsgToRecv
{
int a;
int b;
};
int main()
{
SocketMsgToRecv* pointerToMsg;
char msgBuff[100];
...
recv(socket, msgBuff, 100);
// Ommiting make sure we have a complete message from the stream
// but lets assume msgBuff[0] has a complete msg, and lets interpret the msg
// SAFE!?!?!?
pointerToMsg = &msgBuff[0];
printf("Got Msg: a: %i, b: %i", pointerToMsg->a, pointerToMsg->b);
}
</code></pre>
<p>Will this second example not work because the base type is a char array and I'm casting it to a struct? How do you handle this situation in a strictly aliased world?</p>
|
[
{
"answer_id": 262401,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 2,
"selected": false,
"text": "-fstrict-aliasing union\n{\n SocketMsgToRecv msg;\n char msgBuff[100];\n};\n\nrecv(socket, msgBuff, 100);\n\nprintf(\"Got Msg: a: %i, b: %i\", msg.a, msg.b);\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8123/"
] |
262,380
|
<p>How to make a shadow to main window widget on windows using Qt?</p>
|
[
{
"answer_id": 262401,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 2,
"selected": false,
"text": "-fstrict-aliasing union\n{\n SocketMsgToRecv msg;\n char msgBuff[100];\n};\n\nrecv(socket, msgBuff, 100);\n\nprintf(\"Got Msg: a: %i, b: %i\", msg.a, msg.b);\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,392
|
<p>In an actionscript function (method) I have access to arguments.caller which returns a Function object but I can't find out the name of the function represented by this Function object.
Its toString() simply returns [Function] and I can't find any other useful accessors that give me that...
Help :-/</p>
|
[
{
"answer_id": 294462,
"author": "Ran",
"author_id": 10272,
"author_profile": "https://Stackoverflow.com/users/10272",
"pm_score": 2,
"selected": true,
"text": "39: /**\n40: * Checks that cond is true. Use this method to validate that condition\n41: * cond holds.\n42: * If cond is false, traces a severe message and returns false to indicate\n43: * check failure.\n44: *\n45: * @param cond the contition expected to be true\n46: * @param msg the message to emit in case the condition is false.\n47: *\n48: * @return false is cond is false\n49: */\n50: public static function checkTrue(cond:Boolean, msg:String):Boolean {\n51: if (!cond) {\n52: trace(\"severe\", \"CHECK FAILED at \" +\n53: **getFunctionName(arguments.caller)** + \":\\n\" + msg);\n54: }\n55: return cond;\n56: }\n\n\n94: /**\n95: * Gets the name of the function func.\n96: * Warning: Use this only in debug version, not in release\n98: *\n99: * @return The full package path to the function. null if the function\n100: * isn't found.\n101: */\n102: private static function getFunctionName(func:Function):String {\n103: var name:String = getFunctionNameRecursive(func, _global);\n108: return name;\n109: }\n110: \n111: /**\n112: * Gets the name of the function func by recursively iterating over root.\n113: * Warning: Use this only in debug version, not in release\n114: */\n115: private static function getFunctionNameRecursive(func:Function,\n116: root:Object):String {\n117: if (!root) {\n118: return null;\n119: }\n120: \n121: // Iterate over classes in this package\n122: // A class is a function with a prototype object\n123: for (var i:String in root) {\n124: if (root[i] instanceof Function && root[i].prototype != null) {\n125: // Found a class.\n126: // Iterate over class static members to see if there's a match\n127: for (var f:String in root[i]) {\n128: if(root[i][f] == func) {\n129: return i + \".\" + f;\n130: }\n131: }\n132: // Loop over the class's prototype to look for instance methods\n133: var instance:Object = root[i].prototype;\n134: // Reveal prototype's methods.\n135: // Warning: Not to be used in production code!!!\n136: // The following line make all the instance attributes visible to the\n137: // for-in construct. The \"n\" value is 8 which means \"unhide\"\n138: // See http://osflash.org/flashcoders/undocumented/assetpropflags\n139: // This operation is later undone by setting the \"n\" to 1 which means\n140: // \"hide\"\n141: _global.ASSetPropFlags(instance, null, 8, 1);\n142: for (var f:String in instance) {\n143: if(instance[f] == func) {\n144: return i + \".\" + f;\n145: }\n146: }\n147: // And hide instance methods again\n148: // This line undoes the previous ASSetPropFlags\n149: _global.ASSetPropFlags(instance, null, 1, false);\n150: }\n151: }\n152: \n153: // Iterate over sub packages. Sub packages have type \"object\"\n154: for (var i:String in root) {\n155: if (typeof(root[i]) == \"object\") {\n156: var name:String = getFunctionNameRecursive(func, root[i]);\n157: if (name) {\n158: return i + \".\" + name;\n159: }\n160: }\n161: }\n162: return null;\n163: }\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262392",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10272/"
] |
262,425
|
<p>In short - How do I translate a NETBIOS domain to a FQDN ?</p>
<p>Details:
Assuming I'm in domain A and I have user credentials for domain B which has a trust relationship with domain A (I can authenticate the credentials).
How do I get domain B's FQDN when all I have are the credentials of some authenticated user from that domain, including the netbios domain name?</p>
<p>I'm coding in C# but a COM/WMI/Win32 solution would be welcomed as well.</p>
|
[
{
"answer_id": 2005257,
"author": "Per",
"author_id": 170150,
"author_profile": "https://Stackoverflow.com/users/170150",
"pm_score": 1,
"selected": false,
"text": "DirectoryEntry rootDSE = new DirectoryEntry(\"LDAP://10.11.12.13/rootDSE\", @\"DOMAIN\\Username\", \"Password\");\nConsole.WriteLine(rootDSE.Properties[\"defaultNamingContext\"].Value);\n"
},
{
"answer_id": 65099227,
"author": "marsh-wiggle",
"author_id": 1574221,
"author_profile": "https://Stackoverflow.com/users/1574221",
"pm_score": 0,
"selected": false,
"text": "Vanara.PInvoke.NetApi32 public static string ResolveNetBIOSDomainNameToDnsName(string netBIOSName)\n{\n Vanara.PInvoke.NetApi32.DOMAIN_CONTROLLER_INFO domainDcInfo = \n Vanara.PInvoke.NetApi32.DsGetDcName(Vanara.PInvoke.NetApi32.DsGetDcNameFlags.DS_RETURN_DNS_NAME | Vanara.PInvoke.NetApi32.DsGetDcNameFlags.DS_IS_FLAT_NAME, null, netBIOSName);\n return domainDcInfo.DomainName;\n}\n\npublic static string ResolveDNSDomainNameToNetBIOSName(string dnsName)\n{\n Vanara.PInvoke.NetApi32.DOMAIN_CONTROLLER_INFO domainDcInfo = \n Vanara.PInvoke.NetApi32.DsGetDcName(Vanara.PInvoke.NetApi32.DsGetDcNameFlags.DS_RETURN_FLAT_NAME | Vanara.PInvoke.NetApi32.DsGetDcNameFlags.DS_IS_DNS_NAME, null, dnsName);\n return domainDcInfo.DomainName;\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262425",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11519/"
] |
262,427
|
<p>From the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noreferrer">Mozilla Developer Network</a>:</p>
<pre><code>[1,4,9].map(Math.sqrt)
</code></pre>
<p>will yield:</p>
<pre><code>[1,2,3]
</code></pre>
<p>Why then does this:</p>
<pre><code>['1','2','3'].map(parseInt)
</code></pre>
<p>yield this:</p>
<pre><code>[1, NaN, NaN]
</code></pre>
<p>I have tested in Firefox 3.0.1 and Chrome 0.3 and just as a disclaimer, I know this is not cross-browser functionality (no IE).</p>
<p>I found out that the following will accomplish the desired effect. However, it still doesn’t explain the errant behavior of <code>parseInt</code>.</p>
<pre><code>['1','2','3'].map(function(i){return +i;}) // returns [1,2,3]
</code></pre>
|
[
{
"answer_id": 262468,
"author": "Peter Bailey",
"author_id": 8815,
"author_profile": "https://Stackoverflow.com/users/8815",
"pm_score": 4,
"selected": false,
"text": "// Works fine\nparseInt( 4 );\nparseInt( 9 );\n\n// Breaks! Why?\n[1,4,9].map( parseInt );\n\n// Fixes the problem\n[1,4,9].map( function( num ){ return parseInt( num, 10 ) } );\n"
},
{
"answer_id": 262511,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 10,
"selected": true,
"text": "Array.map parseInt parseInt parseInt('1', 0); // OK - gives 1\nparseInt('2', 1); // FAIL - 1 isn't a legal radix\nparseInt('3', 2); // FAIL - 3 isn't legal in base 2 \n ['1','2','3'].map(function(num) { return parseInt(num, 10); });\n ['1','2','3'].map(num => parseInt(num, 10));\n parseInt 0x"
},
{
"answer_id": 26855210,
"author": "philfreo",
"author_id": 137067,
"author_profile": "https://Stackoverflow.com/users/137067",
"pm_score": 5,
"selected": false,
"text": "map parseInt ['10','1','100'].map(_.partial(parseInt, _, 10)) ['10','1','100'].map(function(x) { return parseInt(x, 10); });"
},
{
"answer_id": 31960786,
"author": "yonatanmn",
"author_id": 4391952,
"author_profile": "https://Stackoverflow.com/users/4391952",
"pm_score": 2,
"selected": false,
"text": "var parseInt10 = function(x){return parseInt(x, 10);}\n\n['0', '1', '2', '10', '15', '57'].map(parseInt10);\n//[0, 1, 2, 10, 15, 57]\n"
},
{
"answer_id": 39005879,
"author": "Vlad Bezden",
"author_id": 30038,
"author_profile": "https://Stackoverflow.com/users/30038",
"pm_score": 2,
"selected": false,
"text": "[10, 20, 30].map(x => parseInt(x))\n [10, 20, 30].map(x => parseInt(x, 10))\n"
},
{
"answer_id": 40563484,
"author": "acontell",
"author_id": 3565885,
"author_profile": "https://Stackoverflow.com/users/3565885",
"pm_score": 5,
"selected": false,
"text": "var a = ['0', '1', '2', '10', '15', '57'].map(Number);\n\nconsole.log(a); console.log(parseInt(\"19asdf\"));\nconsole.log(Number(\"19asf\"));"
},
{
"answer_id": 46760432,
"author": "Doug Coburn",
"author_id": 878906,
"author_profile": "https://Stackoverflow.com/users/878906",
"pm_score": -1,
"selected": false,
"text": "parseInt const safe = {\n parseInt: (s, opt) => {\n const { radix = 10 } = opt ? opt : {};\n return parseInt(s, radix);\n }\n}\n\nconsole.log( ['1','2','3'].map(safe.parseInt) );\nconsole.log(\n ['1', '10', '11'].map(e => safe.parseInt(e, { radix: 2 }))\n); parseInt"
},
{
"answer_id": 68380302,
"author": "Blackjack",
"author_id": 13682949,
"author_profile": "https://Stackoverflow.com/users/13682949",
"pm_score": 1,
"selected": false,
"text": "array.map(x => parseInt(x)) var arr = [\"3\", \"5\", \"7\"];\n\nconsole.log(\n arr.map(x => parseInt(x))\n);"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262427",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/208/"
] |
262,431
|
<p>What are the best algorithms for sorting data in C#? </p>
<p>Is there one sorting algorithm that can handle 80% of sorts well? </p>
<p>Please give code examples if applicable.</p>
|
[
{
"answer_id": 262464,
"author": "CubanX",
"author_id": 27555,
"author_profile": "https://Stackoverflow.com/users/27555",
"pm_score": 7,
"selected": true,
"text": ".Sort"
},
{
"answer_id": 262604,
"author": "Keltex",
"author_id": 28260,
"author_profile": "https://Stackoverflow.com/users/28260",
"pm_score": 3,
"selected": false,
"text": "List<T>.Sort() ? \n"
},
{
"answer_id": 33440691,
"author": "Yadira Garnica",
"author_id": 4855379,
"author_profile": "https://Stackoverflow.com/users/4855379",
"pm_score": 2,
"selected": false,
"text": "//O(nlogn) \npublic static void QuickSort(int[] array, int init, int end)\n{\n if (init < end)\n {\n int pivot = Partition(array, init, end);\n QuickSort(array, init, pivot-1);\n QuickSort(array, pivot + 1, end);\n } \n}\n\n//O(n)\nprivate static int Partition(int[] array, int init, int end)\n{\n int last = array[end];\n int i = init - 1;\n for (int j = init; j < end; j++)\n {\n if (array[j] <= last)\n {\n i++;\n Exchange(array, i, j); \n }\n }\n Exchange(array, i + 1, end);\n return i + 1;\n}\n\nprivate static void Exchange(int[] array, int i, int j)\n{\n int temp = array[i];\n array[i] = array[j];\n array[j] = temp;\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19020/"
] |
262,439
|
<p>I am trying to create wrapper functions for <code>free</code> and <code>malloc</code> in C to help notify me of memory leaks. Does anyone know how to declare these functions so when I call <code>malloc()</code> and <code>free()</code> it will call my custom functions and not the standards lib functions?</p>
|
[
{
"answer_id": 262481,
"author": "Alex B",
"author_id": 23643,
"author_profile": "https://Stackoverflow.com/users/23643",
"pm_score": 6,
"selected": false,
"text": "glibc gcc malloc free malloc free malloc dlsym RTLD_NEXT -ldl #define _GNU_SOURCE\n#include <dlfcn.h>\n#include <stdio.h>\n\nvoid* malloc(size_t sz)\n{\n void *(*libc_malloc)(size_t) = dlsym(RTLD_NEXT, \"malloc\");\n printf(\"malloc\\n\");\n return libc_malloc(sz);\n}\n\nvoid free(void *p)\n{\n void (*libc_free)(void*) = dlsym(RTLD_NEXT, \"free\");\n printf(\"free\\n\");\n libc_free(p);\n}\n\nint main()\n{\n free(malloc(10));\n return 0;\n}\n LD_PRELOAD LD_PRELOAD=mymalloc.so ./exe\n DYLD_INSERT_LIBRARIES"
},
{
"answer_id": 262609,
"author": "Raymond Martineau",
"author_id": 33952,
"author_profile": "https://Stackoverflow.com/users/33952",
"pm_score": 3,
"selected": false,
"text": "#define malloc(x) _my_malloc(x, __FILE__, __LINE__)\n#define free(x) _my_free(x)\n"
},
{
"answer_id": 4586534,
"author": "Grzegorz Wierzowiecki",
"author_id": 544721,
"author_profile": "https://Stackoverflow.com/users/544721",
"pm_score": 4,
"selected": false,
"text": "LD_PRELOAD=/path.../lib_fake_malloc.so ./app\n #define _GNU_SOURCE\n#include <stdio.h>\n#include <stdint.h>\n#include <dlfcn.h>\n\nvoid* malloc(size_t size)\n{\n static void* (*real_malloc)(size_t) = NULL;\n if (!real_malloc)\n real_malloc = dlsym(RTLD_NEXT, \"malloc\");\n\n void *p = real_malloc(size);\n fprintf(stderr, \"malloc(%d) = %p\\n\", size, p);\n return p;\n}\n void *\n__wrap_malloc (size_t c)\n{\n printf (\"malloc called with %zu\\n\", c);\n return __real_malloc (c);\n}\n --wrap=symbol\n Use a wrapper function for symbol.\n Any undefined reference to symbol will be resolved to \"__wrap_symbol\".\n Any undefined reference to \"__real_symbol\" will be resolved to symbol.\n"
},
{
"answer_id": 33820054,
"author": "user9869932",
"author_id": 1183098,
"author_profile": "https://Stackoverflow.com/users/1183098",
"pm_score": 4,
"selected": false,
"text": "/* \n * Link-time interposition of malloc and free using the static\n * linker's (ld) \"--wrap symbol\" flag.\n * \n * Compile the executable using \"-Wl,--wrap,malloc -Wl,--wrap,free\".\n * This tells the linker to resolve references to malloc as\n * __wrap_malloc, free as __wrap_free, __real_malloc as malloc, and\n * __real_free as free.\n */\n#include <stdio.h>\n\nvoid *__real_malloc(size_t size);\nvoid __real_free(void *ptr);\n\n\n/* \n * __wrap_malloc - malloc wrapper function \n */\nvoid *__wrap_malloc(size_t size)\n{\n void *ptr = __real_malloc(size);\n printf(\"malloc(%d) = %p\\n\", size, ptr);\n return ptr;\n}\n\n/* \n * __wrap_free - free wrapper function \n */\nvoid __wrap_free(void *ptr)\n{\n __real_free(ptr);\n printf(\"free(%p)\\n\", ptr);\n}\n \n"
},
{
"answer_id": 63061254,
"author": "michaelsnowden",
"author_id": 2770572,
"author_profile": "https://Stackoverflow.com/users/2770572",
"pm_score": 1,
"selected": false,
"text": "malloc free #ifndef ALLOCATOR_H\n#define ALLOCATOR_H\n\n#include <stddef.h>\n\nstruct Allocator;\n\ntypedef struct {\n void *(*allocate)(struct Allocator *allocator, size_t size);\n\n void (*free)(struct Allocator *allocator, void *object);\n} AllocatorVTable;\n\ntypedef struct Allocator {\n const AllocatorVTable *vptr;\n} Allocator;\n\ntypedef struct {\n Allocator super;\n char *buffer;\n size_t offset;\n size_t capacity;\n} BufferedAllocator;\n\nvoid BufferedAllocator_init(BufferedAllocator *allocator, char *buffer, size_t capacity);\n\ntypedef Allocator MallocAllocator;\n\nvoid MallocAllocator_init(MallocAllocator *allocator);\n\nvoid *Allocator_allocate(Allocator *allocator, size_t size);\n\nvoid Allocator_free(Allocator *allocator, void *object);\n\n#endif\n #include \"allocator.h\"\n#include \"malloc.h\"\n\nvoid *Allocator_allocate(Allocator *allocator, size_t size) {\n return allocator->vptr->allocate(allocator, size);\n}\n\nvoid Allocator_free(Allocator *allocator, void *object) {\n allocator->vptr->free(allocator, object);\n}\n\nvoid *BufferedAllocator_allocate(Allocator *allocator, size_t size) {\n BufferedAllocator *bufferedAllocator = (BufferedAllocator *) allocator;\n if (bufferedAllocator->offset + size > bufferedAllocator->capacity) {\n fprintf(stderr, \"buffer overflow: %ld + %ld > %ld\\n\",\n bufferedAllocator->offset, size, bufferedAllocator->capacity);\n return NULL;\n }\n bufferedAllocator->offset += size;\n return bufferedAllocator->buffer + bufferedAllocator->offset - size;\n}\n\nvoid BufferedAllocator_free(Allocator *allocator, void *object) {\n\n}\n\nconst AllocatorVTable bufferedAllocatorVTable = {\n .allocate = BufferedAllocator_allocate,\n .free = BufferedAllocator_free,\n};\n\nvoid BufferedAllocator_init(BufferedAllocator *allocator, char *buffer,\n size_t capacity) {\n allocator->super.vptr = &bufferedAllocatorVTable;\n allocator->buffer = buffer;\n allocator->offset = 0;\n allocator->capacity = capacity;\n}\n\nvoid *MallocAllocator_allocate(Allocator *allocator, size_t size) {\n return malloc(size);\n}\n\nvoid MallocAllocator_free(Allocator *allocator, void *object) {\n free(object);\n}\n\nconst AllocatorVTable mallocAllocatorVTable = {\n .allocate = MallocAllocator_allocate,\n .free = MallocAllocator_free,\n};\n\nvoid MallocAllocator_init(MallocAllocator *allocator) {\n allocator->vptr = &mallocAllocatorVTable;\n}\n #include <assert.h>\n#include \"allocator_test.h\"\n#include \"allocator.h\"\n\nvoid testAllocator() {\n {\n BufferedAllocator bufferedAllocator;\n char buffer[4];\n size_t capacity = sizeof(buffer);\n BufferedAllocator_init(&bufferedAllocator, buffer, capacity);\n Allocator *allocator = &bufferedAllocator.super;\n\n void *chill = Allocator_allocate(allocator, capacity);\n assert(chill == buffer);\n void *oops = Allocator_allocate(allocator, 1);\n assert(oops == NULL);\n }\n\n {\n MallocAllocator allocator;\n MallocAllocator_init(&allocator);\n\n void *chill = Allocator_allocate(&allocator, 100);\n assert(chill != NULL);\n void *alsoChill = Allocator_allocate(&allocator, 100);\n assert(alsoChill != NULL);\n }\n}\n Allocator * char buf[n] MallocAllocator malloc free BufferedAllocator BufferedAllocator"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262439",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,443
|
<p>I am having an issue with IEMobile accessing my site. A certain redirect I use has a 302 response code, and the headers (yep, that's app-engine):</p>
<pre>Server Development/1.0 Python/2.5.2
Date Tue, 04 Nov 2008 16:47:02 GMT
Content-Type text/html; charset=utf-8
Cache-Control no-cache
Location http://localhost/games/edit-game.html?game=110&frame_to_edit=3#input-top
Content-Length 0</pre>
<p>This works fine for most browsers. Enter IEMobile (via Windows Mobile 6.1). Upon receiving this response, IEMobile heads to</p>
<pre>http://localhost/games/edit-game.html?game=110&frame_to_edit=3</pre>
<p>Note the missing <code>#input-top</code>. What can I do?</p>
|
[
{
"answer_id": 262481,
"author": "Alex B",
"author_id": 23643,
"author_profile": "https://Stackoverflow.com/users/23643",
"pm_score": 6,
"selected": false,
"text": "glibc gcc malloc free malloc free malloc dlsym RTLD_NEXT -ldl #define _GNU_SOURCE\n#include <dlfcn.h>\n#include <stdio.h>\n\nvoid* malloc(size_t sz)\n{\n void *(*libc_malloc)(size_t) = dlsym(RTLD_NEXT, \"malloc\");\n printf(\"malloc\\n\");\n return libc_malloc(sz);\n}\n\nvoid free(void *p)\n{\n void (*libc_free)(void*) = dlsym(RTLD_NEXT, \"free\");\n printf(\"free\\n\");\n libc_free(p);\n}\n\nint main()\n{\n free(malloc(10));\n return 0;\n}\n LD_PRELOAD LD_PRELOAD=mymalloc.so ./exe\n DYLD_INSERT_LIBRARIES"
},
{
"answer_id": 262609,
"author": "Raymond Martineau",
"author_id": 33952,
"author_profile": "https://Stackoverflow.com/users/33952",
"pm_score": 3,
"selected": false,
"text": "#define malloc(x) _my_malloc(x, __FILE__, __LINE__)\n#define free(x) _my_free(x)\n"
},
{
"answer_id": 4586534,
"author": "Grzegorz Wierzowiecki",
"author_id": 544721,
"author_profile": "https://Stackoverflow.com/users/544721",
"pm_score": 4,
"selected": false,
"text": "LD_PRELOAD=/path.../lib_fake_malloc.so ./app\n #define _GNU_SOURCE\n#include <stdio.h>\n#include <stdint.h>\n#include <dlfcn.h>\n\nvoid* malloc(size_t size)\n{\n static void* (*real_malloc)(size_t) = NULL;\n if (!real_malloc)\n real_malloc = dlsym(RTLD_NEXT, \"malloc\");\n\n void *p = real_malloc(size);\n fprintf(stderr, \"malloc(%d) = %p\\n\", size, p);\n return p;\n}\n void *\n__wrap_malloc (size_t c)\n{\n printf (\"malloc called with %zu\\n\", c);\n return __real_malloc (c);\n}\n --wrap=symbol\n Use a wrapper function for symbol.\n Any undefined reference to symbol will be resolved to \"__wrap_symbol\".\n Any undefined reference to \"__real_symbol\" will be resolved to symbol.\n"
},
{
"answer_id": 33820054,
"author": "user9869932",
"author_id": 1183098,
"author_profile": "https://Stackoverflow.com/users/1183098",
"pm_score": 4,
"selected": false,
"text": "/* \n * Link-time interposition of malloc and free using the static\n * linker's (ld) \"--wrap symbol\" flag.\n * \n * Compile the executable using \"-Wl,--wrap,malloc -Wl,--wrap,free\".\n * This tells the linker to resolve references to malloc as\n * __wrap_malloc, free as __wrap_free, __real_malloc as malloc, and\n * __real_free as free.\n */\n#include <stdio.h>\n\nvoid *__real_malloc(size_t size);\nvoid __real_free(void *ptr);\n\n\n/* \n * __wrap_malloc - malloc wrapper function \n */\nvoid *__wrap_malloc(size_t size)\n{\n void *ptr = __real_malloc(size);\n printf(\"malloc(%d) = %p\\n\", size, ptr);\n return ptr;\n}\n\n/* \n * __wrap_free - free wrapper function \n */\nvoid __wrap_free(void *ptr)\n{\n __real_free(ptr);\n printf(\"free(%p)\\n\", ptr);\n}\n \n"
},
{
"answer_id": 63061254,
"author": "michaelsnowden",
"author_id": 2770572,
"author_profile": "https://Stackoverflow.com/users/2770572",
"pm_score": 1,
"selected": false,
"text": "malloc free #ifndef ALLOCATOR_H\n#define ALLOCATOR_H\n\n#include <stddef.h>\n\nstruct Allocator;\n\ntypedef struct {\n void *(*allocate)(struct Allocator *allocator, size_t size);\n\n void (*free)(struct Allocator *allocator, void *object);\n} AllocatorVTable;\n\ntypedef struct Allocator {\n const AllocatorVTable *vptr;\n} Allocator;\n\ntypedef struct {\n Allocator super;\n char *buffer;\n size_t offset;\n size_t capacity;\n} BufferedAllocator;\n\nvoid BufferedAllocator_init(BufferedAllocator *allocator, char *buffer, size_t capacity);\n\ntypedef Allocator MallocAllocator;\n\nvoid MallocAllocator_init(MallocAllocator *allocator);\n\nvoid *Allocator_allocate(Allocator *allocator, size_t size);\n\nvoid Allocator_free(Allocator *allocator, void *object);\n\n#endif\n #include \"allocator.h\"\n#include \"malloc.h\"\n\nvoid *Allocator_allocate(Allocator *allocator, size_t size) {\n return allocator->vptr->allocate(allocator, size);\n}\n\nvoid Allocator_free(Allocator *allocator, void *object) {\n allocator->vptr->free(allocator, object);\n}\n\nvoid *BufferedAllocator_allocate(Allocator *allocator, size_t size) {\n BufferedAllocator *bufferedAllocator = (BufferedAllocator *) allocator;\n if (bufferedAllocator->offset + size > bufferedAllocator->capacity) {\n fprintf(stderr, \"buffer overflow: %ld + %ld > %ld\\n\",\n bufferedAllocator->offset, size, bufferedAllocator->capacity);\n return NULL;\n }\n bufferedAllocator->offset += size;\n return bufferedAllocator->buffer + bufferedAllocator->offset - size;\n}\n\nvoid BufferedAllocator_free(Allocator *allocator, void *object) {\n\n}\n\nconst AllocatorVTable bufferedAllocatorVTable = {\n .allocate = BufferedAllocator_allocate,\n .free = BufferedAllocator_free,\n};\n\nvoid BufferedAllocator_init(BufferedAllocator *allocator, char *buffer,\n size_t capacity) {\n allocator->super.vptr = &bufferedAllocatorVTable;\n allocator->buffer = buffer;\n allocator->offset = 0;\n allocator->capacity = capacity;\n}\n\nvoid *MallocAllocator_allocate(Allocator *allocator, size_t size) {\n return malloc(size);\n}\n\nvoid MallocAllocator_free(Allocator *allocator, void *object) {\n free(object);\n}\n\nconst AllocatorVTable mallocAllocatorVTable = {\n .allocate = MallocAllocator_allocate,\n .free = MallocAllocator_free,\n};\n\nvoid MallocAllocator_init(MallocAllocator *allocator) {\n allocator->vptr = &mallocAllocatorVTable;\n}\n #include <assert.h>\n#include \"allocator_test.h\"\n#include \"allocator.h\"\n\nvoid testAllocator() {\n {\n BufferedAllocator bufferedAllocator;\n char buffer[4];\n size_t capacity = sizeof(buffer);\n BufferedAllocator_init(&bufferedAllocator, buffer, capacity);\n Allocator *allocator = &bufferedAllocator.super;\n\n void *chill = Allocator_allocate(allocator, capacity);\n assert(chill == buffer);\n void *oops = Allocator_allocate(allocator, 1);\n assert(oops == NULL);\n }\n\n {\n MallocAllocator allocator;\n MallocAllocator_init(&allocator);\n\n void *chill = Allocator_allocate(&allocator, 100);\n assert(chill != NULL);\n void *alsoChill = Allocator_allocate(&allocator, 100);\n assert(alsoChill != NULL);\n }\n}\n Allocator * char buf[n] MallocAllocator malloc free BufferedAllocator BufferedAllocator"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/96/"
] |
262,448
|
<p>Quick add on requirement in our project. A field in our DB to hold a phone number is set to only allow 10 characters. So, if I get passed "(913)-444-5555" or anything else, is there a quick way to run a string through some kind of special replace function that I can pass it a set of characters to allow?</p>
<p>Regex?</p>
|
[
{
"answer_id": 262466,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 9,
"selected": true,
"text": "string CleanPhone(string phone)\n{\n Regex digitsOnly = new Regex(@\"[^\\d]\"); \n return digitsOnly.Replace(phone, \"\");\n}\n private static Regex digitsOnly = new Regex(@\"[^\\d]\"); \n\npublic static string CleanPhone(string phone)\n{\n return digitsOnly.Replace(phone, \"\");\n}\n"
},
{
"answer_id": 262497,
"author": "Jon Norton",
"author_id": 4797,
"author_profile": "https://Stackoverflow.com/users/4797",
"pm_score": 2,
"selected": false,
"text": "string getTenDigitNumber(string input)\n{ \n StringBuilder sb = new StringBuilder();\n for(int i - 0; i < input.Length; i++)\n {\n int junk;\n if(int.TryParse(input[i], ref junk))\n sb.Append(input[i]);\n }\n return sb.ToString();\n}\n"
},
{
"answer_id": 262503,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 6,
"selected": false,
"text": "string subject = \"(913)-444-5555\";\nstring result = Regex.Replace(subject, \"[^0-9]\", \"\"); // result = \"9134445555\"\n"
},
{
"answer_id": 262533,
"author": "Wes Mason",
"author_id": 2228202,
"author_profile": "https://Stackoverflow.com/users/2228202",
"pm_score": 3,
"selected": false,
"text": "phoneNumber = Regex.Replace(phoneNumber, \"\\\\D\", String.Empty);\n"
},
{
"answer_id": 262904,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": -1,
"selected": false,
"text": "public static string cleanPhone(string inVal)\n {\n char[] newPhon = new char[inVal.Length];\n int i = 0;\n foreach (char c in inVal)\n if (c.CompareTo('0') > 0 && c.CompareTo('9') < 0)\n newPhon[i++] = c;\n return newPhon.ToString();\n }\n"
},
{
"answer_id": 7853482,
"author": "Aaron",
"author_id": 107851,
"author_profile": "https://Stackoverflow.com/users/107851",
"pm_score": 5,
"selected": false,
"text": "public static class Extensions\n{\n public static string ToDigitsOnly(this string input)\n {\n Regex digitsOnly = new Regex(@\"[^\\d]\");\n return digitsOnly.Replace(input, \"\");\n }\n}\n"
},
{
"answer_id": 21013136,
"author": "Usman Zafar",
"author_id": 1069757,
"author_profile": "https://Stackoverflow.com/users/1069757",
"pm_score": 6,
"selected": false,
"text": "phone = new String(phone.Where(c => char.IsDigit(c)).ToArray())\n"
},
{
"answer_id": 25657036,
"author": "Michael Lang",
"author_id": 1262398,
"author_profile": "https://Stackoverflow.com/users/1262398",
"pm_score": 3,
"selected": false,
"text": "RegexOptions.Compiled public static string ToDigitsOnly(this string input)\n{\n return new String(input.Where(char.IsDigit).ToArray());\n}\n"
},
{
"answer_id": 34884839,
"author": "Max-PC",
"author_id": 5774944,
"author_profile": "https://Stackoverflow.com/users/5774944",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Diagnostics;\nusing System.Text;\nusing System.Text.RegularExpressions;\n\npublic class Program\n{\n private static Regex digitsOnly = new Regex(@\"[^\\d]\");\n\n public static void Main()\n {\n Console.WriteLine(\"Init...\");\n\n string phone = \"001-12-34-56-78-90\";\n\n var sw = new Stopwatch();\n sw.Start();\n for (int i = 0; i < 1000000; i++)\n {\n DigitsOnly(phone);\n }\n sw.Stop();\n Console.WriteLine(\"Time: \" + sw.ElapsedMilliseconds);\n\n var sw2 = new Stopwatch();\n sw2.Start();\n for (int i = 0; i < 1000000; i++)\n {\n DigitsOnlyRegex(phone);\n }\n sw2.Stop();\n Console.WriteLine(\"Time: \" + sw2.ElapsedMilliseconds);\n\n Console.ReadLine();\n }\n\n public static string DigitsOnly(string phone, string replace = null)\n {\n if (replace == null) replace = \"\";\n if (phone == null) return null;\n var result = new StringBuilder(phone.Length);\n foreach (char c in phone)\n if (c >= '0' && c <= '9')\n result.Append(c);\n else\n {\n result.Append(replace);\n }\n return result.ToString();\n }\n\n public static string DigitsOnlyRegex(string phone)\n {\n return digitsOnly.Replace(phone, \"\");\n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262448",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/232/"
] |
262,450
|
<p>Why is using '*' to build a view bad ?</p>
<p>Suppose that you have a complex join and all fields may be used somewhere.</p>
<p>Then you just have to chose fields needed.</p>
<pre><code>SELECT field1, field2 FROM aview WHERE ...
</code></pre>
<p>The view "aview" could be <code>SELECT table1.*, table2.* ... FROM table1 INNER JOIN table2 ...</code></p>
<p>We have a problem if 2 fields have the same name in table1 and table2.</p>
<p>Is this only the reason why using '*' in a view is bad?</p>
<p>With '*', you may use the view in a different context because the information is there.</p>
<p>What am I missing ?</p>
<p>Regards</p>
|
[
{
"answer_id": 262484,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 2,
"selected": false,
"text": "Select * From dbname..tablename\n"
},
{
"answer_id": 262509,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": false,
"text": "*"
},
{
"answer_id": 262656,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 2,
"selected": false,
"text": "SELECT * SELECT * FROM TheView SELECT * SELECT * SELECT *"
},
{
"answer_id": 263320,
"author": "user12861",
"author_id": 12861,
"author_profile": "https://Stackoverflow.com/users/12861",
"pm_score": 4,
"selected": false,
"text": "create table temp (i int, j int)\ngo\ncreate view vtemp as select * from temp\ngo\ninsert temp select 1, 1\ngo\nalter table temp add k int\ngo\ninsert temp select 1, 1, 1\ngo\nselect * from vtemp\n"
},
{
"answer_id": 33177643,
"author": "AHiggins",
"author_id": 1225845,
"author_profile": "https://Stackoverflow.com/users/1225845",
"pm_score": 2,
"selected": false,
"text": "SELECT * -- create two tables\nCREATE TABLE temp1 (ColumnA INT, ColumnB DATE, ColumnC DECIMAL(2,1))\nCREATE TABLE temp2 (ColumnX INT, ColumnY DATE, ColumnZ DECIMAL(2,1))\nGO\n\n\n-- populate with dummy data\nINSERT INTO temp1 (ColumnA, ColumnB, ColumnC) VALUES (1, '1/1/1900', 0.5)\nINSERT INTO temp2 (ColumnX, ColumnY, ColumnZ) VALUES (1, '1/1/1900', 0.5)\nGO\n\n\n-- create a view with a pair of SELECT * statements\nCREATE VIEW vwtemp AS \nSELECT *\nFROM temp1 INNER JOIN temp2 ON 1=1\nGO\n\n\n-- SELECT showing the columns properly assigned\nSELECT * FROM vwTemp \nGO\n\n\n-- add a few columns to the first table referenced in the SELECT \nALTER TABLE temp1 ADD ColumnD varchar(1)\nALTER TABLE temp1 ADD ColumnE varchar(1)\nALTER TABLE temp1 ADD ColumnF varchar(1)\nGO\n\n\n-- populate those columns with dummy data\nUPDATE temp1 SET ColumnD = 'D', ColumnE = 'E', ColumnF = 'F'\nGO\n\n\n-- notice that the original columns have the wrong data in them now, causing any datatype-specific queries (e.g., arithmetic, dateadd, etc.) to fail\nSELECT *\nFROM vwtemp\nGO\n\n-- clean up\nDROP VIEW vwTemp\nDROP TABLE temp2\nDROP TABLE temp1\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262450",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14673/"
] |
262,451
|
<p>ShellExecute() allows me to perform simple shell tasks, allowing the system to take care of opening or printing files. I want to take a similar approach to sending an email attachment programmatically.</p>
<p>I don't want to manipulate Outlook directly, since I don't want to assume which email client the user uses by default. I don't want to send the email directly, as I want the user to have the opportunity to write the email body using their preferred client. Thus, I really want to accomplish exactly what Windows Explorer does when I right click a file and select Send To -> Mail Recipient.</p>
<p>I'm looking for a C++ solution.</p>
|
[
{
"answer_id": 264725,
"author": "Jeff Hillman",
"author_id": 3950,
"author_profile": "https://Stackoverflow.com/users/3950",
"pm_score": 4,
"selected": true,
"text": "#include <tchar.h>\n#include <windows.h>\n#include <mapi.h>\n#include <mapix.h>\n\nint _tmain( int argc, wchar_t *argv[] )\n{\n HMODULE hMapiModule = LoadLibrary( _T( \"mapi32.dll\" ) );\n\n if ( hMapiModule != NULL )\n {\n LPMAPIINITIALIZE lpfnMAPIInitialize = NULL;\n LPMAPIUNINITIALIZE lpfnMAPIUninitialize = NULL;\n LPMAPILOGONEX lpfnMAPILogonEx = NULL;\n LPMAPISENDDOCUMENTS lpfnMAPISendDocuments = NULL;\n LPMAPISESSION lplhSession = NULL;\n\n lpfnMAPIInitialize = (LPMAPIINITIALIZE)GetProcAddress( hMapiModule, \"MAPIInitialize\" );\n lpfnMAPIUninitialize = (LPMAPIUNINITIALIZE)GetProcAddress( hMapiModule, \"MAPIUninitialize\" );\n lpfnMAPILogonEx = (LPMAPILOGONEX)GetProcAddress( hMapiModule, \"MAPILogonEx\" );\n lpfnMAPISendDocuments = (LPMAPISENDDOCUMENTS)GetProcAddress( hMapiModule, \"MAPISendDocuments\" );\n\n if ( lpfnMAPIInitialize && lpfnMAPIUninitialize && lpfnMAPILogonEx && lpfnMAPISendDocuments )\n {\n HRESULT hr = (*lpfnMAPIInitialize)( NULL );\n\n if ( SUCCEEDED( hr ) )\n {\n hr = (*lpfnMAPILogonEx)( 0, NULL, NULL, MAPI_EXTENDED | MAPI_USE_DEFAULT, &lplhSession );\n\n if ( SUCCEEDED( hr ) )\n {\n // this opens the email client with \"C:\\attachment.txt\" as an attachment\n hr = (*lpfnMAPISendDocuments)( 0, \";\", \"C:\\\\attachment.txt\", NULL, NULL );\n\n if ( SUCCEEDED( hr ) )\n {\n hr = lplhSession->Logoff( 0, 0, 0 );\n hr = lplhSession->Release();\n lplhSession = NULL;\n }\n }\n }\n\n (*lpfnMAPIUninitialize)();\n }\n\n FreeLibrary( hMapiModule );\n }\n\n return 0;\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262451",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8424/"
] |
262,460
|
<p>Is there any way to make a function (the ones I'm thinking of are in the style of the simple ones I've made which generate the fibonnacci sequence from 0 to a point, and all the primes between two points) run indefinitely. E.g. until I press a certain key or until a time has passed, rather than until a number reaches a certain point? </p>
<p>Also, if it is based on time then is there any way I could just extend the time and start it going from that point again, rather than having to start again from 0? I am aware there is a time module, i just don't know much about it.</p>
|
[
{
"answer_id": 262474,
"author": "Davide",
"author_id": 25891,
"author_profile": "https://Stackoverflow.com/users/25891",
"pm_score": 1,
"selected": false,
"text": "while True:\n # check what you want and eventually break\n print nextValue()\n yield return nextValue()"
},
{
"answer_id": 262520,
"author": "Andrew Cox",
"author_id": 27907,
"author_profile": "https://Stackoverflow.com/users/27907",
"pm_score": 1,
"selected": false,
"text": "import threading, time\nrunthread = 1\ndef myfun():\n while runthread:\n print \"A\"\n time.sleep(.1)\n\nt = threading.Thread(target=myfun)\nt.start()\nraw_input(\"\")\nrunthread = 0\nt.join()\n"
},
{
"answer_id": 262542,
"author": "PierreBdR",
"author_id": 7136,
"author_profile": "https://Stackoverflow.com/users/7136",
"pm_score": 2,
"selected": false,
"text": "from threading import Thread, Lock\nfrom time import sleep\n\nclass MyFct(Thread):\n def __init__(self):\n Thread.__init__(self)\n self.mutex = Lock()\n self._quit = False\n\n def stopped(self):\n self.mutex.acquire()\n val = self._quit\n self.mutex.release()\n return val\n\n def stop(self):\n self.mutex.acquire()\n self._quit = True\n self.mutex.release()\n\n def run(self):\n i = 1\n j = 1\n print i\n print j\n while True:\n if self.stopped():\n return\n i,j = j,i+j\n print j\n\ndef main_fct():\n t = MyFct()\n t.start()\n sleep(1)\n t.stop()\n t.join()\n print \"Exited\"\n\nif __name__ == \"__main__\":\n main_fct()\n"
},
{
"answer_id": 263876,
"author": "rjmunro",
"author_id": 3408,
"author_profile": "https://Stackoverflow.com/users/3408",
"pm_score": 0,
"selected": false,
"text": "fibonnacci = [1,1]\nstoptime = time.time() + 1 # set stop time to 1 second in the future\nwhile time.time() < stoptime:\n fibonnacci.append(fibonnacci[-1]+fibonnacci[-2])\n\nprint \"Generated %s numbers, the last one was %s.\" % (len(fibonnacci),fibonnacci[-1])\n"
},
{
"answer_id": 264614,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "def finished():\n \"Define your exit condition here\"\n return ...\n\ndef count(i=0):\n while not finished():\n yield i\n i += 1\n\nfor i in count():\n print i\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33061/"
] |
262,469
|
<p>How is it possible that .NET is finding the wrong 'MyType' in this scenario?</p>
<p>I have a type A.B.C.D.MyType in a project that I'm working on, and I'm referencing a DLL that has a type A.B.MyType? I do not have any 'using A.B;' statements anywhere in my code, and I do have 'using A.B.C.D;'. When I compile, the compiler thinks any naked reference to 'MyType' means 'A.B.MyType'.</p>
<p>I know I could just rename the class or use an alias, but I'm wondering how this is even possible.</p>
<p>Any ideas?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 262532,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "A.B A.B.C using TheTypeIWant = A.B.C.D.MyType;\n TheTypeIWant using MyType=A.B.C.D.MyType"
},
{
"answer_id": 262813,
"author": "Pop Catalin",
"author_id": 4685,
"author_profile": "https://Stackoverflow.com/users/4685",
"pm_score": 5,
"selected": true,
"text": "using using Ns1.Foo.Foo2;\n\nnamespace Ns1.Foo\n{\n class Foo\n {\n public void Print()\n {\n System.Console.WriteLine(\"Ns1.Foo\");\n }\n }\n}\n\nnamespace Ns1.Foo.Foo2\n{\n class Foo\n {\n public void Print()\n {\n System.Console.WriteLine(\"Ns1.Foo.Foo2\");\n }\n }\n}\n\nnamespace Ns1.Foo.Bar\n{\n class Bar\n {\n public void Print()\n {\n new Foo().Print();\n }\n\n static void Main()\n {\n new Bar().Print();\n }\n }\n}\n namespace Ns1.Foo.Bar\n{\n using Ns1.Foo.Foo2;\n class Bar\n {\n public void Print()\n {\n new Foo().Print();\n }\n\n static void Main()\n {\n new Bar().Print();\n }\n }\n}\n Ns1.Foo.Foo2"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7529/"
] |
262,480
|
<p>what's the quickest way to extract a 5 digit number from a string in c#. </p>
<p>I've got </p>
<pre><code>string.Join(null, System.Text.RegularExpressions.Regex.Split(expression, "[^\\d]"));
</code></pre>
<p>Any others?</p>
|
[
{
"answer_id": 262501,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": false,
"text": "text int? value = null;\nstring pat = @\"\\d{5}\"\nRegex r = new Regex(pat);\nMatch m = r.Match(text);\nif (m.Success)\n{\n value = int.Parse(m.Value);\n}\n"
},
{
"answer_id": 262585,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 0,
"selected": false,
"text": "string strIWantNumFrom = \"qweqwe23qeeq3eqqew9qwer0q\";\n\nint num = int.Parse(\n string.Join( null, (\n from c in strIWantNumFrom.ToCharArray()\n where c == '1' || c == '2' || c == '3' || c == '4' || c == '5' ||\n c == '6' || c == '7' || c == '8' || c == '9' || c == '0'\n select c.ToString()\n ).ToArray() ) );\n"
},
{
"answer_id": 262743,
"author": "alexdej",
"author_id": 34304,
"author_profile": "https://Stackoverflow.com/users/34304",
"pm_score": 4,
"selected": true,
"text": "static string Search(string expression)\n{\n int run = 0;\n for (int i = 0; i < expression.Length; i++)\n {\n char c = expression[i];\n if (Char.IsDigit(c))\n run++;\n else if (run == 5)\n return expression.Substring(i - run, run);\n else\n run = 0;\n }\n return null;\n}\nconst string pattern = @\"\\d{5}\";\nstatic string NotCached(string expression)\n{\n return Regex.Match(expression, pattern, RegexOptions.Compiled).Value;\n}\n\nstatic Regex regex = new Regex(pattern, RegexOptions.Compiled);\nstatic string Cached(string expression)\n{\n return regex.Match(expression).Value;\n}\n"
},
{
"answer_id": 262864,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 0,
"selected": false,
"text": "public static string DigitsOnly(string inVal)\n {\n char[] newPhon = new char[inVal.Length];\n int i = 0;\n foreach (char c in inVal)\n if (c.CompareTo('0') > 0 && c.CompareTo('9') < 0)\n newPhon[i++] = c;\n return newPhon.ToString();\n }\n public static string DigitsOnly(string inVal)\n {\n char[] newPhon = new char[inVal.Length];\n int i = 0;\n foreach (char c in inVal)\n if (c.CompareTo('0') > 0 && c.CompareTo('9') < 0 && i < 5)\n newPhon[i++] = c;\n return newPhon.ToString();\n }\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9948/"
] |
262,493
|
<p>What would be the best way of inserting functionality into a binary application (3d party, closed source).</p>
<p>The target application is on OSX and seems to have been compiled using gcc 3+. I can see the listing of functions implemented in the binary and have debugged and isolated one particular function which I would like to remotely call.</p>
<p>Specifically, I would like to call this function - let's call it void <code>zoomByFactor(x,y)</code> - when I receive certain data from a complex HIDevice.</p>
<p>I can easily modify or inject instructions into the binary file itself (ie. the patching does not need to occur only in RAM).</p>
<p>What would you recommend as a way of "nicely" doing this?</p>
<p><strong>Edit:</strong></p>
<p>I do indeed need to entire application. So I can't ditch it and use a library. (For those who need an ethical explanation: this is a proprietary piece of CAD software whose company website hasn't been updated since 2006. I have paid for this product (quite a lot of money for what it is, really) and have project data which I can not easily migrate away from it. The product suits me just fine as it is, but I want to use a new HID which I recently got. I've examined the internals of the application, and I'm fairly confident that I can call the correct function with the relevant data and get it to work properly).</p>
<p>Here's what I've done so far, and it is quite gheto.</p>
<p>I've already modified parts of the application through this process:</p>
<pre>
xxd -g 0 binary > binary.hex
cat binary.hex | awk 'substitute work' > modified.hex
xxd -r modified.hex > newbinary
chmod 777 newbinary
</pre>
<p>I'm doing this kind of jumping through hoops because the binary is almost 100 megs large.</p>
<p>The jist of what I'm thinking is that I'd jmp somewhere in the main application loop, launch a thread, and return to the main function. </p>
<p>Now, the questions are: where can I insert the new code? do I need to modify symbol tables? alternatively, how could I make a dylib load automatically so that the only "hacking" I need to do is inserting a call to a normally loaded dylib into the main function?</p>
|
[
{
"answer_id": 275216,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "otool -l dyld: bad external relocation length fork()"
},
{
"answer_id": 23497928,
"author": "jar",
"author_id": 183677,
"author_profile": "https://Stackoverflow.com/users/183677",
"pm_score": 1,
"selected": false,
"text": "mach_star"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
262,508
|
<p>I am using some code which was originally taken from the Apple sample ViewTransitions to swap two views with each other.</p>
<pre><code>CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.3f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[[container layer] addAnimation:animation forKey:@"swap"];
</code></pre>
<p>When my transition executes on the devlice, I sometimes get a single frame flash of the final frame of the transition animation and then the animation plays smoothly. This gives a very jarring effect of the 2nd view which flickers in and then out again before the smooth animation executes.</p>
<p>The main difference between my example and the Apple example is that my views are not full screen, I have a container UIView which contains both sub-views and I am applying my animation to the container layer instead the root view layer. I can not see that this should make much difference though.</p>
<p>This issue does not happen at all in the simulator and is intermittent (about 60-70% of the time) on the device. Is anyone else seeing this behaviour and if so, how did you work around it?</p>
<p><strong>Updated with more information:</strong>
The code was originally part of a multi part animation but I moved it to be triggered by a button to isolate the problem. The issue occurs in both situations.</p>
<p>The animation delegates were implemented but have been removed to try and isolate the problem.</p>
<p>The views are not changing during the animation and in fact <code>[container setUserInteractionEnabled:NO]</code> is being called (but the problem also happens without user interaction being disabled).</p>
<p>I have tried starting the animation from the middle of the transition and ending before the end using <code>setStartProgress</code> and <code>setEndProgress</code>, again the problem persists.</p>
<p>I have tried slowing the animation duration right down as well with no effect.</p>
|
[
{
"answer_id": 275216,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "otool -l dyld: bad external relocation length fork()"
},
{
"answer_id": 23497928,
"author": "jar",
"author_id": 183677,
"author_profile": "https://Stackoverflow.com/users/183677",
"pm_score": 1,
"selected": false,
"text": "mach_star"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/262508",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4496/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.