qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
203,383
|
<p>I get obsessed with the best names for arrays and variables that I use, I'll look up words in the thesaurus, dictionary, etc..</p>
<p>So I'm trying to name this array / structure:</p>
<pre><code>$nameMe = array(
'392' => TRUE,
'234' => TRUE,
'754' => TRUE,
'464' => TRUE,
);
</code></pre>
<p>and it's used to check if that id has a certain property, like so</p>
<pre><code>if(isset($name[$id])) {
doSomething();
}
</code></pre>
<p>Problem being I'm getting really long variable names like</p>
<pre><code>$propertyNameArrayIdIndexed
</code></pre>
<p>Any ideas for how I can better name this particular function of array? or better names in general</p>
|
[
{
"answer_id": 203414,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 3,
"selected": true,
"text": "$hasProperty[$id]\n $isSomething[$id]\n $isOdd[$id]\n$isWriteable[$id]\n$hasAssociatedFile[$id]\n"
},
{
"answer_id": 203424,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 0,
"selected": false,
"text": "true $availableIds = array(392, 234, 754, 464);\n if if (in_array($myId, $availableIds)) { ... }\n"
},
{
"answer_id": 203452,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 1,
"selected": false,
"text": "Set<Property> displayableIcons String b64JpgMugshot"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5261/"
] |
203,384
|
<p>Various programs can do stuff only when you haven't used the computer for a while (eg screensaver, Google Desktop indexing, etc).</p>
<p>How do they know when it has been inactive? Is there some function in Windows that tells you how long it has been inactive, or do you have to use some kind of keyboard/mouse hook to track activity yourself?</p>
<p>I'm using C#, but I'm interested in any method of determining the inactivity.</p>
|
[
{
"answer_id": 203410,
"author": "Bill",
"author_id": 14547,
"author_profile": "https://Stackoverflow.com/users/14547",
"pm_score": 0,
"selected": false,
"text": "using System;\nusing System.Runtime.InteropServices;\nusing System.Threading;\nusing System.Windows.Forms;\n\nnamespace Example {\n\n public class Hook {\n\n delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);\n\n [FlagsAttribute]\n public enum WindowMessage {\n WM_KEYDOWN = 0x0000000000000100, // &H100\n WM_MOUSEMOVE = 0x0000000000000200, // &H200\n WM_LBUTTONDOWN = 0x0000000000000201, // &H201\n WM_RBUTTONDOWN = 0x0000000000000204, // &H204\n WH_KEYBOARD = 2,\n WH_MOUSE = 7,\n HC_ACTION = 0\n }\n\n [DllImport(\"user32.dll\",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]\n private static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);\n\n [DllImport(\"user32.dll\",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]\n private static extern bool UnhookWindowsHookEx(int idHook);\n\n [DllImport(\"user32.dll\",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]\n private static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);\n\n //Declare MouseHookProcedure as a HookProc type.\n static HookProc MouseHookProcedure;\n static HookProc KeyboardHookProcedure;\n\n private static int mhMouseHook = 0;\n private static int mhKeyboardHook = 0;\n\n public Hook() {}\n\n public static void Init() {\n MouseHookProcedure = new HookProc( MouseHookProc );\n KeyboardHookProcedure = new HookProc( KeyboardHookProc );\n mhMouseHook = SetWindowsHookEx( (int)WindowMessage.WH_MOUSE, MouseHookProcedure, (IntPtr)0, AppDomain.GetCurrentThreadId() );\n mhKeyboardHook = SetWindowsHookEx( (int)WindowMessage.WH_KEYBOARD, KeyboardHookProcedure, (IntPtr)0, AppDomain.GetCurrentThreadId() );\n }\n\n public static void Terminate() {\n UnhookWindowsHookEx( mhMouseHook );\n UnhookWindowsHookEx( mhKeyboardHook );\n }\n\n private static int MouseHookProc( int nCode, IntPtr wParam, IntPtr lParam ) {\n if ( nCode >= 0 ) {\n //do something here to update the last activity point, i.e. a keystroke was detected so reset our idle timer.\n }\n return CallNextHookEx( mhMouseHook, nCode, wParam, lParam );\n }\n\n private static int KeyboardHookProc( int nCode, IntPtr wParam, IntPtr lParam ) {\n if ( nCode >= 0 ) {\n //do something here to update the last activity point, i.e. a mouse action was detected so reset our idle timer.\n }\n return CallNextHookEx( mhKeyboardHook, nCode, wParam, lParam );\n }\n\n }\n}\n"
},
{
"answer_id": 203420,
"author": "TheSoftwareJedi",
"author_id": 18941,
"author_profile": "https://Stackoverflow.com/users/18941",
"pm_score": 5,
"selected": true,
"text": "[DllImport(\"user32.dll\")]\nstatic extern bool GetLastInputInfo(ref LASTINPUTINFO plii);\n\nstatic int GetLastInputTime()\n{\n int idleTime = 0;\n LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();\n lastInputInfo.cbSize = Marshal.SizeOf( lastInputInfo );\n lastInputInfo.dwTime = 0;\n\n int envTicks = Environment.TickCount;\n\n if( GetLastInputInfo( ref lastInputInfo ) )\n {\n int lastInputTick = lastInputInfo.dwTime;\n\n idleTime = envTicks - lastInputTick;\n }\n\n return (( idleTime > 0 ) ? ( idleTime / 1000 ) : idleTime );\n}\n\n[StructLayout( LayoutKind.Sequential )]\nstruct LASTINPUTINFO\n{\n public static readonly int SizeOf = Marshal.SizeOf(typeof(LASTINPUTINFO));\n\n [MarshalAs(UnmanagedType.U4)]\n public int cbSize; \n [MarshalAs(UnmanagedType.U4)]\n public UInt32 dwTime;\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4495/"
] |
203,397
|
<p>Is there a way to change the context sensitive help in Visual Studio so that it will only search against the text under the caret instead of a compilation error in your code?</p>
<p>More info:
After you compile and receive a compilation error(underlined), placing the caret within the underlined text and pressing <kbd>F1</kbd> will take you to the Compilation error page instead of the help for the function under the caret.
Can this behavior be changed to always go to the method/keyword help?</p>
<p>Language: C#</p>
|
[
{
"answer_id": 211389,
"author": "Robin Bennett",
"author_id": 27794,
"author_profile": "https://Stackoverflow.com/users/27794",
"pm_score": 3,
"selected": true,
"text": "int myInt = new int(3);\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4490/"
] |
203,399
|
<p>I'm running a MySQL database locally for development, but deploying to Heroku which uses Postgres. Heroku handles almost everything, but my case-insensitive Like statements become case sensitive. I could use iLike statements, but my local MySQL database can't handle that.</p>
<p>What is the best way to write a case insensitive query that is compatible with both MySQL and Postgres? Or do I need to write separate Like and iLike statements depending on the DB my app is talking to?</p>
|
[
{
"answer_id": 203419,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 7,
"selected": true,
"text": "select * from foo where upper(bar) = upper(?);\n"
},
{
"answer_id": 203428,
"author": "Adam Pierce",
"author_id": 5324,
"author_profile": "https://Stackoverflow.com/users/5324",
"pm_score": 4,
"selected": false,
"text": "SELECT whatever FROM mytable WHERE something ILIKE 'match this';\n SELECT whatever FROM mytable WHERE UPPER(something) = UPPER('match this');\n"
},
{
"answer_id": 4664415,
"author": "Sheldon Ross",
"author_id": 60789,
"author_profile": "https://Stackoverflow.com/users/60789",
"pm_score": 1,
"selected": false,
"text": "Select * from table where column ~* 'UnEvEn TeXt';\nSelect * from table where column ~ 'Uneven text';\n"
},
{
"answer_id": 10149458,
"author": "jswanner",
"author_id": 542478,
"author_profile": "https://Stackoverflow.com/users/542478",
"pm_score": 5,
"selected": false,
"text": "Author.where(Author.arel_table[:name].matches(\"%foo%\"))\n matches ILIKE LIKE"
},
{
"answer_id": 11749968,
"author": "Ben Wilhelm",
"author_id": 1461460,
"author_profile": "https://Stackoverflow.com/users/1461460",
"pm_score": 3,
"selected": false,
"text": " SELECT id FROM person WHERE name REGEXP 'john';\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23885/"
] |
203,425
|
<p>What's the ASP equivalent to PHP's <code>.=</code> when concatenating strings? I'm referring to asp NOT asp.net.</p>
<p>I meant to specify that I'm in a for-loop. So I want to know the equivalent for <code>.=</code> (in php) not standard concatenation.</p>
<p><em>Example:</em></p>
<pre><code>For Each Item In Request.Form
If (Item = "service") then
For x=1 To Request.Form(item).Count
service = "&service="&Request.Form(Item)(x)
Next
End If
Next
</code></pre>
|
[
{
"answer_id": 203429,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 3,
"selected": false,
"text": "Variable = Variable & \"something more\"\n variable += \"something more\";\n service = service & \"&service=\" & Request.Form(Item)(x)\n &service=blah1&service=blah2&service=blah3\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203425",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
203,446
|
<p>Does anyone know the format of the MAPI property <code>PR_SEARCH_KEY</code>?</p>
<p>The <a href="http://msdn.microsoft.com/en-us/library/ms529414(EXCHG.10).aspx" rel="nofollow noreferrer">online documentation</a> has this to say about it:</p>
<blockquote>
<p>The search key is formed by
concatenating the address type (in
uppercase characters), the colon
character ':', the e-mail address in
canonical form, and the terminating
null character.</p>
</blockquote>
<p>And the exchange document <a href="http://msdn.microsoft.com/en-us/library/cc433489(EXCHG.80).aspx" rel="nofollow noreferrer">MS-OXOABK</a> says this:</p>
<blockquote>
<p>The PidTagSearchKey property of type
PtypBinary is a binary value formed by
concatenating the ASCII string "EX: "
followed by the DN for the object
converted to all upper case, followed
by a zero byte value.</p>
</blockquote>
<p>However all the MAPI messages I've seen with this property have it as some sort of binary 16 byte sequence that looks like a GUID. Does anyone else have any more information about it? Is it always 16 bytes?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 206432,
"author": "Henk",
"author_id": 4613,
"author_profile": "https://Stackoverflow.com/users/4613",
"pm_score": 3,
"selected": true,
"text": "PR_SEARCH_KEY PR_SEARCH_KEY PR_SEARCH_KEY PR_SEARCH_KEY"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18437/"
] |
203,456
|
<p>I can get the executable location from the process, how do I get the icon from file?</p>
<p>Maybe use windows api LoadIcon(). I wonder if there is .NET way...</p>
|
[
{
"answer_id": 203490,
"author": "TheSoftwareJedi",
"author_id": 18941,
"author_profile": "https://Stackoverflow.com/users/18941",
"pm_score": 6,
"selected": true,
"text": "Icon ico = Icon.ExtractAssociatedIcon(theProcess.MainModule.FileName);\n"
},
{
"answer_id": 203517,
"author": "RobS",
"author_id": 18471,
"author_profile": "https://Stackoverflow.com/users/18471",
"pm_score": 4,
"selected": false,
"text": "using System;\nusing System.Drawing; //For Icon\nusing System.Reflection; //For Assembly\n\nnamespace ConsoleApplication\n{\n class Program\n {\n static void Main(string[] args)\n {\n try\n {\n //Gets the icon associated with the currently executing assembly\n //(or pass a different file path and name for a different executable)\n Icon appIcon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); \n }\n catch(ArgumentException ae) \n {\n //handle\n } \n }\n }\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44972/"
] |
203,468
|
<p>Ok, so I'm looking for a bit of architecture guidance, my team is getting a chance to re-cast certain decisions with a new feature that we're building, and I wanted to see what SO thought :-) There are of course certain things that we're not changing, so the solution would have to fit in this model. Namely, that we've got an ASP.NET application, which uses web services to allow users to perform actions on the system.</p>
<p>The problem comes in because, as with many systems, different users need access to different functions. Some roles have access to Y button, and others have access to Y and B button, while another still only has access to B. Most of the time that I see this, developers just put in a mish-mosh of if statements to deal with the UI state. My fear is that left unchecked, this will become an unmaintainable mess, because in addition to putting authorization logic in the GUI, it needs to be put in the web services (which are called via ajax) to ensure that only authorized users call certain methods.</p>
<p>so my question to you is, how can a system be designed to decrease the random ad-hoc if statements here and there that check for specific roles, which could be re-used in both GUI/webform code, and web service code.</p>
<p>Just for clarity, this is an ASP.NET web application, using webforms, and <a href="http://projects.nikhilk.net/ScriptSharp/" rel="nofollow noreferrer">Script#</a> for the AJAX functionality. Don't let the script# throw you off of answering, it's not fundamentally different than asp.net ajax :-)</p>
|
[
{
"answer_id": 203490,
"author": "TheSoftwareJedi",
"author_id": 18941,
"author_profile": "https://Stackoverflow.com/users/18941",
"pm_score": 6,
"selected": true,
"text": "Icon ico = Icon.ExtractAssociatedIcon(theProcess.MainModule.FileName);\n"
},
{
"answer_id": 203517,
"author": "RobS",
"author_id": 18471,
"author_profile": "https://Stackoverflow.com/users/18471",
"pm_score": 4,
"selected": false,
"text": "using System;\nusing System.Drawing; //For Icon\nusing System.Reflection; //For Assembly\n\nnamespace ConsoleApplication\n{\n class Program\n {\n static void Main(string[] args)\n {\n try\n {\n //Gets the icon associated with the currently executing assembly\n //(or pass a different file path and name for a different executable)\n Icon appIcon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); \n }\n catch(ArgumentException ae) \n {\n //handle\n } \n }\n }\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5416/"
] |
203,469
|
<p>How do you use enums in Oracle using SQL only? (No PSQL)</p>
<p>In MySQL you can do:</p>
<pre><code>CREATE TABLE sizes (
name ENUM('small', 'medium', 'large')
);
</code></pre>
<p>What would be a similar way to do this in Oracle?</p>
|
[
{
"answer_id": 203547,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 7,
"selected": true,
"text": "CREATE TABLE sizes (\n name VARCHAR2(10) CHECK( name IN ('small','medium','large') )\n);\n CREATE TABLE valid_names (\n name_id NUMBER PRIMARY KEY,\n name_str VARCHAR2(10)\n);\n\nINSERT INTO valid_sizes VALUES( 1, 'small' );\nINSERT INTO valid_sizes VALUES( 2, 'medium' );\nINSERT INTO valid_sizes VALUES( 3, 'large' );\n\nCREATE TABLE sizes (\n name_id NUMBER REFERENCES valid_names( name_id )\n);\n\nCREATE VIEW vw_sizes\n AS \n SELECT a.name_id name, <<other columns from the sizes table>>\n FROM valid_sizes a,\n sizes b\n WHERE a.name_id = b.name_id\n"
},
{
"answer_id": 4931205,
"author": "giacomino",
"author_id": 213588,
"author_profile": "https://Stackoverflow.com/users/213588",
"pm_score": 1,
"selected": false,
"text": "RED constant number(1):=1;\nGREEN constant number(1):=2;\nBLUE constant number(1):=3;\nYELLOW constant number(1):=4;\n\nsubtype COLORS is binary_integer range 1..4;\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15124/"
] |
203,473
|
<p>I have a Crystal Report that looks like:</p>
<p><em>Date | Person | Ticket | Summary <br>
Date | Person | Ticket | Summary <br>
Date | Person | Ticket | Summary</em> </p>
<p>I would like it to look like: </p>
<p><em>Date <br>
Person | Ticket | Summary <br>
Person | Ticket | Summary <br><br>
Date <br>
Person | Ticket | Summary</em></p>
<p>All values are pulled from a MS SQL 2000 database, the application that will ultimately use the report is a VB 6 app that I unfortunately have to support. </p>
|
[
{
"answer_id": 203547,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 7,
"selected": true,
"text": "CREATE TABLE sizes (\n name VARCHAR2(10) CHECK( name IN ('small','medium','large') )\n);\n CREATE TABLE valid_names (\n name_id NUMBER PRIMARY KEY,\n name_str VARCHAR2(10)\n);\n\nINSERT INTO valid_sizes VALUES( 1, 'small' );\nINSERT INTO valid_sizes VALUES( 2, 'medium' );\nINSERT INTO valid_sizes VALUES( 3, 'large' );\n\nCREATE TABLE sizes (\n name_id NUMBER REFERENCES valid_names( name_id )\n);\n\nCREATE VIEW vw_sizes\n AS \n SELECT a.name_id name, <<other columns from the sizes table>>\n FROM valid_sizes a,\n sizes b\n WHERE a.name_id = b.name_id\n"
},
{
"answer_id": 4931205,
"author": "giacomino",
"author_id": 213588,
"author_profile": "https://Stackoverflow.com/users/213588",
"pm_score": 1,
"selected": false,
"text": "RED constant number(1):=1;\nGREEN constant number(1):=2;\nBLUE constant number(1):=3;\nYELLOW constant number(1):=4;\n\nsubtype COLORS is binary_integer range 1..4;\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8900/"
] |
203,475
|
<p>In my code, I am creating a collection of objects which will be accessed by various threads in a fashion that is only safe if the objects are immutable. When an attempt is made to insert a new object into my collection, I want to test to see if it is immutable (if not, I'll throw an exception).</p>
<p>One thing I can do is to check a few well-known immutable types:</p>
<pre><code>private static final Set<Class> knownImmutables = new HashSet<Class>(Arrays.asList(
String.class, Byte.class, Short.class, Integer.class, Long.class,
Float.class, Double.class, Boolean.class, BigInteger.class, BigDecimal.class
));
...
public static boolean isImmutable(Object o) {
return knownImmutables.contains(o.getClass());
}
</code></pre>
<p>This actually gets me 90% of the way, but sometimes my users will want to create simple immutable types of their own:</p>
<pre><code>public class ImmutableRectangle {
private final int width;
private final int height;
public ImmutableRectangle(int width, int height) {
this.width = width;
this.height = height;
}
public int getWidth() { return width; }
public int getHeight() { return height; }
}
</code></pre>
<p>Is there some way (perhaps using reflection) that I could reliably detect whether a class is immutable? False positives (thinking it's immutable when it isn't) are not acceptable but false negatives (thinking it's mutable when it isn't) are.</p>
<p><strong>Edited to add:</strong> Thanks for the insightful and helpful answers. As some of the answers pointed out, I neglected to define my security objectives. The threat here is clueless developers -- this is a piece of framework code that will be used by large numbers of people who know next-to-nothing about threading and won't be reading the documentation. I do NOT need to defend against malicious developers -- anyone clever enough to <a href="http://directwebremoting.org/blog/joe/2005/05/26/1117108773674.html" rel="noreferrer">mutate a String</a> or perform other shenanigans will also be smart enough to know it's not safe in this case. Static analysis of the codebase IS an option, so long as it is automated, but code reviews cannot be counted on because there is no guarantee every review will have threading-savvy reviewers.</p>
|
[
{
"answer_id": 203504,
"author": "Jason Cohen",
"author_id": 4926,
"author_profile": "https://Stackoverflow.com/users/4926",
"pm_score": 3,
"selected": false,
"text": "@Immutable"
},
{
"answer_id": 203506,
"author": "Pablo Fernandez",
"author_id": 7595,
"author_profile": "https://Stackoverflow.com/users/7595",
"pm_score": 2,
"selected": false,
"text": "@Retention(RetentionPolicy.RUNTIME)\n@Target(ElementType.CLASS)\npublic @interface Immutable{ }\n @Immutable\npublic class ImmutableRectangle {\n private final int width;\n private final int height;\n public ImmutableRectangle(int width, int height) {\n this.width = width;\n this.height = height;\n }\n public int getWidth() { return width; }\n public int getHeight() { return height; }\n}\n"
},
{
"answer_id": 203571,
"author": "Simon Lehmann",
"author_id": 27011,
"author_profile": "https://Stackoverflow.com/users/27011",
"pm_score": 6,
"selected": true,
"text": "static boolean isImmutable(Object obj) {\n Class<?> objClass = obj.getClass();\n\n // Class of the object must be a direct child class of the required class\n Class<?> superClass = objClass.getSuperclass();\n if (!Immutable.class.equals(superClass)) {\n return false;\n }\n\n // Class must be final\n if (!Modifier.isFinal(objClass.getModifiers())) {\n return false;\n }\n\n // Check all fields defined in the class for type and if they are final\n Field[] objFields = objClass.getDeclaredFields();\n for (int i = 0; i < objFields.length; i++) {\n if (!Modifier.isFinal(objFields[i].getModifiers())\n || !isValidFieldType(objFields[i].getType())) {\n return false;\n }\n }\n\n // Lets hope we didn't forget something\n return true;\n}\n\nstatic boolean isValidFieldType(Class<?> type) {\n // Check for all allowed property types...\n return type.isPrimitive() || String.class.equals(type);\n}\n hash"
},
{
"answer_id": 203797,
"author": "Daniel Hiller",
"author_id": 16193,
"author_profile": "https://Stackoverflow.com/users/16193",
"pm_score": 2,
"selected": false,
"text": "interface Immutable {}\n\nclass MyImmutable implements Immutable{...}\n\npublic void add(Object o) {\n if (!(o instanceof Immutable) && !checkIsImmutableBasePrimitive(o))\n throw new IllegalArgumentException(\"o is not immutable!\");\n ...\n}\n"
},
{
"answer_id": 203961,
"author": "Martin Probst",
"author_id": 22227,
"author_profile": "https://Stackoverflow.com/users/22227",
"pm_score": 2,
"selected": false,
"text": "class Foo {\n final String x;\n final Integer y;\n ...\n\n public bar() {\n Singleton.getInstance().foolAround();\n }\n}\n foolAround() class A {\n final B b; // might be immutable...\n}\n\nclass B {\n final A a; // same so here.\n}\n"
},
{
"answer_id": 6843336,
"author": "M. Tempesta",
"author_id": 865227,
"author_profile": "https://Stackoverflow.com/users/865227",
"pm_score": 1,
"selected": false,
"text": "public static boolean isImmutable(Object object){\n if (object instanceof Number) { // Numbers are immutable\n if (object instanceof AtomicInteger) {\n // AtomicIntegers are mutable\n } else if (object instanceof AtomicLong) {\n // AtomLongs are mutable\n } else {\n return true;\n }\n } else if (object instanceof String) { // Strings are immutable\n return true;\n } else if (object instanceof Character) { // Characters are immutable\n return true;\n } else if (object instanceof Class) { // Classes are immutable\n return true;\n }\n\n Class<?> objClass = object.getClass();\n\n // Class must be final\n if (!Modifier.isFinal(objClass.getModifiers())) {\n return false;\n }\n\n // Check all fields defined in the class for type and if they are final\n Field[] objFields = objClass.getDeclaredFields();\n for (int i = 0; i < objFields.length; i++) {\n if (!Modifier.isFinal(objFields[i].getModifiers())\n || !isImmutable(objFields[i].getType())) {\n return false;\n }\n }\n\n // Lets hope we didn't forget something\n return true;\n}\n"
},
{
"answer_id": 14931051,
"author": "yegor256",
"author_id": 187141,
"author_profile": "https://Stackoverflow.com/users/187141",
"pm_score": 2,
"selected": false,
"text": "@Immutable @Immutable\npublic class Foo {\n private String data;\n}\n// this line will throw a runtime exception since class Foo\n// is actually mutable, despite the annotation\nObject object = new Foo();\n"
},
{
"answer_id": 23955278,
"author": "Grundlefleck",
"author_id": 4120,
"author_profile": "https://Stackoverflow.com/users/4120",
"pm_score": 1,
"selected": false,
"text": "/*\n* Request an analysis of the runtime class, to discover if this\n* instance will be immutable or not.\n*/\nAnalysisResult result = analysisSession.resultFor(dottedClassName);\n\nif (result.isImmutable.equals(IMMUTABLE)) {\n /*\n * rest safe in the knowledge the class is\n * immutable, share across threads with joyful abandon\n */\n} else if (result.isImmutable.equals(NOT_IMMUTABLE)) {\n /*\n * be careful here: make defensive copies,\n * don't publish the reference,\n * read Java Concurrency In Practice right away!\n */\n}\n"
},
{
"answer_id": 28112166,
"author": "Mike Nakis",
"author_id": 773113,
"author_profile": "https://Stackoverflow.com/users/773113",
"pm_score": 0,
"selected": false,
"text": "Unknown Mutable Immutable Calculating Unknown Calculating Calculating Immutable Mutable super Calculating Calculating UnmodifiableCollection String Immutable @ImmutabilityOverride"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570/"
] |
203,477
|
<p>I'm using KML and the GGeoXml object to overlay some shapes on an embedded Google map. The placemarks in the KML file have some custom descriptive information that shows up in the balloons.</p>
<pre><code><Placemark>
<name />
<description>
<![CDATA[
<div class="MapPopup">
<h6>Concession</h6>
<h4>~Name~</h4>
<p>Description goes here</p>
<a class="Button GoRight FloatRight" href="#"><span></span>View details</a>
</div>
]]>
</description>
<styleUrl>#masterPolyStyle</styleUrl>
...Placemarks go here ...
</Placemark>
</code></pre>
<p>So far so good - the popups show up and have the correct text in them. Here's the weird thing: I'm trying to use CSS to format what goes in the popups, and it halfway works.</p>
<p>Specifically:</p>
<ul>
<li><p>The <code><h6></code> and <code><h4></code> elements are rendered using the colors and background images I've specified in my stylesheet.</p>
</li>
<li><p>Everything shows up in Arial, not in the font I've specified in my CSS.</p>
</li>
<li><p>The class names seem to be ignored (e.g. none of the <code>a.Button</code> formatting is applied; if I define a style like the one below, it's ignored.)</p>
<pre><code> div.MapPopup { background:pink; }
</code></pre>
</li>
</ul>
<p>Any ideas? I wouldn't have been surprised for the CSS not to work at all, but it's weird that it only partly works.</p>
<h3>Update</h3>
<p>Here's a screenshot to better illustrate this. I've reproduced the <code><div class="MapPopup"></code> markup further down on the page (in yellow), to show how it should be rendered according to my CSS.</p>
<p><img src="https://farm4.static.flickr.com/3072/2942636927_2f8119a72a.jpg?v=0" alt="alt text" /></p>
|
[
{
"answer_id": 208902,
"author": "Herb Caudill",
"author_id": 239663,
"author_profile": "https://Stackoverflow.com/users/239663",
"pm_score": 4,
"selected": true,
"text": "<div style=\"font-family: Arial,sans-serif; font-size: small;\">\n <div id=\"iw_kml\">\n <div>\n <h6>Concession</h6>\n <h4>BOIS KASSA 1108000 (Mobola-Mbondo)</h4>\n <p>\n Description goes here</p>\n <a target=\"_blank\"><span />View details </a>\n </div>\n </div>\n</div>\n MapPopup div Button <a> !important div"
},
{
"answer_id": 213893,
"author": "Herb Caudill",
"author_id": 239663,
"author_profile": "https://Stackoverflow.com/users/239663",
"pm_score": 2,
"selected": false,
"text": "<description> target=\"_blank\""
},
{
"answer_id": 6949199,
"author": "Mitchell",
"author_id": 823833,
"author_profile": "https://Stackoverflow.com/users/823833",
"pm_score": 1,
"selected": false,
"text": "/*start of myHtml2 variable*/\nvar myHtml2 = \"<div style=\\\"background-color:lightgray\\\"><div style=\\\"padding:5px\\\"><div\nstyle=\\\"font-size:1.25em\\\">Some text</div><div>Some more text<br/>\nYet more text<br/></div><table style=\\\"padding:5px\\\"><tr><td><img src=\\\"A lake.jpg\\\"\nwidth=\\\"75px\\\" height=\\\"50px\\\"></td><td>More text<br/>Again, more text<br/><div\nstyle=\\\"font-size:.7em\\\">Last text</div></td></tr></table></div></div>\"\n/*end of variable*/\n\nvar infowindow2 = new google.maps.InfoWindow({content: myHtml2});\n /*mouseover could be 'click', etc.*/\ngoogle.maps.event.addListener(marker, 'mouseover', function(){ \ninfowindow2.open(map, marker);\n}); \n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/239663/"
] |
203,493
|
<p>I know that it <em>does</em> consider ' ' as <code>NULL</code>, but that doesn't do much to tell me <em>why</em> this is the case. As I understand the SQL specifications, ' ' is not the same as <code>NULL</code> -- one is a valid datum, and the other is indicating the absence of that same information.</p>
<p>Feel free to speculate, but please indicate if that's the case. If there's anyone from Oracle who can comment on it, that'd be fantastic!</p>
|
[
{
"answer_id": 203536,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 9,
"selected": true,
"text": "VARCHAR VARCHAR2 NULL NULL NULL VARCHAR VARCHAR2"
},
{
"answer_id": 29209211,
"author": "Sorter",
"author_id": 1097600,
"author_profile": "https://Stackoverflow.com/users/1097600",
"pm_score": 1,
"selected": false,
"text": "val IS NOT NULL val != '' val != '' and val IS NOT NULL"
},
{
"answer_id": 31895391,
"author": "zloctb",
"author_id": 1673376,
"author_profile": "https://Stackoverflow.com/users/1673376",
"pm_score": -1,
"selected": false,
"text": " set serveroutput on; \n DECLARE\n empty_varchar2 VARCHAR2(10) := '';\n empty_char CHAR(10) := '';\n BEGIN\n IF empty_varchar2 IS NULL THEN\n DBMS_OUTPUT.PUT_LINE('empty_varchar2 is NULL');\n END IF;\n\n\n IF '' IS NULL THEN\n DBMS_OUTPUT.PUT_LINE(''''' is NULL');\n END IF;\n\n IF empty_char IS NULL THEN\n DBMS_OUTPUT.PUT_LINE('empty_char is NULL');\n ELSIF empty_char IS NOT NULL THEN\n DBMS_OUTPUT.PUT_LINE('empty_char is NOT NULL');\n END IF;\n\n END;\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23309/"
] |
203,495
|
<p>My organization is working on building RESTful webservices on JBoss appserver. The QA team is used to testing SOAP webservices so far using SoapUI. SoapUI has a new version that has REST capabilities. We're considering using that.</p>
<ol>
<li>Are there any publicly available RESTful services available on the net for free that someone could test ? <br> </li>
<li>What tools are available(and used) for testing RESTful web services ?</li>
</ol>
|
[
{
"answer_id": 203601,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 4,
"selected": false,
"text": "urllib urllib2 unittest class TestSomeREST( unittest.TestCase ):\n def setUp(self):\n REALM = \"blah@blah.com\"\n self.client= RESTClient( \"localhost\", 18000, \"tester\", \"tester\", REALM )\n def test_1_get(self):\n response = self.client.get('/this/that/other/2/')\n self.failUnlessEqual(200, response.status_code)\n j1= JSONDecoder().decode(response.content)\n self.assertEquals(2, j1[0]['pk'] )\n entity= j1[0]['fields']\n self.assertEquals('Some Other Group', entity['name'])\n self.assertEquals('E1G2', entity['customer_id'])\n"
},
{
"answer_id": 12298362,
"author": "Heiko Rupp",
"author_id": 100957,
"author_profile": "https://Stackoverflow.com/users/100957",
"pm_score": 1,
"selected": false,
"text": "@Rule\npublic Destination destination = new Destination(\"http://localhost:8080/rest/\");\n\n\n@HttpTest( method = Method.GET, path = \"/status\" ,authentications =\n @Authentication(type = AuthenticationType.BASIC, user = \"joe\", password = \"doe\")\n)\npublic void testAuthRhqadmin() {\n com.eclipsesource.restfuse.Assert.assertOk(response);\n}\n http://localhost:8080/rest/status"
},
{
"answer_id": 13333301,
"author": "code4j",
"author_id": 1022209,
"author_profile": "https://Stackoverflow.com/users/1022209",
"pm_score": 3,
"selected": false,
"text": "curl curl http://localhost:3000/courses.json\n curl -H \"Content-Type:application/json\" -d '{\"courseCode\":\"55555\",\"courseName\":\"SEEEE\",\"courseYr\":999}' http://localhost:3000/courses.json\n curl -H \"X-Http-Method-Override: put\" -H \"Content-Type:application/json\" -d '{\"courseCode\":\"123456\",\"courseName\":\"AAAAAAAA\",\"courseYr\":12345}' http://localhost:3000/courses/5.json\n curl -H \"X-Http-Method-Override: put\" -H \"Content-Type:application/json\" -d '{\"courseYr\":999999999}' http://localhost:3000/courses/3.json\n curl -H \"X-Http-Method-Override: delete\" -H \"Content-Type:application/json\" -d '{\"id\":4}' http://localhost:3000/courses/5.json\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11142/"
] |
203,520
|
<p>I have what must be a typical catch-22 problem. I have a .NET WinForm control that contains a textbox and a checkbox. Both controls are data bound to properties on a data class instance. The textbox is for price, the check box to indicate that the price is a price override. Also on the data class is a property that holds the item's original price.</p>
<p>I would like the controls to respect the following rules:</p>
<ul>
<li>When the user enters a value into the price textbox, the checkbox is automatically checked to indicate they are overriding the price value</li>
<li>When the check box is un-checked, the item's price is restored to the original price.</li>
</ul>
<p>When the user unchecks the checkbox, the event handler tests the checked state, and sets the item's price property to the original price value. However, the price value being databound, a bind event is fired, which updates the textbox value, which fires the text changed event handler which re-checks the checkbox. </p>
<p>I've attempted to trap the conditions where I'm explicitly updating something that would trigger a control change event. This only works for part of it though. The textbox change event fires other times that are outside my control, such as when databinding fires when the form is initially shown.</p>
<p>I've been searching around and I guess I'm just not coming up with the right search terms to find what I'm looking for. It seems that databinding is all wonderful and nifty until you need to do something pratical with it, like having two bound controls interact with each other. There just doesn't seem to be a way to discriminate between what triggered the control events.</p>
<p>I've also looked at the events available on the binding source component but there doesn't seem to be anything there that is any more useful. I can handle the event that fires after binding is complete, but that's after the problems occur.</p>
<p>Anyone have any suggestions?</p>
|
[
{
"answer_id": 203920,
"author": "Tom Juergens",
"author_id": 2899,
"author_profile": "https://Stackoverflow.com/users/2899",
"pm_score": 2,
"selected": false,
"text": "Private _dc As DataClass\n\nPrivate Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load\n _dc = New DataClass\n txtPrice.DataBindings.Add(\"text\", _dc, \"Price\")\n chkOverride.DataBindings.Add(\"checked\", _dc, \"override\")\nEnd Sub\n Private _originalPrice As Double = 50\n\nPrivate _price As Double = _originalPrice\nPublic Property Price() As Double\n Get\n Return _price\n End Get\n Set(ByVal value As Double)\n If (_price <> value) Then\n _price = value\n Override = _price <> _originalPrice\n End If\n End Set\nEnd Property\n\n\nPrivate _override As Boolean\nPublic Property Override() As Boolean\n Get\n Return _override\n End Get\n Set(ByVal value As Boolean)\n If _override <> value Then\n _override = value\n If Not _override Then Price = OriginalPrice\n End If\n End Set\nEnd Property\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203520",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5496/"
] |
203,528
|
<p>When I build XML up from scratch with <code>XmlDocument</code>, the <code>OuterXml</code> property already has everything nicely indented with line breaks. However, if I call <code>LoadXml</code> on some very "compressed" XML (no line breaks or indention) then the output of <code>OuterXml</code> stays that way. So ...</p>
<p>What is the simplest way to get beautified XML output from an instance of <code>XmlDocument</code>?</p>
|
[
{
"answer_id": 203533,
"author": "DocMax",
"author_id": 6234,
"author_profile": "https://Stackoverflow.com/users/6234",
"pm_score": 6,
"selected": false,
"text": "XmlDocument doc = new XmlDocument();\ndoc.LoadXml(\"<item><name>wrench</name></item>\");\n// Save the document to a file and auto-indent the output.\nusing (XmlTextWriter writer = new XmlTextWriter(\"data.xml\", null)) {\n writer.Formatting = Formatting.Indented;\n doc.Save(writer);\n}\n"
},
{
"answer_id": 203534,
"author": "benPearce",
"author_id": 4490,
"author_profile": "https://Stackoverflow.com/users/4490",
"pm_score": 3,
"selected": false,
"text": "XmlTextWriter xw = new XmlTextWriter(writer);\nxw.Formatting = Formatting.Indented;\n"
},
{
"answer_id": 203581,
"author": "Neil C. Obremski",
"author_id": 9642,
"author_profile": "https://Stackoverflow.com/users/9642",
"pm_score": 9,
"selected": true,
"text": "XmlTextWriter static public string Beautify(this XmlDocument doc)\n{\n StringBuilder sb = new StringBuilder();\n XmlWriterSettings settings = new XmlWriterSettings\n {\n Indent = true,\n IndentChars = \" \",\n NewLineChars = \"\\r\\n\",\n NewLineHandling = NewLineHandling.Replace\n };\n using (XmlWriter writer = XmlWriter.Create(sb, settings)) {\n doc.Save(writer);\n }\n return sb.ToString();\n}\n"
},
{
"answer_id": 1417071,
"author": "Uwe Keim",
"author_id": 107625,
"author_profile": "https://Stackoverflow.com/users/107625",
"pm_score": 4,
"selected": false,
"text": "XmlDocument XmlProcessingInstruction private static string beautify(\n XmlDocument doc)\n{\n var sb = new StringBuilder();\n var settings =\n new XmlWriterSettings\n {\n Indent = true,\n IndentChars = @\" \",\n NewLineChars = Environment.NewLine,\n NewLineHandling = NewLineHandling.Replace,\n };\n\n using (var writer = XmlWriter.Create(sb, settings))\n {\n if (doc.ChildNodes[0] is XmlProcessingInstruction)\n {\n doc.RemoveChild(doc.ChildNodes[0]);\n }\n\n doc.Save(writer);\n return sb.ToString();\n }\n}\n XmlProcessingInstruction private static string beautify(string xml)\n{\n var doc = new XmlDocument();\n doc.LoadXml(xml);\n\n var settings = new XmlWriterSettings\n {\n Indent = true,\n IndentChars = \"\\t\",\n NewLineChars = Environment.NewLine,\n NewLineHandling = NewLineHandling.Replace,\n Encoding = new UTF8Encoding(false)\n };\n\n using (var ms = new MemoryStream())\n using (var writer = XmlWriter.Create(ms, settings))\n {\n doc.Save(writer);\n var xmlString = Encoding.UTF8.GetString(ms.ToArray());\n return xmlString;\n }\n}\n"
},
{
"answer_id": 3947518,
"author": "Jonathan Mitchem",
"author_id": 104523,
"author_profile": "https://Stackoverflow.com/users/104523",
"pm_score": 4,
"selected": false,
"text": "public static string ToIndentedString( this XmlDocument doc )\n{\n var stringWriter = new StringWriter(new StringBuilder());\n var xmlTextWriter = new XmlTextWriter(stringWriter) {Formatting = Formatting.Indented};\n doc.Save( xmlTextWriter );\n return stringWriter.ToString();\n}\n"
},
{
"answer_id": 11396054,
"author": "Munim",
"author_id": 981001,
"author_profile": "https://Stackoverflow.com/users/981001",
"pm_score": 2,
"selected": false,
"text": "writer.WriteRaw(space_char);\n private void generateXML(string filename)\n {\n using (XmlWriter writer = XmlWriter.Create(filename))\n {\n writer.WriteStartDocument();\n //new line\n writer.WriteRaw(\"\\n\");\n writer.WriteStartElement(\"treeitems\");\n //new line\n writer.WriteRaw(\"\\n\");\n foreach (RootItem root in roots)\n {\n //indent\n writer.WriteRaw(\"\\t\");\n writer.WriteStartElement(\"treeitem\");\n writer.WriteAttributeString(\"name\", root.name);\n writer.WriteAttributeString(\"uri\", root.uri);\n writer.WriteAttributeString(\"fontsize\", root.fontsize);\n writer.WriteAttributeString(\"icon\", root.icon);\n if (root.children.Count != 0)\n {\n foreach (ChildItem child in children)\n {\n //indent\n writer.WriteRaw(\"\\t\");\n writer.WriteStartElement(\"treeitem\");\n writer.WriteAttributeString(\"name\", child.name);\n writer.WriteAttributeString(\"uri\", child.uri);\n writer.WriteAttributeString(\"fontsize\", child.fontsize);\n writer.WriteAttributeString(\"icon\", child.icon);\n writer.WriteEndElement();\n //new line\n writer.WriteRaw(\"\\n\");\n }\n }\n writer.WriteEndElement();\n //new line\n writer.WriteRaw(\"\\n\");\n }\n\n writer.WriteEndElement();\n writer.WriteEndDocument();\n\n }\n\n }\n"
},
{
"answer_id": 11582762,
"author": "JFK",
"author_id": 851774,
"author_profile": "https://Stackoverflow.com/users/851774",
"pm_score": 5,
"selected": false,
"text": "try\n{\n RequestPane.Text = System.Xml.Linq.XElement.Parse(RequestPane.Text).ToString();\n}\ncatch (System.Xml.XmlException xex)\n{\n displayException(\"Problem with formating text in Request Pane: \", xex);\n}\n"
},
{
"answer_id": 16524516,
"author": "Nyerguds",
"author_id": 395685,
"author_profile": "https://Stackoverflow.com/users/395685",
"pm_score": 2,
"selected": false,
"text": "XmlWriterSettings StringBuilder XMLDocument preserveWhitespace public static void SaveFormattedXml(XmlDocument doc, String outputPath, Encoding encoding)\n{\n XmlWriterSettings settings = new XmlWriterSettings();\n settings.Indent = true;\n settings.IndentChars = \"\\t\";\n settings.NewLineChars = \"\\r\\n\";\n settings.NewLineHandling = NewLineHandling.Replace;\n\n using (MemoryStream memstream = new MemoryStream())\n using (StreamWriter sr = new StreamWriter(memstream, encoding))\n using (XmlWriter writer = XmlWriter.Create(sr, settings))\n using (FileStream fileWriter = new FileStream(outputPath, FileMode.Create))\n {\n if (doc.ChildNodes.Count > 0 && doc.ChildNodes[0] is XmlProcessingInstruction)\n doc.RemoveChild(doc.ChildNodes[0]);\n // save xml to XmlWriter made on encoding-specified text writer\n doc.Save(writer);\n // Flush the streams (not sure if this is really needed for pure mem operations)\n writer.Flush();\n // Write the underlying stream of the XmlWriter to file.\n fileWriter.Write(memstream.GetBuffer(), 0, (Int32)memstream.Length);\n }\n}\n"
},
{
"answer_id": 24659519,
"author": "theJerm",
"author_id": 118191,
"author_profile": "https://Stackoverflow.com/users/118191",
"pm_score": 1,
"selected": false,
"text": "var xmlString = \"<xml>...</xml>\"; // Your original XML string that needs indenting.\nxmlString = this.PrettifyXml(xmlString);\n\nprivate string PrettifyXml(string xmlString)\n{\n var prettyXmlString = new StringBuilder();\n\n var xmlDoc = new XmlDocument();\n xmlDoc.LoadXml(xmlString);\n\n var xmlSettings = new XmlWriterSettings()\n {\n Indent = true,\n IndentChars = \" \",\n NewLineChars = \"\\r\\n\",\n NewLineHandling = NewLineHandling.Replace\n };\n\n using (XmlWriter writer = XmlWriter.Create(prettyXmlString, xmlSettings))\n {\n xmlDoc.Save(writer);\n }\n\n return prettyXmlString.ToString();\n}\n"
},
{
"answer_id": 26963811,
"author": "rewrew",
"author_id": 4029290,
"author_profile": "https://Stackoverflow.com/users/4029290",
"pm_score": 3,
"selected": false,
"text": " public static string FormatXml(string xml)\n {\n try\n {\n var doc = XDocument.Parse(xml);\n return doc.ToString();\n }\n catch (Exception)\n {\n return xml;\n }\n }\n"
},
{
"answer_id": 45983263,
"author": "d.i.joe",
"author_id": 2450402,
"author_profile": "https://Stackoverflow.com/users/2450402",
"pm_score": 1,
"selected": false,
"text": "static public string Beautify(this XmlDocument doc) {\n StringBuilder sb = new StringBuilder();\n XmlWriterSettings settings = new XmlWriterSettings\n {\n Indent = true\n };\n\n using (XmlWriter writer = XmlWriter.Create(sb, settings)) {\n doc.Save(writer);\n }\n\n return sb.ToString(); \n}\n"
},
{
"answer_id": 74262094,
"author": "cSharper",
"author_id": 19148480,
"author_profile": "https://Stackoverflow.com/users/19148480",
"pm_score": 0,
"selected": false,
"text": "var document = new XmlDocument();\ndocument.PreserveWhitespace = true;\ndocument.Load(filename);\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203528",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9642/"
] |
203,543
|
<p>I recently had to work on a project where the previous developer modified the wp-admin directory. It seems like a bad idea to me, since Wordpress is constantly updated. Am I just not at that level of expertise with modifying Wordpress?</p>
|
[
{
"answer_id": 203662,
"author": "joelhardi",
"author_id": 11438,
"author_profile": "https://Stackoverflow.com/users/11438",
"pm_score": 3,
"selected": false,
"text": "siteurl"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203543",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/65465/"
] |
203,548
|
<p>I've been getting this undefined symbol building with this command line:</p>
<pre><code>$ gcc test.cpp
Undefined symbols:
"___gxx_personality_v0", referenced from:
etc...
</code></pre>
<p>test.cpp is simple and should build fine. What is the deal?</p>
|
[
{
"answer_id": 203550,
"author": "ryan_s",
"author_id": 13728,
"author_profile": "https://Stackoverflow.com/users/13728",
"pm_score": 7,
"selected": true,
"text": "g++ test.cpp\n gcc -lstdc++ gcc test.cpp -lstdc++\n md5 a.out g++"
},
{
"answer_id": 1626030,
"author": "pseudosudo",
"author_id": 196678,
"author_profile": "https://Stackoverflow.com/users/196678",
"pm_score": 2,
"selected": false,
"text": ".cpp gcc .c mv test.cpp\ngcc test.c\n -x c gcc -x c -c test.cpp -o test.o\n nm test.o ___gxx_personality_v0 gcc -c test.cpp -o test.o ___gxx_personality_v0"
},
{
"answer_id": 4340486,
"author": "inket",
"author_id": 528645,
"author_profile": "https://Stackoverflow.com/users/528645",
"pm_score": 2,
"selected": false,
"text": ".c .C"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203548",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13728/"
] |
203,589
|
<p>I have an iPhone app that compiles and runs fine in the Simulator on my laptop. Now, I try to build and run the same code in the Simulator on an iMac, and it starts up and lets me click a button, but then I get an assertion failure.</p>
<p>Here is what is in the console:</p>
<pre><code>*** Assertion failure in -[UILabel setFont:], /SourceCache/UIKit/UIKit-738/UILabel.m:438
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: font != nil'
Stack: (
2493366603,
2432871995,
2493366059,
2459146836,
817183141,
817926218,
837317240,
837317032,
837315376,
837314643,
2492860866,
2492867620,
2492869880,
85304,
85501,
816175835,
816221412,
9096,
8930
)
</code></pre>
<p>Here's the stack trace:</p>
<pre><code>#0 0x949dbff4 in ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___
#1 0x9102ae3b in objc_exception_throw
#2 0x94962ad3 in CFRunLoopRunSpecific
#3 0x94962cf8 in CFRunLoopRunInMode
#4 0x00014d38 in GSEventRunModal
#5 0x00014dfd in GSEventRun
#6 0x30a5dadb in -[UIApplication _run]
#7 0x30a68ce4 in UIApplicationMain
#8 0x00002388 in main at main.m:16
</code></pre>
<p>My code does not make any direct calls to setFont:. However, this would be the point in the program's execution where some buttons are made visible for the first time.</p>
<p>I've Googled. A few people with similar problems say that this gets magically fixed when they edit the NIB, or change their time zone, or other weirdness.</p>
<p>Any ideas what the real cause is?</p>
<p>(Please no whining about NDA's.)</p>
<hr>
<p><strong>Update:</strong> If I change the font of some of my buttons from "TimesNewRomanPS-BoldMT" to "Times", then the assertion failure no longer occurs. But why can't I use the desired font, which exists on the iPhone, is installed on the new machine, and is selectable in Interface Builder?</p>
|
[
{
"answer_id": 10255142,
"author": "user102008",
"author_id": 102008,
"author_profile": "https://Stackoverflow.com/users/102008",
"pm_score": 0,
"selected": false,
"text": "[UIFont fontWithName:fontSize:] Helvatica Bold Helvetica-Bold Helvatica Bold Helvetica-Bold"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203589",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1175/"
] |
203,605
|
<p>I'm looking for a way to match only fully composed characters in a Unicode string.</p>
<p>Is <code>[:print:]</code> dependent upon locale in any regular expression implementation that incorporates this character class? For example, will it match Japanese character 'あ', since it is not a control character, or is <code>[:print:]</code> always going to be ASCII codes 0x20 to 0x7E?</p>
<p>Is there any character class, including Perl REs, that can be used to match anything other than a control character? If <code>[:print:]</code> includes only characters in ASCII range I would assume <code>[:cntrl:]</code> does too.</p>
|
[
{
"answer_id": 203623,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 1,
"selected": false,
"text": "[^[:cntrl:]]"
},
{
"answer_id": 203801,
"author": "Tanktalus",
"author_id": 23512,
"author_profile": "https://Stackoverflow.com/users/23512",
"pm_score": 4,
"selected": true,
"text": "echo あ| perl -nle 'BEGIN{binmode STDIN,\":utf8\"} print\"[$_]\"; print /[[:print:]]/ ? \"YES\" : \"NO\"'\n"
},
{
"answer_id": 203894,
"author": "moritz",
"author_id": 14132,
"author_profile": "https://Stackoverflow.com/users/14132",
"pm_score": 3,
"selected": false,
"text": "\\w \\d 0..9 \\p{PropertyName} \\p{Print}"
},
{
"answer_id": 2024396,
"author": "daxim",
"author_id": 46395,
"author_profile": "https://Stackoverflow.com/users/46395",
"pm_score": 2,
"selected": false,
"text": "\\X #!/usr/bin/env perl\nuse 5.010;\nuse utf8;\nuse Encode qw(encode_utf8);\n\nfor my $string (qw(あ ご ご), \"\\x{3099}\") {\n say encode_utf8 sprintf \"%s $string\", $string =~ /\\A \\X \\z/msx ? 'ok' : 'nok';\n}\n \\X [[:print:]]"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10320/"
] |
203,616
|
<p>The <a href="http://www.cplusplus.com/doc/tutorial/inheritance/" rel="noreferrer">C++ friend keyword</a> allows a <code>class A</code> to designate <code>class B</code> as its friend. This allows <code>Class B</code> to access the <code>private</code>/<code>protected</code> members of <code>class A</code>.</p>
<p>I've never read anything as to why this was left out of C# (and VB.NET). Most answers to this <a href="https://stackoverflow.com/questions/17434/when-should-you-use-friend-in-c">earlier StackOverflow question</a> seem to be saying it is a useful part of C++ and there are good reasons to use it. In my experience I'd have to agree.</p>
<p>Another <a href="https://stackoverflow.com/questions/200079/inheritance-trees-and-protected-constructors-in-c#200117">question</a> seems to me to be really asking how to do something similar to <code>friend</code> in a C# application. While the answers generally revolve around nested classes, it doesn't seem quite as elegant as using the <code>friend</code> keyword.</p>
<p>The original <a href="https://rads.stackoverflow.com/amzn/click/com/0201633612" rel="noreferrer" rel="nofollow noreferrer">Design Patterns book</a> uses it regularly throughout its examples.</p>
<p>So in summary, why is <code>friend</code> missing from C#, and what is the "best practice" way (or ways) of simulating it in C#?</p>
<p>(By the way, the <code>internal</code> keyword is <em>not</em> the same thing, it allows <em>all</em> classes within the entire assembly to access <code>internal</code> members, while <code>friend</code> allows you to give a certain class <em>complete access</em> to <em>exactly one</em> other class)</p>
|
[
{
"answer_id": 203813,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 6,
"selected": false,
"text": "[InternalsVisibleTo]"
},
{
"answer_id": 4577298,
"author": "Nick Alexeev",
"author_id": 279844,
"author_profile": "https://Stackoverflow.com/users/279844",
"pm_score": 4,
"selected": false,
"text": "friend internal friend internal friend internal internal friend"
},
{
"answer_id": 10893312,
"author": "FadeToBlack",
"author_id": 1436720,
"author_profile": "https://Stackoverflow.com/users/1436720",
"pm_score": 2,
"selected": false,
"text": "// c++ style\nclass Foo {\n public_for Bar:\n void addBar(Bar *bar) { }\n public:\n private:\n protected:\n};\n\n// c#\nclass Foo {\n public_for Bar void addBar(Bar bar) { }\n}\n"
},
{
"answer_id": 11145676,
"author": "Reuven Bass",
"author_id": 675116,
"author_profile": "https://Stackoverflow.com/users/675116",
"pm_score": 1,
"selected": false,
"text": "interface IFriend { }\n\nclass Friend : IFriend\n{\n public static IFriend New() { return new Friend(); }\n private Friend() { }\n\n private void CallTheBody() \n { \n var body = new Body();\n body.ItsMeYourFriend(this);\n }\n}\n\nclass Body\n{ \n public void ItsMeYourFriend(Friend onlyAccess) { }\n}\n ItsMeYourFriend() Friend Friend New()"
},
{
"answer_id": 11340230,
"author": "ehud117",
"author_id": 1503319,
"author_profile": "https://Stackoverflow.com/users/1503319",
"pm_score": 0,
"selected": false,
"text": " class C1\n {\n private void MyMethod(double x, int i)\n {\n // some code\n }\n // the friend class would be able to call myMethod\n public void MyMethod(FriendClass F, double x, int i)\n {\n this.MyMethod(x, i);\n }\n //my friend class wouldn't have access to this method \n private void MyVeryPrivateMethod(string s)\n {\n // some code\n }\n }\n class FriendClass\n {\n public void SomeMethod()\n {\n C1 c = new C1();\n c.MyMethod(this, 5.5, 3);\n }\n }\n #if UNIT_TESTING\n public\n#else\n private\n#endif\n double x;\n"
},
{
"answer_id": 11549441,
"author": "Scott Forbes",
"author_id": 847485,
"author_profile": "https://Stackoverflow.com/users/847485",
"pm_score": 1,
"selected": false,
"text": "ReportError(\"Uh Oh!\");\n MyBasePage bp = Page as MyBasePage;\nbp.ReportError(\"Uh Oh\");\n protected void ReportError(string str) {\n MyBasePage bp = Page as MyBasePage;\n bp.ReportError(str);\n}\n [Friend(B)]\nclass A {\n\n AMethod() { }\n\n [Friend(C)]\n ACMethod() { }\n}\n\nclass B {\n BMethod() { A.AMethod() }\n}\n\nclass C {\n CMethod() { A.ACMethod() }\n}\n class BasePage {\n\n [Friend(BaseControl.ReportError(string)]\n protected void ReportError(string str) { }\n}\n\nclass BaseControl {\n protected void ReportError(string str) {\n MyBasePage bp = Page as MyBasePage;\n bp.ReportError(str);\n }\n}\n"
},
{
"answer_id": 20886700,
"author": "Aberro",
"author_id": 1137816,
"author_profile": "https://Stackoverflow.com/users/1137816",
"pm_score": 0,
"selected": false,
"text": "public class A // Class that contains private members\n{\n private class Accessor : B.BAgent // Implement accessor part of agent.\n {\n private A instance; // A instance for access to non-static members.\n static Accessor() \n { // Init static accessors.\n B.BAgent.ABuilder = Builder;\n B.BAgent.PrivateStaticAccessor = StaticAccessor;\n }\n // Init non-static accessors.\n internal override void PrivateMethodAccessor() { instance.SomePrivateMethod(); }\n // Agent constructor for non-static members.\n internal Accessor(A instance) { this.instance = instance; }\n private static A Builder() { return new A(); }\n private static void StaticAccessor() { A.PrivateStatic(); }\n }\n public A(B friend) { B.Friendship(new A.Accessor(this)); }\n private A() { } // Private constructor that should be accessed only from B.\n private void SomePrivateMethod() { } // Private method that should be accessible from B.\n private static void PrivateStatic() { } // ... and static private method.\n}\npublic class B\n{\n // Agent for accessing A.\n internal abstract class BAgent\n {\n internal static Func<A> ABuilder; // Static members should be accessed only by delegates.\n internal static Action PrivateStaticAccessor;\n internal abstract void PrivateMethodAccessor(); // Non-static members may be accessed by delegates or by overrideable members.\n }\n internal static void Friendship(BAgent agent)\n {\n var a = BAgent.ABuilder(); // Access private constructor.\n BAgent.PrivateStaticAccessor(); // Access private static method.\n agent.PrivateMethodAccessor(); // Access private non-static member.\n }\n}\n"
},
{
"answer_id": 28034819,
"author": "Rami Yampolsky",
"author_id": 2766543,
"author_profile": "https://Stackoverflow.com/users/2766543",
"pm_score": 2,
"selected": false,
"text": "public interface IStudentFriend\n{\n Student Stu { get; set; }\n double GetGPS();\n}\n\npublic class Student\n{\n // this is private member that I expose to friend only\n double GPS { get; set; }\n public string Name { get; set; }\n\n PrivateData privateData;\n\n public Student(string name, double gps) => (GPS, Name, privateData) = (gps, name, new PrivateData(this);\n\n // No one can instantiate this class, but Student\n // Calling it is possible via the IStudentFriend interface\n class PrivateData : IStudentFriend\n {\n public Student Stu { get; set; }\n\n public PrivateData(Student stu) => Stu = stu;\n public double GetGPS() => Stu.GPS;\n }\n\n // This is how I \"mark\" who is Students \"friend\"\n public void RegisterFriend(University friend) => friend.Register(privateData);\n}\n\npublic class University\n{\n var studentsFriends = new List<IStudentFriend>();\n\n public void Register(IStudentFriend friendMethod) => studentsFriends.Add(friendMethod);\n\n public void PrintAllStudentsGPS()\n {\n foreach (var stu in studentsFriends)\n Console.WriteLine($\"{stu.Stu.Name}: stu.GetGPS()\");\n }\n}\n\npublic static void Main(string[] args)\n{\n var Technion = new University();\n var Alex = new Student(\"Alex\", 98);\n var Jo = new Student(\"Jo\", 91);\n\n Alex.RegisterFriend(Technion);\n Jo.RegisterFriend(Technion);\n Technion.PrintAllStudentsGPS();\n\n Console.ReadLine();\n}\n"
},
{
"answer_id": 37238655,
"author": "max_cn",
"author_id": 6334867,
"author_profile": "https://Stackoverflow.com/users/6334867",
"pm_score": 4,
"selected": false,
"text": "public class Controller\n{\n private interface IState\n {\n void Update();\n }\n\n public class StateBase : IState\n {\n void IState.Update() { }\n }\n\n public Controller()\n {\n //it's only way call Update is to cast obj to IState\n IState obj = new StateBase();\n obj.Update();\n }\n}\n class Program\n{\n static void Main(string[] args)\n {\n //it's impossible to write Controller.IState p = new Controller.StateBase();\n //Controller.IState is hidden\n var p = new Controller.StateBase();\n //p.Update(); //is not accessible\n }\n}\n public class Controller\n{\n protected interface IState\n {\n void Update();\n }\n\n public class StateBase : IState\n {\n void IState.Update() { OnUpdate(); }\n protected virtual void OnUpdate()\n {\n Console.WriteLine(\"StateBase.OnUpdate()\");\n }\n }\n\n public Controller()\n {\n IState obj = new PlayerIdleState();\n obj.Update();\n }\n}\n public class PlayerIdleState: Controller.StateBase\n{\n protected override void OnUpdate()\n {\n base.OnUpdate();\n Console.WriteLine(\"PlayerIdleState.OnUpdate()\");\n }\n}\n class ControllerTest: Controller\n{\n public ControllerTest()\n {\n IState testObj = new PlayerIdleState();\n testObj.Update();\n }\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5023/"
] |
203,618
|
<ul>
<li>What rules do you use to name your variables?</li>
<li>Where are single letter vars allowed?</li>
<li>How much info do you put in the name?</li>
<li>How about for example code?</li>
<li>What are your preferred meaningless variable names? (after foo & bar)</li>
<li>Why are they spelled <a href="http://en.wikipedia.org/wiki/Foobar" rel="nofollow noreferrer">"foo" and "bar"</a> rather than <a href="http://en.wikipedia.org/wiki/FUBAR" rel="nofollow noreferrer">FUBAR</a></li>
</ul>
|
[
{
"answer_id": 203648,
"author": "Tony BenBrahim",
"author_id": 80075,
"author_profile": "https://Stackoverflow.com/users/80075",
"pm_score": 6,
"selected": false,
"text": "function startEditing(){\n if (user.canEdit(currentDocument)){\n editorControl.setEditMode(true);\n setButtonDown(btnStartEditing);\n }\n }\n"
},
{
"answer_id": 203654,
"author": "Craig",
"author_id": 27294,
"author_profile": "https://Stackoverflow.com/users/27294",
"pm_score": 4,
"selected": false,
"text": "int theTotalAccountValueIsStoredHere"
},
{
"answer_id": 203661,
"author": "acrosman",
"author_id": 24215,
"author_profile": "https://Stackoverflow.com/users/24215",
"pm_score": 2,
"selected": false,
"text": "for(int i = 0; i< endPoint; i++) {...}\n\nint max( int a, int b) {\n if (a > b)\n return a;\n return b;\n}\n"
},
{
"answer_id": 203666,
"author": "akuhn",
"author_id": 24468,
"author_profile": "https://Stackoverflow.com/users/24468",
"pm_score": 0,
"selected": false,
"text": "$ $"
},
{
"answer_id": 203682,
"author": "hlfcoding",
"author_id": 65465,
"author_profile": "https://Stackoverflow.com/users/65465",
"pm_score": -1,
"selected": false,
"text": "arrItems CustomSet Array ProperCase snake_case camelCase this prototype import [path] as [alias]; _"
},
{
"answer_id": 203725,
"author": "Jeffrey L Whitledge",
"author_id": 10174,
"author_profile": "https://Stackoverflow.com/users/10174",
"pm_score": 4,
"selected": false,
"text": "int postalCodeDistanceMiles;\ndecimal reactorCoreTemperatureKelvin;\ndecimal altitudeMsl;\nint userExperienceWongBakerPainScale\n"
},
{
"answer_id": 203734,
"author": "Jeffrey L Whitledge",
"author_id": 10174,
"author_profile": "https://Stackoverflow.com/users/10174",
"pm_score": 0,
"selected": false,
"text": "for (int firstStageRocketEngineIndex = 0; firstStageRocketEngineIndex < firstStageRocketEngines.Length; firstStageRocketEngineIndex++)\n{\n firstStageRocketEngines[firstStageRocketEngineIndex].Ignite();\n Thread.Sleep(100); // Don't start them all at once. That would be bad.\n}\n"
},
{
"answer_id": 203810,
"author": "Robert Rossney",
"author_id": 19403,
"author_profile": "https://Stackoverflow.com/users/19403",
"pm_score": 3,
"selected": false,
"text": "private int _Foo;\npublic int Foo { get { return _Foo; } set { _Foo = value; } }\n _Foo = GetResult();\n XmlWriterSettings xws = new XmlWriterSettings();\nxws.Indent = true;\nXmlWriter xw = XmlWriter.Create(outputStream, xws);\n XmlWriter xw = XmlWriter.Create(\n outputStream, \n new XmlWriterSettings() { Indent=true; });\n xwsTemp Temp xws internal void WriteXml(XmlWriter xw)\n {\n if (!Active)\n {\n return;\n }\n xw.WriteStartElement(Row.Table.TableName);\n\n xw.WriteAttributeString(\"ID\", Row[\"ID\"].ToString());\n xw.WriteAttributeString(\"RowState\", Row.RowState.ToString());\n\n for (int i = 0; i < ColumnManagers.Length; i++)\n {\n ColumnManagers[i].Value = Row.ItemArray[i];\n xw.WriteElementString(ColumnManagers[i].ColumnName, ColumnManagers[i].ToXmlString());\n }\n ...\n xw RowManager r = (RowManager)sender;\n\n // if the settings allow adding a new row, add one if the context row\n // is the last sibling, and it is now active.\n if (Settings.AllowAdds && r.IsLastSibling && r.Active)\n {\n r.ParentRowManager.AddNewChildRow(r.RecordTypeRow, false);\n }\n AllowAdds AllowAddingNewRows"
},
{
"answer_id": 267592,
"author": "Randy Stegbauer",
"author_id": 34301,
"author_profile": "https://Stackoverflow.com/users/34301",
"pm_score": 2,
"selected": false,
"text": "for (int ii=0; ii < array.length; ii++)\n{\n int element = array[ii];\n printf(\"%d\", element);\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203618",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] |
203,620
|
<p>I need ideas on how to go about table layout problem.
I want to set different width of the columns dependent on the picked language.</p>
|
[
{
"answer_id": 203647,
"author": "cdeszaq",
"author_id": 20770,
"author_profile": "https://Stackoverflow.com/users/20770",
"pm_score": 2,
"selected": true,
"text": "<%\ndim columnWidth\nif session(\"lang\") = \"eng\" then\n columnWidth = 50\nelse\n columnWidth = 100\nend if\n%>\n\n<table>\n <tr>\n <td width=\"<%= columnWidth %>px\">[content]</td>\n </tr>\n</table>\n <%\nprivate int columnWidth;\nif (session(\"lang\") == \"eng\") {\n columnWidth = 50;\n} else {\n columnWidth = 100;\n}\n%>\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203620",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28098/"
] |
203,629
|
<p>Has anyone used OSGi and JSF together?</p>
<p>I ask because JSF uses class-loader magic to find custom components. From a tutorial (emphasis mine):</p>
<blockquote>
<p>This configuration file will end up
being META-INF/faces-config.xml in the
.jar file that represents this
component. <strong>JSF will look for such a
file name in each of the .jar files
that are loaded at runtime</strong> (in the
WEB-INF/lib directory for .war files)
and use each of them in its
configuration. In this way, multiple
component .jar files can be combined
into one web application, and all of
the components described in each .jar
will be available to the application.</p>
</blockquote>
<p>I would like to be able to have JSF custom components as OSGi bundles (i.e. custom components are in different OSGi bundles than the JSF runtime) and for JSF to be able to find these at runtime.</p>
<p>Has anyone done anything similar?</p>
|
[
{
"answer_id": 203647,
"author": "cdeszaq",
"author_id": 20770,
"author_profile": "https://Stackoverflow.com/users/20770",
"pm_score": 2,
"selected": true,
"text": "<%\ndim columnWidth\nif session(\"lang\") = \"eng\" then\n columnWidth = 50\nelse\n columnWidth = 100\nend if\n%>\n\n<table>\n <tr>\n <td width=\"<%= columnWidth %>px\">[content]</td>\n </tr>\n</table>\n <%\nprivate int columnWidth;\nif (session(\"lang\") == \"eng\") {\n columnWidth = 50;\n} else {\n columnWidth = 100;\n}\n%>\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203629",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1666/"
] |
203,677
|
<p>Just got a question about generics, why doesn't this compile when using a generic List? If its not possible, anyway around it? Much appreciate any answer.</p>
<pre><code>// Interface used in the ServiceAsync inteface.
public interface BaseObject
{
public String getId();
}
// Class that implements the interface
public class _ModelDto implements BaseObject, IsSerializable
{
protected String id;
public void setId(String id)
{
this.id = id;
}
public String getId()
{
return id;
}
}
// Interface used in the ServiceAsync inteface.
public interface MyAsync<T>
{
// Nothing here.
}
// Service interface use both interfaces above.
public interface ServiceAsync
{
public void getList(MyAsync<List<? extends BaseObject>> callback);
}
public class MyClass
{
ServiceAsync service = (some implementation);
MyAsync<List<_ModelDto>> callBack = new MyAsync<List<_ModelDto>>()
{
};
service.getList(callBack); // This does not compile, says arguments are not applicable????
}
</code></pre>
|
[
{
"answer_id": 203741,
"author": "Aaron",
"author_id": 3752,
"author_profile": "https://Stackoverflow.com/users/3752",
"pm_score": 2,
"selected": false,
"text": " ServiceAsync service = (some implementation);\n MyAsync<List<? extends BaseObject>> callBack = new MyAsync<List<? extends BaseObject>>() \n {\n\n };\n\n service.getList(callBack);\n public interface ServiceAsync<T extends BaseObject>\n{\n public void getList(MyAsync<List<T>> callback);\n}\n public class MyClass \n{\n public void method() \n {\n ServiceAsync<_ModelDto> service = (some implementation);\n MyAsync<List<_ModelDto>> callBack = new MyAsync<List<_ModelDto>>() \n {\n\n };\n\n service.getList(callBack);\n }\n}\n"
},
{
"answer_id": 203777,
"author": "Kris Nuttycombe",
"author_id": 390636,
"author_profile": "https://Stackoverflow.com/users/390636",
"pm_score": 3,
"selected": false,
"text": "getList(MyAsync callback); MyAsync<List<? extends BaseObject>> List<? extends BaseObject> public interface ServiceAsync {\n public <T extends BaseObject> void getList(MyAsync<List<T>> callback);\n}\n\npublic class MyClass {\n public void foo() {\n ServiceAsync service = null;\n MyAsync<List<_ModelDto>> callBack = new MyAsync<List<_ModelDto>>() {};\n\n service.getList (callBack); // This compiles\n }\n}\n"
},
{
"answer_id": 204456,
"author": "Bruno De Fraine",
"author_id": 6918,
"author_profile": "https://Stackoverflow.com/users/6918",
"pm_score": 2,
"selected": true,
"text": "<: _ModelDto <: BaseObject\n List<_ModelDto> <: List<BaseObject>\n List<_ModelDto> <: List<? extends _ModelDto> <: List<? extends BaseObject>\n List<_ModelDto> <: List<? extends BaseObject>\n MyAsync<List<_ModelDto>> <: MyAsync<List<? extends BaseObject>>\n service.getList(callBack) MyAsync<List<_ModelDto>>\n <: MyAsync<? extends List<_ModelDto>>\n <: MyAsync<? extends List<? extends BaseObject>>\n getList public void getList(MyAsync<? extends List<? extends BaseObject>> callback);\n getList callback MyAsync public interface MyAsync<T> {\n T get();\n void set(T t);\n}\n getList get set null ? set"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28108/"
] |
203,684
|
<p>I need to parse recipe ingredients into amount, measurement, item, and description as applicable to the line, such as 1 cup flour, the peel of 2 lemons and 1 cup packed brown sugar etc. What would be the best way of doing this? I am interested in using python for the project so I am assuming using the nltk is the best bet but I am open to other languages.</p>
|
[
{
"answer_id": 204013,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": -1,
"selected": false,
"text": "1 cup flour\n2 lemon peels\n1 cup packed brown sugar\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18926/"
] |
203,695
|
<p>When you create an instance of a class with the <code>new</code> operator, memory gets allocated on the heap. When you create an instance of a struct with the <code>new</code> operator where does the memory get allocated, on the heap or on the stack ?</p>
|
[
{
"answer_id": 204009,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 9,
"selected": true,
"text": "new new new Guid() new Guid(someString) new(...) Guid localVariable = new Guid(someString);\n myInstanceOrStaticVariable = new Guid(someString);\n stfld stsfld using System;\n\npublic class Test\n{\n static Guid field;\n\n static void Main() {}\n static void MethodTakingGuid(Guid guid) {}\n\n\n static void ParameterisedCtorAssignToField()\n {\n field = new Guid(\"\");\n }\n\n static void ParameterisedCtorAssignToLocal()\n {\n Guid local = new Guid(\"\");\n // Force the value to be used\n local.ToString();\n }\n\n static void ParameterisedCtorCallMethod()\n {\n MethodTakingGuid(new Guid(\"\"));\n }\n\n static void ParameterlessCtorAssignToField()\n {\n field = new Guid();\n }\n\n static void ParameterlessCtorAssignToLocal()\n {\n Guid local = new Guid();\n // Force the value to be used\n local.ToString();\n }\n\n static void ParameterlessCtorCallMethod()\n {\n MethodTakingGuid(new Guid());\n }\n}\n .class public auto ansi beforefieldinit Test extends [mscorlib]System.Object \n{\n // Removed Test's constructor, Main, and MethodTakingGuid.\n\n .method private hidebysig static void ParameterisedCtorAssignToField() cil managed\n {\n .maxstack 8\n L_0001: ldstr \"\"\n L_0006: newobj instance void [mscorlib]System.Guid::.ctor(string)\n L_000b: stsfld valuetype [mscorlib]System.Guid Test::field\n L_0010: ret \n }\n\n .method private hidebysig static void ParameterisedCtorAssignToLocal() cil managed\n {\n .maxstack 2\n .locals init ([0] valuetype [mscorlib]System.Guid guid) \n L_0001: ldloca.s guid \n L_0003: ldstr \"\" \n L_0008: call instance void [mscorlib]System.Guid::.ctor(string) \n // Removed ToString() call\n L_001c: ret\n }\n\n .method private hidebysig static void ParameterisedCtorCallMethod() cil managed \n { \n .maxstack 8\n L_0001: ldstr \"\"\n L_0006: newobj instance void [mscorlib]System.Guid::.ctor(string)\n L_000b: call void Test::MethodTakingGuid(valuetype [mscorlib]System.Guid)\n L_0011: ret \n }\n\n .method private hidebysig static void ParameterlessCtorAssignToField() cil managed\n {\n .maxstack 8\n L_0001: ldsflda valuetype [mscorlib]System.Guid Test::field\n L_0006: initobj [mscorlib]System.Guid\n L_000c: ret \n }\n\n .method private hidebysig static void ParameterlessCtorAssignToLocal() cil managed\n {\n .maxstack 1\n .locals init ([0] valuetype [mscorlib]System.Guid guid)\n L_0001: ldloca.s guid\n L_0003: initobj [mscorlib]System.Guid\n // Removed ToString() call\n L_0017: ret \n }\n\n .method private hidebysig static void ParameterlessCtorCallMethod() cil managed\n {\n .maxstack 1\n .locals init ([0] valuetype [mscorlib]System.Guid guid) \n L_0001: ldloca.s guid\n L_0003: initobj [mscorlib]System.Guid\n L_0009: ldloc.0 \n L_000a: call void Test::MethodTakingGuid(valuetype [mscorlib]System.Guid)\n L_0010: ret \n }\n\n .field private static valuetype [mscorlib]System.Guid field\n}\n newobj call instance new initobj initobj new void HowManyStackAllocations()\n{\n Guid guid = new Guid();\n // [...] Use guid\n guid = new Guid(someBytes);\n // [...] Use guid\n guid = new Guid(someString);\n // [...] Use guid\n}\n new guid Guid"
},
{
"answer_id": 12329123,
"author": "Sujit",
"author_id": 792713,
"author_profile": "https://Stackoverflow.com/users/792713",
"pm_score": 2,
"selected": false,
"text": "class struct class struct properties fields class class struct struct struct struct classes class Structs struct"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18709/"
] |
203,707
|
<p>The following two forms of jQuery selectors seem to do the same thing:</p>
<ul>
<li>$("div > ul.posts") </li>
<li>$("div ul.posts")</li>
</ul>
<p>which is to select all the "ul" elements of class "posts" under "div" elements.</p>
<p>Is there any difference?</p>
|
[
{
"answer_id": 203710,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 3,
"selected": false,
"text": "<div>\n <blockquote>\n <ul class=\"posts\"></ul>\n </blockquote>\n</div>\n"
},
{
"answer_id": 203713,
"author": "Andrew Moore",
"author_id": 26210,
"author_profile": "https://Stackoverflow.com/users/26210",
"pm_score": 6,
"selected": true,
"text": "$(\"div > ul.posts\") DIV <div>\n <ul class=\"posts\"> <!--SELECTED-->\n <li>List Item</li>\n <ul class=\"posts\"> <!--NOT SELECTED-->\n <li>Sub list item</li>\n </ul>\n </ul>\n\n <fieldset>\n <ul class=\"posts\"> <!--NOT SELECTED-->\n <li>List item</li>\n </ul>\n </fieldset>\n\n <ul class=\"posts\"> <!--SELECTED-->\n <li>List item</li>\n </ul>\n</div>\n $(\"div ul.posts\") ul.posts div"
},
{
"answer_id": 7082050,
"author": "Chris",
"author_id": 444178,
"author_profile": "https://Stackoverflow.com/users/444178",
"pm_score": 0,
"selected": false,
"text": ">"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6225/"
] |
203,739
|
<pre><code>"foo" instanceof String //=> false
"foo" instanceof Object //=> false
true instanceof Boolean //=> false
true instanceof Object //=> false
false instanceof Boolean //=> false
false instanceof Object //=> false
12.21 instanceof Number //=> false
/foo/ instanceof RegExp //=> true
// the tests against Object really don't make sense
</code></pre>
<p>Array literals and Object literals match...</p>
<pre><code>[0,1] instanceof Array //=> true
{0:1} instanceof Object //=> true
</code></pre>
<p>Why don't all of them? Or, why don't they all <em>not</em>?<br />
And, what are they an instance of, then?</p>
<p>It's the same in FF3, IE7, Opera, and Chrome. So, at least it's consistent.</p>
|
[
{
"answer_id": 203757,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 10,
"selected": true,
"text": "var color1 = new String(\"green\");\ncolor1 instanceof String; // returns true\nvar color2 = \"coral\";\ncolor2 instanceof String; // returns false (color2 is not a String object)\n typeof \"foo\" === \"string\" instanceof"
},
{
"answer_id": 1185835,
"author": "user144049",
"author_id": 144049,
"author_profile": "https://Stackoverflow.com/users/144049",
"pm_score": 5,
"selected": false,
"text": "'foo'.constructor == String // returns true\ntrue.constructor == Boolean // returns true\n"
},
{
"answer_id": 2274632,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "function isInstanceOf(obj, clazz){\n return (obj instanceof eval(\"(\"+clazz+\")\")) || (typeof obj == clazz.toLowerCase());\n};\n isInstanceOf('','String');\nisInstanceOf(new String(), 'String');\n"
},
{
"answer_id": 7772724,
"author": "axkibe",
"author_id": 588779,
"author_profile": "https://Stackoverflow.com/users/588779",
"pm_score": 7,
"selected": false,
"text": "function isString(s) {\n return typeof(s) === 'string' || s instanceof String;\n}\n"
},
{
"answer_id": 18057157,
"author": "Aadit M Shah",
"author_id": 783743,
"author_profile": "https://Stackoverflow.com/users/783743",
"pm_score": 6,
"selected": false,
"text": "undefined console.log(typeof true); // boolean\nconsole.log(typeof 0); // number\nconsole.log(typeof \"\"); // string\nconsole.log(typeof undefined); // undefined\nconsole.log(typeof null); // object\nconsole.log(typeof []); // object\nconsole.log(typeof {}); // object\nconsole.log(typeof function () {}); // function\n null null true 0 \"\" undefined Boolean Number String console.log(typeof new Boolean(true)); // object\nconsole.log(typeof new Number(0)); // object\nconsole.log(typeof new String(\"\")); // object\n Boolean Number String instanceof false console.log(true instanceof Boolean); // false\nconsole.log(0 instanceof Number); // false\nconsole.log(\"\" instanceof String); // false\nconsole.log(new Boolean(true) instanceof Boolean); // true\nconsole.log(new Number(0) instanceof Number); // true\nconsole.log(new String(\"\") instanceof String); // true\n typeof instanceof typeof instanceof toString Object.prototype.toString [[Class]] function classOf(value) {\n return Object.prototype.toString.call(value);\n}\n\nconsole.log(classOf(true)); // [object Boolean]\nconsole.log(classOf(0)); // [object Number]\nconsole.log(classOf(\"\")); // [object String]\nconsole.log(classOf(new Boolean(true))); // [object Boolean]\nconsole.log(classOf(new Number(0))); // [object Number]\nconsole.log(classOf(new String(\"\"))); // [object String]\n [[Class]] typeof Object.prototype.toString typeof function typeOf(value) {\n return Object.prototype.toString.call(value).slice(8, -1);\n}\n\nconsole.log(typeOf(true)); // Boolean\nconsole.log(typeOf(0)); // Number\nconsole.log(typeOf(\"\")); // String\nconsole.log(typeOf(new Boolean(true))); // Boolean\nconsole.log(typeOf(new Number(0))); // Number\nconsole.log(typeOf(new String(\"\"))); // String\n"
},
{
"answer_id": 27899344,
"author": "mko",
"author_id": 456218,
"author_profile": "https://Stackoverflow.com/users/456218",
"pm_score": -1,
"selected": false,
"text": "\"str\".__proto__ // #1\n=> String\n \"str\" istanceof String true \"str\".__proto__ == String.prototype // #2\n=> true\n __proto__ Object.getPrototypeOf Object.getPrototypeOf(\"str\") // #3\n=> TypeError: Object.getPrototypeOf called on non-object\n"
},
{
"answer_id": 42868539,
"author": "Robby Harris",
"author_id": 7729688,
"author_profile": "https://Stackoverflow.com/users/7729688",
"pm_score": 1,
"selected": false,
"text": "Object.getPrototypeOf('test') === String.prototype //true\nObject.getPrototypeOf(1) === String.prototype //false\n"
},
{
"answer_id": 45837316,
"author": "saurabhgoyal795",
"author_id": 7539786,
"author_profile": "https://Stackoverflow.com/users/7539786",
"pm_score": 4,
"selected": false,
"text": " typeof(text) === 'string' || text instanceof String; \n var text=\"foo\"; String text= new String(\"foo\");"
},
{
"answer_id": 56655832,
"author": "HKTonyLee",
"author_id": 474197,
"author_profile": "https://Stackoverflow.com/users/474197",
"pm_score": 2,
"selected": false,
"text": "If Type(O) is not Object, return false. Obj Obj instanceof Callable instanceof false"
},
{
"answer_id": 66213427,
"author": "Belhadjer Samir",
"author_id": 13762673,
"author_profile": "https://Stackoverflow.com/users/13762673",
"pm_score": 2,
"selected": false,
"text": "var name = \"foo\";\nvar firstChar = name.charAt(0);\nconsole.log(firstChar);\n // what the JavaScript engine does\nvar name = \"foo\";\nvar temp = new String(name);\nvar firstChar = temp.charAt(0);\ntemp = null;\nconsole.log(firstChar);\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15031/"
] |
203,754
|
<p>I have a thread running in the background that is reading events from an input device in a blocking fashion, now when I exit the application I want to clean up the thread properly, but I can't just run a pthread_join() because the thread would never exit due to the blocking IO.</p>
<p>How do I properly solve that situation? Should I send a pthread_kill(theard, SIGIO) or a pthread_kill(theard, SIGALRM) to break the block? Is either of that even the right signal? Or is there another way to solve this situation and let that child thread exit the blocking read?</p>
<p>Currently a bit puzzled since none of my googling turned up a solution.</p>
<p>This is on Linux and using pthreads.</p>
<p>Edit: I played around a bit with SIGIO and SIGALRM, when I don't install a signal handler they break the blocking IO up, but give a message on the console ("I/O possible") but when I install a signal handler, to avoid that message, they no longer break the blocking IO, so the thread doesn't terminate. So I am kind of back to step one.</p>
|
[
{
"answer_id": 203902,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "select()"
},
{
"answer_id": 204027,
"author": "bog",
"author_id": 20909,
"author_profile": "https://Stackoverflow.com/users/20909",
"pm_score": 4,
"selected": false,
"text": "#include <stdlib.h>\n#include <stdio.h>\n#include <pthread.h>\n#include <signal.h>\n\nint global_gotsig = 0;\n\nvoid *gotsig(int sig, siginfo_t *info, void *ucontext) \n{\n global_gotsig++;\n return NULL;\n}\n\nvoid *reader(void *arg)\n{\n char buf[32];\n int i;\n int hdlsig = (int)arg;\n\n struct sigaction sa;\n sa.sa_handler = NULL;\n sa.sa_sigaction = gotsig;\n sa.sa_flags = SA_SIGINFO;\n sigemptyset(&sa.sa_mask);\n\n if (sigaction(hdlsig, &sa, NULL) < 0) {\n perror(\"sigaction\");\n return (void *)-1;\n }\n i = read(fileno(stdin), buf, 32);\n if (i < 0) {\n perror(\"read\");\n } else {\n printf(\"Read %d bytes\\n\", i);\n }\n return (void *)i;\n}\n\nmain(int argc, char **argv)\n{\n pthread_t tid1;\n void *ret;\n int i;\n int sig = SIGUSR1;\n\n if (argc == 2) sig = atoi(argv[1]);\n printf(\"Using sig %d\\n\", sig);\n\n if (pthread_create(&tid1, NULL, reader, (void *)sig)) {\n perror(\"pthread_create\");\n exit(1);\n }\n sleep(5);\n printf(\"killing thread\\n\");\n pthread_kill(tid1, sig);\n i = pthread_join(tid1, &ret);\n if (i < 0)\n perror(\"pthread_join\");\n else\n printf(\"thread returned %ld\\n\", (long)ret);\n printf(\"Got sig? %d\\n\", global_gotsig);\n\n}\n"
},
{
"answer_id": 204804,
"author": "Nicholas Mancuso",
"author_id": 8945,
"author_profile": "https://Stackoverflow.com/users/8945",
"pm_score": 0,
"selected": false,
"text": "while (!_finished)\n{\n pthread_cond_wait(&cond);\n handleio();\n}\ncleanup();\n"
},
{
"answer_id": 205325,
"author": "luke",
"author_id": 25920,
"author_profile": "https://Stackoverflow.com/users/25920",
"pm_score": 0,
"selected": false,
"text": "struct pollfd pfd;\npfd.fd = socket;\npfd.events = POLLIN | POLLHUP | POLLERR;\npthread_lock(&lock);\nwhile(thread_alive)\n{\n int ret = poll(&pfd, 1, 100);\n if(ret == 1)\n {\n //handle IO\n }\n else\n {\n pthread_cond_timedwait(&lock, &cond, 100);\n }\n}\npthread_unlock(&lock);\n"
},
{
"answer_id": 3800023,
"author": "qqq",
"author_id": 458979,
"author_profile": "https://Stackoverflow.com/users/458979",
"pm_score": 4,
"selected": false,
"text": "pthread_cancel pthread_cleanup_push pop try {} catch() pthread_cancel SIGUSR1 pthread_kill(SIGUSR1) EINTR EINTR pthread_cancel"
},
{
"answer_id": 36854661,
"author": "Alexis Wilke",
"author_id": 212378,
"author_profile": "https://Stackoverflow.com/users/212378",
"pm_score": 4,
"selected": true,
"text": "signalfd() // defined a set of signals\nsigset_t set;\nsigemptyset(&set);\nsigaddset(&set, SIGUSR1);\n// ... you can add more than one ...\n\n// prevent the default signal behavior (very important)\nsigprocmask(SIG_BLOCK, &set, nullptr);\n\n// open a file descriptor using that set of Unix signals\nf_socket = signalfd(-1, &set, SFD_NONBLOCK | SFD_CLOEXEC);\n poll() select()"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28113/"
] |
203,771
|
<p>I have been using CPPUnit as a unit testing framework and am now trying to use it in an automated build and package system. However a problem holding me back is that if a crash occurs during the running of the unit tests, e.g. a null pointer dereferencing, it halts the remainder of the automation.</p>
<p>Is there any way for CPPUnit to recover from the exception, record the test failure and then exist gracefully rather than terminating the unit test process? Even an approach specific to null pointer dereferencing would be useful as that makes up about 90% of the issues I have had.</p>
<p>To be technology-specific, I am using makefiles on a Windows system.</p>
|
[
{
"answer_id": 203889,
"author": "philant",
"author_id": 18804,
"author_profile": "https://Stackoverflow.com/users/18804",
"pm_score": 3,
"selected": true,
"text": "class TestObject : public CPPUNIT_NS::TestCase\n{\n CPPUNIT_TEST_SUITE(Test);\n CPPUNIT_TEST(testObjectIsReady);\n CPPUNIT_TEST_SUITE_END();\n\npublic:\n void setUp(void) {}\n void tearDown(void) {} \n\nprotected:\n void testObjectIsReady(void)\n { \n Object *theObject = GetObject();\n\n CPPUNIT_ASSERT_MESSAGE(\"check pointer is not null\", theObject != NULL);\n\n //--- now you can play with your object without dereferencing a NULL pointer\n CPPUNIT_ASSERT_MESSAGE(\"check objet is ready\", theObject->isReady());\n }\n};\n"
},
{
"answer_id": 1886433,
"author": "Baiyan Huang",
"author_id": 70198,
"author_profile": "https://Stackoverflow.com/users/70198",
"pm_score": 0,
"selected": false,
"text": "__try\n{\n// running your case\n}\n\n__except\n{\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203771",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10247/"
] |
203,787
|
<p>I have an object, that is facing a particular direction with (for instance) a 45 degree field of view, and a limit view range. I have done all the initial checks (Quadtree node, and distance), but now I need to check if a particular object is within that view cone, (In this case to decide only to follow that object if we can see it). </p>
<p>Apart from casting a ray for each degree from <code>Direction - (FieldOfView / 2)</code> to <code>Direction + (FieldOfView / 2)</code> (I am doing that at the moment and it is horrible), what is the best way to do this visibility check?</p>
|
[
{
"answer_id": 203802,
"author": "Federico A. Ramponi",
"author_id": 18770,
"author_profile": "https://Stackoverflow.com/users/18770",
"pm_score": 4,
"selected": true,
"text": "arccos(scalarProduct(viewDirection, (object - you)) / (norm(viewDirection)*norm(object - you))).\n"
},
{
"answer_id": 254086,
"author": "postfuturist",
"author_id": 1892,
"author_profile": "https://Stackoverflow.com/users/1892",
"pm_score": 4,
"selected": false,
"text": "float cos_angle = cos(PI/4); // 45 degrees, for example\n vector test_point_vector = normalize(test_point_loc - cone_origin);\nfloat dot_product = dot(normalized_cone_vector, text_point_vector);\nbool inside_code = dot_product > cos_angle;\n A · B = |A| * |B| * cos(Θ)\n An · Bn = cos(Θ)\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24793/"
] |
203,807
|
<p>I have a VB application which extracts data and creates 3 CSV files (a.csv, b.csv, c.csv). Then I use another Excel spreadsheet (import.xls) to import all the data from the above CSV files into this sheet.</p>
<p>import.xls file has a macro which opens the CSV files one by one and copies the data. The problem I am facing is the dates in the CSV files are stored as mm/dd/yyyy and this is copied as is to the Excel sheet. But I want the date in dd/mm/yyy format.</p>
<p>When I open any of the CSV files manually the dates are displayed in the correct format (mm/dd/yyyy). Any idea how I can solve this issue?</p>
|
[
{
"answer_id": 203814,
"author": "Mark",
"author_id": 26310,
"author_profile": "https://Stackoverflow.com/users/26310",
"pm_score": 4,
"selected": true,
"text": "Format(DateText, \"dd/mm/yyyy\")\n"
},
{
"answer_id": 264992,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "format(date,'dd-mmm-yyyy') cstr"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12178/"
] |
203,809
|
<p>This might be a little hard to explain, but I will try.</p>
<p>I want to display a list of categories (stored in 1 table), and number of domains associated with each category (stored in another table). </p>
<p>The monkey wrench in this case is that each domain has a set of records associated with it (which are stored in a 3rd table). I only want to show the categories that have domains associated with them, and the count of domains should reflect only the domains that have records associated with them (from the 3rd table).</p>
<p>My current query</p>
<pre><code>SELECT r.rev_id, c.cat_id, c.cat_name, count(d.dom_id) As rev_id_count FROM reviews r
INNER JOIN domains d ON r.rev_domain_from=d.dom_id
INNER JOIN categories c ON d.dom_catid=c.cat_id
WHERE rev_status = 1
GROUP BY cat_name
ORDER BY cat_name
</code></pre>
<p>This selects the correct category names, but shows a false count (rev_id_count). If the category has 2 domains in it, and each domain has 2 records, it will show count of 4, when it should be 2.</p>
|
[
{
"answer_id": 203815,
"author": "AquilaX",
"author_id": 17734,
"author_profile": "https://Stackoverflow.com/users/17734",
"pm_score": 0,
"selected": false,
"text": "SELECT c.name, count(d.id)\nFROM categories c\nJOIN domains d ON c.id = d.cid\nJOIN records r ON r.did = d.id\nGROUP BY c.name;\n"
},
{
"answer_id": 203851,
"author": "Richard Harrison",
"author_id": 19624,
"author_profile": "https://Stackoverflow.com/users/19624",
"pm_score": 0,
"selected": false,
"text": " SELECT * FROM records \n INNER JOIN domains on <clause> \n INNER JOIN categories on <clause>\n WHERE <something>\n"
},
{
"answer_id": 203869,
"author": "Mark",
"author_id": 26310,
"author_profile": "https://Stackoverflow.com/users/26310",
"pm_score": 0,
"selected": false,
"text": "SELECT c.name, d.name, count(d.id)\n FROM categories c\n JOIN domains d ON c.id = d.cid\n JOIN records r ON r.did = d.id\nGROUP BY c.name, d.name;\n Cat 1, Domain 1, 2\nCat 1, Domain 2, 1\nCat 2, Domain 3, 5\n"
},
{
"answer_id": 203887,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 2,
"selected": false,
"text": "select c.name, count(distinct d.did) from domains d\n left join categories c on c.cid = d.cid\n left join records r on r.did = d.did\n group by c.name\n name count\n---- ----- \ntest 2\ntest2 2\n"
},
{
"answer_id": 203892,
"author": "Mathias",
"author_id": 7241,
"author_profile": "https://Stackoverflow.com/users/7241",
"pm_score": 3,
"selected": true,
"text": "SELECT Categories.Name,count(DISTINCT categories.name) FROM Categories\nJOIN Domains ON Categories.ID=Domains.CID\nJOIN Records ON Records.DID=Domains.ID\nGROUP BY Categories.Name \nCREATE TABLE Categories (Name nvarchar(50), ID int NOT NULL IDENTITY(1,1))\nCREATE TABLE Domains (Name nvarchar(50), ID int NOT NULL IDENTITY(1,1), CID int)\nCREATE TABLE Records (Name nvarchar(50), ID int NOT NULL IDENTITY(1,1), DID int)\n\nINSERT INTO Records (DID) VALUES (1)\nINSERT INTO Records (DID) VALUES (1)\nINSERT INTO Records (DID) VALUES (2)\nINSERT INTO Records (DID) VALUES (2)\nINSERT INTO Records (DID) VALUES (3)\nINSERT INTO Records (DID) VALUES (3)\n\nINSERT INTO Domains (Name,CID) VALUES ('D1',1)\nINSERT INTO Domains (Name,CID) VALUES ('D2',1)\nINSERT INTO Domains (Name,CID) VALUES ('D5',1)\nINSERT INTO Domains (Name,CID) VALUES ('D3',2)\nINSERT INTO Domains (Name,CID) VALUES ('D4',2)\n\nINSERT INTO Categories (Name) VALUES ('1')\nINSERT INTO Categories (Name) VALUES ('2')\nINSERT INTO Categories (Name) VALUES ('3')\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203809",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
203,823
|
<p>One of classes in my program uses some third-party library. Library object is a private member of my class:</p>
<pre><code>// My.h
#include <3pheader.h>
class My
{
...
private:
3pObject m_object;
}
</code></pre>
<p>The problem with this - any other unit in my program that uses My class should be configured to include 3p headers. Moving to another kind of 3p will jeopardize the whole build...
I see two ways to fix this - one is to is to make 3pObject extern and turn m_Object into a pointer, being initialized in constructor; second is to create an "interface" and "factory" classes and export them...</p>
<p>Could you suggest another ways to solve that ?</p>
|
[
{
"answer_id": 203830,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 4,
"selected": true,
"text": "// header\nclass My\n{\n class impl;\n std::auto_ptr<impl> _impl;\n};\n\n// cpp\n#include <3pheader.h>\nclass My::impl\n{\n 3pObject _object;\n};\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18174/"
] |
203,837
|
<p>I am trying to use a StreamReader to read a file, but it is always in use by another process so I get this error:</p>
<blockquote>
<p>The process cannot access the file
'\arfjwknasgmed17\C$\FLAG
CONDITION\CP-ARFJN-FLAG.XLS' because
it is being used by another process.</p>
</blockquote>
<p>Is there a way I can read this without copying it? Or is that my only option?</p>
|
[
{
"answer_id": 9123879,
"author": "JST",
"author_id": 1076973,
"author_profile": "https://Stackoverflow.com/users/1076973",
"pm_score": 2,
"selected": false,
"text": "FileStream fileStr = File.Open(<full file name>, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);\nfileStream = new StreamReader(fileStr);\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14777/"
] |
203,844
|
<p>I have a form with multiple fields that I'm validating (some with methods added for custom validation) with Jörn Zaeffere's excellent jQuery Validation plugin. How do you circumvent validation with specified submit controls (in other words, fire validation with some submit inputs, but do not fire validation with others)? This would be similar to ValidationGroups with standard ASP.NET validator controls.</p>
<p>My situation:</p>
<p>It's with ASP.NET WebForms, but you can ignore that if you wish. However, I am using the validation more as a "recommendation": in other words, when the form is submitted, validation fires but instead of a "required" message displaying, a "recommendation" shows that says something along the line of "you missed the following fields.... do you wish to proceed anyways?" At that point in the error container there's another submit button now visible that can be pressed which would ignore the validation and submit anyways. How to circumvent the forms .validate() for this button control and still post?</p>
<p>The Buy and Sell a House sample at <a href="http://jquery.bassistance.de/validate/demo/multipart/" rel="noreferrer">http://jquery.bassistance.de/validate/demo/multipart/</a> allows for this in order to hit the previous links, but it does so through creating custom methods and adding it to the validator. I would prefer to not have to create custom methods duplicating functionality already in the validation plugin.</p>
<p>The following is a shortened version of the immediately applicable script that I've got right now:</p>
<pre><code>var container = $("#<%= Form.ClientID %> div.validationSuggestion");
$('#<%= Form.ClientID %>').validate({
errorContainer: container,
errorLabelContainer: $("ul",container),
rules: {
<%= YesNo.UniqueID %>: { required: true },
<%= ShortText.UniqueID %>: { required: true } // etc.
},
messages: {
<%= YesNo.UniqueID %>: 'A message.',
<%= ShortText.UniqueID %>: 'Another message.' // etc.
},
highlight: function(element, errorClass) {
$(element).addClass(errorClass);
$(element.form).find("label[for=" + element.id + "]").addClass(errorClass);
$(element.form).find("label[for=" + element.id + "]").removeClass("valid");
},
unhighlight: function(element, errorClass) {
$(element).removeClass(errorClass);
$(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);
$(element.form).find("label[for=" + element.id + "]").addClass("valid");
},
wrapper: 'li'
});
</code></pre>
|
[
{
"answer_id": 203989,
"author": "redsquare",
"author_id": 6440,
"author_profile": "https://Stackoverflow.com/users/6440",
"pm_score": 9,
"selected": true,
"text": "cancel <input class=\"cancel\" type=\"submit\" value=\"Save\" />\n formnovalidate <input formnovalidate=\"formnovalidate\" type=\"submit\" value=\"Save\" />\n"
},
{
"answer_id": 2879499,
"author": "lepe",
"author_id": 196507,
"author_profile": "https://Stackoverflow.com/users/196507",
"pm_score": 7,
"selected": false,
"text": "$(\"form\").validate().cancelSubmit = true;\n"
},
{
"answer_id": 17401929,
"author": "Simon_Weaver",
"author_id": 16940,
"author_profile": "https://Stackoverflow.com/users/16940",
"pm_score": 2,
"selected": false,
"text": "@lepe @redsquare ASP.NET MVC jquery.validate.unobtrusive.js .cancel To skip validation while still using a submit-button, add a class=\"cancel\" to that input.\n\n <input type=\"submit\" name=\"submit\" value=\"Submit\"/>\n <input type=\"submit\" class=\"cancel\" name=\"cancel\" value=\"Cancel\"/>\n type='reset' jquery.validation.unobtrusive.js .cancel // restore behavior of .cancel from jquery validate to allow submit button \n // to automatically bypass all jquery validation\n $(document).on('click', 'input[type=image].cancel,input[type=submit].cancel', function (evt)\n {\n // find parent form, cancel validation and submit it\n // cancelSubmit just prevents jQuery validation from kicking in\n $(this).closest('form').data(\"validator\").cancelSubmit = true;\n $(this).closest('form').submit();\n return false;\n });\n .ignore button"
},
{
"answer_id": 27642144,
"author": "bradlis7",
"author_id": 179311,
"author_profile": "https://Stackoverflow.com/users/179311",
"pm_score": 1,
"selected": false,
"text": "$('#formId')[0].submit() <input type='button' value='SubmitWithoutValidation' onclick='$(this).closest('form')[0].submit()'/>\n input submit"
},
{
"answer_id": 29615155,
"author": "TastyCode",
"author_id": 949827,
"author_profile": "https://Stackoverflow.com/users/949827",
"pm_score": 4,
"selected": false,
"text": " <input type=\"submit\" name=\"go\" value=\"Submit\"> \n <input type=\"submit\" formnovalidate name=\"cancel\" value=\"Cancel\"> \n"
},
{
"answer_id": 31665025,
"author": "Daniel Garcia",
"author_id": 259824,
"author_profile": "https://Stackoverflow.com/users/259824",
"pm_score": 5,
"selected": false,
"text": "$(\"form\").validate().settings.ignore = \"*\";\n $(\"form\").validate().settings.ignore = \":hidden\";\n"
},
{
"answer_id": 39412871,
"author": "Scott Mayers",
"author_id": 4670975,
"author_profile": "https://Stackoverflow.com/users/4670975",
"pm_score": 1,
"selected": false,
"text": "event.preventDefault():\n $(\"#redirectButton\").click(function( event ) {\n event.preventDefault();\n window.location.href='http://www.skip-submit.com';\n});\n $(\"#saveButton\").click(function( event ) {\n event.preventDefault();\n var postData = $('#myForm').serialize();\n var jqxhr = $.post('http://www.another-end-point.com', postData ,function() {\n }).done(function() {\n alert(\"Data sent!\");\n }).fail(function(jqXHR, textStatus, errorThrown) {\n alert(\"Ooops, we have an error\");\n })\n"
},
{
"answer_id": 41952058,
"author": "Bugfixer",
"author_id": 2050394,
"author_profile": "https://Stackoverflow.com/users/2050394",
"pm_score": 1,
"selected": false,
"text": "$('.save_exist').on('click', function (event) {\n $('#MyformID').removeData('validator');\n $('.form-control').removeClass('error');\n $('.form-control').removeClass('required'); \n $(\"#loanApplication\").validate().cancelSubmit = true;\n $('#loanApplication').submit();\n event.preventDefault();\n});\n"
},
{
"answer_id": 48323384,
"author": "Davide Ciarmiello",
"author_id": 7752815,
"author_profile": "https://Stackoverflow.com/users/7752815",
"pm_score": 2,
"selected": false,
"text": "$(\"form\").validate().settings.ignore = \"*\";\n $(\"form\").validate().cancelSubmit = true;\n var btn = form.children('input.cancel.fakeSubmitFormButton');\nif (btn.length === 0) {\n btn = $('<input name=\"FakeCancelSubmitButton\" class=\"cancel fakeSubmitFormButton hide\" type=\"submit\" formnovalidate value=\"FakeCancelSubmitButton\" />');\n form.append(btn);\n}\nbtn.click();\n"
},
{
"answer_id": 53108235,
"author": "Lucy",
"author_id": 8808260,
"author_profile": "https://Stackoverflow.com/users/8808260",
"pm_score": 0,
"selected": false,
"text": "$('#cancel-button').click(function() {\n var $form = $(this).closest('form');\n $form.find('*[data-validation]').attr('data-validation', null);\n $form.get(0).submit();\n});\n"
},
{
"answer_id": 63010987,
"author": "user3024034",
"author_id": 3024034,
"author_profile": "https://Stackoverflow.com/users/3024034",
"pm_score": 2,
"selected": false,
"text": "<button type=\"submit\" formnovalidate=\"formnovalidate\">submit</button>\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9344/"
] |
203,854
|
<p>Example. 123456, and we want the third from the right ('4') out.</p>
<p>The idea in practise is to access each digit seperately (ie. 6 5 4 3 2 1).</p>
<p>C/C++/C# preferred.</p>
|
[
{
"answer_id": 203864,
"author": "SmacL",
"author_id": 22564,
"author_profile": "https://Stackoverflow.com/users/22564",
"pm_score": -1,
"selected": false,
"text": "char nthDigitFromRight(int x,int n)\n{\n char str[20];\n sprintf(str,\"%020d\",x);\n return(str[19 - x]);\n}\n"
},
{
"answer_id": 203874,
"author": "moritz",
"author_id": 14132,
"author_profile": "https://Stackoverflow.com/users/14132",
"pm_score": 2,
"selected": false,
"text": "pow(2, 3) == 8"
},
{
"answer_id": 203877,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 5,
"selected": false,
"text": "char nthdigit(int x, int n)\n{\n while (n--) {\n x /= 10;\n }\n return (x % 10) + '0';\n}\n char nthdigit(int x, int n)\n{\n static int powersof10[] = {1, 10, 100, 1000, ...};\n return ((x / powersof10[n]) % 10) + '0';\n}\n"
},
{
"answer_id": 203881,
"author": "Brannon",
"author_id": 5745,
"author_profile": "https://Stackoverflow.com/users/5745",
"pm_score": 3,
"selected": false,
"text": "class Program\n{\n static void Main(string[] args)\n {\n int x = 123456;\n\n for (int i = 1; i <= 6; i++)\n {\n Console.WriteLine(GetDigit(x, i));\n }\n }\n\n static int GetDigit(int number, int digit)\n {\n return (number / (int)Math.Pow(10, digit - 1)) % 10;\n }\n}\n 6\n5\n4\n3\n2\n1\n"
},
{
"answer_id": 204011,
"author": "Darius Bacon",
"author_id": 27024,
"author_profile": "https://Stackoverflow.com/users/27024",
"pm_score": 2,
"selected": false,
"text": "def hundreds_digit(u): return mod10(div100(u))\n\ndef div100(u): return div10(div10(u))\ndef mod10(u): return u - mul10(div10(u))\ndef mul10(u): return ((u << 2) + u) << 1\n\ndef div10(u):\n Q = ((u >> 1) + u) >> 1 # Q = u*0.11\n Q = ((Q >> 4) + Q) # Q = u*0.110011\n Q = ((Q >> 8) + Q) >> 3 # Q = u*0.00011001100110011\n return Q\n\n# Alternatively:\n# def div100(u): return (u * 0xa3d7) >> 22\n# though that'd only work for 16-bit u values.\n# Or you could construct shifts and adds along the lines of div10(),\n# but I didn't go to the trouble.\n >>> hundreds_digit(123456)\n4\n>>> hundreds_digit(123956)\n9\n"
},
{
"answer_id": 16094891,
"author": "eselk",
"author_id": 1042232,
"author_profile": "https://Stackoverflow.com/users/1042232",
"pm_score": 3,
"selected": false,
"text": "public static int GetDigits(this int number, int highestDigit, int numDigits)\n{\n return (number / (int)Math.Pow(10, highestDigit - numDigits)) % (int)Math.Pow(10, numDigits);\n}\n int i = 20010607;\nstring year = i.GetDigits(8,4).ToString();\nstring month = i.GetDigits(4,2).ToString();\nstring day = i.GetDigits(2,2).ToString();\n"
},
{
"answer_id": 26696263,
"author": "Michael Peterson",
"author_id": 211614,
"author_profile": "https://Stackoverflow.com/users/211614",
"pm_score": 1,
"selected": false,
"text": "+ (int)digitAtPosition:(int)pos of:(int)number {\n\n return (number % ((int)pow(10, pos))) / (int)pow(10, pos - 1);\n}\n"
},
{
"answer_id": 31288251,
"author": "Sonal S.",
"author_id": 1736902,
"author_profile": "https://Stackoverflow.com/users/1736902",
"pm_score": 0,
"selected": false,
"text": "public void getDigit(long n,int k){\n int i=0;\n long r =0;\n while(i<n){\n r=n%10;\n n=n/10;\n i++;\n }\n System.out.println( k + \"th digit from right \" + r);\n }\n"
},
{
"answer_id": 34098361,
"author": "Evorlor",
"author_id": 1889720,
"author_profile": "https://Stackoverflow.com/users/1889720",
"pm_score": 0,
"selected": false,
"text": "public static class IntExtensions\n{\n /// <summary>\n /// Returns the nth digit from an int, \n /// where 0 is the least significant digit \n /// and n is the most significant digit.\n /// </summary>\n public static int GetDigit(this int number, int digit)\n {\n for (int i = 0; i < digit; i++)\n {\n number /= 10;\n }\n return number % 10;\n }\n}\n int myNumber = 12345;\nint five = myNumber.GetDigit(0);\nint four = myNumber.GetDigit(1);\nint three = myNumber.GetDigit(2);\nint two = myNumber.GetDigit(3);\nint one = myNumber.GetDigit(4);\nint zero = myNumber.GetDigit(5);\n"
},
{
"answer_id": 37766556,
"author": "KLeviss XHyra",
"author_id": 6454151,
"author_profile": "https://Stackoverflow.com/users/6454151",
"pm_score": -1,
"selected": false,
"text": "int returndigit(int n,int d)\n{\n d=d-1;\n while(d--)\n {\n n/=10;\n }\n return (n%10);\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24661/"
] |
203,859
|
<p>Markdown is a great tool for formatting plain text into pretty html, but it doesn't turn plain-text links into URLs automatically. Like this one:</p>
<p><a href="http://www.google.com/" rel="noreferrer">http://www.google.com/</a></p>
<p>How do I get markdown to add tags to URLs when I format a block of text?</p>
|
[
{
"answer_id": 203870,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 2,
"selected": false,
"text": "AutoLink"
},
{
"answer_id": 206486,
"author": "andrewrk",
"author_id": 432,
"author_profile": "https://Stackoverflow.com/users/432",
"pm_score": 2,
"selected": false,
"text": "<div class=\"news_post\">\n {% autoescape off %}\n {{ post.content|markdown|urlify2}}\n {% endautoescape %}\n</div>\n from django import template\nimport re\n\nregister = template.Library()\n\nurlfinder = re.compile(\"([0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}|((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\\\.)[-A-Za-z0-9\\\\.]+):[0-9]*)?/[-A-Za-z0-9_\\\\$\\\\.\\\\+\\\\!\\\\*\\\\(\\\\),;:@&=\\\\?/~\\\\#\\\\%]*[^]'\\\\.}>\\\\),\\\\\\\"]\")\n\n@register.filter(\"urlify2\")\ndef urlify2(value):\n return urlfinder.sub(r'<a href=\"\\1\">\\1</a>', value)\n"
},
{
"answer_id": 828458,
"author": "csytan",
"author_id": 86568,
"author_profile": "https://Stackoverflow.com/users/86568",
"pm_score": 3,
"selected": true,
"text": "urlfinder = re.compile('^(http:\\/\\/\\S+)')\nurlfinder2 = re.compile('\\s(http:\\/\\/\\S+)')\n@register.filter('urlify_markdown')\ndef urlify_markdown(value):\n value = urlfinder.sub(r'<\\1>', value)\n return urlfinder2.sub(r' <\\1>', value)\n <div>\n {{ content|urlify_markdown|markdown}}\n</div>\n"
},
{
"answer_id": 1665440,
"author": "SamBarnes",
"author_id": 168632,
"author_profile": "https://Stackoverflow.com/users/168632",
"pm_score": 3,
"selected": false,
"text": "import markdown\nfrom markdown.inlinepatterns import Pattern\n\nEXTRA_AUTOLINK_RE = r'(?<!\"|>)((https?://|www)[-\\w./#?%=&]+)'\n\nclass AutoLinkPattern(Pattern):\n\n def handleMatch(self, m):\n el = markdown.etree.Element('a')\n if m.group(2).startswith('http'):\n href = m.group(2)\n else:\n href = 'http://%s' % m.group(2)\n el.set('href', href)\n el.text = m.group(2)\n return el\n\nclass AutoLinkExtension(markdown.Extension):\n \"\"\"\n There's already an inline pattern called autolink which handles \n <http://www.google.com> type links. So lets call this extra_autolink \n \"\"\"\n\n def extendMarkdown(self, md, md_globals):\n md.inlinePatterns.add('extra_autolink', \n AutoLinkPattern(EXTRA_AUTOLINK_RE, self), '<automail')\n\ndef makeExtension(configs=[]):\n return AutoLinkExtension(configs=configs)\n {% load markdown %}\n\n(( content|markdown:'autolink'))\n [www.google.com](http://www.yahoo.co.uk)\n"
},
{
"answer_id": 42060153,
"author": "chriscauley",
"author_id": 266564,
"author_profile": "https://Stackoverflow.com/users/266564",
"pm_score": 1,
"selected": false,
"text": "(google.com) <google.com> markdown.markdown(text, extensions=['urlize'], safe_mode=True)\nmarkdown.markdown(text, extensions=['path.to.mdx_urlize'], safe_mode=True)\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203859",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/432/"
] |
203,863
|
<p>I am getting this warning: "Missing XML comment for publicly visible type or member".</p>
<p>How to solve this?</p>
|
[
{
"answer_id": 203871,
"author": "Matthias Meid",
"author_id": 17713,
"author_profile": "https://Stackoverflow.com/users/17713",
"pm_score": 5,
"selected": false,
"text": "/// <summary>\n/// Describe your member here.\n/// </summary>\npublic string Something\n{\n get;\n set;\n}\n"
},
{
"answer_id": 203873,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 10,
"selected": false,
"text": "#pragma warning disable 1591 #pragma warning restore 1591"
},
{
"answer_id": 203876,
"author": "Isak Savo",
"author_id": 8521,
"author_profile": "https://Stackoverflow.com/users/8521",
"pm_score": 7,
"selected": false,
"text": "///<Summary>\n/// Gets the answer\n///</Summary>\npublic int MyMethod()\n{\n return 42;\n}\n <summary>"
},
{
"answer_id": 12201277,
"author": "Mike Guthrie",
"author_id": 1223642,
"author_profile": "https://Stackoverflow.com/users/1223642",
"pm_score": 3,
"selected": false,
"text": "private internal"
},
{
"answer_id": 20252069,
"author": "Coyolero",
"author_id": 1013206,
"author_profile": "https://Stackoverflow.com/users/1013206",
"pm_score": -1,
"selected": false,
"text": "[webMethod]\npublic void DoSomething()\n{\n}\n [webMethod()] // Note the Parentheses \npublic void DoSomething()\n{\n}\n"
},
{
"answer_id": 32474314,
"author": "Hassan Faghihi",
"author_id": 1260751,
"author_profile": "https://Stackoverflow.com/users/1260751",
"pm_score": 3,
"selected": false,
"text": "#pragma warning disable 1591 #pragma warning restore 1591 #pragma warning disable 1591 #pragma warning restore 1591 using System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing MongoDB.Bson;\nusing MongoDB.Bson.Serialization.Attributes;\nusing RealEstate.Entity.Models.Base;\n\nnamespace RealEstate.Models.Base\n{\n public class CityVM\n {\n\n#pragma warning disable 1591\n\n [Required]\n public string Id { get; set; }\n\n [Required]\n public string Name { get; set; }\n\n public List<LanguageBasedName> LanguageBasedNames { get; set; }\n\n [Required]\n public string CountryId { get; set; }\n\n#pragma warning restore 1591\n\n /// <summary>\n /// Some countries do not have neither a State, nor a Province\n /// </summary>\n public string StateOrProvinceId { get; set; }\n }\n}\n"
},
{
"answer_id": 35621278,
"author": "Pitka",
"author_id": 3091627,
"author_profile": "https://Stackoverflow.com/users/3091627",
"pm_score": 2,
"selected": false,
"text": "#pragma warning disable 1591\n#pragma warning disable 1591\n#pragma warning disable 1572\n#pragma warning disable 1571\n#pragma warning disable 1573\n#pragma warning disable 1587\n#pragma warning disable 1570\n"
},
{
"answer_id": 41998713,
"author": "Nameless",
"author_id": 4792175,
"author_profile": "https://Stackoverflow.com/users/4792175",
"pm_score": 4,
"selected": false,
"text": "/// <summary>\n/// Description of the class/method/variable\n/// </summary>\n..declaration goes here..\n"
},
{
"answer_id": 44305685,
"author": "Sujeet Singh",
"author_id": 5217876,
"author_profile": "https://Stackoverflow.com/users/5217876",
"pm_score": 1,
"selected": false,
"text": "public EventLogger()\n{\n LogFile = string.Format(\"{0}{1}\", LogFilePath, FileName);\n}\n ///<Summary>\n/// To write a log <Anycomment as per your code>\n///</Summary>\npublic EventLogger()\n{\n LogFile = string.Format(\"{0}{1}\", LogFilePath, FileName);\n}\n"
},
{
"answer_id": 48900635,
"author": "Bill Tarbell",
"author_id": 1721136,
"author_profile": "https://Stackoverflow.com/users/1721136",
"pm_score": 2,
"selected": false,
"text": "/p:NoWarn=1591\n"
},
{
"answer_id": 62948945,
"author": "abdusco",
"author_id": 5298150,
"author_profile": "https://Stackoverflow.com/users/5298150",
"pm_score": 4,
"selected": false,
"text": ".csproj <Project>\n <PropertyGroup>\n ... \n <!--disable missing comment warning-->\n <NoWarn>$(NoWarn);1591</NoWarn>\n </PropertyGroup>\n...\n"
},
{
"answer_id": 68927462,
"author": "MarkD",
"author_id": 5374487,
"author_profile": "https://Stackoverflow.com/users/5374487",
"pm_score": 0,
"selected": false,
"text": " /// <summary>\n /// Creates a Service\n /// </summary>\n /// <param name=\"service\">The Service Definition</param> (**note no cancellation token param**)\n /// <returns>A newly created item</returns>\n /// <response code=\"201\">Returns the newly created service</response>\n /// <response code=\"400\">If there are validation errors with the submitted json body</response>\n /// <response code=\"409\">Conflict. The service already exists</response>\n /// <response code=\"500\">Because life is never perfect</response>\n [ProducesResponseType(typeof(Service), 201)]\n [ProducesResponseType(400)]\n [ProducesResponseType(409)]\n [ProducesResponseType(500)]\n [HttpPost]\n public async Task<ActionResult> ServiceCreate([FromBody] ServicePostRequest service,\n#pragma warning disable 1573 \n CancellationToken cancellationToken = default) //**note: no warning**\n#pragma warning restore 1573\n {\n"
},
{
"answer_id": 72418532,
"author": "Ogglas",
"author_id": 3850405,
"author_profile": "https://Stackoverflow.com/users/3850405",
"pm_score": 0,
"selected": false,
"text": ".editorconfig dotnet_diagnostic.CS1591.severity = none\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
203,890
|
<p>How do I generate an audio sine or square wave of a given frequency?</p>
<p>I am hoping to do this to calibrate equipment, so how precise would these waves be?</p>
|
[
{
"answer_id": 203917,
"author": "Mark Heath",
"author_id": 7532,
"author_profile": "https://Stackoverflow.com/users/7532",
"pm_score": 6,
"selected": true,
"text": "int sampleRate = 8000;\nshort[] buffer = new short[8000];\ndouble amplitude = 0.25 * short.MaxValue;\ndouble frequency = 1000;\nfor (int n = 0; n < buffer.Length; n++)\n{\n buffer[n] = (short)(amplitude * Math.Sin((2 * Math.PI * n * frequency) / sampleRate));\n}\n"
},
{
"answer_id": 19772815,
"author": "Edward",
"author_id": 2953342,
"author_profile": "https://Stackoverflow.com/users/2953342",
"pm_score": 5,
"selected": false,
"text": "MemoryStream MemoryStream System.Media.SoundPlayer using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Windows.Forms;\n\npublic static void PlayBeep(UInt16 frequency, int msDuration, UInt16 volume = 16383)\n{\n var mStrm = new MemoryStream();\n BinaryWriter writer = new BinaryWriter(mStrm);\n\n const double TAU = 2 * Math.PI;\n int formatChunkSize = 16;\n int headerSize = 8;\n short formatType = 1;\n short tracks = 1;\n int samplesPerSecond = 44100;\n short bitsPerSample = 16;\n short frameSize = (short)(tracks * ((bitsPerSample + 7) / 8));\n int bytesPerSecond = samplesPerSecond * frameSize;\n int waveSize = 4;\n int samples = (int)((decimal)samplesPerSecond * msDuration / 1000);\n int dataChunkSize = samples * frameSize;\n int fileSize = waveSize + headerSize + formatChunkSize + headerSize + dataChunkSize;\n // var encoding = new System.Text.UTF8Encoding();\n writer.Write(0x46464952); // = encoding.GetBytes(\"RIFF\")\n writer.Write(fileSize);\n writer.Write(0x45564157); // = encoding.GetBytes(\"WAVE\")\n writer.Write(0x20746D66); // = encoding.GetBytes(\"fmt \")\n writer.Write(formatChunkSize);\n writer.Write(formatType);\n writer.Write(tracks);\n writer.Write(samplesPerSecond);\n writer.Write(bytesPerSecond);\n writer.Write(frameSize);\n writer.Write(bitsPerSample);\n writer.Write(0x61746164); // = encoding.GetBytes(\"data\")\n writer.Write(dataChunkSize);\n {\n double theta = frequency * TAU / (double)samplesPerSecond;\n // 'volume' is UInt16 with range 0 thru Uint16.MaxValue ( = 65 535)\n // we need 'amp' to have the range of 0 thru Int16.MaxValue ( = 32 767)\n double amp = volume >> 2; // so we simply set amp = volume / 2\n for (int step = 0; step < samples; step++)\n {\n short s = (short)(amp * Math.Sin(theta * (double)step));\n writer.Write(s);\n }\n }\n\n mStrm.Seek(0, SeekOrigin.Begin);\n new System.Media.SoundPlayer(mStrm).Play();\n writer.Close();\n mStrm.Close();\n} // public static void PlayBeep(UInt16 frequency, int msDuration, UInt16 volume = 16383)\n"
},
{
"answer_id": 21500396,
"author": "Aleks",
"author_id": 3258422,
"author_profile": "https://Stackoverflow.com/users/3258422",
"pm_score": 3,
"selected": false,
"text": "private void TestSine()\n{\n IntPtr format;\n byte[] data;\n GetSineWave(1000, 100, 44100, -1, out format, out data);\n WaveWriter ww = new WaveWriter(File.Create(@\"d:\\work\\sine.wav\"),\n AudioCompressionManager.FormatBytes(format));\n ww.WriteData(data);\n ww.Close();\n}\n\nprivate void GetSineWave(double freq, int durationMs, int sampleRate, short decibel, out IntPtr format, out byte[] data)\n{\n short max = dB2Short(decibel);//short.MaxValue\n double fs = sampleRate; // sample freq\n int len = sampleRate * durationMs / 1000;\n short[] data16Bit = new short[len];\n for (int i = 0; i < len; i++)\n {\n double t = (double)i / fs; // current time\n data16Bit[i] = (short)(Math.Sin(2 * Math.PI * t * freq) * max);\n }\n IntPtr format1 = AudioCompressionManager.GetPcmFormat(1, 16, (int)fs);\n byte[] data1 = new byte[data16Bit.Length * 2];\n Buffer.BlockCopy(data16Bit, 0, data1, 0, data1.Length);\n format = format1;\n data = data1;\n}\n\nprivate static short dB2Short(double dB)\n{\n double times = Math.Pow(10, dB / 10);\n return (short)(short.MaxValue * times);\n}\n"
},
{
"answer_id": 50389401,
"author": "Declan Taylor",
"author_id": 8201378,
"author_profile": "https://Stackoverflow.com/users/8201378",
"pm_score": 1,
"selected": false,
"text": " Generate.Sinusoidal(15, 1000.0, 100.0, 10.0);\n Generate.Square(...\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5302/"
] |
203,911
|
<p>I am using Java API and XPath to parse my XML. I have XML like this:</p>
<pre><code><animals>
<dog>
<looks>dangerous </looks>
<bites> hard </bites>
<growls> yes </growls>
</dog>
<cat>nothing special</cat>
</animals>
</code></pre>
<p>I would like an XPath condition to print </p>
<pre><code><dog>
<looks>dangerous </looks>
<bites> hard </bites>
<growls> yes </growls>
</dog>
</code></pre>
<p>But I am not able to now. If I use <code>/animal/dog/text()</code> it gives <code>dangerous</code>. But I guess it is used print text alone. Is there a way using XPath condition to fetch a block of XML?</p>
<p><strong>EDIT</strong>:</p>
<p>Thanks a lot for your responses. Appreciate your time spent on this. Is there way to do it in Java without printing the inner text? </p>
<p>Here is where my XPath condition goes:</p>
<pre><code>public static final String XPATH_INPUT_DATA="//text()";
</code></pre>
|
[
{
"answer_id": 204526,
"author": "bortzmeyer",
"author_id": 15625,
"author_profile": "https://Stackoverflow.com/users/15625",
"pm_score": 1,
"selected": false,
"text": "% xpath -e /animals/dog animals.xml \nFound 1 nodes in animals.xml:\n-- NODE --\n<dog>\n <looks>dangerous </looks> \n <bites> hard </bites>\n <growls> yes </growls>\n</dog>\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25458/"
] |
203,912
|
<p>What is the difference between multiprocessor programming and multicore programming?</p>
<p>Preferably show examples in python how to write a small program for multiprocessor programming & multicore programming</p>
|
[
{
"answer_id": 204150,
"author": "Glyph",
"author_id": 13564,
"author_profile": "https://Stackoverflow.com/users/13564",
"pm_score": 7,
"selected": false,
"text": "threading processing multiprocessing subprocess"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20211/"
] |
203,918
|
<p>Been creating a simple program using VBA that I can use to review vocabulary in Chinese.</p>
<p>I've gotten a fair bit working so far, but have run into a huge problem with inputting a macron-character such as "ā" (unicode 257). The specific application I am working on right now involves changing the contents of the text-box form so that an "a" can automatically be replaced as I type into the text box. Such a procedure itself is easy--I can get it to work with the pinyin characters "á" and "à".</p>
<pre><code>Select Case testchar
Case "a"
Mid(strclip, markloc, 1) = "ā"
End Select
</code></pre>
<p>The previous is an attempt at using the Mid function to replace one character in the textbox string with a pinyin character at the appropriate cue from the user.</p>
<p>The hangup is I can't enter the "ā" into VBA! I've been looking around the internet but this doesn't seem like a problem to anyone else. When I am in the VBA editor and I type alt + 0257, nothing happens. I can't copy-paste from notepad either.. I'm about ready to scrap VBA and redo this application in some other language..</p>
<p>Cheers</p>
|
[
{
"answer_id": 203946,
"author": "Ozgur Ozcitak",
"author_id": 976,
"author_profile": "https://Stackoverflow.com/users/976",
"pm_score": 2,
"selected": false,
"text": "Mid(strclip, markloc, 1) = ChrW(257)\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
203,930
|
<p>Kinda long title, but anyways...</p>
<p>I've been looking at these examples, specifically on the parts on writing and reading the size of the message to the byte streams<br>
<a href="http://doc.trolltech.com/4.4/network-fortuneclient-client-cpp.html" rel="nofollow noreferrer">http://doc.trolltech.com/4.4/network-fortuneclient-client-cpp.html</a><br>
<a href="http://doc.trolltech.com/4.4/network-fortuneserver-server-cpp.html" rel="nofollow noreferrer">http://doc.trolltech.com/4.4/network-fortuneserver-server-cpp.html</a></p>
<p>But I can't seem to figure it out in C#.</p>
<pre><code>StreamWriter writer = new StreamWriter(tcpClient.GetStream());
writer.Write(data.Length + data);
</code></pre>
<p>This doesn't work very well at all. Could someone give me a nudge in the right direction?</p>
|
[
{
"answer_id": 203934,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 1,
"selected": false,
"text": "data.Length writer.Write(chr(data.Length) + data);\n"
},
{
"answer_id": 203962,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 3,
"selected": true,
"text": " byte[] data = ...\n int len = data.Length;\n byte[] prefix = Bitconverter.GetBytes(len);\n stream.Write(prefix, 0, prefix.Length); // fixed 4 bytes\n stream.Write(data, 0, data.Length);\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203930",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15067/"
] |
203,969
|
<p>How do you get an instance of the actionscript class <code>Class</code> from an instance of that class?</p>
<p>In Python, this would be <code>x.__class__</code>; in Java, <code>x.getClass();</code>.</p>
<p>I'm aware that <a href="http://actionscript.org/forums/showthread.php3?t=120135#td_post_545693" rel="noreferrer">certain terrible hacks</a> exist to do this, but I'm looking for a built-in language facility, or at least a library routine built on something reliable.</p>
|
[
{
"answer_id": 204003,
"author": "fenomas",
"author_id": 10651,
"author_profile": "https://Stackoverflow.com/users/10651",
"pm_score": 4,
"selected": false,
"text": "var s:Sprite = new flash.display.Sprite();\n\nvar className:String = flash.utils.getQualifiedClassName( s );\nvar myClass:Class = flash.utils.getDefinitionByName( className ) as Class;\n\ntrace(className ); // flash.display::Sprite\ntrace(myClass); // [class Sprite]\n\nvar s2 = new myClass();\ntrace(s2); // [object Sprite]\n"
},
{
"answer_id": 204006,
"author": "Gerald",
"author_id": 19404,
"author_profile": "https://Stackoverflow.com/users/19404",
"pm_score": 7,
"selected": true,
"text": "var myClass:Class = Object(myObj).constructor;\n"
},
{
"answer_id": 9152781,
"author": "iND",
"author_id": 516537,
"author_profile": "https://Stackoverflow.com/users/516537",
"pm_score": 4,
"selected": false,
"text": "int var sprite:Sprite = new Sprite();\nvar xml:XML = new XML();\nvar testInt:int = 2;\nvar testClass:TestClass = new TestClass();\nvar testAnon:Object = {};\n\ntrace(\"classname 1 = \" + getQualifiedClassName(sprite));\ntrace(\"myclass 1 = \" + getDefinitionByName(getQualifiedClassName(sprite)));\ntrace(\"constructor a 1 = \" + Object(sprite).constructor);\ntrace(\"constructor a 1 = \" + (Object(sprite).constructor as Class));\ntrace(\"constructor b 1 = \" + sprite[\"constructor\"]);\ntrace(\"constructor b 1 = \" + (sprite[\"constructor\"] as Class));\ntrace(\"...\");\ntrace(\"classname 2 = \" + getQualifiedClassName(xml));\ntrace(\"myclass 2 = \" + getDefinitionByName(getQualifiedClassName(xml)));\ntrace(\"constructor a 2 = \" + Object(xml).constructor);\ntrace(\"constructor a 2 = \" + (Object(xml).constructor as Class));\ntrace(\"constructor b 2 = \" + xml[\"constructor\"]);\ntrace(\"constructor b 2 = \" + (xml[\"constructor\"] as Class));\ntrace(\"...\");\ntrace(\"classname 3 = \" + getQualifiedClassName(testInt));\ntrace(\"myclass 3 = \" + getDefinitionByName(getQualifiedClassName(testInt)));\ntrace(\"constructor a 3 = \" + Object(testInt).constructor);\ntrace(\"constructor a 3 = \" + (Object(testInt).constructor as Class));\ntrace(\"constructor b 3 = \" + testInt[\"constructor\"]);\ntrace(\"constructor b 3 = \" + (testInt[\"constructor\"] as Class));\ntrace(\"...\");\ntrace(\"classname 4 = \" + getQualifiedClassName(testClass));\ntrace(\"myclass 4 = \" + getDefinitionByName(getQualifiedClassName(testClass)));\ntrace(\"constructor a 4 = \" + Object(testClass).constructor);\ntrace(\"constructor a 4 = \" + (Object(testClass).constructor as Class));\ntrace(\"constructor b 4 = \" + testClass[\"constructor\"]);\ntrace(\"constructor b 4 = \" + (testClass[\"constructor\"] as Class));\ntrace(\"...\");\ntrace(\"classname 5 = \" + getQualifiedClassName(testAnon));\ntrace(\"myclass 5 = \" + getDefinitionByName(getQualifiedClassName(testAnon)));\ntrace(\"constructor a 5 = \" + Object(testAnon).constructor);\ntrace(\"constructor a 5 = \" + (Object(testAnon).constructor as Class));\ntrace(\"constructor b 5 = \" + testAnon[\"constructor\"]);\ntrace(\"constructor b 5 = \" + (testAnon[\"constructor\"] as Class));\ntrace(\"...\");\n TestClass package\n{\n public class TestClass\n {\n }\n}\n classname 1 = flash.display::Sprite\nmyclass 1 = [class Sprite]\nconstructor a 1 = [class Sprite]\nconstructor a 1 = [class Sprite]\nconstructor b 1 = [class Sprite]\nconstructor b 1 = [class Sprite]\n...\nclassname 2 = XML\nmyclass 2 = [class XML]\nconstructor a 2 = \nconstructor a 2 = null\nconstructor b 2 = \nconstructor b 2 = null\n...\nclassname 3 = int\nmyclass 3 = [class int]\nconstructor a 3 = [class Number]\nconstructor a 3 = [class Number]\nconstructor b 3 = [class Number]\nconstructor b 3 = [class Number]\n...\nclassname 4 = src::TestClass\nmyclass 4 = [class TestClass]\nconstructor a 4 = [class TestClass]\nconstructor a 4 = [class TestClass]\nconstructor b 4 = [class TestClass]\nconstructor b 4 = [class TestClass]\n...\nclassname 5 = Object\nmyclass 5 = [class Object]\nconstructor a 5 = [class Object]\nconstructor a 5 = [class Object]\nconstructor b 5 = [class Object]\nconstructor b 5 = [class Object]\n...\n getDefinitionByName constructor getDefinitionByName uint int int getDefinitionByName"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13564/"
] |
203,984
|
<p>I have an <code>ArrayList<String></code>, and I want to remove repeated strings from it. How can I do this?</p>
|
[
{
"answer_id": 203992,
"author": "jonathan-stafford",
"author_id": 27587,
"author_profile": "https://Stackoverflow.com/users/27587",
"pm_score": 11,
"selected": true,
"text": "Collection Collection Set Set ArrayList Set<String> set = new HashSet<>(yourList);\nyourList.clear();\nyourList.addAll(set);\n ArrayList"
},
{
"answer_id": 203997,
"author": "Benno Richters",
"author_id": 3565,
"author_profile": "https://Stackoverflow.com/users/3565",
"pm_score": 6,
"selected": false,
"text": "List List Set // list is some List of Strings\nSet<String> s = new HashSet<String>(list);\n Set List"
},
{
"answer_id": 204004,
"author": "abahgat",
"author_id": 27565,
"author_profile": "https://Stackoverflow.com/users/27565",
"pm_score": 8,
"selected": false,
"text": "ArrayList HashSet // list is some List of Strings\nSet<String> s = new LinkedHashSet<>(list);\n List"
},
{
"answer_id": 215212,
"author": "volley",
"author_id": 13905,
"author_profile": "https://Stackoverflow.com/users/13905",
"pm_score": 4,
"selected": false,
"text": "public static <T> void removeDuplicates(ArrayList<T> list) {\n int size = list.size();\n int out = 0;\n {\n final Set<T> encountered = new HashSet<T>();\n for (int in = 0; in < size; in++) {\n final T t = list.get(in);\n final boolean first = encountered.add(t);\n if (first) {\n list.set(out++, t);\n }\n }\n }\n while (out < size) {\n list.remove(--size);\n }\n}\n public static <T> void removeDuplicates(LinkedList<T> list) {\n final Set<T> encountered = new HashSet<T>();\n for (Iterator<T> iter = list.iterator(); iter.hasNext(); ) {\n final T t = iter.next();\n final boolean first = encountered.add(t);\n if (!first) {\n iter.remove();\n }\n }\n}\n public static <T> void removeDuplicates(List<T> list) {\n if (list instanceof RandomAccess) {\n // use first version here\n } else {\n // use other version here\n }\n}\n"
},
{
"answer_id": 4547382,
"author": "stbn",
"author_id": 554467,
"author_profile": "https://Stackoverflow.com/users/554467",
"pm_score": 5,
"selected": false,
"text": "ArrayList l1 = new ArrayList();\nArrayList l2 = new ArrayList();\n\nIterator iterator = l1.iterator();\n\nwhile (iterator.hasNext()) {\n YourClass o = (YourClass) iterator.next();\n if(!l2.contains(o)) l2.add(o);\n}\n"
},
{
"answer_id": 5618571,
"author": "HarpyWar",
"author_id": 701779,
"author_profile": "https://Stackoverflow.com/users/701779",
"pm_score": 2,
"selected": false,
"text": " ArrayList< Integer > al = new ArrayList< Integer >(); \n\n // fill 1 \n for ( int i = 0; i <= 5; i++ ) \n if ( !al.contains( i ) ) \n al.add( i ); \n\n // fill 2 \n for (int i = 0; i <= 10; i++ ) \n if ( !al.contains( i ) ) \n al.add( i ); \n\n for( Integer i: al )\n {\n System.out.print( i + \" \"); \n }\n"
},
{
"answer_id": 8452741,
"author": "Timofey Gorshkov",
"author_id": 274205,
"author_profile": "https://Stackoverflow.com/users/274205",
"pm_score": 4,
"selected": false,
"text": "ImmutableSet ImmutableSet.copyOf(list);\n"
},
{
"answer_id": 8962127,
"author": "Ghyour",
"author_id": 1163576,
"author_profile": "https://Stackoverflow.com/users/1163576",
"pm_score": 2,
"selected": false,
"text": "for(int a=0;a<myArray.size();a++){\n for(int b=a+1;b<myArray.size();b++){\n if(myArray.get(a).equalsIgnoreCase(myArray.get(b))){\n myArray.remove(b); \n dups++;\n b--;\n }\n }\n}\n"
},
{
"answer_id": 12665409,
"author": "reddy",
"author_id": 1710433,
"author_profile": "https://Stackoverflow.com/users/1710433",
"pm_score": 0,
"selected": false,
"text": "import java.util.*;\nclass RemoveDupFrmString\n{\n public static void main(String[] args)\n {\n\n String s=\"appsc\";\n\n Set<Character> unique = new LinkedHashSet<Character> ();\n\n for(char c : s.toCharArray()) {\n\n System.out.println(unique.add(c));\n }\n for(char dis:unique){\n System.out.println(dis);\n }\n\n\n }\n}\n"
},
{
"answer_id": 14126093,
"author": "user1912383",
"author_id": 1912383,
"author_profile": "https://Stackoverflow.com/users/1912383",
"pm_score": 1,
"selected": false,
"text": "String[] arr2 = {\"5\",\"1\",\"2\",\"3\",\"3\",\"4\",\"1\",\"2\"};\nSet<String> set = new LinkedHashSet<String>(Arrays.asList(arr2));\nfor(String s1 : set)\n System.out.println(s1);\n\nSystem.out.println( \"------------------------\" );\nString[] arr3 = set.toArray(new String[0]);\nfor(int i = 0; i < arr3.length; i++)\n System.out.println(arr3[i].toString());\n"
},
{
"answer_id": 18504616,
"author": "Harsha",
"author_id": 2706817,
"author_profile": "https://Stackoverflow.com/users/2706817",
"pm_score": 0,
"selected": false,
"text": "public Set<Object> findDuplicates(List<Object> list) {\n Set<Object> items = new HashSet<Object>();\n Set<Object> duplicates = new HashSet<Object>();\n for (Object item : list) {\n if (items.contains(item)) {\n duplicates.add(item);\n } else { \n items.add(item);\n } \n } \n return duplicates;\n }\n"
},
{
"answer_id": 19305534,
"author": "user2868724",
"author_id": 2868724,
"author_profile": "https://Stackoverflow.com/users/2868724",
"pm_score": 5,
"selected": false,
"text": "private List<SomeClass> clearListFromDuplicateFirstName(List<SomeClass> list1) {\n\n Map<String, SomeClass> cleanMap = new LinkedHashMap<String, SomeClass>();\n for (int i = 0; i < list1.size(); i++) {\n cleanMap.put(list1.get(i).getFirstName(), list1.get(i));\n }\n List<SomeClass> list = new ArrayList<SomeClass>(cleanMap.values());\n return list;\n}\n"
},
{
"answer_id": 19334383,
"author": "ram",
"author_id": 2071911,
"author_profile": "https://Stackoverflow.com/users/2071911",
"pm_score": 2,
"selected": false,
"text": "LinkedHashSet link=new LinkedHashSet();\nList listOfValues=new ArrayList();\nlistOfValues.add(link);\n"
},
{
"answer_id": 19434592,
"author": "CarlJohn",
"author_id": 369035,
"author_profile": "https://Stackoverflow.com/users/369035",
"pm_score": 4,
"selected": false,
"text": " ArrayList<String> lst = new ArrayList<String>();\n lst.add(\"ABC\");\n lst.add(\"ABC\");\n lst.add(\"ABCD\");\n lst.add(\"ABCD\");\n lst.add(\"ABCE\");\n\n System.out.println(\"Duplicates List \"+lst);\n\n Object[] st = lst.toArray();\n for (Object s : st) {\n if (lst.indexOf(s) != lst.lastIndexOf(s)) {\n lst.remove(lst.lastIndexOf(s));\n }\n }\n\n System.out.println(\"Distinct List \"+lst);\n Duplicates List [ABC, ABC, ABCD, ABCD, ABCE]\nDistinct List [ABC, ABCD, ABCE]\n"
},
{
"answer_id": 23177411,
"author": "Vitalii Fedorenko",
"author_id": 288671,
"author_profile": "https://Stackoverflow.com/users/288671",
"pm_score": 7,
"selected": false,
"text": "List<String> deduped = list.stream().distinct().collect(Collectors.toList());\n"
},
{
"answer_id": 24205781,
"author": "SparkOn",
"author_id": 3282808,
"author_profile": "https://Stackoverflow.com/users/3282808",
"pm_score": 0,
"selected": false,
"text": " ArrayList<String> list = new ArrayList<String>();\n HashSet<String> unique = new LinkedHashSet<String>();\n HashSet<String> dup = new LinkedHashSet<String>();\n boolean b = false;\n list.add(\"Hello\");\n list.add(\"Hello\");\n list.add(\"how\");\n list.add(\"are\");\n list.add(\"u\");\n list.add(\"u\");\n\n for(Iterator iterator= list.iterator();iterator.hasNext();)\n {\n String value = (String)iterator.next();\n System.out.println(value);\n\n if(b==unique.add(value))\n dup.add(value);\n else\n unique.add(value);\n\n\n }\n System.out.println(unique);\n System.out.println(dup);\n"
},
{
"answer_id": 25780946,
"author": "Thananjayan N",
"author_id": 4029759,
"author_profile": "https://Stackoverflow.com/users/4029759",
"pm_score": 0,
"selected": false,
"text": "public static Object[] removeDuplicate(Object[] inputArray)\n{\n long startTime = System.nanoTime();\n int totalSize = inputArray.length;\n Object[] resultArray = new Object[totalSize];\n int newSize = 0;\n for(int i=0; i<totalSize; i++)\n {\n Object value = inputArray[i];\n if(value == null)\n {\n continue;\n }\n\n for(int j=i+1; j<totalSize; j++)\n {\n if(value.equals(inputArray[j]))\n {\n inputArray[j] = null;\n }\n }\n resultArray[newSize++] = value;\n }\n\n long endTime = System.nanoTime()-startTime;\n System.out.println(\"Total Time-B:\"+endTime);\n return resultArray;\n}\n"
},
{
"answer_id": 27356461,
"author": "M Kaweepatt Churcharoen",
"author_id": 1516571,
"author_profile": "https://Stackoverflow.com/users/1516571",
"pm_score": 2,
"selected": false,
"text": "List<Entity> entities = repository.findByUserId(userId);\n\nSet<Entity> s = new LinkedHashSet<Entity>(entities);\nentities.clear();\nentities.addAll(s);\n"
},
{
"answer_id": 28987005,
"author": "sambhu",
"author_id": 4435902,
"author_profile": "https://Stackoverflow.com/users/4435902",
"pm_score": 2,
"selected": false,
"text": "List<String> duplicatList = new ArrayList<String>();\nduplicatList = Arrays.asList(\"AA\",\"BB\",\"CC\",\"DD\",\"DD\",\"EE\",\"AA\",\"FF\");\n//above AA and DD are duplicate\nSet<String> uniqueList = new HashSet<String>(duplicatList);\nduplicatList = new ArrayList<String>(uniqueList); //let GC will doing free memory\nSystem.out.println(\"Removed Duplicate : \"+duplicatList);\n"
},
{
"answer_id": 31160570,
"author": "sharkbait",
"author_id": 1353274,
"author_profile": "https://Stackoverflow.com/users/1353274",
"pm_score": 0,
"selected": false,
"text": "public static <T> void removeDuplicate(List <T> list) {\nSet <T> set = new HashSet <T>();\nList <T> newList = new ArrayList <T>();\nfor (Iterator <T>iter = list.iterator(); iter.hasNext(); ) {\n Object element = iter.next();\n if (set.add((T) element))\n newList.add((T) element);\n }\n list.clear();\n list.addAll(newList);\n}\n"
},
{
"answer_id": 31770675,
"author": "siva",
"author_id": 5182491,
"author_profile": "https://Stackoverflow.com/users/5182491",
"pm_score": 1,
"selected": false,
"text": " List<String> result = new ArrayList<String>();\n Set<String> set = new LinkedHashSet<String>();\n String s = \"ravi is a good!boy. But ravi is very nasty fellow.\";\n StringTokenizer st = new StringTokenizer(s, \" ,. ,!\");\n while (st.hasMoreTokens()) {\n result.add(st.nextToken());\n }\n System.out.println(result);\n set.addAll(result);\n result.clear();\n result.addAll(set);\n System.out.println(result);\n\noutput:\n[ravi, is, a, good, boy, But, ravi, is, very, nasty, fellow]\n[ravi, is, a, good, boy, But, very, nasty, fellow]\n"
},
{
"answer_id": 31971798,
"author": "infoj",
"author_id": 4851359,
"author_profile": "https://Stackoverflow.com/users/4851359",
"pm_score": 5,
"selected": false,
"text": " List<String> cityList = new ArrayList<>();\n cityList.add(\"Delhi\");\n cityList.add(\"Mumbai\");\n cityList.add(\"Bangalore\");\n cityList.add(\"Chennai\");\n cityList.add(\"Kolkata\");\n cityList.add(\"Mumbai\");\n\n cityList = cityList.stream().distinct().collect(Collectors.toList());\n"
},
{
"answer_id": 32680600,
"author": "Manash Ranjan Dakua",
"author_id": 4879651,
"author_profile": "https://Stackoverflow.com/users/4879651",
"pm_score": 4,
"selected": false,
"text": "public static void main(String[] args){\n ArrayList<Object> al = new ArrayList<Object>();\n al.add(\"abc\");\n al.add('a');\n al.add('b');\n al.add('a');\n al.add(\"abc\");\n al.add(10.3);\n al.add('c');\n al.add(10);\n al.add(\"abc\");\n al.add(10);\n System.out.println(\"Before Duplicate Remove:\"+al);\n for(int i=0;i<al.size();i++){\n for(int j=i+1;j<al.size();j++){\n if(al.get(i).equals(al.get(j))){\n al.remove(j);\n j--;\n }\n }\n }\n System.out.println(\"After Removing duplicate:\"+al);\n}\n"
},
{
"answer_id": 32735976,
"author": "neo7",
"author_id": 1982580,
"author_profile": "https://Stackoverflow.com/users/1982580",
"pm_score": 0,
"selected": false,
"text": "public static <T> ArrayList<T> uniquefy(ArrayList<T> myList) {\n\n ArrayList <T> uniqueArrayList = new ArrayList<T>();\n for (int i = 0; i < myList.size(); i++){\n if (!uniqueArrayList.contains(myList.get(i))){\n uniqueArrayList.add(myList.get(i));\n }\n }\n\n return uniqueArrayList;\n}\n"
},
{
"answer_id": 33751322,
"author": "satish",
"author_id": 5281441,
"author_profile": "https://Stackoverflow.com/users/5281441",
"pm_score": -1,
"selected": false,
"text": "public static void main(String[] args) {\n List<String> l = new ArrayList<String>();\n l.add(\"A\");\n l.add(\"B\");\n l.add(\"C\");\n l.add(\"A\");\n System.out.println(\"Before removing duplicates: \");\n for (String s : l) {\n System.out.println(s);\n }\n Set<String> set = new HashSet<String>(l);\n List<String> newlist = new ArrayList<String>(set);\n System.out.println(\"after removing duplicates: \");\n for (String s : newlist) {\n System.out.println(s);\n }\n }\n"
},
{
"answer_id": 34033817,
"author": "Ravi Vital",
"author_id": 5628310,
"author_profile": "https://Stackoverflow.com/users/5628310",
"pm_score": 0,
"selected": false,
"text": "public static void removeDuplicates(ArrayList<String> list) {\n Arraylist<Object> ar = new Arraylist<Object>();\n Arraylist<Object> tempAR = new Arraylist<Object>();\n while (list.size()>0){\n ar.add(list(0));\n list.removeall(Collections.singleton(list(0)));\n }\n list.addAll(ar);\n}\n"
},
{
"answer_id": 34204842,
"author": "Craig P. Motlin",
"author_id": 23572,
"author_profile": "https://Stackoverflow.com/users/23572",
"pm_score": 3,
"selected": false,
"text": "distinct() ListIterable<Integer> integers = FastList.newListWith(1, 3, 1, 2, 2, 1);\nAssert.assertEquals(\n FastList.newListWith(1, 3, 2),\n integers.distinct());\n distinct() distinct() MutableSet<T> seenSoFar = UnifiedSet.newSet();\nint size = list.size();\nfor (int i = 0; i < size; i++)\n{\n T item = list.get(i);\n if (seenSoFar.add(item))\n {\n targetCollection.add(item);\n }\n}\nreturn targetCollection;\n MutableList<Integer> distinct = ListAdapter.adapt(integers).distinct();\n"
},
{
"answer_id": 36234085,
"author": "Hardip",
"author_id": 5018911,
"author_profile": "https://Stackoverflow.com/users/5018911",
"pm_score": 2,
"selected": false,
"text": "ArrayList<String> city=new ArrayList<String>();\ncity.add(\"rajkot\");\ncity.add(\"gondal\");\ncity.add(\"rajkot\");\ncity.add(\"gova\");\ncity.add(\"baroda\");\ncity.add(\"morbi\");\ncity.add(\"gova\");\n\nHashSet<String> hashSet = new HashSet<String>();\nhashSet.addAll(city);\ncity.clear();\ncity.addAll(hashSet);\nToast.makeText(getActivity(),\"\" + city.toString(),Toast.LENGTH_SHORT).show();\n"
},
{
"answer_id": 37405769,
"author": "akhil_mittal",
"author_id": 1216775,
"author_profile": "https://Stackoverflow.com/users/1216775",
"pm_score": 6,
"selected": false,
"text": "String List<String> strList = new ArrayList<>(5);\n// insert up to five items to list. \n List<String> deDupStringList = new ArrayList<>(new HashSet<>(strList));\n LinkedHashSet HashSet List<String> deDupStringList2 = Lists.newArrayList(Sets.newHashSet(strList));\n List<String> deDupStringList3 = strList.stream().distinct().collect(Collectors.toList());\n LinkedList List<String> deDupStringList3 = strList.stream().distinct()\n .collect(Collectors.toCollection(LinkedList::new));\n parallelStream"
},
{
"answer_id": 40419515,
"author": "Nenad Bulatović",
"author_id": 1159404,
"author_profile": "https://Stackoverflow.com/users/1159404",
"pm_score": 5,
"selected": false,
"text": "// delete duplicates (if any) from 'myArrayList'\nmyArrayList = new ArrayList<String>(new LinkedHashSet<String>(myArrayList));\n"
},
{
"answer_id": 43025730,
"author": "Gujjula Ramesh Reddy",
"author_id": 6128908,
"author_profile": "https://Stackoverflow.com/users/6128908",
"pm_score": 1,
"selected": false,
"text": " public List<Contact> removeDuplicates(List<Contact> list) {\n // Set set1 = new LinkedHashSet(list);\n Set set = new TreeSet(new Comparator() {\n\n @Override\n public int compare(Object o1, Object o2) {\n if (((Contact) o1).getId().equalsIgnoreCase(((Contact) o2).getId()) /*&&\n ((Contact)o1).getName().equalsIgnoreCase(((Contact)o2).getName())*/) {\n return 0;\n }\n return 1;\n }\n });\n set.addAll(list);\n\n final List newList = new ArrayList(set);\n return newList;\n}\n"
},
{
"answer_id": 47580485,
"author": "HamidReza",
"author_id": 767555,
"author_profile": "https://Stackoverflow.com/users/767555",
"pm_score": 2,
"selected": false,
"text": "ArrayList<Class1> l1 = new ArrayList<Class1>();\nArrayList<Class1> l2 = new ArrayList<Class1>();\n\n Iterator iterator1 = l1.iterator();\n boolean repeated = false;\n\n while (iterator1.hasNext())\n {\n Class1 c1 = (Class1) iterator1.next();\n for (Class1 _c: l2) {\n if(_c.getId() == c1.getId())\n repeated = true;\n }\n if(!repeated)\n l2.add(c1);\n }\n"
},
{
"answer_id": 50253949,
"author": "Saurabh Gaddelpalliwar",
"author_id": 4019233,
"author_profile": "https://Stackoverflow.com/users/4019233",
"pm_score": 3,
"selected": false,
"text": "for (int i = 0; i < Models.size(); i++){\nfor (int j = i + 1; j < Models.size(); j++) { \n if (Models.get(i).getName().equals(Models.get(j).getName())) { \n Models.remove(j);\n j--;\n }\n }\n}\n"
},
{
"answer_id": 50382676,
"author": "Sameer Shrestha",
"author_id": 7044810,
"author_profile": "https://Stackoverflow.com/users/7044810",
"pm_score": 0,
"selected": false,
"text": "private static void removeDup(ArrayList<String> listWithDuplicateElements) {\n System.out.println(\" Original Duplicate List :\" + listWithDuplicateElements);\n List<String> listWithoutDuplicateElements = new ArrayList<>(listWithDuplicateElements.size());\n\n listWithDuplicateElements.stream().forEach(str -> {\n if (listWithoutDuplicateElements.indexOf(str) == -1) {\n listWithoutDuplicateElements.add(str);\n }\n }); \n\n System.out.println(\" Without Duplicate List :\" + listWithoutDuplicateElements);\n}\n"
},
{
"answer_id": 51181971,
"author": "seekingStillness",
"author_id": 6592058,
"author_profile": "https://Stackoverflow.com/users/6592058",
"pm_score": 0,
"selected": false,
"text": " public static ArrayList<String> removeDuplicates (ArrayList<String> arrayList){\n if (arrayList.isEmpty()) return null; //return what makes sense for your app\n Collections.sort(arrayList, String.CASE_INSENSITIVE_ORDER);\n //remove duplicates\n ArrayList <String> arrayList_mod = new ArrayList<>();\n arrayList_mod.add(arrayList.get(0));\n for (int i=1; i<arrayList.size(); i++){\n if (!arrayList.get(i).equals(arrayList.get(i-1))) arrayList_mod.add(arrayList.get(i));\n }\n return arrayList_mod;\n}\n"
},
{
"answer_id": 54595465,
"author": "saif",
"author_id": 7208392,
"author_profile": "https://Stackoverflow.com/users/7208392",
"pm_score": 0,
"selected": false,
"text": "Set<String> strSet = strList.stream().collect(Collectors.toSet());\n"
},
{
"answer_id": 55073204,
"author": "LiNKeR",
"author_id": 10138416,
"author_profile": "https://Stackoverflow.com/users/10138416",
"pm_score": 0,
"selected": false,
"text": "public static class HashList<T> extends ArrayList<T>{\n private HashMap <T,T> hashMap;\n public HashList(){\n hashMap=new HashMap<>();\n }\n\n @Override\n public boolean add(T t){\n if(hashMap.get(t)==null){\n hashMap.put(t,t);\n return super.add(t);\n }else return false;\n }\n\n @Override\n public boolean addAll(Collection<? extends T> c){\n HashList<T> addup=(HashList<T>)c;\n for(int i=0;i<addup.size();i++){\n add(addup.get(i));\n }return true;\n }\n\n }\n Usage Example: HashList<String> hashlist=new HashList<>();\nhashList.add(\"hello\");\nhashList.add(\"hello\");\nSystem.out.println(\" HashList: \"+hashlist);\n"
},
{
"answer_id": 69499989,
"author": "Gil SH",
"author_id": 880223,
"author_profile": "https://Stackoverflow.com/users/880223",
"pm_score": 0,
"selected": false,
"text": "public static <T> List<T> clearDuplicates(List<T> messages,Comparator<T> comparator) {\n List<T> results = new ArrayList<T>();\n for (T m1 : messages) {\n boolean found = false;\n for (T m2 : results) {\n if (comparator.compare(m1,m2)==0) {\n found=true;\n break;\n }\n }\n if (!found) {\n results.add(m1);\n }\n }\n return results;\n}\n"
},
{
"answer_id": 71637149,
"author": "Kirguduck",
"author_id": 8619606,
"author_profile": "https://Stackoverflow.com/users/8619606",
"pm_score": 0,
"selected": false,
"text": "val list = listOf('a', 'A', 'b', 'B', 'A', 'a')\nprintln(list.distinct()) // [a, A, b, B]\nprintln(list.distinctBy { it.uppercaseChar() }) // [a, b]\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25778/"
] |
203,990
|
<p>I'm writing a C++ client which is using libcurl for communicating with a PHP script.</p>
<p>The communication should be session based, and thus the first task is to login and make the PHP script set up a session.</p>
<p>I'm not used to working with sessions either from C++ or PHP. I basically know that it has to do with cookies and communicating session id.</p>
<p>I can't find any example on the curl homepage which demonstrates a simple session management use case.</p>
<p>I'm assuming it has something to do with one or many of the following options in curl:</p>
<pre><code>CURLOPT_COOKIE
CURLOPT_COOKIEFILE
CURLOPT_COOKIEJAR
CURLOPT_COOKIESESSION
CURLOPT_COOKIELIST
</code></pre>
<p>But I can't really see the big picture just from the documentation of CURLOPT_COOKIESESSION for instance.</p>
<p>Anybody who has done this, please share a simple piece of code which shows the concept.</p>
<p>Regards</p>
<p>Robert</p>
|
[
{
"answer_id": 204357,
"author": "Tometzky",
"author_id": 15862,
"author_profile": "https://Stackoverflow.com/users/15862",
"pm_score": 1,
"selected": false,
"text": "#!/bin/bash\n\nPHPMYADMINURL=\"http://www.example.com/phpmyadmin/\"\n\n# Username and password, has to be URL-encoded\nMYUSERNAME=\"username\"\nMYPASSWORD=\"password\"\n\nTMPCOOKIES=\"$(mktemp)\" || exit 1\n\nTOKEN=$(\n curl \\\n --silent \\\n --show-error \\\n --data @- \\\n --data \"lang=en-utf-8\" \\\n --cookie-jar \"$TMPCOOKIES\" \\\n --dump-header - \\\n --url \"$PHPMYADMINURL\" \\\n <<< \"pma_username=$MYUSERNAME&pma_password=$MYPASSWORD\" \\\n | egrep 'token=[0-9a-h]+' \\\n | head -1 \\\n | sed -r 's/^(.*token=)([0-9a-h]+)(.*)/\\2/' \\\n ) || exit 1\n\ncurl \\\n --cookie \"$TMPCOOKIES\" \\\n --data \"token=$TOKEN\" \\\n --data \"export_type=server\" \\\n --data \"what=sql\" \\\n --data \"asfile=sendit\" \\\n --data \"sql_data=something\" \\\n --data \"sql_columns=something\" \\\n --data \"sql_hex_for_blob=something\" \\\n --data \"compression=gzip\" \\\n --url \"$PHPMYADMINURL\"export.php 1>&2 || exit 1\n\nrm -f \"$TMPCOOKIES\" || exit 1\n"
},
{
"answer_id": 205417,
"author": "pk.",
"author_id": 10615,
"author_profile": "https://Stackoverflow.com/users/10615",
"pm_score": 3,
"selected": true,
"text": "CURL *Handle = curl_easy_init();\n\n// Read cookies from a previous session, as stored in MyCookieFileName.\ncurl_easy_setopt( Handle, CURLOPT_COOKIEFILE, MyCookieFileName );\n// Save cookies from *this* session in MyCookieFileName\ncurl_easy_setopt( Handle, CURLOPT_COOKIEJAR, MyCookieFileName );\n\ncurl_easy_setopt( Handle, CURLOPT_URL, MyLoginPageUrl );\nassert( curl_easy_perform( Handle ) == CURLE_OK );\n\ncurl_easy_setopt( Handle, CURLOPT_URL, MyActionPageUrl );\nassert( curl_easy_perform( Handle ) == CURLE_OK );\n\n// The cookies are actually saved here.\ncurl_easy_cleanup( Handle );\n curl_easy_setopt( Handle, CURLOPT_COOKIEFILE, \"\" );\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/203990",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7891/"
] |
204,007
|
<p>I get this error:-</p>
<p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' at line 1</p>
<p>whenever I tried something like this:-</p>
<pre><code>mysql> source /home/user1/sql/ddl.sql
mysql> source /home/user1/sql/insert.sql
mysql> source /home/user1/sql/cleanup.sql
</code></pre>
<p>The intresting thing is, this happen to each and every one of the sql scripts but only the first statement is corrupted. The rest of the statements in the script will run fine. I have worked around this by putting a dummy statement in every script.</p>
<p>Anyone had this problem before? I am completely stumped and checking Google hadn't helped yet. Thanks in advance.</p>
|
[
{
"answer_id": 204022,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 4,
"selected": true,
"text": ":set nobomb\n :x!\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18500/"
] |
204,010
|
<p>how can i figure out the last modified date of a html file im importing into my web app?</p>
<p>The html file is on another server and different users can make updates, when i retrieve the page i want to be able see when it was last updated so i can label the updated date on my homepage. I</p>
|
[
{
"answer_id": 204021,
"author": "michaeljoseph",
"author_id": 5549,
"author_profile": "https://Stackoverflow.com/users/5549",
"pm_score": 3,
"selected": false,
"text": "document.lastModified"
},
{
"answer_id": 204028,
"author": "Node",
"author_id": 7190,
"author_profile": "https://Stackoverflow.com/users/7190",
"pm_score": 2,
"selected": false,
"text": " Last-Modified = \"Last-Modified\" \":\" HTTP-date\n"
},
{
"answer_id": 204029,
"author": "dogbane",
"author_id": 7412,
"author_profile": "https://Stackoverflow.com/users/7412",
"pm_score": 2,
"selected": false,
"text": "<script type=\"text/javascript\">\n<!--\ndocument.write(document.lastModified);\n// -->\n</script>\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24481/"
] |
204,017
|
<p>I have a Python script that needs to execute an external program, but for some reason fails.</p>
<p>If I have the following script:</p>
<pre><code>import os;
os.system("C:\\Temp\\a b c\\Notepad.exe");
raw_input();
</code></pre>
<p>Then it fails with the following error:</p>
<blockquote>
<p>'C:\Temp\a' is not recognized as an internal or external command, operable program or batch file.</p>
</blockquote>
<p>If I escape the program with quotes:</p>
<pre><code>import os;
os.system('"C:\\Temp\\a b c\\Notepad.exe"');
raw_input();
</code></pre>
<p>Then it works. However, if I add a parameter, it stops working again:</p>
<pre><code>import os;
os.system('"C:\\Temp\\a b c\\Notepad.exe" "C:\\test.txt"');
raw_input();
</code></pre>
<p>What is the right way to execute a program and wait for it to complete? I do not need to read output from it, as it is a visual program that does a job and then just exits, but I need to wait for it to complete.</p>
<p>Also note, moving the program to a non-spaced path is not an option either.</p>
<hr>
<p>This does not work either:</p>
<pre><code>import os;
os.system("'C:\\Temp\\a b c\\Notepad.exe'");
raw_input();
</code></pre>
<p>Note the swapped single/double quotes.</p>
<p>With or without a parameter to Notepad here, it fails with the error message</p>
<blockquote>
<p>The filename, directory name, or volume label syntax is incorrect.</p>
</blockquote>
|
[
{
"answer_id": 204024,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 2,
"selected": false,
"text": "import os;\nos.system(\"\\\"C:\\\\Temp\\\\a b c\\\\Notepad.exe\\\" C:\\\\test.txt\");\n"
},
{
"answer_id": 204049,
"author": "Brian",
"author_id": 9493,
"author_profile": "https://Stackoverflow.com/users/9493",
"pm_score": 9,
"selected": true,
"text": "subprocess.call import subprocess\nsubprocess.call(['C:\\\\Temp\\\\a b c\\\\Notepad.exe', 'C:\\\\test.txt'])\n"
},
{
"answer_id": 206215,
"author": "user16738",
"author_id": 16738,
"author_profile": "https://Stackoverflow.com/users/16738",
"pm_score": 6,
"selected": false,
"text": "filepath = 'textfile.txt'\nimport os\nos.startfile(filepath)\n import os\nos.startfile('textfile.txt')\n"
},
{
"answer_id": 911976,
"author": "Daniel Serodio",
"author_id": 112254,
"author_profile": "https://Stackoverflow.com/users/112254",
"pm_score": 5,
"selected": false,
"text": "os.system('\"C://Temp/a b c/Notepad.exe\"')\n"
},
{
"answer_id": 1622730,
"author": "Paul Hoffman",
"author_id": 196379,
"author_profile": "https://Stackoverflow.com/users/196379",
"pm_score": 4,
"selected": false,
"text": "os.system TheCommand = '\\\"\\\"C:\\\\Temp\\\\a b c\\\\Notepad.exe\\\"\\\"'\n os.system(TheCommand)\n subprocess.call os.system TheCommand = '\\\"\\\"C:\\\\Program Files\\\\Sun\\\\VirtualBox\\\\VBoxManage.exe\\\" ' \\\n + ' clonehd \\\"' + OrigFile + '\\\" \\\"' + NewFile + '\\\"\\\"'\n os.system(TheCommand)\n"
},
{
"answer_id": 2742855,
"author": "rahul",
"author_id": 329544,
"author_profile": "https://Stackoverflow.com/users/329544",
"pm_score": 4,
"selected": false,
"text": "import win32api # if active state python is installed or install pywin32 package seperately\n\ntry: win32api.WinExec('NOTEPAD.exe') # Works seamlessly\nexcept: pass\n"
},
{
"answer_id": 48382479,
"author": "gbonetti",
"author_id": 1534775,
"author_profile": "https://Stackoverflow.com/users/1534775",
"pm_score": 4,
"selected": false,
"text": "subprocess.run subprocess.call import subprocess\nsubprocess.run(['notepad.exe', 'test.txt'])\n"
},
{
"answer_id": 48382727,
"author": "Benyamin Jafari - aGn",
"author_id": 3702377,
"author_profile": "https://Stackoverflow.com/users/3702377",
"pm_score": 0,
"selected": false,
"text": "'/home/<you>/<first-path-section> <second-path-section>' import subprocess\n\nargs = ['{}/manage.py'.format('/home/<you>/<first-path-section> <second-path-section>'), 'runserver']\nres = subprocess.Popen(args, stdout=subprocess.PIPE)\noutput, error_ = res.communicate()\n\nif not error_:\n print(output)\nelse:\n print(error_)\n chmod 755 -R <'yor path'> manage.py chmod +x manage.py"
},
{
"answer_id": 57399125,
"author": "WestAce",
"author_id": 3781163,
"author_profile": "https://Stackoverflow.com/users/3781163",
"pm_score": 1,
"selected": false,
"text": "import subprocess\nsubprocess.call([r'C:\\Temp\\Example\\Notepad.exe', 'C:\\test.txt'])\n"
},
{
"answer_id": 61435838,
"author": "rajat prakash",
"author_id": 6593856,
"author_profile": "https://Stackoverflow.com/users/6593856",
"pm_score": 0,
"selected": false,
"text": "GitPath=\"C:\\\\Program Files\\\\Git\\\\git-bash.exe\"# Application File Path in mycase its GITBASH\nos.startfile(GitPath)\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/267/"
] |
204,025
|
<p>What do I have to consider <strong>in database design</strong> for a new application which should be able to support the most common relational database systems (SQL Server, MySQL, Oracle, PostgreSQL ...)?</p>
<p>Is it even worth the effort? What are the pitfalls?</p>
|
[
{
"answer_id": 68858389,
"author": "Lukas Eder",
"author_id": 521799,
"author_profile": "https://Stackoverflow.com/users/521799",
"pm_score": 1,
"selected": false,
"text": "FROM WHERE DUAL UNION UNION AS '' NULL TIMESTAMP TIMESTAMP WITH TIME ZONE DATE TIMESTAMP(0)"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6461/"
] |
204,032
|
<p>I've run into a problem trying to return an object that holds a collection of childobjects that again can hold a collection of grandchild objects. I get an error, 'connection forcibly closed by host'.</p>
<p>Is there any way to make this work? I currently have a structure resembling this:</p>
<p>pseudo code:</p>
<pre><code>Person:
IEnumerable<Order>
Order:
IEnumerable<OrderLine>
</code></pre>
<p>All three objects have the DataContract attribute and all public properties i want exposed (including the IEnumerable's) have the DataMember attribute.</p>
<p>I have multiple OperationContract's on my service and all the methods returning a single object OR an IEnumerable of an object works perfectly. It's only when i try to nest IEnumerable that it turns bad. Also in my client service reference i picked the generic list as my collection type. I just want to emphasize, <strong>only one of my operations/methods fail with this error - the rest of them work perfectly</strong>.</p>
<p>EDIT (more detailed error description):</p>
<pre><code>[SocketException (0x2746): An existing connection was forcibly closed by
the remote host]
[IOException: Unable to read data from the transport connection:
An existing connection was forcibly closed by the remote host.]
[WebException: The underlying connection was closed: An unexpected
error occurred on a receive.]
[CommunicationException: An error occurred while receiving the HTTP
response to http://myservice.mydomain.dk/MyService.svc. This could
be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by
the server (possibly due to the service shutting down). See server
logs for more details.]
</code></pre>
<p>I tried looking for logs but i can't find any... also i'm using a WSHttpBinding and an http endpoint.</p>
|
[
{
"answer_id": 204126,
"author": "Per Hornshøj-Schierbeck",
"author_id": 11619,
"author_profile": "https://Stackoverflow.com/users/11619",
"pm_score": 0,
"selected": false,
"text": "Server Error in '/' Application.\n--------------------------------------------------------------------------------\n\nAn existing connection was forcibly closed by the remote host \nDescription: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. \n\nException Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host\n\nSource Error: \n\nAn unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. \n\nStack Trace: \n\n\n[SocketException (0x2746): An existing connection was forcibly closed by the remote host]\n System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +93\n System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +119\n\n[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]\n System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +267\n System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) +25\n System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) +306\n\n[WebException: The underlying connection was closed: An unexpected error occurred on a receive.]\n System.Net.HttpWebRequest.GetResponse() +1532114\n System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +40\n\n[CommunicationException: An error occurred while receiving the HTTP response to http://Zzzstrukturservice.xxx.dk/ZzzstrukturService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.]\n System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +2668969\n System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +717\n xxx.Services.ZzzstrukturServiceClient.ZzzstrukturServiceProxy.IZzzstrukturService.GetMatrixSet(Int32 matrixSetId) +0\n xxx.Services.ZzzstrukturServiceClient.ZzzstrukturRepository.GetMatrixSetById(Int32 matrixSetId) in f:\\ccnet\\work\\xxx.Zzzstruktur\\1. Presentation Layer\\ZzzstrukturServiceClient\\ZzzstrukturRepository.cs:90\n xxx.yyy.yyyWeb.AnnoncePage.OnLoad(EventArgs e) in f:\\ccnet\\work\\yyyV2\\1. Presentation Layer\\yyyWeb\\Annonce.aspx.cs:40\n System.Web.UI.Control.LoadRecursive() +47\n System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436\n\n\n\n\n--------------------------------------------------------------------------------\nVersion Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433 \n"
},
{
"answer_id": 2114679,
"author": "Kyle Lahnakoski",
"author_id": 214460,
"author_profile": "https://Stackoverflow.com/users/214460",
"pm_score": 1,
"selected": false,
"text": "DataContract"
},
{
"answer_id": 2114693,
"author": "Chris O",
"author_id": 194709,
"author_profile": "https://Stackoverflow.com/users/194709",
"pm_score": 0,
"selected": false,
"text": "IEnumerable"
},
{
"answer_id": 2474727,
"author": "Thoại Nguyễn",
"author_id": 297058,
"author_profile": "https://Stackoverflow.com/users/297058",
"pm_score": 2,
"selected": false,
"text": "<system.web/> <httpRuntime maxRequestLength=\"102400\" executionTimeout=\"3600\" />\n"
},
{
"answer_id": 2699473,
"author": "Tiny122",
"author_id": 324294,
"author_profile": "https://Stackoverflow.com/users/324294",
"pm_score": 0,
"selected": false,
"text": "DataMember"
},
{
"answer_id": 3477537,
"author": "trkll",
"author_id": 419623,
"author_profile": "https://Stackoverflow.com/users/419623",
"pm_score": 0,
"selected": false,
"text": "[OperationBehavior()]"
},
{
"answer_id": 4016710,
"author": "Rob Willis",
"author_id": 333315,
"author_profile": "https://Stackoverflow.com/users/333315",
"pm_score": 0,
"selected": false,
"text": "DataContract ToList ToArray"
},
{
"answer_id": 4050171,
"author": "indiPy",
"author_id": 341950,
"author_profile": "https://Stackoverflow.com/users/341950",
"pm_score": 3,
"selected": false,
"text": "ObjectContext.ContextOptions.LazyLoadingEnabled = false;\nObjectContext.ContextOptions.ProxyCreationEnabled = false;\n"
},
{
"answer_id": 4638483,
"author": "Brandon Roberson",
"author_id": 568669,
"author_profile": "https://Stackoverflow.com/users/568669",
"pm_score": 2,
"selected": false,
"text": "DataContract DataMember EnumMember"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11619/"
] |
204,040
|
<p>REBOL has no built-in way to perform list comprehensions. However, REBOL has a powerful facility (known as <code>parse</code>) that can be used to create domain-specific languages (DSLs). I've used <code>parse</code> to create such a mini-DSL for list comprehensions. In order to interpret the expression, the block containing the comprehension is passed to a function, which for lack of a better term I've called <code>comprehend</code>.</p>
<p><strong>Example:</strong></p>
<pre><code>comprehend [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]
</code></pre>
<p>For some reason, <code>comprehend</code> doesn't sound right to me, but something like <code>eval</code> is too general.</p>
<p>I haven't found any other language that requires a keyword or function for list comprehensions. They are pure syntactic sugar wherever they exist. Unfortunately I don't have that option. So, seeing that I must have a function, what's a good, succinct, logical name for it?</p>
|
[
{
"answer_id": 501642,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": "select select [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]"
},
{
"answer_id": 501651,
"author": "Logan Capaldo",
"author_id": 61289,
"author_profile": "https://Stackoverflow.com/users/61289",
"pm_score": 1,
"selected": false,
"text": "do do comp yielding yielding [(a * b) for a in 1x100 for b in 4x10 where (all [odd? a odd? b])]"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204040",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27779/"
] |
204,041
|
<p>In my asp.net mvc app I want to check if a certain url returns a valid response.
Therefor I send the url to a method that tests the HttpWebRequest.GetResponse()</p>
<p>On my dev server (vs2008) it works just fine.
When deployed on production server however, it returns a Bad Request.
The method is never hit and my asp.net custom error pages are not used.</p>
<p>any ideas?</p>
|
[
{
"answer_id": 204136,
"author": "J c",
"author_id": 25837,
"author_profile": "https://Stackoverflow.com/users/25837",
"pm_score": 0,
"selected": false,
"text": "<%@ Page Language=\"C#\" CodeFile=\"Default.aspx.cs\" Inherits=\"_Default\" ValidateRequest=\"false\" %>\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204041",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
204,050
|
<p>I know a role name and want to find all users in this role.
How do I acheive this in SQL Server 2000 (in the SQL script, not in Management Studio or other tool)?</p>
|
[
{
"answer_id": 204105,
"author": "Tim",
"author_id": 10363,
"author_profile": "https://Stackoverflow.com/users/10363",
"pm_score": 3,
"selected": true,
"text": "exec sp_helpsrvrolemember 'role'\n exec sp_helprolemember 'role'\n"
},
{
"answer_id": 204106,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 0,
"selected": false,
"text": "exec sp_helprolemember rolename\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204050",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23714/"
] |
204,075
|
<p>I know many people who use computers every day, who do not know how to select multiple items in a HTML select box/list. I don't want to use this control in my pages any more:</p>
<pre><code>Please pick 3 options:
<select name="categories" size="10" multiple="yes">
</code></pre>
<p>So what user-friendly alternatives do you suggest? Perhaps have 10 tickboxes...or maybe just have each option in a coloured block which changes colour when they click to choose it? This gets messier when I consider my current list of 20 options might grow to 50 eventually.</p>
<p>Whatever way I pick it's gonna be a pain to validate it (using Javascript), to make sure the person picks at least 1 item and not more than 3. It's not about detecting how many options they have picked, the problem is more about how to convey this to the user in a friendly way!</p>
<p><b>Edit:</b>
I suppose I could use tags, like right here on stackoverflow, but I feel these are less appropriate if the users are non-technical (and half of them will be).</p>
|
[
{
"answer_id": 204104,
"author": "Aleris",
"author_id": 20417,
"author_profile": "https://Stackoverflow.com/users/20417",
"pm_score": 4,
"selected": false,
"text": "<div style=\"overflow: scroll\" />\n"
},
{
"answer_id": 204109,
"author": "Vlad Gudim",
"author_id": 22088,
"author_profile": "https://Stackoverflow.com/users/22088",
"pm_score": 1,
"selected": false,
"text": "<select><option>Capa Verde</option></select>\n<select><option>Holiday</option></select>\n<select><option>Competition</option></select>\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11461/"
] |
204,087
|
<blockquote>
<p>"To help protect your security,
Explorer has restricted this webpage
from running scripts or ActiveX
controls that could access your
computer"</p>
</blockquote>
<p>Whenever I add Flash movies or javascript code this message will show. It also shows for somebody else, so how do I get rid of this message? If I load or access some other website which cotains these features it doesn't show this message. Please tell me how to write a script so that it does not show this error.</p>
|
[
{
"answer_id": 280326,
"author": "Javier Suero Santos",
"author_id": 34432,
"author_profile": "https://Stackoverflow.com/users/34432",
"pm_score": 0,
"selected": false,
"text": "<head>\n<!-- saved from url=(0021)http://www.myurl.com/ -->\n</head>\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204087",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
204,115
|
<p>So there seems to be this problem with GNU Make's $(wildcard) function keeping a directory open on Windows. See (unasnwered) post "<a href="http://www.cygwin.com/ml/cygwin/2003-06/msg01182.html" rel="nofollow noreferrer">make is holding a directory open</a>". Google does not provide much information on the topic.</p>
<p>In short: the Makefile uses the $(wildcard) function at some point, and keeps a directory open, which typically prevents the "make clean" rule to do its work correctly. Re-running "make clean" a second time usually solves it.</p>
<p>I'm using GNU Make version 3.81 under a standard DOS-Box. The author of the post linked to above is using Cygwin.</p>
<p>Has anyone found a fix for this?</p>
|
[
{
"answer_id": 220331,
"author": "Charles Duffy",
"author_id": 14122,
"author_profile": "https://Stackoverflow.com/users/14122",
"pm_score": 2,
"selected": false,
"text": "/proc/self/fd /proc/$PPID/fd"
},
{
"answer_id": 388248,
"author": "Carl Seleborg",
"author_id": 2095,
"author_profile": "https://Stackoverflow.com/users/2095",
"pm_score": 1,
"selected": true,
"text": "$(wildcard) # The clean rule is always parsed\nclean:\n rm -rf $(OUTPUT_DIRECTORY)\n\n# The compile rule is only interpreted if we did not invoke 'make clean'. We\n# can test the value of $(MAKECMDGOALS) for that:\nifeq ($(filter $(MAKECMDGOALS),clean),)\n\nSOURCE_FILES := $(wildcard ...)\n\ncompile:\n g++ $(SOURCE_FILES) ...\n\nendif\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2095/"
] |
204,123
|
<p>I am cloning a hidden table row then populating it and after validation I want to show the row using a jquery effect ... say .show("slow")</p>
<pre><code>var baseRow = $("#tasks tr#baseTaskLine");
var newRow = baseRow.clone();
var lastRow = $("#tasks tr[id^='TaskLine_']" + dayClass + ":last");
var newRowId;
if (lastRow.length == 0) {
newRowId = "TaskLine_new0";
}
else {
newRowId = "TaskLine_new" + lastRow[0].rowIndex;
}
newRow.attr("id", newRowId);
:
[populate new row]
:
if (lastRow.length == 0) {
baseRow.after(newRow);
}
else {
lastRow.after(newRow);
}
newRow.hide();
:
:
[validate via webservice call]
:
newRow.show("slow");
</code></pre>
<p>This does show the row but it appears instantly. I have tried hiding all the <code><td></code> elements of the row then showing those and that does seem to work but some strange styles get added to each <code><td></code> which interfere with the formatting i.e. <code>style="display: block;"</code></p>
|
[
{
"answer_id": 204142,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 4,
"selected": true,
"text": "<table>\n<tr id=\"row1\"><td><div>Cell1:1</div></td><td><div>Cell2:1</div></td></tr>\n<tr id=\"row2\"><td><div>Cell1:2</div></td><td><div>Cell2:2</div></td></tr>\n</table>\n $('#row2 td div').show('slow');\n"
},
{
"answer_id": 204672,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 0,
"selected": false,
"text": "<table id=\"myTable\">\n <tbody>\n <tr><td>Row 1,1</td><td>Row 1,2</td></tr>\n <tr><td>Row 2,1</td><td>Row 2,2</td></tr>\n </tbody>\n</table>\n // get the row you're after.\nvar $row = $(\"#myTable tr:last\");\n// store its height\nvar h = $row.height();\n\n$row\n .css(\"height\", 0) // set the height back to 0\n .animate({\n height : h + \"px\" // animate it back to normal.\n }, \"slow\")\n;\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18349/"
] |
204,140
|
<p>How can I move items from one list box control to another listbox control using JavaScript in ASP.NET?</p>
|
[
{
"answer_id": 204161,
"author": "Remy Sharp",
"author_id": 22617,
"author_profile": "https://Stackoverflow.com/users/22617",
"pm_score": 5,
"selected": false,
"text": "$('#firstSelect option:selected').appendTo('#secondSelect');\n"
},
{
"answer_id": 204429,
"author": "Tom",
"author_id": 20,
"author_profile": "https://Stackoverflow.com/users/20",
"pm_score": 4,
"selected": true,
"text": "document.getElementById('moveTrigger').onclick = function() {\n\n var listTwo = document.getElementById('secondList');\n var options = document.getElementById('firstList').getElementsByTagName('option');\n\n while(options.length != 0) {\n listTwo.appendChild(options[0]);\n }\n\n }\n"
},
{
"answer_id": 204457,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 3,
"selected": false,
"text": "function Move(inputControl)\n{\n var left = document.getElementById(\"Left\");\n var right = document.getElementById(\"Right\");\n var from, to;\n var bAll = false;\n switch (inputControl.value)\n {\n case '<<':\n bAll = true;\n // Fall through\n case '<':\n from = right; to = left;\n break;\n case '>>':\n bAll = true;\n // Fall through\n case '>':\n from = left; to = right;\n break;\n default:\n alert(\"Check your HTML!\");\n }\n for (var i = from.length - 1; i >= 0; i--)\n {\n var o = from.options[i];\n if (bAll || o.selected)\n {\n from.remove(i);\n try\n {\n to.add(o, null); // Standard method, fails in IE (6&7 at least)\n }\n catch (e)\n {\n to.add(o); // IE only\n }\n }\n }\n}\n <select id=\"Left\" multiple=\"multiple\" size=\"10\">\n <option>Some</option>\n <option>List</option>\n <option>Of</option>\n <option>Items</option>\n <option>To</option>\n <option>Move</option>\n <option>Around</option>\n</select>\n\n<div id=\"Toolbar\">\n <input type=\"button\" value=\">\" onclick=\"Move(this)\"/>\n <input type=\"button\" value=\">>\" onclick=\"Move(this)\"/>\n <input type=\"button\" value=\"<<\" onclick=\"Move(this)\"/>\n <input type=\"button\" value=\"<\" onclick=\"Move(this)\"/>\n</div>\n\n<select id=\"Right\" multiple=\"multiple\" size=\"10\">\n</select>\n select { width: 200px; float: left; }\n#Toolbar { width: 50px; float: left; text-align: center; padding-top: 30px; }\n#Toolbar input { width: 40px; }\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22162/"
] |
204,169
|
<p>I have a very simple question. I want to test whether a particular port is currently under use or not. For this, I want to bind a TCP socket to the port, if the connection is refused means the port is in use and if not that mean the port is free.</p>
<p>Can someone please tell me how can I write the TCP socket code in C? I am on a solaris platform.</p>
<p>I know its very basic. But I appreciate your help. Thanks in advance.</p>
|
[
{
"answer_id": 204236,
"author": "Joel Cunningham",
"author_id": 5360,
"author_profile": "https://Stackoverflow.com/users/5360",
"pm_score": 5,
"selected": true,
"text": "#include <stdio.h>\n#include <sys/socket.h>\n#include <netinet/in.h>\n\n#define PORT 12345\n\nint main()\n{\n struct sockaddr_in addr;\n int fd;\n\n fd = socket(AF_INET, SOCK_STREAM, 0);\n if(fd == -1)\n {\n printf(\"Error opening socket\\n\");\n return -1;\n }\n\n addr.sin_port = htons(PORT);\n addr.sin_addr.s_addr = 0;\n addr.sin_addr.s_addr = INADDR_ANY;\n addr.sin_family = AF_INET;\n\n if(bind(fd, (struct sockaddr *)&addr,sizeof(struct sockaddr_in) ) == -1)\n {\n printf(\"Error binding socket\\n\");\n return -1;\n }\n\n printf(\"Successfully bound to port %u\\n\", PORT);\n}\n"
},
{
"answer_id": 204362,
"author": "Andrew Edgecombe",
"author_id": 11694,
"author_profile": "https://Stackoverflow.com/users/11694",
"pm_score": 3,
"selected": false,
"text": "bind() bind() errno == EADDRINUSE \nif(bind(socket, (struct sockaddr *)&sin,sizeof(struct sockaddr_in) ) == -1)\n{\n if( errno == EADDRINUSE )\n {\n // handle port already open case\n }\n else\n {\n // handle other errors\n }\n}\n \n sin.sin_addr.s_addr = inet_addr(\"192.168.1.1\");\n close() EADDRINUSE netstat bind() netstat -a --numeric-ports -t"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27778/"
] |
204,170
|
<p>So I need to update a text field. Neither the UPDATE statement or the WRITETEXT statement work when used below</p>
<pre><code>CREATE TABLE MyTable (IDField int, MyField text)
INSERT INTO MyTable (IDField) SELECT 1
DECLARE @Data1 varchar(8000), @Data2 varchar(8000), @ptrval binary(16)
SELECT @Data1 = REPLICATE('1',8000)
SELECT @Data2 = REPLICATE('2',8000)
-- this sets MyField to string of only 8000 characters
UPDATE MyTable SET MyField = @Data1 + @Data2 WHERE IDField = 1
SELECT @ptrval = TEXTPTR(MyField )
FROM MyTable
WHERE IDField = 1
-- this causes an error: Incorrect syntax near '+'.
--WRITETEXT MyTable.MyField @ptrval @Data1 + @Data2
</code></pre>
<p>How am I supposed to do this when local variables cannot be of type TEXT? (If I had SSQL Server 2005 I would use varchar(max) - but I don't)</p>
|
[
{
"answer_id": 204255,
"author": "Jim Birchall",
"author_id": 989,
"author_profile": "https://Stackoverflow.com/users/989",
"pm_score": 4,
"selected": true,
"text": "WRITETEXT MyTable.MyField @ptrval @Data1 \nUPDATETEXT MyTable.MyField @ptrval 8000 NULL @Data2\n"
},
{
"answer_id": 204392,
"author": "Mark Plumpton",
"author_id": 10422,
"author_profile": "https://Stackoverflow.com/users/10422",
"pm_score": 2,
"selected": false,
"text": "WRITETEXT MyTable.MyField @ptrval @Data1 \nUPDATETEXT MyTable.MyField @ptrval Len(@Data1) NULL @Data2\n WRITETEXT MyTable.MyField @ptrval @Data1\nSET @Len = LEN(@Data1)\nUPDATETEXT MyTable.MyField @ptrval @Len NULL @Data2\n"
},
{
"answer_id": 25936794,
"author": "Jim Torguson",
"author_id": 4058859,
"author_profile": "https://Stackoverflow.com/users/4058859",
"pm_score": 0,
"selected": false,
"text": " SQLst = \"UPDATE Test SET Text = cast (@value as ntext)\" & _\n \" WHERE Num = 3 \"\n\n Debug.Print(SQLst.ToString)\n\n Dim cnn As New SqlServerCe.SqlCeConnection(Tcon)\n Dim cmd = New SqlCeCommand(SQLst, cnn)\n cmd.Parameters.AddWithValue(\"@value\", strQuestionQUESTION)\n cnn.Open()\n cmd.ExecuteNonQuery()\n cnn.Close()\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10422/"
] |
204,172
|
<p>How can I turn off certificate revocation for a WCF service's client?
The client proxy was generated by wsdl.exe and inherits SoapHttpClientProtocol.</p>
|
[
{
"answer_id": 204209,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 4,
"selected": true,
"text": "ServicePointManager.ServerCertificateValidationCallback RemoteCertificateValidationCallback class Program\n{\n static void Main(string[] args)\n {\n ServicePointManager.ServerCertificateValidationCallback +=\n new RemoteCertificateValidationCallback(ValidateCertificate);\n\n // Do WCF calls...\n }\n\n public static bool ValidateCertificate(object sender, X509Certificate cert, \n X509Chain chain, SslPolicyErrors sslPolicyErrors)\n {\n if(sslPolicyErrors == SslPolicyErrors.RemoteCertificateChainErrors)\n {\n foreach(X509ChainStatus chainStatus in chain.ChainStatus)\n {\n if(chainStatus.Status == X509ChainStatusFlags.Revoked)\n {\n return true;\n }\n }\n }\n \n /* \n WARNING!\n \n You should perform other cert validation checks here and not blindly \n override your cert validation by returning true.\n\n Otherwise the secure channel between your client and service\n may not be secure.\n\n */\n\n return false;\n }\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204172",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19956/"
] |
204,181
|
<p>I've got two applications I'm developing using Qt on windows. I want the user to be able to press a button in one application which makes the other application come to the foreground. (The programs communicate using QLocalSocket and named pipes.)</p>
<p>Currently I'm using Qt's QWidget::activateWindow() which occasionally brings the application to the foreground, but most of the time it just highlights the program on the taskbar.</p>
<p>Can someone please tell me how to do this, preferably using Qt although failing that using the WIN32 API would be fine.</p>
<hr>
<p>Unfortunately, I couldn't find a way to do this only with Qt. I solved it using Chris Becke's suggestion of calling SetForegroundWindow from the currently active application.</p>
|
[
{
"answer_id": 204228,
"author": "PierreBdR",
"author_id": 7136,
"author_profile": "https://Stackoverflow.com/users/7136",
"pm_score": 2,
"selected": false,
"text": "QWidget::activateWindow QWidget::raise"
},
{
"answer_id": 1017667,
"author": "nurxb01",
"author_id": 132736,
"author_profile": "https://Stackoverflow.com/users/132736",
"pm_score": 2,
"selected": false,
"text": "event() bool MyWidgetB:event ( QEvent * e )\n{\n QEvent::Type type = e->type ();\n\n // Somehow the correct state of window is not getting set,\n // so doing it manually\n if( e->type() == QEvent::Hide)\n {\n this->setWindowState(WindowMinimized);\n }\n else if( e->type() == QEvent::Show )\n {\n this->setWindowState((this->windowState() & ~WindowMinimized) |\n WindowActive);\n }\n return QWidget::event(e);\n}\n void BringUpWidget(QWidget* pWidget)\n{\n pWidget ->showMinimized(); // This is to bring up the window if not minimized\n // but beneath some other window\n\n pWidget ->setWindowState(Qt::WindowActive);\n pWidget ->showNormal();\n}\n MainWidget QWidget QMainWindow BringUpWidget MainWindow"
},
{
"answer_id": 4038080,
"author": "ctd",
"author_id": 58133,
"author_profile": "https://Stackoverflow.com/users/58133",
"pm_score": 1,
"selected": false,
"text": " this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);\n this->show();\n this->setWindowFlags(Qt::FramelessWindowHint);\n this->show();\n this->setWindowFlags(Qt::WindowStaysOnTopHint);\n this->show();\n this->setWindowFlags(0);\n this->show();\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22648/"
] |
204,186
|
<p>In writing some test code I have found that Selector.select() can return without Selector.selectedKeys() containing any keys to process. This is happening in a tight loop when I register an accept()ed channel with</p>
<pre>SelectionKey.OP_READ | SelectionKey.OP_CONNECT</pre>
<p>as the operations of interest.</p>
<p>According to the docs, select() should return when:</p>
<p>1) There are channels that can be acted upon.</p>
<p>2) You explicitly call Selector.wakeup() - no keys are selected.</p>
<p>3) You explicitly Thread.interrupt() the thread doing the select() - no keys are selected.</p>
<p>If I get no keys after the select() I must be in cases (2) and (3). However, my code is not calling wakeup() or interrupt() to initiate these returns.</p>
<p>Any ideas as to what is causing this behaviour?</p>
|
[
{
"answer_id": 205354,
"author": "Alexander",
"author_id": 16724,
"author_profile": "https://Stackoverflow.com/users/16724",
"pm_score": 4,
"selected": true,
"text": "OP_CONNECT import java.net.*;\nimport java.nio.channels.*;\n\n\npublic class MyNioServer {\n public static void main(String[] params) throws Exception {\n final ServerSocketChannel serverChannel = ServerSocketChannel.open();\n serverChannel.configureBlocking(true);\n serverChannel.socket().bind(new InetSocketAddress(\"localhost\", 12345));\n System.out.println(\"Listening for incoming connections\");\n final SocketChannel clientChannel = serverChannel.accept();\n System.out.println(\"Accepted connection: \" + clientChannel);\n\n\n final Selector selector = Selector.open();\n clientChannel.configureBlocking(false);\n final SelectionKey clientKey = clientChannel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_CONNECT);\n System.out.println(\"Selecting...\");\n System.out.println(selector.select());\n System.out.println(selector.selectedKeys().size());\n System.out.println(clientKey.readyOps());\n }\n}\n select()"
},
{
"answer_id": 6646131,
"author": "user207421",
"author_id": 207421,
"author_profile": "https://Stackoverflow.com/users/207421",
"pm_score": 3,
"selected": false,
"text": "OP_CONNECT OP_WRITE OP_ACCEPT OP_READ OP_CONNECT OP_WRITE OP_CONNECT, OP_WRITE, select()"
},
{
"answer_id": 74562799,
"author": "Pavel Moukhataev",
"author_id": 5260478,
"author_profile": "https://Stackoverflow.com/users/5260478",
"pm_score": 0,
"selected": false,
"text": "OP_CONNECT Selector selector = Selector.open();\n SocketChannel serverChannel = SocketChannel.open(StandardProtocolFamily.INET);\n serverChannel.configureBlocking(false);\n serverChannel.connect(new InetSocketAddress(\"localhost\", 5454));\n serverChannel.register(selector, SelectionKey.OP_CONNECT);\n // event process cycle\n { \n int count = selector.select();\n for (SelectionKey key : selector.selectedKeys()) {\n log.info(\" {}\", key.readyOps());\n if (key.isConnectable()) {\n log.info(\"Connection is ready\");\n key.interestOps(SelectionKey.OP_READ);\n }\n if (key.isReadable()) {\n // read data here\n }\n }\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28164/"
] |
204,194
|
<p>I have a JSP accessed through JBoss. It renders a list (a search result).
If the response gets big, approximately larger than 200k the response is truncated. I can see how the page just ends in the middle of a tag in Firefox. IE totally freaks out an so does Fiddler.
Responses smaller than 200k are no problem.</p>
<p>Anyone has experienced this?
I don't know where to look for the problem... any suggestions are welcome.</p>
|
[
{
"answer_id": 204246,
"author": "Victor",
"author_id": 14514,
"author_profile": "https://Stackoverflow.com/users/14514",
"pm_score": 1,
"selected": false,
"text": "<%@page buffer=\"500kb\" autoFlush=\"true\" %>\n"
},
{
"answer_id": 20885515,
"author": "Ujjwal Singh",
"author_id": 483588,
"author_profile": "https://Stackoverflow.com/users/483588",
"pm_score": 2,
"selected": false,
"text": "<%@ page buffer=\"none\" %>\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28180/"
] |
204,208
|
<p>I want to detect and replace malformed UTF-8 characters with blank space using a Perl script while loading the data using SQL*Loader. How can I do this? </p>
|
[
{
"answer_id": 205713,
"author": "Constantin",
"author_id": 20310,
"author_profile": "https://Stackoverflow.com/users/20310",
"pm_score": 2,
"selected": false,
"text": "import codecs\ncodecs.register_error('spacer', lambda ex: (u' ', ex.start + 1))\ns = 'spam\\xb0\\xc0eggs\\xd0bacon'.decode('utf8', 'spacer')\nprint s.encode('utf8')\n spam eggs bacon\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
204,241
|
<p>Using <code>WritePrivateProfileString</code> and <code>GetPrivateProfileString</code> results in <code>???</code> instead of the real characters.</p>
|
[
{
"answer_id": 204254,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 1,
"selected": false,
"text": "WritePrivateProfileString WritePrivateProfileStringW"
},
{
"answer_id": 8821555,
"author": "Roger Bamforth",
"author_id": 1143459,
"author_profile": "https://Stackoverflow.com/users/1143459",
"pm_score": 3,
"selected": false,
"text": "GetPrivateProfileString() WritePrivateProfileString()"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
204,256
|
<p>Why does a Boolean consume 4 bytes and a char 2 bytes in the .NET framework? A Boolean should take up 1bit or at least be smaller than a char.</p>
|
[
{
"answer_id": 434182,
"author": "Blaisorblade",
"author_id": 53974,
"author_profile": "https://Stackoverflow.com/users/53974",
"pm_score": 4,
"selected": false,
"text": "boolean char char"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17211/"
] |
204,282
|
<p>My problem is that I set some breakpoints in my code and some of them aren't working. In some places it complains about "Unresolved Breakpoint". </p>
<p>Does anyone have any clue why this is happening? I am using gdb, by the way.</p>
<p>EDIT: Yes, of course is compiled with debug information. It only happens at some classes or points in the code. And I am pretty sure that that part of the code is reached because I can reach it stepping</p>
<p>EDIT: The solution from Richard doesn't work; thanks anyway. I am compiling in Debug, without any optimization.</p>
|
[
{
"answer_id": 19493016,
"author": "Arks",
"author_id": 1582090,
"author_profile": "https://Stackoverflow.com/users/1582090",
"pm_score": 0,
"selected": false,
"text": "template <typename T>\nint doit(T a) {\n return a.do(); // <-- breakpoint here\n}\n...\nA a;\ncout << doit(a);\n"
},
{
"answer_id": 26852630,
"author": "Israelm",
"author_id": 1483978,
"author_profile": "https://Stackoverflow.com/users/1483978",
"pm_score": 0,
"selected": false,
"text": "1.- Removed the breakpoints. \n2.- Restart eclipse \n3.- Clean the project by using project -> clean \n4.- Add again the breakpoints and start your debugging.\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/366094/"
] |
204,289
|
<p>Been trying to find a working implementation of a WPF listview (or listbox) where
you can order items by dragging them up or down.</p>
<p>I have found a few, but none really works,
for example this one
<a href="http://www.codeproject.com/KB/WPF/ListViewDragDropManager.aspx?msg=2765618#xx2765618xx" rel="nofollow noreferrer">http://www.codeproject.com/KB/WPF/ListViewDragDropManager.aspx?msg=2765618#xx2765618xx</a>
stops working once you have list where you need to scroll down to get to the last items.</p>
<p>Why is Drag&Drop so hard in WPF?
Does anybody know a working control?</p>
|
[
{
"answer_id": 204462,
"author": "rudigrobler",
"author_id": 5147,
"author_profile": "https://Stackoverflow.com/users/5147",
"pm_score": 1,
"selected": false,
"text": "<ListBox src:DragAndDrop.DragEnabled=\"true\"/> \n <ListBox src:DragAndDrop.DropEnabled=\"true\"/> \n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204289",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28149/"
] |
204,303
|
<p>I'm starting to investigate T4 for Code Generation.</p>
<p>I get that you have a basic template in which you can embed little chunks of c#/vb which can perform clever stuff...</p>
<pre><code><#@ template language="VB" debug="True" hostspecific="True" #>
<#@ output extension=".vb" debug="True" hostspecific="True" #>
Imports System
<#For Each Table as String in New String(0 {"Table1","Table2"}#>
Public Class <#=Table#>DA
Public Sub New
<#= WriteConstructorBody() #>
End Sub
End Class
<#Next#>
<#+
Public Function WriteConstructorBody() as String
return "' Some comment"
End function
#>
</code></pre>
<p>This is great.. However I would like to be able to write my main block thus...</p>
<pre><code><#@ template language="VB" debug="True" hostspecific="True" #>
<#@ output extension=".vb" debug="True" hostspecific="True" #>
Imports System
<#
For Each BaseTableName as String in New String(){"Table1","Table2"}
WriteRecDataInterface(BaseTableName)
WriteRecDataClass(BaseTableName)
WriteDAInterface(BaseTableName)
WriteDAClass(BaseTableName)
Next
#>
</code></pre>
<p>Then I would like to be able to have the WriteX methods exist in a Class Block but themselves be writable using code by example ie escaped Code blocks.</p>
<p>How can I achieve this?</p>
|
[
{
"answer_id": 204367,
"author": "Enrico Campidoglio",
"author_id": 26396,
"author_profile": "https://Stackoverflow.com/users/26396",
"pm_score": 2,
"selected": true,
"text": "<#@ template language=\"C#\" #>\n<# HelloWorld(); #>\n<#+\n private string _field = \"classy\";\n private void HelloWorld()\n {\n for(int i = 1; i <= 3; i++)\n {\n#>\nHello <#=_field#> World <#= i #>!\n<#+\n }\n }\n#>\n"
},
{
"answer_id": 204376,
"author": "Rory Becker",
"author_id": 11356,
"author_profile": "https://Stackoverflow.com/users/11356",
"pm_score": 2,
"selected": false,
"text": "<#@ template language=\"VB\" debug=\"True\" hostspecific=\"True\" #>\n<#@ output extension=\".vb\" debug=\"True\" hostspecific=\"True\" #>\nImports System\n<# \nFor Each BaseTableName as String in New String(){\"Table1\",\"Table2\"} \n WriteRecDataInterface(BaseTableName) \n\n ' WriteRecDataClass(BaseTableName) \n ' WriteDAInterface(BaseTableName) \n ' WriteDAClass(BaseTableName) \nNext \n#>\n\n\n<#+ Public Sub WriteRecDataInterface(BaseTableName as String)#>\n Some Templated unescaped code might go here\n <#+ For SomeLoopVar as Integer = 1 to 10 #>\n Some Templated unescaped code might go here\n <#+ Next #>\n Some Templated unescaped code might go here\n<#+ End Sub #>\n'...\n'...\n' Other Subs left out for brevity\n'...\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204303",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11356/"
] |
204,305
|
<p>I have an asp.net server control (with the asp: in its definition). The button has been set to do post back.</p>
<p>On the server side, I have the on click event handler
e.g btnSave_click()</p>
<p>On the client side, I have a javascript function to be invoked on the click event
e.g btnSave.Attributes.Add("onclick","javascript: return CheckIsDirty();")</p>
<p>Am not sure which order these two will be executed. Because I want first on the client side to warn of any data entry fields that are not yet filled-out before actually saving any data.</p>
<p>Any help?</p>
|
[
{
"answer_id": 204325,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 3,
"selected": true,
"text": "close.Attributes[\"OnClick\"] = \"return confirm('Are you sure?')\";\n"
},
{
"answer_id": 204454,
"author": "Jason Whitehorn",
"author_id": 27860,
"author_profile": "https://Stackoverflow.com/users/27860",
"pm_score": 1,
"selected": false,
"text": "btnSave.Attributes.Add(\"onclick\", \"CheckIsDirty();\" + GetPostBackEventReference(btnSave).ToString());\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204305",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13370/"
] |
204,308
|
<p>I regularly want to check if an object has a member or not. An example is the creation of a singleton in a function. For that purpose, you can use <code>hasattr</code> like this:</p>
<pre><code>class Foo(object):
@classmethod
def singleton(self):
if not hasattr(self, 'instance'):
self.instance = Foo()
return self.instance
</code></pre>
<p>But you can also do this:</p>
<pre><code>class Foo(object):
@classmethod
def singleton(self):
try:
return self.instance
except AttributeError:
self.instance = Foo()
return self.instance
</code></pre>
<p>Is one method better of the other?</p>
<p><strong>Edit:</strong> Added the <code>@classmethod</code> ... But note that the question is <em>not</em> about how to make a singleton but how to check the presence of a member in an object.</p>
<p><strong>Edit:</strong> For that example, a typical usage would be:</p>
<pre><code>s = Foo.singleton()
</code></pre>
<p>Then <code>s</code> is an object of type <code>Foo</code>, the same each time. And, typically, the method is called many times.</p>
|
[
{
"answer_id": 204318,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": false,
"text": "instance instance instance"
},
{
"answer_id": 204481,
"author": "Andrea Ambu",
"author_id": 21384,
"author_profile": "https://Stackoverflow.com/users/21384",
"pm_score": 3,
"selected": false,
"text": "class Foo(object):\n @classmethod\n def singleton(self):\n if not hasattr(self, 'instance'):\n self.instance = Foo()\n return self.instance\n\n\n\nclass Bar(object):\n @classmethod\n def singleton(self):\n try:\n return self.instance\n except AttributeError:\n self.instance = Bar()\n return self.instance\n\n\n\nfrom time import time\n\nn = 1000000\nfoo = [Foo() for i in xrange(0,n)]\nbar = [Bar() for i in xrange(0,n)]\n\nprint \"Objs created.\"\nprint\n\n\nfor times in xrange(1,4):\n t = time()\n for d in foo: d.singleton()\n print \"#%d Foo pass in %f\" % (times, time()-t)\n\n t = time()\n for d in bar: d.singleton()\n print \"#%d Bar pass in %f\" % (times, time()-t)\n\n print\n Objs created.\n\n#1 Foo pass in 1.719000\n#1 Bar pass in 1.140000\n\n#2 Foo pass in 1.750000\n#2 Bar pass in 1.187000\n\n#3 Foo pass in 1.797000\n#3 Bar pass in 1.203000\n"
},
{
"answer_id": 204520,
"author": "Brian",
"author_id": 18192,
"author_profile": "https://Stackoverflow.com/users/18192",
"pm_score": 0,
"selected": false,
"text": "class Singleton:\n class __impl:\n def spam(self):\n return id(self)\n __instance = None\n def __init__(self):\n if Singleton.__instance is None:\n Singleton.__instance = Singleton.__impl()\n self.__dict__['_Singleton__instance'] = Singleton.__instance\n def __getattr__(self, attr):\n return getattr(self.__instance, attr)\n def __setattr__(self, attr, value):\n return setattr(self.__instance, attr, value)\n"
},
{
"answer_id": 204523,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 6,
"selected": true,
"text": "try raise"
},
{
"answer_id": 204561,
"author": "gx.",
"author_id": 21580,
"author_profile": "https://Stackoverflow.com/users/21580",
"pm_score": 1,
"selected": false,
"text": "class Borg:\n __shared_state = {}\n def __init__(self):\n self.__dict__ = self.__shared_state\n # and whatever else you want in your class -- that's all!\n obj = Borg()\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7136/"
] |
204,316
|
<p>According to this</p>
<p><a href="http://perldoc.perl.org/UNIVERSAL.html" rel="noreferrer">http://perldoc.perl.org/UNIVERSAL.html</a></p>
<p>I shouldn't use UNIVERSAL::isa() and should instead use $obj->isa() or CLASS->isa().</p>
<p>This means that to find out if something is a reference in the first place and then is reference to this class I have to do</p>
<pre><code>eval { $poss->isa("Class") }
</code></pre>
<p>and check $@ and all that gumph, or else</p>
<pre><code>use Scalar::Util 'blessed';
blessed $ref && $ref->isa($class);
</code></pre>
<p>My question is why? What's wrong with UNIVERSAL::isa called like that? It's much cleaner for things like:</p>
<pre><code>my $self = shift if UNIVERSAL::isa($_[0], __PACKAGE__)
</code></pre>
<p>To see whether this function is being called on the object or not. And is there a nice clean alternative that doesn't get cumbersome with ampersands and potentially long lines?</p>
|
[
{
"answer_id": 204352,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": false,
"text": "isa UNIVERSAL::isa isa isa FooBar::method FooBar->method $foobar->method FooBar::method"
},
{
"answer_id": 204355,
"author": "Penfold",
"author_id": 11952,
"author_profile": "https://Stackoverflow.com/users/11952",
"pm_score": 3,
"selected": false,
"text": "my $self = shift if UNIVERSAL::isa($_[0], __PACKAGE__)"
},
{
"answer_id": 204368,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 6,
"selected": true,
"text": "UNIVERSAL::isa isa isa isa UNIVERSAL::isa isa $ref UNIVERSAL use CGI;\n\nmy $a = CGI->new();\n\nmy $b = \"CGI\";\n\nprint UNIVERSAL::isa($a,\"CGI\"); # prints 1, $a is a CGI object.\nprint UNIVERSAL::isa($b,\"CGI\"); # Also prints 1!! Uh-oh!!\n UNIVERSAL::isa isa"
},
{
"answer_id": 204387,
"author": "Dave Sherohman",
"author_id": 18914,
"author_profile": "https://Stackoverflow.com/users/18914",
"pm_score": 2,
"selected": false,
"text": "if (ref $_[0]) {\n my $self = shift;\n # called on instance, so do instancey things\n} else {\n my $class = shift;\n # called as a class/static method, so do classy things\n}\n"
},
{
"answer_id": 204899,
"author": "pjf",
"author_id": 19422,
"author_profile": "https://Stackoverflow.com/users/19422",
"pm_score": 3,
"selected": false,
"text": "UNIVERSAL::isa isa if (eval { $foo->isa(\"thing\") }) {\n # Do thingish things\n}\n eval if ( $foo->isa(\"thing\") ) {\n # Do thingish things\n}\n $foo $foo use autobox; # Everything is now a first class object.\nuse CGI; # Because I know you have it installed.\n\nmy $x = 5;\nmy $y = CGI->new;\n\nprint \"\\$x is a CGI object\\n\" if $x->isa('CGI'); # This isn't printed.\nprint \"\\$y is a CGI object\\n\" if $y->isa('CGI'); # This is!\n ->isa()"
},
{
"answer_id": 2302118,
"author": "codeholic",
"author_id": 268224,
"author_profile": "https://Stackoverflow.com/users/268224",
"pm_score": 1,
"selected": false,
"text": "isa if (eval { $obj->isa($class) }) {\n"
},
{
"answer_id": 65603289,
"author": "brian d foy",
"author_id": 2766176,
"author_profile": "https://Stackoverflow.com/users/2766176",
"pm_score": 1,
"selected": false,
"text": "isa $something use v5.32;\n\nif( $something isa 'Animal' ) { ... }\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2386199/"
] |
204,320
|
<p>Is there a way to declare a variable as Nullable in c#?</p>
<pre><code>struct MyStruct {
int _yer, _ner;
public MyStruct() {
_yer = Nullable<int>; //This does not work.
_ner = 0;
}
}
</code></pre>
|
[
{
"answer_id": 204326,
"author": "Joel Cunningham",
"author_id": 5360,
"author_profile": "https://Stackoverflow.com/users/5360",
"pm_score": 1,
"selected": false,
"text": "int? yer;\n"
},
{
"answer_id": 204327,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 0,
"selected": false,
"text": "struct MyStruct\n{\n private int? _yer, _ner;\n public MyStruct(int? yer, int? ner)\n {\n _yer = yer;\n _ner = ner;\n }\n}\n"
},
{
"answer_id": 204329,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 4,
"selected": true,
"text": " int? _yer;\n int _ner;\n\n public MyStruct(int? ver, int ner) {\n\n _yer = ver;\n _ner = ner;\n }\n}\n Nullable<int> _yer;\n int _ner;\n\n public MyStruct(Nullable<int> ver, int ner) {\n\n _yer = ver;\n _ner = ner;\n }\n}\n error CS0568: Structs cannot contain explicit parameterless constructors\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17211/"
] |
204,334
|
<p><strong>What?</strong></p>
<p>I have a DLGTEMPLATE loaded from a resource DLL, how can I change the strings assigned to the controls at runtime programmatically?</p>
<p>I want to be able to do this before the dialog is created, such that I can tell that the strings on display came from the resource DLL, and not from calls to SetWindowText when the dialog is initialized.</p>
<p>Google has found examples of creating DLGTEMPLATE in code, or twiddling simple style bits but nothing on editing the strings in memory.</p>
<p><strong>How?</strong></p>
<p>I am doing this by hooking the Dialog/Property Sheet creation API's. Which gives me access to the DLGTEMPLATE before the actual dialog is created and before it has a HWND. </p>
<p><strong>Why?</strong></p>
<p>I want to be able to do runtime localization, and localization testing. I already have this implemented for loading string (including the MFC 7.0 wrapper), menus and accelerator tables, but I am struggling to handle dialog/property sheet creation.</p>
<p>Code examples would be the perfect answer, ideally a class to wrap around the DLGTEMPLATE, if I work out my own solution I will post it.</p>
|
[
{
"answer_id": 205935,
"author": "Aidan Ryan",
"author_id": 1042,
"author_profile": "https://Stackoverflow.com/users/1042",
"pm_score": 1,
"selected": false,
"text": "CMyDialog::OnInitDialog()\n{\n ::EnumChildWindows(\n this->GetSafeHwnd(),\n CMyDialog::UpdateControlText,\n (LPARAM)this )\n}\n\nBOOL CALLBACK CMyDialog::UpdateControlText( HWND hWnd, LPARAM lParam )\n{\n CMyDialog* pDialog = (CMyDialog*)lParam;\n CWnd* pChildWnd = CWnd::FromHandle( hWnd );\n\n int ctrlId = pChildWnd->GetDlgCtrlID();\n if (ctrlId)\n {\n CString curWindowText;\n pChildWnd->GetWindowText( curWindowText );\n if (!curWindowText.IsEmpty())\n {\n CString newWindowText = // some look up\n pChildWnd->SetWindowText( newWindowText );\n }\n }\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204334",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2387/"
] |
204,343
|
<p>In .net, is there a way using reflection to determine if a parameter on a method is marked with the "params" keyword?</p>
|
[
{
"answer_id": 204377,
"author": "Nathan Baulch",
"author_id": 8799,
"author_profile": "https://Stackoverflow.com/users/8799",
"pm_score": 5,
"selected": false,
"text": "ParamArrayAttribute ParameterInfo //use string.Format(str, args) as a test\nvar method = typeof(string).GetMethod(\"Format\", new[] {typeof(string), typeof(object[])});\nvar param = method.GetParameters()[1];\nConsole.WriteLine(Attribute.IsDefined(param, typeof(ParamArrayAttribute)));\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204343",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13943/"
] |
204,360
|
<p>What's the term for this design?</p>
<pre><code>object.method1().method2().method3()
</code></pre>
<p>..when all methods return *this?</p>
<p>I found the term for this a while ago, but lost it meanwhile.
I have no clue how to search for this on google :)
Also if anyone can think of a better title for the question, feel free to change it.</p>
<p>Thanks</p>
<p><strong>Update-Gishu</strong>: After reading about it, I feel that your question is misleading w.r.t. code snippet provided.. (Feel free to rollback)</p>
<p><em>Method Chaining</em></p>
<pre><code>object.method1().method2().method3()
</code></pre>
<p><em>Fluent Interfaces</em></p>
<pre><code>private void makeFluent(Customer customer) {
customer.newOrder()
.with(6, "TAL")
.with(5, "HPK").skippable()
.with(3, "LGV")
.priorityRush();
}
</code></pre>
|
[
{
"answer_id": 28081241,
"author": "Barry",
"author_id": 2069064,
"author_profile": "https://Stackoverflow.com/users/2069064",
"pm_score": 2,
"selected": false,
"text": "vector<int> v; \nv += 1,2,3,4,5,6,7,8,9;\n\ntypedef pair< string,string > str_pair;\ndeque<str_pair> deq;\npush_front( deq )( \"foo\", \"bar\")( \"boo\", \"far\" ); \n FluentGlutApp(argc, argv)\n .withDoubleBuffer().withRGBA().withAlpha().withDepth()\n .at(200, 200).across(500, 500)\n .named(\"My OpenGL/GLUT App\")\n .create();\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21240/"
] |
204,363
|
<p>Is it possible to create a simple 3D model (for example in 3DS MAX) and then import it to Android?</p>
|
[
{
"answer_id": 741926,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "gl.glFrontFace(GL10.GL_CCW);\n"
},
{
"answer_id": 742087,
"author": "Maciej Gryka",
"author_id": 3037,
"author_profile": "https://Stackoverflow.com/users/3037",
"pm_score": 6,
"selected": true,
"text": "int vertices[] = context.getResources().getIntArray(R.array.vertices); gl.glDrawElements(GL10.GL_TRIANGLES, 212*6, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);"
},
{
"answer_id": 12611525,
"author": "Ievgen",
"author_id": 508330,
"author_profile": "https://Stackoverflow.com/users/508330",
"pm_score": 2,
"selected": false,
"text": "glDisable(GL_TEXTURE_2D);\nglEnable(GL_LIGHTING);\nglEnable(GL_NORMALIZE);\n\nGLfloat Material_1[] = { 0.498039f, 0.498039f, 0.498039f, 1.000000f };\n\nglBegin(GL_TRIANGLES);\n\n glMaterialfv(GL_FRONT,GL_DIFFUSE,Material_1\n glNormal3d(0.452267,0.000000,0.891883);\n glVertex3d(5.108326,1.737655,2.650969);\n glVertex3d(9.124107,-0.002484,0.614596);\n glVertex3d(9.124107,4.039649,0.614596);\n\nglEnd();\n Point3 Object1_vertex[] = {\n {5.108326,1.737655,2.650969},\n {9.124107,-0.002484,0.614596},\n {9.124107,4.039649,0.614596}};\nlong Object1_face[] = {\n 3,0,1,2,\n 3,3,4,5\n 3,6,3,5};\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3037/"
] |
204,369
|
<p>Recently our company has started measuring the cyclomatic complexity (CC) of the functions in our code on a weekly basis, and reporting which functions have improved or worsened. So we have started paying a lot more attention to the CC of functions.</p>
<p>I've read that CC could be informally calculated as 1 + the number of decision points in a function (e.g. if statement, for loop, select etc), or also the number of paths through a function...</p>
<p>I understand that the easiest way of reducing CC is to use the Extract Method refactoring repeatedly...</p>
<p>There are somethings I am unsure about, e.g. what is the CC of the following code fragments?</p>
<p>1)</p>
<pre><code>for (int i = 0; i < 3; i++)
Console.WriteLine("Hello");
</code></pre>
<p>And</p>
<pre><code>Console.WriteLine("Hello");
Console.WriteLine("Hello");
Console.WriteLine("Hello");
</code></pre>
<p>They both do the same thing, but does the first version have a higher CC because of the for statement?</p>
<p>2)</p>
<pre><code>if (condition1)
if (condition2)
if (condition 3)
Console.WriteLine("wibble");
</code></pre>
<p>And</p>
<pre><code>if (condition1 && condition2 && condition3)
Console.WriteLine("wibble");
</code></pre>
<p>Assuming the language does short-circuit evaluation, such as C#, then these two code fragments have the same effect... but is the CC of the first fragment higher because it has 3 decision points/if statements?</p>
<p>3)</p>
<pre><code>if (condition1)
{
Console.WriteLine("one");
if (condition2)
Console.WriteLine("one and two");
}
</code></pre>
<p>And</p>
<pre><code>if (condition3)
Console.WriteLine("fizz");
if (condition4)
Console.WriteLine("buzz");
</code></pre>
<p>These two code fragments do different things, but do they have the same CC? Or does the nested if statement in the first fragment have a higher CC? i.e. nested if statements are mentally more complex to understand, but is that reflected in the CC?</p>
|
[
{
"answer_id": 204415,
"author": "PW.",
"author_id": 927,
"author_profile": "https://Stackoverflow.com/users/927",
"pm_score": 0,
"selected": false,
"text": "if (condition1 && condition2 && condition3)\n Console.WriteLine(\"wibble\");\n bool/boolean theWeatherIsFine = condition1 && condition2 && condition3;\n\nif (theWeatherIsFine)\n Console.WriteLine(\"wibble\");\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7261/"
] |
204,396
|
<p>When returning objects from a class, when is the right time to release the memory?</p>
<p>Example,</p>
<pre><code>class AnimalLister
{
public:
Animal* getNewAnimal()
{
Animal* animal1 = new Animal();
return animal1;
}
}
</code></pre>
<p>If i create an instance of Animal Lister and get Animal reference from it, then where am i supposed to delete it?</p>
<pre><code>int main() {
AnimalLister al;
Animal *a1, *a2;
a1 = al.getNewAnimal();
a2 = al.getNewAnimal();
}
</code></pre>
<p>The problem here is AnimalLister doesnot have a way to track the list of Animals Created, so how do i change the logic of such code to have a way to delete the objects created.</p>
|
[
{
"answer_id": 204408,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 5,
"selected": false,
"text": "std::tr1::shared_ptr boost::shared_ptr Animal* std::tr1::shared_ptr<Animal>"
},
{
"answer_id": 204410,
"author": "Igor Semenov",
"author_id": 11401,
"author_profile": "https://Stackoverflow.com/users/11401",
"pm_score": 3,
"selected": false,
"text": "std::auto_ptr< Animal> getNewAnimal() \n{\n std::auto_ptr< Animal > animal1( new Animal() );\n return animal1;\n}\n"
},
{
"answer_id": 204466,
"author": "gbjbaanb",
"author_id": 13744,
"author_profile": "https://Stackoverflow.com/users/13744",
"pm_score": 3,
"selected": false,
"text": "class AnimalLister \n{\nAnimal getAnimal() { Animal a; return a; }; // uses fast Return Value Optimisation\n};\n\nAnimal myownanimal = AnimalLister.getAnimal(); // copy ctors into your Animal object\n"
},
{
"answer_id": 204542,
"author": "martinsb",
"author_id": 837,
"author_profile": "https://Stackoverflow.com/users/837",
"pm_score": 2,
"selected": false,
"text": "AnimalLister lister;\nAnimal* a = lister.getNewAnimal();\na->sayMeow();\ndelete a;\n"
},
{
"answer_id": 418252,
"author": "Eclipse",
"author_id": 8701,
"author_profile": "https://Stackoverflow.com/users/8701",
"pm_score": 5,
"selected": false,
"text": "class AnimalLister \n{\npublic:\n Animal getNewAnimal() \n {\n return Animal();\n }\n};\n\nint main() {\n AnimalLister al;\n Animal a1 = al.getNewAnimal();\n Animal a2 = al.getNewAnimal();\n}\n Animal Animal Animal Animal shared_ptr<Animal> class AnimalLister \n{\npublic:\n shared_ptr<Animal> getNewAnimal() \n {\n return new Animal();\n }\n};\n\nint main() {\n AnimalLister al;\n shared_ptr<Animal> a1 = al.getNewAnimal();\n shared_ptr<Animal> a2 = al.getNewAnimal();\n}\n Animal Animal AnimalLister class AnimalLister \n{\n vector<Animal *> Animals;\n\npublic:\n Animal *getNewAnimal() \n {\n Animals.push_back(NULL);\n Animals.back() = new Animal();\n return Animals.back();\n }\n\n ~AnimalLister()\n {\n for(vector<Animal *>::iterator iAnimal = Animals.begin(); iAnimal != Animals.end(); ++iAnimal)\n delete *iAnimal;\n }\n};\n\nint main() {\n AnimalLister al;\n Animal *a1 = al.getNewAnimal();\n Animal *a2 = al.getNewAnimal();\n} // All the animals get deleted when al goes out of scope.\n Animal Animal delete Animal"
},
{
"answer_id": 524697,
"author": "BigSandwich",
"author_id": 26983,
"author_profile": "https://Stackoverflow.com/users/26983",
"pm_score": 0,
"selected": false,
"text": "class Animal\n{\n...\nprivate:\n //only let the lister create or delete animals.\n Animal() { ... }\n ~Animal() { ... } \nfriend class AnimalLister;\n...\n}\n\nclass AnimalLister \n{\n static s_count = 0;\n\npublic:\n ~AnimalLister() { ASSERT(s_count == 0); } //warn if all animals didn't get cleaned up\n\n Animal* NewAnimal() \n {\n ++count;\n return new Animal();\n }\n\n void FreeAnimal(Animal* a)\n {\n delete a;\n --s_count;\n }\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28202/"
] |
204,398
|
<p>Let's have the following class hierarchy:</p>
<pre><code>public class ParentClass implements SomeInterface {
}
public class ChildClass extends ParentClass {
}
</code></pre>
<p>Then let's have these two instances:</p>
<pre><code>ParentClass parent;
ChildClass child;
</code></pre>
<p>Then we have the following TRUE statements</p>
<pre><code>(parent instanceof SomeInterface) == true
(child instanceof SomeInterface) == true
</code></pre>
<p>Is it possible to unimplement the SomeInterface in the ChildClass, so when we check with the instanceof operator it returns false?</p>
<p>If not possible, is there a workaround?</p>
|
[
{
"answer_id": 204418,
"author": "user28205",
"author_id": 28205,
"author_profile": "https://Stackoverflow.com/users/28205",
"pm_score": 5,
"selected": true,
"text": "interface SomeInterface {}\nabstract class AbstractParentClass {}\nclass ParentClass extends AbstractParentClass implements SomeInterface {}\nclass ChildClass extends AbstractParentClass {}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/446104/"
] |
204,406
|
<p>I am trying to convert all DateTime values in a DataTable to strings. Here is the method I use:</p>
<pre><code>private static void ConvertDateTimesToStrings(DataTable dataTable)
{
if (dataTable == null)
{
return;
}
for (int rowIndex = 0; rowIndex < dataTable.Rows.Count; rowIndex++ )
{
for (int i = 0; i < dataTable.Columns.Count; i++)
{
DateTime dateTime;
try
{
dateTime = (DateTime)dataTable.Rows[rowIndex][i];
}
catch (InvalidCastException)
{
continue;
}
dataTable.Rows[rowIndex][i] = dateTime.ToString("dd.MM.yyyy hh:mm:ss");
}
}
}
</code></pre>
<p>After this line works:</p>
<pre><code>dataTable.Rows[rowIndex][i] = dateTime.ToString("dd.MM.yyyy hh:mm:ss");
</code></pre>
<p>I check the value of dataTable.Rows[rowIndex][i] and see it is still a DateTime, not a string. Why does this happen and how can I solve this?</p>
<p>Edit: I am trying to do this because I am fighting an api and unfortunately I do not have the choice of which component to use.</p>
|
[
{
"answer_id": 204419,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 4,
"selected": false,
"text": "if (dataTable.Columns[0].DataType == typeof(DateTime))\n{\n}\n"
},
{
"answer_id": 204507,
"author": "Eduardo Campañó",
"author_id": 12091,
"author_profile": "https://Stackoverflow.com/users/12091",
"pm_score": 1,
"selected": false,
"text": "foreach (DataColumn column in dataTable.Columns) {\n if (column.DataType == typeof(DateTime)) {\n dataTable.Columns.Add(column.ColumnName + \"_string\", typeof(string));\n }\n}\n\nforeach (DataRow row in dataTable.Rows) {\n foreach (DataColumn column in dataTable.Columns) {\n if (column.DataType == typeof(DateTime)) {\n row[column.ColumnName + \"_string\"] = row[column.ColumnName].ToString(\"dd.MM.yyyy hh:mm:ss\");\n }\n }\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204406",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31505/"
] |
204,444
|
<p>As can be seen in the Mozilla changlog for JavaScript 1.7 they have added destructuring assignment. Sadly I'm not very fond of the syntax (why write a and b twice?):</p>
<pre><code>var a, b;
[a, b] = f();
</code></pre>
<p>Something like this would have been a lot better:</p>
<pre><code>var [a, b] = f();
</code></pre>
<p>That would still be backwards compatible. Python-like destructuring would not be backwards compatible.</p>
<p>Anyway the best solution for JavaScript 1.5 that I have been able to come up with is:</p>
<pre><code>function assign(array, map) {
var o = Object();
var i = 0;
$.each(map, function(e, _) {
o[e] = array[i++];
});
return o;
}
</code></pre>
<p>Which works like:</p>
<pre><code>var array = [1,2];
var _ = assign[array, { var1: null, var2: null });
_.var1; // prints 1
_.var2; // prints 2
</code></pre>
<p>But this really sucks because _ has no meaning. It's just an empty shell to store the names. But sadly it's needed because JavaScript doesn't have pointers. On the plus side you can assign default values in the case the values are not matched. Also note that this solution doesn't try to slice the array. So you can't do something like <code>{first: 0, rest: 0}</code>. But that could easily be done, if one wanted that behavior.</p>
<p>What is a better solution?</p>
|
[
{
"answer_id": 205254,
"author": "Ates Goral",
"author_id": 23501,
"author_profile": "https://Stackoverflow.com/users/23501",
"pm_score": 2,
"selected": false,
"text": "window[\"foo\"] = \"bar\";\nalert(foo); // Gives \"bar\"\n function destructure(dest, src) { \n dest = dest.split(\",\"); \n\n for (var i = 0; i < src.length; i++) { \n window[dest[i]] = src[i]; \n } \n} \n\nvar arr = [42, 66]; \n\ndestructure(\"var1,var2\", arr); \n\nalert(var1); // Gives 42\nalert(var2); // Gives 66\n"
},
{
"answer_id": 206566,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 6,
"selected": true,
"text": "var [a, b] = f() with() var array = [1,2];\nwith (assign(array, { var1: null, var2: null }))\n{\n var1; // == 1\n var2; // == 2\n}\n"
},
{
"answer_id": 18805777,
"author": "Eamonn O'Brien-Strain",
"author_id": 978525,
"author_profile": "https://Stackoverflow.com/users/978525",
"pm_score": 0,
"selected": false,
"text": "function divMod1(a, b) {\n return [ Math.floor(a / b), a % b ];\n}\n\nvar _ = divMod1(11, 3);\nvar div = _[0];\nvar mod = _[1];\nalert(\"(1) div=\" + div + \", mod=\" + mod );\n function divMod2(a, b, callback) {\n callback(Math.floor(a / b), a % b);\n}\n\ndivMod2(11, 3, function(div, mod) {\n alert(\"(2) div=\" + div + \", mod=\" + mod );\n});\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204444",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13995/"
] |
204,461
|
<p>Suppose you have:</p>
<pre><code>A-B-C
</code></pre>
<p>Now your build/test fails. The fix should be merged in A.
My current work-flow is like this:</p>
<pre><code>$ git commit -m "fixA"
A-B-C-fixA
$ git rebase -i A~1
</code></pre>
<p>And squash fixA in A, result in: </p>
<pre><code>A'-B-C
</code></pre>
<p>Is there a command to do something like:</p>
<pre><code>A-B-C + (index with fix for A)
$ git commit -supperdupper A
</code></pre>
<p>Result:</p>
<pre><code>A'-B-C
</code></pre>
|
[
{
"answer_id": 4607280,
"author": "Jo Liss",
"author_id": 525872,
"author_profile": "https://Stackoverflow.com/users/525872",
"pm_score": 5,
"selected": true,
"text": "--autosquash rebase --fixup --squash commit git/Documentation/RelNotes $ grep -i -A1 autosquash\\\\\\|fixup *\n1.7.0.txt: * \"git rebase -i\" learned new action \"fixup\" that squashes the change\n1.7.0.txt- but does not affect existing log message.\n--\n1.7.0.txt: * \"git rebase -i\" also learned --autosquash option that is useful\n1.7.0.txt: together with the new \"fixup\" action.\n1.7.0.txt-\n--\n1.7.3.txt: * \"git rebase -i\" peeks into rebase.autosquash configuration and acts as\n1.7.3.txt: if you gave --autosquash from the command line.\n1.7.3.txt-\n--\n1.7.4.txt: * \"git commit\" learned --fixup and --squash options to help later invocation\n1.7.4.txt- of the interactive rebase.\n--\n1.7.4.txt: * \"git rebase --autosquash\" can use SHA-1 object names to name which\n1.7.4.txt: commit to fix up (e.g. \"fixup! e83c5163\").\n1.7.4.txt-\n"
},
{
"answer_id": 5538884,
"author": "lanoxx",
"author_id": 474034,
"author_profile": "https://Stackoverflow.com/users/474034",
"pm_score": 2,
"selected": false,
"text": "git rebase --interactive <3rd last commit>\n"
},
{
"answer_id": 14959746,
"author": "bkeepers",
"author_id": 262540,
"author_profile": "https://Stackoverflow.com/users/262540",
"pm_score": 3,
"selected": false,
"text": "git commit --fixup git commit --squash ~/.gitconfig [alias]\n fixup = !sh -c 'REV=$(git rev-parse $1) && git commit --fixup $@ && git rebase -i --autosquash $REV^' -\n squash = !sh -c 'REV=$(git rev-parse $1) && git commit --squash $@ && git rebase -i --autosquash $REV^' -\n $ git commit -am 'bad commit'\n$ git commit -am 'good commit'\n\n$ git add . # Stage changes to correct the bad commit\n$ git fixup HEAD^ # HEAD^ can be replaced by the SHA of the bad commit\n"
},
{
"answer_id": 24656286,
"author": "Mika Eloranta",
"author_id": 1058622,
"author_profile": "https://Stackoverflow.com/users/1058622",
"pm_score": 2,
"selected": false,
"text": "--fixup --squash git-fixup git fixup git fixup -a --fixup git fixup -r git rebase --autosquash git log --fixup"
},
{
"answer_id": 36317398,
"author": "Oktalist",
"author_id": 1639256,
"author_profile": "https://Stackoverflow.com/users/1639256",
"pm_score": 0,
"selected": false,
"text": "commit --fixup rebase --autosquash A-B-C fixup! git diff git blame git commit --fixup fixup! foo(bar()); foo fox bar baz git"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1277510/"
] |
204,465
|
<p>I'm planning to develop an app for the iPhone and that app would have to access a couple of SOAP services. While doing some basic checking in the iPhone SDK I was not able to find any support for accessing SOAP services, a bit of Googling lead to the conclusion that there is no support for SOAP in the iPhone SDK. </p>
<p>So if I do want to build that app I'll need to come up with a approach to access SOAP services from the iPhone. What would be the best approach? Any best practices? Did someone already write a library using the functionality that is present in the iPhone SDK to access SOAP services?</p>
<p>(Since the service I need to access is exposed by another party and they only expose it as SOAP, it's unfortunately not an option to switch to another type of interface (e.g. REST based API).</p>
<p>Gero</p>
|
[
{
"answer_id": 14586865,
"author": "Bennya",
"author_id": 1569335,
"author_profile": "https://Stackoverflow.com/users/1569335",
"pm_score": 2,
"selected": false,
"text": "SampleServiceProxy *proxy = [[SampleServiceProxy alloc]initWithUrl:@\"YOUR\n URL\" AndDelegate:self];\n\n[proxy GetDouble];\n[proxy GetEnum];\n[proxy getEnum:kTestEnumTestEnum2];\n[proxy GetInt16];\n[proxy GetInt32];\n[proxy GetInt64];\n[proxy GetString];\n[proxy getListStrings];\n"
},
{
"answer_id": 47969605,
"author": "Sunil M.",
"author_id": 7348569,
"author_profile": "https://Stackoverflow.com/users/7348569",
"pm_score": 2,
"selected": false,
"text": " func callSOAPWSToGetData() {\n\n let strSOAPMessage =\n \"<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?>\" +\n \"<soap:Envelope xmlns:xsi=\\\"http://www.w3.org/2001/XMLSchema-instance\\\" xmlns:xsd=\\\"http://www.w3.org/2001/XMLSchema\\\" xmlns:soap=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\">\" +\n \"<soap:Body>\" +\n \"<CelsiusToFahrenheit xmlns=\\\"http://www.yourapi.com/webservices/\\\">\" +\n \"<Celsius>50</Celsius>\" +\n \"</CelsiusToFahrenheit>\" +\n \"</soap:Body>\" +\n \"</soap:Envelope>\"\n\n guard let url = URL.init(string: \"http://www.example.org\") else {\n return\n }\n var request = URLRequest.init(url: url)\n let length = (strSOAPMessage as NSString).length\n request.addValue(\"application/soap+xml; charset=utf-8\", forHTTPHeaderField: \"Content-Type\")\n request.addValue(\"http://www.yourapi.com/webservices/CelsiusToFahrenheit\", forHTTPHeaderField: \"SOAPAction\")\n request.addValue(String(length), forHTTPHeaderField: \"Content-Length\")\n request.httpMethod = \"POST\"\n request.httpBody = strSOAPMessage.data(using: .utf8)\n\n let config = URLSessionConfiguration.default\n let session = URLSession(configuration: config)\n let task = session.dataTask(with: request) { (data, response, error) in\n guard let responseData = data else {\n print(\"Error: did not receive data\")\n return\n }\n guard error == nil else {\n print(\"error calling GET on /todos/1\")\n print(error ?? \"\")\n return\n }\n print(responseData)\n let strData = String.init(data: responseData, encoding: .utf8)\n print(strData ?? \"\")\n }\n task.resume()\n }\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25277/"
] |
204,467
|
<p>I have trouble using Perl grep() with a string that <em>may</em> contain chars that are interpreted as regular expressions quantifiers. </p>
<p>I got the following error when the grep pattern is "g++" because the '+' symbols
are interpreted as quantifiers. Here is the output of for program that follows:</p>
<pre><code>1..3
ok 1 - grep, pattern not found
ok 2 - grep, pattern found
Nested quantifiers in regex; marked by <-- HERE
in m/g++ <-- HERE / at escape_regexp_quantifier.pl line 8.
</code></pre>
<p>Is there a modifier I could use to indicate to grep that the quantifiers shall be ignored,
or is there a function that would escape the quantifiers ?</p>
<pre><code>#! /usr/bin/perl
sub test_grep($)
{
my $filter = shift;
my @output = ("-r-xr-xr-x 3 root bin 122260 Jan 23 2005 gcc",
"-r-xr-xr-x 4 root bin 124844 Jan 23 2005 g++");
return grep (!/$filter/, @output);
}
use Test::Simple tests => 2;
ok(test_grep("foo"), "grep, pattern not found");
ok(test_grep("gcc"), "grep, pattern found");
ok(test_grep("g++"), "grep, pattern found");
</code></pre>
<p>PS: in addition to the answer question above, I welcome any feedback on Perl usage in the above as I'm still learning. Thanks</p>
|
[
{
"answer_id": 204474,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 6,
"selected": true,
"text": "\\Q return grep (!/\\Q$filter/, @output);\n"
},
{
"answer_id": 204943,
"author": "pjf",
"author_id": 19422,
"author_profile": "https://Stackoverflow.com/users/19422",
"pm_score": 2,
"selected": false,
"text": "Perl::Critic Perl::Critic::Policy::"
},
{
"answer_id": 205144,
"author": "Tanktalus",
"author_id": 23512,
"author_profile": "https://Stackoverflow.com/users/23512",
"pm_score": 2,
"selected": false,
"text": "ok(test_grep(qr/foo/), \"grep, pattern not found\");\nok(test_grep(qr/gcc/), \"grep, pattern found\");\nok(test_grep(qr/g\\+\\+/), \"grep, pattern found\");\n ok(test_grep(qr/\\Qg++/), \"grep, pattern found\");\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18804/"
] |
204,468
|
<p>So I have the following:</p>
<pre><code>public class Singleton
{
private Singleton(){}
public static readonly Singleton instance = new Singleton();
public string DoSomething(){ ... }
public string DoSomethingElse(){ ... }
}
</code></pre>
<p>Using reflection how can I invoke the DoSomething Method? </p>
<p>Reason I ask is because I store the method names in XML and dynamically create the UI. For example I'm dynamically creating a button and telling it what method to call via reflection when the button is clicked. In some cases it would be DoSomething or in others it would be DoSomethingElse.</p>
|
[
{
"answer_id": 204508,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 5,
"selected": true,
"text": "string methodName = \"DoSomething\"; // e.g. read from XML\nMethodInfo method = typeof(Singleton).GetMethod(methodName);\nFieldInfo field = typeof(Singleton).GetField(\"instance\",\n BindingFlags.Static | BindingFlags.Public);\nobject instance = field.GetValue(null);\nmethod.Invoke(instance, Type.EmptyTypes);\n"
},
{
"answer_id": 2205668,
"author": "nasser",
"author_id": 266859,
"author_profile": "https://Stackoverflow.com/users/266859",
"pm_score": 2,
"selected": false,
"text": "static void Main(string[] args)\n {\n Assembly asm = null;\n string assemblyPath = @\"C:\\works\\...\\StaticMembers.dll\" \n string classFullname = \"StaticMembers.MySingleton\";\n string doSomethingMethodName = \"DoSomething\";\n string doSomethingElseMethodName = \"DoSomethingElse\";\n\n asm = Assembly.LoadFrom(assemblyPath);\n if (asm == null)\n throw new FileNotFoundException();\n\n\n Type[] types = asm.GetTypes();\n Type theSingletonType = null;\n foreach(Type ty in types)\n {\n if (ty.FullName.Equals(classFullname))\n {\n theSingletonType = ty;\n break;\n }\n }\n if (theSingletonType == null)\n {\n Console.WriteLine(\"Type was not found!\");\n return;\n }\n MethodInfo doSomethingMethodInfo = \n theSingletonType.GetMethod(doSomethingMethodName );\n\n\n FieldInfo field = theSingletonType.GetField(\"instance\", \n BindingFlags.Static | BindingFlags.Public);\n\n object instance = field.GetValue(null);\n\n string msg = (string)doSomethingMethodInfo.Invoke(instance, Type.EmptyTypes);\n\n Console.WriteLine(msg);\n\n MethodInfo somethingElse = theSingletonType.GetMethod(\n doSomethingElseMethodName );\n msg = (string)doSomethingElse.Invoke(instance, Type.EmptyTypes);\n Console.WriteLine(msg);}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6204/"
] |
204,476
|
<p>What is the correct (most efficient) way to define the <code>main()</code> function in C and C++ — <code>int main()</code> or <code>void main()</code> — and why? And how about the arguments?
If <code>int main()</code> then <code>return 1</code> or <code>return 0</code>?</p>
<hr>
<p><em>There are numerous duplicates of this question, including:</em></p>
<ul>
<li><a href="https://stackoverflow.com/questions/2108192/what-are-the-valid-signatures-for-cs-main-function/">What are the valid signatures for C's <code>main()</code> function?</a></li>
<li><a href="https://stackoverflow.com/questions/17715008/the-return-type-of-main-function/">The return type of <code>main()</code> function</a></li>
<li><a href="https://stackoverflow.com/questions/636829/difference-between-void-main-and-int-main">Difference between <code>void main()</code> and <code>int main()</code>?</a></li>
<li><a href="https://stackoverflow.com/questions/1621574/mains-signature-in-c"><code>main()</code>'s signature in C++</a></li>
<li><a href="https://stackoverflow.com/questions/4207134/what-is-the-proper-declaration-of-main">What is the proper declaration of <code>main()</code>?</a> — For C++, with a very good answer indeed.</li>
<li><a href="https://stackoverflow.com/questions/8692120/styles-of-main-functions-in-c">Styles of <code>main()</code> functions in C</a></li>
<li><a href="https://stackoverflow.com/questions/10915713/return-type-of-main-method-in-c">Return type of <code>main()</code> method in C</a></li>
<li><a href="https://stackoverflow.com/questions/9356510/int-main-vs-void-main-in-c"><code>int main()</code> vs <code>void main()</code> in C</a></li>
</ul>
<p>Related:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/5191965/c-int-mainint-argc-char-argv">C++ — <code>int main(int argc, char **argv)</code></a></li>
<li><a href="https://stackoverflow.com/questions/5217395/c-int-mainint-argc-char-argv">C++ — <code>int main(int argc, char *argv[])</code></a></li>
<li><a href="https://stackoverflow.com/questions/10321435/is-char-envp-as-a-third-argument-to-main-portable">Is <code>char *envp[]</code> as a third argument to <code>main()</code> portable?</a></li>
<li><a href="https://stackoverflow.com/questions/18402853/must-the-int-main-function-return-a-value-in-all-compilers">Must the <code>int main()</code> function return a value in all compilers?</a></li>
<li><a href="https://stackoverflow.com/questions/5296163/why-is-the-type-of-the-main-function-in-c-and-c-left-to-the-user-to-define">Why is the type of the <code>main()</code> function in C and C++ left to the user to define?</a></li>
<li><a href="https://stackoverflow.com/questions/22239/why-does-int-main-compile">Why does <code>int main(){}</code> compile?</a></li>
<li><a href="https://stackoverflow.com/questions/26470912/legal-definitions-of-main-in-c14">Legal definitions of <code>main()</code> in C++14?</a></li>
</ul>
|
[
{
"answer_id": 204483,
"author": "workmad3",
"author_id": 16035,
"author_profile": "https://Stackoverflow.com/users/16035",
"pm_score": 10,
"selected": true,
"text": "main main void main() main int main()\n int main(int argc, char* argv[])\n int main(int argc, char** argv)\n int main() return 0; main main()"
},
{
"answer_id": 204530,
"author": "dmityugov",
"author_id": 3232,
"author_profile": "https://Stackoverflow.com/users/3232",
"pm_score": 6,
"selected": false,
"text": "main() EXIT_SUCCESS EXIT_FAILURE stdlib.h"
},
{
"answer_id": 207992,
"author": "Chris Young",
"author_id": 9417,
"author_profile": "https://Stackoverflow.com/users/9417",
"pm_score": 8,
"selected": false,
"text": "main() int main(void)\nint main(int argc, char **argv)\n int main(int argc, char *argv[]) int int main() int main(int argc, char *argv[], char *envp[]) 0 EXIT_SUCCESS EXIT_FAILURE main() return main() main() return 0 main()"
},
{
"answer_id": 5260799,
"author": "phoxis",
"author_id": 702361,
"author_profile": "https://Stackoverflow.com/users/702361",
"pm_score": 2,
"selected": false,
"text": "int main (void) { .. return 0; .. }"
},
{
"answer_id": 6554135,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "main() zero"
},
{
"answer_id": 8642388,
"author": "Jeegar Patel",
"author_id": 775964,
"author_profile": "https://Stackoverflow.com/users/775964",
"pm_score": 3,
"selected": false,
"text": "main() return 1? return 0?\n int main() } return 0 return 1 main() $ ./a.out\n$ echo $?\n $? main() return 0"
},
{
"answer_id": 18721336,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 7,
"selected": false,
"text": "main int int main(void) { /* ... */ }\n argc argv int main(int argc, char *argv[]) { /* ... */ }\n argc argv[argc] argc argv[0] argv[argc-1] argc argv[0] argv[0][0] argc argv[1] argv[argc-1] argc argv argv int int argv char **argv main() main int main exit main } main int main 0 EXIT_FAILURE EXIT_SUCCESS <stdlib.h> main() exit status EXIT_SUCCESS status EXIT_FAILURE int main() { /* ... */ }\n int main(int argc, char* argv[]) { /* ... */ }\n argc argc argv[0] argv[argc-1] argv[0] \"\" argc argv[argc] argv main main std::exit return 0;\n int main exit EXIT_SUCCESS EXIT_FAILURE <cstdlib> int main(int argc, char **argv, char **envp) { ... }\n extern char **environ; char *envp[] char int main();\n int main(int argc, char *argv[], char *envp[]);\n main wmain void main wmain main wmain void exit void main() main() char **envp wmain() void main() main <float.h> <iso646.h> <limits.h> <stdalign.h> <stdarg.h> <stdbool.h> <stddef.h> <stdint.h> <stdnoreturn.h> #ifdef __STDC_IEC_559__ /* FE_UPWARD defined */\n /* ... */\n fesetround(FE_UPWARD);\n /* ... */\n#endif\n <stdarg.h> <cstdlib> abort atexit at_quick_exit exit quick_exit Subclause Header(s)\n <ciso646>\n18.2 Types <cstddef>\n18.3 Implementation properties <cfloat> <limits> <climits>\n18.4 Integer types <cstdint>\n18.5 Start and termination <cstdlib>\n18.6 Dynamic memory management <new>\n18.7 Type identification <typeinfo>\n18.8 Exception handling <exception>\n18.9 Initializer lists <initializer_list>\n18.10 Other runtime support <cstdalign> <cstdarg> <cstdbool>\n20.9 Type traits <type_traits>\n29 Atomics <atomic>\n int main() int main(void) int main() int main() int main() sizeof _Alignof #include <stddef.h>\n\nsize_t fsize3(int n)\n{\n char b[n+3]; // variable length array\n return sizeof b; // execution time sizeof\n}\nint main()\n{\n size_t size;\n size = fsize3(10); // fsize3 returns 13\n return 0;\n}\n int main(){ … } main() main() main() int i = 0;\nint main()\n{\n if (i++ < 10)\n main(i, i * i);\n return 0;\n}\n -Wstrict-prototypes main(void)"
},
{
"answer_id": 28443025,
"author": "rbaleksandar",
"author_id": 1559401,
"author_profile": "https://Stackoverflow.com/users/1559401",
"pm_score": 2,
"selected": false,
"text": "$ grep order myfile\n $ echo $?\n$ 0\n $ grep foo myfile\n$ echo $?\n$ 1\n $ grep foo myfile\n$ CHECK=$?\n$ [ $CHECK -eq 0] && echo 'Match found'; [ $CHECK -ne 0] && echo 'No match was found'\n$ No match was found\n"
},
{
"answer_id": 31263079,
"author": "Lundin",
"author_id": 584518,
"author_profile": "https://Stackoverflow.com/users/584518",
"pm_score": 6,
"selected": false,
"text": "int main (void)\nint main (int argc, char *argv[])\n\nmain (void)\nmain (int argc, char *argv[])\n/*... etc, similar forms with implicit int */\n int main (void)\nint main (int argc, char *argv[])\n/* or in some other implementation-defined manner. */\n main() int main() main() int main int main (void)\nint main (int argc, char *argv[])\n/* or in some other implementation-defined manner. */\n int main() () (void) int main ()\nint main (int argc, char *argv[])\n main() // implementation-defined name, or \nint main ()\nint main (int argc, char *argv[])\n int main ()\nint main (int argc, char *argv[])\n main() // implementation-defined name, or \nint main ()\nint main (int argc, char *argv[])\n int main(void) { /* ... */ } \n int main(int argc, char *argv[]) { /* ... */ }\n int main(void) { /* ... */ } \n int main(int argc, char *argv[]) { /* ... */ }\n } int main() { /* ... */ }\n int main(int argc, char* argv[]) { /* ... */ }\n"
},
{
"answer_id": 43558724,
"author": "Edward",
"author_id": 3191481,
"author_profile": "https://Stackoverflow.com/users/3191481",
"pm_score": 2,
"selected": false,
"text": "return 0 main return 0; main main exit main } main return; void return 0; main"
},
{
"answer_id": 46554052,
"author": "Steve Summit",
"author_id": 3923896,
"author_profile": "https://Stackoverflow.com/users/3923896",
"pm_score": 2,
"selected": false,
"text": "main() int main() int main() main() main() main main"
},
{
"answer_id": 64295173,
"author": "gsamaras",
"author_id": 2411320,
"author_profile": "https://Stackoverflow.com/users/2411320",
"pm_score": 0,
"selected": false,
"text": "int int main(void) { /* ... */ }\n argc argv int main(int argc, char *argv[]) { /* ... */ }\n int read_file(char filename[LEN]);"
},
{
"answer_id": 68975989,
"author": "Dwedit",
"author_id": 2300396,
"author_profile": "https://Stackoverflow.com/users/2300396",
"pm_score": -1,
"selected": false,
"text": "STATUS_ACCESS_VIOLATION (0xC0000005) main exit"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25632/"
] |
204,488
|
<p>I am trying to create a new contact using Dynamic Entity. The sample i found in CRM SDK had this code.</p>
<pre><code>// Set the properties of the contact using property objects.
StringProperty firstname = new StringProperty();
firstname.Name = "firstname";
firstname.Value = "Jesper";
StringProperty lastname = new StringProperty();
lastname.Name = "lastname";
lastname.Value = "Aaberg";
// Create the DynamicEntity object.
DynamicEntity contactEntity = new DynamicEntity();
// Set the name of the entity type.
contactEntity.Name = EntityName.contact.ToString();
// Set the properties of the contact.
contactEntity.Properties = new Property[] {firstname, lastname};
</code></pre>
<p>In my code i have the following implementation.</p>
<pre><code> StringProperty sp_Field1 = new StringProperty("Field1","Value1");
StringProperty sp_Field2 = new StringProperty("Field2","Value1");
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the DynamicEntity object.
DynamicEntity contactEntity = new DynamicEntity();
// Set the name of the entity type.
contactEntity.Name = EntityName.contact.ToString();
// Set the properties of the contact.
contactEntity.Properties = new Property[] {sp_Field1,sp_Field2};
</code></pre>
<p>I don't see much differences in the code. In the examples i found in the internet i have the same implementation as i found in SDK. But if i run the same i get the following error</p>
<blockquote>
<p>CS0029: Cannot implicitly convert type 'Microsoft.Crm.Sdk.StringProperty' to 'Microsoft.Crm.Sdk.PropertyCollection'</p>
</blockquote>
<p>I tried created a new variable of type PropertyCollection(one that belongs in mscrm namespace) and added the stringpropertys into that and passed it to the entity. </p>
<pre><code>Microsoft.Crm.Sdk.PropertyCollection propTest = new Microsoft.Crm.Sdk.PropertyCollection();
propTest.Add(sp_SSNNo);
propTest.Add(sp_FirstName);
contactEntity.Properties = new Property[] {propTest};
</code></pre>
<p>This gave me the following error</p>
<blockquote>
<p>CS0029: Cannot implicitly convert type 'Microsoft.Crm.Sdk.PropertyCollection' to 'Microsoft.Crm.Sdk.Property'</p>
</blockquote>
<p>I am sure its a minor typecasting error but i am not able to figure out where the error is. And moreover, even if it was a typecasting error why is it working for all the samples given in the internet and not for me. I tried getting the code sample to run but i am encountering the same conversion error. Please let me know if you need more info on this, any help on this would be appreciated.</p>
|
[
{
"answer_id": 204985,
"author": "SaaS Developer",
"author_id": 7215,
"author_profile": "https://Stackoverflow.com/users/7215",
"pm_score": 3,
"selected": true,
"text": " StringProperty sp_Field1 = new StringProperty(\"Field1\",\"Value1\");\n StringProperty sp_Field2 = new StringProperty(\"Field2\",\"Value1\");\n\n CrmService service = new CrmService();\n service.Credentials = System.Net.CredentialCache.DefaultCredentials;\n // Create the DynamicEntity object.\n DynamicEntity contactEntity = new DynamicEntity();\n // Set the name of the entity type.\n contactEntity.Name = EntityName.contact.ToString();\n\n // Set the properties of the contact.\n PropertyCollection properties = new PropertyCollection();\n properties.Add(sp_Field1);\n contactEntity.Properties = properties;\n"
},
{
"answer_id": 205046,
"author": "vikramjb",
"author_id": 2245,
"author_profile": "https://Stackoverflow.com/users/2245",
"pm_score": 1,
"selected": false,
"text": "contactEntity.Properties.Add(sp_SSNNo);\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2245/"
] |
204,505
|
<p>I use LINQ to Objects instructions on an ordered array.
Which operations shouldn't I do to be sure the order of the array is not changed?</p>
|
[
{
"answer_id": 204516,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 3,
"selected": false,
"text": "Dictionary<,>"
},
{
"answer_id": 204777,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 10,
"selected": true,
"text": " private static IEnumerable<TSource> DistinctIterator<TSource>\n (IEnumerable<TSource> source, IEqualityComparer<TSource> comparer)\n {\n Set<TSource> set = new Set<TSource>(comparer);\n foreach (TSource element in source)\n if (set.Add(element)) yield return element;\n }\n"
},
{
"answer_id": 24172557,
"author": "Curtis Yallop",
"author_id": 854342,
"author_profile": "https://Stackoverflow.com/users/854342",
"pm_score": 3,
"selected": false,
"text": "Enumerable List<T> Select Where GroupBy ToDictionary Distinct IGrouping<TKey, TElement> IGrouping<TKey, TElement> source IQueryable"
},
{
"answer_id": 56206435,
"author": "andrew pate",
"author_id": 2668869,
"author_profile": "https://Stackoverflow.com/users/2668869",
"pm_score": 0,
"selected": false,
"text": "mysqlresult.OrderBy(e=>e.SomeColumn)\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28216/"
] |
204,519
|
<p>I've got nutch and lucene setup to crawl and index some sites and I'd like to use a .net website instead of the JSP site that comes with nutch.</p>
<p>Can anyone recommend some solutions?</p>
<p>I've seen solutions where there was an app running on the index server which the .Net site used remoting to connect to.</p>
<p>Speed is a consideration obviously so can this still perform well?</p>
<p><strong>Edit:</strong> could NHibernate.Search work for this?</p>
<p><strong>Edit:</strong> We ended up going with Solr index servers being used by our ASP.net site with the <a href="http://code.google.com/p/solrnet/" rel="nofollow noreferrer">solrnet</a> library.</p>
|
[
{
"answer_id": 582489,
"author": "Sam",
"author_id": 37379,
"author_profile": "https://Stackoverflow.com/users/37379",
"pm_score": 1,
"selected": false,
"text": "private void Form1_Load(object sender, EventArgs e)\n {\n searchurl.Text = \"http://localhost:8080/opensearch?query=\";\n\n\n }\n\n private void search_Click(object sender, EventArgs e)\n {\n string uri;\n\n uri = searchurl.Text.ToString() + query.Text.ToString();\n Console.WriteLine(uri);\n\n XmlDocument myXMLDocument = new XmlDocument();\n\n myXMLDocument.Load(uri);\n\n DataSet ds = new DataSet();\n\n ds.ReadXml(new XmlNodeReader(myXMLDocument));\n\n SearchResultsGridView1.DataSource = ds;\n SearchResultsGridView1.DataMember = \"item\";\n\n }\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/253/"
] |
204,538
|
<p>I am having a listbox in ASP.net. I am populating the listbox values from another listbox in a page dynamically. During postbacks the values of output listbox are not persisted.
(while going to another page and come back to this page).</p>
<p>Please suggest some good answer. EnableViewstate = "true" is not working.</p>
|
[
{
"answer_id": 204551,
"author": "Lou Franco",
"author_id": 3937,
"author_profile": "https://Stackoverflow.com/users/3937",
"pm_score": 3,
"selected": true,
"text": "if(!IsPostBack) {}\n"
},
{
"answer_id": 204577,
"author": "thmsn",
"author_id": 28145,
"author_profile": "https://Stackoverflow.com/users/28145",
"pm_score": 1,
"selected": false,
"text": "if(!IsPostBack) {}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204538",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22162/"
] |
204,548
|
<p>How to change overview rule <strong>background</strong> color in Eclipse 3.4.0.I20080617-2000 (vertical bar on right of editing window with some annotations) ? </p>
<p>General > Editors > Text Editors > Annotations allows only to change colors of marks itself not background of whole bar.</p>
<p>It looks like my web searching skills are getting weaker since I cannot find it anywhere ... </p>
|
[
{
"answer_id": 6994150,
"author": "Rachel K. Westmacott",
"author_id": 846145,
"author_profile": "https://Stackoverflow.com/users/846145",
"pm_score": 1,
"selected": false,
"text": "(Window -> Preferences -> General -> Editors -> Text Editors -> Background color => BLACK"
},
{
"answer_id": 37512393,
"author": "john_v",
"author_id": 6312102,
"author_profile": "https://Stackoverflow.com/users/6312102",
"pm_score": 2,
"selected": false,
"text": "#org-eclipse-e4-ui-compatibility-editor Composite > Canvas {\n background-color : #232323;\n}\n"
},
{
"answer_id": 40491683,
"author": "Jai",
"author_id": 5299091,
"author_profile": "https://Stackoverflow.com/users/5299091",
"pm_score": 0,
"selected": false,
"text": "#org-eclipse-e4-ui-compatibility-editor Canvas,\n#org-eclipse-e4-ui-compatibility-editor Canvas > * > * {\n background-color: #b5c7ce;\n}\n background-color: #e0d2d2;\n}"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204548",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/501/"
] |
204,549
|
<p>I need to insert some data into a table in Oracle. </p>
<p>The only problem is one of the fields is a timestamp(6) type and it is required data. I don't care about what actually goes in here I just need to get the right syntax for an entry so that the database will accept it.</p>
<p>I'm using the gui web client to enter data however I don't mind using raw SQL if I have to.</p>
<p>Thanks.</p>
|
[
{
"answer_id": 204620,
"author": "Mike Woodhouse",
"author_id": 1060,
"author_profile": "https://Stackoverflow.com/users/1060",
"pm_score": 4,
"selected": false,
"text": "create table x ( a timestamp(6));\ninsert into x values ( current_timestamp );\nselect * from x;\n T\n---------------------------------------------------------------------------\n15-OCT-08 02.01.25.604309 PM\n select to_timestamp('27/02/2002 15:51.12.539880', 'dd/mm/yyyy hh24:mi.ss.ff') \nfrom dual ; \n"
},
{
"answer_id": 1399554,
"author": "Benedikt Waldvogel",
"author_id": 4308,
"author_profile": "https://Stackoverflow.com/users/4308",
"pm_score": 3,
"selected": false,
"text": "to_timestamp() INSERT INTO table VALUES (timestamp'2009-09-09 09:30:25 CET');\n"
},
{
"answer_id": 29661721,
"author": "Cale Sweeney",
"author_id": 2242045,
"author_profile": "https://Stackoverflow.com/users/2242045",
"pm_score": 0,
"selected": false,
"text": "TO_TIMESTAMP('04/14/2015 2:25:55','mm/dd/yyyy hh24:mi.ss.ff')\n TO_TIMESTAMP('04/15/2015','mm/dd/yyyy')\n"
},
{
"answer_id": 50120973,
"author": "Piyush",
"author_id": 9168466,
"author_profile": "https://Stackoverflow.com/users/9168466",
"pm_score": 0,
"selected": false,
"text": "insert into x values(to_timestamp('22:20:00','hh24:mi'));\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22061/"
] |
204,553
|
<p>im using httpclient and last-modified header in order to retrieve the last updated date of an html file however when i try this on a linux box it returns yesterdays date but when i use a windows machine it returns todays date. is anyone aware of issues using this header field in linux?</p>
|
[
{
"answer_id": 205456,
"author": "Mihai Limbășan",
"author_id": 14444,
"author_profile": "https://Stackoverflow.com/users/14444",
"pm_score": 0,
"selected": false,
"text": "date date MMDDhhmmCCYY.ss date 101519412008.27"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24481/"
] |
204,557
|
<p>I'm working on scripts that apply database schema updates. I've setup all my SQL update scripts using start transaction/commit. I pass these scripts to psql on the command line.</p>
<p>I now need to apply multiple scripts at the same time, and in one transaction. So far the only solution I've come up with is to remove the start transaction/commit from the original set of scripts, then jam them together inside a new start transaction/commit block. I'm writing perl scripts to do this on the fly.</p>
<p>Effectively I want nested transactions, which I can't figure out how to do in postgresql. </p>
<p>Is there any way to do or simulate nested transactions for this purpose? I have things setup to automatically bail out on any error, so I don't need to continue in the top level transaction if any of the lower ones fail.</p>
|
[
{
"answer_id": 204592,
"author": "MysticSlayer",
"author_id": 28139,
"author_profile": "https://Stackoverflow.com/users/28139",
"pm_score": 4,
"selected": true,
"text": "CREATE TABLE t1 (a integer PRIMARY KEY);\n\nCREATE FUNCTION test_exception() RETURNS boolean LANGUAGE plpgsql AS\n$$BEGIN\n INSERT INTO t1 (a) VALUES (1);\n INSERT INTO t1 (a) VALUES (2);\n INSERT INTO t1 (a) VALUES (1);\n INSERT INTO t1 (a) VALUES (3);\n RETURN TRUE;\nEXCEPTION\n WHEN integrity_constraint_violation THEN\n RAISE NOTICE 'Rollback to savepoint';\n RETURN FALSE;\nEND;$$;\n\nBEGIN;\n\nSELECT test_exception();\nNOTICE: Rollback to savepoint\n test_exception \n----------------\n f\n(1 row)\n\nCOMMIT;\n\nSELECT count(*) FROM t1;\n count \n-------\n 0\n(1 row)\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204557",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5801/"
] |
204,564
|
<p>Is there any way to get the custom attributes of a specific object I am receiving in a method?</p>
<p>I do not want nor can to iterate over Type.GetMembers() and search for my member. I have the object, which is also a member, that has the attribute.</p>
<p>How do I get the attribute?</p>
<pre><code>class Custom
{
[Availability]
private object MyObject = "Hello";
private void Do(object o)
{
//does object 'o' has any custom attributes of type 'Availability'?
}
//somewhere I make the call: Do(MyObject)
}
</code></pre>
|
[
{
"answer_id": 204573,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 1,
"selected": false,
"text": "abstract MyBase\n{\n public string Name;\n protected MyBase()\n {\n //look up value of Name attribute and assign to Name\n } \n}\n\n[Name(\"Foo\")]\nclass MyClass : MyBase\n{\n}\n"
}
] |
2008/10/15
|
[
"https://Stackoverflow.com/questions/204564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2130892/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.