qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
246,438
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/358874/how-can-i-use-a-carriage-return-in-a-html-tooltip">How can I use a carriage return in a HTML tooltip?</a> </p>
</blockquote>
<p>I'd like to know if it's possible to force a newline to show in the tooltip when using title property of a TD.
something like </p>
<pre><code><td title="lineone \n linetwo \n etc...">
</code></pre>
<p>Can this be done?</p>
|
[
{
"answer_id": 246439,
"author": "Ady",
"author_id": 31395,
"author_profile": "https://Stackoverflow.com/users/31395",
"pm_score": 2,
"selected": false,
"text": "<td title=\"lineone\nlinetwo \netc...\">\n"
},
{
"answer_id": 246451,
"author": "RealHowTo",
"author_id": 25122,
"author_profile": "https://Stackoverflow.com/users/25122",
"pm_score": 9,
"selected": true,
"text": "<img src=\"'../images/foo.gif'\" \n alt=\"line 1
line 2\" title=\"line 1
line 2\">\n"
},
{
"answer_id": 3316441,
"author": "Stéphane Klein",
"author_id": 261061,
"author_profile": "https://Stackoverflow.com/users/261061",
"pm_score": 5,
"selected": false,
"text": "<td title=\"lineone 
 linetwo 
 etc...\">\n"
},
{
"answer_id": 4555163,
"author": "baik",
"author_id": 533292,
"author_profile": "https://Stackoverflow.com/users/533292",
"pm_score": 1,
"selected": false,
"text": "<br>"
},
{
"answer_id": 8526097,
"author": "Petr Tuma",
"author_id": 345436,
"author_profile": "https://Stackoverflow.com/users/345436",
"pm_score": 5,
"selected": false,
"text": "<td>Cell content.\n <div class=\"popup\">\n This is the popup.\n <br>\n Another line of popup.\n </div>\n</td>\n td div.popup { display: none; }\ntd:hover div.popup { display: block; position: absolute; }\n"
},
{
"answer_id": 10624123,
"author": "Dave Van Meter",
"author_id": 1399313,
"author_profile": "https://Stackoverflow.com/users/1399313",
"pm_score": 3,
"selected": false,
"text": "
"
},
{
"answer_id": 12284082,
"author": "Erez Cohen",
"author_id": 145599,
"author_profile": "https://Stackoverflow.com/users/145599",
"pm_score": 2,
"selected": false,
"text": "
 <img src=\"'../images/foo.gif'\" title=\"line 1<br>line 2\">\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15616/"
] |
246,440
|
<p>I want to draw spinner controls, such as those found on a NumericUpDown, on a custom component. If I want to draw a drop-down button, I can use ComboBoxRenderer. Is there an equivalent of ComboBoxRenderer for NumericUpDown?</p>
|
[
{
"answer_id": 259078,
"author": "Alan",
"author_id": 31223,
"author_profile": "https://Stackoverflow.com/users/31223",
"pm_score": 0,
"selected": false,
"text": "[DllImport(\"uxtheme.dll\", ExactSpelling = true, CharSet = CharSet.Unicode)]\npublic static extern IntPtr OpenThemeData(IntPtr hWnd, String classList);\n\n[DllImport(\"uxtheme\", ExactSpelling = true)]\npublic extern static Int32 DrawThemeBackground(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, ref RECT pRect, IntPtr pClipRect);\n\n[DllImport(\"uxtheme.dll\", ExactSpelling = true)]\npublic extern static Int32 CloseThemeData(IntPtr hTheme);\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246440",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15371/"
] |
246,443
|
<p>I am experiencing some strange behavior of embedded audio (wav file) on HTML page.
I've got a page <code>https://server.com/listen-to-sound</code>, and a Wav file embedded in it via <code><EMBED/></code> tag, like this:</p>
<pre><code><embed src='https://server.com/path-to-sound' hidden="true" autostart="true" />
</code></pre>
<p>The page <code>https://server.com/listen-to-sound</code> is opened in IE 6 SP3 on machine#1 - the sound is played in the headphones.
The same page is opened on another machine(#2), with <strong>exactly</strong> same IE 6 SP3 version, privacy and proxy settings - there's no sound.</p>
<p>Totally, from 6 machines the sound is played on 2 and not played on 4. From these 4 machines, when the page <code>https://server.com/listen-to-sound</code> is opened in Opera, the sound is played.</p>
<p>I've triple-checked headphone connections, volume settings and other possible hardware and software driver issues: the problem is definitely in IE settings.</p>
<p>I've also checked <code>https://server.com/path.to.sound</code> URL - the 4 machnies that do not play sound fail to open this link, failing with an error like "Failed to download page".</p>
<p>Cleaning IE caches, temporary internet files, SSL certificate caches did not solve the problem either.</p>
<p>Googling gave me nothing special but old Flash trick to use <code><OBJECT></code> tag and <code><EMBED></code> tag to be written in Object's comments.</p>
<p>What have I missed? Have you experienced similar or related problems? How were they solved?
Do you have any suggestions on where the trick is? Do you know some IE "features" that might affect execution(playing, showing) of embedded objects?</p>
|
[
{
"answer_id": 246729,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 0,
"selected": false,
"text": "<NOEMBED> <object>"
},
{
"answer_id": 821112,
"author": "Travis",
"author_id": 307338,
"author_profile": "https://Stackoverflow.com/users/307338",
"pm_score": 1,
"selected": false,
"text": "<object type=\"audio/x-wav\" data=\"data/test.wav\" width=\"200\" height=\"20\">\n <param name=\"src\" value=\"data/test.wav\">\n <param name=\"autoplay\" value=\"false\">\n <param name=\"autoStart\" value=\"0\">\n alt : <a href=\"data/test.wav\">test.wav</a>\n</object>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17707/"
] |
246,445
|
<p>I have a <code>char* p</code>, which points to a <code>\0</code>-terminated string. How do I create a C++ <code>string</code> from it in an exception-safe way?</p>
<p>Here is an unsafe version:</p>
<pre><code>string foo()
{
char *p = get_string();
string str( p );
free( p );
return str;
}
</code></pre>
<p>An obvious solution would be to try-catch - any easier ways? </p>
|
[
{
"answer_id": 246457,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 6,
"selected": true,
"text": "shared_ptr string\nfoo()\n{\n shared_ptr<char> p(get_string(), &free);\n string str(p.get());\n return str;\n}\n shared_ptr auto_ptr free"
},
{
"answer_id": 246460,
"author": "MSalters",
"author_id": 15416,
"author_profile": "https://Stackoverflow.com/users/15416",
"pm_score": 1,
"selected": false,
"text": "struct Cleanup {\n void* toFree;\n Cleanup(void* toFree) : toFree(toFree) {}\n ~Cleanup() { free(toFree); }\n private:\n Cleanup(Cleanup&);\n void operator=(Cleanup&);\n};\n"
},
{
"answer_id": 246853,
"author": "Johann Gerell",
"author_id": 6345,
"author_profile": "https://Stackoverflow.com/users/6345",
"pm_score": 1,
"selected": false,
"text": "p get_string() std::string get_string() std::string Cleanup p string foo()\n{\n const char* p = get_string();\n const Cleanup cleanup(p);\n const std::string str(p != NULL ? p : \"\");\n\n return str;\n}\n"
},
{
"answer_id": 246888,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 0,
"selected": false,
"text": "string foo()\n{\n char *p = get_string();\n ScopeGuard sg = MakeGuard(&free, p);\n string str( p );\n return str;\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23420/"
] |
246,498
|
<p>I'm trying to create a unit test to test the case for when the timezone changes on a machine because it has been incorrectly set and then corrected.</p>
<p>In the test I need to be able to create DateTime objects in a none local time zone to ensure that people running the test can do so successfully irrespective of where they are located.</p>
<p>From what I can see from the DateTime constructor I can set the TimeZone to be either the local timezone, the UTC timezone or not specified.</p>
<p>How do I create a DateTime with a specific timezone like PST?</p>
|
[
{
"answer_id": 246529,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 9,
"selected": true,
"text": "public struct DateTimeWithZone\n{\n private readonly DateTime utcDateTime;\n private readonly TimeZoneInfo timeZone;\n\n public DateTimeWithZone(DateTime dateTime, TimeZoneInfo timeZone)\n {\n var dateTimeUnspec = DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified);\n utcDateTime = TimeZoneInfo.ConvertTimeToUtc(dateTimeUnspec, timeZone); \n this.timeZone = timeZone;\n }\n\n public DateTime UniversalTime { get { return utcDateTime; } }\n\n public TimeZoneInfo TimeZone { get { return timeZone; } }\n\n public DateTime LocalTime\n { \n get \n { \n return TimeZoneInfo.ConvertTime(utcDateTime, timeZone); \n }\n } \n}\n"
},
{
"answer_id": 1281006,
"author": "CleverPatrick",
"author_id": 22399,
"author_profile": "https://Stackoverflow.com/users/22399",
"pm_score": 6,
"selected": false,
"text": "DateTimeOffset do1 = new DateTimeOffset(2008, 8, 22, 1, 0, 0, new TimeSpan(-5, 0, 0));"
},
{
"answer_id": 9027480,
"author": "Chris Moschini",
"author_id": 176877,
"author_profile": "https://Stackoverflow.com/users/176877",
"pm_score": 6,
"selected": false,
"text": "public static DateTime GmtToPacific(DateTime dateTime)\n{\n return TimeZoneInfo.ConvertTimeFromUtc(dateTime,\n TimeZoneInfo.FindSystemTimeZoneById(\"Pacific Standard Time\"));\n}\n FindSystemTimeZoneById HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\ FindSystemTimeZoneById"
},
{
"answer_id": 20504276,
"author": "Gabe Halsmer",
"author_id": 922258,
"author_profile": "https://Stackoverflow.com/users/922258",
"pm_score": 2,
"selected": false,
"text": "public DateTime TimeInOriginalZone { get { return TimeZoneInfo.ConvertTime(utcDateTime, timeZone); } }\npublic DateTime TimeInLocalZone { get { return TimeZoneInfo.ConvertTime(utcDateTime, TimeZoneInfo.Local); } }\npublic DateTime TimeInSpecificZone(TimeZoneInfo tz)\n{\n return TimeZoneInfo.ConvertTime(utcDateTime, tz);\n}\n"
},
{
"answer_id": 22829864,
"author": "Jernej Novak",
"author_id": 1063571,
"author_profile": "https://Stackoverflow.com/users/1063571",
"pm_score": 3,
"selected": false,
"text": "public static class DateTimeWithZone\n{\n\nprivate static readonly TimeZoneInfo timeZone;\n\nstatic DateTimeWithZone()\n{\n//I added web.config <add key=\"CurrentTimeZoneId\" value=\"Central Europe Standard Time\" />\n//You can add value directly into function.\n timeZone = TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings[\"CurrentTimeZoneId\"]);\n}\n\n\npublic static DateTime LocalTime(this DateTime t)\n{\n return TimeZoneInfo.ConvertTime(t, timeZone); \n}\n}\n"
},
{
"answer_id": 58189080,
"author": "Meghs Dhameliya",
"author_id": 2030126,
"author_profile": "https://Stackoverflow.com/users/2030126",
"pm_score": 1,
"selected": false,
"text": "TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(TimeZones.Paris.Id));\n"
},
{
"answer_id": 69205190,
"author": "Eugene Ihnatsyeu",
"author_id": 8419483,
"author_profile": "https://Stackoverflow.com/users/8419483",
"pm_score": 2,
"selected": false,
"text": "TimeZoneInfo.ConvertTime(dateTime, sourceTimeZone, destinationTimeZone)"
},
{
"answer_id": 69913523,
"author": "Arthur",
"author_id": 816351,
"author_profile": "https://Stackoverflow.com/users/816351",
"pm_score": 1,
"selected": false,
"text": " var time = TimeSpan.Parse(\"9:00\");\n var est = TimeZoneInfo.FindSystemTimeZoneById(\"Eastern Standard Time\");\n var nationalDateTime = new DateTimeOffset(DateTime.Today.Ticks + time.Ticks, est.BaseUtcOffset);\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42109/"
] |
246,503
|
<p>OK, I am trying to generate the rDoc for paperclip, but the rake task is choking on another plugin before it gets to it, so this is out of the question:</p>
<pre><code>rake doc:plugins
</code></pre>
<p>I could go and fix up the broken plugin, but I'm busy and lazy, so I just want to generate the docs for paperclip. Is there any way of doing this?</p>
|
[
{
"answer_id": 246507,
"author": "Codebeef",
"author_id": 12037,
"author_profile": "https://Stackoverflow.com/users/12037",
"pm_score": 4,
"selected": true,
"text": "rake doc:plugins:paperclip\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12037/"
] |
246,518
|
<p>I used the owner-drawn strategy on CMyListBox class which derives from CListBox. I only want the DrawItem() method to perform when I insert an item in the listbox. But the method is invoked many times. How can I change to invoke it whenever I need.</p>
|
[
{
"answer_id": 246543,
"author": "SmacL",
"author_id": 22564,
"author_profile": "https://Stackoverflow.com/users/22564",
"pm_score": 0,
"selected": false,
"text": "void CMyListBox::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )\n{\n if (!m_DrawingEnabled)\n return;\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246518",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26404/"
] |
246,520
|
<p>I'm writing a web application which uses windows authentication and I can happily get the user's login name using something like:</p>
<pre><code> string login = User.Identity.Name.ToString();
</code></pre>
<p>But I don't need their login name I want their DisplayName. I've been banging my head for a couple hours now...</p>
<p>Can I access my organisation's AD via a web application?</p>
|
[
{
"answer_id": 246655,
"author": "Panos",
"author_id": 8049,
"author_profile": "https://Stackoverflow.com/users/8049",
"pm_score": 3,
"selected": false,
"text": "GetUserProperty(\"<myaccount>\", \"DisplayName\");\n\npublic static string GetUserProperty(string accountName, string propertyName)\n{\n DirectoryEntry entry = new DirectoryEntry();\n // \"LDAP://CN=<group name>, CN =<Users>, DC=<domain component>, DC=<domain component>,...\"\n entry.Path = \"LDAP://...\";\n entry.AuthenticationType = AuthenticationTypes.Secure;\n\n DirectorySearcher search = new DirectorySearcher(entry);\n search.Filter = \"(SAMAccountName=\" + accountName + \")\";\n search.PropertiesToLoad.Add(propertyName);\n\n SearchResultCollection results = search.FindAll();\n if (results != null && results.Count > 0)\n {\n return results[0].Properties[propertyName][0].ToString();\n }\n else\n {\n return \"Unknown User\";\n }\n}\n"
},
{
"answer_id": 246700,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "private static string GetFullName()\n {\n try\n {\n DirectoryEntry de = new DirectoryEntry(\"WinNT://\" + Environment.UserDomainName + \"/\" + Environment.UserName);\n return de.Properties[\"displayName\"].Value.ToString();\n }\n catch { return null; }\n }\n"
},
{
"answer_id": 280812,
"author": "Ian G",
"author_id": 31765,
"author_profile": "https://Stackoverflow.com/users/31765",
"pm_score": 2,
"selected": false,
"text": " /// This is some imaginary code to show you how to use it\n\n Session[\"USER\"] = User.Identity.Name.ToString();\n Session[\"LOGIN\"] = RemoveDomainPrefix(User.Identity.Name.ToString()); // not a real function :D\n string ldappath = \"LDAP://your_ldap_path\";\n // \"LDAP://CN=<group name>, CN =<Users>, DC=<domain component>, DC=<domain component>,...\"\n\n\n Session[\"cn\"] = GetAttribute(ldappath, (string)Session[\"LOGIN\"], \"cn\");\n Session[\"displayName\"] = GetAttribute(ldappath, (string)Session[\"LOGIN\"], \"displayName\");\n Session[\"mail\"] = GetAttribute(ldappath, (string)Session[\"LOGIN\"], \"mail\");\n Session[\"givenName\"] = GetAttribute(ldappath, (string)Session[\"LOGIN\"], \"givenName\");\n Session[\"sn\"] = GetAttribute(ldappath, (string)Session[\"LOGIN\"], \"sn\");\n\n\n/// working code\n\npublic static string GetAttribute(string ldappath, string sAMAccountName, string attribute)\n {\n string OUT = string.Empty;\n\n try\n {\n DirectoryEntry de = new DirectoryEntry(ldappath);\n DirectorySearcher ds = new DirectorySearcher(de);\n ds.Filter = \"(&(objectClass=user)(objectCategory=person)(sAMAccountName=\" + sAMAccountName + \"))\";\n\n SearchResultCollection results = ds.FindAll();\n\n foreach (SearchResult result in results)\n {\n OUT = GetProperty(result, attribute);\n }\n }\n catch (Exception t)\n {\n // System.Diagnostics.Debug.WriteLine(t.Message);\n }\n\n return (OUT != null) ? OUT : string.Empty;\n }\n\npublic static string GetProperty(SearchResult searchResult, string PropertyName)\n {\n if (searchResult.Properties.Contains(PropertyName))\n {\n return searchResult.Properties[PropertyName][0].ToString();\n }\n else\n {\n return string.Empty;\n }\n }\n"
},
{
"answer_id": 15782876,
"author": "user2239589",
"author_id": 2239589,
"author_profile": "https://Stackoverflow.com/users/2239589",
"pm_score": 3,
"selected": false,
"text": "string displayName = UserPrincipal.Current.DisplayName;"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246520",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31765/"
] |
246,525
|
<p>I'm using Python's Imaging Library and I would like to draw some bezier curves.
I guess I could calculate pixel by pixel but I'm hoping there is something simpler.</p>
|
[
{
"answer_id": 246628,
"author": "Jasper Bekkers",
"author_id": 31486,
"author_profile": "https://Stackoverflow.com/users/31486",
"pm_score": 5,
"selected": true,
"text": "A B C t P0 = A * t + (1 - t) * B\nP1 = B * t + (1 - t) * C\n Pfinal = P0 * t + (1 - t) * P1\n dt 0 <= t <= 1"
},
{
"answer_id": 246933,
"author": "Toni Ruža",
"author_id": 6267,
"author_profile": "https://Stackoverflow.com/users/6267",
"pm_score": 3,
"selected": false,
"text": "Path curveto from PIL import Image\nimport aggdraw\n\nimg = Image.new(\"RGB\", (200, 200), \"white\")\ncanvas = aggdraw.Draw(img)\n\npen = aggdraw.Pen(\"black\")\npath = aggdraw.Path()\npath.moveto(0, 0)\npath.curveto(0, 60, 40, 100, 100, 100)\ncanvas.path(path.coords(), path, pen)\ncanvas.flush()\n\nimg.save(\"curve.png\", \"PNG\")\nimg.show()\n"
},
{
"answer_id": 2292690,
"author": "unutbu",
"author_id": 190597,
"author_profile": "https://Stackoverflow.com/users/190597",
"pm_score": 5,
"selected": false,
"text": "def make_bezier(xys):\n # xys should be a sequence of 2-tuples (Bezier control points)\n n = len(xys)\n combinations = pascal_row(n-1)\n def bezier(ts):\n # This uses the generalized formula for bezier curves\n # http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Generalization\n result = []\n for t in ts:\n tpowers = (t**i for i in range(n))\n upowers = reversed([(1-t)**i for i in range(n)])\n coefs = [c*a*b for c, a, b in zip(combinations, tpowers, upowers)]\n result.append(\n tuple(sum([coef*p for coef, p in zip(coefs, ps)]) for ps in zip(*xys)))\n return result\n return bezier\n\ndef pascal_row(n, memo={}):\n # This returns the nth row of Pascal's Triangle\n if n in memo:\n return memo[n]\n result = [1]\n x, numerator = 1, n\n for denominator in range(1, n//2+1):\n # print(numerator,denominator,x)\n x *= numerator\n x /= denominator\n result.append(x)\n numerator -= 1\n if n&1 == 0:\n # n is even\n result.extend(reversed(result[:-1]))\n else:\n result.extend(reversed(result))\n memo[n] = result\n return result\n from PIL import Image\nfrom PIL import ImageDraw\n\nif __name__ == '__main__':\n im = Image.new('RGBA', (100, 100), (0, 0, 0, 0)) \n draw = ImageDraw.Draw(im)\n ts = [t/100.0 for t in range(101)]\n\n xys = [(50, 100), (80, 80), (100, 50)]\n bezier = make_bezier(xys)\n points = bezier(ts)\n\n xys = [(100, 50), (100, 0), (50, 0), (50, 35)]\n bezier = make_bezier(xys)\n points.extend(bezier(ts))\n\n xys = [(50, 35), (50, 0), (0, 0), (0, 50)]\n bezier = make_bezier(xys)\n points.extend(bezier(ts))\n\n xys = [(0, 50), (20, 80), (50, 100)]\n bezier = make_bezier(xys)\n points.extend(bezier(ts))\n\n draw.polygon(points, fill = 'red')\n im.save('out.png')\n"
},
{
"answer_id": 21416678,
"author": "Karim Bahgat",
"author_id": 2898490,
"author_profile": "https://Stackoverflow.com/users/2898490",
"pm_score": 3,
"selected": false,
"text": "aggdraw.Symbol(pathstring) draw.symbol(args) print \"initializing script\"\n\n# imports\nfrom PIL import Image\nimport aggdraw\n\n# setup\nimg = Image.new(\"RGBA\", (1000,1000)) # last part is image dimensions\ndraw = aggdraw.Draw(img)\noutline = aggdraw.Pen(\"black\", 5) # 5 is the outlinewidth in pixels\nfill = aggdraw.Brush(\"yellow\")\n\n# the pathstring:\n#m for starting point\n#c for bezier curves\n#z for closing up the path, optional\n#(all lowercase letters for relative path)\npathstring = \" m0,0 c300,300,700,600,300,900 z\"\n\n# create symbol\nsymbol = aggdraw.Symbol(pathstring)\n\n# draw and save it\nxy = (20,20) # xy position to place symbol\ndraw.symbol(xy, symbol, outline, fill)\ndraw.flush()\nimg.save(\"testbeziercurves.png\") # this image gets saved to same folder as the script\n\nprint \"finished drawing and saved!\"\n"
},
{
"answer_id": 45843865,
"author": "Lucas VL",
"author_id": 6189478,
"author_profile": "https://Stackoverflow.com/users/6189478",
"pm_score": 0,
"selected": false,
"text": "import math\nfrom PIL import Image\nfrom PIL import ImageDraw\n\nimage = Image.new('RGB',(1190,841),'white')\ndraw = ImageDraw.Draw(image)\ncurve_smoothness = 100\n\n#First, select start and end of curve (pixels)\ncurve_start = [(167,688)] \ncurve_end = [(678,128)]\n\n#Second, split the path into segments\ncurve = [] \nfor i in range(1,curve_smoothness,1):\n split = (curve_end[0][0] - curve_start[0][0])/curve_smoothness\n x = curve_start[0][0] + split * i \n curve.append((x, -7 * math.pow(10,-7) * math.pow(x,3) - 0.0011 * math.pow(x,2) + 0.235 * x + 682.68))\n\n#Third, edit any other corners of polygon\nother =[(1026,721), (167,688)]\n\n#Finally, combine all parts of polygon into one list\nxys = curve_start + curve + curve_end + other #putting all parts of the polygon together\ndraw.polygon(xys, fill = None, outline = 256)\n\nimage.show()\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20498/"
] |
246,540
|
<p>This error has been driving me nuts. We have a server running Apache and Tomcat, serving multiple different sites. Normally the server runs fine, but sometimes an error happens where people are served the wrong page - <strong>the page that <em>somebody else</em> requested!</strong></p>
<p>Clues:</p>
<ul>
<li>The pages being delivered are those that another user requested recently, and are otherwise delivered correctly. It's been known for two simultaneous requests to be swapped. As far as I can tell, none of the pages being incorrectly delivered are older than a few minutes.</li>
<li>It only affects the files that are being served by Tomcat. Static files like images are unaffected.</li>
<li>It doesn't happen all the time. When it does happen, it happens for everybody.</li>
<li>It seems to happen at times of peak demand. However, the demand is not yet very high - it's certainly well within the bounds of what Apache can cope with.</li>
<li>Restarting Tomcat fixed it, but only for a few minutes. Restarting Apache fixed it, but only for a few minutes.</li>
<li>The server is running Apache 2 and Tomcat 6, using a Java 6 VM on Gentoo. The connection is with AJP13, and <code>JkMount</code> directives within <code><VirtualHost></code> blocks are correct.</li>
<li>There's nothing of use in any of the log files.</li>
</ul>
<hr>
<p><strong>Further information:</strong></p>
<p>Apache does not have any form of caching turned on. All the caching-related entries in httpd.conf and related imports say, for example:</p>
<pre><code><IfDefine CACHE>
LoadModule cache_module modules/mod_cache.so
</IfDefine>
</code></pre>
<p>While the options for Apache don't include that flag:</p>
<pre><code>APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D SSL -D SSL_DEFAULT_VHOST -D PHP5 -D JK"
</code></pre>
<p>Tomcat likewise has no caching options switched on, that I can find.</p>
<p><a href="https://stackoverflow.com/questions/246540/apachetomcat-error-wrong-pages-being-delivered#246566">toolkit's suggestion</a> was good, but not appropriate in this case. What leads me to believe that the error can't be within my own code is that it isn't simply a few values that are being transferred - it's the entire request, including the URL, parameters, session cookies, the whole thing. People are getting pages back saying "You are logged in as John", when they clearly aren't.</p>
<hr>
<p><strong>Update:</strong></p>
<p>Based on suggestions from several people, I'm going to add the following HTTP headers to Tomcat-served pages to disable all forms of caching:</p>
<pre><code>Cache-Control: no-store
Vary: *
</code></pre>
<p>Hopefully these headers will be respected not just by Apache, but also by any other caches or proxies that may be in the way. Unfortunately I have no way of deliberately reproducing this error, so I'm just going to have to wait and see if it turns up again.</p>
<p>I notice that the following headers are being included - could they be related in any way?</p>
<pre><code>Connection: Keep-Alive
Keep-Alive: timeout=5, max=66
</code></pre>
<hr>
<p><strong>Update:</strong></p>
<p>Apparently this happened again while I was asleep, but has stopped happening now I'm awake to see it. Again, there's nothing useful in the logs that I can see, so I have no clues to what was actually happening or how to prevent it.</p>
<p>Is there any extra information I can put in Apache or Tomcat's logs to make this easier to diagnose?</p>
<hr>
<p><strong>Update:</strong></p>
<p>Since this has happened again a couple of times, we've changed how Apache connects to Tomcat to see if it affects things. We were using <code>mod_jk</code> with a directive like this:</p>
<pre><code>JkMount /portal ajp13
</code></pre>
<p>We've switched now to using <code>mod_proxy_ajp</code>, like so:</p>
<pre><code>ProxyPass /portal ajp://localhost:8009/portal
</code></pre>
<p>We'll see if it makes any difference. This error was always annoyingly unpredictable, so we can never definitively say if it's worked or not.</p>
<hr>
<p><strong>Update:</strong></p>
<p>We just got the error briefly on a site that was left using <code>mod_jk</code>, while a sister site on the same server using <code>mod_proxy_ajp</code> didn't show the error. This doesn't prove anything, but it does provide evidence that swithing to <code>mod_proxy_ajp</code> may have helped.</p>
<hr>
<p><strong>Update:</strong></p>
<p>We just got the error again last night on a site using <code>mod_proxy_ajp</code>, so clearly that hasn't solved it - <code>mod_jk</code> wasn't the source of the problem. I'm going to try the anonymous suggestion of turning off persistent connections:</p>
<pre><code>KeepAlive Off
</code></pre>
<p>If that fails as well, I'm going to be desperate enough to start investigating GlassFish.</p>
<hr>
<p><strong>Update:</strong></p>
<p>Dammit! The problem just came back. I hadn't seen it in a while, so I was starting to think we'd finally sorted it. I hate heisenbugs.</p>
|
[
{
"answer_id": 246566,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 3,
"selected": false,
"text": "public class MyServlet ... {\n private String action;\n\n public void doGet(...) {\n action = request.getParameter(\"action\");\n processAction(response);\n }\n\n public void processAction(...) {\n if (action.equals(\"foo\")) {\n // send foo page\n } else if (action.equals(\"bar\")) {\n // send bar page\n }\n }\n}\n public class MyServlet ... {\n public void doGet(...) {\n String action = request.getParameter(\"action\");\n processAction(action, response);\n }\n\n public void processAction(...) {\n if (action.equals(\"foo\")) {\n // send foo page\n } else if (action.equals(\"bar\")) {\n // send bar page\n }\n }\n}\n"
},
{
"answer_id": 248724,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 2,
"selected": false,
"text": "Vary Vary"
},
{
"answer_id": 764922,
"author": "cherouvim",
"author_id": 72478,
"author_profile": "https://Stackoverflow.com/users/72478",
"pm_score": 1,
"selected": false,
"text": "response.setHeader(\"Cache-Control\", \"no-cache\"); //HTTP 1.1\nresponse.setHeader(\"Pragma\", \"no-cache\"); //HTTP 1.0\nresponse.setDateHeader(\"Expires\", 0); //prevents caching at the proxy server\n"
},
{
"answer_id": 1743757,
"author": "Marcus Downing",
"author_id": 1000,
"author_profile": "https://Stackoverflow.com/users/1000",
"pm_score": 1,
"selected": true,
"text": "mod_jk JkMount /portal ajp13\n mod_proxy_ajp ProxyPass /portal ajp://localhost:8009/portal\n mod_proxy ProxyPass /portal http://localhost:8080/portal\n / / ProxyPass / http://localhost:8080/\n"
},
{
"answer_id": 4786167,
"author": "William Lee",
"author_id": 588004,
"author_profile": "https://Stackoverflow.com/users/588004",
"pm_score": 2,
"selected": false,
"text": "CacheIgnoreHeaders Set-Cookie\n"
},
{
"answer_id": 11375693,
"author": "Steven Lizarazo",
"author_id": 589132,
"author_profile": "https://Stackoverflow.com/users/589132",
"pm_score": 0,
"selected": false,
"text": " <Connector port=\"8080\" protocol=\"HTTP/1.1\"\n connectionTimeout=\"20000\"\n redirectPort=\"8443\" />\n <Connector port=\"8080\" protocol=\"HTTP/1.1\"\n connectionTimeout=\"2000000\"\n redirectPort=\"8443\" />\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1000/"
] |
246,542
|
<p>There was no endpoint listening at http;//localhost:8080/xdxservice/xdsrepository that could accept the message. This is often caused by an incorrect address or SOAP action. </p>
|
[
{
"answer_id": 246625,
"author": "ZombieSheep",
"author_id": 377,
"author_profile": "https://Stackoverflow.com/users/377",
"pm_score": 1,
"selected": false,
"text": "http;//localhost:8080/xdxservice/xdsrepository\n http://localhost:8080/xdxservice/xdsrepository\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,559
|
<p>I need to copy a set of DLL and PDB files from a set of folders recursively into another folder. I don't want to recreate the folder hierarchy in the target folder.
I want to use built in Windows tools, e.g. DOS commands. </p>
|
[
{
"answer_id": 246576,
"author": "Alexander Prokofyev",
"author_id": 11256,
"author_profile": "https://Stackoverflow.com/users/11256",
"pm_score": 8,
"selected": true,
"text": "mkdir targetDir\nfor /r %x in (*.dll, *pdb) do copy \"%x\" targetDir\\\n"
},
{
"answer_id": 5632706,
"author": "Henrik Thomsen",
"author_id": 703690,
"author_profile": "https://Stackoverflow.com/users/703690",
"pm_score": -1,
"selected": false,
"text": "@echo off\nif %1'==' goto usage\nif %2'==' goto usage\nif %3'==' goto usage\nfor /D %%F in (%1\\*) do xcopy %%F\\%2 %3 /D /Y\nfor /D %%F in (%1\\*.) do call TreeCopy %%F %2 %3\ngoto end\n:usage\n@echo Usage: TreeCopy [Source folder] [Search pattern] [Destination folder]\n@echo Example: TreeCopy C:\\Project\\UDI *.xsd C:\\Project\\UDI\\SOA\\Deploy\\Metadata\n:end\n"
},
{
"answer_id": 13681925,
"author": "Bronek",
"author_id": 769465,
"author_profile": "https://Stackoverflow.com/users/769465",
"pm_score": 5,
"selected": false,
"text": "mkdir DestFolder\nxcopy SrcFolder DestFolder /E\n"
},
{
"answer_id": 24206920,
"author": "SteckDEV",
"author_id": 1771899,
"author_profile": "https://Stackoverflow.com/users/1771899",
"pm_score": 0,
"selected": false,
"text": "if not exist \"$(TargetDir)..\\SingleFolderOutput\" mkdir -p \"$(TargetDir)..\\SingleFolderOutput\"\n\nfor /r **%%x** in (*.dll, *.pdb, *.xml, *.xaml, *.exe, *.exe.config) do xcopy **\"%%x\"** \"$(TargetDir)..\\SingleFolderOutput\" /Y\n"
},
{
"answer_id": 60885062,
"author": "uzrgm",
"author_id": 936541,
"author_profile": "https://Stackoverflow.com/users/936541",
"pm_score": 0,
"selected": false,
"text": "cmd /q /c for /R \"<your_source_folder>\" %f in (*.pdb) do xcopy \"%f\" \"<your_destination_folder>\" /I /Y\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32333/"
] |
246,564
|
<p>If a variable is declared as <code>static</code> in a function's scope it is only initialized once and retains its value between function calls. What exactly is its lifetime? When do its constructor and destructor get called?</p>
<pre><code>void foo()
{
static string plonk = "When will I die?";
}
</code></pre>
|
[
{
"answer_id": 246568,
"author": "Motti",
"author_id": 3848,
"author_profile": "https://Stackoverflow.com/users/3848",
"pm_score": 9,
"selected": true,
"text": "static struct emitter {\n string str;\n emitter(const string& s) : str(s) { cout << \"Created \" << str << endl; }\n ~emitter() { cout << \"Destroyed \" << str << endl; }\n};\n\nvoid foo(bool skip_first) \n{\n if (!skip_first)\n static emitter a(\"in if\");\n static emitter b(\"in foo\");\n}\n\nint main(int argc, char*[])\n{\n foo(argc != 2);\n if (argc == 3)\n foo(false);\n}\n [0] [1] 3.6.3.1 [2]"
},
{
"answer_id": 246594,
"author": "Roddy",
"author_id": 1737,
"author_profile": "https://Stackoverflow.com/users/1737",
"pm_score": 7,
"selected": false,
"text": "foo plonk plonk"
},
{
"answer_id": 247470,
"author": "Roddy",
"author_id": 1737,
"author_profile": "https://Stackoverflow.com/users/1737",
"pm_score": 3,
"selected": false,
"text": "C:\\> sample.exe 1 2\nCreated in foo\nCreated in if\nDestroyed in foo\nDestroyed in if\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3848/"
] |
246,577
|
<p>I am writing an RSS feed (for fun) and was looking at the spec <a href="http://cyber.law.harvard.edu/rss/rss.html" rel="noreferrer">here</a>.</p>
<blockquote>
<p>RSS is a dialect of XML. All RSS files must conform to the XML 1.0 specification, as published on the World Wide Web Consortium (W3C) website.</p>
</blockquote>
<p>Obviously this means that I am not serving 'pure' RSS if I choose the JSON option. That said, if I conform to the rest of the spec, is it likely that (customised) readers will be able to parse it?</p>
<p>To put it another way, if I conform to the spec, but using JSON instead of XML is it a usable RSS feed?</p>
<p><em>edit</em>
I am not sure I made myself clear.
There is no XML involved. I want to write something akin to RSS (which is XML) using JSON instead. Obviously the readers of such a feed would need to be written to understand the JSON format.
I was wondering if this had been done already. Are there services that serve a feed this way? Are there programs that can aggregate/understand this format. Is the RSS spec (sans the XML part) a useful spec to conform to in this case?</p>
<p>rg </p>
<pre><code>{
"title":"example.com",
"link":"http://www.example.com/",
"description":"Awesome news about junk",
"items":[
{
"title":"An article",
"link":"http://www.example.com/an-article",
"descrition":"Some sample text here",
"pubDate":"2008-10-27 11:06 EST",
"author":"example author",
},
{
"title":"Second",
"link":"http://www.example.com/Seond",
"descrition":"Some sample text here",
"pubDate":"2008-10-25 23:20 EST",
"author":"author mcauthor",
},
{
"title":"third article",
"link":"http://www.example.com/third-article",
"descrition":"Some sample text here",
"pubDate":"2008-10-25 23:18 EST",
"author":"some other author",
}
]
}
</code></pre>
|
[
{
"answer_id": 251764,
"author": "Dan Esparza",
"author_id": 19020,
"author_profile": "https://Stackoverflow.com/users/19020",
"pm_score": 4,
"selected": false,
"text": "jQuery.getFeed(options);\n jQuery.getFeed({\n url: 'rss.xml',\n success: function(feed) {\n alert(feed.title);\n }\n });\n var myJSONText = JSON.stringify(feed);\n"
},
{
"answer_id": 251780,
"author": "James Newton-King",
"author_id": 11829,
"author_profile": "https://Stackoverflow.com/users/11829",
"pm_score": 2,
"selected": false,
"text": "XmlDocument doc = new XmlDocument();\n\ndoc.LoadXml(@\"<?xml version=\"\"1.0\"\" standalone=\"\"no\"\"?>\n<root>\n <person id=\"\"1\"\">\n <name>Alan</name>\n <url>http://www.google.com</url>\n </person>\n <person id=\"\"2\"\">\n <name>Louis</name>\n <url>http://www.yahoo.com</url>\n </person>\n</root>\");\n\n\nstring jsonText = JavaScriptConvert.SerializeXmlNode(doc);\n//{\n// \"?xml\": {\n// \"@version\": \"1.0\",\n// \"@standalone\": \"no\"\n// },\n// \"root\": {\n// \"person\": [\n// {\n// \"@id\": \"1\",\n// \"name\": \"Alan\",\n// \"url\": \"http://www.google.com\"\n// },\n// {\n// \"@id\": \"2\",\n// \"name\": \"Louis\",\n// \"url\": \"http://www.yahoo.com\"\n// }\n// ]\n// }\n//}\n\nXmlDocument newDoc = (XmlDocument)JavaScriptConvert.DeerializeXmlNode(jsonText);\n\nAssert.AreEqual(doc.InnerXml, newDoc.InnerXml);\n"
},
{
"answer_id": 1692951,
"author": "Uzbekjon",
"author_id": 52317,
"author_profile": "https://Stackoverflow.com/users/52317",
"pm_score": 1,
"selected": false,
"text": "$.jGFeed('http://twitter.com/statuses/user_timeline/26767000.rss',\n function(feeds){\n\n // feeds is a javascript object with RSS content\n\n }, 10);\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3431280/"
] |
246,623
|
<p>I want do something like this:</p>
<pre><code>Result = 'MyString' in [string1, string2, string3, string4];
</code></pre>
<p>This can't be used with strings and I don't want to do something like this:</p>
<pre><code>Result = (('MyString' = string1) or ('MyString' = string2));
</code></pre>
<p>Also I think that creating a StringList to do just this is too complex.</p>
<p>Is there some other way to achieve this?</p>
<p>Thanks.</p>
|
[
{
"answer_id": 246660,
"author": "Burkhard",
"author_id": 12860,
"author_profile": "https://Stackoverflow.com/users/12860",
"pm_score": 2,
"selected": false,
"text": "function StringInArray(Value: string; Strings: array of string): Boolean;\nvar I: Integer;\nbegin\n Result := False;\n for I := Low(Strings) to High(Strings) do\n Result := Result or (Value = Strings[I]);\nend;\n"
},
{
"answer_id": 246730,
"author": "gabr",
"author_id": 4997,
"author_profile": "https://Stackoverflow.com/users/4997",
"pm_score": 3,
"selected": false,
"text": "function StringInArray(const Value: string; Strings: array of string): Boolean;\nvar I: Integer;\nbegin\n Result := True;\n for I := Low(Strings) to High(Strings) do\n if Strings[i] = Value then Exit;\n Result := False;\nend;\n"
},
{
"answer_id": 246753,
"author": "Re0sless",
"author_id": 2098,
"author_profile": "https://Stackoverflow.com/users/2098",
"pm_score": 7,
"selected": true,
"text": "AnsiIndexText(const AnsiString AText, const array of string AValues):integer MatchStr(const AText: string; const AValues: array of string): Boolean; StrUtils Result := (AnsiIndexText('Hi',['Hello','Hi','Foo','Bar']) > -1);\n Result := MatchStr('Hi', ['foo', 'Bar']); \n AnsiIndexText MatchStr MatchText MatchStr"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/727/"
] |
246,636
|
<p>My WCF Service uses wsHttpBinding and works fine from the client when the service is gerenated by the client using the default options as follows:</p>
<pre><code>RServiceClient R = new RServiceClient();
</code></pre>
<p>However, at some point I'll need to be able to specify the location of the service, presumably by changing the endpoint address as follows:</p>
<pre><code>RServiceClient R = new RServiceClient();
R.Endpoint.Address = new EndpointAddress(new Uri "http://xxx.xxxx.xxx:80/RServer/RService.svc"));
</code></pre>
<p>However, when I do specify the exact endpoint, I get a SecurityNegotiationException:
System.ServiceModel.Security.SecurityNegotiationException was unhandled
Message="The caller was not authenticated by the service."
Source="mscorlib"....</p>
<p>The WCF service runs on IIS and has anonymous access enabled under IIS admin. Also, this error occurs when the client is run from the same machine as the service under an admin account - I havn't got to the scary part of running it over the net yet!</p>
<p>Any Ideas?</p>
|
[
{
"answer_id": 246694,
"author": "Calanus",
"author_id": 445,
"author_profile": "https://Stackoverflow.com/users/445",
"pm_score": 0,
"selected": false,
"text": "<system.serviceModel>\n <services>\n <service behaviorConfiguration=\"ServiceBehavior\" name=\"RService\">\n<endpoint address=\"\" binding=\"wsHttpBinding\" bindingConfiguration=\"\"\n name=\"RService\" contract=\"IRService\">\n <identity>\n <dns value=\"localhost\" />\n </identity>\n</endpoint>\n<endpoint address=\"mex\" binding=\"mexHttpBinding\" name=\"MetadataExchange\"\n contract=\"IMetadataExchange\" />\n </service>\n</services>\n <behaviors>\n <serviceBehaviors>\n <behavior name=\"ServiceBehavior\">\n <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->\n <serviceMetadata httpGetEnabled=\"true\"/>\n <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->\n <serviceDebug includeExceptionDetailInFaults=\"true\"/>\n </behavior>\n </serviceBehaviors>\n </behaviors>\n</system.serviceModel>\n"
},
{
"answer_id": 246754,
"author": "Joachim Kerschbaumer",
"author_id": 20227,
"author_profile": "https://Stackoverflow.com/users/20227",
"pm_score": 2,
"selected": false,
"text": "... \n <identity>\n <dns value=\"localhost\" />\n </identity>\n...\n"
},
{
"answer_id": 246858,
"author": "Calanus",
"author_id": 445,
"author_profile": "https://Stackoverflow.com/users/445",
"pm_score": 0,
"selected": false,
"text": " R.Endpoint.Address = new EndpointAddress(new Uri(\"http://bigpuss.homeip.net/RServer/RService.svc\"));\n R.Endpoint.Address = new EndpointAddress(new Uri(\"http://localhost/RServer/RService.svc\"));\n"
},
{
"answer_id": 246862,
"author": "Mike L",
"author_id": 12085,
"author_profile": "https://Stackoverflow.com/users/12085",
"pm_score": 4,
"selected": true,
"text": "<system.serviceModel>\n <bindings>\n <wsHttpBinding>\n <binding name=\"wsHttpBind\">\n <security mode=\"None\">\n <transport clientCredentialType=\"None\" protectionLevel=\"EncryptAndSign\" />\n <message clientCredentialType=\"None\" algorithmSuite=\"Default\" />\n </security>\n </binding>\n </wsHttpBinding>\n </bindings>\n <services>\n <service behaviorConfiguration=\"ServiceBehavior\" \n name=\"RService\">\n <endpoint address=\"\" \n binding=\"wsHttpBinding\" \n bindingConfiguration=\"wsHttpBind\" \n name=\"RService\" \n contract=\"IRService\"> \n <identity>\n <dns value=\"localhost\" />\n </identity>\n </endpoint>\n <endpoint address=\"mex\" \n binding=\"mexHttpBinding\" \n name=\"MetadataExchange\" \n contract=\"IMetadataExchange\" />\n </service>\n </services>\n <behaviors>\n <serviceBehaviors>\n <behavior name=\"ServiceBehavior\">\n <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->\n <serviceMetadata httpGetEnabled=\"true\"/>\n <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->\n <serviceDebug includeExceptionDetailInFaults=\"true\"/>\n </behavior>\n </serviceBehaviors>\n </behaviors>\n</system.serviceModel>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246636",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/445/"
] |
246,644
|
<p>Here is a simplified version of my database model. I have two tables: "Image", and "HostingProvider" which look like this:</p>
<p><strong>[Image]</strong></p>
<ul>
<li>id</li>
<li>filename</li>
<li>hostingprovider_id</li>
</ul>
<p><strong>[HostingProvider]</strong></p>
<ul>
<li>id</li>
<li>base_url</li>
</ul>
<p>Image HostingproviderId is a many-to-one foreign key relationship to the HostingProvider table. (Each image has one hosting provider). </p>
<p>Essentially I want to be able to have my Image class look like this:</p>
<p><strong>[Image]</strong></p>
<ul>
<li>Id</li>
<li>base_url</li>
<li>filename</li>
</ul>
<p>In NHibernate, how can I create a mapping file that will combine the base_url from the HostingProvider table, into the Image class?</p>
|
[
{
"answer_id": 246769,
"author": "yfeldblum",
"author_id": 12349,
"author_profile": "https://Stackoverflow.com/users/12349",
"pm_score": 0,
"selected": false,
"text": "public class Image {\n public virtual HostingProvider HostingProvider { get; set; } // NHibernate takes care of this\n public virtual string BaseUrl { get { return HostingProvider.BaseUrl; } }\n}\n"
},
{
"answer_id": 246782,
"author": "Ben Scheirman",
"author_id": 3381,
"author_profile": "https://Stackoverflow.com/users/3381",
"pm_score": 3,
"selected": true,
"text": "<class name=\"Person\">\n\n <id name=\"Id\" column=\"person_id\" unsaved-value=\"0\">\n\n <generator class=\"native\"/>\n\n </id>\n\n\n\n <property name=\"Name\"/>\n\n <property name=\"Sex\"/>\n\n\n\n <join table=\"address\">\n\n <key column=\"address_id\"/>\n\n <property name=\"Address\"/>\n\n <property name=\"Zip\"/>\n\n <property name=\"Country\"/>\n\n <property name=\"HomePhone\"/>\n\n <property name=\"BusinessPhone\"/>\n\n </join>\n\n</class> \n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13145/"
] |
246,656
|
<p>I am trying to match the folder name in a relative path using C#. I am using the expression: <code>"/(.*)?/"</code> and reversing the matching from left to right to right to left.
When I pass <code>"images/gringo/"</code> into the regular expression, it correctly gives me <code>"gringo"</code> in the first group - I'm only interested in what is between the brackets.
When I pass in <code>"images/"</code>, it fails to pick up <code>"images"</code>.
I have tried using <code>[/^]</code> and <code>[/$]</code> but neither work.</p>
<p>Thanks,
David</p>
|
[
{
"answer_id": 246663,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 4,
"selected": false,
"text": "DirectoryInfo di = new DirectoryInfo(\"images/gringo/\");\nConsole.Out.WriteLine(di.Name);\n"
},
{
"answer_id": 246670,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 2,
"selected": false,
"text": "\"([^/]+)/?$\"\n"
},
{
"answer_id": 247616,
"author": "Dave Sherohman",
"author_id": 18914,
"author_profile": "https://Stackoverflow.com/users/18914",
"pm_score": 1,
"selected": false,
"text": "? * (.*) (.*)? .* /([^/]*)/"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,667
|
<p>I have a table in Access 2007 with 11,000 rows and about 20 columns. I want to create a form button that exports the table to an Excel sheet. The code need to be VBA.</p>
<p>Any Ideas?</p>
|
[
{
"answer_id": 246663,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 4,
"selected": false,
"text": "DirectoryInfo di = new DirectoryInfo(\"images/gringo/\");\nConsole.Out.WriteLine(di.Name);\n"
},
{
"answer_id": 246670,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 2,
"selected": false,
"text": "\"([^/]+)/?$\"\n"
},
{
"answer_id": 247616,
"author": "Dave Sherohman",
"author_id": 18914,
"author_profile": "https://Stackoverflow.com/users/18914",
"pm_score": 1,
"selected": false,
"text": "? * (.*) (.*)? .* /([^/]*)/"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,671
|
<p>Is it possible to import csv data into mysql and automatically create the column names, as in can I create just the table, or must I create the table names as well?</p>
<p>Is it possible to check for duplicate entries upon importing? I have an identifier field, but dont know how to make it so it will not be imported twice.</p>
<p>How would you import a jpeg file on a website into a field? Assume the website has been stored locally, and has the same filename as an identifer with ".jpeg" added on to the end.</p>
|
[
{
"answer_id": 246695,
"author": "Ken",
"author_id": 20074,
"author_profile": "https://Stackoverflow.com/users/20074",
"pm_score": 2,
"selected": true,
"text": "LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'\n[REPLACE | IGNORE]\nINTO TABLE tbl_name\n[CHARACTER SET charset_name]\n[{FIELDS | COLUMNS}\n [TERMINATED BY 'string']\n [[OPTIONALLY] ENCLOSED BY 'char']\n [ESCAPED BY 'char']\n]\n[LINES\n [STARTING BY 'string']\n [TERMINATED BY 'string']\n]\n[IGNORE number LINES]\n[(col_name_or_user_var,...)]\n[SET col_name = expr,...]\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246671",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1246613/"
] |
246,697
|
<p>I need to create some windows service which will execute every N period of time.<br>
The question is:<br>
Which timer control should I use: <code>System.Timers.Timer</code> or <code>System.Threading.Timer</code> one? Does it influence on something? </p>
<p>I am asking because I heard many evidences to non correct work of <code>System.Timers.Timer</code> in windows services.<br>
Thank you.</p>
|
[
{
"answer_id": 246719,
"author": "Andrew Moore",
"author_id": 26210,
"author_profile": "https://Stackoverflow.com/users/26210",
"pm_score": 8,
"selected": true,
"text": "System.Timers.Timer System.Threading.Timer System.Web.UI.Timer System.Windows.Forms.Timer System.Timers.Timer using System;\nusing System.Timers;\n\npublic class Timer1\n{\n private static System.Timers.Timer aTimer;\n\n public static void Main()\n {\n // Normally, the timer is declared at the class level,\n // so that it stays in scope as long as it is needed.\n // If the timer is declared in a long-running method, \n // KeepAlive must be used to prevent the JIT compiler \n // from allowing aggressive garbage collection to occur \n // before the method ends. (See end of method.)\n //System.Timers.Timer aTimer;\n\n // Create a timer with a ten second interval.\n aTimer = new System.Timers.Timer(10000);\n\n // Hook up the Elapsed event for the timer.\n aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);\n\n // Set the Interval to 2 seconds (2000 milliseconds).\n aTimer.Interval = 2000;\n aTimer.Enabled = true;\n\n Console.WriteLine(\"Press the Enter key to exit the program.\");\n Console.ReadLine();\n\n // If the timer is declared in a long-running method, use\n // KeepAlive to prevent garbage collection from occurring\n // before the method ends.\n //GC.KeepAlive(aTimer);\n }\n\n // Specify what you want to happen when the Elapsed event is \n // raised.\n private static void OnTimedEvent(object source, ElapsedEventArgs e)\n {\n Console.WriteLine(\"The Elapsed event was raised at {0}\", e.SignalTime);\n }\n}\n\n/* This code example produces output similar to the following:\n\nPress the Enter key to exit the program.\nThe Elapsed event was raised at 5/20/2007 8:42:27 PM\nThe Elapsed event was raised at 5/20/2007 8:42:29 PM\nThe Elapsed event was raised at 5/20/2007 8:42:31 PM\n...\n */\n System.Threading.Timer using System;\nusing System.Threading;\n\nclass TimerExample\n{\n static void Main()\n {\n AutoResetEvent autoEvent = new AutoResetEvent(false);\n StatusChecker statusChecker = new StatusChecker(10);\n\n // Create the delegate that invokes methods for the timer.\n TimerCallback timerDelegate = \n new TimerCallback(statusChecker.CheckStatus);\n\n // Create a timer that signals the delegate to invoke \n // CheckStatus after one second, and every 1/4 second \n // thereafter.\n Console.WriteLine(\"{0} Creating timer.\\n\", \n DateTime.Now.ToString(\"h:mm:ss.fff\"));\n Timer stateTimer = \n new Timer(timerDelegate, autoEvent, 1000, 250);\n\n // When autoEvent signals, change the period to every \n // 1/2 second.\n autoEvent.WaitOne(5000, false);\n stateTimer.Change(0, 500);\n Console.WriteLine(\"\\nChanging period.\\n\");\n\n // When autoEvent signals the second time, dispose of \n // the timer.\n autoEvent.WaitOne(5000, false);\n stateTimer.Dispose();\n Console.WriteLine(\"\\nDestroying timer.\");\n }\n}\n\nclass StatusChecker\n{\n int invokeCount, maxCount;\n\n public StatusChecker(int count)\n {\n invokeCount = 0;\n maxCount = count;\n }\n\n // This method is called by the timer delegate.\n public void CheckStatus(Object stateInfo)\n {\n AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;\n Console.WriteLine(\"{0} Checking status {1,2}.\", \n DateTime.Now.ToString(\"h:mm:ss.fff\"), \n (++invokeCount).ToString());\n\n if(invokeCount == maxCount)\n {\n // Reset the counter and signal Main.\n invokeCount = 0;\n autoEvent.Set();\n }\n }\n}\n"
},
{
"answer_id": 16566309,
"author": "Nick N.",
"author_id": 869033,
"author_profile": "https://Stackoverflow.com/users/869033",
"pm_score": 1,
"selected": false,
"text": "System.Threading.Timer System.Timers.Timer System.Threading.Timer System.Threading.Timer System.Timers.Timer"
},
{
"answer_id": 31071436,
"author": "MigaelM",
"author_id": 5052740,
"author_profile": "https://Stackoverflow.com/users/5052740",
"pm_score": 0,
"selected": false,
"text": "System.Threading.Timer using System;\nusing System.ServiceProcess;\nusing System.Threading;\n\n public partial class TimerExampleService : ServiceBase\n {\n private AutoResetEvent AutoEventInstance { get; set; }\n private StatusChecker StatusCheckerInstance { get; set; }\n private Timer StateTimer { get; set; }\n public int TimerInterval { get; set; }\n\n public CaseIndexingService()\n {\n InitializeComponent();\n TimerInterval = 300000;\n }\n\n protected override void OnStart(string[] args)\n {\n AutoEventInstance = new AutoResetEvent(false);\n StatusCheckerInstance = new StatusChecker();\n\n // Create the delegate that invokes methods for the timer.\n TimerCallback timerDelegate =\n new TimerCallback(StatusCheckerInstance.CheckStatus);\n\n // Create a timer that signals the delegate to invoke \n // 1.CheckStatus immediately, \n // 2.Wait until the job is finished,\n // 3.then wait 5 minutes before executing again. \n // 4.Repeat from point 2.\n Console.WriteLine(\"{0} Creating timer.\\n\",\n DateTime.Now.ToString(\"h:mm:ss.fff\"));\n //Start Immediately but don't run again.\n StateTimer = new Timer(timerDelegate, AutoEventInstance, 0, Timeout.Infinite);\n while (StateTimer != null)\n {\n //Wait until the job is done\n AutoEventInstance.WaitOne();\n //Wait for 5 minutes before starting the job again.\n StateTimer.Change(TimerInterval, Timeout.Infinite);\n }\n //If the Job somehow takes longer than 5 minutes to complete then it wont matter because we will always wait another 5 minutes before running again.\n }\n\n protected override void OnStop()\n {\n StateTimer.Dispose();\n }\n }\n\n class StatusChecker\n {\n\n public StatusChecker()\n {\n }\n\n // This method is called by the timer delegate.\n public void CheckStatus(Object stateInfo)\n {\n AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;\n Console.WriteLine(\"{0} Start Checking status.\",\n DateTime.Now.ToString(\"h:mm:ss.fff\"));\n //This job takes time to run. For example purposes, I put a delay in here.\n int milliseconds = 5000;\n Thread.Sleep(milliseconds);\n //Job is now done running and the timer can now be reset to wait for the next interval\n Console.WriteLine(\"{0} Done Checking status.\",\n DateTime.Now.ToString(\"h:mm:ss.fff\"));\n autoEvent.Set();\n }\n }\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,701
|
<p>Why do database guys go on about normalisation? </p>
<p>What is it? How does it help? </p>
<p>Does it apply to anything outside of databases? </p>
|
[
{
"answer_id": 246746,
"author": "Chris Cudmore",
"author_id": 18907,
"author_profile": "https://Stackoverflow.com/users/18907",
"pm_score": 3,
"selected": false,
"text": "id, name, address\n214 Mr. Chris 123 Main St.\n317 Mrs. Chris 123 Main St.\n id name familyID\n214 Mr. Chris 27\n317 Mrs. Chris 27\n ID, address\n27 123 Main St.\n"
},
{
"answer_id": 246751,
"author": "JacquesB",
"author_id": 7488,
"author_profile": "https://Stackoverflow.com/users/7488",
"pm_score": 9,
"selected": true,
"text": "Moon(PK) | Planet | Planet kind\n------------------------------\nPhobos | Mars | Rock\nDaimos | Mars | Rock\nIo | Jupiter | Gas\nEuropa | Jupiter | Gas\nGanymede | Jupiter | Gas\n Moon(PK) | Planet | Planet kind\n------------------------------\nPhobos | Mars | Rock\nDeimos | Mars | Rock\nIo | Jupiter | Gas\nEuropa | Jupiter | Rock <-- Oh no!\nGanymede | Jupiter | Gas\n Moon(PK) | Planet(FK) Planet(PK) | Planet kind\n--------------------- ------------------------\nPhobos | Mars Mars | Rock\nDeimos | Mars Jupiter | Gas\nIo | Jupiter \nEuropa | Jupiter \nGanymede | Jupiter \n join"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7211/"
] |
246,710
|
<p>How do I implement the singleton pattern in C#? I want to put my constants and some basic functions in it as I use those everywhere in my project. I want to have them 'Global' and not need to manually bind them every object I create.</p>
|
[
{
"answer_id": 246740,
"author": "yfeldblum",
"author_id": 12349,
"author_profile": "https://Stackoverflow.com/users/12349",
"pm_score": 3,
"selected": false,
"text": "Singleton != Global static"
},
{
"answer_id": 246750,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 6,
"selected": true,
"text": "public static class GlobalSomething\n{\n public static int NumberOfSomething { get; set; }\n\n public static string MangleString( string someValue )\n {\n }\n}\n"
},
{
"answer_id": 246829,
"author": "Sam Meldrum",
"author_id": 16005,
"author_profile": "https://Stackoverflow.com/users/16005",
"pm_score": 2,
"selected": false,
"text": "/// <summary>\n/// Thread-safe singleton implementation\n/// </summary>\npublic sealed class MySingleton {\n\n private static volatile MySingleton instance = null;\n private static object syncRoot = new object();\n\n /// <summary>\n /// The instance of the singleton\n /// safe for multithreading\n /// </summary>\n public static MySingleton Instance {\n get {\n // only create a new instance if one doesn't already exist.\n if (instance == null) {\n // use this lock to ensure that only one thread can access\n // this block of code at once.\n lock (syncRoot) {\n if (instance == null) {\n instance = new MySingleton();\n }\n }\n }\n // return instance where it was just created or already existed.\n return instance;\n }\n }\n\n\n /// <summary>\n /// This constructor must be kept private\n /// only access the singleton through the static Instance property\n /// </summary>\n private MySingleton() {\n\n }\n\n}\n"
},
{
"answer_id": 247058,
"author": "user7375",
"author_id": 7375,
"author_profile": "https://Stackoverflow.com/users/7375",
"pm_score": 2,
"selected": false,
"text": "var builder = new ContainerBuilder()\nbuilder.Register(typeof(Dependency)).SingletonScoped()\nbuilder.Register(c => new RequiresDependency(c.Resolve<Dependency>()))\n\nvar container = builder.Build();\n\nvar configured = container.Resolve<RequiresDependency>();\n"
},
{
"answer_id": 247079,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 3,
"selected": false,
"text": " internal FooService() { } \n static FooService() { }\n\n private static readonly FooService _instance = new FooService();\n\n public static FooService Instance\n {\n get { return _instance; }\n }\n"
},
{
"answer_id": 249057,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 0,
"selected": false,
"text": "public class MySingleton \n{ \n private static MySingleton sngltn; \n private static object locker; \n private MySingleton() {} // Hides parameterless ctor, inhibits use of new() \n public static MySingleton GetMySingleton() \n { \n lock(locker)\n return sngltn?? new MySingleton();\n } \n}\n"
},
{
"answer_id": 373688,
"author": "awaisj",
"author_id": 46520,
"author_profile": "https://Stackoverflow.com/users/46520",
"pm_score": 2,
"selected": false,
"text": "public class Globals\n{\n private string setting1;\n private string setting2;\n\n #region Singleton Pattern Implementation\n\n private class SingletonCreator\n {\n internal static readonly Globals uniqueInstance = new Globals();\n\n static SingletonCreator()\n {\n }\n }\n\n /// <summary>Private Constructor for Singleton Pattern Implementaion</summary>\n /// <remarks>can be used for initializing member variables</remarks>\n private Globals()\n {\n\n }\n\n /// <summary>Returns a reference to the unique instance of Globals class</summary>\n /// <remarks>used for getting a reference of Globals class</remarks>\n public static Globals GetInstance\n {\n get { return SingletonCreator.uniqueInstance; }\n }\n\n #endregion\n\n public string Setting1\n {\n get { return this.setting1; }\n set { this.setting1 = value; }\n }\n\n public string Setting2\n {\n get { return this.setting2; }\n set { this.setting2 = value; }\n }\n\n public static int Constant1 \n {\n get { reutrn 100; }\n }\n\n public static int Constat2\n {\n get { return 200; }\n }\n\n public static DateTime SqlMinDate\n {\n get { return new DateTime(1900, 1, 1, 0, 0, 0); }\n }\n\n}\n"
},
{
"answer_id": 384807,
"author": "Scott P",
"author_id": 33848,
"author_profile": "https://Stackoverflow.com/users/33848",
"pm_score": 2,
"selected": false,
"text": " public class GenericSingleton<T> where T : new()\n {\n private static T ms_StaticInstance = new T();\n\n public T Build()\n {\n return ms_StaticInstance;\n }\n }\n\n...\n GenericSingleton<SimpleType> builder1 = new GenericSingleton<SimpleType>();\n SimpleType simple = builder1.Build();\n"
},
{
"answer_id": 47729056,
"author": "Sapnandu",
"author_id": 746270,
"author_profile": "https://Stackoverflow.com/users/746270",
"pm_score": 0,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\n\nnamespace TEClaim.Models\n{\npublic class LogedinUserDetails\n{\n public string UserID { get; set; }\n public string UserRole { get; set; }\n public string UserSupervisor { get; set; }\n public LogedinUserDetails()\n {\n\n }\n\n public static LogedinUserDetails Singleton()\n {\n LogedinUserDetails oSingleton;\n\n if (null == System.Web.HttpContext.Current.Session[\"LogedinUserDetails\"])\n { \n oSingleton = new LogedinUserDetails();\n System.Web.HttpContext.Current.Session[\"LogedinUserDetails\"] = oSingleton;\n }\n else\n { \n oSingleton = (LogedinUserDetails)System.Web.HttpContext.Current.Session[\"LogedinUserDetails\"];\n }\n\n //Return the single instance of this class that was stored in the session\n return oSingleton;\n }\n}\n}\n [HttpPost]\npublic ActionResult Login(FormCollection collection)\n{\n LogedinUserDetails User_Details = LogedinUserDetails.Singleton();\n User_Details.UserID = \"12\";\n User_Details.UserRole = \"SuperAdmin\";\n User_Details.UserSupervisor = \"815978\";\n return RedirectToAction(\"Dashboard\", \"Home\");\n}\n public ActionResult Dashboard()\n {\n LogedinUserDetails User_Details = LogedinUserDetails.Singleton();\n ViewData[\"UserID\"] = User_Details.UserID;\n ViewData[\"UserRole\"] = User_Details.UserRole;\n ViewData[\"UserSupervisor\"] = User_Details.UserSupervisor;\n\n return View();\n }\n"
},
{
"answer_id": 49667561,
"author": "brajesh jaishwal",
"author_id": 9456863,
"author_profile": "https://Stackoverflow.com/users/9456863",
"pm_score": 0,
"selected": false,
"text": "public sealed class MySingleton\n{\n static volatile Lazy<MySingleton> _instance = new Lazy<MySingleton>(() => new MySingleton(), true);\n public static MySingleton Instance => _instance.Value;\n private MySingleton() { }\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246710",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22562/"
] |
246,723
|
<p>Which functions are available within Delphi to play a sound-file?</p>
|
[
{
"answer_id": 246772,
"author": "Igal Tabachnik",
"author_id": 8205,
"author_profile": "https://Stackoverflow.com/users/8205",
"pm_score": 6,
"selected": true,
"text": "uses MMSystem;\n\nprocedure TForm1.Button1Click(Sender: TObject);\nbegin\n sndPlaySound('C:\\Windows\\Media\\Tada.wav',\n SND_NODEFAULT Or SND_ASYNC Or SND_LOOP);\nend;\n\nprocedure TForm1.Button2Click(Sender: TObject);\nbegin\n sndPlaySound(nil, 0); // Stops the sound\nend;\n"
},
{
"answer_id": 36690395,
"author": "Server Overflow",
"author_id": 46207,
"author_profile": "https://Stackoverflow.com/users/46207",
"pm_score": 3,
"selected": false,
"text": "procedure PlaySoundFile(FileName: string);\nbegin\n if FileExists(FileName)\n then PlaySound(pchar(FileName), 0, SND_ASYNC or SND_FILENAME); \n \n { Flags are:\n SND_SYNC =0 = Start playing, and wait for the sound to finish\n SND_ASYNC =1 = Start playing, and don't wait to return\n SND_LOOP =8 = Keep looping the sound until another sound is played }\nend;\n procedure PlayWinSound(SystemSoundName: string);\nbegin\n Winapi.MMSystem.PlaySound(PChar(SystemSoundName), 0, SND_ASYNC);\nend;\n\n\nFor SystemSoundName use one of the constants below:\n\n SystemEXCLAMATION - Note)\n SystemHAND - Critical Stop)\n SystemQUESTION - Question)\n SystemSTART - Windows-Start)\n SystemEXIT - Windows-Shutdown)\n SystemASTERIX - Star)\n RESTOREUP - Enlarge)\n RESTOREDOWN - Shrink)\n MENUCOMMAND - Menu)\n MENUPOPUP - Pop-Up)\n MAXIMIZE - Maximize)\n MINIMIZE - Minimize)\n MAILBEEP - New Mail)\n OPEN - Open Application)\n CLOSE - Close Application)\n APPGPFAULT - Program Error)\n Asterisk - played when a popup alert is displayed, like a warning message.\n Calendar Reminder - played when a Calendar event is taking place.\n Critical Battery Alarm - played when your battery reaches its critical level.\n Critical Stop - played when a fatal error occurs.\n Default Beep - played for multiple reasons, depending on what you do. For example, it will play if you try to select a parent window before closing the active one.\n Desktop Mail Notif - played when you receive a message in your desktop email client.\n Device Connect - played when you connect a device to your computer. For example, when you insert a memory stick.\n Device Disconnect - played when you disconnect a device from your computer.\n Device Connect Failed - played when something happened with the device that you were trying to connect.\n Exclamation - played when you try to do something that is not supported by Windows.\n Instant Message Notif - played when you receive an instant message.\n Low Battery Alarm - played when the battery is running Low.\n Message Nudge - played when you receive a BUZZ in an instant message.\n New Fax Notification - played when you receive a fax via your fax-modem.\n New Mail Notification - played when you receive an email message.\n New Text Message Notif - played when you receive a text message.\n NFP Completion - played when the transfer of data via NFC between your Windows device and another device is completed.\n NFP Connection - played when your Windows device is connecting to another device via NFC.\n Notification - played when a default notification from a program or app is displayed.\n System Notification - played when a system notification is displayed.\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32354/"
] |
246,725
|
<p>When starting a django application using <code>python manage.py shell</code>, I get an InteractiveConsole shell - I can use tab completion, etc.</p>
<pre><code>Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
</code></pre>
<p>When just starting a python interpreter using <code>python</code>, it doesn't offer tab completion.</p>
<p>Can someone tell me what django is doing to give me an interactive console, or what I need to do to start an interactive console without a django app?</p>
|
[
{
"answer_id": 246779,
"author": "ashchristopher",
"author_id": 22306,
"author_profile": "https://Stackoverflow.com/users/22306",
"pm_score": 9,
"selected": true,
"text": "# ~/.pythonrc\n# enable syntax completion\ntry:\n import readline\nexcept ImportError:\n print(\"Module readline not available.\")\nelse:\n import rlcompleter\n readline.parse_and_bind(\"tab: complete\")\n export PYTHONSTARTUP=~/.pythonrc\n"
},
{
"answer_id": 32135426,
"author": "alan_wang",
"author_id": 3924168,
"author_profile": "https://Stackoverflow.com/users/3924168",
"pm_score": 4,
"selected": false,
"text": "pip install ptpython\n import os\n\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"testweb.settings\")\n"
},
{
"answer_id": 44874592,
"author": "TrigonaMinima",
"author_id": 2650427,
"author_profile": "https://Stackoverflow.com/users/2650427",
"pm_score": 1,
"selected": false,
"text": "readline pip ImportError: libncursesw.so.5: cannot open shared object file: No such file or directory\n cd /usr/lib\nln -s libncursesw.so libncursesw.so.5\n .pythonrc .bashrc"
},
{
"answer_id": 55012067,
"author": "Mr.B",
"author_id": 11156479,
"author_profile": "https://Stackoverflow.com/users/11156479",
"pm_score": 3,
"selected": false,
"text": "pip install pyreadline3 # previously, pyreadline but that package was abandoned\npip install ipython\n"
},
{
"answer_id": 60163620,
"author": "Ruwinda Fernando",
"author_id": 10165556,
"author_profile": "https://Stackoverflow.com/users/10165556",
"pm_score": 0,
"selected": false,
"text": "fernanr@gnuruwi ~ $ python3.6\nPython 3.6.3 (default, Apr 10 2019, 14:37:36)\n[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import os\n>>> os.\nDisplay all 318 possibilities? (y or n)\nos.CLD_CONTINUED os.O_RDONLY os.ST_NOEXEC os.environ os.getpid( os.readlink( os.spawnvpe(\nos.CLD_DUMPED os.O_RDWR os.ST_NOSUID os.environb os.getppid( os.readv( os.st\n"
},
{
"answer_id": 60163736,
"author": "Ruwinda Fernando",
"author_id": 10165556,
"author_profile": "https://Stackoverflow.com/users/10165556",
"pm_score": -1,
"selected": false,
"text": "fernanr@crsatx4 ~ $ cat .bashrc | grep -i python\n#Tab completion for python shell\nexport PYTHONSTARTUP=~/.pythonrc\nfernanr@crsatx4 ~ $ . ~/.bashrc\nfernanr@crsatx4 ~ $ echo $?\n0\nfernanr@crsatx4 ~ $ python2\nPython 2.7.5 (default, Jun 11 2019, 14:33:56)\n[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import os\n>>> os.\nDisplay all 249 possibilities? (y or n)\nos.EX_CANTCREAT os.O_WRONLY \n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246725",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22306/"
] |
246,726
|
<p>I'm working on a report in SSRS (SQL Server Reporting Services) right now, and I'm having a problem getting a rectanlge I draw on the page in the report designer to grow. Basically, I've got a rectangle drawn, and then I put a text field inside of it. The contents of this text field can be either very short or very long, so I want it to grow to accomodate its contents.</p>
<p>But when I enter the long text, the textbox grows and then sticks outside of the lines of the rectangle. From the SSRS documentation I read, it says rectangles should grow to contain the items within them, and that those items are "peers".</p>
<p>What gives?</p>
|
[
{
"answer_id": 247114,
"author": "Erick B",
"author_id": 1373,
"author_profile": "https://Stackoverflow.com/users/1373",
"pm_score": 3,
"selected": true,
"text": "CanGrow = TRUE"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246726",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/146/"
] |
246,760
|
<p>In an UML component diagram, how does one tag or identify a component as a database, so that it's easily recognizable? In the old days there was the cylinder symbol for showing database but that's not part of the UML. Same goes for an application server for instance, how would that be shown?</p>
<p>Are stereotypes applicable here? Can the component symbol be enhanced with graphical elements?</p>
|
[
{
"answer_id": 246768,
"author": "Thomas Owens",
"author_id": 572,
"author_profile": "https://Stackoverflow.com/users/572",
"pm_score": 1,
"selected": false,
"text": "<<database>> <<infrastructure>>"
},
{
"answer_id": 246771,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 3,
"selected": false,
"text": "<<database>>"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,762
|
<p>I have a Spring Interceptor which attempts to add an HTTP header in the postHandle() method.</p>
<pre><code>public void postHandle(HttpServletRequest req, HttpServletResponse resp,
Object obj1, ModelAndView mv)
throws Exception {
response.setHeader("SomeHeaderSet", "set");
response.addHeader("SomeHeaderAdd", "added");
}
}
</code></pre>
<p>However, neither header is added with either setHeader() or addHeader().</p>
<p>Is this even valid to do in the interceptor? I figured it WOULD be, but it ain't workin.</p>
<p>Regards,
Dustin</p>
|
[
{
"answer_id": 247522,
"author": "DustinB",
"author_id": 7888,
"author_profile": "https://Stackoverflow.com/users/7888",
"pm_score": 2,
"selected": true,
"text": "response.setContentLength() response.setContentLength()"
},
{
"answer_id": 3092988,
"author": "Kristian",
"author_id": 11429,
"author_profile": "https://Stackoverflow.com/users/11429",
"pm_score": 0,
"selected": false,
"text": "<filter>\n <filter-name>etagFilter</filter-name>\n <filter-class>org.springframework.web.filter.ShallowEtagHeaderFilter</filter-class>\n</filter>\n\n<filter-mapping>\n <filter-name>etagFilter</filter-name>\n <servlet-name>myServlet</servlet-name>\n</filter-mapping>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7888/"
] |
246,766
|
<p>I'm using Castle ActiveRecord, but this question applies to NHibernate, too, since a solution that works with NHibernate should work for ActiveRecord. Anyway, what I have is an underlying table structure like this:</p>
<p>TableA -hasMany-> TableB</p>
<p>I have corresponding objects EntityA and EntityB. EntityA has an IList of EntityB objects. This part works fine. Now, I want EntityB to have some kind of reference back to EntityA. I know I can use the BelongsTo attribute on EntityB to give it an actual reference back to the full EntityA type, like:</p>
<pre><code>[BelongsTo("tableAid")]
public EntityA Parent { get; set; }
</code></pre>
<p>But what I'd really like to do is:</p>
<pre><code>[BelongsTo("tableAid")]
public int ParentId { get; set; }
</code></pre>
<p>So, EntityB would store only the ID of the parent object, not a reference to the actual object. This is a trivial example, but I have good reasons for wanting to go with this approach. In the application I'm working on, we have pages that display specific EntityB-like objects, and we'd like for those pages to include links (as in hyperlinks) to the corresponding parent pages. We can do that by using the first approach above, but that requires that the entire EntityA object be loaded when all I really need is the ID. It's not a huge deal, but it just seems wasteful. I know I can use lazy-loading, but again, that seems more like a hack to me...</p>
<p>I have tried flagging the foreign key with the [Property] attribute like so:</p>
<pre><code>[Property]
public int ParentId { get; set; }
</code></pre>
<p>The problem with this approach is that EntityB.ParentId remains null when you do a EntityA.SaveAndFlush() on a new object tree. The correct value is being written to the database, and I can force the value back into EntityB.ParentId by doing an EntityA.Refresh(), but again, that seems like a bit of a hack.</p>
|
[
{
"answer_id": 246988,
"author": "Tim Scott",
"author_id": 29493,
"author_profile": "https://Stackoverflow.com/users/29493",
"pm_score": 0,
"selected": false,
"text": "[Property] public int ParentId { get; set; }\n ParentId"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32353/"
] |
246,787
|
<p>I'm creating a cms and have not yet settled on the matter of where to store the complete url for a given page in the structure.</p>
<p>Every page have a slug (url friendly name of the page) and every page has a nullable (for top-level pages) parent and children.</p>
<p>Where do I store the complete url (/first-page/sub-page) for a given page? Should this go in the database along with the other properties of the page or in some cache?</p>
<p><strong>Update</strong></p>
<p>It's not the database design I'm asking about, rather where to store the complete url to a given page so I don't need to traverse the entire url to get the page that the user requested (/first-page/sub-page)</p>
<p><strong>Update 2</strong></p>
<p>I need to find which page belongs to the currently requested url. If the requested url is /first-page/sub-page I don't want to split the url and looping through the database (obviously).</p>
<p>I'd rather have the entire url in the table so that I can just do a single query (WHERE url = '/first-page/sub-page') but this does not seem ideal, what if I change the slug for the parent page? Then I also need to update the url-field for all descendants.</p>
<p>How do other people solve this issue? Are they putting it in the database? In a cache that maps /first-page-/sub-page to the id for the page? Or are they splitting the requested url and looping though the database?</p>
<p>Thanks</p>
<p>Anders</p>
|
[
{
"answer_id": 246988,
"author": "Tim Scott",
"author_id": 29493,
"author_profile": "https://Stackoverflow.com/users/29493",
"pm_score": 0,
"selected": false,
"text": "[Property] public int ParentId { get; set; }\n ParentId"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22092/"
] |
246,791
|
<p>I'm consuming a third-party resource (a .dll) in a web service, and my problem is, that invoking this resource (calling a method) is done asynchronous - I need to subscribe to an event, to get the answer for my request. How do I do that in a c# web service?</p>
<p><strong>Update:</strong></p>
<p>With regard to <a href="https://stackoverflow.com/questions/246791/invoking-asynchronous-call-in-a-c-web-service/246892#246892">Sunny's answer</a>:</p>
<p>I don't want to make my web service asynchronous.</p>
|
[
{
"answer_id": 246892,
"author": "Sunny Milenov",
"author_id": 8220,
"author_profile": "https://Stackoverflow.com/users/8220",
"pm_score": 0,
"selected": false,
"text": "using System;\nusing System.Web.Services;\n\n[WebService(Namespace=\"http://www.contoso.com/\")]\npublic class MyService : WebService {\n public RemoteService remoteService;\n public MyService() {\n // Create a new instance of proxy class for \n // the XML Web service to be called.\n remoteService = new RemoteService();\n }\n // Define the Begin method.\n [WebMethod]\n public IAsyncResult BeginGetAuthorRoyalties(String Author,\n AsyncCallback callback, object asyncState) {\n // Begin asynchronous communictation with a different XML Web\n // service.\n return remoteService.BeginReturnedStronglyTypedDS(Author,\n callback,asyncState);\n }\n // Define the End method.\n [WebMethod]\n public AuthorRoyalties EndGetAuthorRoyalties(IAsyncResult\n asyncResult) {\n // Return the asynchronous result from the other XML Web service.\n return remoteService.EndReturnedStronglyTypedDS(asyncResult);\n }\n}\n"
},
{
"answer_id": 247661,
"author": "Dan Finucane",
"author_id": 30026,
"author_profile": "https://Stackoverflow.com/users/30026",
"pm_score": 2,
"selected": false,
"text": " HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(\"http://www.stackoverflow.com\");\n IAsyncResult asyncResult = httpWebRequest.BeginGetResponse(null, null);\n\n asyncResult.AsyncWaitHandle.WaitOne();\n\n using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.EndGetResponse(asyncResult))\n using (StreamReader responseStreamReader = new StreamReader(httpWebResponse.GetResponseStream()))\n {\n string responseText = responseStreamReader.ReadToEnd();\n }\n"
},
{
"answer_id": 249532,
"author": "csgero",
"author_id": 21764,
"author_profile": "https://Stackoverflow.com/users/21764",
"pm_score": 2,
"selected": true,
"text": "AutoResetEvent processingCompleteEvent = new AutoResetEvent();\n // call 3rd party component\nprocessingCompleteEvent.WaitOne()\n processingCompleteEvent.Set()\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,801
|
<p>I have a PHP script that can encode a PNG image to a Base64 string.</p>
<p>I'd like to do the same thing using JavaScript. I know how to open files, but I'm not sure how to do the encoding. I'm not used to working with binary data.</p>
|
[
{
"answer_id": 246813,
"author": "Sunny Milenov",
"author_id": 8220,
"author_profile": "https://Stackoverflow.com/users/8220",
"pm_score": 8,
"selected": false,
"text": "/**\n*\n* Base64 encode / decode\n* http://www.webtoolkit.info/\n*\n**/\nvar Base64 = {\n\n // private property\n _keyStr : \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\",\n\n // public method for encoding\n encode : function (input) {\n var output = \"\";\n var chr1, chr2, chr3, enc1, enc2, enc3, enc4;\n var i = 0;\n\n input = Base64._utf8_encode(input);\n\n while (i < input.length) {\n\n chr1 = input.charCodeAt(i++);\n chr2 = input.charCodeAt(i++);\n chr3 = input.charCodeAt(i++);\n\n enc1 = chr1 >> 2;\n enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n enc4 = chr3 & 63;\n\n if (isNaN(chr2)) {\n enc3 = enc4 = 64;\n } else if (isNaN(chr3)) {\n enc4 = 64;\n }\n\n output = output +\n this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +\n this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);\n }\n return output;\n },\n\n // public method for decoding\n decode : function (input) {\n var output = \"\";\n var chr1, chr2, chr3;\n var enc1, enc2, enc3, enc4;\n var i = 0;\n\n input = input.replace(/[^A-Za-z0-9\\+\\/\\=]/g, \"\");\n\n while (i < input.length) {\n\n enc1 = this._keyStr.indexOf(input.charAt(i++));\n enc2 = this._keyStr.indexOf(input.charAt(i++));\n enc3 = this._keyStr.indexOf(input.charAt(i++));\n enc4 = this._keyStr.indexOf(input.charAt(i++));\n\n chr1 = (enc1 << 2) | (enc2 >> 4);\n chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);\n chr3 = ((enc3 & 3) << 6) | enc4;\n\n output = output + String.fromCharCode(chr1);\n\n if (enc3 != 64) {\n output = output + String.fromCharCode(chr2);\n }\n if (enc4 != 64) {\n output = output + String.fromCharCode(chr3);\n }\n }\n\n output = Base64._utf8_decode(output);\n\n return output;\n },\n\n // private method for UTF-8 encoding\n _utf8_encode : function (string) {\n string = string.replace(/\\r\\n/g,\"\\n\");\n var utftext = \"\";\n\n for (var n = 0; n < string.length; n++) {\n\n var c = string.charCodeAt(n);\n\n if (c < 128) {\n utftext += String.fromCharCode(c);\n }\n else if((c > 127) && (c < 2048)) {\n utftext += String.fromCharCode((c >> 6) | 192);\n utftext += String.fromCharCode((c & 63) | 128);\n }\n else {\n utftext += String.fromCharCode((c >> 12) | 224);\n utftext += String.fromCharCode(((c >> 6) & 63) | 128);\n utftext += String.fromCharCode((c & 63) | 128);\n }\n }\n return utftext;\n },\n\n // private method for UTF-8 decoding\n _utf8_decode : function (utftext) {\n var string = \"\";\n var i = 0;\n var c = c1 = c2 = 0;\n\n while ( i < utftext.length ) {\n\n c = utftext.charCodeAt(i);\n\n if (c < 128) {\n string += String.fromCharCode(c);\n i++;\n }\n else if((c > 191) && (c < 224)) {\n c2 = utftext.charCodeAt(i+1);\n string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));\n i += 2;\n }\n else {\n c2 = utftext.charCodeAt(i+1);\n c3 = utftext.charCodeAt(i+2);\n string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));\n i += 3;\n }\n }\n return string;\n }\n}\n"
},
{
"answer_id": 247261,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 11,
"selected": true,
"text": "btoa() atob() btoa() atob() 0 0xff btoa() atob()"
},
{
"answer_id": 6740027,
"author": "user850789",
"author_id": 850789,
"author_profile": "https://Stackoverflow.com/users/850789",
"pm_score": 7,
"selected": false,
"text": "var Base64 = {\n // private property\n _keyStr : \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\",\n\n // public method for encoding\n encode : function (input) {\n var output = \"\";\n var chr1, chr2, chr3, enc1, enc2, enc3, enc4;\n var i = 0;\n\n input = Base64._utf8_encode(input);\n\n while (i < input.length) {\n\n chr1 = input.charCodeAt(i++);\n chr2 = input.charCodeAt(i++);\n chr3 = input.charCodeAt(i++);\n\n enc1 = chr1 >> 2;\n enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n enc4 = chr3 & 63;\n\n if (isNaN(chr2)) {\n enc3 = enc4 = 64;\n } else if (isNaN(chr3)) {\n enc4 = 64;\n }\n\n output = output +\n Base64._keyStr.charAt(enc1) + Base64._keyStr.charAt(enc2) +\n Base64._keyStr.charAt(enc3) + Base64._keyStr.charAt(enc4);\n }\n\n return output;\n },\n\n // public method for decoding\n decode : function (input) {\n var output = \"\";\n var chr1, chr2, chr3;\n var enc1, enc2, enc3, enc4;\n var i = 0;\n\n input = input.replace(/[^A-Za-z0-9\\+\\/\\=]/g, \"\");\n\n while (i < input.length) {\n\n enc1 = Base64._keyStr.indexOf(input.charAt(i++));\n enc2 = Base64._keyStr.indexOf(input.charAt(i++));\n enc3 = Base64._keyStr.indexOf(input.charAt(i++));\n enc4 = Base64._keyStr.indexOf(input.charAt(i++));\n\n chr1 = (enc1 << 2) | (enc2 >> 4);\n chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);\n chr3 = ((enc3 & 3) << 6) | enc4;\n\n output = output + String.fromCharCode(chr1);\n\n if (enc3 != 64) {\n output = output + String.fromCharCode(chr2);\n }\n if (enc4 != 64) {\n output = output + String.fromCharCode(chr3);\n }\n }\n\n output = Base64._utf8_decode(output);\n\n return output;\n },\n\n // private method for UTF-8 encoding\n _utf8_encode : function (string) {\n string = string.replace(/\\r\\n/g,\"\\n\");\n var utftext = \"\";\n\n for (var n = 0; n < string.length; n++) {\n\n var c = string.charCodeAt(n);\n\n if (c < 128) {\n utftext += String.fromCharCode(c);\n }\n else if((c > 127) && (c < 2048)) {\n utftext += String.fromCharCode((c >> 6) | 192);\n utftext += String.fromCharCode((c & 63) | 128);\n }\n else {\n utftext += String.fromCharCode((c >> 12) | 224);\n utftext += String.fromCharCode(((c >> 6) & 63) | 128);\n utftext += String.fromCharCode((c & 63) | 128);\n }\n }\n return utftext;\n },\n\n // private method for UTF-8 decoding\n _utf8_decode : function (utftext) {\n var string = \"\";\n var i = 0;\n var c = c1 = c2 = 0;\n\n while ( i < utftext.length ) {\n\n c = utftext.charCodeAt(i);\n\n if (c < 128) {\n string += String.fromCharCode(c);\n i++;\n }\n else if((c > 191) && (c < 224)) {\n c2 = utftext.charCodeAt(i+1);\n string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));\n i += 2;\n }\n else {\n c2 = utftext.charCodeAt(i+1);\n c3 = utftext.charCodeAt(i+2);\n string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));\n i += 3;\n }\n }\n return string;\n }\n}\n"
},
{
"answer_id": 6836708,
"author": "robbles",
"author_id": 279089,
"author_profile": "https://Stackoverflow.com/users/279089",
"pm_score": 5,
"selected": false,
"text": "_utf8_decode c1 c2 var c3 // private method for UTF-8 decoding\n_utf8_decode : function (utftext) {\n var string = \"\";\n var i = 0;\n var c = 0, c1 = 0, c2 = 0;\n\n while ( i < utftext.length ) {\n\n c = utftext.charCodeAt(i);\n\n if (c < 128) {\n string += String.fromCharCode(c);\n i++;\n }\n else if((c > 191) && (c < 224)) {\n c1 = utftext.charCodeAt(i+1);\n string += String.fromCharCode(((c & 31) << 6) | (c1 & 63));\n i += 2;\n }\n else {\n c1 = utftext.charCodeAt(i+1);\n c2 = utftext.charCodeAt(i+2);\n string += String.fromCharCode(((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63));\n i += 3;\n }\n }\n return string;\n}\n"
},
{
"answer_id": 7139071,
"author": "magikMaker",
"author_id": 729003,
"author_profile": "https://Stackoverflow.com/users/729003",
"pm_score": 4,
"selected": false,
"text": "// if this is your Base64 encoded string\nvar str = 'VGhpcyBpcyBhbiBhd2Vzb21lIHNjcmlwdA=='; \n\n// make URL friendly:\nstr = str.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/\\=+$/, '');\n\n// reverse to original encoding\nstr = (str + '===').slice(0, str.length + (str.length % 4));\nstr = str.replace(/-/g, '+').replace(/_/g, '/');\n"
},
{
"answer_id": 8640873,
"author": "Vitalii Fedorenko",
"author_id": 288671,
"author_profile": "https://Stackoverflow.com/users/288671",
"pm_score": 7,
"selected": false,
"text": "btoa atob $.base64.encode(\"this is a test\");\n$.base64.decode(\"dGhpcyBpcyBhIHRlc3Q=\");\n"
},
{
"answer_id": 12041192,
"author": "Joe Dyndale",
"author_id": 1359450,
"author_profile": "https://Stackoverflow.com/users/1359450",
"pm_score": 4,
"selected": false,
"text": "decodeToHex encodeFromHex var Base64 = (function() {\n \"use strict\";\n\n var _keyStr = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";\n\n var _utf8_encode = function (string) {\n\n var utftext = \"\", c, n;\n\n string = string.replace(/\\r\\n/g,\"\\n\");\n\n for (n = 0; n < string.length; n++) {\n\n c = string.charCodeAt(n);\n\n if (c < 128) {\n\n utftext += String.fromCharCode(c);\n\n } else if((c > 127) && (c < 2048)) {\n\n utftext += String.fromCharCode((c >> 6) | 192);\n utftext += String.fromCharCode((c & 63) | 128);\n } else {\n\n utftext += String.fromCharCode((c >> 12) | 224);\n utftext += String.fromCharCode(((c >> 6) & 63) | 128);\n utftext += String.fromCharCode((c & 63) | 128);\n }\n }\n return utftext;\n };\n\n var _utf8_decode = function (utftext) {\n var string = \"\", i = 0, c = 0, c1 = 0, c2 = 0;\n\n while ( i < utftext.length ) {\n\n c = utftext.charCodeAt(i);\n\n if (c < 128) {\n\n string += String.fromCharCode(c);\n i++;\n\n } else if((c > 191) && (c < 224)) {\n\n c1 = utftext.charCodeAt(i+1);\n string += String.fromCharCode(((c & 31) << 6) | (c1 & 63));\n i += 2;\n\n } else {\n\n c1 = utftext.charCodeAt(i+1);\n c2 = utftext.charCodeAt(i+2);\n string += String.fromCharCode(((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63));\n i += 3;\n }\n }\n return string;\n };\n\n var _hexEncode = function(input) {\n var output = '', i;\n\n for(i = 0; i < input.length; i++) {\n output += input.charCodeAt(i).toString(16);\n }\n\n return output;\n };\n\n var _hexDecode = function(input) {\n var output = '', i;\n\n if(input.length % 2 > 0) {\n input = '0' + input;\n }\n\n for(i = 0; i < input.length; i = i + 2) {\n output += String.fromCharCode(parseInt(input.charAt(i) + input.charAt(i + 1), 16));\n }\n return output;\n };\n\n var encode = function (input) {\n var output = \"\", chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0;\n\n input = _utf8_encode(input);\n\n while (i < input.length) {\n\n chr1 = input.charCodeAt(i++);\n chr2 = input.charCodeAt(i++);\n chr3 = input.charCodeAt(i++);\n\n enc1 = chr1 >> 2;\n enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n enc4 = chr3 & 63;\n\n if (isNaN(chr2)) {\n enc3 = enc4 = 64;\n } else if (isNaN(chr3)) {\n enc4 = 64;\n }\n\n output += _keyStr.charAt(enc1);\n output += _keyStr.charAt(enc2);\n output += _keyStr.charAt(enc3);\n output += _keyStr.charAt(enc4);\n }\n return output;\n };\n\n var decode = function (input) {\n var output = \"\", chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0;\n\n input = input.replace(/[^A-Za-z0-9\\+\\/\\=]/g, \"\");\n\n while (i < input.length) {\n\n enc1 = _keyStr.indexOf(input.charAt(i++));\n enc2 = _keyStr.indexOf(input.charAt(i++));\n enc3 = _keyStr.indexOf(input.charAt(i++));\n enc4 = _keyStr.indexOf(input.charAt(i++));\n\n chr1 = (enc1 << 2) | (enc2 >> 4);\n chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);\n chr3 = ((enc3 & 3) << 6) | enc4;\n\n output += String.fromCharCode(chr1);\n\n if (enc3 !== 64) {\n output += String.fromCharCode(chr2);\n }\n if (enc4 !== 64) {\n output += String.fromCharCode(chr3);\n }\n\n }\n\n return _utf8_decode(output);\n };\n\n var decodeToHex = function(input) {\n return _hexEncode(decode(input));\n };\n\n var encodeFromHex = function(input) {\n return encode(_hexDecode(input));\n };\n\n return {\n 'encode': encode,\n 'decode': decode,\n 'decodeToHex': decodeToHex,\n 'encodeFromHex': encodeFromHex\n };\n}());\n"
},
{
"answer_id": 14298618,
"author": "Nedudi",
"author_id": 890850,
"author_profile": "https://Stackoverflow.com/users/890850",
"pm_score": 3,
"selected": false,
"text": "function getBase64Image(img) {\n var canvas = document.createElement(\"canvas\");\n canvas.width = img.width;\n canvas.height = img.height;\n var ctx = canvas.getContext(\"2d\");\n ctx.drawImage(img, 0, 0);\n var dataURL = canvas.toDataURL(\"image/png\");\n // escape data:image prefix\n return dataURL.replace(/^data:image\\/(png|jpg);base64,/, \"\");\n // or just return dataURL\n // return dataURL\n}\n function getBase64ImageById(id){\n return getBase64Image(document.getElementById(id));\n}\n"
},
{
"answer_id": 14687010,
"author": "Kathir",
"author_id": 1455347,
"author_profile": "https://Stackoverflow.com/users/1455347",
"pm_score": 4,
"selected": false,
"text": "var encodedData = window.btoa(stringToEncode); var decodedData = window.atob(encodedData);"
},
{
"answer_id": 15489720,
"author": "Nijikokun",
"author_id": 983070,
"author_profile": "https://Stackoverflow.com/users/983070",
"pm_score": 4,
"selected": false,
"text": "btoa atob base64.encode(/* String */);\nbase64.decode(/* String */);\n\nutf8.encode(/* String */);\nutf8.decode(/* String */);\n"
},
{
"answer_id": 17827101,
"author": "Nico",
"author_id": 2613359,
"author_profile": "https://Stackoverflow.com/users/2613359",
"pm_score": 2,
"selected": false,
"text": "var encode = function (input) {\n var output = [], chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0;\n\n input = _utf8_encode(input);\n\n while (i < input.length) {\n\n chr1 = input.charCodeAt(i++);\n chr2 = input.charCodeAt(i++);\n chr3 = input.charCodeAt(i++);\n\n enc1 = chr1 >> 2;\n enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n enc4 = chr3 & 63;\n\n if (isNaN(chr2)) {\n enc3 = enc4 = 64;\n } else if (isNaN(chr3)) {\n enc4 = 64;\n }\n\n output.push(_keyStr.charAt(enc1));\n output.push(_keyStr.charAt(enc2));\n output.push(_keyStr.charAt(enc3));\n output.push(_keyStr.charAt(enc4));\n\n }\n\n return output.join(\"\");\n};\n"
},
{
"answer_id": 18513304,
"author": "Vikash Pandey",
"author_id": 2728855,
"author_profile": "https://Stackoverflow.com/users/2728855",
"pm_score": 3,
"selected": false,
"text": "var str = dojox.encoding.base64.encode(myByteArray);\n var bytes = dojox.encoding.base64.decode(str);\n"
},
{
"answer_id": 20090752,
"author": "Johan",
"author_id": 598511,
"author_profile": "https://Stackoverflow.com/users/598511",
"pm_score": 3,
"selected": false,
"text": "window.atob window.btoa (function(){function t(t){this.message=t}var e=\"undefined\"!=typeof exports?exports:this,r=\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\";t.prototype=Error(),t.prototype.name=\"InvalidCharacterError\",e.btoa||(e.btoa=function(e){for(var o,n,a=0,i=r,c=\"\";e.charAt(0|a)||(i=\"=\",a%1);c+=i.charAt(63&o>>8-8*(a%1))){if(n=e.charCodeAt(a+=.75),n>255)throw new t(\"'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.\");o=o<<8|n}return c}),e.atob||(e.atob=function(e){if(e=e.replace(/=+$/,\"\"),1==e.length%4)throw new t(\"'atob' failed: The string to be decoded is not correctly encoded.\");for(var o,n,a=0,i=0,c=\"\";n=e.charAt(i++);~n&&(o=a%4?64*o+n:n,a++%4)?c+=String.fromCharCode(255&o>>(6&-2*a)):0)n=r.indexOf(n);return c})})();\n (function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define([], function() {factory(root);});\n } else factory(root);\n// node.js has always supported base64 conversions, while browsers that support\n// web workers support base64 too, but you may never know.\n})(typeof exports !== \"undefined\" ? exports : this, function(root) {\n if (root.atob) {\n // Some browsers' implementation of atob doesn't support whitespaces\n // in the encoded string (notably, IE). This wraps the native atob\n // in a function that strips the whitespaces.\n // The original function can be retrieved in atob.original\n try {\n root.atob(\" \");\n } catch(e) {\n root.atob = (function(atob) {\n var func = function(string) {\n return atob(String(string).replace(/[\\t\\n\\f\\r ]+/g, \"\"));\n };\n func.original = atob;\n return func;\n })(root.atob);\n }\n return;\n }\n\n // base64 character set, plus padding character (=)\n var b64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\",\n // Regular expression to check formal correctness of base64 encoded strings\n b64re = /^(?:[A-Za-z\\d+\\/]{4})*?(?:[A-Za-z\\d+\\/]{2}(?:==)?|[A-Za-z\\d+\\/]{3}=?)?$/;\n\n root.btoa = function(string) {\n string = String(string);\n var bitmap, a, b, c,\n result = \"\", i = 0,\n rest = string.length % 3; // To determine the final padding\n\n for (; i < string.length;) {\n if ((a = string.charCodeAt(i++)) > 255\n || (b = string.charCodeAt(i++)) > 255\n || (c = string.charCodeAt(i++)) > 255)\n throw new TypeError(\"Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.\");\n\n bitmap = (a << 16) | (b << 8) | c;\n result += b64.charAt(bitmap >> 18 & 63) + b64.charAt(bitmap >> 12 & 63)\n + b64.charAt(bitmap >> 6 & 63) + b64.charAt(bitmap & 63);\n }\n\n // If there's need of padding, replace the last 'A's with equal signs\n return rest ? result.slice(0, rest - 3) + \"===\".substring(rest) : result;\n };\n\n root.atob = function(string) {\n // atob can work with strings with whitespaces, even inside the encoded part,\n // but only \\t, \\n, \\f, \\r and ' ', which can be stripped.\n string = String(string).replace(/[\\t\\n\\f\\r ]+/g, \"\");\n if (!b64re.test(string))\n throw new TypeError(\"Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.\");\n\n // Adding the padding if missing, for semplicity\n string += \"==\".slice(2 - (string.length & 3));\n var bitmap, result = \"\", r1, r2, i = 0;\n for (; i < string.length;) {\n bitmap = b64.indexOf(string.charAt(i++)) << 18 | b64.indexOf(string.charAt(i++)) << 12\n | (r1 = b64.indexOf(string.charAt(i++))) << 6 | (r2 = b64.indexOf(string.charAt(i++)));\n\n result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255)\n : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255)\n : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255);\n }\n return result;\n };\n});\n"
},
{
"answer_id": 23852010,
"author": "A T",
"author_id": 587021,
"author_profile": "https://Stackoverflow.com/users/587021",
"pm_score": 3,
"selected": false,
"text": "'use strict';\n\nvar ProjectNameBase64Factory = angular.module('project_name.factories.base64', []);\n\nProjectNameBase64Factory.factory('Base64', function () {\n var Base64 = {\n // private property\n _keyStr: \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\",\n\n // public method for encoding\n encode: function (input) {\n var output = \"\";\n var chr1, chr2, chr3, enc1, enc2, enc3, enc4;\n var i = 0;\n\n input = Base64._utf8_encode(input);\n\n while (i < input.length) {\n\n chr1 = input.charCodeAt(i++);\n chr2 = input.charCodeAt(i++);\n chr3 = input.charCodeAt(i++);\n\n enc1 = chr1 >> 2;\n enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n enc4 = chr3 & 63;\n\n if (isNaN(chr2)) {\n enc3 = enc4 = 64;\n } else if (isNaN(chr3)) {\n enc4 = 64;\n }\n\n output = output +\n Base64._keyStr.charAt(enc1) + Base64._keyStr.charAt(enc2) +\n Base64._keyStr.charAt(enc3) + Base64._keyStr.charAt(enc4);\n\n }\n\n return output;\n },\n\n // public method for decoding\n decode: function (input) {\n var output = \"\";\n var chr1, chr2, chr3;\n var enc1, enc2, enc3, enc4;\n var i = 0;\n\n input = input.replace(/[^A-Za-z0-9\\+\\/\\=]/g, \"\");\n\n while (i < input.length) {\n\n enc1 = Base64._keyStr.indexOf(input.charAt(i++));\n enc2 = Base64._keyStr.indexOf(input.charAt(i++));\n enc3 = Base64._keyStr.indexOf(input.charAt(i++));\n enc4 = Base64._keyStr.indexOf(input.charAt(i++));\n\n chr1 = (enc1 << 2) | (enc2 >> 4);\n chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);\n chr3 = ((enc3 & 3) << 6) | enc4;\n\n output = output + String.fromCharCode(chr1);\n\n if (enc3 != 64) {\n output = output + String.fromCharCode(chr2);\n }\n if (enc4 != 64) {\n output = output + String.fromCharCode(chr3);\n }\n\n }\n\n output = Base64._utf8_decode(output);\n\n return output;\n\n },\n\n // private method for UTF-8 encoding\n _utf8_encode: function (string) {\n string = string.replace(/\\r\\n/g, \"\\n\");\n var utftext = \"\";\n\n for (var n = 0; n < string.length; n++) {\n\n var c = string.charCodeAt(n);\n\n if (c < 128) {\n utftext += String.fromCharCode(c);\n }\n else if ((c > 127) && (c < 2048)) {\n utftext += String.fromCharCode((c >> 6) | 192);\n utftext += String.fromCharCode((c & 63) | 128);\n }\n else {\n utftext += String.fromCharCode((c >> 12) | 224);\n utftext += String.fromCharCode(((c >> 6) & 63) | 128);\n utftext += String.fromCharCode((c & 63) | 128);\n }\n\n }\n\n return utftext;\n },\n\n // private method for UTF-8 decoding\n _utf8_decode: function (utftext) {\n var string = \"\";\n var i = 0;\n var c = 0, c2 = 0, c3 = 0;\n\n while (i < utftext.length) {\n\n c = utftext.charCodeAt(i);\n\n if (c < 128) {\n string += String.fromCharCode(c);\n i++;\n }\n else if ((c > 191) && (c < 224)) {\n c2 = utftext.charCodeAt(i + 1);\n string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));\n i += 2;\n }\n else {\n c2 = utftext.charCodeAt(i + 1);\n c3 = utftext.charCodeAt(i + 2);\n string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));\n i += 3;\n }\n\n }\n return string;\n }\n };\n return Base64;\n});\n"
},
{
"answer_id": 26195897,
"author": "Ricardo Machado",
"author_id": 524038,
"author_profile": "https://Stackoverflow.com/users/524038",
"pm_score": 3,
"selected": false,
"text": "function strToUTF8Base64(str) {\n\n function decodeSurrogatePair(hi, lo) {\n var resultChar = 0x010000;\n resultChar += lo - 0xDC00;\n resultChar += (hi - 0xD800) << 10;\n return resultChar;\n }\n\n var bytes = [0, 0, 0];\n var byteIndex = 0;\n var result = [];\n\n function output(s) {\n result.push(s);\n }\n\n function emitBase64() {\n\n var digits =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +\n 'abcdefghijklmnopqrstuvwxyz' +\n '0123456789+/';\n\n function toDigit(value) {\n return digits[value];\n }\n\n // --Byte 0-- --Byte 1-- --Byte 2--\n // 1111 1122 2222 3333 3344 4444\n\n var d1 = toDigit(bytes[0] >> 2);\n var d2 = toDigit(\n ((bytes[0] & 0x03) << 4) |\n (bytes[1] >> 4));\n var d3 = toDigit(\n ((bytes[1] & 0x0F) << 2) |\n (bytes[2] >> 6));\n var d4 = toDigit(\n bytes[2] & 0x3F);\n\n if (byteIndex === 1) {\n output(d1 + d2 + '==');\n }\n else if (byteIndex === 2) {\n output(d1 + d2 + d3 + '=');\n }\n else {\n output(d1 + d2 + d3 + d4);\n }\n }\n\n function emit(chr) {\n bytes[byteIndex++] = chr;\n if (byteIndex == 3) {\n emitBase64();\n bytes[0] = 0;\n bytes[1] = 0;\n bytes[2] = 0;\n byteIndex = 0;\n }\n }\n\n function emitLast() {\n if (byteIndex > 0) {\n emitBase64();\n }\n }\n\n // Converts the string to UTF8:\n\n var i, chr;\n var hi, lo;\n for (i = 0; i < str.length; i++) {\n chr = str.charCodeAt(i);\n\n // Test and decode surrogate pairs in the string\n if (chr >= 0xD800 && chr <= 0xDBFF) {\n hi = chr;\n lo = str.charCodeAt(i + 1);\n if (lo >= 0xDC00 && lo <= 0xDFFF) {\n chr = decodeSurrogatePair(hi, lo);\n i++;\n }\n }\n\n // Encode the character as UTF-8.\n if (chr < 0x80) {\n emit(chr);\n }\n else if (chr < 0x0800) {\n emit((chr >> 6) | 0xC0);\n emit(((chr >> 0) & 0x3F) | 0x80);\n }\n else if (chr < 0x10000) {\n emit((chr >> 12) | 0xE0);\n emit(((chr >> 6) & 0x3F) | 0x80);\n emit(((chr >> 0) & 0x3F) | 0x80);\n }\n else if (chr < 0x110000) {\n emit((chr >> 18) | 0xF0);\n emit(((chr >> 12) & 0x3F) | 0x80);\n emit(((chr >> 6) & 0x3F) | 0x80);\n emit(((chr >> 0) & 0x3F) | 0x80);\n }\n }\n\n emitLast();\n\n return result.join('');\n}\n strToUTF8Base64('衠衢蠩蠨')"
},
{
"answer_id": 26514148,
"author": "davidcondrey",
"author_id": 1922144,
"author_profile": "https://Stackoverflow.com/users/1922144",
"pm_score": 8,
"selected": false,
"text": "// Define the string\nvar string = 'Hello World!';\n\n// Encode the String\nvar encodedString = btoa(string);\nconsole.log(encodedString); // Outputs: \"SGVsbG8gV29ybGQh\"\n\n// Decode the String\nvar decodedString = atob(encodedString);\nconsole.log(decodedString); // Outputs: \"Hello World!\"\n // Create Base64 Object\nvar Base64={_keyStr:\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\",encode:function(e){var t=\"\";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t=\"\";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\\+\\/\\=]/g,\"\");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\\r\\n/g,\"\\n\");var t=\"\";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t=\"\";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}}\n\n// Define the string\nvar string = 'Hello World!';\n\n// Encode the String\nvar encodedString = Base64.encode(string);\nconsole.log(encodedString); // Outputs: \"SGVsbG8gV29ybGQh\"\n\n// Decode the String\nvar decodedString = Base64.decode(encodedString);\nconsole.log(decodedString); // Outputs: \"Hello World!\"\n //Buffer() requires a number, array or string as the first parameter, and an optional encoding type as the second parameter.\n// The default is \"utf8\". Possible encoding types are \"ascii\", \"utf8\", \"ucs2\", \"base64\", \"binary\", and \"hex\"\nvar b = Buffer.from('JavaScript');\n// If we don't use toString(), JavaScript assumes we want to convert the object to utf8.\n// We can make it convert to other formats by passing the encoding type to toString().\nvar s = b.toString('base64');\n var b = new Buffer('SmF2YVNjcmlwdA==', 'base64')\nvar s = b.toString();\n var str = dojox.encoding.base64.encode(myByteArray);\n var bytes = dojox.encoding.base64.decode(str)\n <script src=\"bower_components/angular-base64/angular-base64.js\"></script>\n\nangular\n .module('myApp', ['base64'])\n .controller('myController', [\n\n '$base64', '$scope',\n function($base64, $scope) {\n\n $scope.encoded = $base64.encode('a string');\n $scope.decoded = $base64.decode('YSBzdHJpbmc=');\n}]);\n"
},
{
"answer_id": 38493287,
"author": "Malvineous",
"author_id": 308237,
"author_profile": "https://Stackoverflow.com/users/308237",
"pm_score": 3,
"selected": false,
"text": "Blob data:// + data://"
},
{
"answer_id": 40392850,
"author": "John",
"author_id": 1190665,
"author_profile": "https://Stackoverflow.com/users/1190665",
"pm_score": 5,
"selected": false,
"text": "function b64EncodeUnicode(str) {\n return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {\n return String.fromCharCode('0x' + p1);\n }));\n}\n\nb64EncodeUnicode('✓ à la mode'); // \"4pyTIMOgIGxhIG1vZGU=\"\nb64EncodeUnicode('\\n'); // \"Cg==\"\n\n\nfunction b64DecodeUnicode(str) {\n return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {\n return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\n }).join(''));\n}\n\nb64DecodeUnicode('4pyTIMOgIGxhIG1vZGU='); // \"✓ à la mode\"\nb64DecodeUnicode('Cg=='); // \"\\n\"\n"
},
{
"answer_id": 45844934,
"author": "crashwap",
"author_id": 1873386,
"author_profile": "https://Stackoverflow.com/users/1873386",
"pm_score": 6,
"selected": false,
"text": "str = \"The quick brown fox jumps over the lazy dog\";\nb64 = btoa(unescape(encodeURIComponent(str)));\nstr = decodeURIComponent(escape(window.atob(b64)));\n const input = document.getElementsByTagName('input')[0];\nconst btnConv = document.getElementById('btnConv');\nconst btnDeConv = document.getElementById('btnDeConv');\n\ninput.value = \"The quick brown fox jumps over the lazy dog\";\n\nbtnConv.addEventListener('click', () => {\n const txt = input.value;\n const b64 = btoa(unescape(encodeURIComponent(txt)));\n input.value = b64;\n btnDeConv.style.display = 'block';\n btnConv.style.display = 'none';\n});\n\nbtnDeConv.addEventListener('click', () => {\n var b64 = input.value;\n var txt = decodeURIComponent(escape(window.atob(b64)));\n input.value = txt;\n btnConv.style.display = 'block';\n btnDeConv.style.display = 'none';\n}); input{width:500px;}\n#btnDeConv{display:none;} <div><input type=\"text\" /></div>\n<button id=\"btnConv\">Convert</button>\n<button id=\"btnDeConv\">DeConvert</button> str = \"The quick brown fox jumps over the lazy dog\";\n\n$('input').val(str);\n\n$('#btnConv').click(function(){\n var txt = $('input').val();\n var b64 = btoa(unescape(encodeURIComponent(txt)));\n $('input').val(b64);\n $('#btnDeConv').show();\n});\n$('#btnDeConv').click(function(){\n var b64 = $('input').val();\n var txt = decodeURIComponent(escape(window.atob(b64)));\n $('input').val(txt);\n}); #btnDeConv{display:none;} <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\n\n<input type=\"text\" />\n<button id=\"btnConv\">Convert</button>\n<button id=\"btnDeConv\">DeConvert</button>"
},
{
"answer_id": 52815649,
"author": "Alireza",
"author_id": 5423108,
"author_profile": "https://Stackoverflow.com/users/5423108",
"pm_score": 3,
"selected": false,
"text": "window.btoa window.atob const encoded = window.btoa('Alireza Dezfoolian'); // encode a string\nconst decoded = window.atob(encoded); // decode the string\n // UCS-2 string to Base64 encoded ASCII\nfunction utoa(str) {\n return window.btoa(unescape(encodeURIComponent(str)));\n}\n// Base64 encoded ASCII to UCS-2 string\nfunction atou(str) {\n return decodeURIComponent(escape(window.atob(str)));\n}\n// Usage:\nutoa('✓ à la mode'); // 4pyTIMOgIGxhIG1vZGU=\natou('4pyTIMOgIGxhIG1vZGU='); // \"✓ à la mode\"\n\nutoa('I \\u2661 Unicode!'); // SSDimaEgVW5pY29kZSE=\natou('SSDimaEgVW5pY29kZSE='); // \"I ♡ Unicode!\"\n"
},
{
"answer_id": 53221307,
"author": "Rix",
"author_id": 1481095,
"author_profile": "https://Stackoverflow.com/users/1481095",
"pm_score": 4,
"selected": false,
"text": "const base64 = {\n decode: s => Uint8Array.from(atob(s), c => c.charCodeAt(0)),\n encode: b => btoa(String.fromCharCode(...new Uint8Array(b)))\n};\n const base64 = {\n decode: s => Buffer.from(s, 'base64'),\n encode: b => Buffer.from(b).toString('base64')\n};\n"
},
{
"answer_id": 54605284,
"author": "Jonathan Applebaum",
"author_id": 5718868,
"author_profile": "https://Stackoverflow.com/users/5718868",
"pm_score": 3,
"selected": false,
"text": "atob() btoa() <!DOCTYPE html>\n<html>\n <head>\n <style>\n textarea{\n width:30%;\n height:100px;\n }\n </style>\n <script>\n // encode string to base64\n function encode()\n {\n var txt = document.getElementById(\"txt1\").value;\n var result = btoa(txt);\n document.getElementById(\"txt2\").value = result;\n }\n // decode base64 back to original string\n function decode()\n {\n var txt = document.getElementById(\"txt3\").value;\n var result = atob(txt);\n document.getElementById(\"txt4\").value = result;\n }\n </script>\n </head>\n <body>\n <div>\n <textarea id=\"txt1\">Some text to decode\n </textarea>\n </div>\n <div>\n <input type=\"button\" id=\"btnencode\" value=\"Encode\" onClick=\"encode()\"/>\n </div>\n <div>\n <textarea id=\"txt2\">\n </textarea>\n </div>\n <br/>\n <div>\n <textarea id=\"txt3\">U29tZSB0ZXh0IHRvIGRlY29kZQ==\n </textarea>\n </div>\n <div>\n <input type=\"button\" id=\"btndecode\" value=\"Decode\" onClick=\"decode()\"/>\n </div>\n <div>\n <textarea id=\"txt4\">\n </textarea>\n </div>\n </body>\n</html>\n"
},
{
"answer_id": 60734017,
"author": "Shivaji Mutkule",
"author_id": 4365927,
"author_profile": "https://Stackoverflow.com/users/4365927",
"pm_score": 3,
"selected": false,
"text": "var str = \"I was funny \";\nconsole.log(\"Original string:\", str);\n\nvar encodedStr = Base64.encode(str)\nconsole.log(\"Encoded string:\", encodedStr);\n\nvar decodedStr = Base64.decode(encodedStr)\nconsole.log(\"Decoded string:\", decodedStr); <script src=\"https://cdn.jsdelivr.net/npm/js-base64@2.5.2/base64.min.js\"></script>"
},
{
"answer_id": 63114624,
"author": "Kamil Kiełczewski",
"author_id": 860099,
"author_profile": "https://Stackoverflow.com/users/860099",
"pm_score": 2,
"selected": false,
"text": "btoa function bytesArrToBase64(arr) {\n const abc = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\"; // base64 alphabet\n const bin = n => n.toString(2).padStart(8,0); // convert num to 8-bit binary string\n const l = arr.length\n let result = '';\n\n for(let i=0; i<=(l-1)/3; i++) {\n let c1 = i*3+1>=l; // case when \"=\" is on end\n let c2 = i*3+2>=l; // case when \"=\" is on end\n let chunk = bin(arr[3*i]) + bin(c1? 0:arr[3*i+1]) + bin(c2? 0:arr[3*i+2]);\n let r = chunk.match(/.{1,6}/g).map((x,j)=> j==3&&c2 ? '=' :(j==2&&c1 ? '=':abc[+('0b'+x)]));\n result += r.join('');\n }\n\n return result;\n}\n\n\n\n// TEST\n\nconst pic = [ // PNG binary data\n 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,\n 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,\n 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff, 0x61, 0x00, 0x00, 0x00,\n 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,\n 0x01, 0x59, 0x69, 0x54, 0x58, 0x74, 0x58, 0x4d, 0x4c, 0x3a, 0x63, 0x6f,\n 0x6d, 0x2e, 0x61, 0x64, 0x6f, 0x62, 0x65, 0x2e, 0x78, 0x6d, 0x70, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x3c, 0x78, 0x3a, 0x78, 0x6d, 0x70, 0x6d, 0x65,\n 0x74, 0x61, 0x20, 0x78, 0x6d, 0x6c, 0x6e, 0x73, 0x3a, 0x78, 0x3d, 0x22,\n 0x61, 0x64, 0x6f, 0x62, 0x65, 0x3a, 0x6e, 0x73, 0x3a, 0x6d, 0x65, 0x74,\n 0x61, 0x2f, 0x22, 0x20, 0x78, 0x3a, 0x78, 0x6d, 0x70, 0x74, 0x6b, 0x3d,\n 0x22, 0x58, 0x4d, 0x50, 0x20, 0x43, 0x6f, 0x72, 0x65, 0x20, 0x35, 0x2e,\n 0x34, 0x2e, 0x30, 0x22, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x3c, 0x72, 0x64,\n 0x66, 0x3a, 0x52, 0x44, 0x46, 0x20, 0x78, 0x6d, 0x6c, 0x6e, 0x73, 0x3a,\n 0x72, 0x64, 0x66, 0x3d, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f,\n 0x77, 0x77, 0x77, 0x2e, 0x77, 0x33, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x31,\n 0x39, 0x39, 0x39, 0x2f, 0x30, 0x32, 0x2f, 0x32, 0x32, 0x2d, 0x72, 0x64,\n 0x66, 0x2d, 0x73, 0x79, 0x6e, 0x74, 0x61, 0x78, 0x2d, 0x6e, 0x73, 0x23,\n 0x22, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x72, 0x64,\n 0x66, 0x3a, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f,\n 0x6e, 0x20, 0x72, 0x64, 0x66, 0x3a, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x3d,\n 0x22, 0x22, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,\n 0x20, 0x20, 0x20, 0x78, 0x6d, 0x6c, 0x6e, 0x73, 0x3a, 0x74, 0x69, 0x66,\n 0x66, 0x3d, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6e, 0x73,\n 0x2e, 0x61, 0x64, 0x6f, 0x62, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74,\n 0x69, 0x66, 0x66, 0x2f, 0x31, 0x2e, 0x30, 0x2f, 0x22, 0x3e, 0x0a, 0x20,\n 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x66,\n 0x66, 0x3a, 0x4f, 0x72, 0x69, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f,\n 0x6e, 0x3e, 0x31, 0x3c, 0x2f, 0x74, 0x69, 0x66, 0x66, 0x3a, 0x4f, 0x72,\n 0x69, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3e, 0x0a, 0x20,\n 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x72, 0x64, 0x66, 0x3a, 0x44,\n 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x3e, 0x0a,\n 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x72, 0x64, 0x66, 0x3a, 0x52, 0x44, 0x46,\n 0x3e, 0x0a, 0x3c, 0x2f, 0x78, 0x3a, 0x78, 0x6d, 0x70, 0x6d, 0x65, 0x74,\n 0x61, 0x3e, 0x0a, 0x4c, 0xc2, 0x27, 0x59, 0x00, 0x00, 0x00, 0xf9, 0x49,\n 0x44, 0x41, 0x54, 0x38, 0x11, 0x95, 0x93, 0x3d, 0x0a, 0x02, 0x41, 0x0c,\n 0x85, 0xb3, 0xb2, 0x85, 0xb7, 0x10, 0x6c, 0x04, 0x1b, 0x0b, 0x4b, 0x6f,\n 0xe2, 0x76, 0x1e, 0xc1, 0xc2, 0x56, 0x6c, 0x2d, 0xbc, 0x85, 0xde, 0xc4,\n 0xd2, 0x56, 0xb0, 0x11, 0xbc, 0x85, 0x85, 0xa0, 0xfb, 0x46, 0xbf, 0xd9,\n 0x30, 0x33, 0x88, 0x06, 0x76, 0x93, 0x79, 0x93, 0xf7, 0x92, 0xf9, 0xab,\n 0xcc, 0xec, 0xd9, 0x7e, 0x7f, 0xd9, 0x63, 0x33, 0x8e, 0xf9, 0x75, 0x8c,\n 0x92, 0xe0, 0x34, 0xe8, 0x27, 0x88, 0xd9, 0xf4, 0x76, 0xcf, 0xb0, 0xaa,\n 0x45, 0xb2, 0x0e, 0x4a, 0xe4, 0x94, 0x39, 0x59, 0x0c, 0x03, 0x54, 0x14,\n 0x58, 0xce, 0xbb, 0xea, 0xdb, 0xd1, 0x3b, 0x71, 0x75, 0xb9, 0x9a, 0xe2,\n 0x7a, 0x7d, 0x36, 0x3f, 0xdf, 0x4b, 0x95, 0x35, 0x09, 0x09, 0xef, 0x73,\n 0xfc, 0xfa, 0x85, 0x67, 0x02, 0x3e, 0x59, 0x55, 0x31, 0x89, 0x31, 0x56,\n 0x8c, 0x78, 0xb6, 0x04, 0xda, 0x23, 0x01, 0x01, 0xc8, 0x8c, 0xe5, 0x77,\n 0x87, 0xbb, 0x65, 0x02, 0x24, 0xa4, 0xad, 0x82, 0xcb, 0x4b, 0x4c, 0x64,\n 0x59, 0x14, 0xa0, 0x72, 0x40, 0x3f, 0xbf, 0xe6, 0x68, 0xb6, 0x9f, 0x75,\n 0x08, 0x63, 0xc8, 0x9a, 0x09, 0x02, 0x25, 0x32, 0x34, 0x48, 0x7e, 0xcc,\n 0x7d, 0x10, 0xaf, 0xa6, 0xd5, 0xd2, 0x1a, 0x3d, 0x89, 0x38, 0xf5, 0xf1,\n 0x14, 0xb4, 0x69, 0x6a, 0x4d, 0x15, 0xf5, 0xc9, 0xf0, 0x5c, 0x1a, 0x61,\n 0x8a, 0x75, 0xd1, 0xe8, 0x3a, 0x2c, 0x41, 0x5d, 0x70, 0x41, 0x20, 0x29,\n 0xf9, 0x9b, 0xb1, 0x37, 0xc5, 0x4d, 0xfc, 0x45, 0x84, 0x7d, 0x08, 0x8f,\n 0x89, 0x76, 0x54, 0xf1, 0x1b, 0x19, 0x92, 0xef, 0x2c, 0xbe, 0x46, 0x8e,\n 0xa6, 0x49, 0x5e, 0x61, 0x89, 0xe4, 0x05, 0x5e, 0x4e, 0xa4, 0x5c, 0x10,\n 0x6e, 0x9f, 0xfc, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44,\n 0xae, 0x42, 0x60, 0x82\n];\n\nlet b64pic = bytesArrToBase64(pic);\nmyPic.src = \"data:image/png;base64,\"+b64pic;\nmsg.innerHTML = \"Base64 encoded pic data:<br>\" + b64pic; img { zoom: 10; image-rendering: pixelated; }\n#msg { word-break: break-all; } <img id=\"myPic\">\n<code id=\"msg\"></code>"
},
{
"answer_id": 66518127,
"author": "qux",
"author_id": 7164926,
"author_profile": "https://Stackoverflow.com/users/7164926",
"pm_score": 4,
"selected": false,
"text": "let a = Buffer.from('JavaScript').toString('base64');\nconsole.log(a);\n\nlet b = Buffer.from(a, 'base64').toString();\nconsole.log(b);\n"
},
{
"answer_id": 67415709,
"author": "Carson",
"author_id": 9935654,
"author_profile": "https://Stackoverflow.com/users/9935654",
"pm_score": 2,
"selected": false,
"text": "btoa(\"☸☹☺☻☼☾☿\"))\n function toBinary(string) {\n const codeUnits = new Uint16Array(string.length);\n for (let i = 0; i < codeUnits.length; i++) {\n codeUnits[i] = string.charCodeAt(i);\n }\n return String.fromCharCode(...new Uint8Array(codeUnits.buffer));\n}\n\nfunction fromBinary(binary) {\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return String.fromCharCode(...new Uint16Array(bytes.buffer));\n}\n\nconst myString = \"☸☹☺☻☼☾☿\"\n// console.log(btoa(myString)) // Error InvalidCharacterError: The string to be encoded contains characters outside of the Latin1 range.\nconst converted = toBinary(myString)\nconst encoded = btoa(converted)\nconsole.log(encoded)\n\nconst decoded = atob(encoded)\nconst original = fromBinary(decoded)\nconsole.log(original);"
},
{
"answer_id": 70893658,
"author": "Nasib",
"author_id": 10403133,
"author_profile": "https://Stackoverflow.com/users/10403133",
"pm_score": 0,
"selected": false,
"text": "//decodes utf-16 characters such as ARABIC, URDU,PASHTO text\nfunction decodeBase64(s) {\n var percentEncodedStr = atob(s).split('').map(function (c) {\n return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\n }).join('');\n return decodeURIComponent(percentEncodedStr);\n}\n"
},
{
"answer_id": 71032651,
"author": "Oded BD",
"author_id": 1037613,
"author_profile": "https://Stackoverflow.com/users/1037613",
"pm_score": 3,
"selected": false,
"text": "This function is only provided for compatibility with legacy web platform APIs and should never be used in new code, \nbecause they use strings to represent binary data and predate the introduction of typed arrays in JavaScript. \nFor code running using Node.js APIs, \nconverting between base64-encoded strings and binary data should be performed using Buffer.from(str, 'base64') andbuf.toString('base64').\n window.btoa"
},
{
"answer_id": 71672936,
"author": "Brian M. Wachira",
"author_id": 8885582,
"author_profile": "https://Stackoverflow.com/users/8885582",
"pm_score": -1,
"selected": false,
"text": "const Base64 = {\n\n\n_keyStr: \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\",\n\n// added type string to input\nencode: function(input: string) {\n let output = \"\";\n let chr1, chr2, chr3, enc1, enc2, enc3, enc4;\n let i = 0;\n\n input = Base64._utf8_encode(input);\n\n while (i < input.length) {\n\n chr1 = input.charCodeAt(i++);\n chr2 = input.charCodeAt(i++);\n chr3 = input.charCodeAt(i++);\n\n enc1 = chr1 >> 2;\n enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);\n enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);\n enc4 = chr3 & 63;\n\n if (isNaN(chr2)) {\n enc3 = enc4 = 64;\n } else if (isNaN(chr3)) {\n enc4 = 64;\n }\n\n output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);\n\n }\n\n return output;\n},\n// added type string to input\n_utf8_encode: function(input: string) {\n input= input.replace(/\\r\\n/g, \"\\n\");\n let utftext = \"\";\n\n for (let n = 0; n < input.length; n++) {\n\n let c = input.charCodeAt(n);\n\n if (c < 128) {\n utftext += String.fromCharCode(c);\n }\n else if ((c > 127) && (c < 2048)) {\n utftext += String.fromCharCode((c >> 6) | 192);\n utftext += String.fromCharCode((c & 63) | 128);\n }\n else {\n utftext += String.fromCharCode((c >> 12) | 224);\n utftext += String.fromCharCode(((c >> 6) & 63) | 128);\n utftext += String.fromCharCode((c & 63) | 128);\n }\n\n }\n\n return utftext;\n },\n}\n \n// function that consumes that Base64.encode function\nconst encode = ( cipher : string) => {\n\n const encodedString: string = Base64.encode(cipher)\n\n return encodedString;\n}\n\nconsole.log(encode('Hello World!'))\n"
},
{
"answer_id": 72299162,
"author": "Jeroi",
"author_id": 6244317,
"author_profile": "https://Stackoverflow.com/users/6244317",
"pm_score": 1,
"selected": false,
"text": "base64url (s) {\n var to64url = btao(s);\n // Replace non-url compatible chars with base64url standard chars and remove leading =\n return to64url.replace(/\\+/g, '_').replace(/\\//g, '-').replace(/=+$/g, '');\n }\n"
},
{
"answer_id": 74199618,
"author": "Jaume Mussons Abad",
"author_id": 4664714,
"author_profile": "https://Stackoverflow.com/users/4664714",
"pm_score": -1,
"selected": false,
"text": "<script src=\"../yourpathtothelibrary/turbocommons-es5.js\"></script>\n\n<script>\n var ConversionUtils = org_turbocommons.ConversionUtils;\n\n ConversionUtils.stringToBase64('hello');\n</script>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246801",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4939/"
] |
246,806
|
<p>Is there any method?
My computer is AMD64.</p>
<pre><code>::std::string str;
BOOL loadU(const wchar_t* lpszPathName, int flag = 0);
</code></pre>
<p>When I used: </p>
<pre><code>loadU(&str);
</code></pre>
<p>the VS2005 compiler says:</p>
<pre><code>Error 7 error C2664:: cannot convert parameter 1 from 'std::string *__w64 ' to 'const wchar_t *'
</code></pre>
<p>How can I do it?</p>
|
[
{
"answer_id": 246811,
"author": "Matt Dillard",
"author_id": 863,
"author_profile": "https://Stackoverflow.com/users/863",
"pm_score": 7,
"selected": true,
"text": "c_str() wchar_t* std::wstring name( L\"Steve Nash\" );\nconst wchar_t* szName = name.c_str();\n MultiByteToWideChar LPWSTR wchar_t*"
},
{
"answer_id": 246818,
"author": "marijne",
"author_id": 7038,
"author_profile": "https://Stackoverflow.com/users/7038",
"pm_score": 7,
"selected": false,
"text": "std::wstring widestr = std::wstring(str.begin(), str.end());\n const wchar_t* widecstr = widestr.c_str();\n"
},
{
"answer_id": 246852,
"author": "Rob",
"author_id": 9236,
"author_profile": "https://Stackoverflow.com/users/9236",
"pm_score": 3,
"selected": false,
"text": "#include <atlconv.h>\n...\nstd::string str = \"Hello, world!\";\nCA2W pszWide(str.c_str());\nloadU(pszWide);\n CA2W pszWide(str.c_str(), CP_UTF8);\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25749/"
] |
246,814
|
<p>I have a function called FindSpecificRowValue that takes in a datatable and returns the row number that contains a particular value. If that value isn't found, I want to indicate so to the calling function.</p>
<p>Is the best approach to:</p>
<ol>
<li>Write a function that returns false if not found, true if found, and the found row number as a byref/output parameter, or</li>
<li>Write a function that returns an int and pass back -999 if the row value isn't found, the row number if it is?</li>
</ol>
|
[
{
"answer_id": 246872,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 5,
"selected": true,
"text": "TryFindSpecificRow\nFindSpecificRow\n public static Boolean TryFindSpecificRow(DataTable table, out Int32 rowNumber)\n{\n if (row-can-be-found)\n {\n rowNumber = index-of-row-that-was-found;\n return true;\n }\n else\n {\n rowNumber = 0; // this value will not be used anyway\n return false;\n }\n}\n\npublic static Int32 FindSpecificRow(DataTable table)\n{\n Int32 rowNumber;\n\n\n if (TryFindSpecificRow(table, out rowNumber))\n return rowNumber;\n else\n throw new RowNotFoundException(String.Format(\"Row {0} was not found\", rowNumber));\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/335036/"
] |
246,817
|
<p>I want to automate SVN adds using NAnt. I want to add to SVN all new files in a given directory. The NAnt script will successfully execute the add command, however it displays the Tortoise SVN add dialog and this is not acceptable because it will execute on a build server running CruiseControl. The build server is running Windows Server 2003. </p>
<p>Any ideas?</p>
<pre><code><target name="addtest">
<exec program="c:\program files\tortoisesvn\bin\tortoiseproc.exe"
commandline="/command:add * --force /path:C:\svn\test /notempfile /closeonend:1"
basedir="C:\svn\test"
failonerror="false"/>
</target>
</code></pre>
|
[
{
"answer_id": 246833,
"author": "Ben Scheirman",
"author_id": 3381,
"author_profile": "https://Stackoverflow.com/users/3381",
"pm_score": 1,
"selected": false,
"text": "c:\\>svn add ...\n"
},
{
"answer_id": 247688,
"author": "Scott Saad",
"author_id": 4916,
"author_profile": "https://Stackoverflow.com/users/4916",
"pm_score": 3,
"selected": false,
"text": "<svn command=\"add\" ... />\n <exec program=\"svn.exe\" commandline=\"add...\" />\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246817",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,822
|
<p>I'm writing a password encryption routine. I've written the below app to illustrate my problem. About 20% of the time, this code works as expected. The rest of the time, the decryption throws a cryptographic exception - "The data is invalid".</p>
<p>I believe the problem is in the encryption portion, because the decryption portion works the same every time. That is, if the encryption routine yields a value that the decryption routine can decrypt, it can always decrypt it. But if the encryption routine yields a value that chokes the decryption routine, it always chokes. So the decrypt routine is consistent; the encrypt routine is not.</p>
<p>I suspect my use of Unicode encoding is incorrect, but I've tried others with the same result.</p>
<p>What am I doing wrong?</p>
<pre><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace DataProtectionTest
{
public partial class Form1 : Form
{
private static readonly byte[] entropy = { 1, 2, 3, 4, 1, 2, 3, 4 };
private string password;
public Form1()
{
InitializeComponent();
}
private void btnEncryptIt_Click(object sender, EventArgs e)
{
Byte[] pw = Encoding.Unicode.GetBytes(textBox1.Text);
Byte[] encryptedPw = ProtectedData.Protect(pw, entropy, DataProtectionScope.LocalMachine);
password = Encoding.Unicode.GetString(encryptedPw);
}
private void btnDecryptIt_Click(object sender, EventArgs e)
{
Byte[] pwBytes = Encoding.Unicode.GetBytes(password);
try
{
Byte[] decryptedPw = ProtectedData.Unprotect(pwBytes, entropy, DataProtectionScope.LocalMachine);
string pw = Encoding.Unicode.GetString(decryptedPw);
textBox2.Text = pw;
}
catch (CryptographicException ce)
{
textBox2.Text = ce.Message;
}
}
}
}
</code></pre>
|
[
{
"answer_id": 247019,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 1,
"selected": false,
"text": "Encoding.GetEncoding(28591)\nEncoding.GetEncoding(\"Latin1\")\nEncoding.GetEncoding(\"iso-8859-1\")\n"
},
{
"answer_id": 247070,
"author": "Eric",
"author_id": 2610,
"author_profile": "https://Stackoverflow.com/users/2610",
"pm_score": 4,
"selected": true,
"text": "using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Data;\nusing System.Drawing;\nusing System.Text;\nusing System.Windows.Forms;\nusing System.Security.Cryptography;\n\nnamespace DataProtectionTest\n{\n public partial class Form1 : Form\n {\n private static readonly byte[] entropy = { 1, 2, 3, 4, 1, 2, 3, 4 };\n private string password;\n public Form1()\n {\n InitializeComponent();\n }\n\n private void btnEncryptIt_Click(object sender, EventArgs e)\n {\n Byte[] pw = Encoding.Unicode.GetBytes(textBox1.Text);\n Byte[] encryptedPw = ProtectedData.Protect(pw, entropy, DataProtectionScope.LocalMachine);\n //password = Encoding.Unicode.GetString(encryptedPw); \n password = Convert.ToBase64String(encryptedPw);\n }\n\n private void btnDecryptIt_Click(object sender, EventArgs e)\n {\n //Byte[] pwBytes = Encoding.Unicode.GetBytes(password);\n Byte[] pwBytes = Convert.FromBase64String(password);\n try\n {\n Byte[] decryptedPw = ProtectedData.Unprotect(pwBytes, entropy, DataProtectionScope.LocalMachine);\n string pw = Encoding.Unicode.GetString(decryptedPw);\n textBox2.Text = pw;\n }\n catch (CryptographicException ce)\n {\n textBox2.Text = ce.Message;\n }\n }\n }\n}\n"
},
{
"answer_id": 8682691,
"author": "Dave Black",
"author_id": 251267,
"author_profile": "https://Stackoverflow.com/users/251267",
"pm_score": 2,
"selected": false,
"text": "System.Text.Encoding System.Convert string byte[] Convert.ToBase64String(byte[] bytes)\n byte[] string Convert.FromBase64String(string data)\n"
},
{
"answer_id": 42580745,
"author": "Vladimir Arustamian",
"author_id": 3945778,
"author_profile": "https://Stackoverflow.com/users/3945778",
"pm_score": 1,
"selected": false,
"text": "public static class StringEncryptor\n{\n private static readonly byte[] key = { 0x45, 0x4E, 0x3A, 0x8C, 0x89, 0x70, 0x37, 0x99, 0x58, 0x31, 0x24, 0x98, 0x3A, 0x87, 0x9B, 0x34 };\n\n public static string EncryptString(this string sourceString)\n {\n if (string.IsNullOrEmpty(sourceString))\n {\n return string.Empty;\n }\n\n var base64String = Base64Encode(sourceString);\n var protectedBytes = ProtectedData.Protect(Convert.FromBase64String(base64String), key, DataProtectionScope.CurrentUser);\n return Convert.ToBase64String(protectedBytes);\n }\n\n public static string DecryptString(this string sourceString)\n {\n if (string.IsNullOrEmpty(sourceString))\n {\n return string.Empty;\n }\n\n var unprotectedBytes = ProtectedData.Unprotect(Convert.FromBase64String(sourceString), key, DataProtectionScope.CurrentUser);\n var base64String = Convert.ToBase64String(unprotectedBytes);\n return Base64Decode(base64String);\n }\n\n private static string Base64Encode(string plainText)\n {\n var plainTextBytes = Encoding.UTF8.GetBytes(plainText);\n return Convert.ToBase64String(plainTextBytes);\n }\n\n private static string Base64Decode(string base64EncodedData)\n {\n var base64EncodedBytes = Convert.FromBase64String(base64EncodedData);\n return Encoding.UTF8.GetString(base64EncodedBytes);\n }\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2610/"
] |
246,841
|
<p>We may tag a question with multiple tags in StackOverflow website, I'm wondering how to find out the most related questions with common tags.</p>
<p>Assume we have 100 questions in a database, each question has several tags. Let's say user is browsing a specific question, and we want to make the system to display the related questions on the page. The criteria for related question is they have most common tags.</p>
<p>For example:
Question 1 is tagged with AAA, BBB, CCC, DDD, EEE.</p>
<p>Question 2 is top 1 related because it also has all those 5 tags.
Question 3 is top 2 related because it has only 4 or 3 tags that Questio1 has.
......</p>
<p>So my question is how to design the database and find out the questions that's related to Question 1 quickly. Thank you very much.</p>
|
[
{
"answer_id": 246847,
"author": "Ross",
"author_id": 2025,
"author_profile": "https://Stackoverflow.com/users/2025",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM `questions` WHERE `tag` LIKE '%tagname%' OR (looped for each tag) LIMIT 5,0\n LIKE"
},
{
"answer_id": 247041,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 3,
"selected": false,
"text": "select qt.question_id, count(*)\nfrom question_tags qt\nwhere qt.tag in\n( select qt2.tag\n from question_tags qt2\n where qt2.question_id = 123\n)\ngroup by qt.question_id\norder by 2 desc\n"
},
{
"answer_id": 247236,
"author": "Tom H",
"author_id": 5696608,
"author_profile": "https://Stackoverflow.com/users/5696608",
"pm_score": 2,
"selected": false,
"text": "SELECT\n QT2.question_id,\n COUNT(*) AS cnt\nFROM\n Question_Tags QT1\nINNER JOIN Question_Tags QT2 ON QT2.tag = QT1.tag AND QT2.question_id <> QT1.question_id\nWHERE\n QT1.question_id = @question_id\nGROUP BY\n QT2.question_id\nORDER BY\n cnt DESC\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246841",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,849
|
<p>we're currently planning a larger WPF LoB application and i wonder what others think being the best practice for storing lots of UI settings e.g.</p>
<ul>
<li>Expander States</li>
<li>Menu orders</li>
<li>Sizing Properties</li>
<li>etc...</li>
</ul>
<p>i don't like the idea of having dozens of stored values using the delivered SettingsProvider (i.e. App.config file) although it can be used to store it in an embedded database using a custom SettingsProvider.
being able to use some kind of databinding is also a concern.
Has anyone had the same problems? </p>
<p>What did you do to store lots of ui user settings?</p>
|
[
{
"answer_id": 246880,
"author": "thismat",
"author_id": 14045,
"author_profile": "https://Stackoverflow.com/users/14045",
"pm_score": 4,
"selected": false,
"text": "Environment.SpecialFolder.ApplicationData\n"
},
{
"answer_id": 246889,
"author": "Patrick Desjardins",
"author_id": 13913,
"author_profile": "https://Stackoverflow.com/users/13913",
"pm_score": 2,
"selected": false,
"text": "Isolation Storage"
},
{
"answer_id": 247839,
"author": "decasteljau",
"author_id": 12082,
"author_profile": "https://Stackoverflow.com/users/12082",
"pm_score": 3,
"selected": false,
"text": "<Window ...\n xmlns:p=\"clr-namespace:UserSettings.Properties\"\n Height=\"{Binding Source={x:Static p:Settings.Default}, Path=Height, Mode=TwoWay}\" \n Width=\"{Binding Source={x:Static p:Settings.Default}, Path=Width, Mode=TwoWay}\" \n Left=\"{Binding Source={x:Static p:Settings.Default}, Path=Left, Mode=TwoWay}\" \n Top=\"{Binding Source={x:Static p:Settings.Default}, Path=Top, Mode=TwoWay}\">\n\n...\nprotected override void OnClosing(System.ComponentModel.CancelEventArgs e) \n{ \n Settings.Default.Save(); \n base.OnClosing(e); \n}\n"
},
{
"answer_id": 2227269,
"author": "sean e",
"author_id": 103912,
"author_profile": "https://Stackoverflow.com/users/103912",
"pm_score": 2,
"selected": false,
"text": "<Window ...\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n xmlns:p=\"clr-namespace:MyApp\"\n Height=\"{Binding Source={x:Static p:MyAppSettings.Default}, Path=MainWndHeight, Mode=TwoWay}\"\n Width=\"{Binding Source={x:Static p:MyAppSettings.Default}, Path=MainWndWidth, Mode=TwoWay}\"\n Left=\"{Binding Source={x:Static p:MyAppSettings.Default}, Path=MainWndLeft, Mode=TwoWay}\"\n Top=\"{Binding Source={x:Static p:MyAppSettings.Default}, Path=MainWndTop, Mode=TwoWay}\"\n ...\n namespace MyApp\n{\n class MainWindow ....\n {\n ...\n\n protected override void OnClosing(System.ComponentModel.CancelEventArgs e)\n {\n MyAppSettings.Default.Save();\n base.OnClosing(e);\n }\n }\n\n public sealed class MyAppSettings : System.Configuration.ApplicationSettingsBase\n {\n private static MyAppSettings defaultInstance = ((MyAppSettings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new MyAppSettings())));\n public static MyAppSettings Default\n {\n get { return defaultInstance; }\n }\n\n [System.Configuration.UserScopedSettingAttribute()]\n [System.Configuration.DefaultSettingValueAttribute(\"540\")]\n public int MainWndHeight\n {\n get { return (int)this[\"MainWndHeight\"]; }\n set { this[\"MainWndHeight\"] = value; }\n }\n\n [System.Configuration.UserScopedSettingAttribute()]\n [System.Configuration.DefaultSettingValueAttribute(\"790\")]\n public int MainWndWidth\n {\n get { return (int)this[\"MainWndWidth\"]; }\n set { this[\"MainWndWidth\"] = value; }\n }\n\n [System.Configuration.UserScopedSettingAttribute()]\n [System.Configuration.DefaultSettingValueAttribute(\"300\")]\n public int MainWndTop\n {\n get { return (int)this[\"MainWndTop\"]; }\n set { this[\"MainWndTop\"] = value; }\n }\n\n [System.Configuration.UserScopedSettingAttribute()]\n [System.Configuration.DefaultSettingValueAttribute(\"300\")]\n public int MainWndLeft\n {\n get { return (int)this[\"MainWndLeft\"]; }\n set { this[\"MainWndLeft\"] = value; }\n }\n }\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20227/"
] |
246,859
|
<p>Could somebody give me a brief overview of the differences between HTTP 1.0 and HTTP 1.1? I've spent some time with both of the RFCs, but haven't been able to pull out a lot of difference between them. Wikipedia says this:</p>
<blockquote>
<p><strong>HTTP/1.1 (1997-1999)</strong></p>
<p>Current version; persistent connections enabled by default and works well with proxies. Also supports request pipelining, allowing multiple requests to be sent at the same time, allowing the server to prepare for the workload and potentially transfer the requested resources more quickly to the client.</p>
</blockquote>
<p>But that doesn't mean a lot to me. I realize this is a somewhat complicated subject, so I'm not expecting a full answer, but can someone give me a brief overview of the differences at a bit lower level?<br />
By this I mean that I'm looking for the info I would need to know to implement either an HTTP server or application. I'm mostly looking for a nudge in the right direction so that I can figure it out on my own.</p>
|
[
{
"answer_id": 246897,
"author": "Leandro López",
"author_id": 22695,
"author_profile": "https://Stackoverflow.com/users/22695",
"pm_score": 3,
"selected": false,
"text": "GET POST"
},
{
"answer_id": 247026,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 10,
"selected": true,
"text": "GET / HTTP/1.1\nHost: www.blahblahblahblah.com\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246859",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] |
246,870
|
<p>Each of my clients can have many todo items and every todo item has a due date.</p>
<p>What would be the query for discovering the next undone todo item by due date for each file? In the event that a client has more than one todo, the one with the lowest id is the correct one.</p>
<p>Assuming the following minimal schema:</p>
<pre><code>clients (id, name)
todos (id, client_id, description, timestamp_due, timestamp_completed)
</code></pre>
<p>Thank you.</p>
|
[
{
"answer_id": 246918,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": -1,
"selected": false,
"text": "SELECT\n C.Id,\n C.Name,\n T.Id\n T.Description,\n T.timestamp_due\nFROM\n{\n SELECT\n client_id,\n MIN(timestamp_due) AS \"DueDate\"\n FROM todos\n WHERE timestamp_completed IS NULL\n GROUP BY ClientId\n} AS MinValues\n INNER JOIN Clients C\n ON (MinValues.client_id = C.Id)\n INNER JOIN todos T\n ON (MinValues.client_id = T.client_id\n AND MinValues.DueDate = T.timestamp_due)\nORDER BY C.Name\n"
},
{
"answer_id": 246927,
"author": "Aaron Maenpaa",
"author_id": 2603,
"author_profile": "https://Stackoverflow.com/users/2603",
"pm_score": 2,
"selected": false,
"text": "SELECT c.name, MIN(t.id)\nFROM clients c, todos t\nWHERE c.id = t.client_id AND t.timestamp_complete IS NULL\nGROUP BY c.id\nHAVING t.timestamp_due <= MIN(t.timestamp_due)\n"
},
{
"answer_id": 246934,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 2,
"selected": false,
"text": "SELECT *\nFROM todos t\nWHERE t.timestamp_completed is null\n and\n(\n SELECT top 1 t2.id\n FROM todos t2\n WHERE t.client_id = t2.client_id\n and t2.timestamp_completed is null\n --there is no earlier record\n and\n (t.timestamp_due > t2.timestamp_due\n or (t.timestamp_due = t2.timestamp_due and t.id > t2.id)\n )\n) is null\n"
},
{
"answer_id": 247008,
"author": "Fionnuala",
"author_id": 2548,
"author_profile": "https://Stackoverflow.com/users/2548",
"pm_score": 0,
"selected": false,
"text": "SELECT c.name, t.description, t.timestamp_due\nFROM (clients c \n INNER JOIN \n (SELECT t.client_id, Min(t.id) AS MinOfid\n FROM todos t\n WHERE t.timestamp_completed Is Null\n GROUP BY t.client_id) AS tm \nON c.id = tm.client_id) \nINNER JOIN todos t ON tm.MinOfid = t.id\n"
},
{
"answer_id": 247157,
"author": "Tom H",
"author_id": 5696608,
"author_profile": "https://Stackoverflow.com/users/5696608",
"pm_score": 3,
"selected": true,
"text": "SELECT\n TD1.client_id,\n TD1.id,\n TD1.description,\n TD1.timestamp_due\nFROM\n Todos TD1\nLEFT OUTER JOIN Todos TD2 ON\n TD2.client_id = TD1.client_id AND\n TD2.timestamp_completed IS NULL AND\n (\n TD2.timestamp_due < TD1.timestamp_due OR\n (TD2.timestamp_due = TD1.timestamp_due AND TD2.id < TD1.id)\n )\nWHERE\n TD2.id IS NULL\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246870",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2443/"
] |
246,876
|
<pre><code>$doba = explode("/", $dob);
$date = date("Y-m-d", mktime(0,0,0, $doba[0], $doba[1], $doba[2]));
</code></pre>
<p>The above code turns any date i pass through into 1999-11-30 and i know it was working yesterday. Date is correct when I echo $doba. Anyone have any ideas?</p>
<p>Cheers</p>
|
[
{
"answer_id": 246891,
"author": "Ross",
"author_id": 2025,
"author_profile": "https://Stackoverflow.com/users/2025",
"pm_score": 3,
"selected": true,
"text": "$doba mktime $doba = explode('/', '1991/08/03');\necho(date('Y-m-d', mktime(0,0,0, $doba[1], $doba[2], $doba[0]);\n\n$doba = explode('/', '03/08/1991');\necho(date('Y-m-d', mktime(0,0,0, $doba[1], $doba[0], $doba[2]);\n"
},
{
"answer_id": 246908,
"author": "Andrew Moore",
"author_id": 26210,
"author_profile": "https://Stackoverflow.com/users/26210",
"pm_score": 2,
"selected": false,
"text": "mktime $dob MM/DD/YYYY $dob $doba = explode(\"/\", $dob);\n$date = vsprintf('%3$04d-%1$02d-%2$02d', $doba);\n"
},
{
"answer_id": 247648,
"author": "jcoby",
"author_id": 2884,
"author_profile": "https://Stackoverflow.com/users/2884",
"pm_score": 2,
"selected": false,
"text": "$date = date('Y-m-d', strtotime($dob))"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31677/"
] |
246,877
|
<p>Any links to a good template for a windows service? (looking for C# code)</p>
<p>Something that has the basic functionality that I could extend.</p>
|
[
{
"answer_id": 249770,
"author": "KeesDijk",
"author_id": 6434,
"author_profile": "https://Stackoverflow.com/users/6434",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.ServiceProcess;\nusing System.Timers;\n\nnamespace WindowsService1\n{\n public partial class Service1 : ServiceBase\n {\n //better is to read from settings or config file\n private readonly Double _interval = (new TimeSpan(1, 0, 0, 0)).TotalMilliseconds;\n private Timer m_Timer;\n\n public Service1()\n {\n InitializeComponent();\n Init();\n }\n\n private void Init()\n {\n m_Timer = new Timer();\n m_Timer.BeginInit();\n m_Timer.AutoReset = false;\n m_Timer.Enabled = true;\n m_Timer.Interval = 1000.0;\n m_Timer.Elapsed += m_Timer_Elapsed;\n m_Timer.EndInit();\n }\n\n private void m_Timer_Elapsed(object sender, ElapsedEventArgs e)\n {\n //TODO WORK WORK WORK\n RestartTimer();\n }\n\n private void RestartTimer()\n {\n m_Timer.Interval = _interval;\n m_Timer.Start();\n }\n\n protected override void OnStart(string[] args)\n {\n base.OnStart(args);\n Start();\n }\n\n protected override void OnStop()\n {\n Stop();\n base.OnStop();\n }\n\n public void Start()\n {\n m_Timer.Start();\n }\n\n public new void Stop()\n {\n m_Timer.Stop();\n }\n }\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246877",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,884
|
<p>I haven´t experience in making setup, but I all ready make mine but now I need help because when I made a new version I want that the user double click the shortcut and it do the update if there are any.</p>
<p>The application is in <code>c#</code>.</p>
<p>Could you help?</p>
|
[
{
"answer_id": 246955,
"author": "Dan Walker",
"author_id": 752,
"author_profile": "https://Stackoverflow.com/users/752",
"pm_score": 1,
"selected": false,
"text": " WebClient wc = new WebClient();\n wc.DownloadFile(UrlOfIniContainingLatestVersion, PlacetoSaveIniFile);\n if (LatestVersion > CurrentVersion)\n {\n //Download update.\n }\n wc.DownloadFile(UrlOfLatestSetupFile, PlaceToSaveSetupFile);\n System.Diagnostics.Start(PathOfDownloadedSetupFile);\n using System;\nusing System.Runtime.InteropServices;\nusing System.Text;\n\nnamespace Ini\n{\n /// <summary>\n /// Create a New INI file to store or load data\n /// </summary>\n public class IniFile\n {\n public string path;\n\n [DllImport(\"kernel32\")]\n private static extern long WritePrivateProfileString(string section,\n string key, string val, string filePath);\n [DllImport(\"kernel32\")]\n private static extern int GetPrivateProfileString(string section,\n string key, string def, StringBuilder retVal,\n int size, string filePath);\n\n /// <summary>\n /// INIFile Constructor.\n /// </summary>\n /// <PARAM name=\"INIPath\"></PARAM>\n public IniFile(string INIPath)\n {\n path = INIPath;\n }\n\n /// <summary>\n /// Write Data to the INI File\n /// </summary>\n /// <PARAM name=\"Section\"></PARAM>\n /// Section name\n /// <PARAM name=\"Key\"></PARAM>\n /// Key Name\n /// <PARAM name=\"Value\"></PARAM>\n /// Value Name\n public void IniWriteValue(string Section, string Key, string Value)\n {\n WritePrivateProfileString(Section, Key, Value, this.path);\n }\n\n /// <summary>\n /// Read Data Value From the Ini File\n /// </summary>\n /// <PARAM name=\"Section\"></PARAM>\n /// <PARAM name=\"Key\"></PARAM>\n /// <PARAM name=\"Path\"></PARAM>\n /// <returns></returns>\n public string IniReadValue(string Section, string Key)\n {\n StringBuilder temp = new StringBuilder(255);\n int i = GetPrivateProfileString(Section, Key, \"\", temp,\n 255, this.path);\n return temp.ToString();\n\n }\n }\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32115/"
] |
246,890
|
<p>I recently converted a site from asp to CF. Unfortunately, alot of the old users had the "homepage" bookmarked. www.example.com/homepage.asp</p>
<p>Is there a sort of catch all way I could redirect any traffic from that page to the current index.cfm?</p>
<p>I would normally just delete those files, but the owner(s) wanted to keep it around for their own comparison reasons.</p>
<p>Any ideas?</p>
<p>Thanks</p>
|
[
{
"answer_id": 246929,
"author": "Patrick McElhaney",
"author_id": 437,
"author_profile": "https://Stackoverflow.com/users/437",
"pm_score": 4,
"selected": true,
"text": "<%@ Language=VBScript %>\n<%\nResponse.Status=\"301 Moved Permanently\"\nResponse.AddHeader \"Location\", \"/index.cfm\"\n%>\n"
},
{
"answer_id": 247173,
"author": "warren",
"author_id": 4418,
"author_profile": "https://Stackoverflow.com/users/4418",
"pm_score": 0,
"selected": false,
"text": "ln -s /path/to/source /path/to/target"
},
{
"answer_id": 248325,
"author": "Andy Waschick",
"author_id": 6000,
"author_profile": "https://Stackoverflow.com/users/6000",
"pm_score": 2,
"selected": false,
"text": "<!--- parse out the text in the URL parameters into an array --->\n<cfset variables.requestparams = listtoarray(cgi.query_string,'/?&')>\n\n<!--- get rid of the first 2 items in the array since they dont represent request info --->\n<cfset foo = arraydeleteat(variables.requestparams,1)>\n<cfset foo = arraydeleteat(variables.requestparams,1)>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26121/"
] |
246,893
|
<p>Is there a .net equivalent to the C++ unexpected()/set_unexpected() functionality?</p>
<hr>
<p><strong>Edit:</strong> Sorry--I omitted some details previously:</p>
<p>Language: C# 2.0</p>
<p>I have some legacy apps that seem to be throwing some unhandled exception somewhere. I just want to put something in place to stop the customer's pain until I can trace the actual source of the problem. In C++, the function pointed at by set_unexpected() gets called, as far as I know, when an otherwise unhandled exception bubbles to the main routine. Hence my question about a .net equivalent functionality. </p>
|
[
{
"answer_id": 11666389,
"author": "Dunc",
"author_id": 188926,
"author_profile": "https://Stackoverflow.com/users/188926",
"pm_score": 0,
"selected": false,
"text": "private delegate long UnhandledExceptionFilter(IntPtr exception);\n\n[DllImport(\"KERNEL32.DLL\", SetLastError = true)]\nprivate static extern IntPtr SetUnhandledExceptionFilter([MarshalAs(UnmanagedType.FunctionPtr)] UnhandledExceptionFilter filter);\n\n// put these in your bootstrapper\nAppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;\nApplication.ThreadException += ApplicationThreadException;\nSetUnhandledExceptionFilter(UnhandledExceptionFilter);\n\nvoid CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)\n{\n ...\n}\n\nvoid ApplicationThreadException(object sender, ThreadExceptionEventArgs e)\n{\n ...\n}\n\nlong UnhandledExceptionFilter(IntPtr exception)\n{\n ....\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2820/"
] |
246,905
|
<p>I just finished a 2d platformer in C++/Allegro. Its still in an incomplete stage...</p>
<p>I wonder how to go about a peer-review from people who are into game development.
I would like to review my project on grounds of </p>
<ol>
<li>game play</li>
<li>Collision detection</li>
<li>use of OOP</li>
<li>programming of sounds, effects etc</li>
<li>any further ideas</li>
<li>ways in which i could have done better</li>
<li>ways to optimize</li>
</ol>
<p>current code looks like a garbage at some places... so could you also suggest some simplification techniques?</p>
<p>you can view my project (if you wish) at updated link - <a href="http://ideamonk.blogspot.com/2008/09/nincompoop-all-ready-for-shaastra-2008.html" rel="nofollow noreferrer">nincompoop</a> <a href="http://ideamonk.googlepages.com/nincompoop_distro.rar" rel="nofollow noreferrer">(direct link)</a></p>
<p><a href="http://ideamonk.googlepages.com/nincompoop_distro.rar" rel="nofollow noreferrer">http://ideamonk.googlepages.com/nincompoop_distro.rar</a></p>
<p>As of now I am switching to C# and XNA, finding it very easy and fast to learn all because I'm impressed from - </p>
<p><a href="http://catalog.xna.com/GameDetails.aspx?releaseId=341" rel="nofollow noreferrer">http://catalog.xna.com/GameDetails.aspx?releaseId=341</a></p>
<blockquote>
<p>I do no intend to sell any product or popularise anything here... my intent is to get tips to be better from people who are better. As for the page where I have uploaded my project, its not supported by ads of any kind. so please feel safe.</p>
</blockquote>
|
[
{
"answer_id": 254242,
"author": "postfuturist",
"author_id": 1892,
"author_profile": "https://Stackoverflow.com/users/1892",
"pm_score": 3,
"selected": true,
"text": "int main () \n{\n game_object gob;\n gob.init_allegro();\n gob.load_assets();\n while(true) {\n gob.handle_inputs()\n if (!gob.update())\n break;\n gob.render();\n }\n gob.cleanup();\n}\n bool playerwins = check_win_condition();\n\nif(playerwins) {\n // win condition code\n} else {\n // lose condition code\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8786/"
] |
246,912
|
<p>Currently there are 2 pages in a jsp file: one of them displays the data and the second one is used for pagination. The task is to include exactly the same paginator table above the data table. Sorry, couldn't resist to draw it :)</p>
<pre><code>|-----------------------------------------|
| Page 2 of 200 < > |
|-----------------------------------------|
|-----------------------------------------|
| Some weird business data comes here |
|-----------------------------------------|
|-----------------------------------------|
| Page 2 of 200 < > |
|-----------------------------------------|
</code></pre>
<p>The question is: how do I do it w/o shameless copypasting?</p>
|
[
{
"answer_id": 246975,
"author": "pkaeding",
"author_id": 4257,
"author_profile": "https://Stackoverflow.com/users/4257",
"pm_score": 2,
"selected": false,
"text": "<jsp:include page=\"pagination.jsp\" flush=\"true\" />\n\n<table>...business data...</table>\n\n<jsp:include page=\"pagination.jsp\" flush=\"true\" />\n"
},
{
"answer_id": 247034,
"author": "Will Hartung",
"author_id": 13663,
"author_profile": "https://Stackoverflow.com/users/13663",
"pm_score": 3,
"selected": true,
"text": "<jsp:include \"page_naviagtor.jsp\"/>\n<table id=\"results\">...</table>\n<jsp:include \"page_navigator.jsp\"/>\n <tag:wrap_in_page_nav>\n <table id=\"results\"> ... </table>\n</tag:wrap_in_page_nav>\n <%@tag description=\"put the tag description here\" pageEncoding=\"UTF-8\"%>\n<%@ taglib prefix=\"t\" tagdir=\"/WEB-INF/yourtags\" %> \n<%@attribute name=\"startPage\" required=\"true\"%>\n<%@attribute name=\"endPage\" required=\"true\"%> \n<html>\n <head>\n <title>Page Title</title>\n </head>\n <body>\n <tag:page_nav startPage=\"${startPage}\" endPage=\"${endPage}\"/>\n <jsp:doBody/>\n <tag:page_nav startPage=\"${startPage}\" endPage=\"${endPage}\"/>\n </body>\n</html>\n <%@tag description=\"put the tag description here\" pageEncoding=\"UTF-8\"%>\n<%@ taglib prefix=\"t\" tagdir=\"/WEB-INF/yourtags\" %> \n<%@attribute name=\"startPage\" required=\"true\"%>\n<%@attribute name=\"endPage\" required=\"true\"%> \n<div>${startPage} .. ${endPage}</div>\n <%@page contentType=\"text/html\"%>\n<%@page pageEncoding=\"UTF-8\"%>\n<%@ taglib prefix=\"t\" tagdir=\"/WEB-INF/yourtags\" %>\n<tag:page startPage=\"1\" endPage=\"4\">\n <table> ... </table>\n</tag:page>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15187/"
] |
246,919
|
<p>What is the best way to implement the page view counter like the ones they have here on the site where each question has a "Views" counter?</p>
<p>Factoring in Performance and Scalability issues.</p>
|
[
{
"answer_id": 246980,
"author": "Bob Fanger",
"author_id": 19165,
"author_profile": "https://Stackoverflow.com/users/19165",
"pm_score": 4,
"selected": true,
"text": "UPDATE page_views SET counter = counter + 1 WHERE page_id = x\nif (affected_rows == 0 ) {\n INSERT INTO page_views (page_id, counter) VALUES (x, 1)\n}\n"
},
{
"answer_id": 247015,
"author": "Eduardo Molteni",
"author_id": 2385,
"author_profile": "https://Stackoverflow.com/users/2385",
"pm_score": 0,
"selected": false,
"text": "UPDATE Questions SET views = views + 1 WHERE QuestionID = x\n"
},
{
"answer_id": 247222,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 4,
"selected": false,
"text": "link <link href=\"/questions/246919/increment-view-count\" type=\"text/css\" rel=\"stylesheet\" />"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32372/"
] |
246,930
|
<p>I see these two acronyms being thrown around and I was wondering if there are any differences between a GUID and a UUID?</p>
|
[
{
"answer_id": 6953207,
"author": "Hoylen",
"author_id": 232064,
"author_profile": "https://Stackoverflow.com/users/232064",
"pm_score": 11,
"selected": true,
"text": "version variant Bits Bytes Name Endianness Endianness\n (GUID) RFC 4122\n\n32 4 Data1 Native Big\n16 2 Data2 Native Big\n16 2 Data3 Native Big\n64 8 Data4 Big Big\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246930",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/343/"
] |
246,931
|
<p>I have two models, Article and Post that both inherit from a base model called ContentBase.</p>
<p>You can leave comments on both Articles and Posts, so I am using a Polymorphic Association between Comments and Article or Post.</p>
<p>However, since both Article and Post inherit from ContentBase, the commentable_type field ends up being "ContentBase" for both and screws everything up.</p>
<p>Is there a way to specify the commentable_type field in the has_many relationship in Article and Post?</p>
<p>Edit:</p>
<p>By "screws everything up" I mean if there is an Article with ID=1 and Post with ID=1 and I add a Comment with commentable_id=1, commentable_type=ContentBase, that comment will show up for both the Article and Post.</p>
<p>Here's the code:</p>
<pre><code>class Article < BaseContent
has_many :comments, :as => :commentable
end
class Post < BaseContent
has_many :comments, :as => :commentable
end
</code></pre>
<p>and here's my Comment model:</p>
<pre><code>class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end
</code></pre>
|
[
{
"answer_id": 247617,
"author": "Mike Breen",
"author_id": 22346,
"author_profile": "https://Stackoverflow.com/users/22346",
"pm_score": 3,
"selected": true,
"text": "Module BaseContent\n def self.included(base)\n base.class_eval do\n validates_presence_of :somefield\n validates_length_of :someotherfield\n\n def my_method\n \"hello\"\n end\n end\n end\n\nend\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246931",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1396/"
] |
246,961
|
<p>I have many articles in a database (with title,text), I'm looking for an algorithm to find the X most similar articles, something like Stack Overflow's "Related Questions" when you ask a question. </p>
<p>I tried googling for this but only found pages about other "similar text" issues, something like comparing every article with all the others and storing a similarity somewhere. SO does this in "real time" on text that I just typed.</p>
<p>How?</p>
|
[
{
"answer_id": 42482364,
"author": "DroidOS",
"author_id": 1077485,
"author_profile": "https://Stackoverflow.com/users/1077485",
"pm_score": 1,
"selected": false,
"text": "[and,amd] [and,dan] function wordPairCount(word)\n{\n var i,rslt = [],len = word.length - 1;\n for(i=0;i < len;i++) rslt.push(word.substr(i,2));\n if (2 == len) rslt.push(word[0] + word[len]);\n return rslt;\n}\n\nfunction pairCount(arr)\n{\n var i,rslt = [];\n arr = arr.toLowerCase().split(' ');\n for(i=0;i < arr.length;i++) rslt = rslt.concat(wordPairCount(arr[i]));\n return rslt;\n}\n\nfunction commonCount(a,b)\n{\n var t;\n if (b.length > a.length) t = b, b = a, a = t; \n t = a.filter(function (e){return b.indexOf(e) > -1;});\n return t.length;\n}\n\nfunction myDice(a,b)\n{\n var bigrams = [],\n aPairs = pairCount(a),\n bPairs = pairCount(b);\n debugger;\n var isct = commonCount(aPairs,bPairs);\n return 2*commonCount(aPairs,bPairs)/(aPairs.length + bPairs.length); \n}\n\n$('#rslt1').text(myDice('WEB Applications','PHP Web Application'));\n$('#rslt2').text(myDice('And','Dan'));\n$('#rslt3').text(myDice('and','aMd'));\n$('#rslt4').text(myDice('abracadabra','abracabadra')); *{font-family:arial;}\ntable\n{\n width:80%;\n margin:auto;\n border:1px solid silver;\n}\n\nthead > tr > td\n{\n font-weight:bold;\n text-align:center;\n background-color:aqua;\n} <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js\"></script>\n<table>\n<thead>\n<tr>\n<td>Phrase 1</td>\n<td>Phrase 2</td>\n<td>Dice</td>\n</tr>\n<thead>\n<tbody>\n<tr>\n<td>WEB Applications</td>\n<td>PHP Web Application</td>\n<td id='rslt1'></td>\n</tr>\n<tr>\n<td>And</td>\n<td>Dan</td>\n<td id='rslt2'></td>\n</tr>\n<tr>\n<td>and</td>\n<td>aMd</td>\n<td id='rslt3'></td>\n</tr>\n<tr>\n<td>abracadabra</td>\n<td>abracabadra</td>\n<td id='rslt4'></td>\n</tr>\n</tbody>\n</table>"
},
{
"answer_id": 52152966,
"author": "Serge Rogatch",
"author_id": 1915854,
"author_profile": "https://Stackoverflow.com/users/1915854",
"pm_score": 1,
"selected": false,
"text": "class Statistics {\n std::unordered_map<std::string, int64_t> _counts;\n int64_t _totWords;\n\n void process(std::string& token);\npublic:\n explicit Statistics(const std::string& text);\n\n double Dist(const Statistics& fellow) const;\n\n bool IsEmpty() const { return _totWords == 0; }\n};\n\nnamespace {\n const std::string gPunctStr = \".,;:!?\";\n const std::unordered_set<char> gPunctSet(gPunctStr.begin(), gPunctStr.end());\n}\n\nStatistics::Statistics(const std::string& text) {\n std::string lastToken;\n for (size_t i = 0; i < text.size(); i++) {\n int ch = static_cast<uint8_t>(text[i]);\n if (!isspace(ch)) {\n lastToken.push_back(tolower(ch));\n continue;\n }\n process(lastToken);\n }\n process(lastToken);\n}\n\nvoid Statistics::process(std::string& token) {\n do {\n if (token.size() == 0) {\n break;\n }\n if (gPunctSet.find(token.back()) != gPunctSet.end()) {\n token.pop_back();\n }\n } while (false);\n if (token.size() != 0) {\n auto it = _counts.find(token);\n if (it == _counts.end()) {\n _counts.emplace(token, 1);\n }\n else {\n it->second++;\n }\n _totWords++;\n token.clear();\n }\n}\n\ndouble Statistics::Dist(const Statistics& fellow) const {\n double sum = 0;\n for (const auto& wordInfo : _counts) {\n const std::string wordText = wordInfo.first;\n const double freq = double(wordInfo.second) / _totWords;\n auto it = fellow._counts.find(wordText);\n double fellowFreq;\n if (it == fellow._counts.end()) {\n fellowFreq = 0;\n }\n else {\n fellowFreq = double(it->second) / fellow._totWords;\n }\n const double d = freq - fellowFreq;\n sum += d * d;\n }\n return std::sqrt(sum);\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246961",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25544/"
] |
246,963
|
<p>Say I have a class called PermissionManager which should only exist once for my system and basically fulfills the function of managing various permissions for various actions in my application. Now I have some class in my application which needs to be able to check a certain permission in one of its methods. This class's constructor is currently public, i.e. used by API users.</p>
<p>Until a couple of weeks ago, I would have simply had my class call the following pseudo-code somewhere:</p>
<pre><code> PermissionManager.getInstance().isReadPermissionEnabled(this)
</code></pre>
<p>But since I have noticed everyone here hating singletons + this kind of coupling, I was wondering what the better solution would be, since the arguments I have read against singletons seem to make sense (not testable, high coupling, etc.).</p>
<p>So should I actually require API users to pass in a PermissionManager instance in the constructor of the class? Even though I only want a single PermissionManager instance to exist for my application?</p>
<p>Or am I going about this all wrong and should have a non-public constructor and a factory somewhere which passes in the instance of PermissionManager for me?</p>
<hr>
<p><strong>Additional info</strong> Note that when I say "Dependency Injection", I'm talking about the DI <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="noreferrer">Pattern</a>...I am not using any DI framework like Guice or Spring. (...yet)</p>
|
[
{
"answer_id": 247056,
"author": "Eddie Deyo",
"author_id": 9323,
"author_profile": "https://Stackoverflow.com/users/9323",
"pm_score": 3,
"selected": true,
"text": "PermissionManager mManager = null;\npublic PermissionManager Permissions\n{\n if (mManager == null)\n {\n return mManager;\n }\n return PermissionManager.getInstance();\n}\n"
},
{
"answer_id": 247087,
"author": "Mike Furtak",
"author_id": 3005,
"author_profile": "https://Stackoverflow.com/users/3005",
"pm_score": 2,
"selected": false,
"text": "PermissionManager"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6583/"
] |
246,966
|
<p>I've found that given a form in a HTML page like this:</p>
<pre><code><form name="form">
<input type="image" name="foo"
src="somewhere.gif" alt="image" value="blah"/>
<input type="text" name="bar" value="blah"/>
</form>
</code></pre>
<p>When accessing the elements via the DOM in Javascript, there is <em>no</em> element for the image input! It is just omitted. So, <code>document.forms[0].elements.length</code> is 1, and <code>document.forms[0].element[0].type</code> is "text".</p>
<p>This seems to be the case in Firefox, and IE. I can't find this fact documented anywhere in my reference books or on the web. All I can find is a throwaway comment here:</p>
<p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=163822#c4" rel="nofollow noreferrer">https://bugzilla.mozilla.org/show_bug.cgi?id=163822#c4</a></p>
<p>Which suggests it "just is like this". If so, well so be it - but is it <em>really</em> not documented anywhere? Is it a historical mistake, or is there a reason for it?</p>
|
[
{
"answer_id": 247002,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 2,
"selected": false,
"text": "elements childNodes document.forms[0].childNodes.length; // equals 5 (2 inputs and 3 text nodes).\ndocument.forms[0].childNodes[1]; // This is your input with type='image'\n"
},
{
"answer_id": 247042,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 0,
"selected": false,
"text": ".elements"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,969
|
<p>I want to do something like this:</p>
<pre><code>const
MyFirstConstArray: array[0..1] of string = ('Hi', 'Foo');
MySecondConstArrayWhichIncludesTheFirstOne: array[0..2] of string =
MyFirstConstArray + ('Bar');
</code></pre>
<p>Basically I want the following result:</p>
<pre><code>MyFirstConstArray -> ('Hi', 'Foo');
MySecondConstArrayWhichIncludesTheFirstOne -> ('Hi', 'Foo', 'Bar');
</code></pre>
<p>Is it possible somehow?</p>
|
[
{
"answer_id": 247618,
"author": "Francesca",
"author_id": 9842,
"author_profile": "https://Stackoverflow.com/users/9842",
"pm_score": 3,
"selected": true,
"text": "const\n MyConst1 = 'Hi';\n MyConst2 = 'Foo';\n MyConst3 = 'Bar';\n MyFirstConstArray: array[0..1] of string = (MyConst1, MyConst2);\n MySecondConstArrayWhichIncludesTheFirstOne: array[0..2] of string = \n (MyConst1, MyConst2, MyConst3);\n"
},
{
"answer_id": 247672,
"author": "X-Ray",
"author_id": 14031,
"author_profile": "https://Stackoverflow.com/users/14031",
"pm_score": 1,
"selected": false,
"text": "type\n TPerson=record\n // generally you'd put all kinds of addition stuff here including enums, \n // sets, etc\n saPets:array[0..2] of string;\n end;\n\nconst\n scDog='Dog';\n\n MyPeople:array[0..1] of TPerson=\n ((saPets:(scDog, 'Cat', 'Fish'); ),\n (saPets:('Iguana', 'Tarantula', ''); ));\n\nbegin\n ShowMessage(MyPeople[0].saPets[0]);\n\nend;\n"
},
{
"answer_id": 255093,
"author": "Jim McKeeth",
"author_id": 255,
"author_profile": "https://Stackoverflow.com/users/255",
"pm_score": 1,
"selected": false,
"text": "type\n TMyConsts = (tConstFoo, tConstHi, TConstBar);\nconst\n MyFirstConstSet = [tConstFoo, tConstHi];\n MySecondConstSet = MyFirstConstSet + [TConstBar];\n MyConstStrings: array[TMyConsts] of string = ('Foo', 'Hi', 'Bar');\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/727/"
] |
246,977
|
<p>I recently read that using flexible array members in C was poor software engineering practice. However, that statement was not backed by any argument. Is this an accepted fact?</p>
<p>(<a href="https://en.wikipedia.org/wiki/Flexible_array_member" rel="noreferrer">Flexible array members</a> are a C feature introduced in C99 whereby one can declare the last element to be an array of unspecified size. For example: )</p>
<pre><code>struct header {
size_t len;
unsigned char data[];
};
</code></pre>
|
[
{
"answer_id": 247038,
"author": "Roddy",
"author_id": 1737,
"author_profile": "https://Stackoverflow.com/users/1737",
"pm_score": 4,
"selected": false,
"text": "struct header\n{\n size_t len;\n unsigned char data[];\n}; \n unsigned char data[0];\n foo = malloc(sizeof(header) + N * sizeof(data[0]));\n foo->len = N;\n struct header\n {\n size_t len;\n unsigned char *data;\n }; \n"
},
{
"answer_id": 247040,
"author": "Remo.D",
"author_id": 16827,
"author_profile": "https://Stackoverflow.com/users/16827",
"pm_score": 4,
"selected": false,
"text": "struct header {\n size_t len;\n unsigned char data[1];\n};\n data ptr = malloc(sizeof(struct header) + (n-1));\n"
},
{
"answer_id": 888252,
"author": "diapir",
"author_id": 108172,
"author_profile": "https://Stackoverflow.com/users/108172",
"pm_score": 3,
"selected": false,
"text": "struct header *my_header\n = malloc(offsetof(struct header, data) + n * sizeof my_header->data);\n #define FLEXIBLE_SIZE SIZE_MAX /* or whatever maximum length for an array */\n#define SIZEOF_FLEXIBLE(type, member, length) \\\n ( offsetof(type, member) + (length) * sizeof ((type *)0)->member[0] )\n\nstruct header {\n size_t len;\n unsigned char data[FLEXIBLE_SIZE];\n};\n\n...\n\nsize_t n = 123;\nstruct header *my_header = malloc(SIZEOF_FLEXIBLE(struct header, data, n));\n struct header *my_header = malloc(sizeof *my_header);\n"
},
{
"answer_id": 2948597,
"author": "Nyan",
"author_id": 210946,
"author_profile": "https://Stackoverflow.com/users/210946",
"pm_score": 3,
"selected": false,
"text": " struct header {\n size_t len;\n unsigned char *data;\n};\n\n struct header *p;\n p = malloc(sizeof(*p) + len + 1 );\n p->data = (unsigned char*) (p + 1 ); // memory after p is mine! \n"
},
{
"answer_id": 22143014,
"author": "wds",
"author_id": 10098,
"author_profile": "https://Stackoverflow.com/users/10098",
"pm_score": 3,
"selected": false,
"text": "void test(void) {\n struct header;\n char *p = &header.data[0];\n\n ...\n}\n struct header2 {\n int len;\n char data[MAXLEN]; /* MAXLEN some appropriately large number */\n}\n struct header2 inst1 = inst2;\n struct header2 *inst1 = *inst2;\n memcpy struct header3 {\n int len;\n char data[]; /* flexible array member */\n}\n struct header3 void not_good ( struct header3 ) ;\n void good ( struct header3 * ) ;\n"
},
{
"answer_id": 46251908,
"author": "maxschlepzig",
"author_id": 427158,
"author_profile": "https://Stackoverflow.com/users/427158",
"pm_score": 5,
"selected": false,
"text": "struct Header {\n size_t d;\n long v[];\n};\ntypedef struct Header Header;\nsize_t n = 123; // can dynamically change during program execution\n// ...\nHeader *h = malloc(sizeof(Header) + sizeof(long[n]));\nh->n = n;\n Header *h = malloc(sizeof *h + n * sizeof h->v[0]);\n sizeof(Header) Header *h = malloc(sizeof(size_t) + sizeof(long[n])); // invalid!\n long v[0]; long v[1];"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246977",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
246,981
|
<p>Does anyone have any idea what is wrong with this create statement for mysql? </p>
<p>EDIT: now it states the error is near: revised VARCHAR(20), paypal_accept TINYINT, pre_terminat' at line 4</p>
<p>Thanks for the help everyone</p>
<p>Still errors after using sql beautifier though</p>
<pre><code>CREATE TABLE AUCTIONS (
ARTICLE_NO VARCHAR(20),
ARTICLE_NAME VARCHAR(100),
SUBTITLE VARCHAR(20),
CURRENT_BID VARCHAR(20),
START_PRICE VARCHAR(20),
BID_COUNT VARCHAR(20),
QUANT_TOTAL VARCHAR(20),
QUANT_SOLD VARCHAR(20),
START DATETIME,
ENDS DATETIME,
ORIGIN_END DATETIME,
SELLER_ID VARCHAR(20),
BEST_BIDDER_ID VARCHAR(20),
FINISHED VARCHAR(20),
WATCH VARCHAR(20),
BUYITNOW_PRICE VARCHAR(20),
PIC_URL VARCHAR(20),
PRIVATE_AUCTION VARCHAR(20),
AUCTION_TYPE VARCHAR(20),
INSERT_DATE DATETIME,
UPDATE_DATE DATETIME,
CAT_1_ID VARCHAR(20),
CAT_2_ID VARCHAR(20),
ARTICLE_DESC VARCHAR(20),
DESC_TEXTONLY VARCHAR(20),
COUNTRYCODE VARCHAR(20),
LOCATION VARCHAR(20),
CONDITION VARCHAR(20),
REVISED VARCHAR(20),
PAYPAL_ACCEPT TINYINT,
PRE_TERMINATED VARCHAR(20),
SHIPPING_TO VARCHAR(20),
FEE_INSERTION VARCHAR(20),
FEE_FINAL VARCHAR(20),
FEE_LISTING VARCHAR(20),
PIC_XXL TINYINT,
PIC_DIASHOW TINYINT,
PIC_COUNT VARCHAR(20),
ITEM_SITE_ID VARCHAR(20),
PRIMARY KEY ( `ARTICLE_NO` ));
</code></pre>
<p>The error is now near 'CONDITION VARCHAR(20), REVISED VARCHAR(20), PAYPAL_ACCEPT TI' at line 29</p>
<p>I really can't see what is wrong, does TINYINT need a parameter?</p>
<p>Do MYSQL column names have to be capitals?</p>
|
[
{
"answer_id": 246996,
"author": "dove",
"author_id": 30913,
"author_profile": "https://Stackoverflow.com/users/30913",
"pm_score": 3,
"selected": false,
"text": "watch VARCHAR(20), **????** VARCHAR(20), \nauction_type VARCHAR(20),\n"
},
{
"answer_id": 247061,
"author": "Stephen Walcher",
"author_id": 25375,
"author_profile": "https://Stackoverflow.com/users/25375",
"pm_score": 0,
"selected": false,
"text": "PRIMARY KEY (`article_no`)\n"
},
{
"answer_id": 247075,
"author": "andy",
"author_id": 32033,
"author_profile": "https://Stackoverflow.com/users/32033",
"pm_score": 2,
"selected": false,
"text": "pic_count VARCHAR(20),item_site_id); item_site_id"
},
{
"answer_id": 247121,
"author": "Ed Guiness",
"author_id": 4200,
"author_profile": "https://Stackoverflow.com/users/4200",
"pm_score": 2,
"selected": false,
"text": "CREATE TABLE auctions (\n article_no VARCHAR(20),\n article_name VARCHAR(100),\n subtitle VARCHAR(20),\n current_bid VARCHAR(20),\n start_price VARCHAR(20),\n bid_count VARCHAR(20),\n quant_total VARCHAR(20),\n quant_sold VARCHAR(20),\n start DATETIME,\n ends DATETIME,\n origin_end DATETIME,\n seller_id VARCHAR(20),\n best_bidder_id VARCHAR(20),\n finished VARCHAR(20),\n watch VARCHAR(20),\n buyitnow_price VARCHAR(20),\n pic_url VARCHAR(20),\n private_auction VARCHAR(20),\n auction_type VARCHAR(20),\n insert_date DATETIME,\n update_date DATETIME,\n cat_1_id VARCHAR(20),\n cat_2_id VARCHAR(20),\n article_desc VARCHAR(20),\n desc_textonly VARCHAR(20),\n countrycode VARCHAR(20),\n location VARCHAR(20),\n condition VARCHAR(20),\n revised VARCHAR(20),\n paypal_accept TINYINT,\n pre_terminated VARCHAR(20),\n shipping_to VARCHAR(20),\n fee_insertion VARCHAR(20),\n fee_final VARCHAR(20),\n fee_listing VARCHAR(20),\n pic_xxl TINYINT,\n pic_diashow TINYINT,\n pic_count VARCHAR(20),\n item_site_id\n);\n"
},
{
"answer_id": 247359,
"author": "grammar31",
"author_id": 12815,
"author_profile": "https://Stackoverflow.com/users/12815",
"pm_score": 2,
"selected": false,
"text": "CONDITION"
},
{
"answer_id": 247377,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 2,
"selected": false,
"text": "CONDITION . . .\nLOCATION VARCHAR(20),\n`CONDITION` VARCHAR(20),\nREVISED VARCHAR(20),\n. . .\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1246613/"
] |
246,983
|
<p>What's the most efficient way of getting the value of the SERIAL column after the INSERT statement? I.e. I am looking for a way to replicate <code>@@IDENTITY</code> or <code>SCOPE_IDENTITY</code> functionality of MS SQL</p>
|
[
{
"answer_id": 247159,
"author": "Brian Schmitt",
"author_id": 30492,
"author_profile": "https://Stackoverflow.com/users/30492",
"pm_score": 1,
"selected": false,
"text": "if LOCAL_SQLCA^.sqlcode = 0 then\n/* return serial */\n Result := LOCAL_SQLCA^.sqlerrd[1]\nelse\n/* return error code */\n Result := -(Abs(LOCAL_SQLCA^.sqlcode));\n"
},
{
"answer_id": 252433,
"author": "RET",
"author_id": 14750,
"author_profile": "https://Stackoverflow.com/users/14750",
"pm_score": 5,
"selected": true,
"text": "LET new_id = DBINFO('sqlca.sqlerrd1');\n $sth->{ix_sqlerrd}[1]"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/246983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15329/"
] |
247,006
|
<p>I've got a PHP application which needs to grab the contents from another web page, and the web page I'm reading needs a cookie.</p>
<p>I've found info on how to make this call once i have the cookie ( <a href="http://groups.google.com/group/comp.lang.php/msg/4f618114ab15ae2a" rel="nofollow noreferrer">http://groups.google.com/group/comp.lang.php/msg/4f618114ab15ae2a</a> ), however I've no idea how to generate the cookie, or how / where the cookie is saved.</p>
<p>For example, to read this web page via wget I do the following:</p>
<pre><code>wget --quiet --save-cookies cookie.file --output-document=who.cares \
http://remoteServer/login.php?user=xxx&pass=yyy
wget --quiet --load-cookies cookie.file --output-document=documentiwant.html \
http://remoteServer/pageicareabout.html
</code></pre>
<p>... my question is how do I do the '--save-cookies' bit in PHP so that I can use the cookie in the follow-up PHP stream_context_create / file_get_contents block:</p>
<pre><code>$opts = array(http'=> array(
'method'=> "GET",
'header'=>
"Accept-language: en\r\n" .
"Cookie: **NoClueAtAll**\r\n"
)
);
$context = stream_context_create($opts);
$documentiwant = file_get_contents("http://remoteServer/pageicareabout.html",
0, $context);
</code></pre>
|
[
{
"answer_id": 247472,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "<?php\n\n$cr = curl_init('http://remoteServer/login.php?user=xxx&pass=yyy');\ncurl_setopt($cr, CURLOPT_RETURNTRANSFER, true); \ncurl_setopt($cr, CURLOPT_COOKIEJAR, 'cookie.txt'); \n$whoCares = curl_exec($cr); \ncurl_close($cr); \n\n$cr = curl_init('http://remoteServer/pageicareabout.html');\ncurl_setopt($cr, CURLOPT_RETURNTRANSFER, true); \ncurl_setopt($cr, CURLOPT_COOKIEFILE, 'cookie.txt'); \n$documentiwant = curl_exec($cr);\ncurl_close($cr);\n\n?>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
247,023
|
<p>I have a structure like this:</p>
<pre><code><ul>
<li>text1</li>
<li>text2</li>
<li>text3</li>
</ul>
</code></pre>
<p>How do I use javascript or jQuery to get the text as an array?</p>
<pre><code>['text1', 'text2', 'text3']
</code></pre>
<p>My plan after this is to assemble it into a string, probably using <code>.join(', ')</code>, and get it in a format like this:</p>
<pre><code>'"text1", "text2", "text3"'
</code></pre>
|
[
{
"answer_id": 247057,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 8,
"selected": true,
"text": "var optionTexts = [];\n$(\"ul li\").each(function() { optionTexts.push($(this).text()) });\n join() var quotedCSV = '\"' + optionTexts.join('\", \"') + '\"';\n"
},
{
"answer_id": 247067,
"author": "Dave Ward",
"author_id": 60,
"author_profile": "https://Stackoverflow.com/users/60",
"pm_score": 3,
"selected": false,
"text": "var arr = new Array();\n\n$('li').each(function() { \n arr.push(this.innerHTML); \n})\n"
},
{
"answer_id": 247203,
"author": "roenving",
"author_id": 23142,
"author_profile": "https://Stackoverflow.com/users/23142",
"pm_score": 4,
"selected": false,
"text": "var texts = [], lis = document.getElementsByTagName(\"li\");\nfor(var i=0, im=lis.length; im>i; i++)\n texts.push(lis[i].firstChild.nodeValue);\n\nalert(texts);\n"
},
{
"answer_id": 5196124,
"author": "kimstik",
"author_id": 645031,
"author_profile": "https://Stackoverflow.com/users/645031",
"pm_score": 6,
"selected": false,
"text": "var arr = $('li').map(function(i,el) {\n return $(el).text();\n}).get();\n"
},
{
"answer_id": 7518268,
"author": "Cybolic",
"author_id": 242846,
"author_profile": "https://Stackoverflow.com/users/242846",
"pm_score": 4,
"selected": false,
"text": "$.map( $('li'), function (element) { return $(element).text() });\n $.map( $('li'), function (element) { return $(element).text() }).join(', ');\n"
},
{
"answer_id": 54793123,
"author": "noone",
"author_id": 5229871,
"author_profile": "https://Stackoverflow.com/users/5229871",
"pm_score": 2,
"selected": false,
"text": "let array = $('ul>li').toArray().map(item => $(item).html()); let array = $('ul>li').toArray().map(item => $(item).html());\nconsole.log(array); <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n<ul>\n <li>text1</li>\n <li>text2</li>\n <li>text3</li>\n</ul>"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247023",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3757/"
] |
247,025
|
<p>It is good practice to use the main method to test a java/.net class?</p>
<p>I've seen it reccommended in some text books, but to me it seems like using a unit testing framework would make more sense...</p>
<p>The main method gives you one point of entry to the class and you can test one aspect of the classes functionality. You could I guess test many but it doesn't seem to make sense as much as using Junit or Nunit.</p>
|
[
{
"answer_id": 248334,
"author": "Motti",
"author_id": 3848,
"author_profile": "https://Stackoverflow.com/users/3848",
"pm_score": 0,
"selected": false,
"text": "Compile with /main to specify the type that contains the entry point."
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400/"
] |
247,045
|
<p>Been a while since I've dealt with ASP.NET and this is the first time I've had to deal with master pages. Been following tutorials everything is fine except a problem I'm having with the footer.</p>
<p>The master page has divs for topContent, mainContent and footerContent. In mainContent I have a ContentPlaceHolder.</p>
<p>The default content page (just getting some proof-of-concept going here) has a few labels and text boxes in it with one multi-line text box in the Content area. "Content1" properly links back to ContentPlaceHolder1 back on the master page.</p>
<p>When I run the site, the content appears but the footer section isn't "pushed down" by the now-filled ContentPlaceHolder - it almost acts like a background image.</p>
<p>What attribute am I missing here? I tried using CSS to force the footerContent to the bottom, but that just put the fotter content at the bottom of the browser and when I expanded the multi-line text box to greater than the browser's window height, the same thing happened (content overlaying the footer)</p>
<p>I know this has to be something simple that I'm missing.</p>
<p>The basics of the master page are as follows:</p>
<pre><code><form id="form1" runat="server">
<div id="topContent">
<table style="width: 832px">
</table>
</div>
<div id="mainContent">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div id="footerContent">
<br/><br/>
<center style="font-size: small; font-style: italic; font-family: Arial">
<a target="_new" href="/Disclaimer.html">Security and Privacy Notice</a><br/>
...
</center>
</div>
</form>
</code></pre>
<p>Help!</p>
<p>EDIT: Turns out that VS2005 was putting "position: absolute" tags on all the components (labels and text boxes) that I put on the content.aspx page. Going into the asp tags and changing them to "position: relative" did the trick.</p>
|
[
{
"answer_id": 247095,
"author": "Schalk Versteeg",
"author_id": 15724,
"author_profile": "https://Stackoverflow.com/users/15724",
"pm_score": 2,
"selected": false,
"text": " <div id=\"mainContent\"style=\"position:relative;\">\n <asp:ContentPlaceHolder id=\"ContentPlaceHolder1\" runat=\"server\">\n </asp:ContentPlaceHolder>\n </div>\n<br style=\"clear:both;\" />\n <div id=\"footerContent\" style=\"position:relative;\">\n <br/><br/>\n <center style=\"font-size: small; font-style: italic; font-family: Arial\">\n <a target=\"_new\" href=\"/Disclaimer.html\">Security and Privacy Notice</a><br/>\n ...\n </center>\n </div>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247045",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15891/"
] |
247,053
|
<p>On Linux, feenableexcept and fedisableexcept can be used to control the generation of SIGFPE interrupts on floating point exceptions. How can I do this on Mac OS X Intel?</p>
<p>Inline assembly for enabling floating point interrupts is provided in <a href="http://developer.apple.com/documentation/Performance/Conceptual/Mac_OSX_Numerics/Mac_OSX_Numerics.pdf" rel="noreferrer">http://developer.apple.com/documentation/Performance/Conceptual/Mac_OSX_Numerics/Mac_OSX_Numerics.pdf</a>, pp. 7-15, but only for PowerPC assembly.</p>
|
[
{
"answer_id": 252590,
"author": "Louis Gerbarg",
"author_id": 30506,
"author_profile": "https://Stackoverflow.com/users/30506",
"pm_score": 3,
"selected": false,
"text": "short fpflags = 0x1332 // Default FP flags, change this however you want. \nasm(\"fnclex\");\nasm(\"fldcw _fpflags\");\n"
},
{
"answer_id": 340683,
"author": "Geoffrey Irving",
"author_id": 16480,
"author_profile": "https://Stackoverflow.com/users/16480",
"pm_score": 6,
"selected": true,
"text": "_MM_SET_EXCEPTION_MASK xmmintrin.h #include <xmmintrin.h>\n...\n_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID);\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16480/"
] |
247,059
|
<p>In C# there is the static property <a href="http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx" rel="noreferrer">Environment.Newline</a> that changed depending on the running platform.</p>
<p>Is there anything similar in Java?</p>
|
[
{
"answer_id": 247069,
"author": "Tom Lokhorst",
"author_id": 2597,
"author_profile": "https://Stackoverflow.com/users/2597",
"pm_score": 9,
"selected": true,
"text": "System.lineSeparator()\n System.getProperty(\"line.separator\");\n"
},
{
"answer_id": 247597,
"author": "Alan Moore",
"author_id": 20938,
"author_profile": "https://Stackoverflow.com/users/20938",
"pm_score": 6,
"selected": false,
"text": "\\n \\r\\n \\r\\n \\n \\r \\r\\n"
},
{
"answer_id": 30217755,
"author": "J.Steve",
"author_id": 736737,
"author_profile": "https://Stackoverflow.com/users/736737",
"pm_score": 7,
"selected": false,
"text": "System.lineSeparator()\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20480/"
] |
247,064
|
<p>I've recently been lifted out of the .Net world into the Java world and I miss my unit tests.</p>
<p>Using Visual Studio I used NUnit and TestDriven.net to run my unit tests.</p>
<p>What is a comparable system for Java Using Eclipse?</p>
<p>I'm looking specifically for the plugins that will get me going, or a guide on how to do it.</p>
<p>I'm aware that JUnit is what NUnit was initially based on, but I want to know the best way to integrate it into Eclipse as there seem to be a few plugins that do this and I don't have the time to play around with them all.</p>
<p><strong>UPDATE</strong></p>
<p>Okay I didn't know that JUnit was built into the IDE. Are there any plugins that make using JUnit any easier?</p>
|
[
{
"answer_id": 247975,
"author": "Powerlord",
"author_id": 15880,
"author_profile": "https://Stackoverflow.com/users/15880",
"pm_score": 1,
"selected": false,
"text": "@Test\npublic myTest() {\n // Test code here\n}\n @Before @After @BeforeClass @AfterClass @Ignore @Before @BeforeClass"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400/"
] |
247,066
|
<p>I want the most performat way to read and parse a file.</p>
<p>Is it possible to read a file in .NET, but not load the entire file into memory? i.e. just load the file line by line as I parse the content of each row?</p>
<p>Does XmlTextReader load the entire file into memory or does it stream the file into memory as it reads the file?</p>
|
[
{
"answer_id": 247107,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 3,
"selected": false,
"text": "string line;\n\n// Read the file and display it line by line.\nSystem.IO.StreamReader file = \n new System.IO.StreamReader(\"c:\\\\test.txt\");\n\nwhile((line = file.ReadLine()) != null)\n{\n Console.WriteLine (line);\n}\n\nfile.Close();\n"
},
{
"answer_id": 247112,
"author": "JFV",
"author_id": 1391,
"author_profile": "https://Stackoverflow.com/users/1391",
"pm_score": 0,
"selected": false,
"text": "Dim theLine as String\nDim fsFile As New FileStream(inputFile, FileMode.Open) 'File Stream for the Input File\nDim fsImport As New FileStream(outputFile, FileMode.OpenOrCreate) 'File Stream for the Output File\nDim srFile As New StreamReader(fsFile) 'Stream Reader for Input File\nDim swfile As New StreamWriter(fsImport) 'Stream Writer for Output File\n\nDo While srFile.Peek <> -1 'Do While it's not the last line of the file\n theLine = srFile.ReadLine 'Read the line\n Messagebox.Show(theLine, \"Line-by-Line!\")\nLoop\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
247,086
|
<p>I know that one of the defining principles of Test driven development is that you write your Unit tests first and then write code to pass those unit tests, but is it necessary to do it this way?</p>
<p>I've found that I often don't know what I am testing until I've written it, mainly because the past couple of projects I've worked on have more evolved from a proof of concept rather than been designed.</p>
<p>I've tried to write my unit tests before and it can be useful, but it doesn't seem natural to me.</p>
|
[
{
"answer_id": 247119,
"author": "Jonke",
"author_id": 15638,
"author_profile": "https://Stackoverflow.com/users/15638",
"pm_score": 2,
"selected": false,
"text": "picker = Pick.new\nitem=picker.pick('a')\nassert item\n class Pick\n def pick(something)\n return nil\n end\nend\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247086",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400/"
] |
247,090
|
<p>I'm familiar with the issue behind ORA-01775: looping chain of synonyms, but is there any trick to debugging it, or do I just have to "create or replace" my way out of it? </p>
<p>Is there a way to query the schema or whatever to find out what the current definition of a public synonym is? </p>
<p>Even more awesome would be a graphical tool, but at this point, anything would be helpful.</p>
|
[
{
"answer_id": 247180,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 5,
"selected": false,
"text": "DBA_SYNONYMS SELECT table_owner, table_name, db_link\n FROM dba_synonyms \n WHERE owner = 'PUBLIC'\n AND synonym_name = <<synonym name>>\n"
},
{
"answer_id": 247191,
"author": "warren",
"author_id": 4418,
"author_profile": "https://Stackoverflow.com/users/4418",
"pm_score": -1,
"selected": false,
"text": "CREATE SYNONYM s1 for s2 CREATE SYNONYM s2 for s3 CREATE SYNONYM s3 for s1"
},
{
"answer_id": 25187479,
"author": "grokster",
"author_id": 502441,
"author_profile": "https://Stackoverflow.com/users/502441",
"pm_score": 2,
"selected": false,
"text": "select * from all_objects where object_name = upper('&object_name');\n select * from all_synonyms where synonym_name = upper('&synonym_name');\n"
},
{
"answer_id": 26276851,
"author": "Michal Mikolajczyk",
"author_id": 4124933,
"author_profile": "https://Stackoverflow.com/users/4124933",
"pm_score": 3,
"selected": false,
"text": "SELECT *\nFROM dba_synonyms\nWHERE table_owner = 'USER'\n AND (\n NOT EXISTS (\n SELECT *\n FROM dba_tables\n WHERE dba_synonyms.table_name = dba_tables.TABLE_NAME\n )\n AND NOT EXISTS (\n SELECT *\n FROM dba_views\n WHERE dba_synonyms.table_name = dba_views.VIEW_NAME\n )\n AND NOT EXISTS (\n SELECT *\n FROM dba_sequences\n WHERE dba_synonyms.table_name = dba_sequences.sequence_NAME\n )\n AND NOT EXISTS (\n SELECT *\n FROM dba_dependencies\n WHERE type IN (\n 'PACKAGE'\n ,'PROCEDURE'\n ,'FUNCTION'\n )\n AND dba_synonyms.table_name = dba_dependencies.NAME\n )\n )\n"
},
{
"answer_id": 28861293,
"author": "Faxon Lander Montenegro",
"author_id": 2966714,
"author_profile": "https://Stackoverflow.com/users/2966714",
"pm_score": -1,
"selected": false,
"text": "v_query: = 'insert into table select * from table2 v_query"
},
{
"answer_id": 31759938,
"author": "Jarrod Chesney",
"author_id": 1051479,
"author_profile": "https://Stackoverflow.com/users/1051479",
"pm_score": 4,
"selected": false,
"text": "SELECT S.OWNER as SYN_OWNER, S.SYNONYM_NAME as SYN_NAME,\n S.TABLE_OWNER as OBJ_OWNER, S.TABLE_NAME as OBJ_NAME,\n CASE WHEN O.OWNER is null THEN 'MISSING' ELSE O.STATUS END as OBJ_STATUS\nFROM DBA_SYNONYMS S\n LEFT JOIN DBA_OBJECTS O ON S.TABLE_OWNER = O.OWNER AND S.TABLE_NAME = O.OBJECT_NAME\nWHERE O.OWNER is null\n OR O.STATUS != 'VALID';\n"
},
{
"answer_id": 32191321,
"author": "Tim Lewis",
"author_id": 67865,
"author_profile": "https://Stackoverflow.com/users/67865",
"pm_score": 2,
"selected": false,
"text": "CREATE OR REPLACE PUBLIC SYNONYM \"DUAL\" FOR \"DUAL\"; select * from dba_synonyms where table_name = 'DUAL';\n PUBLIC DUAL SOME_USER DUAL PUBLIC DUAL SYS DUAL ALTER SYSTEM SET \"_SYSTEM_TRIG_ENABLED\"=FALSE SCOPE=MEMORY;\nCREATE OR REPLACE PUBLIC SYNONYM DUAL FOR SYS.DUAL;\nALTER SYSTEM SET \"_SYSTEM_TRIG_ENABLED\"=true SCOPE=MEMORY;\n"
},
{
"answer_id": 36094116,
"author": "mahi_0707",
"author_id": 4266332,
"author_profile": "https://Stackoverflow.com/users/4266332",
"pm_score": 1,
"selected": false,
"text": "ORA-01775 package table table synonym SELECT * FROM DBA_TABLES WHERE TABLE_NAME = '&TABLE_NAME'; -- No rows returned\n\nSELECT * FROM DBA_SYNONYMS WHERE SYNONYM_NAME = '&SYNONYM_NAME'; -- 1 row returned\n synonym table"
},
{
"answer_id": 36770521,
"author": "wmorrison365",
"author_id": 758831,
"author_profile": "https://Stackoverflow.com/users/758831",
"pm_score": 0,
"selected": false,
"text": " select * \n from all_synonyms \n where table_owner = 'SCOTT' \n and synonym_name not like '%/%'\n and table_name not in (\n select object_name from user_objects\n where object_type in (\n 'TABLE', 'VIEW', 'PACKAGE', 'SEQUENCE',\n 'PROCEDURE', 'FUNCTION', 'TYPE'\n )\n );\n"
},
{
"answer_id": 51047341,
"author": "Justin",
"author_id": 537243,
"author_profile": "https://Stackoverflow.com/users/537243",
"pm_score": 2,
"selected": false,
"text": "select owner, synonym_name, connect_by_iscycle CYCLE\nfrom dba_synonyms\nwhere connect_by_iscycle > 0\nconnect by nocycle prior table_name = synonym_name\nand prior table_owner = owner\nunion\nselect 'PUBLIC', synonym_name, 1\nfrom dba_synonyms\nwhere owner = 'PUBLIC'\nand table_name = synonym_name\nand (table_name, table_owner) not in (select object_name, owner from dba_objects\nwhere object_type != 'SYNONYM')\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/549/"
] |
247,093
|
<p>I want to change the registry values on the pocketPC. I ran the following code:</p>
<pre><code>if(enabled)
{
dwData = 120;
}
if(RegSetValueEx(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Control\\Power\\Timeouts\\BattSuspendTimeout"), 0, REG_DWORD, (LPBYTE)&dwData, sizeof(DWORD)))
{
return FALSE;
}
</code></pre>
<p>but it doesn't shange the registry entry. Does anyone know how to set registry key values with c++?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 248604,
"author": "Shane Powell",
"author_id": 23235,
"author_profile": "https://Stackoverflow.com/users/23235",
"pm_score": 4,
"selected": true,
"text": "HKEY key;\nif(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, \"System\\\\CurrentControlSet\\\\Control\\\\Power\\\\Timeouts\", 0, 0, &key))\n{\n if(RegSetValueEx(key, _T(\"BattSuspendTimeout\"), 0, REG_DWORD, (LPBYTE)&dwData, sizeof(DWORD)))\n {\n RegCloseKey(key);\n return FALSE;\n }\n\n RegCloseKey(key);\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22996/"
] |
247,106
|
<p>Looking at this loop that copies one c-string to another:</p>
<pre><code>void strcpyr(char *s, char *t)
{
while(*s++=*t++)// Why does this work?
;
}
</code></pre>
<p>Why do we not check for the '\0' character in the while loop, like this?</p>
<pre><code>while((*s++=*r++)!='\0')..
</code></pre>
<p>How does the first loop terminate?</p>
|
[
{
"answer_id": 247122,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 2,
"selected": false,
"text": "'\\0' t *s++=*t++ s '\\0' false 0 '\\0' c != '\\0' c"
},
{
"answer_id": 247126,
"author": "Adam Davis",
"author_id": 2915,
"author_profile": "https://Stackoverflow.com/users/2915",
"pm_score": 1,
"selected": false,
"text": "while(*s++=*t++)\n;\n"
},
{
"answer_id": 247130,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 4,
"selected": false,
"text": "char c = *s++ = *t++;\n"
},
{
"answer_id": 247136,
"author": "Joseph Bui",
"author_id": 3275,
"author_profile": "https://Stackoverflow.com/users/3275",
"pm_score": 0,
"selected": false,
"text": "void strcpyr(char *s, char *t) {\n while (*s++ = *t++);\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
247,110
|
<p>I'm getting started on building a REST API for a project I'm working on, and it led me to do a little research as to the best way to build an API using RoR. I find out pretty quickly that by default, models are open to the world and can be called via URL by simply putting a ".xml" at the end of the URL and passing appropriate parameters.</p>
<p>So then the next question came. How do I secure my app to prevent unauthorized changes? In doing some research I found a couple articles talking about <code>attr_accessible</code> and <code>attr_protected</code> and how they can be used. The particular URL I found talking about these was posted back in May of '07 (<a href="http://railscasts.com/episodes/26-hackers-love-mass-assignment" rel="noreferrer">here</a>). </p>
<p>As with all things ruby, I'm sure that things have evolved since then. So my question is, is this still the best way to secure a REST API within RoR?</p>
<p>If not what do you suggest in either a "new project" or an "existing project"scenario?</p>
|
[
{
"answer_id": 247162,
"author": "jonnii",
"author_id": 4590,
"author_profile": "https://Stackoverflow.com/users/4590",
"pm_score": 2,
"selected": false,
"text": " class Model < ActiveRecord::Base \n attr_accessible nil \n end\n"
},
{
"answer_id": 248101,
"author": "Gabe Hollombe",
"author_id": 30632,
"author_profile": "https://Stackoverflow.com/users/30632",
"pm_score": 3,
"selected": false,
"text": "attr_accessible attr_protected before_filter"
},
{
"answer_id": 250308,
"author": "Micah",
"author_id": 19964,
"author_profile": "https://Stackoverflow.com/users/19964",
"pm_score": 8,
"selected": true,
"text": "http://myusername:mypass@www.someapp.com/\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23458/"
] |
247,123
|
<p>I am writing a C# console application that takes a binary file, rips it apart, analyzes it, and stores the data into a database. </p>
<p>We want to use BizTalk to orchestrate watching when a new binary file is placed in a directory and calling my application with the file name/names to be parsed. </p>
<p>Can BizTalk run a command line program?<br>
Can it pass command line parameters to the program?<br>
How would I report back to BizTalk that the last run was a success or a failure? </p>
<p>Thank you,<br>
Keith</p>
|
[
{
"answer_id": 248503,
"author": "David Hall",
"author_id": 2660,
"author_profile": "https://Stackoverflow.com/users/2660",
"pm_score": 3,
"selected": true,
"text": "System.Diagnostics.Process.Start(@\"C:\\yourPath\\yourExecutable.exe\") System.Diagnostics"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247123",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1048/"
] |
247,128
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/153152/resizing-an-iframe-based-on-content">Resizing an iframe based on content</a> </p>
</blockquote>
<p>I'm loading an iFrame and want the parent to automatically change the height based upon the height of the iFrame's content.</p>
<p>To simply things, all pages belong to the same domain, so I shouldn't run into cross-site scripting issues.</p>
|
[
{
"answer_id": 247160,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 5,
"selected": false,
"text": "scrollHeight offsetHeight function setHeight() {\n parent.document.getElementById('the-iframe-id').style.height = document['body'].offsetHeight + 'px';\n}\n onLoad"
},
{
"answer_id": 247221,
"author": "Allan",
"author_id": 5123,
"author_profile": "https://Stackoverflow.com/users/5123",
"pm_score": 0,
"selected": false,
"text": "\n $(document).ready(function(){\n setTimeout(setHeight);\n });\n\n function setHeight() {\n alert(document['body'].offsetHeight); \n }\n"
},
{
"answer_id": 247230,
"author": "TimeSpace Traveller",
"author_id": 5116,
"author_profile": "https://Stackoverflow.com/users/5116",
"pm_score": 1,
"selected": false,
"text": "iframe.height = iframe.contentWindow.document.scrollHeight;\n iframe.height = iframe.contentDocument.scrollHeight\n"
},
{
"answer_id": 247821,
"author": "Allan",
"author_id": 5123,
"author_profile": "https://Stackoverflow.com/users/5123",
"pm_score": -1,
"selected": false,
"text": "\nif ($.browser.msie == false) {\n var h = (document.getElementById(\"iframeID\").contentDocument.body.offsetHeight);\n} else {\n var h = (document.getElementById(\"iframeID\").Document.body.scrollHeight);\n}\n"
},
{
"answer_id": 2967388,
"author": "Shripad Krishna",
"author_id": 277537,
"author_profile": "https://Stackoverflow.com/users/277537",
"pm_score": 4,
"selected": false,
"text": "$('iframe').contents().find('body').css({\"min-height\": \"100\", \"overflow\" : \"hidden\"});\nsetInterval( \"$('iframe').height($('iframe').contents().find('body').height() + 20)\", 1 );\n"
},
{
"answer_id": 3454721,
"author": "Sky",
"author_id": 91379,
"author_profile": "https://Stackoverflow.com/users/91379",
"pm_score": 3,
"selected": false,
"text": "<head>\n<style type=\"text/css\"> \nhtml {height:100%}\nbody {\nmargin:0;\nheight:100%;\noverflow:hidden\n}\n</style>\n</head>\n\n<body>\n<iframe allowtransparency=true frameborder=0 id=rf sandbox=\"allow-same-origin allow-forms allow-scripts\" scrolling=auto src=\"http://www.externaldomain.com/\" style=\"width:100%;height:100%\"></iframe>\n</body>\n"
},
{
"answer_id": 4111904,
"author": "Gale",
"author_id": 499041,
"author_profile": "https://Stackoverflow.com/users/499041",
"pm_score": 0,
"selected": false,
"text": "background transparent allow-transparency true scrolling no"
},
{
"answer_id": 6383596,
"author": "Ian Harrigan",
"author_id": 611329,
"author_profile": "https://Stackoverflow.com/users/611329",
"pm_score": 0,
"selected": false,
"text": "<html>\n<head>\n\n\n<script src=\"prototype.js\"></script>\n\n<script>\n function init() {\n var iframe = $(document.getElementById(\"iframe\"));\n var iframe_content = $(iframe.contentWindow.document.getElementById(\"iframe_content\"));\n var cy = iframe_content.getDimensions().height;\n iframe.style.height = cy + \"px\";\n }\n</script>\n\n</head>\n\n<body onload=\"init()\">\n\n\n<iframe src=\"./content.html\" id=\"iframe\" frameBorder=\"0\" scroll=\"no\"></iframe>\n\n<br>\nthis is the next line\n\n</body>\n</html>\n <html>\n<head>\n<script src=\"prototype.js\"></script>\n\n\n<style>\nbody {\n margin: 0px;\n padding: 0px;\n}\n</style>\n\n\n</head>\n\n<body>\n\n\n<div id=\"iframe_content\" style=\"max-height:200px;\">\nSub content<br>\nSub content<br>\n...\n...\n...\n</div>\n\n\n</body>\n</html>\n"
},
{
"answer_id": 7372390,
"author": "geekQ",
"author_id": 111995,
"author_profile": "https://Stackoverflow.com/users/111995",
"pm_score": 1,
"selected": false,
"text": "function autoResizeIFrame() {\n $('iframe').height(\n function() {\n return $(this).contents().find('body').height() + 20;\n }\n )\n}\n\n$('iframe').contents().find('body').css(\n {\"min-height\": \"100\", \"overflow\" : \"hidden\"});\n\nsetTimeout(autoResizeIFrame, 2000);\nsetTimeout(autoResizeIFrame, 10000);\n $('iframe').height($('iframe').contents().find('body').height() + 20) height() + 20 setTimeout setInterval(..., 1)"
},
{
"answer_id": 7889432,
"author": "iknowitwasyoufredo",
"author_id": 607890,
"author_profile": "https://Stackoverflow.com/users/607890",
"pm_score": 1,
"selected": false,
"text": "<iframe id=\"Iframe1\" class=\"tabFrame\" width=\"100%\" height=\"100%\" scrolling=\"no\" src=\"http://samedomain\" frameborder=\"0\" >\n</iframe> \n<script type=\"text/javascript\">\n $(function () {\n\n $('.tabFrame').load(function () {\n var iframeContentWindow = this.contentWindow;\n var height = iframeContentWindow.$(document).height();\n this.style.height = height + 'px';\n });\n });\n</script>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5123/"
] |
247,135
|
<p>I use <a href="http://xpath.alephzarro.com/" rel="noreferrer">XPather Browser</a> to check my XPATH expressions on an HTML page.</p>
<p>My end goal is to use these expressions in Selenium for the testing of my user interfaces.</p>
<p>I got an HTML file with a content similar to this:</p>
<pre>
<tr>
<td>abc</td>
<td>&nbsp;</td>
</tr>
</pre>
<p>I want to select a node with a text containing the string "<code>&nbsp;</code>".</p>
<p>With a normal string like "abc" there is no problem. I use an XPATH similar to <code>//td[text()="abc"]</code>.</p>
<p>When I try with an an XPATH like <code>//td[text()="&nbsp;"]</code> it returns nothing. Is there a special rule concerning texts with "<code>&</code>" ?</p>
|
[
{
"answer_id": 247158,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": " nbsp"
},
{
"answer_id": 247368,
"author": "James Sulak",
"author_id": 207,
"author_profile": "https://Stackoverflow.com/users/207",
"pm_score": 3,
"selected": false,
"text": "  "
},
{
"answer_id": 247405,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 5,
"selected": false,
"text": "//table[@id='TableID']//td[text()=' ']\n"
},
{
"answer_id": 247628,
"author": "Zack The Human",
"author_id": 18265,
"author_profile": "https://Stackoverflow.com/users/18265",
"pm_score": 0,
"selected": false,
"text": "<xsl:value-of select=\"count(//td[text()=' '])\" />\n <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp \" \"> ]>\n"
},
{
"answer_id": 247903,
"author": "Bergeroy",
"author_id": 16927,
"author_profile": "https://Stackoverflow.com/users/16927",
"pm_score": 8,
"selected": true,
"text": "//td[text()=\"${nbsp}\"] <br> <p> <pre> <td> foo <td>foo </td> ${space} ${space} <td>foo${space}${space}${space}</td> ${nbsp} //div[text()=\"hello world\"] hello world //div[text()=\"hello${nbsp}world\"]"
},
{
"answer_id": 248097,
"author": "ChuckB",
"author_id": 28605,
"author_profile": "https://Stackoverflow.com/users/28605",
"pm_score": 1,
"selected": false,
"text": "& > < ' "  "
},
{
"answer_id": 59699055,
"author": "undetected Selenium",
"author_id": 7429447,
"author_profile": "https://Stackoverflow.com/users/7429447",
"pm_score": 3,
"selected": false,
"text": "<tr>\n <td>abc</td>\n <td> </td>\n</tr>\n text() \"//td[text()='\\u00A0']\"\n contains() \"//td[contains(., '\\u00A0')]\"\n <tr> following-sibling \"//tr//following-sibling::td[2]\"\n starts-with() \"//tr//td[last()]\"\n <td> following node and \"//td[text()='abc']//following::td[1]\"\n "
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16927/"
] |
247,143
|
<p>FORTRAN provides several functions to convert a double precision number to an integral value. The method used for truncation/rounding differs. I am converting complex scientific algorithms which use these.</p>
<p>According to FORTRAN documentation:<br>
<b>aint(x)</b> returns the integral value between x and 0, nearest x.<br>
<b>anint(x)</b> returns the nearest integral value to x, except halfway cases are
rounded to the integral value larger in magnitude.<br>
<b>nint(x)</b> converts x into int format rounding to the nearest int value, except
halfway cases are rounded to the int value larger in magnitude.</p>
<p><b>Does anyone have an implementation of these in C#?</b>
It might be tricky getting it right.</p>
<p>(int)x appears to match aint()<br>
Convert.ToInt32(x) does not match any of the above.<br>
Trunc(x) does not match any of the above.<br>
Round(x) might match anint or nint. <br></p>
<p>The difference between anint and nint seems to be the return type, where anint returns a double precision value but nint returns an integer. Both are used (acutal sample):<br>
DOUBLE PRECISION A, B, C, D, E, F, G<br>
... values set here ...<br>
F = ANINT(A-B) + ANINT(C-D) + ANINT(B+D-E)<br>
G = NINT(F) + 1D0;<br>
Perhaps a FORTRAN expert could help clarify why the author chose to use both (I am assuming it was intentional).</p>
|
[
{
"answer_id": 247171,
"author": "Jeff Yates",
"author_id": 23234,
"author_profile": "https://Stackoverflow.com/users/23234",
"pm_score": 3,
"selected": true,
"text": "nint anint Math.Round MidpointRounding.AwayFromZero aint double int"
},
{
"answer_id": 247185,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 1,
"selected": false,
"text": "aint() Math.Floor() nint() anint()"
},
{
"answer_id": 17426864,
"author": "Leonardo Leano",
"author_id": 2542793,
"author_profile": "https://Stackoverflow.com/users/2542793",
"pm_score": 0,
"selected": false,
"text": "double anint(double x)\n{\n int a;\n double y;\n\n a = (int)x; //a=9\n\n if (10 * x - 10 * (double)a >= 5)\n {\n a = a + 1;\n }\n\n y = (double)a;\n\n return y;\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247143",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10722/"
] |
247,149
|
<pre><code><?php
/**
* My codebase is littered with the same conditionals over and over
* again. I'm trying to refactor using inheritance and the Factory
* pattern and I've had some success but I'm now stuck.
*
* I'm stuck because I want to derive a new class from the one
* returned by the Factory. But I can't do that, so I'm obviously
* doing something wrong somewhere else.
*/
/**
* The old implementation was as follows. There's if statements
* everywhere throughout both LayoutView and ItemIndexView and
* SomeOtherView.
*/
class LayoutView { }
class IndexView extends LayoutView { }
class SomeOtherView extends LayoutView { }
/**
* Below is the new implementation. So far I've managed to tidy
* up LayoutView (I think I have anyway). But now I'm stuck because
* the way I've tidied it up has left me not knowing how to extend
* it.
*
* For example's sake, let's say the conditions were relating to a
* type of fish: salmon or tuna.
*/
abstract class LayoutView {
protected function prepareHeader() { echo __METHOD__, "\n"; }
protected function prepareLeftHandSide() { echo __METHOD__, "\n"; }
protected function prepareFooter() { echo __METHOD__, "\n"; }
public function prepare() {
$this->prepareHeader();
$this->prepareLeftHandSide();
$this->prepareFooter();
}
}
class SalmonLayoutView extends LayoutView
{
protected function prepareLeftHandSide() { echo __METHOD__, "\n"; }
}
class TunaLayoutView extends LayoutView
{
protected function prepareLeftHandSide() { echo __METHOD__, "\n"; }
protected function prepareFooter() { echo __METHOD__, "\n"; }
}
class ViewFactory {
public static function getLayoutView($fishType) {
switch($this->$fishType) {
case 'salmon':
return new SalmonLayoutView();
break;
case 'tuna':
return new TunaLayoutView();
break;
}
}
}
/**
* Now LayoutView has been cleaned up and the condition that was once
* scattered through every LayoutView method is now in one place.
*/
$view = ViewFactory::getLayoutView( Config::getOption('fishtype') );
$view->prepare();
/**
* Now here's where I'm stuck. I want to effectively extend whatever
* class $view is an instance of.
*
* The reason being, I wish to derive a view to show an index of
* articles within the appropriate *LayoutView. The IndexView code is
* the same for Salmon and Tuna.
*
* I can do something like this:
*/
class SalmonIndexView extends SalmonLayoutView { }
class TunaIndexView extends TunaLayoutView { }
/**
* But then I'll be writing the same IndexView code twice. What I'd
* like to do is something like this:
*/
$view = ViewFactory::getLayoutView( Config::getOption('fishtype') );
class IndexView extends get_class($view) { }
/**
* But I'm pretty certain that's not possible, and even if it was
* it seems very wrong.
*
* Can someone more experienced in refactoring and OO please let
* me know where I've gone wrong and suggest a clean way to solve
* this?
*/
</code></pre>
|
[
{
"answer_id": 249602,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 0,
"selected": false,
"text": "class LayoutView {\n protected View $subview; //Potentially an array of views\n public function prepare() {\n // empty, to be filled out by derived classes\n }\n public function setSubView($view) { $this->subview = $view; }\n public function display() {\n $this->prepare();\n $this->subview->prepare($this->template);\n $this->template->render();\n }\n}\n\nclass IndexView {\n protected View $subview; //Potentially an array of views\n public function prepare() {\n // empty, to be filled out by derived classes\n }\n public function prepare($template) {\n //operate on it, maybe even assigning it to $this->template\n }\n public function setSubView($view) { $this->subview = $view; }\n public function display() {\n $this->prepare();\n $this->subview->prepare($this->template);\n $this->template->render();\n }\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
247,152
|
<p>I have an app that is failing on the install. The vendor says I probably have ini_set() disabled. How can I check this?</p>
|
[
{
"answer_id": 247224,
"author": "Noah Goodrich",
"author_id": 20178,
"author_profile": "https://Stackoverflow.com/users/20178",
"pm_score": 0,
"selected": false,
"text": "<?php\n if(ini_set('error_reporting', 'ALL') === false)\n {\n // Perform failure handling logic\n }\n?>\n"
},
{
"answer_id": 247374,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "disable_functions php_admin_flag php_admin_value ini_set()"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247152",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
247,156
|
<p>I'm having a disagreement with someone over how best to implement a simple method that takes an array of integers, and returns the highest integer (using C# 2.0).</p>
<p>Below are the two implementations - I have my own opinion of which is better, and why, but I'd appreciate any impartial opinions.</p>
<p><strong>Option A</strong></p>
<pre><code>public int GetLargestValue(int[] values)
{
try {
Array.Sort(values);
return values[values.Length - 1];
}
catch (Exception){ return -1;}
}
</code></pre>
<p><strong>Option B</strong></p>
<pre><code>public int GetLargestValue(int[] values)
{
if(values == null)
return -1;
if(values.Length < 1)
return -1;
int highestValue = values[0];
foreach(int value in values)
if(value > highestValue)
highestValue = value;
return highestValue;
}
</code></pre>
|
[
{
"answer_id": 247176,
"author": "SharePoint Newbie",
"author_id": 21586,
"author_profile": "https://Stackoverflow.com/users/21586",
"pm_score": 3,
"selected": false,
"text": "O(N LogN) O(N)"
},
{
"answer_id": 247201,
"author": "JacquesB",
"author_id": 7488,
"author_profile": "https://Stackoverflow.com/users/7488",
"pm_score": 3,
"selected": false,
"text": "ArgumentException"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
247,161
|
<p>How can I transform a <code>String</code> value into an <code>InputStreamReader</code>?</p>
|
[
{
"answer_id": 247184,
"author": "Guido",
"author_id": 12388,
"author_profile": "https://Stackoverflow.com/users/12388",
"pm_score": 9,
"selected": true,
"text": "InputStream is = new ByteArrayInputStream( myString.getBytes( charset ) );\n InputStreamReader reader = new InputStreamReader(is);\n"
},
{
"answer_id": 247193,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 4,
"selected": false,
"text": "String charset = ...; // your charset\nbyte[] bytes = string.getBytes(charset);\nByteArrayInputStream bais = new ByteArrayInputStream(bytes);\nInputStreamReader isr = new InputStreamReader(bais);\n"
},
{
"answer_id": 247344,
"author": "Yossale",
"author_id": 4038,
"author_profile": "https://Stackoverflow.com/users/4038",
"pm_score": 6,
"selected": false,
"text": "IOUtils InputStreamReader isr = new InputStreamReader(IOUtils.toInputStream(myString));\n"
},
{
"answer_id": 27907431,
"author": "Fai Ng",
"author_id": 1413206,
"author_profile": "https://Stackoverflow.com/users/1413206",
"pm_score": 2,
"selected": false,
"text": "Reader InputStreamReader InputStream InputStreamReader InputStreamReader InputStream InputStreamReader InputStream Reader Reader StringReader InputStream IOUtils.toInputStream(..)"
},
{
"answer_id": 45905170,
"author": "yegor256",
"author_id": 187141,
"author_profile": "https://Stackoverflow.com/users/187141",
"pm_score": 2,
"selected": false,
"text": "InputStream stream = new InputStreamOf(str);\n Reader Reader reader = new ReaderOf(stream);\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4038/"
] |
247,167
|
<p>Looking for a bit of regex help.
I'd like to design an expression that matches a string with "<em>foo</em>" OR "<em>bar</em>", but not both "<em>foo</em>" AND "<em>bar</em>"</p>
<p>If I do something like...</p>
<pre><code>/((foo)|(bar))/
</code></pre>
<p>It'll match "<em>foobar</em>". Not what I'm looking for. So, how can I make regex match only when one term or the other is present?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 247177,
"author": "Ed Guiness",
"author_id": 4200,
"author_profile": "https://Stackoverflow.com/users/4200",
"pm_score": 4,
"selected": true,
"text": "(/foo/ and not /bar/) || (/bar/ and not /foo/)\n"
},
{
"answer_id": 247202,
"author": "Robert K",
"author_id": 24950,
"author_profile": "https://Stackoverflow.com/users/24950",
"pm_score": 0,
"selected": false,
"text": "\\b \\B \\w /\\s((foo)|(bar))\\s/\n"
},
{
"answer_id": 247227,
"author": "Can Berk Güder",
"author_id": 2119,
"author_profile": "https://Stackoverflow.com/users/2119",
"pm_score": 0,
"selected": false,
"text": "foo = re.search(\"foo\", str) != None\nbar = re.search(\"bar\", str) != None\nif foo ^ bar:\n # do someting...\n"
},
{
"answer_id": 247243,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 0,
"selected": false,
"text": "x foo y\nx bar y\nx foobar y\n g \\b(foo|bar)\\b\n"
},
{
"answer_id": 247299,
"author": "Andrew Cowenhoven",
"author_id": 12281,
"author_profile": "https://Stackoverflow.com/users/12281",
"pm_score": 0,
"selected": false,
"text": "\\b(foo)\\b|\\b(bar)\\b\n"
},
{
"answer_id": 247363,
"author": "Josh",
"author_id": 2204759,
"author_profile": "https://Stackoverflow.com/users/2204759",
"pm_score": 2,
"selected": false,
"text": "(?(?=regex)then|else)\n"
},
{
"answer_id": 247485,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 4,
"selected": false,
"text": "(?<!foo|bar)(foo|bar)(?!foo|bar)\n foo: true\nbar: true\nfoofoo: false\nbarfoo: false\nfoobarfoo: false\nbarbar: false\nbarfoofoo: false\n"
},
{
"answer_id": 247525,
"author": "bill_the_loser",
"author_id": 5239,
"author_profile": "https://Stackoverflow.com/users/5239",
"pm_score": 0,
"selected": false,
"text": "me@home ~ \n$ echo \"Where is my bar of soap?\" | egrep \"\\bfoo\\b|\\bbar\\b\" \nWhere is my bar of soap? \n\nme@home ~ \n$ echo \"What the foo happened here?\" | egrep \"\\bfoo\\b|\\bbar\\b\" \nWhat the foo happened here? \n\nme@home ~ \n$ echo \"Boy, that sure is foobar\\!\" | egrep \"\\bfoo\\b|\\bbar\\b\" \n"
},
{
"answer_id": 247585,
"author": "Dave Sherohman",
"author_id": 18914,
"author_profile": "https://Stackoverflow.com/users/18914",
"pm_score": 2,
"selected": false,
"text": "@matches = ($value =~ /(foo|bar)/g) # @matches now hold all foos or bars present\nif (scalar @matches == 1) { # exactly one match found\n ...\n}\n"
},
{
"answer_id": 247789,
"author": "cjm",
"author_id": 8355,
"author_profile": "https://Stackoverflow.com/users/8355",
"pm_score": 2,
"selected": false,
"text": "/foo/ xor /bar/\n /foo|bar/ my $matches = 0;\nwhile (/foo|bar/g) {\n last if ++$matches > 1;\n}\n\nmy $ok = ($matches == 1)\n"
},
{
"answer_id": 8361884,
"author": "Tristan",
"author_id": 1078141,
"author_profile": "https://Stackoverflow.com/users/1078141",
"pm_score": 5,
"selected": false,
"text": "/^(foo|bar){1}$/\n"
},
{
"answer_id": 25742668,
"author": "oriadam",
"author_id": 3356679,
"author_profile": "https://Stackoverflow.com/users/3356679",
"pm_score": 3,
"selected": false,
"text": "/^(foo|bar)$/\n\n^ = mark start of string (or line)\n$ = mark end of string (or line)\n /\\b(foo|bar)\\b/\n\n\\b = mark word boundry\n"
},
{
"answer_id": 31237322,
"author": "qmckinsey",
"author_id": 5030228,
"author_profile": "https://Stackoverflow.com/users/5030228",
"pm_score": 1,
"selected": false,
"text": "(/b(?:(?:(?!foo)bar)|(?:(?!bar)foo))/b)\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247167",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26001/"
] |
247,174
|
<p>I'm working on a project that contains Thomas Brothers Map page and grid numbers. Is there a way to programatically convert from this map page to a latitude & longitude?</p>
<p>An Example would be for the intersection of the US101 & I405 freeways.</p>
<p>ThomasBrothers: 561-3G (page-grid)</p>
|
[
{
"answer_id": 1371593,
"author": "chovy",
"author_id": 33522,
"author_profile": "https://Stackoverflow.com/users/33522",
"pm_score": 0,
"selected": false,
"text": "<Area>\"El Cajon\"</Area>\n<ThomasBrothers>\"1297 5E\"</ThomasBrothers>\n<TBXY>\"6481390:1827008\"</TBXY>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25007/"
] |
247,204
|
<p>We use Telerik's RadEditor for our content management system's WYSIWYG editor. We need the find & replace functionality that is in the WYSIWYG editor to also be in the HTML editor. The editor is pretty customizable, anyone know if there is a way to enable this or hack it in?</p>
|
[
{
"answer_id": 247238,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 0,
"selected": false,
"text": "... \n<telerik:EditorSeparator />\n<telerik:editortool name=\"FindAndReplace\" />\n<telerik:editortool name=\"TableWizard\" />\n<telerik:editortool name=\"LinkManager\" />\n<telerik:editortool name=\"PageProperties\" />\n<telerik:EditorSeparator />\n...\n"
},
{
"answer_id": 969946,
"author": "Sean Molam",
"author_id": 61498,
"author_profile": "https://Stackoverflow.com/users/61498",
"pm_score": 2,
"selected": true,
"text": "editor.get_html() editor.set_html()"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1208/"
] |
247,209
|
<p>As JavaScript frameworks like jQuery make client side web applications richer and more functional, I've started to notice one problem...</p>
<p><strong>How in the world do you keep this organized?</strong></p>
<ul>
<li>Put all your handlers in one spot and write functions for all the events?</li>
<li>Create function/classes to wrap all your functionality?</li>
<li>Write like crazy and just hope it works out for the best?</li>
<li>Give up and get a new career?</li>
</ul>
<p>I mention jQuery, but it's really any JavaScript code in general. I'm finding that as lines upon lines begin to pile up, it gets harder to manage the script files or find what you are looking for. Quite possibly the biggest propblems I've found is there are so many ways to do the same thing, it's hard to know which one is the current commonly accepted best practice.</p>
<p>Are there any general recommendations on the best way to keep your <strong>.js</strong> files as nice and neat as the rest of your application? Or is this just a matter of IDE? Is there a better option out there?</p>
<hr>
<p><strong>EDIT</strong></p>
<p>This question was intended to be more about code organization and not file organization. There has been some really good examples of merging files or splitting content around.</p>
<p>My question is: what is the current commonly accepted best practice way to organize your actual code? What is your way, or even a recommended way to interact with page elements and create reuseable code that doesn't conflict with each other?</p>
<p>Some people have listed <strong>namespaces</strong> which is a good idea. What are some other ways, more specifically dealing with elements on the page and keeping the code organized and neat?</p>
|
[
{
"answer_id": 247256,
"author": "Aron Rotteveel",
"author_id": 11568,
"author_profile": "https://Stackoverflow.com/users/11568",
"pm_score": 0,
"selected": false,
"text": "Behaviour.register({ \n 'a.delete-post': function(element) {\n element.observe('click', function(event) { ... });\n },\n\n 'a.anotherlink': function(element) {\n element.observe('click', function(event) { ... });\n }\n\n});\n"
},
{
"answer_id": 247406,
"author": "polarbear",
"author_id": 3636,
"author_profile": "https://Stackoverflow.com/users/3636",
"pm_score": 8,
"selected": false,
"text": "var DED = (function() {\n\n var private_var;\n\n function private_method()\n {\n // do stuff here\n }\n\n return {\n method_1 : function()\n {\n // do stuff here\n },\n method_2 : function()\n {\n // do stuff here\n }\n };\n})();\n"
},
{
"answer_id": 248951,
"author": "Damir Zekić",
"author_id": 401510,
"author_profile": "https://Stackoverflow.com/users/401510",
"pm_score": 5,
"selected": false,
"text": "require 'rake'\n\nROOT = File.expand_path(File.dirname(__FILE__))\nOUTPUT_MERGED = \"final.js\"\nOUTPUT_MINIFIED = \"final.min.js\"\n\ntask :default => :check\n\ndesc \"Merges the JavaScript sources.\"\ntask :merge do\n require File.join(ROOT, \"vendor\", \"sprockets\")\n\n environment = Sprockets::Environment.new(\".\")\n preprocessor = Sprockets::Preprocessor.new(environment)\n\n %w(main.js).each do |filename|\n pathname = environment.find(filename)\n preprocessor.require(pathname.source_file)\n end\n\n output = preprocessor.output_file\n File.open(File.join(ROOT, OUTPUT_MERGED), 'w') { |f| f.write(output) }\nend\n\ndesc \"Check the JavaScript source with JSLint.\"\ntask :check => [:merge] do\n jslint_path = File.join(ROOT, \"vendor\", \"jslint.js\")\n\n sh 'java', 'org.mozilla.javascript.tools.shell.Main',\n jslint_path, OUTPUT_MERGED\nend\n\ndesc \"Minifies the JavaScript source.\"\ntask :minify => [:merge] do\n sh 'java', 'com.yahoo.platform.yui.compressor.Bootstrap', '-v',\n OUTPUT_MERGED, '-o', OUTPUT_MINIFIED\nend\n rake merge rake check rake rake minify require (function() {\n//= require \"subdir/jsfile.js\"\n//= require \"anotherfile.js\"\n\n // some code that depends on included files\n // note that all included files can be in the same private scope\n})();\n List if (typeof org === 'undefined') {\n var org = {};\n}\n\nif (!org.hasOwnProperty('example')) {\n org.example = {};\n}\n\norg.example.AnotherObject = function () {\n // constructor body\n};\n"
},
{
"answer_id": 284700,
"author": "Jason Moore",
"author_id": 18158,
"author_profile": "https://Stackoverflow.com/users/18158",
"pm_score": 6,
"selected": false,
"text": "// file: survey.js\n$(document).ready(function() {\n var jS = $('#surveycontainer');\n var jB = $('#dimscreencontainer');\n var d = new DimScreen({container: jB});\n var s = new Survey({container: jS, DimScreen: d});\n s.show();\n});\n // file: dimscreen.js\nfunction DimScreen(opts) { \n this.jB = opts.container;\n // ...\n}; // need the semi-colon for minimizing!\n\n\nDimScreen.prototype.draw = function(msg) {\n var me = this;\n me.jB.addClass('fullscreen').append('<div>'+msg+'</div>');\n //...\n};\n"
},
{
"answer_id": 387621,
"author": "Eugene Lazutkin",
"author_id": 26394,
"author_profile": "https://Stackoverflow.com/users/26394",
"pm_score": 4,
"selected": false,
"text": "dojo.declare() dojo.require()"
},
{
"answer_id": 388666,
"author": "Danita",
"author_id": 26481,
"author_profile": "https://Stackoverflow.com/users/26481",
"pm_score": 3,
"selected": false,
"text": "vjr.Required = [\"vjr.gallery\", \"vjr.comments\", \"vjr.favorites\"];\n vjr.include(vjr.Required);\nvjr.include = function(moduleList) {\n if (!moduleList) return false;\n for (var i = 0; i < moduleList.length; i++) {\n if (moduleList[i]) {\n $.ajax({\n type: \"GET\", url: vjr.module2fileName(moduleList[i]), dataType: \"script\"\n });\n }\n }\n};\n vjr.comments = {}\n\nvjr.comments.submitComment = function() { // do stuff }\nvjr.comments.validateComment = function() { // do stuff }\n\n// Handlers\nvjr.comments.setUpUI = function() {\n // Assign handlers to screen elements\n}\n\nvjr.comments.init = function () {\n // initialize stuff\n vjr.comments.setUpUI();\n}\n\n$(document).ready(vjr.comments.init);\n"
},
{
"answer_id": 696428,
"author": "ken",
"author_id": 84473,
"author_profile": "https://Stackoverflow.com/users/84473",
"pm_score": 2,
"selected": false,
"text": "var App;\n(function()\n{\n App = new Domain( 'test' );\n\n function Domain( id )\n {\n this.id = id;\n this.echo = function echo( s )\n {\n alert( s );\n }\n return this;\n }\n})();\n\n// separate file\n(function(Domain)\n{\n Domain.Console = new Console();\n\n function Console()\n {\n this.Log = function Log( s )\n {\n console.log( s );\n }\n return this;\n }\n})(App);\n\n// implementation\nApp.Console.Log('foo');\n"
},
{
"answer_id": 756255,
"author": "Darryl",
"author_id": 87555,
"author_profile": "https://Stackoverflow.com/users/87555",
"pm_score": 3,
"selected": false,
"text": "<script src=\"jquery/1.3.2/jquery.js\" type=\"text/javascript\"></script>\n<script type=\"text/javascript\">\n\nvar AcmeJQ = jQuery.noConflict(true);\nvar Acme = {fn: function(){}};\n\n(function($){\n\n Acme.sayHi = function()\n {\n console.log('Hello');\n };\n\n Acme.sayBye = function()\n {\n console.log('Good Bye');\n };\n})(AcmeJQ);\n\n// Usage\n// Acme.sayHi();\n// or\n// <a href=\"#\" onclick=\"Acme.sayHi();\">Say Hello</a>\n\n\n</script>\n"
},
{
"answer_id": 861483,
"author": "Dmitri Farkov",
"author_id": 103647,
"author_profile": "https://Stackoverflow.com/users/103647",
"pm_score": 2,
"selected": false,
"text": "$(function(){\n //Preload header images\n $('a.rollover').preload();\n\n //Create new datagrid\n var dGrid = datagrid.init({width: 5, url: 'datalist.txt', style: 'aero'});\n});\n\nvar datagrid = {\n init: function(w, url, style){\n //Rendering code goes here for style / width\n //code etc\n\n //Fetch data in\n $.get(url, {}, function(data){\n data = data.split('\\n');\n for(var i=0; i < data.length; i++){\n //fetching data\n }\n })\n },\n refresh: function(deep){\n //more functions etc.\n }\n};\n"
},
{
"answer_id": 1175238,
"author": "Justin Johnson",
"author_id": 126562,
"author_profile": "https://Stackoverflow.com/users/126562",
"pm_score": 3,
"selected": false,
"text": "dojo.require dojo.provide dojo.declare"
},
{
"answer_id": 4179439,
"author": "gaperton",
"author_id": 507576,
"author_profile": "https://Stackoverflow.com/users/507576",
"pm_score": 2,
"selected": false,
"text": "$.include({\n html: \"my_template.html\" // include template from file...\n})\n.define( function( _ ){ // define module...\n _.exports = function widget( $this, a_data, a_events ){ // exporting function...\n _.html.renderTo( $this, a_data ); // which expands template inside of $this.\n\n $this.find( \"#ok\").click( a_events.on_click ); // throw event up to the caller...\n $this.find( \"#refresh\").click( function(){\n widget( $this, a_data, a_events ); // ...and update ourself. Yep, in that easy way.\n });\n }\n});\n"
},
{
"answer_id": 6757813,
"author": "rolnn",
"author_id": 492563,
"author_profile": "https://Stackoverflow.com/users/492563",
"pm_score": 2,
"selected": false,
"text": "$.Controller.extend('Todos',{\n \".todo mouseover\" : function( el, ev ) {\n el.css(\"backgroundColor\",\"red\")\n },\n \".todo mouseout\" : function( el, ev ) {\n el.css(\"backgroundColor\",\"\")\n },\n \".create click\" : function() {\n this.find(\"ol\").append(\"<li class='todo'>New Todo</li>\"); \n }\n})\n\nnew Todos($('#todos'));\n"
},
{
"answer_id": 7626289,
"author": "Nery Jr",
"author_id": 848937,
"author_profile": "https://Stackoverflow.com/users/848937",
"pm_score": 4,
"selected": false,
"text": "Exc = {};\n Exc = {};\nExc.ui = {};\nExc.ui.maskedInput = function (mask) {\n this.mask = mask;\n ...\n};\nExc.ui.domTips = function (dom, tips) {\n this.dom = gift;\n this.tips = tips;\n ...\n};\n Exc.ui.domTips = function (dom, tips) {\n this.dom = gift;\n this.tips = tips;\n this.internal = {\n widthEstimates: function (tips) {\n ...\n }\n formatTips: function () {\n ...\n }\n };\n ...\n};\n /**\n * Namespace <i> Example </i> created to group other namespaces of the \"Example\". \n */\nExc = {};\n/**\n * Namespace <i> ui </i> created with the aim of grouping namespaces user interface.\n */\nExc.ui = {};\n\n/**\n * Class <i> maskdInput </i> used to add an input HTML formatting capabilities and validation of data and information.\n * @ Param {String} mask - mask validation of input data.\n */\nExc.ui.maskedInput = function (mask) {\n this.mask = mask;\n ...\n};\n\n/**\n * Class <i> domTips </i> used to add an HTML element the ability to present tips and information about its function or rule input etc..\n * @ Param {String} id - id of the HTML element.\n * @ Param {String} tips - tips on the element that will appear when the mouse is over the element whose identifier is id <i> </i>.\n */\n Exc.ui.domTips = function (id, tips) {\n this.domID = id;\n this.tips = tips;\n ...\n};\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17091/"
] |
247,228
|
<p>How can I run a stored procedure from a CL program? RUNSQLSTM requires a source member, but I just want to build a command so users can pass in variables easily, so this won't work.</p>
|
[
{
"answer_id": 251921,
"author": "Paul Morgan",
"author_id": 16322,
"author_profile": "https://Stackoverflow.com/users/16322",
"pm_score": 3,
"selected": false,
"text": "QZDFMDB2 CALL PGM(QZDFMDB2) PARM('CALL PROCEDURE (''XYZ'', ''ABC'')')\n DCL VAR(&CALL) TYPE(*CHAR) LEN(200) \n\n CHGVAR VAR(&CALL) \n VALUE('CALL PROCEDURE (''' *CAT &PARM1 *TCAT ''', ''' *CAT &PARM2 *TCAT ''')')\n\n CALL PGM(QZDFMDB2) PARM(&CALL)\n"
},
{
"answer_id": 9124306,
"author": "Mitch",
"author_id": 1186823,
"author_profile": "https://Stackoverflow.com/users/1186823",
"pm_score": 0,
"selected": false,
"text": "QCMDEXC"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
247,234
|
<p>A quick search gives me <a href="http://www.tawbaware.com/wc.htm" rel="noreferrer">tawbaware wc</a>, but it does not accept stdout as input stream, meaning I can not use pipe within a <em>DOS</em> session.</p>
<p><em>Note:</em> </p>
<p>I can not install cygwin or use powershell (which would have allowed a '<code>|foreach-object {(get-content $_).count}</code>')</p>
<p><a href="http://unxutils.sourceforge.net" rel="noreferrer">unxutils</a> and and <a href="http://gnuwin32.sourceforge.net/" rel="noreferrer">gnuwin32</a> Packages might have this feature...</p>
|
[
{
"answer_id": 4354472,
"author": "Dan S.",
"author_id": 399441,
"author_profile": "https://Stackoverflow.com/users/399441",
"pm_score": 3,
"selected": false,
"text": "find /c /v \"~any string that will never occur~\"\n"
},
{
"answer_id": 4820378,
"author": "jeff drake",
"author_id": 592702,
"author_profile": "https://Stackoverflow.com/users/592702",
"pm_score": 5,
"selected": false,
"text": "find /c netstat -an | find /c \"ESTABLISHED\"\n find /c"
},
{
"answer_id": 12592540,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "set n=0\nfor /f %a in ('git log --oneline') do set /a n=n+1\n git log --online | find /v /c \"\"\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247234",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6309/"
] |
247,241
|
<p>What's the point in the standard pattern for event delegates in .net? I.e. the EventHandler predefined delegate? Why not just choose the most appropriate signature for the requirement?</p>
<p>Edit: And furthermore, is it necessary to slavishly follow Microsoft's example in all cases?</p>
|
[
{
"answer_id": 247279,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 3,
"selected": true,
"text": "sender args"
},
{
"answer_id": 247477,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "public void SaveDocument(object sender, EventArgs args)\n{\n // Save the document here\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3856/"
] |
247,245
|
<p>I have not had to mess with mailto links much. However I now need to add a link in the body of a mailto if it is possible. </p>
<p>Is there a way to add a link or to change the email opened to an html email vs a text email?</p>
<p>Something like:</p>
<pre><code><a href="mailto:test@test.test?body=The message's first paragraph.%0A%0aSecond paragraph.%0A%0AThird Paragraph.%0A%0ALink goes here">Link text goes here</a>
</code></pre>
|
[
{
"answer_id": 247395,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 8,
"selected": true,
"text": "body text/plain"
},
{
"answer_id": 247794,
"author": "scunliffe",
"author_id": 6144,
"author_profile": "https://Stackoverflow.com/users/6144",
"pm_score": 5,
"selected": false,
"text": " \"http://\"\n <http://www.example.com/foo.php?this=a&really=long&url=with&lots=and&lots=and&lots=of&prameters=on_it>\n"
},
{
"answer_id": 11830737,
"author": "chanchal1987",
"author_id": 395703,
"author_profile": "https://Stackoverflow.com/users/395703",
"pm_score": 3,
"selected": false,
"text": "<html>\n <head>\n <script type=\"text/javascript\">\n function OpenOutlookDoc(){\n try {\n\n var outlookApp = new ActiveXObject(\"Outlook.Application\");\n var nameSpace = outlookApp.getNameSpace(\"MAPI\");\n mailFolder = nameSpace.getDefaultFolder(6);\n mailItem = mailFolder.Items.add('IPM.Note.FormA');\n mailItem.Subject=\"a subject test\";\n mailItem.To = \"an@email.here\";\n mailItem.HTMLBody = \"<b>bold</b>\";\n mailItem.display (0); \n }\n catch(e){\n alert(e);\n // act on any error that you get\n }\n }\n </script>\n </head>\n <body>\n <a href=\"javascript:OpenOutlookDoc()\">Click</a>\n </body>\n</html>\n"
},
{
"answer_id": 15262608,
"author": "Mike",
"author_id": 2142622,
"author_profile": "https://Stackoverflow.com/users/2142622",
"pm_score": 1,
"selected": false,
"text": "<a href=\"mailto:me@me.com?subject=Me&body=%3Chtml%20xmlns%3D%22http:%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3C%2Fhead%3E%3Cbody%3EPlease%20%3Ca%20href%3D%22http:%2F%2Fwww.w3.org%22%3Eclick%3C%2Fa%3E%20me%3C%2Fbody%3E%3C%2Fhtml%3E\">\n"
},
{
"answer_id": 21455516,
"author": "Kamlesh",
"author_id": 3021758,
"author_profile": "https://Stackoverflow.com/users/3021758",
"pm_score": 1,
"selected": false,
"text": "<a href=\"mailto:?subject=Your mate might be interested...&body=<div style='padding: 0;'><div style='padding: 0;'><p>I found this on the site I think you might find it interesting. <a href='@(Request.Url.ToString())' >Click here </a></p></div></div>\">Share This</a>\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13341/"
] |
247,247
|
<p>It seems like there is a lot of overhead involved in rapidly opening and closing sqlconnections. Should I persist a connection (one, per client, per database), or continue declaring a new sqlconnection object whenever I need one, and making sure I clean up after myself?</p>
<p>What have you done? What worked well and what worked poorly?</p>
|
[
{
"answer_id": 247805,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 0,
"selected": false,
"text": "DbConnection conn = Database.GetConnection();\ntry\n{\n //do stuff with the connetion\n ...\n}\nfinally\n{\n Database.DisposeConnection(conn);\n}\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15769/"
] |
247,252
|
<p>One of the "best practice" is accessing data via stored procedures. I understand why is this scenario good.
My motivation is split database and application logic ( the tables can me changed, if the behaviour of stored procedures are same ), defence for SQL injection ( users can not execute "select * from some_tables", they can only call stored procedures ), and security ( in stored procedure can be "anything" which secure, that user can not select/insert/update/delete data, which is not for them ).</p>
<p>What I don't know is how to access data with dynamic filters.</p>
<p>I'm using MSSQL 2005.</p>
<p>If I have table:</p>
<pre><code>CREATE TABLE tblProduct (
ProductID uniqueidentifier -- PK
, IDProductType uniqueidentifier -- FK to another table
, ProductName nvarchar(255) -- name of product
, ProductCode nvarchar(50) -- code of product for quick search
, Weight decimal(18,4)
, Volume decimal(18,4)
)
</code></pre>
<p>then I should create 4 stored procedures ( create / read / update / delete ).</p>
<p>The stored procedure for "create" is easy.</p>
<pre><code>CREATE PROC Insert_Product ( @ProductID uniqueidentifier, @IDProductType uniqueidentifier, ... etc ... ) AS BEGIN
INSERT INTO tblProduct ( ProductID, IDProductType, ... etc .. ) VALUES ( @ProductID, @IDProductType, ... etc ... )
END
</code></pre>
<p>The stored procedure for "delete" is easy too.</p>
<pre><code>CREATE PROC Delete_Product ( @ProductID uniqueidentifier, @IDProductType uniqueidentifier, ... etc ... ) AS BEGIN
DELETE tblProduct WHERE ProductID = @ProductID AND IDProductType = @IDProductType AND ... etc ...
END
</code></pre>
<p>The stored procedure for "update" is similar as for "delete", but I'm not sure this is the right way, how to do it. I think that updating all columns is not efficient.</p>
<pre><code>CREATE PROC Update_Product( @ProductID uniqueidentifier, @Original_ProductID uniqueidentifier, @IDProductType uniqueidentifier, @Original_IDProductType uniqueidentifier, ... etc ... ) AS BEGIN
UPDATE tblProduct SET ProductID = @ProductID, IDProductType = @IDProductType, ... etc ...
WHERE ProductID = @Original_ProductID AND IDProductType = @Original_IDProductType AND ... etc ...
END
</code></pre>
<p>And the last - stored procedure for "read" is littlebit mystery for me. How pass filter values for complex conditions? I have a few suggestion:</p>
<p>Using XML parameter for passing where condition:</p>
<pre><code>CREATE PROC Read_Product ( @WhereCondition XML ) AS BEGIN
DECLARE @SELECT nvarchar(4000)
SET @SELECT = 'SELECT ProductID, IDProductType, ProductName, ProductCode, Weight, Volume FROM tblProduct'
DECLARE @WHERE nvarchar(4000)
SET @WHERE = dbo.CreateSqlWherecondition( @WhereCondition ) --dbo.CreateSqlWherecondition is some function which returns text with WHERE condition from passed XML
DECLARE @LEN_SELECT int
SET @LEN_SELECT = LEN( @SELECT )
DECLARE @LEN_WHERE int
SET @LEN_WHERE = LEN( @WHERE )
DECLARE @LEN_TOTAL int
SET @LEN_TOTAL = @LEN_SELECT + @LEN_WHERE
IF @LEN_TOTAL > 4000 BEGIN
-- RAISE SOME CONCRETE ERROR, BECAUSE DYNAMIC SQL ACCEPTS MAX 4000 chars
END
DECLARE @SQL nvarchar(4000)
SET @SQL = @SELECT + @WHERE
EXEC sp_execsql @SQL
END
</code></pre>
<p>But, I think the limitation of "4000" characters for one query is ugly.</p>
<p>The next suggestion is using filter tables for every column. Insert filter values into the filter table and then call stored procedure with ID of filters:</p>
<pre><code>CREATE TABLE tblFilter (
PKID uniqueidentifier -- PK
, IDFilter uniqueidentifier -- identification of filter
, FilterType tinyint -- 0 = ignore, 1 = equals, 2 = not equals, 3 = greater than, etc ...
, BitValue bit , TinyIntValue tinyint , SmallIntValue smallint, IntValue int
, BigIntValue bigint, DecimalValue decimal(19,4), NVarCharValue nvarchar(4000)
, GuidValue uniqueidentifier, etc ... )
CREATE TABLE Read_Product ( @Filter_ProductID uniqueidentifier, @Filter_IDProductType uniqueidentifier, @Filter_ProductName uniqueidentifier, ... etc ... ) AS BEGIN
SELECT ProductID, IDProductType, ProductName, ProductCode, Weight, Volume
FROM tblProduct
WHERE ( @Filter_ProductID IS NULL
OR ( ( ProductID IN ( SELECT GuidValue FROM tblFilter WHERE IDFilter = @Filter_ProductID AND FilterType = 1 ) AND NOT ( ProductID IN ( SELECT GuidValue FROM tblFilter WHERE IDFilter = @Filter_ProductID AND FilterType = 2 ) )
AND ( @Filter_IDProductType IS NULL
OR ( ( IDProductType IN ( SELECT GuidValue FROM tblFilter WHERE IDFilter = @Filter_IDProductType AND FilterType = 1 ) AND NOT ( IDProductType IN ( SELECT GuidValue FROM tblFilter WHERE IDFilter = @Filter_IDProductType AND FilterType = 2 ) )
AND ( @Filter_ProductName IS NULL OR ( ... etc ... ) )
END
</code></pre>
<p>But this suggestion is littlebit complicated I think.</p>
<p>Is there some "best practice" to do this type of stored procedures?</p>
|
[
{
"answer_id": 247440,
"author": "Mauro",
"author_id": 2208,
"author_profile": "https://Stackoverflow.com/users/2208",
"pm_score": 2,
"selected": false,
"text": "Create sp_ProductSelect\n(\n @ProductID int = null,\n @IDProductType int = null,\n @ProductName varchar(50) = null,\n @ProductCode varchar(10) = null,\n ...\n @Volume int = null\n)\nAS\nSELECT ProductID, IDProductType, ProductName, ProductCode, Weight, Volume FROM tblProduct' \nWhere\n ((@ProductID is null) or (ProductID = @ProductID)) AND\n ((@ProductName is null) or (ProductName = @ProductName)) AND\n ...\n ((@Volume is null) or (Volume= @Volume))\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20382/"
] |
247,257
|
<p>I am admin on a forum.
Earlier we had phpbb 2.0 and i made a bot that could write to the forum.
Now, we have upgraded the forum to phpbb 3.0, but i can't get my bot to write to the forum anymore.</p>
<p>I have looked for a solution, but now i am out of ideas.
So it would have been great if anyone have a suggestion.</p>
<p>i have btw used CURL and php to make this bot.</p>
<p>Usage of bot:
Users log in on an external website to report results of footballmatches they have played online. The bot will then automatically write a post to the forum.</p>
<p>So basically i need to know what $_POST[] i need to send.</p>
|
[
{
"answer_id": 247281,
"author": "Philip Morton",
"author_id": 21709,
"author_profile": "https://Stackoverflow.com/users/21709",
"pm_score": 2,
"selected": false,
"text": "input select"
},
{
"answer_id": 2472276,
"author": "Andrew Moore",
"author_id": 26210,
"author_profile": "https://Stackoverflow.com/users/26210",
"pm_score": 0,
"selected": false,
"text": "INSERT"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24872/"
] |
247,269
|
<p>If I invoke a method which does something illegal, the debugger will stop at the line of code, in that method, which threw the exception</p>
<p>If I use reflection to call a method via Invoke and that method throws an exception, the debugger stops on line where the method was called via reflection and not in the faulty method itself </p>
<p>How do I change this, and have the debugger stop on the line of code in error in regardless of how the method was invoked?</p>
<p>The code is built in Debug</p>
|
[
{
"answer_id": 247289,
"author": "TcKs",
"author_id": 20382,
"author_profile": "https://Stackoverflow.com/users/20382",
"pm_score": 1,
"selected": false,
"text": "public class MyClass {\n private string GetSomeText() { return DateTime.Now.ToString(); }\n}\n delegate string DlgGetSomeText();\n MyClass cls = new MyClass();\nDlgGetSomeText dlg = (DlgGetSomeText)Delegate.CreateDelegate( cls.GetType(), cls, \"GetSomeText\" );\nstring result = dlg();\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
247,284
|
<p>I have a form I am submitting using jQuery's ajaxSubmit function from the Forms plugin. I'm trying to add a form name/value pair to the form data just before submission occurs. My plan is to modify the form data in the beforeSubmit event handler.</p>
<p>Given a function that looks like:</p>
<pre><code>function handleActionFormBeforeSubmit(formData, form, options) {
// Add a name/value pair here somehow to formData
}
</code></pre>
<p>How do I add a simple pair to formData? It is an array in the form of:</p>
<pre><code>[ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
</code></pre>
<p>Thanks,
Brian</p>
|
[
{
"answer_id": 247776,
"author": "Brian Vallelunga",
"author_id": 2656,
"author_profile": "https://Stackoverflow.com/users/2656",
"pm_score": 5,
"selected": true,
"text": "function handleActionFormBeforeSubmit(formData, form, options) {\n\n // Add a name/value pair indicating this is an asynchronous call.\n // This works with the ASP.NET MVC framework's Request.IsMvcAjaxRequest() method.\n formData[formData.length] = { \"name\": \"__MVCASYNCPOST\", \"value\": \"true\" };\n}\n formData[0].value = 'new value';\n"
},
{
"answer_id": 1659333,
"author": "tony",
"author_id": 200723,
"author_profile": "https://Stackoverflow.com/users/200723",
"pm_score": 3,
"selected": false,
"text": "formData.push({ \"name\": \"__MVCASYNCPOST\", \"value\": \"true\" });\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2656/"
] |
247,304
|
<p>I'm not sure how password hashing works (will be implementing it later), but need to create database schema now.</p>
<p>I'm thinking of limiting passwords to 4-20 characters, but as I understand after encrypting hash string will be of different length.</p>
<p>So, how to store these passwords in the database?</p>
|
[
{
"answer_id": 247348,
"author": "Noah Goodrich",
"author_id": 20178,
"author_profile": "https://Stackoverflow.com/users/20178",
"pm_score": 4,
"selected": false,
"text": "CHAR SHA1"
},
{
"answer_id": 247379,
"author": "yfeldblum",
"author_id": 12349,
"author_profile": "https://Stackoverflow.com/users/12349",
"pm_score": 3,
"selected": false,
"text": "binary(n) varbinary(n)"
},
{
"answer_id": 247627,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 10,
"selected": true,
"text": "$hash = password_hash(\"rasmuslerdorf\", PASSWORD_DEFAULT);\n $2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a\n CHAR(60) UNHEX()"
},
{
"answer_id": 45314547,
"author": "bart",
"author_id": 78297,
"author_profile": "https://Stackoverflow.com/users/78297",
"pm_score": 3,
"selected": false,
"text": "TEXT"
},
{
"answer_id": 55753734,
"author": "Gilles 'SO- stop being evil'",
"author_id": 387076,
"author_profile": "https://Stackoverflow.com/users/387076",
"pm_score": 5,
"selected": false,
"text": "algorithm parameters salt output = CHAR(82) BINARY(40)"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28098/"
] |
247,305
|
<p>I am using the jQuery tableSorter plugin on a page.</p>
<p>Unfortunatley, the table that is being sorted is dynamically modified, and when I sort after adding an element, the element disappears, restoring the table to the state that it was in when the tableSorter was created.</p>
<p>Is there any way that i can force tableSorter to rescan the page so that these new elements are sorted properly?</p>
|
[
{
"answer_id": 247319,
"author": "Josh",
"author_id": 2204759,
"author_profile": "https://Stackoverflow.com/users/2204759",
"pm_score": 6,
"selected": true,
"text": "$(table).trigger(\"update\")\n"
},
{
"answer_id": 11052245,
"author": "Devaroop",
"author_id": 909297,
"author_profile": "https://Stackoverflow.com/users/909297",
"pm_score": 2,
"selected": false,
"text": "$(table).trigger(\"update\"); Uncaught TypeError: Cannot read property 'rows' of undefined \n .ajaxStop() tablesorter() .ready() jQuery(document).ajaxStop(function(){\n jQuery(\"#table_name\").tablesorter();\n })\n"
},
{
"answer_id": 42313521,
"author": "Ishwar Rimal",
"author_id": 5088262,
"author_profile": "https://Stackoverflow.com/users/5088262",
"pm_score": 2,
"selected": false,
"text": "$('#tableId').tablesorter().trigger('update');\n var tableData = \"<thead><tr><th>Name</th><th>Age</th></thead><tbody><tr><td>Izaki</td><td>24</td><tr><tr><td>Serizawa</td><td>25</td></tr>\";\n$('#tableId').html('tableData');\n$('#tableId').tablesorter().trigger('update');\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247305",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32392/"
] |
247,313
|
<p>If I had a phone number like this </p>
<pre><code>string phone = "6365555796";
</code></pre>
<p>Which I store with only numeric characters in my database <strong>(as a string)</strong>, is it possible to output the number like this: </p>
<pre><code>"636-555-5796"
</code></pre>
<p>Similar to how I could if I were using a number: </p>
<pre><code>long phone = 6365555796;
string output = phone.ToString("000-000-0000");
</code></pre>
<p>I've tried searching and all I could find online were numeric formatting documents.</p>
<p>The reason I ask is because I think it would be an interesting idea to be able to store only the numeric values in the DB and allow for different formatting using a Constant string value to dictate how my phone numbers are formatted. Or am I better off using a number for this?</p>
<p>EDIT: The question is to format a string that contains numbers, not a number itself.</p>
|
[
{
"answer_id": 247332,
"author": "Stu Mackellar",
"author_id": 28591,
"author_profile": "https://Stackoverflow.com/users/28591",
"pm_score": 1,
"selected": false,
"text": "string phoneText = \"6365555796\";\nlong phoneNum = long.Parse(phoneText);\nstring output = phoneNum.ToString(\"000-000-0000\");\n"
},
{
"answer_id": 247393,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": -1,
"selected": false,
"text": "public class PhoneDisplay\n{\n long phoneNum;\n public PhoneDisplay(long number)\n {\n phoneNum = number;\n }\n public override string ToString()\n {\n return string.Format(\"{0:###-###-####}\", phoneNum);\n }\n\n}\n PhoneDisplay MyPhone = new PhoneDisplay(6365555796);\n"
},
{
"answer_id": 247398,
"author": "AJ.",
"author_id": 7211,
"author_profile": "https://Stackoverflow.com/users/7211",
"pm_score": 2,
"selected": false,
"text": "string s = string.Format(\"{0:###-###-####}\", ulong.Parse(phone));\n"
},
{
"answer_id": 247417,
"author": "Esteban Brenes",
"author_id": 14177,
"author_profile": "https://Stackoverflow.com/users/14177",
"pm_score": 4,
"selected": true,
"text": "string number = \"1234567890\";\nstring formattedNumber = string.Format(\"{0}-{1}-{2}\", number.Substring(0,3), number.Substring(3,3), number.Substring(6));\n"
},
{
"answer_id": 247526,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 3,
"selected": false,
"text": "string phone = \"6365555796\";\nConvert.ToInt64(phone).ToString(\"000-000-0000\");\n string FormatPhone(string phone)\n{\n /*assume the phone string came from the database, so we already know it's\n only digits. If this changes in the future a simple RegEx can validate \n (or correct) the digits requirement. */\n\n // still want to check the length:\n if (phone.Length != 10) throw new InvalidArgumentException();\n\n return Convert.ToInt64(phone).ToString(\"000-000-0000\");\n}\n"
},
{
"answer_id": 247671,
"author": "Jesse C. Slicer",
"author_id": 3312,
"author_profile": "https://Stackoverflow.com/users/3312",
"pm_score": 1,
"selected": false,
"text": " /// <summary>\n /// Formats a string of nine digits into a U.S. phone number.\n /// </summary>\n /// <param name=\"value\">\n /// The string to format as a phone number.\n /// </param>\n /// <returns>\n /// The numeric string as a U.S. phone number.\n /// </returns>\n public static string\n ToUSPhone (this string value)\n {\n if (value == null)\n {\n return null;\n }\n\n long dummy;\n\n if ((value.Length != 10) ||\n !long.TryParse (\n value,\n NumberStyles.None,\n CultureInfo.CurrentCulture,\n out dummy))\n {\n return value;\n }\n\n return string.Format (\n CultureInfo.CurrentCulture,\n \"{0}-{1}-{2}\",\n value.Substring (0, 3),\n value.Substring (3, 3),\n value.Substring (6));\n }\n"
},
{
"answer_id": 248467,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 0,
"selected": false,
"text": "Regex.Replace(phone, @\"^(\\d{3})(\\d{3})(\\d{4})$\", @\"$1-$2-$3\")\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/392/"
] |
247,317
|
<p>I am trying to use MS access to connect to a Oracle database.
I keep on getting the following error message:</p>
<p>ORA-12154: TSN- could not resolve the connect identifier secified</p>
<p>The Oracle Drivers OracleClient10g can verify that the database server exists.</p>
<p>I have a section in my tsnnames.ora file that looks like this:
UBASEP10G =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = bxxx-xxx.yyyy.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = UBASE)
)
)</p>
<p>per my attempts to get this error resolves I added this to the sqlnet.ora file:</p>
<p>NAMES.DIRECTORY_PATH= (HOSTNAME, ONAMES, TNSNAMES,LDAP,EZCONNECT)</p>
<p>When using the Windows ODBC driver configuration utility it asks for the following
following information
DATA SOURCE NAME : MYSOURCE NAME
TSN SERVICE NAME:UBASEP10G
USERID:MYUSERID</p>
<p>any suggestions ?????</p>
|
[
{
"answer_id": 247459,
"author": "DCookie",
"author_id": 8670,
"author_profile": "https://Stackoverflow.com/users/8670",
"pm_score": 0,
"selected": false,
"text": "(SID_DESC =\n (GLOBAL_DBNAME = THESERVICE)\n (ORACLE_HOME = d:\\oracle\\10.2.0_DB)\n (SID_NAME = SID1)\n (SID_DESC =\n (GLOBAL_DBNAME = THESERVICE)\n (ORACLE_HOME = d:\\oracle\\10.2.0_DB)\n (SID_NAME = SID2)\n"
},
{
"answer_id": 247552,
"author": "BQ.",
"author_id": 4632,
"author_profile": "https://Stackoverflow.com/users/4632",
"pm_score": 0,
"selected": false,
"text": "select value from v$parameter where name='service_names';\n"
},
{
"answer_id": 247658,
"author": "DCookie",
"author_id": 8670,
"author_profile": "https://Stackoverflow.com/users/8670",
"pm_score": 0,
"selected": false,
"text": "Services Summary...\nService \"UBASE\" has 1 instance(s).\n Instance \"UBASE\", status READY, has 1 handler(s) for this service...\n"
},
{
"answer_id": 248231,
"author": "BQ.",
"author_id": 4632,
"author_profile": "https://Stackoverflow.com/users/4632",
"pm_score": 0,
"selected": false,
"text": "C:\\>tnsping notreal.world\n\nTNS Ping Utility for 32-bit Windows: Version 9.2.0.5.0 - Production on 29-OCT-2008 15:56:47\n\nCopyright (c) 1997 Oracle Corporation. All rights reserved.\n\nUsed parameter files:\nC:\\oracle\\ora92\\network\\admin\\sqlnet.ora\n\nTNS-03505: Failed to resolve name\n O:\\>tnsping real.world\n\nTNS Ping Utility for 32-bit Windows: Version 9.2.0.5.0 - Production on 29-OCT-2008 15:57:42\n\nCopyright (c) 1997 Oracle Corporation. All rights reserved.\n\nUsed parameter files:\n\nC:\\oracle\\ora92\\network\\admin\\sqlnet.ora\n\nUsed TNSNAMES adapter to resolve the alias\nAttempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)\n(HOST = DBSERVER.DOMAIN.COM)(PORT = 1521)) (LOAD_BALANCE = YES) (FAILOVER = YES))\n(CONNECT_DATA = (SERVICE_NAME = REAL.WORLD) \n(FAILOVER_MODE = (TYPE = SELECT) (METHOD = BASIC) (RETRIES = 10) (DELAY = 3))))\nOK (40 msec)\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26883/"
] |
247,318
|
<p>Calling addChild with an empty string as the value (or even with whitespace) seems to cause a redundant SimpleXml node to be added inside the node instead of adding just the node with no value.</p>
<p>Here's a quick demo of what happens:</p>
<pre><code>[description] => !4jh5jh1uio4jh5ij14j34io5j!
</code></pre>
<p>And here's with an empty string:</p>
<pre><code>[description] => SimpleXMLElement Object ( [0] => )
</code></pre>
<p>The workaround I'm using at the moment is pretty horrible - I'm doing a str_replace on the final JSON to replace !4jh5jh1uio4jh5ij14j34io5j! with an empty string. Yuck. Perhaps the only answer at this point is 'submit a bug report to simplexml'...</p>
<p>Does anyone have a better solution?</p>
|
[
{
"answer_id": 258352,
"author": "joelhardi",
"author_id": 11438,
"author_profile": "https://Stackoverflow.com/users/11438",
"pm_score": 1,
"selected": false,
"text": "$xml = new SimpleXMLElement('<xml></xml>');\n$xml->addChild('node','value');\nprint_r($xml);\n\n$xml = new SimpleXMLElement('<xml></xml>');\n$xml->addChild('node','');\nprint_r($xml);\n\n$xml = new SimpleXMLElement('<xml></xml>');\n$xml->addChild('node');\nprint_r($xml);\n SimpleXMLElement Object\n(\n [node] => value\n)\nSimpleXMLElement Object\n(\n [node] => SimpleXMLElement Object\n (\n [0] => \n )\n\n)\nSimpleXMLElement Object\n(\n [node] => SimpleXMLElement Object\n (\n )\n\n)\n $mystery_string = '';\n\n$xml = new SimpleXMLElement('<xml></xml>');\nif (preg_match('#\\S#', $mystery_string)) // Checks for non-whitespace character\n $xml->addChild('node', $mystery_string);\nelse\n $xml->addChild('node');\n\nprint_r($xml);\necho \"\\nOr in JSON:\\n\";\necho json_encode($xml);\n SimpleXMLElement Object\n(\n [node] => SimpleXMLElement Object\n (\n )\n\n)\n\nOr in JSON:\n{\"node\":{}}\n"
},
{
"answer_id": 408622,
"author": "null",
"author_id": 25411,
"author_profile": "https://Stackoverflow.com/users/25411",
"pm_score": 0,
"selected": false,
"text": "$xml = new bXml('<xml></xml>');\n$xml->addChild('node', '');\n$json_w_root = $xml->asJson(); // is { 'xml': {'node':'' } }\n$json = $xml->children()->asJson(); // is { 'node' : '' } as expected.\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247318",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32300/"
] |
247,329
|
<p>Unfortunately on my project, we generate a lot of the HTML code in JavaScript like this:</p>
<pre><code>var html = new StringBuffer();
html.append("<td class=\"gr-my-deals\"><a href=\"").append(deal.url).append("\" target=\"_blank\">").append(deal.description).append("</a></td>");
</code></pre>
<p>I have 2 specific complaints about this:</p>
<ol>
<li>The use of escaped double quotes (\”) within the HTML string. These should be replaced by single quotes (‘) to improve readability.</li>
<li>The use of .append() instead of the JavaScript string concatentation operator “+”</li>
</ol>
<p>Applying both of these suggestions, produces the following equivalent line of code, which I consider to be much more readable:</p>
<pre><code>var html = "<td class=’gr-my-deals’><a href=’" + deal.url + "’ target=’_blank’>" + deal.description + "</a></td>";
</code></pre>
<p>I'm now looking for a way to automatically transform the first line of code into the second. All I've come up with so far is to run the following find and replace over all our Javascript code:</p>
<pre><code>Find: ).append(
Replace: +
</code></pre>
<p>This will convert the line of code shown above to:</p>
<pre><code>html.append("<td class=\"gr-my-deals\"><a href=\"" + deal.url + "\" target=\"_blank\">" + deal.description + "</a></td>)";
</code></pre>
<p>This should safely remove all but the first 'append()' statement. Unfortunately, I can't think of any safe way to automatically convert the escaped double-quotes to single quotes. Bear in mind that I can't simply do a find/replace because in some cases you actually do need to use escaped double-quotes. Typically, this is when you're generating HTML that includes nested JS, and that JS contains string parameters, e.g.</p>
<pre><code>function makeLink(stringParam) {
var sb = new StringBuffer();
sb.append("<a href=\"JavaScript:myFunc('" + stringParam + "');\">");
}
</code></pre>
<p>My questions (finally) are:</p>
<ul>
<li>Is there a better way to safely replace the calls to 'append()' with '+'</li>
<li>Is there any way to safely replace the escaped double quotes with single quotes, regex?</li>
</ul>
<p>Cheers,
Don</p>
|
[
{
"answer_id": 247383,
"author": "rp.",
"author_id": 2536,
"author_profile": "https://Stackoverflow.com/users/2536",
"pm_score": 2,
"selected": false,
"text": "function stringFormat( str ) {\n\n for( i = 0; i < arguments.length; i++ ) {\n var r = new RegExp( '\\\\{' + ( i ) + '\\\\}','gm' );\n\n str = str.replace( r, arguments[ i + 1 ] ); \n }\n return str;\n}\n var htmlMask = \"<td class=’gr-my-deals’><a href=’{0}’ target=’_blank’>{1}</a></td>\";\n\nvar x = stringFormat( htmlMask, deal.Url, deal.description ); \n"
},
{
"answer_id": 248132,
"author": "Andrew Hedges",
"author_id": 11577,
"author_profile": "https://Stackoverflow.com/users/11577",
"pm_score": 1,
"selected": false,
"text": "var tmpl, vals, html;\n\ntmpl = '<td class=\"gr-my-deals\">';\ntmpl += '<a href=\"#{href}\">#{text}</a>';\ntmpl += '</td>';\n\nvals = {\n href : 'http://example.com/example',\n text : 'Click me!'\n};\n\nhtml = $.tmpl(tmpl, vals);\n"
},
{
"answer_id": 4559123,
"author": "Michael Lorton",
"author_id": 238884,
"author_profile": "https://Stackoverflow.com/users/238884",
"pm_score": 0,
"selected": false,
"text": "TD({ \"class\" : \"gr-my-deals\" },\n A({ href : deal.url,\n target : \"_blank\"},\n deal.description ))\n class"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247329",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2648/"
] |
247,331
|
<p>I'm using jQuery validate on a form I am building and it is working great. What I want to do is when something is invalid to have the text field change colors and the error message to be white. I figured the following CSS would work:</p>
<pre><code>label .error {color: white; font-weight: bold;}
input .error {background-color: pink; border: 1px dashed red; color: white}
</code></pre>
<p>When I test the validation the above CSS doesn't seem to apply. I checked using Firebug and the label and input area have the 'error' class applied.</p>
<p>The CSS seems valid as when I leave off the .error clause everything looks like I want it too. What am I doing wrong?</p>
|
[
{
"answer_id": 247343,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 5,
"selected": true,
"text": "label.error {color: white; font-weight: bold;}\ninput.error {background-color: pink; border: 1px dashed red; color: white}\n label .error /* selects all elements of class \"error\" *within* any label */\nlabel.error /* selects labels of class \"error\" */\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/204/"
] |
247,350
|
<p>There's a lot of questions on here regarding various niche build needs (.NET, continuous integration, etc) but, of course, my niche need is different.</p>
<p>Rather than asking a very specific question right now, I'd like a survey of available build tools (such as make, ant, etc) so I can ask a follow up question more intelligently if needed.</p>
<p>In your answer, please include:</p>
<ul>
<li><strong>ONE</strong> build tool</li>
<li>Link to the main page about that tool</li>
<li>If you know some pros and cons (ie, runs on windows with cygwin, or .NET specific, etc) then list some (not required - the name and link are required)</li>
</ul>
<p>If your build tool is already in an answer, comment on it adding pros/cons/limitations/experiences. Feel free to add as many answers as you like as long as they don't already exist - but don't put several build tools into one answer.</p>
<p>Please be aware that if you duplicate answers you may be downvoted - add additional information about a given build in the comments. Ideally these comments will be incorporated into the answer over time.</p>
<p>-Adam</p>
|
[
{
"answer_id": 790667,
"author": "Will Robertson",
"author_id": 4161,
"author_profile": "https://Stackoverflow.com/users/4161",
"pm_score": 2,
"selected": false,
"text": ":-)"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247350",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2915/"
] |
247,369
|
<p>I am attempting to allow my web designers to use the metadata we have about database fields in the asp.net pages they are creating. The most obvious one is as follows:</p>
<pre><code><asp:TextBox runat="server" id="txTextBox" MaxLength="<Value From Metadata here>" ... />
</code></pre>
<p>All the required metadata is stored in our class objects and is accessible due to its public static nature.</p>
<p>The benefit of this would be that they can set values which</p>
<p><strong>a)</strong> might change without them being aware or caring<br>
<strong>b)</strong> improve the user experience with very little coding effort</p>
<p>and all without having them need worry about what the value is or where it has come from. This will primarily be used for automatically bound controls - i.e. ones which are added with little or no developer interaction. </p>
<p>This question is very similar to <a href="https://stackoverflow.com/questions/232986/xaml-binding-textbox-maxlength-to-class-constant">One of my previous questions</a> which now works wonderfully (but that was in WPF / XAML ).</p>
<p>The main point of this question is that I want as little developer requirement on this as possible - Ideally there would be some <code><%# Constant.Value %></code> type syntax which could be used directly within the <code>Maxlength=""</code> attribute of the asp:Textbox control meaning that no code needs to be added to a page/usercontrol at all.</p>
<p>I have a feeling it isn't possible, but I would love someone to prove me wrong.</p>
<p>Ta</p>
|
[
{
"answer_id": 247390,
"author": "Marcus King",
"author_id": 19840,
"author_profile": "https://Stackoverflow.com/users/19840",
"pm_score": 0,
"selected": false,
"text": "<asp:TextBox runat=\"server\" id=\"txTextBox\" MaxLength=\"<%=Constants.SomeValue%>\" />\n"
},
{
"answer_id": 247502,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 2,
"selected": true,
"text": "<asp:TextBox MaxLength=\"<%# Constant.Value %>\" />\n <asp:TextBox MaxLength=\"<%$ Constants:Value %>\" />\n using System;\nusing System.Web.UI;\nusing System.Web.Compilation;\nusing System.CodeDom;\nusing System.Collections.Generic;\n\nclass ConstantsExpressionBuilder : ExpressionBuilder {\n private static readonly Dictionary<string, object> Values = \n new Dictionary<string, object>() {\n { \"Value1\", 12 },\n { \"Value2\", false },\n { \"Value3\", \"this is a test\" }\n };\n\n public override bool SupportsEvaluate { get { return true; } }\n\n public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) {\n string key = entry.Expression.Trim();\n return GetValue(key);\n }\n\n public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) {\n CodePrimitiveExpression keyExpression = new CodePrimitiveExpression(entry.Expression.Trim());\n return new CodeMethodInvokeExpression(this.GetType(), \"GetValue\", new CodeExpression[] { keyExpression }); \n }\n\n public static object GetValue(string key) {\n return Values[key];\n }\n}\n <system.web>\n <compilation>\n <expressionBuilders>\n <add expressionPrefix=\"Constants\" type=\"ConstantsExpressionBuilder\" />\n </expressionBuilders>\n </compilation>\n</system.web>\n <asp:Textbox runat=\"server\" MaxLength=\"<%$ Constants:Value1 %>\" ReadOnly=\"<%$ Constants:Value2 %>\" Text=\"<%$ Constants:Value3 %>\" />\n <input type=\"text\" maxlength=\"12\" readonly=\"false\" value=\"this is a test\" />\n"
}
] |
2008/10/29
|
[
"https://Stackoverflow.com/questions/247369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31128/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.