qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
---|---|---|---|---|
69,440 |
<p>I'm wondering if there's any way to write CSS specifically for Safari using only CSS. I know there has to be something out there, but I haven't found it yet.</p>
|
[
{
"answer_id": 70827,
"author": "Rich Adams",
"author_id": 10018,
"author_profile": "https://Stackoverflow.com/users/10018",
"pm_score": 3,
"selected": false,
"text": ".blah { color: #fff; }\n.blah { color: #000;# }\n"
},
{
"answer_id": 71750,
"author": "Bryan M.",
"author_id": 4636,
"author_profile": "https://Stackoverflow.com/users/4636",
"pm_score": 6,
"selected": true,
"text": "@media screen and (-webkit-min-device-pixel-ratio:0) {\n /* Safari 3.0 and Opera 9 rules here */\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69440",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8970/"
] |
69,445 |
<p>I'm using the After Effects CS3 Javascript API to dynamically create and change text layers in a composition.</p>
<p>Or at least I'm trying to because I can't seem to find the right property to change to alter the actual text of the TextLayer object.</p>
|
[
{
"answer_id": 73071,
"author": "Gareth Simpson",
"author_id": 147,
"author_profile": "https://Stackoverflow.com/users/147",
"pm_score": 3,
"selected": true,
"text": "var theComposition = app.project.item(1);\nvar theTextLayer = theComposition.layers[1];\ntheTextLayer.property(\"Source Text\").setValue(\"This text is from code\");\n"
},
{
"answer_id": 28845462,
"author": "Chris",
"author_id": 5073,
"author_profile": "https://Stackoverflow.com/users/5073",
"pm_score": 1,
"selected": false,
"text": "var comp = app.project.item(23);\nvar layer = comp.layer('some_layer_name');\nvar textProp = layer.property(\"Source Text\");\nvar textDocument = textProp.value;\n\ntextDocument.text = \"This is the new text\";\ntextProp.setValue(textDocument);"
},
{
"answer_id": 59913842,
"author": "Myzel394",
"author_id": 9878135,
"author_profile": "https://Stackoverflow.com/users/9878135",
"pm_score": 0,
"selected": false,
"text": "function change_prop(prop, name, value){\n var doc = prop.value;\n\n doc[name] = value;\n prop.setValue(doc);\n\n return prop;\n}\n // Changing source text\nchange_prop(text_layer.property(\"Source Text\"), \"text\", \"That's the source text\");\n\n// Changing font size\nchange_prop(text_layer.property(\"ADBE Text Properties\").property(\"ADBE Text Document\"), \"fontSize\", 10)\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69445",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/147/"
] |
69,448 |
<p>I am using VS2008 and Resharper. Resharper creates a directory _Resharper.ProjectName. These files provide no value for source control that I am aware of and cause issues when committing changes. How can I get SVN to ignore them? I am using TortoiseSVN as my interface for SVN.</p>
<p>EDIT: You guys are fast.</p>
|
[
{
"answer_id": 69461,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 4,
"selected": false,
"text": "_Resharper.* svn:ignore"
},
{
"answer_id": 69472,
"author": "user11087",
"author_id": 11087,
"author_profile": "https://Stackoverflow.com/users/11087",
"pm_score": 2,
"selected": false,
"text": "# cd /your/working/copy\n# export EDITOR=vi\n# svn propedit svn:ignore .\n"
},
{
"answer_id": 69483,
"author": "JasonS",
"author_id": 1865,
"author_profile": "https://Stackoverflow.com/users/1865",
"pm_score": 3,
"selected": false,
"text": "*ReSharper*\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69448",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1865/"
] |
69,480 |
<p>I have a script that renders graphs in gnuplot. The graphs all end up with an ugly white background. How do I change this? (Ideally, with a command that goes into a gnuplot script, as opposed to a command-line option or something in a settings file)</p>
|
[
{
"answer_id": 69512,
"author": "raldi",
"author_id": 7598,
"author_profile": "https://Stackoverflow.com/users/7598",
"pm_score": 4,
"selected": true,
"text": "set terminal png x222222 xffffff\n"
},
{
"answer_id": 7334137,
"author": "hsxz",
"author_id": 932735,
"author_profile": "https://Stackoverflow.com/users/932735",
"pm_score": 5,
"selected": false,
"text": "set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb\"green\" behind"
},
{
"answer_id": 64352284,
"author": "Marco Righele",
"author_id": 162945,
"author_profile": "https://Stackoverflow.com/users/162945",
"pm_score": 1,
"selected": false,
"text": "set term wxt background rgb \"gray75\"\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7598/"
] |
69,497 |
<p>I'm sick and tired of manually tracking my branches and merges across my repository! It's too error prone. In a world where everyone seems to get the idea of reducing duplication and automating everything, subversion branching/merging feels like it's left over from the 80's. What is a good alternative to subversion that has excellent branching and merging support without adding the complexity of a distributed SCM paradigm? Ideally it would be free, but if I have to shell out some cash I might be inclined if it's good enough.</p>
|
[
{
"answer_id": 60791348,
"author": "bahrep",
"author_id": 761095,
"author_profile": "https://Stackoverflow.com/users/761095",
"pm_score": 0,
"selected": false,
"text": "svn:mergeinfo"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10945/"
] |
69,539 |
<p>I am curious if anyone have used UnderC, Cint, Cling, Ch, or any other C++ interpreter and could share their experience.</p>
|
[
{
"answer_id": 9446693,
"author": "Shep",
"author_id": 915501,
"author_profile": "https://Stackoverflow.com/users/915501",
"pm_score": 5,
"selected": false,
"text": "if (energy > 30) { \n float correction = 2.4;\n}\nelse {\n float correction = 6.3;\n}\n\nsomevalue += correction; \n correcton"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69539",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9706/"
] |
69,546 |
<p>I have a multi-frame layout. One of the frames contains a form, which I am submitting through XMLHttpRequest. Now when I use document.write() to rewrite the frame with the form, and the new page I am adding contains any javascript then the javascript is not exectuted in IE6?</p>
<p>For example:</p>
<pre><code>document.write("<html><head><script>alert(1);</script></head><body>test</body></html>");
</code></pre>
<p>In the above case the page content is replaced with test but the alert() isn't executed. This works fine in Firefox.</p>
<p>What is a workaround to the above problem? </p>
|
[
{
"answer_id": 69655,
"author": "dimarzionist",
"author_id": 10778,
"author_profile": "https://Stackoverflow.com/users/10778",
"pm_score": 1,
"selected": false,
"text": "<script>"
},
{
"answer_id": 159840,
"author": "Ates Goral",
"author_id": 23501,
"author_profile": "https://Stackoverflow.com/users/23501",
"pm_score": 1,
"selected": false,
"text": "doIt window.parent.rewriteFormFrame(theHtml);\n rewriteFormFrame function rewriteFormFrame(html) {\n formFrame.document.body.innerHTML = html;\n formFrame.doIt();\n}\n"
},
{
"answer_id": 1575755,
"author": "Ollie Saunders",
"author_id": 113019,
"author_profile": "https://Stackoverflow.com/users/113019",
"pm_score": 0,
"selected": false,
"text": "<body onload=\"jsWrittenLoaded()\">"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
69,561 |
<p>gnuplot is giving the error: "sh: kpsexpand: not found." </p>
<p>I feel like the guy in Office Space when he saw "PC LOAD LETTER". What the heck is kpsexpand?</p>
<p>I searched Google, and there were a lot of pages that make reference to kpsexpand, and say not to worry about it, but I can't find anything, anywhere that actually explains <em>what it is.</em></p>
<p>Even the man page stinks:</p>
<pre><code>$ man kpsexpand
kpsetool - script to make teTeX-style kpsetool, kpsexpand, and kpsepath available
</code></pre>
<p>Edit: Again, I'm not asking what to do -- I know what to do, thanks to Google. What I'm wondering is what the darn thing <em>is.</em></p>
|
[
{
"answer_id": 2538565,
"author": "Born2Smile",
"author_id": 250287,
"author_profile": "https://Stackoverflow.com/users/250287",
"pm_score": 2,
"selected": false,
"text": "$ kpsexpand $VAR1 Hello World $ kpsexpand $VAR2 kpsewhich which which progname kpsewhich filename less `which kpsexpand`"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7598/"
] |
69,591 |
<p>I want to create a regexp in Emacs that matches exactly 3 digits. For example, I want to match the following:</p>
<pre><code>123
345
789
</code></pre>
<p>But not</p>
<pre><code>1234
12
12 23
</code></pre>
<p>If I use <code>[0-9]+</code> I match any single string of digits. I thought <code>[0-9]{3}</code> would work, but when tested in re-builder it doesn't match anything.</p>
|
[
{
"answer_id": 69593,
"author": "mike511",
"author_id": 9593,
"author_profile": "https://Stackoverflow.com/users/9593",
"pm_score": -1,
"selected": false,
"text": "[0-9][0-9][0-9]\n"
},
{
"answer_id": 69615,
"author": "Joe Hildebrand",
"author_id": 8388,
"author_profile": "https://Stackoverflow.com/users/8388",
"pm_score": 7,
"selected": true,
"text": "{3} \\b \\b[0-9]\\{3\\}\\b\n \\b \\bfoo\\b foo \\bballs?\\b ball balls \\b (highlight-regexp \"\\\\b[0-9]\\\\{3\\\\}\\\\b\")\n"
},
{
"answer_id": 69622,
"author": "SCdF",
"author_id": 1666,
"author_profile": "https://Stackoverflow.com/users/1666",
"pm_score": 3,
"selected": false,
"text": "[0-9][0-9][0-9] [0-9]{3} \\d{3} ^/[0-9]{3}/$ \\w+[0-9]{3}\\w+"
},
{
"answer_id": 69636,
"author": "Lukas Šalkauskas",
"author_id": 5369,
"author_profile": "https://Stackoverflow.com/users/5369",
"pm_score": 2,
"selected": false,
"text": "\"^\\d{3}$\"\n"
},
{
"answer_id": 69644,
"author": "Antti Rasinen",
"author_id": 8570,
"author_profile": "https://Stackoverflow.com/users/8570",
"pm_score": 2,
"selected": false,
"text": "(^|\\D)\\d{3}(\\D|$)\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6180/"
] |
69,627 |
<p>I am looking for a simple unpatented one-way encryption algorithm, preferably in c.
I would like to use it to validate passwords.</p>
|
[
{
"answer_id": 69639,
"author": "Jeremy",
"author_id": 1114,
"author_profile": "https://Stackoverflow.com/users/1114",
"pm_score": 5,
"selected": true,
"text": ":-)"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69627",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3740/"
] |
69,637 |
<p>I am serializing a <code>JPEG</code> Image in <code>c#.net</code>. I am simply converting it into a byte steam and sending it through web service. </p>
<p>I observed that serialized byte stream is 30 times more than that of the size of actual image. Can any one <strong>suggest me a better approach</strong> to serialize and stay relative to the size of the actual image? </p>
|
[
{
"answer_id": 69709,
"author": "Ash",
"author_id": 11194,
"author_profile": "https://Stackoverflow.com/users/11194",
"pm_score": -1,
"selected": false,
"text": "byte[] arr = File.ReadAllBytes(filename);\nstring str = Convert.ToBase64String(arr);\n byte[] arr = Convert.FromBase64String(string);\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
69,645 |
<p>I want to take a screenshot via a python script and unobtrusively save it.</p>
<p>I'm only interested in the Linux solution, and should support any X based environment.</p>
|
[
{
"answer_id": 70237,
"author": "Slava V",
"author_id": 37141,
"author_profile": "https://Stackoverflow.com/users/37141",
"pm_score": 3,
"selected": false,
"text": "import ImageGrab\nimg = ImageGrab.grab()\nimg.save('test.jpg','JPEG')\n"
},
{
"answer_id": 769221,
"author": "Juliano",
"author_id": 55078,
"author_profile": "https://Stackoverflow.com/users/55078",
"pm_score": 4,
"selected": false,
"text": "import sys\nfrom PyQt4.QtGui import QPixmap, QApplication\napp = QApplication(sys.argv)\nQPixmap.grabWindow(QApplication.desktop().winId()).save('test.png', 'png')\n"
},
{
"answer_id": 782768,
"author": "Rusty",
"author_id": 95083,
"author_profile": "https://Stackoverflow.com/users/95083",
"pm_score": 7,
"selected": true,
"text": "import gtk.gdk\n\nw = gtk.gdk.get_default_root_window()\nsz = w.get_size()\nprint \"The size of the window is %d x %d\" % sz\npb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])\npb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])\nif (pb != None):\n pb.save(\"screenshot.png\",\"png\")\n print \"Screenshot saved to screenshot.png.\"\nelse:\n print \"Unable to get the screenshot.\"\n"
},
{
"answer_id": 6380186,
"author": "Snowball",
"author_id": 802490,
"author_profile": "https://Stackoverflow.com/users/802490",
"pm_score": 3,
"selected": false,
"text": "import wx\nwx.App() # Need to create an App instance before doing anything\nscreen = wx.ScreenDC()\nsize = screen.GetSize()\nbmp = wx.EmptyBitmap(size[0], size[1])\nmem = wx.MemoryDC(bmp)\nmem.Blit(0, 0, size[0], size[1], screen, 0, 0)\ndel mem # Release bitmap\nbmp.SaveFile('screenshot.png', wx.BITMAP_TYPE_PNG)\n"
},
{
"answer_id": 7711106,
"author": "Alex Raeder",
"author_id": 244382,
"author_profile": "https://Stackoverflow.com/users/244382",
"pm_score": 6,
"selected": false,
"text": "#!/usr/bin/env python\n# encoding: utf-8\n\"\"\"\nscreengrab.py\n\nCreated by Alex Snet on 2011-10-10.\nCopyright (c) 2011 CodeTeam. All rights reserved.\n\"\"\"\n\nimport sys\nimport os\n\nimport Image\n\n\nclass screengrab:\n def __init__(self):\n try:\n import gtk\n except ImportError:\n pass\n else:\n self.screen = self.getScreenByGtk\n\n try:\n import PyQt4\n except ImportError:\n pass\n else:\n self.screen = self.getScreenByQt\n\n try:\n import wx\n except ImportError:\n pass\n else:\n self.screen = self.getScreenByWx\n\n try:\n import ImageGrab\n except ImportError:\n pass\n else:\n self.screen = self.getScreenByPIL\n\n\n def getScreenByGtk(self):\n import gtk.gdk \n w = gtk.gdk.get_default_root_window()\n sz = w.get_size()\n pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])\n pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])\n if pb is None:\n return False\n else:\n width,height = pb.get_width(),pb.get_height()\n return Image.fromstring(\"RGB\",(width,height),pb.get_pixels() )\n\n def getScreenByQt(self):\n from PyQt4.QtGui import QPixmap, QApplication\n from PyQt4.Qt import QBuffer, QIODevice\n import StringIO\n app = QApplication(sys.argv)\n buffer = QBuffer()\n buffer.open(QIODevice.ReadWrite)\n QPixmap.grabWindow(QApplication.desktop().winId()).save(buffer, 'png')\n strio = StringIO.StringIO()\n strio.write(buffer.data())\n buffer.close()\n del app\n strio.seek(0)\n return Image.open(strio)\n\n def getScreenByPIL(self):\n import ImageGrab\n img = ImageGrab.grab()\n return img\n\n def getScreenByWx(self):\n import wx\n wx.App() # Need to create an App instance before doing anything\n screen = wx.ScreenDC()\n size = screen.GetSize()\n bmp = wx.EmptyBitmap(size[0], size[1])\n mem = wx.MemoryDC(bmp)\n mem.Blit(0, 0, size[0], size[1], screen, 0, 0)\n del mem # Release bitmap\n #bmp.SaveFile('screenshot.png', wx.BITMAP_TYPE_PNG)\n myWxImage = wx.ImageFromBitmap( myBitmap )\n PilImage = Image.new( 'RGB', (myWxImage.GetWidth(), myWxImage.GetHeight()) )\n PilImage.fromstring( myWxImage.GetData() )\n return PilImage\n\nif __name__ == '__main__':\n s = screengrab()\n screen = s.screen()\n screen.show()\n"
},
{
"answer_id": 7817506,
"author": "ponty",
"author_id": 700820,
"author_profile": "https://Stackoverflow.com/users/700820",
"pm_score": 4,
"selected": false,
"text": "easy_install pyscreenshot\n import pyscreenshot as ImageGrab\n\n# fullscreen\nim=ImageGrab.grab()\nim.show()\n\n# part of the screen\nim=ImageGrab.grab(bbox=(10,10,500,500))\nim.show()\n\n# to file\nImageGrab.grab_to_file('im.png')\n"
},
{
"answer_id": 16141058,
"author": "b0bz",
"author_id": 1149259,
"author_profile": "https://Stackoverflow.com/users/1149259",
"pm_score": 6,
"selected": false,
"text": "from Xlib import display, X\nimport Image #PIL\n\nW,H = 200,200\ndsp = display.Display()\ntry:\n root = dsp.screen().root\n raw = root.get_image(0, 0, W,H, X.ZPixmap, 0xffffffff)\n image = Image.fromstring(\"RGB\", (W, H), raw.data, \"raw\", \"BGRX\")\n image.show()\nfinally:\n dsp.close()\n #include <stdio.h>\n#include <X11/X.h>\n#include <X11/Xlib.h>\n//Compile hint: gcc -shared -O3 -lX11 -fPIC -Wl,-soname,prtscn -o prtscn.so prtscn.c\n\nvoid getScreen(const int, const int, const int, const int, unsigned char *);\nvoid getScreen(const int xx,const int yy,const int W, const int H, /*out*/ unsigned char * data) \n{\n Display *display = XOpenDisplay(NULL);\n Window root = DefaultRootWindow(display);\n\n XImage *image = XGetImage(display,root, xx,yy, W,H, AllPlanes, ZPixmap);\n\n unsigned long red_mask = image->red_mask;\n unsigned long green_mask = image->green_mask;\n unsigned long blue_mask = image->blue_mask;\n int x, y;\n int ii = 0;\n for (y = 0; y < H; y++) {\n for (x = 0; x < W; x++) {\n unsigned long pixel = XGetPixel(image,x,y);\n unsigned char blue = (pixel & blue_mask);\n unsigned char green = (pixel & green_mask) >> 8;\n unsigned char red = (pixel & red_mask) >> 16;\n\n data[ii + 2] = blue;\n data[ii + 1] = green;\n data[ii + 0] = red;\n ii += 3;\n }\n }\n XDestroyImage(image);\n XDestroyWindow(display, root);\n XCloseDisplay(display);\n}\n import ctypes\nimport os\nfrom PIL import Image\n\nLibName = 'prtscn.so'\nAbsLibPath = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + LibName\ngrab = ctypes.CDLL(AbsLibPath)\n\ndef grab_screen(x1,y1,x2,y2):\n w, h = x2-x1, y2-y1\n size = w * h\n objlength = size * 3\n\n grab.getScreen.argtypes = []\n result = (ctypes.c_ubyte*objlength)()\n\n grab.getScreen(x1,y1, w, h, result)\n return Image.frombuffer('RGB', (w, h), result, 'raw', 'RGB', 0, 1)\n \nif __name__ == '__main__':\n im = grab_screen(0,0,1440,900)\n im.show()\n"
},
{
"answer_id": 20219666,
"author": "Anand",
"author_id": 2659276,
"author_profile": "https://Stackoverflow.com/users/2659276",
"pm_score": -1,
"selected": false,
"text": "#!/usr/bin/python\n\nimport gtk.gdk\nimport time\nimport random\nimport socket\nimport fcntl\nimport struct\nimport getpass\nimport os\nimport paramiko \n\nwhile 1:\n # generate a random time between 120 and 300 sec\n random_time = random.randrange(20,25)\n # wait between 120 and 300 seconds (or between 2 and 5 minutes) \n\n print \"Next picture in: %.2f minutes\" % (float(random_time) / 60)\n\n time.sleep(random_time)\n w = gtk.gdk.get_default_root_window() \n sz = w.get_size()\n print \"The size of the window is %d x %d\" % sz\n pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])\n pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])\n ts = time.asctime( time.localtime(time.time()) )\n date = time.strftime(\"%d-%m-%Y\")\n timer = time.strftime(\"%I:%M:%S%p\")\n filename = timer\n filename += \".png\"\n\n if (pb != None):\n username = getpass.getuser() #Get username\n newpath = r'screenshots/'+username+'/'+date #screenshot save path\n if not os.path.exists(newpath): os.makedirs(newpath)\n saveas = os.path.join(newpath,filename)\n print saveas\n pb.save(saveas,\"png\")\n else:\n print \"Unable to get the screenshot.\"\n"
},
{
"answer_id": 25805492,
"author": "rominf",
"author_id": 2108548,
"author_profile": "https://Stackoverflow.com/users/2108548",
"pm_score": 0,
"selected": false,
"text": "from PyQt5.QtWidgets import QApplication\napp = QApplication([])\nscreen = app.primaryScreen()\nscreenshot = screen.grabWindow(QApplication.desktop().winId())\nscreenshot.save('/tmp/screenshot.png')\n"
},
{
"answer_id": 29136548,
"author": "anderstood",
"author_id": 1555099,
"author_profile": "https://Stackoverflow.com/users/1555099",
"pm_score": 1,
"selected": false,
"text": " import os\n os.system(\"import -window root temp.png\")\n"
},
{
"answer_id": 30503686,
"author": "pkm",
"author_id": 2490439,
"author_profile": "https://Stackoverflow.com/users/2490439",
"pm_score": 2,
"selected": false,
"text": "import autopy\nimport time\ntime.sleep(2)\nb = autopy.bitmap.capture_screen()\nb.save(\"C:/Users/mak/Desktop/m.png\")\n"
},
{
"answer_id": 45579657,
"author": "cyera",
"author_id": 8436827,
"author_profile": "https://Stackoverflow.com/users/8436827",
"pm_score": 2,
"selected": false,
"text": "pyscreenshot python demo.py import os\nos.system(\"gnome-screenshot --file=this_directory.png\")\n gnome-screenshot --help Application Options:\n -c, --clipboard Send the grab directly to the clipboard\n -w, --window Grab a window instead of the entire screen\n -a, --area Grab an area of the screen instead of the entire screen\n -b, --include-border Include the window border with the screenshot\n -B, --remove-border Remove the window border from the screenshot\n -p, --include-pointer Include the pointer with the screenshot\n -d, --delay=seconds Take screenshot after specified delay [in seconds]\n -e, --border-effect=effect Effect to add to the border (shadow, border, vintage or none)\n -i, --interactive Interactively set options\n -f, --file=filename Save screenshot directly to this file\n --version Print version information and exit\n --display=DISPLAY X display to use\n"
},
{
"answer_id": 52549704,
"author": "Jack Sparrow",
"author_id": 3293019,
"author_profile": "https://Stackoverflow.com/users/3293019",
"pm_score": 3,
"selected": false,
"text": "import os\nos.system(\"import -window root screen_shot.png\")\n"
},
{
"answer_id": 64236518,
"author": "Matheus K.",
"author_id": 14391919,
"author_profile": "https://Stackoverflow.com/users/14391919",
"pm_score": 2,
"selected": false,
"text": "import gi\ngi.require_version('Gtk', '3.0')\ngi.require_version('Gdk', '3.0')\n\nfrom gi.repository import Gdk\nfrom gi.repository import GdkPixbuf\nimport numpy as np\nfrom Xlib.display import Display\n\n#define the window name\nwindow_name = 'Spotify'\n\n#define xid of your select 'window'\ndef locate_window(stack,window):\n disp = Display()\n NET_WM_NAME = disp.intern_atom('_NET_WM_NAME')\n WM_NAME = disp.intern_atom('WM_NAME') \n name= []\n for i, w in enumerate(stack):\n win_id =w.get_xid()\n window_obj = disp.create_resource_object('window', win_id)\n for atom in (NET_WM_NAME, WM_NAME):\n window_name=window_obj.get_full_property(atom, 0)\n name.append(window_name.value)\n for l in range(len(stack)):\n if(name[2*l]==window):\n return stack[l]\n\nwindow = Gdk.get_default_root_window()\nscreen = window.get_screen()\nstack = screen.get_window_stack()\nmyselectwindow = locate_window(stack,window_name)\nimg_pixbuf = Gdk.pixbuf_get_from_window(myselectwindow,*myselectwindow.get_geometry()) \n def pixbuf_to_array(p):\n w,h,c,r=(p.get_width(), p.get_height(), p.get_n_channels(), p.get_rowstride())\n assert p.get_colorspace() == GdkPixbuf.Colorspace.RGB\n assert p.get_bits_per_sample() == 8\n if p.get_has_alpha():\n assert c == 4\n else:\n assert c == 3\n assert r >= w * c\n a=np.frombuffer(p.get_pixels(),dtype=np.uint8)\n if a.shape[0] == w*c*h:\n return a.reshape( (h, w, c) )\n else:\n b=np.zeros((h,w*c),'uint8')\n for j in range(h):\n b[j,:]=a[r*j:r*j+w*c]\n return b.reshape( (h, w, c) )\n\nbeauty_print = pixbuf_to_array(img_pixbuf)\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69645",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1724701/"
] |
69,676 |
<p>How do I get Asterisk to forward incoming calls based on matching the incoming call number with a number to forward to? Both numbers are stored in a MySQL database.</p>
|
[
{
"answer_id": 75492,
"author": "Jeremy Wadhams",
"author_id": 8995,
"author_profile": "https://Stackoverflow.com/users/8995",
"pm_score": 2,
"selected": false,
"text": "/usr/bin/php fwd_table caller_id destination forward_by_callerid.agi #!/usr/bin/php\n<?php\nini_set('display_errors','false'); //Supress errors getting sent to the Asterisk process\n\nrequire('phpagi.php');\n$agi = new AGI();\n\ntry {\n $pdo = new PDO('mysql:host='.$db_hostname.';dbname='.$db_database.';charset=UTF-8', $db_user, $db_pass);\n} catch (PDOException $e) {\n $agi->conlog(\"FAIL: Error connecting to the database! \" . $e->getMessage());\n die();\n}\n\n$find_fwd_by_callerid = $pdo->prepare('SELECT destination FROM fwd_table WHERE caller_id=? ');\n\n$caller_id = $agi->request['agi_callerid'];\n\nif($callerid==\"unknown\" or $callerid==\"private\" or $callerid==\"\"){\n $agi->conlog(\"Call came in without caller id, I give up\");\n exit;\n}else{\n $agi->conlog(\"Call came in with caller id number $caller_id.\");\n}\n\nif($find_fwd_by_callerid->execute(array($caller_id)) === false){\n $agi->conlog(\"Database problem searching for forward destination (find_fwd_by_callerid), croaking\");\n exit;\n} \n$found_fwds = $find_fwd_by_callerid->fetchAll();\nif(count($found_fwds) > 0){\n $destination = $found_contacts[0]['destination'];\n $agi->set_variable('FWD_TO', $destination);\n\n $agi->conlog(\"Caller ID matched, setting FWD_TO variable to ''\");\n}\n\n?>\n AGI(forward_by_callerid.agi)\n FWD_TO"
},
{
"answer_id": 1869230,
"author": "Aaron",
"author_id": 11176,
"author_profile": "https://Stackoverflow.com/users/11176",
"pm_score": 2,
"selected": true,
"text": "[default]\nexten => _X.,1,Set(ARRAY(${EXTEN}_phone)=${DTC_ICF(phone_number,${EXTEN})})\nexten => _X.,n(callphone),Dial(SIP/metaswitch/${${EXTEN}_phone},26)\nexten => _X.,n(end),Hangup()\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11176/"
] |
69,692 |
<p>What is the best way to setup one Linux box to listen on its serial port for incoming connections? I've done a lot of googling but I can't find the right combination of commands to actually get them to talk!</p>
<p>My main objective is to provide a serial interface to running instances of kvm/qemu VMs. They currently only have a VNC interface (they are on headless servers, no X). I can get the VM to create a serial device by starting it with the -serial file: flag, but how to talk to it, is a whole other problem. Both boxes are running Ubuntu 8.04.</p>
|
[
{
"answer_id": 74208,
"author": "catfood",
"author_id": 12802,
"author_profile": "https://Stackoverflow.com/users/12802",
"pm_score": 0,
"selected": false,
"text": "chown *youruser* /dev/tty1\n open PORT, \"</dev/tty1\" || die \"Can't open port: $!\";\nwhile (defined ($_ = <PORT>))\n{\n do_something($_);\n}\nclose PORT;\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11105/"
] |
69,695 |
<p>I am trying to use a stringstream object in VC++ (VStudio 2003) butI am getting an error when I use the overloaded << operator to try and set some manipulators. </p>
<p>I am trying the following: </p>
<pre><code>int SomeInt = 1;
stringstream StrStream;
StrStream << std::setw(2) << SomeInt;
</code></pre>
<p>This will not compile (error C2593: 'operator <<' is ambiguous).<br>
Does VStudio 2003 support using manipulators in this way?<br>
I know that I can just set the width directly on the stringstream object e.g. StrStream.width(2);<br>
I was wondering why the more usual method doesn't work?</p>
|
[
{
"answer_id": 69721,
"author": "Jesse Beder",
"author_id": 112,
"author_profile": "https://Stackoverflow.com/users/112",
"pm_score": 2,
"selected": true,
"text": "#include <iostream>\n#include <sstream>\n#include <iomanip>\n\nint main()\n{\n int SomeInt = 1;\n std::stringstream StrStream;\n StrStream << std::setw(2) << SomeInt;\n return 0;\n}\n"
},
{
"answer_id": 69779,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "#include <sstream>\n#include <iomanip>\n\nint main()\n{\n int SomeInt = 1;\n std::stringstream StrStream;\n StrStream << std::setw(2) << SomeInt;\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1682/"
] |
69,702 |
<pre><code>public static void main(String[] args) {
List<? extends Object> mylist = new ArrayList<Object>();
mylist.add("Java"); // compile error
}
</code></pre>
<p>The above code does not allow you to add elements to the list and wild cards can only be used as a signature in methods, again not for adding but only for accessing.
In this case what purpose does the above fulfil ??</p>
|
[
{
"answer_id": 69815,
"author": "Henning",
"author_id": 7034,
"author_profile": "https://Stackoverflow.com/users/7034",
"pm_score": 1,
"selected": false,
"text": "Stack<E> public void pushAll(Iterable<? extends E> elements) {\n for(E element : elements){\n push(e);\n }\n}\n pushAll(Iterable<E> elements) E Iterable<String> Iterable<Object>"
},
{
"answer_id": 69825,
"author": "Stu Thompson",
"author_id": 2961,
"author_profile": "https://Stackoverflow.com/users/2961",
"pm_score": 0,
"selected": false,
"text": "List<? super Object> mylist = new ArrayList<Object>();\nmylist.add(\"Java\"); // no compile error\n"
},
{
"answer_id": 69893,
"author": "Bruno De Fraine",
"author_id": 6918,
"author_profile": "https://Stackoverflow.com/users/6918",
"pm_score": 0,
"selected": false,
"text": "List<? extends Object> List<?> List<String> List<Number> List<Object> ? List<?> List<Object> Object null"
},
{
"answer_id": 70393,
"author": "rmaruszewski",
"author_id": 6856,
"author_profile": "https://Stackoverflow.com/users/6856",
"pm_score": 4,
"selected": true,
"text": "interface IResult {}\nclass AResult implements IResult {}\nclass BResult implements IResult {}\n interface ITest<T extends IResult> {\n List<T> getResult();\n}\n\nclass ATest implements ITest<AResult> {\n // look, overridden!\n List<AResult> getResult();\n}\n\nclass BTest implements ITest<BResult> {\n // overridden again!\n List<BResult> getResult();\n}\n"
},
{
"answer_id": 36215658,
"author": "stackinfostack",
"author_id": 6088524,
"author_profile": "https://Stackoverflow.com/users/6088524",
"pm_score": 0,
"selected": false,
"text": "Now you want to use different type of collection in every child class.\n public abstract class AbstractMain<T,E extends MainColorTO> {\n public abstract void paintObject(T Object,E TO); \n}\n public class MainColorTO { \n public void paintColor(){\n System.out.println(\"Paint Color........\");\n } \n }\n\npublic class RedTO extends MainColorTO {\n @Override\n public void paintColor() {\n System.out.println(\"RedTO......\");\n }\n}\npublic class WhiteTO extends MainColorTO {\n @Override\n public void paintColor() {\n System.out.println(\"White TO......\");\n }\n }\n public class PaintHome extends AbstractMain<ArrayList, RedTO> {\n @Override\n public void paintObject(ArrayList arrayList,RedTO red) {\n System.out.println(arrayList);\n\n }\n }\n public class PaintCar extends AbstractMain<HashSet, WhiteTO>{\n @Override\n public void paintObject(HashSet Object,WhiteTO white) {\n System.out.println(Object);\n\n }\n }\n public abstract class AbstractMain<P,E super MainColorTO> {\n\n public abstract void paintObject(P Object,E TO);\n\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11193/"
] |
69,711 |
<p>I would like to know how to infer coercions (a.k.a. implicit conversions) during type inference. I am using the type inference scheme described in <a href="http://people.cs.uu.nl/bastiaan/phdthesis/index.html" rel="noreferrer">Top Quality Type Error Messages</a> by Bastiaan Heeren, but I'd assume that the general idea is probably the same in all Hindley-Milner-esque approaches.</p>
<p>It seems like coercion could be treated as a form of overloading, but the overloading approach described in this paper doesn't consider (at least not in a way I could follow) overloading based on requirements that the context places on return type, which is a must for coercions. I'm also concerned that such an approach might make it difficult to give priority to the identity coercion, and also to respect the transitive closure of coercibility. I can see sugaring each coercible expression, say <em>e</em>, to coerce(<em>e</em>), but sugaring it to coerce(coerce(coerce(... coerce(<em>e</em>) ...))) for some depth equal to the maximum nesting of coercions seems silly, and also limits the coercibility relation to something with a finite transitive closure whose depth is independent of the context, which seems (needlessly?) restrictive.</p>
|
[
{
"answer_id": 2048127,
"author": "mayfly",
"author_id": 223690,
"author_profile": "https://Stackoverflow.com/users/223690",
"pm_score": 1,
"selected": false,
"text": "foo x (coerce foo) (coerce x) coerce :: a -> b\ncoerce x = REDUCE (cast x) if a and b are incompatible\nx otherwise\n class Cast a, b where {cast :: a -> b };\n-- ¬:: is an operator, literally meaning: don’t cast\n--(!) is the reduction operator. Perform one stage of reduction.\n\n-- Reduce on demand\ninstance Cast Exp c, c where { inline cast = ¬::(!)(\\x::(Exp c) -> ¬::(!)x) };\n ¬:: Cast"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69711",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11173/"
] |
69,722 |
<p>I have a dl containing some input boxes that I "clone" with a bit of JavaScript like: </p>
<pre><code>var newBox = document.createElement('dl');
var sourceBox = document.getElementById(oldkey);
newBox.innerHTML = sourceBox.innerHTML;
newBox.id = newkey;
document.getElementById('boxes').appendChild(columnBox);
</code></pre>
<p>In IE, the form in sourceBox is duplicated in newBox, complete with user-supplied values. In Firefox, last value entered in the orginal sourceBox is not present in newBox. How do I make this "stick?"</p>
|
[
{
"answer_id": 69795,
"author": "rpetrich",
"author_id": 4007,
"author_profile": "https://Stackoverflow.com/users/4007",
"pm_score": 1,
"selected": false,
"text": "cloneNode var newBox;\nvar sourceBox = document.getElementById(oldkey);\nif (sourceBox.cloneNode) \n newBox = sourceBox.cloneNode(true);\nelse {\n newBox = document.createElement(sourceBox.tagName); \n newBox.innerHTML = sourceBox.innerHTML; \n}\nnewBox.id = newkey; \ndocument.getElementById('boxes').appendChild(newBox);\n"
},
{
"answer_id": 80723,
"author": "Ross Morrissey",
"author_id": 6997,
"author_profile": "https://Stackoverflow.com/users/6997",
"pm_score": 1,
"selected": false,
"text": "document.getElementById(oldkey) $(oldkey) <script src=\"j/prototype.js\" type=\"text/javascript\"></script> \n\nvar newBox; \nvar sourceBox = $(oldkey); \nif (sourceBox.cloneNode) \n newBox = sourceBox.cloneNode(true); \nelse { \n newBox = document.createElement(sourceBox.tagName); \n newBox.innerHTML = sourceBox.innerHTML; \n} \nnewBox.id = newkey; \ndocument.getElementById('boxes').appendChild(newBox);\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6997/"
] |
69,738 |
<p>I am working with an open-source UNIX tool that is implemented in C++, and I need to change some code to get it to do what I want. I would like to make the smallest possible change in hopes of getting my patch accepted upstream. Solutions that are implementable in standard C++ and do not create more external dependencies are preferred.</p>
<p>Here is my problem. I have a C++ class -- let's call it "A" -- that currently uses fprintf() to print its heavily formatted data structures to a file pointer. In its print function, it also recursively calls the identically defined print functions of several member classes ("B" is an example). There is another class C that has a member std::string "foo" that needs to be set to the print() results of an instance of A. Think of it as a to_str() member function for A.</p>
<p>In pseudocode:</p>
<pre><code>class A {
public:
...
void print(FILE* f);
B b;
...
};
...
void A::print(FILE *f)
{
std::string s = "stuff";
fprintf(f, "some %s", s);
b.print(f);
}
class C {
...
std::string foo;
bool set_foo(std::str);
...
}
...
A a = new A();
C c = new C();
...
// wish i knew how to write A's to_str()
c.set_foo(a.to_str());
</code></pre>
<p>I should mention that C is fairly stable, but A and B (and the rest of A's dependents) are in a state of flux, so the less code changes necessary the better. The current print(FILE* F) interface also needs to be preserved. I have considered several approaches to implementing A::to_str(), each with advantages and disadvantages:</p>
<ol>
<li><p>Change the calls to fprintf() to sprintf()</p>
<ul>
<li>I wouldn't have to rewrite any format strings</li>
<li>print() could be reimplemented as: fprint(f, this.to_str());</li>
<li>But I would need to manually allocate char[]s, merge a lot of c strings , and finally convert the character array to a std::string</li>
</ul></li>
<li><p>Try to catch the results of a.print() in a string stream</p>
<ul>
<li>I would have to convert all of the format strings to << output format. There are hundreds of fprintf()s to convert :-{</li>
<li>print() would have to be rewritten because there is no standard way that I know of to create an output stream from a UNIX file handle (though <a href="http://synflood.at/blog/index.php?/archives/456-One-word-of-warning-about-stdio_filebuf.html" rel="nofollow noreferrer">this guy says it may be possible</a>).</li>
</ul></li>
<li><p>Use Boost's string <a href="http://www.boost.org/doc/libs/1_36_0/libs/format/doc/format.html" rel="nofollow noreferrer">format library</a></p>
<ul>
<li>More external dependencies. Yuck.</li>
<li>Format's syntax is different enough from printf() to be annoying: </li>
</ul>
<p>printf(format_str, args) -> cout << boost::format(format_str) % arg1 % arg2 % etc</p></li>
<li><p>Use Qt's <a href="https://doc.qt.io/qt-5/qstring.html#asprintf%3E" rel="nofollow noreferrer">QString::asprintf()</a></p>
<ul>
<li>A different external dependency.</li>
</ul></li>
</ol>
<p>So, have I exhausted all possible options? If so, which do you think is my best bet? If not, what have I overlooked?</p>
<p>Thanks.</p>
|
[
{
"answer_id": 69765,
"author": "bernhardrusch",
"author_id": 3056,
"author_profile": "https://Stackoverflow.com/users/3056",
"pm_score": 5,
"selected": true,
"text": "sprintf(buffer, \"This is a string with some %s and %d numbers\", \"strings\", 42);\n string = boost::str(boost::format(\"This is a string with some %s and %d numbers\") %\"strings\" %42);\n"
},
{
"answer_id": 69911,
"author": "Larry Gritz",
"author_id": 3832,
"author_profile": "https://Stackoverflow.com/users/3832",
"pm_score": 5,
"selected": false,
"text": "#include <string>\n#include <cstdarg>\n#include <vector>\n#include <string>\n\nstd::string\nformat (const char *fmt, ...)\n{\n va_list ap;\n va_start (ap, fmt);\n std::string buf = vformat (fmt, ap);\n va_end (ap);\n return buf;\n}\n\n\n\nstd::string\nvformat (const char *fmt, va_list ap)\n{\n // Allocate a buffer on the stack that's big enough for us almost\n // all the time.\n size_t size = 1024;\n char buf[size];\n\n // Try to vsnprintf into our buffer.\n va_list apcopy;\n va_copy (apcopy, ap);\n int needed = vsnprintf (&buf[0], size, fmt, ap);\n // NB. On Windows, vsnprintf returns -1 if the string didn't fit the\n // buffer. On Linux & OSX, it returns the length it would have needed.\n\n if (needed <= size && needed >= 0) {\n // It fit fine the first time, we're done.\n return std::string (&buf[0]);\n } else {\n // vsnprintf reported that it wanted to write more characters\n // than we allotted. So do a malloc of the right size and try again.\n // This doesn't happen very often if we chose our initial size\n // well.\n std::vector <char> buf;\n size = needed;\n buf.resize (size);\n needed = vsnprintf (&buf[0], size, fmt, apcopy);\n return std::string (&buf[0]);\n }\n}\n std::string\nStrutil::vformat (const char *fmt, va_list ap)\n{\n // Allocate a buffer on the stack that's big enough for us almost\n // all the time. Be prepared to allocate dynamically if it doesn't fit.\n size_t size = 1024;\n char stackbuf[1024];\n std::vector<char> dynamicbuf;\n char *buf = &stackbuf[0];\n va_list ap_copy;\n\n while (1) {\n // Try to vsnprintf into our buffer.\n va_copy(ap_copy, ap);\n int needed = vsnprintf (buf, size, fmt, ap);\n va_end(ap_copy);\n\n // NB. C99 (which modern Linux and OS X follow) says vsnprintf\n // failure returns the length it would have needed. But older\n // glibc and current Windows return -1 for failure, i.e., not\n // telling us how much was needed.\n\n if (needed <= (int)size && needed >= 0) {\n // It fit fine so we're done.\n return std::string (buf, (size_t) needed);\n }\n\n // vsnprintf reported that it wanted to write more characters\n // than we allotted. So try again using a dynamic buffer. This\n // doesn't happen very often if we chose our initial size well.\n size = (needed > 0) ? (needed+1) : (size*2);\n dynamicbuf.resize (size);\n buf = &dynamicbuf[0];\n }\n}\n"
},
{
"answer_id": 69915,
"author": "Jan de Vos",
"author_id": 11215,
"author_profile": "https://Stackoverflow.com/users/11215",
"pm_score": 1,
"selected": false,
"text": "void A::printto(ostream outputstream) {\n char buffer[100];\n string s = \"stuff\";\n sprintf(buffer, \"some %s\", s);\n outputstream << buffer << endl;\n b.printto(outputstream);\n}\n B::printto void A::print(FILE *f) {\n printto(ofstream(f));\n}\n\nstring A::to_str() {\n ostringstream os;\n printto(os);\n return os.str();\n}\n"
},
{
"answer_id": 56267043,
"author": "vitaut",
"author_id": 471164,
"author_profile": "https://Stackoverflow.com/users/471164",
"pm_score": 2,
"selected": false,
"text": "fmt::sprintf printf std::string std::string s = fmt::sprintf(\"The answer is %d.\", 42);\n"
},
{
"answer_id": 73359248,
"author": "dgnuff",
"author_id": 4022617,
"author_profile": "https://Stackoverflow.com/users/4022617",
"pm_score": 0,
"selected": false,
"text": "pipe(2) fdopen(3) FILE * FILE * A::print() read(2) std::string"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8146/"
] |
69,743 |
<p>I am trying to populate a string with a double value using a <code>sprintf</code> like this:</p>
<pre><code>sprintf(S, "%f", val);
</code></pre>
<p>But the precision is being cut off to six decimal places. I need about 10 decimal places for the precision.</p>
<p>How can that be achieved?</p>
|
[
{
"answer_id": 69747,
"author": "Yann Ramin",
"author_id": 9167,
"author_profile": "https://Stackoverflow.com/users/9167",
"pm_score": 3,
"selected": false,
"text": "sprintf(S, \"%.10f\", val);\n"
},
{
"answer_id": 75791,
"author": "EvilTeach",
"author_id": 7734,
"author_profile": "https://Stackoverflow.com/users/7734",
"pm_score": 1,
"selected": false,
"text": "%f %lf"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69743",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11212/"
] |
69,748 |
<p>Another easy one hopefully.</p>
<p>Let's say I have a collection like this:</p>
<pre><code>List<DateTime> allDates;
</code></pre>
<p>I want to turn that into </p>
<pre><code>List<List<DateTime>> dividedDates;
</code></pre>
<p>where each List in 'dividedDates' contains all of the dates in 'allDates' that belong to a distinct year.</p>
<p>Is there a bit of LINQ trickery that my tired mind can't pick out right now?</p>
<p><strong>Solution</strong></p>
<p>The Accepted Answer is correct.</p>
<p>Thanks, I don't think I was aware of the 'into' bit of GroupBy and I was trying to use the .GroupBy() sort of methods rather than the SQL like syntax. And thanks for confirming the ToList() amendment and including it in the Accepted Answer :-)</p>
|
[
{
"answer_id": 69769,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 4,
"selected": true,
"text": "var q = from date in allDates \n group date by date.Year into datesByYear\n select datesByYear.ToList();\nq.ToList(); //returns List<List<DateTime>>\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/364/"
] |
69,761 |
<p>I'd like to to associate a file extension to the current executable in C#.
This way when the user clicks on the file afterwards in explorer, it'll run my executable with the given file as the first argument.
Ideally it'd also set the icon for the given file extensions to the icon for my executable.
Thanks all.</p>
|
[
{
"answer_id": 899360,
"author": "Paul J",
"author_id": 111237,
"author_profile": "https://Stackoverflow.com/users/111237",
"pm_score": 3,
"selected": false,
"text": "Other Project Types Setup and Deployment Setup Project View File Types"
},
{
"answer_id": 28585998,
"author": "Strong84",
"author_id": 1422691,
"author_profile": "https://Stackoverflow.com/users/1422691",
"pm_score": 3,
"selected": false,
"text": "private void Create_abc_FileAssociation()\n{\n /***********************************/\n /**** Key1: Create \".abc\" entry ****/\n /***********************************/\n Microsoft.Win32.RegistryKey key1 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(\"Software\", true);\n\n key1.CreateSubKey(\"Classes\");\n key1 = key1.OpenSubKey(\"Classes\", true);\n\n key1.CreateSubKey(\".abc\");\n key1 = key1.OpenSubKey(\".abc\", true);\n key1.SetValue(\"\", \"DemoKeyValue\"); // Set default key value\n\n key1.Close();\n\n /*******************************************************/\n /**** Key2: Create \"DemoKeyValue\\DefaultIcon\" entry ****/\n /*******************************************************/\n Microsoft.Win32.RegistryKey key2 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(\"Software\", true);\n\n key2.CreateSubKey(\"Classes\");\n key2 = key2.OpenSubKey(\"Classes\", true);\n\n key2.CreateSubKey(\"DemoKeyValue\");\n key2 = key2.OpenSubKey(\"DemoKeyValue\", true);\n\n key2.CreateSubKey(\"DefaultIcon\");\n key2 = key2.OpenSubKey(\"DefaultIcon\", true);\n key2.SetValue(\"\", \"\\\"\" + \"(The icon path you desire)\" + \"\\\"\"); // Set default key value\n\n key2.Close();\n\n /**************************************************************/\n /**** Key3: Create \"DemoKeyValue\\shell\\open\\command\" entry ****/\n /**************************************************************/\n Microsoft.Win32.RegistryKey key3 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(\"Software\", true);\n\n key3.CreateSubKey(\"Classes\");\n key3 = key3.OpenSubKey(\"Classes\", true);\n\n key3.CreateSubKey(\"DemoKeyValue\");\n key3 = key3.OpenSubKey(\"DemoKeyValue\", true);\n\n key3.CreateSubKey(\"shell\");\n key3 = key3.OpenSubKey(\"shell\", true);\n\n key3.CreateSubKey(\"open\");\n key3 = key3.OpenSubKey(\"open\", true);\n\n key3.CreateSubKey(\"command\");\n key3 = key3.OpenSubKey(\"command\", true);\n key3.SetValue(\"\", \"\\\"\" + \"(The application path you desire)\" + \"\\\"\" + \" \\\"%1\\\"\"); // Set default key value\n\n key3.Close();\n}\n"
},
{
"answer_id": 44816888,
"author": "Kirill Osenkov",
"author_id": 37899,
"author_profile": "https://Stackoverflow.com/users/37899",
"pm_score": 3,
"selected": false,
"text": "public class FileAssociation\n{\n public string Extension { get; set; }\n public string ProgId { get; set; }\n public string FileTypeDescription { get; set; }\n public string ExecutableFilePath { get; set; }\n}\n\npublic class FileAssociations\n{\n // needed so that Explorer windows get refreshed after the registry is updated\n [System.Runtime.InteropServices.DllImport(\"Shell32.dll\")]\n private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);\n\n private const int SHCNE_ASSOCCHANGED = 0x8000000;\n private const int SHCNF_FLUSH = 0x1000;\n\n public static void EnsureAssociationsSet()\n {\n var filePath = Process.GetCurrentProcess().MainModule.FileName;\n EnsureAssociationsSet(\n new FileAssociation\n {\n Extension = \".binlog\",\n ProgId = \"MSBuildBinaryLog\",\n FileTypeDescription = \"MSBuild Binary Log\",\n ExecutableFilePath = filePath\n },\n new FileAssociation\n {\n Extension = \".buildlog\",\n ProgId = \"MSBuildStructuredLog\",\n FileTypeDescription = \"MSBuild Structured Log\",\n ExecutableFilePath = filePath\n });\n }\n\n public static void EnsureAssociationsSet(params FileAssociation[] associations)\n {\n bool madeChanges = false;\n foreach (var association in associations)\n {\n madeChanges |= SetAssociation(\n association.Extension,\n association.ProgId,\n association.FileTypeDescription,\n association.ExecutableFilePath);\n }\n\n if (madeChanges)\n {\n SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero);\n }\n }\n\n public static bool SetAssociation(string extension, string progId, string fileTypeDescription, string applicationFilePath)\n {\n bool madeChanges = false;\n madeChanges |= SetKeyDefaultValue(@\"Software\\Classes\\\" + extension, progId);\n madeChanges |= SetKeyDefaultValue(@\"Software\\Classes\\\" + progId, fileTypeDescription);\n madeChanges |= SetKeyDefaultValue($@\"Software\\Classes\\{progId}\\shell\\open\\command\", \"\\\"\" + applicationFilePath + \"\\\" \\\"%1\\\"\");\n return madeChanges;\n }\n\n private static bool SetKeyDefaultValue(string keyPath, string value)\n {\n using (var key = Registry.CurrentUser.CreateSubKey(keyPath))\n {\n if (key.GetValue(null) as string != value)\n {\n key.SetValue(null, value);\n return true;\n }\n }\n\n return false;\n }\n"
},
{
"answer_id": 46900103,
"author": "Mike",
"author_id": 1943229,
"author_profile": "https://Stackoverflow.com/users/1943229",
"pm_score": 0,
"selected": false,
"text": "assoc .bob=BobFile\nftype BobFile=c:\\temp\\BobView.exe \"%1\"\n public static int setFileAssociation(string[] extensions, string fileType, string openCommandString) {\n int v = execute(\"cmd\", \"/c ftype \" + fileType + \"=\" + openCommandString);\n foreach (string ext in extensions) {\n v = execute(\"cmd\", \"/c assoc \" + ext + \"=\" + fileType);\n if (v != 0) return v;\n }\n return v;\n}\npublic static int execute(string exeFilename, string arguments) {\n ProcessStartInfo startInfo = new ProcessStartInfo();\n startInfo.CreateNoWindow = false;\n startInfo.UseShellExecute = true;\n startInfo.FileName = exeFilename;\n startInfo.WindowStyle = ProcessWindowStyle.Hidden;\n startInfo.Arguments = arguments;\n try {\n using (Process exeProcess = Process.Start(startInfo)) {\n exeProcess.WaitForExit();\n return exeProcess.ExitCode;\n }\n } catch {\n return 1;\n }\n}\n"
},
{
"answer_id": 46902772,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "public enum KeyHiveSmall\n{\n ClassesRoot,\n CurrentUser,\n LocalMachine,\n}\n\n/// <summary>\n/// Create an associaten for a file extension in the windows registry\n/// CreateAssociation(@\"vendor.application\",\".tmf\",\"Tool file\",@\"C:\\Windows\\SYSWOW64\\notepad.exe\",@\"%SystemRoot%\\SYSWOW64\\notepad.exe,0\");\n/// </summary>\n/// <param name=\"ProgID\">e.g. vendor.application</param>\n/// <param name=\"extension\">e.g. .tmf</param>\n/// <param name=\"description\">e.g. Tool file</param>\n/// <param name=\"application\">e.g. @\"C:\\Windows\\SYSWOW64\\notepad.exe\"</param>\n/// <param name=\"icon\">@\"%SystemRoot%\\SYSWOW64\\notepad.exe,0\"</param>\n/// <param name=\"hive\">e.g. The user-specific settings have priority over the computer settings. KeyHive.LocalMachine need admin rights</param>\npublic static void CreateAssociation(string ProgID, string extension, string description, string application, string icon, KeyHiveSmall hive = KeyHiveSmall.CurrentUser)\n{\n RegistryKey selectedKey = null;\n\n switch (hive)\n {\n case KeyHiveSmall.ClassesRoot:\n Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(extension).SetValue(\"\", ProgID);\n selectedKey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(ProgID);\n break;\n\n case KeyHiveSmall.CurrentUser:\n Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@\"Software\\Classes\\\" + extension).SetValue(\"\", ProgID);\n selectedKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@\"Software\\Classes\\\" + ProgID);\n break;\n\n case KeyHiveSmall.LocalMachine:\n Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@\"Software\\Classes\\\" + extension).SetValue(\"\", ProgID);\n selectedKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@\"Software\\Classes\\\" + ProgID);\n break;\n }\n\n if (selectedKey != null)\n {\n if (description != null)\n {\n selectedKey.SetValue(\"\", description);\n }\n if (icon != null)\n {\n selectedKey.CreateSubKey(\"DefaultIcon\").SetValue(\"\", icon, RegistryValueKind.ExpandString);\n selectedKey.CreateSubKey(@\"Shell\\Open\").SetValue(\"icon\", icon, RegistryValueKind.ExpandString);\n }\n if (application != null)\n {\n selectedKey.CreateSubKey(@\"Shell\\Open\\command\").SetValue(\"\", \"\\\"\" + application + \"\\\"\" + \" \\\"%1\\\"\", RegistryValueKind.ExpandString);\n }\n }\n selectedKey.Flush();\n selectedKey.Close();\n}\n\n /// <summary>\n /// Creates a association for current running executable\n /// </summary>\n /// <param name=\"extension\">e.g. .tmf</param>\n /// <param name=\"hive\">e.g. KeyHive.LocalMachine need admin rights</param>\n /// <param name=\"description\">e.g. Tool file. Displayed in explorer</param>\n public static void SelfCreateAssociation(string extension, KeyHiveSmall hive = KeyHiveSmall.CurrentUser, string description = \"\")\n {\n string ProgID = System.Reflection.Assembly.GetExecutingAssembly().EntryPoint.DeclaringType.FullName;\n string FileLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;\n CreateAssociation(ProgID, extension, description, FileLocation, FileLocation + \",0\", hive);\n }\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
69,764 |
<p>There are many options for editing and writing Stored Procedures in Oracle; what is the best tool for you and why? (one tool per answer.)</p>
|
[
{
"answer_id": 69876,
"author": "Andrew",
"author_id": 5662,
"author_profile": "https://Stackoverflow.com/users/5662",
"pm_score": 4,
"selected": false,
"text": "TABLE."
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69764",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4491/"
] |
69,766 |
<p>I'm working on VS 2005 and something has gone wrong on my machine. Suddenly, out of the blue, I can no longer build deployment files.
The build message is:</p>
<pre><code>ERROR: An error occurred generating a bootstrapper: Invalid syntax.
ERROR: General failure building bootstrapper
ERROR: Unrecoverable build error
</code></pre>
<p>A quick Google search brings up the last 2 lines, but nobody in cyberspace has ever reported the first message before. (Hooray! I'm first at SOMETHING on the 'net!)</p>
<p>Other machines in my office are able to do the build.
My machine has been able to do the build before. I have no idea what changed that upset the delicate balance of things on my box.
I have also tried all the traditional rituals i.e. closing Visual Studio, blowing away all the bin and obj folders, rebooting, etc. to no avail.</p>
<p>For simplicity's sake, I created a little "Hello World" app with a deployment file.
Herewith the build output:</p>
<pre><code>------ Build started: Project: HelloWorld, Configuration: Debug Any CPU ------
HelloWorld -> C:\Vault\Multi Client\Tests\HelloWorld\HelloWorld\bin\Debug\HelloWorld.exe
------ Starting pre-build validation for project 'HelloWorldSetup' ------
------ Pre-build validation for project 'HelloWorldSetup' completed ------
------ Build started: Project: HelloWorldSetup, Configuration: Debug ------
Building file 'C:\Vault\Multi Client\Tests\HelloWorld\HelloWorldSetup\Debug\HelloWorldSetup.msi'...
ERROR: An error occurred generating a bootstrapper: Invalid syntax.
ERROR: General failure building bootstrapper
ERROR: Unrecoverable build error
========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========
</code></pre>
<p>I am using:</p>
<ul>
<li>MS Visual Studio 2005 Version 8.0.50727.762 (SP .050727-7600) </li>
<li>.NET Framework Version 2.0.50727 </li>
<li>OS: Windows XP Pro</li>
</ul>
<p>Again, I have no idea what changed. All I know is that one day everything was working fine; the next day I suddenly can't do any deployment builds at all (though all other projects still compile fine).</p>
<p>I posted <a href="http://social.msdn.microsoft.com/forums/en-US/vssetup/thread/240c82e9-1696-4618-846c-aaae21427a52/" rel="nofollow noreferrer">this on MSDN</a> about a month ago, and they don't seem to know what's going on, either.</p>
<p>Anyone have any idea what this is about?</p>
<hr>
<p>@Brad Wilson: Thanks, but if you read my original post, you'll see that I already did start an entire solution from scratch, and that didn't help.</p>
<hr>
<p>@deemer: I went through all the pain of uninstalling and reinstalling, even though I didn't have your recommended reading while waiting... and - Misery! - still the same error reappears. It seems that my computer has somehow been branded as unsuitable for doing deployment builds ever again.</p>
<p>Does anyone have any idea where this "secret switch" might be?</p>
|
[
{
"answer_id": 8539010,
"author": "Adam Caviness",
"author_id": 9130,
"author_profile": "https://Stackoverflow.com/users/9130",
"pm_score": 1,
"selected": false,
"text": "An error occurred generating a bootstrapper: Unable to finish updating resource for [YourAssemblyPath] with error 80070005"
},
{
"answer_id": 15834006,
"author": "Rama",
"author_id": 1620537,
"author_profile": "https://Stackoverflow.com/users/1620537",
"pm_score": 2,
"selected": false,
"text": "In Solution Explorer, select the deployment project.\n\nOn the Project menu, click Properties.\n\nIn the Property Pages dialog box, expand the Configuration Properties node, and then select the Build property page.\n\nClick the Prerequisites button.\n\nIn the Prerequisites dialog box, clear the Create setup program to install prerequisite components check box, and then click OK. \n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7850/"
] |
69,768 |
<p>Mac OS X ships with apache pre-installed, but the files are in non-standard locations. This question is a place to collect information about where configuration files live, and how to tweak the apache installation to do things like serve php pages.</p>
|
[
{
"answer_id": 69784,
"author": "ctcherry",
"author_id": 10322,
"author_profile": "https://Stackoverflow.com/users/10322",
"pm_score": 5,
"selected": true,
"text": "#LoadModule php5_module libexec/apache2/libphp5.so\n LoadModule php5_module libexec/apache2/libphp5.so\n $ sudo apachectl restart\n"
},
{
"answer_id": 69798,
"author": "Larry OBrien",
"author_id": 10116,
"author_profile": "https://Stackoverflow.com/users/10116",
"pm_score": 1,
"selected": false,
"text": " LoadModule php5_module libexec/apache2/libphp5.so\n"
},
{
"answer_id": 6964273,
"author": "Scott Willeke",
"author_id": 51061,
"author_profile": "https://Stackoverflow.com/users/51061",
"pm_score": 2,
"selected": false,
"text": "/private/etc/apache2/users/myusername.conf AllowOverride None AllowOverride All Options +Includes\nAddType text/html .html\nAddOutputFilter INCLUDES .html\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3575/"
] |
69,788 |
<p>I recently installed Windows 2008 Server to replace a crashed hard drive on a web server with a variety of web pages including several classic ASP applications. One of these makes extensive use of file uploads using a com tool that has worked for several years.</p>
<p>More information: </p>
<p>My users did not provide good information in that very small zips (65K) work once I tested it myself, but larger ones do not. I did not test for the cut-off, but 365K fails. And it is not only zip files after all. A 700K doc file failed also. ErrorCode 800a0035.</p>
|
[
{
"answer_id": 76885,
"author": "Kal",
"author_id": 11227,
"author_profile": "https://Stackoverflow.com/users/11227",
"pm_score": 1,
"selected": false,
"text": " <sectionGroup name=\"system.webServer\">\n <section name=\"asp\" overrideModeDefault=\"Deny\" />\n <section name=\"asp\" overrideModeDefault=\"Allow\" />\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11227/"
] |
69,828 |
<p>Our security manager dynamically inserts a bit of javascript at the top of every html page when a page is requested by the client. It is inserted above the DOCTYPE statement. I think this might be the cause of the layout problems I am having.</p>
<p>Ideas anyone?</p>
|
[
{
"answer_id": 72063,
"author": "pdc",
"author_id": 8925,
"author_profile": "https://Stackoverflow.com/users/8925",
"pm_score": 2,
"selected": false,
"text": "DOCTYPE DOCTYPE SCRIPT HTML DOCTYPE SCRIPT HEAD BODY"
},
{
"answer_id": 28060787,
"author": "Joe Hansen",
"author_id": 756329,
"author_profile": "https://Stackoverflow.com/users/756329",
"pm_score": 1,
"selected": false,
"text": "<!DOCTYPE html >"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11249/"
] |
69,835 |
<p>I have to admit that I always forgot the syntactical intracacies of the naming patterns for Nant (eg. those used in filesets). The double asterisk/single asterisk stuff seems to be very forgettable in my mind.</p>
<p>Can someone provide a definitive guide to the naming patterns?</p>
|
[
{
"answer_id": 86915,
"author": "benzado",
"author_id": 10947,
"author_profile": "https://Stackoverflow.com/users/10947",
"pm_score": 9,
"selected": true,
"text": "*.c src/*.c */*.c **/*.c bar.* **/bar.* **/bar*.* src/ba?.c"
},
{
"answer_id": 8821223,
"author": "Aditya Kumar Shrivastava",
"author_id": 948547,
"author_profile": "https://Stackoverflow.com/users/948547",
"pm_score": 3,
"selected": false,
"text": "** * = multi characters ? = single character"
},
{
"answer_id": 18233215,
"author": "sparkplug",
"author_id": 1238492,
"author_profile": "https://Stackoverflow.com/users/1238492",
"pm_score": 4,
"selected": false,
"text": "src** **.c **ar.* **/bartest.c/** src/ba?.c/**"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69835",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4884/"
] |
69,843 |
<p>Does anybody have useful example of <code>this</code> assignment inside a C# method? I have been asked for it once during job interview, and I am still interested in answer myself. </p>
|
[
{
"answer_id": 69880,
"author": "Kimoz",
"author_id": 7753,
"author_profile": "https://Stackoverflow.com/users/7753",
"pm_score": 0,
"selected": false,
"text": "private readonly IProvider provider;\npublic MyClass(IProvider provider)\n{\n this.provider = provider;\n}\n"
},
{
"answer_id": 69910,
"author": "LohanJ",
"author_id": 11286,
"author_profile": "https://Stackoverflow.com/users/11286",
"pm_score": -1,
"selected": false,
"text": "class frmMain\n{\n void InitializeComponents()\n {\n btnOK = new Button();\n btnOK.Parent = this;\n }\n}\n"
},
{
"answer_id": 69988,
"author": "ZeroBugBounce",
"author_id": 11314,
"author_profile": "https://Stackoverflow.com/users/11314",
"pm_score": 7,
"selected": true,
"text": "public struct MyValueType\n{\n public int Id;\n public void Swap(ref MyValueType other)\n {\n MyValueType temp = this;\n this = other;\n other = temp;\n }\n}\n"
},
{
"answer_id": 23914965,
"author": "mhand",
"author_id": 1582922,
"author_profile": "https://Stackoverflow.com/users/1582922",
"pm_score": -1,
"selected": false,
"text": "struct public struct SampleStruct : IXmlSerializable\n{\n private readonly int _data;\n\n public int Data { get { return _data; } }\n\n public SampleStruct(int data)\n {\n _data = data;\n }\n\n #region IXmlSerializableMembers\n\n public XmlSchema GetSchema() { return null; }\n\n public void ReadXml(XmlReader reader)\n {\n this = new SampleStruct(int.Parse(reader.ReadString()));\n }\n\n public void WriteXml(XmlWriter writer\n {\n writer.WriteString(data.ToString());\n }\n\n #endregion\n}\n this _data"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69843",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11256/"
] |
69,849 |
<p>When is it a good idea to use factory methods within an object instead of a Factory class?</p>
|
[
{
"answer_id": 399988,
"author": "Rasmus Faber",
"author_id": 5542,
"author_profile": "https://Stackoverflow.com/users/5542",
"pm_score": 7,
"selected": false,
"text": "class Foo{\n public Foo(bool withBar);\n}\n class Foo{\n public static Foo withBar();\n public static Foo withoutBar();\n}\n"
},
{
"answer_id": 2430719,
"author": "kyoryu",
"author_id": 129175,
"author_profile": "https://Stackoverflow.com/users/129175",
"pm_score": 9,
"selected": false,
"text": "public interface IThingFactory\n{\n Thing GetThing(string theString);\n}\n\npublic class ThingFactory : IThingFactory\n{\n public Thing GetThing(string theString)\n {\n return new Thing(theString, firstDependency, secondDependency);\n }\n}\n"
},
{
"answer_id": 10559506,
"author": "Mahn",
"author_id": 1329367,
"author_profile": "https://Stackoverflow.com/users/1329367",
"pm_score": 7,
"selected": false,
"text": "House Kitchen LivingRoom LivingRoom TV House $TVObj = new TV($param1, $param2, $param3);\n$LivingroomObj = new LivingRoom($TVObj, $param1, $param2);\n$KitchenroomObj = new Kitchen($param1, $param2);\n$HouseObj = new House($LivingroomObj, $KitchenroomObj);\n House House class HouseFactory {\n public function create() {\n $TVObj = new TV($param1, $param2, $param3);\n $LivingroomObj = new LivingRoom($TVObj, $param1, $param2);\n $KitchenroomObj = new Kitchen($param1, $param2);\n $HouseObj = new House($LivingroomObj, $KitchenroomObj);\n\n return $HouseObj;\n }\n}\n\n$houseFactory = new HouseFactory();\n$HouseObj = $houseFactory->create();\n House House"
},
{
"answer_id": 17668707,
"author": "Prakash Chhipa",
"author_id": 2251992,
"author_profile": "https://Stackoverflow.com/users/2251992",
"pm_score": 4,
"selected": false,
"text": "interface Deliverable \n{\n /*********/\n}\n\nabstract class DefaultProducer \n{\n\n public void taskToBeDone() \n { \n Deliverable deliverable = factoryMethodPattern();\n }\n protected abstract Deliverable factoryMethodPattern();\n}\n\nclass SpecificDeliverable implements Deliverable \n{\n /***SPECIFIC TASK CAN BE WRITTEN HERE***/\n}\n\nclass SpecificProducer extends DefaultProducer \n{\n protected Deliverable factoryMethodPattern() \n {\n return new SpecificDeliverable();\n }\n}\n\npublic class MasterApplicationProgram \n{\n public static void main(String arg[]) \n {\n DefaultProducer defaultProducer = new SpecificProducer();\n defaultProducer.taskToBeDone();\n }\n}\n"
},
{
"answer_id": 27735620,
"author": "Robert",
"author_id": 1798677,
"author_profile": "https://Stackoverflow.com/users/1798677",
"pm_score": 0,
"selected": false,
"text": "Numbers Shapes Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. class NumbersFactory {\n public static function makeNumber( $type, $number ) {\n $numObject = null;\n $number = null;\n\n switch( $type ) {\n case 'float':\n $numObject = new Float( $number );\n break;\n case 'integer':\n $numObject = new Integer( $number );\n break;\n case 'short':\n $numObject = new Short( $number );\n break;\n case 'double':\n $numObject = new Double( $number );\n break;\n case 'long':\n $numObject = new Long( $number );\n break;\n default:\n $numObject = new Integer( $number );\n break;\n }\n\n return $numObject;\n }\n}\n\n/* Numbers interface */\nabstract class Number {\n protected $number;\n\n public function __construct( $number ) {\n $this->number = $number;\n }\n\n abstract public function add();\n abstract public function subtract();\n abstract public function multiply();\n abstract public function divide();\n}\n/* Float Implementation */\nclass Float extends Number {\n public function add() {\n // implementation goes here\n }\n\n public function subtract() {\n // implementation goes here\n }\n\n public function multiply() {\n // implementation goes here\n }\n\n public function divide() {\n // implementation goes here\n }\n}\n/* Integer Implementation */\nclass Integer extends Number {\n public function add() {\n // implementation goes here\n }\n\n public function subtract() {\n // implementation goes here\n }\n\n public function multiply() {\n // implementation goes here\n }\n\n public function divide() {\n // implementation goes here\n }\n}\n/* Short Implementation */\nclass Short extends Number {\n public function add() {\n // implementation goes here\n }\n\n public function subtract() {\n // implementation goes here\n }\n\n public function multiply() {\n // implementation goes here\n }\n\n public function divide() {\n // implementation goes here\n }\n}\n/* Double Implementation */\nclass Double extends Number {\n public function add() {\n // implementation goes here\n }\n\n public function subtract() {\n // implementation goes here\n }\n\n public function multiply() {\n // implementation goes here\n }\n\n public function divide() {\n // implementation goes here\n }\n}\n/* Long Implementation */\nclass Long extends Number {\n public function add() {\n // implementation goes here\n }\n\n public function subtract() {\n // implementation goes here\n }\n\n public function multiply() {\n // implementation goes here\n }\n\n public function divide() {\n // implementation goes here\n }\n}\n\n$number = NumbersFactory::makeNumber( 'float', 12.5 );\n"
},
{
"answer_id": 35857241,
"author": "Ravindra babu",
"author_id": 4999394,
"author_profile": "https://Stackoverflow.com/users/4999394",
"pm_score": 4,
"selected": false,
"text": "import java.util.HashMap;\n\n\n/* Product interface as per UML diagram */\ninterface Game{\n /* createGame is a complex method, which executes a sequence of game steps */\n public void createGame();\n}\n\n/* ConcreteProduct implementation as per UML diagram */\nclass Chess implements Game{\n public Chess(){\n\n }\n public void createGame(){\n System.out.println(\"---------------------------------------\");\n System.out.println(\"Create Chess game\");\n System.out.println(\"Opponents:2\");\n System.out.println(\"Define 64 blocks\");\n System.out.println(\"Place 16 pieces for White opponent\");\n System.out.println(\"Place 16 pieces for Black opponent\");\n System.out.println(\"Start Chess game\");\n System.out.println(\"---------------------------------------\");\n }\n}\nclass Checkers implements Game{\n public Checkers(){\n\n }\n public void createGame(){\n System.out.println(\"---------------------------------------\");\n System.out.println(\"Create Checkers game\");\n System.out.println(\"Opponents:2 or 3 or 4 or 6\");\n System.out.println(\"For each opponent, place 10 coins\");\n System.out.println(\"Start Checkers game\");\n System.out.println(\"---------------------------------------\");\n }\n}\nclass Ludo implements Game{\n public Ludo(){\n\n }\n public void createGame(){\n System.out.println(\"---------------------------------------\");\n System.out.println(\"Create Ludo game\");\n System.out.println(\"Opponents:2 or 3 or 4\");\n System.out.println(\"For each opponent, place 4 coins\");\n System.out.println(\"Create two dices with numbers from 1-6\");\n System.out.println(\"Start Ludo game\");\n System.out.println(\"---------------------------------------\");\n }\n}\n\n/* Creator interface as per UML diagram */\ninterface IGameFactory {\n public Game getGame(String gameName);\n}\n\n/* ConcreteCreator implementation as per UML diagram */\nclass GameFactory implements IGameFactory {\n\n HashMap<String,Game> games = new HashMap<String,Game>();\n /* \n Since Game Creation is complex process, we don't want to create game using new operator every time.\n Instead we create Game only once and store it in Factory. When client request a specific game, \n Game object is returned from Factory instead of creating new Game on the fly, which is time consuming\n */\n\n public GameFactory(){\n\n games.put(Chess.class.getName(),new Chess());\n games.put(Checkers.class.getName(),new Checkers());\n games.put(Ludo.class.getName(),new Ludo()); \n }\n public Game getGame(String gameName){\n return games.get(gameName);\n }\n}\n\npublic class NonStaticFactoryDemo{\n public static void main(String args[]){\n if ( args.length < 1){\n System.out.println(\"Usage: java FactoryDemo gameName\");\n return;\n }\n\n GameFactory factory = new GameFactory();\n Game game = factory.getGame(args[0]);\n if ( game != null ){ \n game.createGame();\n System.out.println(\"Game=\"+game.getClass().getName());\n }else{\n System.out.println(args[0]+ \" Game does not exists in factory\");\n } \n }\n}\n java NonStaticFactoryDemo Chess\n---------------------------------------\nCreate Chess game\nOpponents:2\nDefine 64 blocks\nPlace 16 pieces for White opponent\nPlace 16 pieces for Black opponent\nStart Chess game\n---------------------------------------\nGame=Chess\n Factory FactoryMethod Game createGame() Chess, Ludo, Checkers createGame() public Game getGame(String gameName) FactoryMethod IGameFactory GameFactory IGameFactory NotStaticFactoryDemo getGame GameFactory Game Client"
},
{
"answer_id": 45575361,
"author": "Samet ÖZTOPRAK",
"author_id": 6717610,
"author_profile": "https://Stackoverflow.com/users/6717610",
"pm_score": 1,
"selected": false,
"text": "public class factoryMethodPattern {\n static String planName = \"COMMERCIALPLAN\";\n static int units = 3;\n public static void main(String args[]) {\n GetPlanFactory planFactory = new GetPlanFactory();\n Plan p = planFactory.getPlan(planName);\n System.out.print(\"Bill amount for \" + planName + \" of \" + units\n + \" units is: \");\n p.getRate();\n p.calculateBill(units);\n }\n}\n\nabstract class Plan {\n protected double rate;\n\n abstract void getRate();\n\n public void calculateBill(int units) {\n System.out.println(units * rate);\n }\n}\n\nclass DomesticPlan extends Plan {\n // @override\n public void getRate() {\n rate = 3.50;\n }\n}\n\nclass CommercialPlan extends Plan {\n // @override\n public void getRate() {\n rate = 7.50;\n }\n}\n\nclass InstitutionalPlan extends Plan {\n // @override\n public void getRate() {\n rate = 5.50;\n }\n}\n\nclass GetPlanFactory {\n\n // use getPlan method to get object of type Plan\n public Plan getPlan(String planType) {\n if (planType == null) {\n return null;\n }\n if (planType.equalsIgnoreCase(\"DOMESTICPLAN\")) {\n return new DomesticPlan();\n } else if (planType.equalsIgnoreCase(\"COMMERCIALPLAN\")) {\n return new CommercialPlan();\n } else if (planType.equalsIgnoreCase(\"INSTITUTIONALPLAN\")) {\n return new InstitutionalPlan();\n }\n return null;\n }\n}\n"
},
{
"answer_id": 71321528,
"author": "Lunatic",
"author_id": 15758781,
"author_profile": "https://Stackoverflow.com/users/15758781",
"pm_score": 2,
"selected": false,
"text": "public abstract class Factory<T> {\n\n public abstract T instantiate(Supplier<? extends T> supplier);\n\n}\n public class SupplierFactory<T> extends Factory<T> {\n\n @Override\n public T instantiate(Supplier<? extends T> supplier) {\n return supplier.get();\n }\n}\n public class Alpha implements BaseInterface {\n @Override\n public void doAction() {\n System.out.println(\"The Alpha executed\");\n }\n}\n\npublic class Beta implements BaseInterface {\n @Override\n public void doAction() {\n System.out.println(\"The Beta executed\");\n }\n}\n\npublic interface BaseInterface {\n void doAction();\n}\n\npublic class Main {\n public static void main(String[] args) {\n Factory<BaseInterface> secondFactory = new SupplierFactory<>();\n secondFactory.instantiate(Beta::new).doAction();\n secondFactory.instantiate(Alpha::new).doAction();\n }\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
69,859 |
<p>Besides the LD_PRELOAD trick , and Linux Kernel Modules that replace a certain syscall with one provided by you , is there any possibility to intercept a syscall ( open for example ) , so that it first goes through your function , before it reaches the actual open ?</p>
|
[
{
"answer_id": 69884,
"author": "DJ Capelis",
"author_id": 10943,
"author_profile": "https://Stackoverflow.com/users/10943",
"pm_score": 4,
"selected": false,
"text": "/*\n * File: soft_atimes.c\n * Author: D.J. Capelis\n *\n * Compile:\n * gcc -fPIC -c -o soft_atimes.o soft_atimes.c\n * gcc -shared -o soft_atimes.so soft_atimes.o -ldl\n *\n * Use:\n * LD_PRELOAD=\"./soft_atimes.so\" command\n *\n * Copyright 2007 Regents of the University of California\n */\n\n#define _GNU_SOURCE\n#include <dlfcn.h>\n#define _FCNTL_H\n#include <sys/types.h>\n#include <bits/fcntl.h>\n#include <stddef.h>\n\nextern int errorno;\n\nint __thread (*_open)(const char * pathname, int flags, ...) = NULL;\nint __thread (*_open64)(const char * pathname, int flags, ...) = NULL;\n\nint open(const char * pathname, int flags, mode_t mode)\n{\n if (NULL == _open) {\n _open = (int (*)(const char * pathname, int flags, ...)) dlsym(RTLD_NEXT, \"open\");\n }\n if(flags & O_CREAT)\n return _open(pathname, flags | O_NOATIME, mode);\n else\n return _open(pathname, flags | O_NOATIME, 0);\n}\n\nint open64(const char * pathname, int flags, mode_t mode)\n{\n if (NULL == _open64) {\n _open64 = (int (*)(const char * pathname, int flags, ...)) dlsym(RTLD_NEXT, \"open64\");\n }\n if(flags & O_CREAT)\n return _open64(pathname, flags | O_NOATIME, mode);\n else\n return _open64(pathname, flags | O_NOATIME, 0);\n}\n"
},
{
"answer_id": 57713437,
"author": "Jaime Hablutzel",
"author_id": 320594,
"author_profile": "https://Stackoverflow.com/users/320594",
"pm_score": 1,
"selected": false,
"text": "openat # stap -e 'probe syscall.openat { printf(\"%s(%s)\\n\", name, argstr) }'\nopenat(AT_FDCWD, \"/dev/fb0\", O_RDWR)\nopenat(AT_FDCWD, \"/sys/devices/virtual/tty/tty0/active\", O_RDONLY)\nopenat(AT_FDCWD, \"/sys/devices/virtual/tty/tty0/active\", O_RDONLY)\nopenat(AT_FDCWD, \"/dev/tty1\", O_RDONLY)\n"
},
{
"answer_id": 69852132,
"author": "Timmmm",
"author_id": 265521,
"author_profile": "https://Stackoverflow.com/users/265521",
"pm_score": 3,
"selected": false,
"text": "LD_PRELOAD LD_PRELOAD PTRACE_SYSCALL SECCOMP_RET_TRACE ptrace PTRACE_SYSCALL open()"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69859",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11234/"
] |
69,871 |
<p>What are the essential vim commands? What does a new-user need to know to keep themselves from getting into trouble? One command per comment, please.</p>
|
[
{
"answer_id": 69896,
"author": "perimosocordiae",
"author_id": 10601,
"author_profile": "https://Stackoverflow.com/users/10601",
"pm_score": 1,
"selected": false,
"text": "a - switch to insert mode (after the cursor)\nesc - return to command mode\n:wq - save and quit\n:q - quit (no save, only without modification)\n:q! - force quit (no save, also with modification)\nx - delete one character (in command mode)\ndd - delete the whole line (in command mode)\n"
},
{
"answer_id": 69916,
"author": "kementeus",
"author_id": 11273,
"author_profile": "https://Stackoverflow.com/users/11273",
"pm_score": 2,
"selected": false,
"text": ":q -> quit\n:w -> save\n:q! -> quit and don't save\n:x -> save and quit\n:[number] -> go to line number\nG -> go to end of file\ndd -> delete line\np -> \"put\" line\nyy -> \"copy\" line\n:s/[searchfor] -> search\n"
},
{
"answer_id": 70307,
"author": "Sarien",
"author_id": 1994377,
"author_profile": "https://Stackoverflow.com/users/1994377",
"pm_score": 3,
"selected": false,
"text": "q[0-9a-z] in normal mode\n qq\n @[0-9a-z] in normal mode\n @q\n"
},
{
"answer_id": 70325,
"author": "jbdavid",
"author_id": 6314,
"author_profile": "https://Stackoverflow.com/users/6314",
"pm_score": 1,
"selected": false,
"text": "i a esc dd x :wq / n ? yy pp r <N> <command> 5dd man vi"
},
{
"answer_id": 70438,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 4,
"selected": false,
"text": "m (backquote letter) to the exact spot, or with 10dd mm d'm"
},
{
"answer_id": 70479,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "\" ~/.vimrc\n\" Turn on line numbering\nset nu\n\" Turn on syntax highlighting\nsyntax on \n\" Set 4 space expanding tabs\nset tabstop=4\nset shiftwidth=4\nset softtabstop=4\nset expandtab\n\"turn off line wrapping\nset nowrap\n\" Map CTRL-N to create a new tab\n:map <C-n> <ESC>:tabnew<RETURN>\n\" Map Tab and CTRL-Tab to move between tabs\n:map <Tab> <ESC>:tabn<RETURN>\n:map <C-Tab> <ESC>:tabp<RETURN>\n"
},
{
"answer_id": 71851,
"author": "Dominic Dos Santos",
"author_id": 5379,
"author_profile": "https://Stackoverflow.com/users/5379",
"pm_score": 3,
"selected": false,
"text": ":set incsearch :set hlsearch"
},
{
"answer_id": 283612,
"author": "Sergio Acosta",
"author_id": 2954,
"author_profile": "https://Stackoverflow.com/users/2954",
"pm_score": 2,
"selected": false,
"text": "inoremap <C-s> <Esc>:w<CR>\n"
},
{
"answer_id": 540216,
"author": "Jeff",
"author_id": 33775,
"author_profile": "https://Stackoverflow.com/users/33775",
"pm_score": 1,
"selected": false,
"text": ":set ignorecase smartcase\n"
},
{
"answer_id": 834517,
"author": "RedBlueThing",
"author_id": 73488,
"author_profile": "https://Stackoverflow.com/users/73488",
"pm_score": 1,
"selected": false,
"text": ":%!xxd\n :%!xxd -r \n"
},
{
"answer_id": 834571,
"author": "Shashikant Kore",
"author_id": 77308,
"author_profile": "https://Stackoverflow.com/users/77308",
"pm_score": 0,
"selected": false,
"text": "% find matching bracket/brace \n* and # next/previous match\ngg top of page\nG end of the page\n<Ctrl-v> Change to visual mode and select column\n<Ctrl-a> increase current number by 1\n<Ctrl-x> decrease current number by 1\nRunning macros\n"
},
{
"answer_id": 4728331,
"author": "Scott Saad",
"author_id": 4916,
"author_profile": "https://Stackoverflow.com/users/4916",
"pm_score": 0,
"selected": false,
"text": "gg=G\n if ( !flag )\n{\n // Do something special\n }\nelse\n {\n // Do another special thing\n}\n if ( !flag ) \n{\n // Do something special \n}\nelse\n{\n // Do another special thing\n}\n <root>\n<addressBook>\n <contact first=\"Frank\" last=\"Tank\"/>\n <contact first=\"Foo\" last=\"Man\"/>\n </addressBook>\n</root>\n <root>\n <addressBook>\n <contact first=\"Frank\" last=\"Tank\"/>\n <contact first=\"Foo\" last=\"Man\"/>\n </addressBook>\n</root>\n"
},
{
"answer_id": 9047380,
"author": "kikuchiyo",
"author_id": 1040358,
"author_profile": "https://Stackoverflow.com/users/1040358",
"pm_score": 0,
"selected": false,
"text": "i"
},
{
"answer_id": 13023747,
"author": "ivotron",
"author_id": 389188,
"author_profile": "https://Stackoverflow.com/users/389188",
"pm_score": 0,
"selected": false,
"text": ":g/<pattern>/t$ <pattern>"
},
{
"answer_id": 34129669,
"author": "sudo bangbang",
"author_id": 3951782,
"author_profile": "https://Stackoverflow.com/users/3951782",
"pm_score": 1,
"selected": false,
"text": "set number\nset relativenumber\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3575/"
] |
69,913 |
<p>What is the reason browsers do not correctly recognize:</p>
<pre><code><script src="foobar.js" /> <!-- self-closing script element -->
</code></pre>
<p>Only this is recognized:</p>
<pre><code><script src="foobar.js"></script>
</code></pre>
<p>Does this break the concept of XHTML support?</p>
<p>Note: This statement is correct at least for all IE (6-8 beta 2).</p>
|
[
{
"answer_id": 69984,
"author": "squadette",
"author_id": 7754,
"author_profile": "https://Stackoverflow.com/users/7754",
"pm_score": 10,
"selected": true,
"text": "EMPTY <p> </p> <p /> <!-- script statements, which may include CDATA sections -->\n<!ELEMENT script (#PCDATA)>\n"
},
{
"answer_id": 69996,
"author": "rpetrich",
"author_id": 4007,
"author_profile": "https://Stackoverflow.com/users/4007",
"pm_score": 5,
"selected": false,
"text": "/ <script defer> <script defer=\"defer\"> <script /> <script /=\"/\">"
},
{
"answer_id": 70288,
"author": "joelhardi",
"author_id": 11438,
"author_profile": "https://Stackoverflow.com/users/11438",
"pm_score": 8,
"selected": false,
"text": "<script /> application/xhtml+xml text/html text/html <script></script> text/html text/html <script /> http-equiv text/html <script />"
},
{
"answer_id": 71836,
"author": "Mike Dimmick",
"author_id": 6970,
"author_profile": "https://Stackoverflow.com/users/6970",
"pm_score": 4,
"selected": false,
"text": "application/xhtml+xml text/html application/xhtml+xml"
},
{
"answer_id": 71998,
"author": "Marijn",
"author_id": 12038,
"author_profile": "https://Stackoverflow.com/users/12038",
"pm_score": 5,
"selected": false,
"text": "<br/> / <p/>foo</p>"
},
{
"answer_id": 3327807,
"author": "greim",
"author_id": 127040,
"author_profile": "https://Stackoverflow.com/users/127040",
"pm_score": 7,
"selected": false,
"text": "<p><div>hello</div></p>\n <p></p><div>hello</div><p></p>\n"
},
{
"answer_id": 13098915,
"author": "defau1t",
"author_id": 724764,
"author_profile": "https://Stackoverflow.com/users/724764",
"pm_score": 5,
"selected": false,
"text": "<link> <link type=\"text/javascript\" rel =\"script\" href=\"/path/tp/javascript\" />\n"
},
{
"answer_id": 28719226,
"author": "Sheepy",
"author_id": 893578,
"author_profile": "https://Stackoverflow.com/users/893578",
"pm_score": 8,
"selected": false,
"text": "<script/> <BR// <B>text</> <B/text/ <OL<LI>item</LI</OL> <BR/> <SCRIPT/> <SCRIPT>> <script> <script> <script> <br/> <hr/> <script> <script> <script/> text/html Content-Type"
},
{
"answer_id": 45746061,
"author": "Bekim Bacaj",
"author_id": 5896426,
"author_profile": "https://Stackoverflow.com/users/5896426",
"pm_score": 3,
"selected": false,
"text": "<br></br> <br /> <H1> <P> < /> <H1>Title< /> < /> <b> <i> < /> </> <H1> <B>"
},
{
"answer_id": 47424940,
"author": "myf",
"author_id": 540955,
"author_profile": "https://Stackoverflow.com/users/540955",
"pm_score": 2,
"selected": false,
"text": "<script src=\"data:text/javascript,/*functionality*/\" /> &x; application/xhtml+xml text/html div { display: flex; }\ndiv + div {flex-direction: column; } <div>Mime type: <label><input type=\"radio\" onchange=\"t.onkeyup()\" id=\"x\" checked name=\"mime\"> application/xhtml+xml</label>\n<label><input type=\"radio\" onchange=\"t.onkeyup()\" name=\"mime\"> text/html</label></div>\n<div><textarea id=\"t\" rows=\"4\" \nonkeyup=\"i.src='data:'+(x.checked?'application/xhtml+xml':'text/html')+','+encodeURIComponent(t.value)\"\n><?xml version=\"1.0\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"\n[<!ENTITY x \"true XHTML\">]>\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<body>\n <p>\n <span id=\"greet\" swapto=\"Hello\">Hell, NO :(</span> &x;.\n <script src=\"data:text/javascript,(g=document.getElementById('greet')).innerText=g.getAttribute('swapto')\" />\n Nice to meet you!\n <!-- \n Previous text node and all further content falls into SCRIPT element content in text/html mode, so is not rendered. Because no end script tag is found, no script runs in text/html\n -->\n </p>\n</body>\n</html></textarea>\n\n<iframe id=\"i\" height=\"80\"></iframe>\n\n<script>t.onkeyup()</script>\n</div> Hello, true XHTML. Nice to meet you! .xhtml .xht"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10778/"
] |
69,923 |
<p>We're having problem with a huge number of legacy stored procedures at work. Do you guys recommend any tool the can help better understand those procedures? Some kind of reverse engineering that indentifies inter-procedure dependencies and/or procedure vs. tables dependencies. Can be a free or commercial tool.</p>
<p>Thanks!</p>
|
[
{
"answer_id": 93967,
"author": "ConcernedOfTunbridgeWells",
"author_id": 15401,
"author_profile": "https://Stackoverflow.com/users/15401",
"pm_score": 3,
"selected": false,
"text": "sys.sql_dependencies referenced_minor_id with dep_cte as (\nselect o2.object_id as parent_id\n ,o2.name as parent_name\n ,o1.object_id as child_id\n ,o1.name as child_name\n ,d.referenced_minor_id\n ,1 as hierarchy_level\n from sys.sql_dependencies d\n join sys.objects o1\n on o1.object_id = d.referenced_major_id\n join sys.objects o2\n on o2.object_id = d.object_id\n where d.referenced_minor_id in (0,1)\n and not exists\n (select 1\n from sys.sql_dependencies d2\n where d2.referenced_major_id = d.object_id)\n\nunion all\n\nselect o2.object_id as parent_id\n ,o2.name as parent_name\n ,o1.object_id as child_id\n ,o1.name as child_name\n ,d.referenced_minor_id\n ,d2.hierarchy_level + 1 as hierarchy_level\n from sys.sql_dependencies d\n join sys.objects o1\n on o1.object_id = d.referenced_major_id\n join sys.objects o2\n on o2.object_id = d.object_id\n join dep_cte d2\n on d.object_id = d2.child_id\n where d.referenced_minor_id in (0,1)\n)\n\nselect *\n from dep_cte\n order by hierarchy_level\n"
},
{
"answer_id": 94484,
"author": "jkinter",
"author_id": 10405,
"author_profile": "https://Stackoverflow.com/users/10405",
"pm_score": 1,
"selected": false,
"text": "select \n so.name + case when so.xtype='P' then ' (Stored Proc)' when so.xtype='U' then ' (Table)' when so.xtype='V' then ' (View)' else ' (Unknown)' end as EntityName, \n so2.name + case when so2.xtype='P' then ' (Stored Proc)' when so2.xtype='U' then ' (Table)' when so2.xtype='V' then ' (View)' else ' (Unknown)' end as FirstDependancy,\n so3.name + case when so3.xtype='P' then ' (Stored Proc)' when so3.xtype='U' then ' (Table)' when so3.xtype='V' then ' (View)' else ' (Unknown)' end as SecondDependancy,\n so4.name + case when so4.xtype='P' then ' (Stored Proc)' when so4.xtype='U' then ' (Table)' when so4.xtype='V' then ' (View)' else ' (Unknown)' end as ThirdDependancy\nfrom \n sysdepends sd \n inner join sysobjects as so on sd.id=so.id \n left join sysobjects as so2 on sd.depid=so2.id\n left join sysdepends as sd2 on so2.id=sd2.id and so2.xtype not in ('S','PK','D')\n left join sysobjects as so3 on sd2.depid=so3.id and so3.xtype not in ('S','PK','D')\n left join sysdepends as sd3 on so3.id=sd3.id and so3.xtype not in ('S','PK','D')\n left join sysobjects as so4 on sd3.depid=so4.id and so4.xtype not in ('S','PK','D')\nwhere so.xtype = 'P' and left(so.name,2)<>'dt'\ngroup by so.name, so2.name, so3.name, so4.name, so.xtype, so2.xtype, so3.xtype, so4.xtype\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69923",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4213/"
] |
69,927 |
<p>I have some domain logic implemented in a number of POJOs. I want to write a Swing user interface to allow the user to initiate and see the results of various domain actions.</p>
<p>What's the best pattern/framework/library for communications between the UI and the domain? This boils down into:</p>
<ul>
<li>the UI being able to convert a user gesture into a domain action</li>
<li>the domain being able to send state/result information back to the UI for display purposes</li>
</ul>
<p>I'm aware of MVC as a broad concept and have fiddled with the Observer pattern (whose Java implementation has some drawbacks if I understand correctly), but I'm wondering if there's an accepted best practise for this problem?</p>
|
[
{
"answer_id": 73436,
"author": "Aidos",
"author_id": 12040,
"author_profile": "https://Stackoverflow.com/users/12040",
"pm_score": 1,
"selected": false,
"text": "pages forms"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10433/"
] |
69,928 |
<p>The company has the traditional complex organizational structure, defining the amount of levels using the letter 'n' rather than an actual number. I will try and express the structure I'm trying to achieve in mono-spaced font: </p>
<pre><code> Alice
,--------|-------,------,------,
Bob Fred Jack Kim Lucy
| |
Charlie Greg
Darren Henry
Eric
</code></pre>
<p>As you can see it's not symmetrical, as Jack, Kim and Lucy report to Alice but have no reports of their own. </p>
<p>Using a <code>TreeView</code> with an <code>ItemsPanel</code> containing a <code>StackPanel</code> and <code>Orientation="Horizontal"</code> is <a href="http://www.codeproject.com/KB/WPF/CustomTreeViewLayout.aspx" rel="nofollow noreferrer">easy enough</a>, but this can result in a very large <code>TreeView</code> once some people have 20 others reporting to them! You can <a href="http://www.codeproject.com/KB/WPF/AdvancedCustomTreeViewLyt.aspx" rel="nofollow noreferrer">also use</a> <code>Triggers</code> to peek into whether a <code>TreeViewItem</code> has children with <code>Property="TreeViewItem.HasItems"</code>, but this is not in the same context as the before-mentioned <code>ItemsPanel</code>. <em>Eg: I can tell that Fred has reports, but not whether they have reports of their own.</em> </p>
<p>So, can you conditionally format <code>TreeViewItems</code> to be Vertical if they have no children of their own?</p>
|
[
{
"answer_id": 113120,
"author": "Mark Glorie",
"author_id": 952,
"author_profile": "https://Stackoverflow.com/users/952",
"pm_score": 1,
"selected": true,
"text": "<ValueConversion(GetType(ItemsPresenter), GetType(Orientation))> _\nPublic Class ItemsPanelOrientationConverter\nImplements IValueConverter\n\nPublic Function Convert(ByVal value As Object, ByVal targetType As System.Type, _\nByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) _\nAs Object Implements System.Windows.Data.IValueConverter.Convert\n\n 'The 'value' argument should reference an ItemsPresenter.'\n Dim itemsPresenter As ItemsPresenter = TryCast(value, ItemsPresenter)\n If itemsPresenter Is Nothing Then\n Return Binding.DoNothing\n End If\n\n 'The ItemsPresenter''s templated parent should be a TreeViewItem.'\n Dim item As TreeViewItem = TryCast(itemsPresenter.TemplatedParent, TreeViewItem)\n If item Is Nothing Then\n Return Binding.DoNothing\n End If\n\n For Each i As Object In item.Items\n Dim element As StaffMember = TryCast(i, StaffMember)\n If element.IsManager Then\n 'If this element has children, then return Horizontal'\n Return Orientation.Horizontal\n End If\n Next\n\n 'Must be a stub ItemPresenter'\n Return Orientation.Vertical\n\nEnd Function\n <Setter Property=\"ItemsPanel\">\n <Setter.Value>\n <ItemsPanelTemplate >\n <ItemsPanelTemplate.Resources>\n <local:ItemsPanelOrientationConverter x:Key=\"conv\" />\n </ItemsPanelTemplate.Resources>\n <StackPanel IsItemsHost=\"True\" \n Orientation=\"{Binding \n RelativeSource={x:Static RelativeSource.TemplatedParent}, \n Converter={StaticResource conv}}\" />\n </ItemsPanelTemplate>\n </Setter.Value>\n </Setter>\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/952/"
] |
69,934 |
<p>I've been unsuccessful in getting Emacs to switch from 8 space tabs to 4 space tabs when pressing the <kbd>TAB</kbd> in buffers with the major mode <code>text-mode</code>. I've added the following to my <code>.emacs</code>:</p>
<pre><code>(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
;;; And I have tried
(setq indent-tabs-mode nil)
(setq tab-width 4)
</code></pre>
<p>No matter how I change my <code>.emacs</code> file (or my buffer's local variables) the <kbd>TAB</kbd> button always does the same thing.</p>
<ol>
<li>If there is no text above, indent <strong>8</strong> spaces</li>
<li>If there is text on the previous line, indent to the beginning of the second word</li>
</ol>
<p>As much as I love Emacs this is getting annoying. Is there a way to make Emacs to at least indent 4 space when there's not text in the previous line?</p>
|
[
{
"answer_id": 69992,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "(setq tab-width 4)\n"
},
{
"answer_id": 70027,
"author": "Bert F",
"author_id": 11296,
"author_profile": "https://Stackoverflow.com/users/11296",
"pm_score": 6,
"selected": true,
"text": "tab-width tab-stop-list TAB TAB (customize-variable (quote tab-stop-list))\n (custom-set-variables\n ;; custom-set-variables was added by Custom.\n ;; If you edit it by hand, you could mess it up, so be careful.\n ;; Your init file should contain only one such instance.\n ;; If there is more than one, they won't work right.\n '(tab-stop-list (quote (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120))))\n M-x edit-tab-stops edit-tab-stops"
},
{
"answer_id": 70205,
"author": "cjm",
"author_id": 8355,
"author_profile": "https://Stackoverflow.com/users/8355",
"pm_score": 3,
"selected": false,
"text": "(add-hook 'text-mode-hook\n (function\n (lambda ()\n (setq tab-width 4)\n (define-key text-mode-map \"\\C-i\" 'self-insert-command)\n )))\n"
},
{
"answer_id": 70329,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 4,
"selected": false,
"text": "M-x customize-group\n Customize group: indent"
},
{
"answer_id": 471916,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "(setq tab-width 4)\n(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80))\n(setq indent-tabs-mode nil)\n"
},
{
"answer_id": 1301711,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "(setq-default tab-width 4)\n(setq-default indent-tabs-mode nil)\n"
},
{
"answer_id": 1819405,
"author": "alcortes",
"author_id": 102532,
"author_profile": "https://Stackoverflow.com/users/102532",
"pm_score": 7,
"selected": false,
"text": "(setq-default indent-tabs-mode nil)\n(setq-default tab-width 4)\n(setq indent-line-function 'insert-tab)\n"
},
{
"answer_id": 10438585,
"author": "qwerty9967",
"author_id": 1305559,
"author_profile": "https://Stackoverflow.com/users/1305559",
"pm_score": 2,
"selected": false,
"text": "(setq default-tab-width 2)\n (global-set-key (kbd \"TAB\") 'self-insert-command)\n (setq c-backspace-function 'backward-delete-char)\n"
},
{
"answer_id": 10439239,
"author": "phils",
"author_id": 324105,
"author_profile": "https://Stackoverflow.com/users/324105",
"pm_score": 6,
"selected": false,
"text": "tab-stop-list nil tab-width tab-stop-list nil (setq tab-stop-list 4 8 12 ................) number-sequence (setq tab-stop-list (number-sequence 4 200 4))\n (defun my-generate-tab-stops (&optional width max)\n \"Return a sequence suitable for `tab-stop-list'.\"\n (let* ((max-column (or max 200))\n (tab-width (or width tab-width))\n (count (/ max-column tab-width)))\n (number-sequence tab-width (* tab-width count) tab-width)))\n\n(setq tab-width 4)\n(setq tab-stop-list (my-generate-tab-stops))\n"
},
{
"answer_id": 13114566,
"author": "gigilibala",
"author_id": 1775441,
"author_profile": "https://Stackoverflow.com/users/1775441",
"pm_score": 3,
"selected": false,
"text": "(custom-set-variables\n '(indent-line-function 'insert-tab)\n '(indent-tabs-mode t)\n '(tab-width 4))\n(add-hook 'text-mode-hook\n (lambda() (setq indent-line-function 'insert-tab)))\n"
},
{
"answer_id": 16127986,
"author": "lawlist",
"author_id": 2112489,
"author_profile": "https://Stackoverflow.com/users/2112489",
"pm_score": 3,
"selected": false,
"text": "(defun my-custom-settings-fn ()\n (setq indent-tabs-mode t)\n (setq tab-stop-list (number-sequence 2 200 2))\n (setq tab-width 2)\n (setq indent-line-function 'insert-tab))\n\n(add-hook 'text-mode-hook 'my-custom-settings-fn)\n"
},
{
"answer_id": 16210873,
"author": "user2318996",
"author_id": 2318996,
"author_profile": "https://Stackoverflow.com/users/2318996",
"pm_score": 3,
"selected": false,
"text": "(setq-default indent-tabs-mode nil)\n(setq-default tab-width 4)\n(setq indent-line-function 'insert-tab)\n(setq c-default-style \"linux\") \n(setq c-basic-offset 4) \n(c-set-offset 'comment-intro 0)\n"
},
{
"answer_id": 18887294,
"author": "flyrain",
"author_id": 933856,
"author_profile": "https://Stackoverflow.com/users/933856",
"pm_score": 0,
"selected": false,
"text": "(setq-default c-basic-offset 4)"
},
{
"answer_id": 31124271,
"author": "user1009285",
"author_id": 1009285,
"author_profile": "https://Stackoverflow.com/users/1009285",
"pm_score": 2,
"selected": false,
"text": "(global-set-key (kbd \"TAB\") 'self-insert-command)\n"
},
{
"answer_id": 42148697,
"author": "ryanpcmcquen",
"author_id": 2662028,
"author_profile": "https://Stackoverflow.com/users/2662028",
"pm_score": 2,
"selected": false,
"text": "(setq-default\n indent-tabs-mode nil\n tab-width 4\n tab-stop-list (quote (4 8))\n)\n quote Python"
},
{
"answer_id": 42841185,
"author": "Yary",
"author_id": 379333,
"author_profile": "https://Stackoverflow.com/users/379333",
"pm_score": 2,
"selected": false,
"text": "(setq tab width 4) setq-default tab-stop-list insert (custom-set-variables\n '(tab-width 4 't)\n )\n (defvaralias 'c-basic-offset 'tab-width)\n(defvaralias 'cperl-indent-level 'tab-width)\n"
},
{
"answer_id": 61216979,
"author": "Saurabh",
"author_id": 13055097,
"author_profile": "https://Stackoverflow.com/users/13055097",
"pm_score": 0,
"selected": false,
"text": "(setq-default\n indent-tabs-mode t\n tab-stop-list (number-sequence 4 200 4)\n tab-width 4\n indent-line-function 'insert-tab)\n"
},
{
"answer_id": 69657718,
"author": "alex_1948511",
"author_id": 1948511,
"author_profile": "https://Stackoverflow.com/users/1948511",
"pm_score": 0,
"selected": false,
"text": "Tab (add-hook 'text-mode-hook\n (lambda()\n (progn\n (setq tab-always-indent nil) \n ;(setq electric-indent-mode nil)\n (setq indent-line-function \n (lambda()\n (indent-relative 't) \n )\n ) \n (setq tab-always-indent nil)\n )))\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69934",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/680/"
] |
69,959 |
<p>After successfully building dblink on solaris 10 using Sun C 5.9
SunOS_sparc 2007/05/03 and gmake.</p>
<p>I ran gmake installcheck and got the following output:</p>
<pre><code>========== running regression test queries ==========
test dblink ... FAILED
======================
1 of 1 tests failed.
</code></pre>
<p>The differences that caused some tests to fail can be viewed in the
file "./regression.diffs". A copy of the test summary that you see
above is saved in the file "./regression.out".</p>
<p>First error in regression.diffs file:</p>
<blockquote>
<p>psql:dblink.sql:11: ERROR: could not load library "/apps/postgresql/
lib/dblink.so": ld.so.1: postgre
s: fatal: relocation error: file /apps/postgresql/lib/dblink.so:
symbol PG_GETARG_TEXT_PP: referenced symbol not found</p>
</blockquote>
<p>I am running postgreSQL version 8.2.4 with the latest dblink source.</p>
<p>Has anyone got any idea what I need to do to solve this problem.
Thanks. </p>
|
[
{
"answer_id": 73275,
"author": "Grant Johnson",
"author_id": 12518,
"author_profile": "https://Stackoverflow.com/users/12518",
"pm_score": 0,
"selected": false,
"text": "find / -type f|grep dblink.so\n su - \nsu - postgres\nless /apps/postgresql/ lib/dblink.so\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5385/"
] |
69,982 |
<p>I had an idea for a client-side language other than JavaScript, and I'd like to look into developing a Firefox plugin that would treat includes of this new language in a page, like <script type="newscript" src="path/script.ns" />, just as if it were a natively supported language. The plugin would do all of the language parsing and ideally be able to perform every operation on the browser and the html and css within the web page just as JavaScript can.</p>
<p>I've done a bunch of Googling and have found some articles on writing basic Firefox plugins, but nothing as complicated as this.</p>
<p>Is this even possible?</p>
|
[
{
"answer_id": 70239,
"author": "Nathan de Vries",
"author_id": 11109,
"author_profile": "https://Stackoverflow.com/users/11109",
"pm_score": 2,
"selected": false,
"text": "<object /> <embed /> <script type=\"application/x-yourtype\" />"
},
{
"answer_id": 70289,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 2,
"selected": false,
"text": "<script type=\"text/ruby\">"
},
{
"answer_id": 70698,
"author": "Nickolay",
"author_id": 1026,
"author_profile": "https://Stackoverflow.com/users/1026",
"pm_score": 3,
"selected": true,
"text": "<script type=...>"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1943957/"
] |
69,998 |
<p>How do I prevent vim from replacing spaces with tabs when autoindent is on?</p>
<p>An example: if I have two tabs and 7 spaces in the beginning of the line, and <code>tabstop=3</code>, and I press Enter, the next line has four tabs and 1 space in the beginning, but I don't want that...</p>
|
[
{
"answer_id": 70034,
"author": "svrist",
"author_id": 86,
"author_profile": "https://Stackoverflow.com/users/86",
"pm_score": 1,
"selected": false,
"text": "set softtabstop=2\n"
},
{
"answer_id": 70049,
"author": "user11211",
"author_id": 11211,
"author_profile": "https://Stackoverflow.com/users/11211",
"pm_score": 7,
"selected": true,
"text": ":set expandtab\n tabstop=3 :%s/^I/ /\n ^I 'tabstop' 'ts' number (default 8)\n local to buffer\nNumber of spaces that a <Tab> in the file counts for. Also see\n|:retab| command, and 'softtabstop' option.\n\nNote: Setting 'tabstop' to any other value than 8 can make your file\nappear wrong in many places (e.g., when printing it).\n\nThere are four main ways to use tabs in Vim:\n1. Always keep 'tabstop' at 8, set 'softtabstop' and 'shiftwidth' to 4\n (or 3 or whatever you prefer) and use 'noexpandtab'. Then Vim\n will use a mix of tabs and spaces, but typing <Tab> and <BS> will\n behave like a tab appears every 4 (or 3) characters.\n2. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use\n 'expandtab'. This way you will always insert spaces. The\n formatting will never be messed up when 'tabstop' is changed.\n3. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use a\n |modeline| to set these values when editing the file again. Only\n works when using Vim to edit the file.\n4. Always set 'tabstop' and 'shiftwidth' to the same value, and\n 'noexpandtab'. This should then work (for initial indents only)\n for any tabstop setting that people use. It might be nice to have\n tabs after the first non-blank inserted as spaces if you do this\n though. Otherwise aligned comments will be wrong when 'tabstop' is\n changed.\n"
},
{
"answer_id": 70054,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 5,
"selected": false,
"text": ".vimrc set autoindent\nset expandtab\nset softtabstop=4\nset shiftwidth=4\n"
},
{
"answer_id": 71422,
"author": "Aristotle Pagaltzis",
"author_id": 9410,
"author_profile": "https://Stackoverflow.com/users/9410",
"pm_score": 5,
"selected": false,
"text": ":help copyindent :help preserveindent"
},
{
"answer_id": 5790967,
"author": "kev",
"author_id": 348785,
"author_profile": "https://Stackoverflow.com/users/348785",
"pm_score": 6,
"selected": false,
"text": "TAB SPACE :set et\n:ret!\n SPACE TAB :set et!\n:ret!\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/69998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
70,004 |
<p>As a lot of people pointed out in <a href="https://stackoverflow.com/questions/4724/learning-lisp-why">this question</a>, Lisp is mostly used as a learning experience. Nevertheless, it would be great if I could somehow use my Lisp algorithms and combine them with my C# programs.
In college my profs never could tell me how to use my Lisp routines in a program (no, not writing a GUI in Lisp, thank you).
So how can I?</p>
|
[
{
"answer_id": 49617190,
"author": "KFL",
"author_id": 695964,
"author_profile": "https://Stackoverflow.com/users/695964",
"pm_score": 2,
"selected": false,
"text": ".ss EXECUTE Func<object, object> EXECUTE ; This script will be load by the server as command `man`. The command\n; is consistent of the following functions chained together:\n;\n; 1. An online man-page look up - it detects the current operating system and \n; decides to use either a linux or freebsd man page web API for the look up.\n; \n; 2. A string truncator `truncate-string` - it truncates the input string, in\n; this case the output of the man-page lookup, to the specified number of\n; characters.\n; \n; The client of the command server connects via raw RCP protocol, and can issue\n; commands like:\n; \n; man ls\n; \n; and gets response of the truncated corresponding online manpage content.\n\n(define EXECUTE\n (let ((os (get-current-os))\n (max-length 500))\n (chain ; chain functions together\n (cond ; pick a manpage lookup based on OS\n ((equal? os \"freebsd\") (man-freebsd))\n ((equal? os \"linux\") (man-linux))\n (else (man-freebsd)))\n (truncate-string max-length)))) ; truncate output string to a max length\n man <unix_command> $ ncat 127.0.0.1 8080\n\nman ls\n\nLS(1) FreeBSD General Commands Manual LS(1)\n\nNAME\n ls -- list directory contents\n\nSYNOPSIS\n ls [--libxo] [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [-D format]\n [file ...]\n\nDESCRIPTION\n For each operand that names a file of a type other than directory, ls\n displays its name as well as any requested, associated information. For\n each operand that names a file of type directory, ls displays the names\n of files contained within that directory, as well as any requested,\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
70,013 |
<p>Is there any way to know if I'm compiling under a specific Microsoft Visual Studio version?</p>
|
[
{
"answer_id": 70041,
"author": "Jeff Hubbard",
"author_id": 8844,
"author_profile": "https://Stackoverflow.com/users/8844",
"pm_score": 3,
"selected": false,
"text": "_MSC_VER"
},
{
"answer_id": 70630,
"author": "jilles de wit",
"author_id": 7531,
"author_profile": "https://Stackoverflow.com/users/7531",
"pm_score": 10,
"selected": true,
"text": "_MSC_VER _MSC_FULL_VER MSVC++ 14.24 _MSC_VER == 1924 (Visual Studio 2019 version 16.4)\nMSVC++ 14.23 _MSC_VER == 1923 (Visual Studio 2019 version 16.3)\nMSVC++ 14.22 _MSC_VER == 1922 (Visual Studio 2019 version 16.2)\nMSVC++ 14.21 _MSC_VER == 1921 (Visual Studio 2019 version 16.1)\nMSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 version 16.0)\nMSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)\nMSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)\nMSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)\nMSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)\nMSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)\nMSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)\nMSVC++ 14.1 _MSC_VER == 1910 (Visual Studio 2017 version 15.0)\nMSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015 version 14.0)\nMSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013 version 12.0)\nMSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012 version 11.0)\nMSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010 version 10.0)\nMSVC++ 9.0 _MSC_FULL_VER == 150030729 (Visual Studio 2008, SP1)\nMSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008 version 9.0)\nMSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005 version 8.0)\nMSVC++ 7.1 _MSC_VER == 1310 (Visual Studio .NET 2003 version 7.1)\nMSVC++ 7.0 _MSC_VER == 1300 (Visual Studio .NET 2002 version 7.0)\nMSVC++ 6.0 _MSC_VER == 1200 (Visual Studio 6.0 version 6.0)\nMSVC++ 5.0 _MSC_VER == 1100 (Visual Studio 97 version 5.0)\n cl.exe /? c:\\program files (x86)\\microsoft visual studio 11.0\\vc\\bin>cl /?\nMicrosoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x86\n.....\n"
},
{
"answer_id": 81262,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "//******************************************************************************\n// Automated platform detection\n//******************************************************************************\n\n// _WIN32 is used by\n// Visual C++\n#ifdef _WIN32\n#define __NT__\n#endif\n\n// Define __MAC__ platform indicator\n#ifdef macintosh\n#define __MAC__\n#endif\n\n// Define __OSX__ platform indicator\n#ifdef __APPLE__\n#define __OSX__\n#endif\n\n// Define __WIN16__ platform indicator \n#ifdef _Windows_\n#ifndef __NT__\n#define __WIN16__\n#endif\n#endif\n\n// Define Windows CE platform indicator\n#ifdef WIN32_PLATFORM_HPCPRO\n#define __WINCE__\n#endif\n\n#if (_WIN32_WCE == 300) // for Pocket PC\n#define __POCKETPC__\n#define __WINCE__\n//#if (_WIN32_WCE == 211) // for Palm-size PC 2.11 (Wyvern)\n//#if (_WIN32_WCE == 201) // for Palm-size PC 2.01 (Gryphon) \n//#ifdef WIN32_PLATFORM_HPC2000 // for H/PC 2000 (Galileo)\n#endif\n"
},
{
"answer_id": 3786113,
"author": "display101",
"author_id": 167899,
"author_profile": "https://Stackoverflow.com/users/167899",
"pm_score": 6,
"selected": false,
"text": "<compiler-major-version>.00.<build-number> _MSC_VER <major-version><minor-version> #if (_MSC_VER == 1500)\n // ... Do VC9/Visual Studio 2008 specific stuff\n#elif (_MSC_VER == 1600)\n // ... Do VC10/Visual Studio 2010 specific stuff\n#elif (_MSC_VER == 1700)\n // ... Do VC11/Visual Studio 2012 specific stuff\n#endif\n compiler-minor-version #if (_MSC_VER >= 1500 && _MSC_VER <= 1600)\n // ... Do VC9/Visual Studio 2008 specific stuff\n#endif\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11234/"
] |
70,074 |
<p>I'm new to Ruby, so I'm having some trouble understanding this weird exception problem I'm having. I'm using the ruby-aaws gem to access Amazon ECS: <a href="http://www.caliban.org/ruby/ruby-aws/" rel="nofollow noreferrer">http://www.caliban.org/ruby/ruby-aws/</a>. This defines a class Amazon::AWS:Error:</p>
<pre><code>module Amazon
module AWS
# All dynamically generated exceptions occur within this namespace.
#
module Error
# An exception generator class.
#
class AWSError
attr_reader :exception
def initialize(xml)
err_class = xml.elements['Code'].text.sub( /^AWS.*\./, '' )
err_msg = xml.elements['Message'].text
unless Amazon::AWS::Error.const_defined?( err_class )
Amazon::AWS::Error.const_set( err_class,
Class.new( StandardError ) )
end
ex_class = Amazon::AWS::Error.const_get( err_class )
@exception = ex_class.new( err_msg )
end
end
end
end
end
</code></pre>
<p>This means that if you get an errorcode like <code>AWS.InvalidParameterValue</code>, this will produce (in its exception variable) a new class <code>Amazon::AWS::Error::InvalidParameterValue</code> which is a subclass of <code>StandardError</code>.</p>
<p>Now here's where it gets weird. I have some code that looks like this:</p>
<pre><code>begin
do_aws_stuff
rescue Amazon::AWS::Error => error
puts "Got an AWS error"
end
</code></pre>
<p>Now, if <code>do_aws_stuff</code> throws a <code>NameError</code>, my rescue block gets triggered. It seems that Amazon::AWS::Error isn't the superclass of the generated error - I guess since it's a module everything is a subclass of it? Certainly if I do:</p>
<pre><code>irb(main):007:0> NameError.new.kind_of?(Amazon::AWS::Error)
=> true
</code></pre>
<p>It says <code>true</code>, which I find confusing, especially given this:</p>
<pre><code>irb(main):009:0> NameError.new.kind_of?(Amazon::AWS)
=> false
</code></pre>
<p>What's going on, and how am I supposed to separate out AWS errors from other type of errors? Should I do something like:</p>
<pre><code>begin
do_aws_stuff
rescue => error
if error.class.to_s =~ /^Amazon::AWS::Error/
puts "Got an AWS error"
else
raise error
end
end
</code></pre>
<p>That seems exceptionally janky. The errors thrown aren't class AWSError either - they're raised like this:</p>
<pre><code>error = Amazon::AWS::Error::AWSError.new( xml )
raise error.exception
</code></pre>
<p>So the exceptions I'm looking to <code>rescue</code> from are the generated exception types that only inherit from StandardError.</p>
<p>To clarify, I have two questions:</p>
<ol>
<li><p>Why is NameError, a Ruby built in exception, a <code>kind_of?(Amazon::AWS::Error)</code>, which is a module?<br>
<strong>Answer:</strong> I had said <code>include Amazon::AWS::Error</code> at the top of my file, thinking it was kind of like a Java import or C++ include. What this actually did was add everything defined in <code>Amazon::AWS::Error</code> (present and future) to the implicit Kernel class, which is an ancestor of every class. This means <strong>anything</strong> would pass <code>kind_of?(Amazon::AWS::Error)</code>.</p></li>
<li><p>How can I best distinguish the dynamically-created exceptions in <code>Amazon::AWS::Error</code> from random other exceptions from elsewhere?</p></li>
</ol>
|
[
{
"answer_id": 70127,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 1,
"selected": false,
"text": "Class.new( StandardError )\n"
},
{
"answer_id": 70231,
"author": "Jean",
"author_id": 7898,
"author_profile": "https://Stackoverflow.com/users/7898",
"pm_score": 4,
"selected": true,
"text": "module A\n module B\n module Error\n def foobar\n puts \"foo\"\n end\n end\n end\nend\n\nclass StandardError\n include A::B::Error\nend\n\nStandardError.new.kind_of?(A::B::Error)\nStandardError.new.kind_of?(A::B)\nStandardError.included_modules #=> [A::B::Error,Kernel]\n class Class\n def has_module?(module_ref)\n if self.included_modules.include?(module_ref) and not self.superclass.included_modules.include?(module_ref) \n puts self.name+\" has module \"+ module_ref.name \n else\n self.superclass.nil? ? false : self.superclass.has_module?(module_ref)\n end \n end\nend\nStandardError.has_module?(A::B::Error)\nNameError.has_module?(A::B::Error)\n begin \n#do AWS error prone stuff\nrescue Exception => e\n if Amazon::AWS::Error.constants.include?(e.class.name)\n #awsError\n else\n whatever\n end \nend\n A couple of points about the include statement before we go on. First, it has nothing to do with files. C programmers use a preprocessor directive called #include to insert the contents of one file into another during compilation. The Ruby include statement simply makes a reference to a named module. If that module is in a separate file, you must use require to drag that file in before using include."
},
{
"answer_id": 71517,
"author": "0124816",
"author_id": 11521,
"author_profile": "https://Stackoverflow.com/users/11521",
"pm_score": 1,
"selected": false,
"text": " unless Amazon::AWS::Error.const_defined?( err_class )\n kls = Class.new( StandardError )\n Amazon::AWS::Error.const_set(err_class, kls)\n kls.include Amazon::AWS::Error\n end\n"
},
{
"answer_id": 1517791,
"author": "Peter Wagenet",
"author_id": 181916,
"author_profile": "https://Stackoverflow.com/users/181916",
"pm_score": 0,
"selected": false,
"text": "Amazon::AWS::Error::AWSError raise exception Exception exception raise Exception.new(\"Something is wrong\") AWSError exception Amazon::AWS::Error::SOME_ERROR raise Amazon::AWS::Error::AWSError.new(SOME_XML) Amazon::AWS::Error::AWSError.new(SOME_XML).exception Amazon::AWS::Error::SOME_ERROR StandardError"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11284/"
] |
70,090 |
<p>How can I visually customize autocomplete fields in Wicket (change colors, fonts, etc.)?</p>
|
[
{
"answer_id": 77292,
"author": "Loren_",
"author_id": 13703,
"author_profile": "https://Stackoverflow.com/users/13703",
"pm_score": 4,
"selected": true,
"text": "div.wicket-aa {\n background-color:white;\n border:1px solid #CCCCCC;\n color:black;\n}\ndiv.wicket-aa ul {\n list-style-image:none;\n list-style-position:outside;\n list-style-type:none;\n margin:0pt;\n padding:5px;\n}\ndiv.wicket-aa ul li.selected {\n background-color:#CCCCCC;\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11384/"
] |
70,096 |
<p>I've been looking for a way to convert an mp3 to aac programmatically or via the command line with no luck. Ideally, I'd have a snippet of code that I could call from my rails app that converts an mp3 to an aac. I installed ffmpeg and libfaac and was able to create an aac file with the following command:</p>
<p><code>ffmpeg -i test.mp3 -acodec libfaac -ab 163840 dest.aac</code></p>
<p>When i change the output file's name to dest.m4a, it doesn't play in iTunes. </p>
<p>Thanks! </p>
|
[
{
"answer_id": 70138,
"author": "rpetrich",
"author_id": 4007,
"author_profile": "https://Stackoverflow.com/users/4007",
"pm_score": 4,
"selected": true,
"text": "ffmpeg -i source.mp3 -acodec libfaac -ab 128k dest.aac\n"
},
{
"answer_id": 72678,
"author": "dmckee --- ex-moderator kitten",
"author_id": 2509,
"author_profile": "https://Stackoverflow.com/users/2509",
"pm_score": 0,
"selected": false,
"text": "#!/bin/sh\n\nTARGET=$1\n\nBASE=`basename \"${TARGET}\"`\necho TARGET: \"${TARGET}\"\necho BASE: \"${BASE}\" .m4a\n\n# Warning! Race condition vulnerability here! Should use a mktemp\n# variant or something...\nmkfifo encode\nmplayer -quiet -ao pcm -aofile encode \"${TARGET}\" &\nlame --silent encode \"${BASE}\".mp3\nrm encode\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
70,109 |
<p>I'm writing an ASP.Net webform with some DropDownList controls on it. Then user changes selected item in one of dropdowns, ASP.Net doesn't seem to handle SelectedIndexChanged event until form is submitted with a 'Submit' button click.
How do I make my dropdowns handle SelectedIndexChanged instantly?</p>
<p>P.S. It's a classic question I have answered too many times, but it seems no one asked it before on stackoverflow.</p>
|
[
{
"answer_id": 70155,
"author": "Chris Roberts",
"author_id": 475,
"author_profile": "https://Stackoverflow.com/users/475",
"pm_score": 4,
"selected": false,
"text": "AutoPostBack If Not IsPostBack ItemCommand"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9024/"
] |
70,143 |
<p>I have a xslt stylesheet with multiple <code>xsl:import</code>s and I want to merge them all into the one xslt file.</p>
<p>It is a limitation of the system we are using where it passes around the xsl stylesheet as a string object stored in memory. This is transmitted to remote machine where it performs the transformation. Since it is not being loaded from disk the href links are broken, so we need to remove the <code>xsl:import</code>s from the stylesheet.</p>
<p>Are there any tools out there which can do this?</p>
|
[
{
"answer_id": 70591,
"author": "Christian Berg",
"author_id": 5035,
"author_profile": "https://Stackoverflow.com/users/5035",
"pm_score": 5,
"selected": true,
"text": "<?xml version=\"1.0\" ?>\n<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" \n version=\"1.0\">\n\n<xsl:template match=\"xsl:include\">\n <xsl:copy-of select=\"document(@href)/xsl:stylesheet/*\"/>\n</xsl:template>\n\n<xsl:template match=\"@*|node()\">\n <xsl:copy>\n <xsl:apply-templates select=\"@*|node()\"/>\n </xsl:copy>\n</xsl:template>\n\n</xsl:stylesheet>\n"
},
{
"answer_id": 1031921,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": " import multiple xsl in single xsl\n\n <xsl:import href=\"FpML_FXOption_Trade_Template1.xsl\"/>\n <xsl:apply-imports/>\n\n<calypso:keyword>\n <calypso:name>DisplayOptionStyle</calypso:name>\n<calypso:value>Vanilla</calypso:value>\n</calypso:keyword>\n\n <xsl:import href=\"FpML_FXOption_Trade_Template2.xsl\"/>\n <xsl:apply-imports/>\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70143",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/716/"
] |
70,150 |
<p>I am looking for attributes I can use to ensure the best runtime performance for my .Net application by giving hints to the loader, JIT compiler or ngen.</p>
<p>For example we have <a href="http://msdn.microsoft.com/en-us/library/k2wxda47.aspx" rel="noreferrer">DebuggableAttribute</a> which should be set to not debug and not disable optimization for optimal performance.</p>
<pre><code>[Debuggable(false, false)]
</code></pre>
<p>Are there any others I should know about?</p>
|
[
{
"answer_id": 70168,
"author": "Lars Truijens",
"author_id": 1242,
"author_profile": "https://Stackoverflow.com/users/1242",
"pm_score": 1,
"selected": false,
"text": "[NeutralResourcesLanguageAttribute(\"nl\", UltimateResourceFallbackLocation.MainAssembly)]\n"
},
{
"answer_id": 74912,
"author": "Lars Truijens",
"author_id": 1242,
"author_profile": "https://Stackoverflow.com/users/1242",
"pm_score": 2,
"selected": false,
"text": "string s1 = \"MyTest\"; \nstring s2 = new StringBuilder().Append(\"My\").Append(\"Test\").ToString(); \nstring s3 = String.Intern(s2); \nConsole.WriteLine((Object)s2==(Object)s1); // Different references.\nConsole.WriteLine((Object)s3==(Object)s1); // The same reference.\n [assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)]\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1242/"
] |
70,161 |
<p>As we all know numbers can be written either in numerics, or called by their names. While there are a lot of examples to be found that convert 123 into one hundred twenty three, I could not find good examples of how to convert it the other way around.</p>
<p>Some of the caveats:</p>
<ol>
<li>cardinal/nominal or ordinal: "one" and "first"</li>
<li>common spelling mistakes: "forty"/"fourty"</li>
<li>hundreds/thousands: 2100 -> "twenty one hundred" and also "two thousand and one hundred"</li>
<li>separators: "eleven hundred fifty two", but also "elevenhundred fiftytwo" or "eleven-hundred fifty-two" and whatnot</li>
<li>colloquialisms: "thirty-something"</li>
<li>fractions: 'one third', 'two fifths'</li>
<li>common names: 'a dozen', 'half'</li>
</ol>
<p>And there are probably more caveats possible that are not yet listed.
Suppose the algorithm needs to be very robust, and even understand spelling mistakes.</p>
<p>What fields/papers/studies/algorithms should I read to learn how to write all this?
Where is the information?</p>
<blockquote>
<p>PS: My final parser should actually understand 3 different languages, English, Russian and Hebrew. And maybe at a later stage more languages will be added. Hebrew also has male/female numbers, like "one man" and "one woman" have a different "one" — "ehad" and "ahat". Russian also has some of its own complexities.</p>
</blockquote>
<p>Google does a great job at this. For example:</p>
<p><a href="http://www.google.com/search?q=two+thousand+and+one+hundred+plus+five+dozen+and+four+fifths+in+decimal" rel="noreferrer">http://www.google.com/search?q=two+thousand+and+one+hundred+plus+five+dozen+and+four+fifths+in+decimal</a></p>
<p>(the reverse is also possible <a href="http://www.google.com/search?q=999999999999+in+english" rel="noreferrer">http://www.google.com/search?q=999999999999+in+english</a>)</p>
|
[
{
"answer_id": 653098,
"author": "MarkusQ",
"author_id": 62970,
"author_profile": "https://Stackoverflow.com/users/62970",
"pm_score": 7,
"selected": true,
"text": "\"one\" -> 1, \"two\" -> 2, ... \"twenty\" -> 20,\n\"dozen\" -> 12, \"score\" -> 20, ...\n\"hundred\" -> 100, \"thousand\" -> 1000, \"million\" -> 1000000\n total = 0\nprior = null\nfor each word w\n v <- value(w) or next if no value defined\n prior <- case\n when prior is null: v\n when prior > v: prior+v\n else prior*v\n else\n if w in {thousand,million,billion,trillion...}\n total <- total + prior\n prior <- null\ntotal = total + prior unless prior is null\n total prior v unconsumed string\n 0 _ four score and seven \n 4 score and seven \n 0 4 \n 20 and seven \n 0 80 \n _ seven \n 0 80 \n 7 \n 0 87 \n 87\n\ntotal prior v unconsumed string\n 0 _ two million four hundred twelve thousand eight hundred seven\n 2 million four hundred twelve thousand eight hundred seven\n 0 2\n 1000000 four hundred twelve thousand eight hundred seven\n2000000 _\n 4 hundred twelve thousand eight hundred seven\n2000000 4\n 100 twelve thousand eight hundred seven\n2000000 400\n 12 thousand eight hundred seven\n2000000 412\n 1000 eight hundred seven\n2000000 412000\n 1000 eight hundred seven\n2412000 _\n 8 hundred seven\n2412000 8\n 100 seven\n2412000 800\n 7\n2412000 807\n2412807\n"
},
{
"answer_id": 653113,
"author": "chaos",
"author_id": 47529,
"author_profile": "https://Stackoverflow.com/users/47529",
"pm_score": 2,
"selected": false,
"text": "internal mapping inordinal = ([]);\ninternal mapping number = ([]);\n\n#define Numbers ([\\\n \"zero\" : 0, \\\n \"one\" : 1, \\\n \"two\" : 2, \\\n \"three\" : 3, \\\n \"four\" : 4, \\\n \"five\" : 5, \\\n \"six\" : 6, \\\n \"seven\" : 7, \\\n \"eight\" : 8, \\\n \"nine\" : 9, \\\n \"ten\" : 10, \\\n \"eleven\" : 11, \\\n \"twelve\" : 12, \\\n \"thirteen\" : 13, \\\n \"fourteen\" : 14, \\\n \"fifteen\" : 15, \\\n \"sixteen\" : 16, \\\n \"seventeen\" : 17, \\\n \"eighteen\" : 18, \\\n \"nineteen\" : 19, \\\n \"twenty\" : 20, \\\n \"thirty\" : 30, \\\n \"forty\" : 40, \\\n \"fifty\" : 50, \\\n \"sixty\" : 60, \\\n \"seventy\" : 70, \\\n \"eighty\" : 80, \\\n \"ninety\" : 90, \\\n \"hundred\" : 100, \\\n \"thousand\" : 1000, \\\n \"million\" : 1000000, \\\n \"billion\" : 1000000000, \\\n])\n\n#define Ordinals ([\\\n \"zeroth\" : 0, \\\n \"first\" : 1, \\\n \"second\" : 2, \\\n \"third\" : 3, \\\n \"fourth\" : 4, \\\n \"fifth\" : 5, \\\n \"sixth\" : 6, \\\n \"seventh\" : 7, \\\n \"eighth\" : 8, \\\n \"ninth\" : 9, \\\n \"tenth\" : 10, \\\n \"eleventh\" : 11, \\\n \"twelfth\" : 12, \\\n \"thirteenth\" : 13, \\\n \"fourteenth\" : 14, \\\n \"fifteenth\" : 15, \\\n \"sixteenth\" : 16, \\\n \"seventeenth\" : 17, \\\n \"eighteenth\" : 18, \\\n \"nineteenth\" : 19, \\\n \"twentieth\" : 20, \\\n \"thirtieth\" : 30, \\\n \"fortieth\" : 40, \\\n \"fiftieth\" : 50, \\\n \"sixtieth\" : 60, \\\n \"seventieth\" : 70, \\\n \"eightieth\" : 80, \\\n \"ninetieth\" : 90, \\\n \"hundredth\" : 100, \\\n \"thousandth\" : 1000, \\\n \"millionth\" : 1000000, \\\n \"billionth\" : 1000000000, \\\n])\n\nvarargs int denumerical(string num, status ordinal) {\n if(ordinal) {\n if(member(inordinal, num))\n return inordinal[num];\n } else {\n if(member(number, num))\n return number[num];\n }\n int sign = 1;\n int total = 0;\n int sub = 0;\n int value;\n string array parts = regexplode(num, \" |-\");\n if(sizeof(parts) >= 2 && parts[0] == \"\" && parts[1] == \"-\")\n sign = -1;\n for(int ix = 0, int iix = sizeof(parts); ix < iix; ix++) {\n string part = parts[ix];\n switch(part) {\n case \"negative\" :\n case \"minus\" :\n sign = -1;\n continue;\n case \"\" :\n continue;\n }\n if(ordinal && ix == iix - 1) {\n if(part[0] >= '0' && part[0] <= '9' && ends_with(part, \"th\"))\n value = to_int(part[..<3]);\n else if(member(Ordinals, part))\n value = Ordinals[part];\n else\n continue;\n } else {\n if(part[0] >= '0' && part[0] <= '9')\n value = to_int(part);\n else if(member(Numbers, part))\n value = Numbers[part];\n else\n continue;\n }\n if(value < 0) {\n sign = -1;\n value = - value;\n }\n if(value < 10) {\n if(sub >= 1000) {\n total += sub;\n sub = value;\n } else {\n sub += value;\n }\n } else if(value < 100) {\n if(sub < 10) {\n sub = 100 * sub + value;\n } else if(sub >= 1000) {\n total += sub;\n sub = value;\n } else {\n sub *= value;\n }\n } else if(value < sub) {\n total += sub;\n sub = value;\n } else if(sub == 0) {\n sub = value;\n } else {\n sub *= value;\n }\n }\n total += sub;\n return sign * total;\n}\n"
},
{
"answer_id": 654409,
"author": "fmsf",
"author_id": 26004,
"author_profile": "https://Stackoverflow.com/users/26004",
"pm_score": 3,
"selected": false,
"text": "One Thousand\nOne Million\nOne Thousand Millions (British also use Milliard)\nOne Billion\nOne Thousand Billions\nOne Trillion\nOne Thousand Trillions\n (American counting Trillion) == (European counting Billion)\n"
},
{
"answer_id": 668360,
"author": "LarryF",
"author_id": 18518,
"author_profile": "https://Stackoverflow.com/users/18518",
"pm_score": 2,
"selected": false,
"text": "(?<Value>(?:zero)|(?:one|first)|(?:two|second)|(?:three|third)|(?:four|fourth)|\n(?:five|fifth)|(?:six|sixth)|(?:seven|seventh)|(?:eight|eighth)|(?:nine|ninth)|\n(?:ten|tenth)|(?:eleven|eleventh)|(?:twelve|twelfth)|(?:thirteen|thirteenth)|\n(?:fourteen|fourteenth)|(?:fifteen|fifteenth)|(?:sixteen|sixteenth)|\n(?:seventeen|seventeenth)|(?:eighteen|eighteenth)|(?:nineteen|nineteenth)|\n(?:twenty|twentieth)|(?:thirty|thirtieth)|(?:forty|fortieth)|(?:fifty|fiftieth)|\n(?:sixty|sixtieth)|(?:seventy|seventieth)|(?:eighty|eightieth)|(?:ninety|ninetieth)|\n(?<Magnitude>(?:hundred|hundredth)|(?:thousand|thousandth)|(?:million|millionth)|\n(?:billion|billionth)))\n char *ones[] = {\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\", \"eleven\", \"twelve\",\n \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\"};\nchar *tens[] = {\"\", \"\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\"};\nchar *ordinalones[] = { \"\", \"first\", \"second\", \"third\", \"fourth\", \"fifth\", \"\", \"\", \"\", \"\", \"\", \"\", \"twelfth\" };\nchar *ordinaltens[] = { \"\", \"\", \"twentieth\", \"thirtieth\", \"fortieth\", \"fiftieth\", \"sixtieth\", \"seventieth\", \"eightieth\", \"ninetieth\" };\nand so on...\n"
},
{
"answer_id": 6925837,
"author": "Alex Brooks",
"author_id": 177674,
"author_profile": "https://Stackoverflow.com/users/177674",
"pm_score": 3,
"selected": false,
"text": ">>> from pattern.en import number\n>>> number('two thousand fifty and a half') => 2050.5\n"
},
{
"answer_id": 8112142,
"author": "Mike Mattie",
"author_id": 1044238,
"author_profile": "https://Stackoverflow.com/users/1044238",
"pm_score": 2,
"selected": false,
"text": ";----------------------------------------------------------------------\n; numbers.clj\n; written by: Mike Mattie [email protected]\n;----------------------------------------------------------------------\n(ns operator.numbers\n (:use compojure.core)\n\n (:require\n [clojure.string :as string] ))\n\n(def number-word-table {\n \"zero\" 0\n \"one\" 1\n \"two\" 2\n \"three\" 3\n \"four\" 4\n \"five\" 5\n \"six\" 6\n \"seven\" 7\n \"eight\" 8\n \"nine\" 9\n \"ten\" 10\n \"eleven\" 11\n \"twelve\" 12\n \"thirteen\" 13\n \"fourteen\" 14\n \"fifteen\" 15\n \"sixteen\" 16\n \"seventeen\" 17\n \"eighteen\" 18\n \"nineteen\" 19\n \"twenty\" 20\n \"thirty\" 30\n \"fourty\" 40\n \"fifty\" 50\n \"sixty\" 60\n \"seventy\" 70\n \"eighty\" 80\n \"ninety\" 90\n})\n\n(def multiplier-word-table {\n \"hundred\" 100\n \"thousand\" 1000\n})\n\n(defn sum-words-to-number [ words ]\n (apply + (map (fn [ word ] (number-word-table word)) words)) )\n\n; are you down with the sickness ?\n(defn words-to-number [ words ]\n (let\n [ n (count words)\n\n multipliers (filter (fn [x] (not (false? x))) (map-indexed\n (fn [ i word ]\n (if (contains? multiplier-word-table word)\n (vector i (multiplier-word-table word))\n false))\n words) )\n\n x (ref 0) ]\n\n (loop [ indices (reverse (conj (reverse multipliers) (vector n 1)))\n left 0\n combine + ]\n (let\n [ right (first indices) ]\n\n (dosync (alter x combine (* (if (> (- (first right) left) 0)\n (sum-words-to-number (subvec words left (first right)))\n 1)\n (second right)) ))\n\n (when (> (count (rest indices)) 0)\n (recur (rest indices) (inc (first right))\n (if (= (inc (first right)) (first (second indices)))\n *\n +))) ) )\n @x ))\n (operator.numbers/words-to-number [\"six\" \"thousand\" \"five\" \"hundred\" \"twenty\" \"two\"])\n(operator.numbers/words-to-number [\"fifty\" \"seven\" \"hundred\"])\n(operator.numbers/words-to-number [\"hundred\"])\n"
},
{
"answer_id": 41387461,
"author": "duhaime",
"author_id": 1727392,
"author_profile": "https://Stackoverflow.com/users/1727392",
"pm_score": 0,
"selected": false,
"text": "def get_data_mapping():\n data_mapping = {\n \"1st\": 1,\n \"2nd\": 2,\n \"3rd\": 3,\n\n \"tenth\": 10,\n \"eleventh\": 11,\n \"twelfth\": 12,\n \"thirteenth\": 13,\n \"fourteenth\": 14,\n \"fifteenth\": 15,\n \"sixteenth\": 16,\n \"seventeenth\": 17,\n \"eighteenth\": 18,\n \"nineteenth\": 19,\n \"twentieth\": 20,\n\n \"new\": 2,\n \"newly\": 2,\n \"nova\": 2,\n \"nouvelle\": 2,\n \"altera\": 2,\n \"andere\": 2,\n\n # latin\n \"primus\": 1,\n \"secunda\": 2,\n \"tertia\": 3,\n \"quarta\": 4,\n \"quinta\": 5,\n \"sexta\": 6,\n \"septima\": 7,\n \"octava\": 8,\n \"nona\": 9,\n \"decima\": 10,\n\n # italian\n \"primo\": 1,\n \"secondo\": 2,\n \"terzo\": 3,\n \"quarto\": 4,\n \"quinto\": 5,\n \"sesto\": 6,\n \"settimo\": 7,\n \"ottavo\": 8,\n \"nono\": 9,\n \"decimo\": 10,\n\n # french\n \"premier\": 1,\n \"deuxième\": 2,\n \"troisième\": 3,\n \"quatrième\": 4,\n \"cinquième\": 5,\n \"sixième\": 6,\n \"septième\": 7,\n \"huitième\": 8,\n \"neuvième\": 9,\n \"dixième\": 10,\n\n # spanish\n \"primero\": 1,\n \"segundo\": 2,\n \"tercero\": 3,\n \"cuarto\": 4,\n \"quinto\": 5,\n \"sexto\": 6,\n \"septimo\": 7,\n \"octavo\": 8,\n \"noveno\": 9,\n \"decimo\": 10\n }\n\n # create 4th, 5th, ... 20th\n for i in xrange(16):\n data_mapping[str(4+i) + \"th\"] = 4+i\n\n # create 21st, 22nd, ... 99th\n for i in xrange(79):\n last_char = str(i)[-1]\n\n if last_char == \"0\":\n data_mapping[str(20+i) + \"th\"] = 20+i\n\n elif last_char == \"1\":\n data_mapping[str(20+i) + \"st\"] = 20+i\n\n elif last_char == \"2\":\n data_mapping[str(20+i) + \"nd\"] = 20+i\n\n elif last_char == \"3\":\n data_mapping[str(20+i) + \"rd\"] = 20+i\n\n else:\n data_mapping[str(20+i) + \"th\"] = 20+i\n\n ordinals = [\n \"first\", \"second\", \"third\", \n \"fourth\", \"fifth\", \"sixth\", \n \"seventh\", \"eighth\", \"ninth\"\n ]\n\n # create first, second ... ninth\n for c, i in enumerate(ordinals):\n data_mapping[i] = c+1\n\n # create twenty-first, twenty-second ... ninty-ninth\n for ci, i in enumerate([\n \"twenty\", \"thirty\", \"forty\", \n \"fifty\", \"sixty\", \"seventy\", \n \"eighty\", \"ninety\"\n ]):\n for cj, j in enumerate(ordinals):\n data_mapping[i + \"-\" + j] = 20 + (ci*10) + (cj+1)\n data_mapping[i.replace(\"y\", \"ieth\")] = 20 + (ci*10)\n\n return data_mapping\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11414/"
] |
70,170 |
<p>I have an Java desktop application which connects directly with the DB (an Oracle). The application has multiple user accounts. What is the correct method to send the user's password (not DB password) over the network? I don't want to send it in plain text.</p>
|
[
{
"answer_id": 70469,
"author": "Rejeev Divakaran",
"author_id": 10980,
"author_profile": "https://Stackoverflow.com/users/10980",
"pm_score": 2,
"selected": false,
"text": "LISTENER = (ADDRESS_LIST= (ADDRESS=(PROTOCOL=tcps)(HOST=servername)(PORT=2484)))\n\nWALLET_LOCATION=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=/server/wallet/path/)))\n ojdb14.jar oraclepki.jar ojpse.jar jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=servername)(PORT=2484))(CONNECT_DATA=(SERVICE_NAME=servicename)))\n javax.net.ssl.trustStore, \njavax.net.ssl.trustStoreType, \njavax.net.ssl.trustStorePassword\n"
},
{
"answer_id": 75725,
"author": "eckes",
"author_id": 13189,
"author_profile": "https://Stackoverflow.com/users/13189",
"pm_score": 0,
"selected": false,
"text": "ORA_ENCRYPT_LOGIN=true"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/518/"
] |
70,197 |
<p>How do I declare "as any" in VB.NET, or what is the equivalent?</p>
|
[
{
"answer_id": 70227,
"author": "Grokys",
"author_id": 6448,
"author_profile": "https://Stackoverflow.com/users/6448",
"pm_score": 2,
"selected": false,
"text": "Dim var as Object"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70197",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11420/"
] |
70,216 |
<p>In Java, you often see a META-INF folder containing some meta files. What is the purpose of this folder and what can I put there?</p>
|
[
{
"answer_id": 70221,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 8,
"selected": false,
"text": "MANIFEST.MF INDEX.LIST -i x.SF x.DSA services/ versions"
},
{
"answer_id": 70253,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 7,
"selected": true,
"text": "<jar ...>\n <manifest>\n <attribute name=\"Main-Class\" value=\"MyApplication\"/>\n </manifest>\n</jar>\n"
},
{
"answer_id": 315588,
"author": "user38748",
"author_id": 38748,
"author_profile": "https://Stackoverflow.com/users/38748",
"pm_score": 5,
"selected": false,
"text": "<import resource=\"classpath:/META-INF/cxf/cxf.xml\" />\n<import resource=\"classpath:/META-INF/cxf/cxf-extensions-*.xml\" />\n"
},
{
"answer_id": 1609825,
"author": "f0ster",
"author_id": 157460,
"author_profile": "https://Stackoverflow.com/users/157460",
"pm_score": 2,
"selected": false,
"text": "persistence.xml import javax.persistence.EntityManagerFactory;\nimport javax.persistence.Persistence;\n\n// ...\n\nEntityManagerFactory emf =\n Persistence.createEntityManagerFactory(persistenceUnitName);\n"
},
{
"answer_id": 14340251,
"author": "Grim",
"author_id": 843943,
"author_profile": "https://Stackoverflow.com/users/843943",
"pm_score": 4,
"selected": false,
"text": "META-INF/resources/button.jpg \n http://localhost/myapp/button.jpg\n java -jar myjar.jar org.myserver.MyMainClass java -jar myjar.jar java.lang.Package.getPackage(\"org.myserver\").getImplementationTitle()"
},
{
"answer_id": 27905756,
"author": "EliuX",
"author_id": 3233398,
"author_profile": "https://Stackoverflow.com/users/3233398",
"pm_score": 4,
"selected": false,
"text": "classpath:/META-INF/resources/"
},
{
"answer_id": 33640221,
"author": "Prateek Joshi",
"author_id": 4281711,
"author_profile": "https://Stackoverflow.com/users/4281711",
"pm_score": 0,
"selected": false,
"text": "MANIFEST.MF Source:"
},
{
"answer_id": 36800847,
"author": "Readren",
"author_id": 1154271,
"author_profile": "https://Stackoverflow.com/users/1154271",
"pm_score": 3,
"selected": false,
"text": "ClassLoader Enumerator<URL> ClassLoader#getSystemResources(String path) getSystemResources"
},
{
"answer_id": 70407970,
"author": "k_o_",
"author_id": 3351474,
"author_profile": "https://Stackoverflow.com/users/3351474",
"pm_score": 0,
"selected": false,
"text": "versions"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11429/"
] |
70,232 |
<p>I was wondering if there are any code or class libraries out there on how to implement multithreading or "green threading" in ActionScript.</p>
<p>As you've might seen, Scott Peterson is developing some kind of toolset, but I haven't found any more info on this other than his performance on the Adobe MAX Chicago event.</p>
<p>Regards Niclas</p>
|
[
{
"answer_id": 70335,
"author": "anirudhsasikumar",
"author_id": 11433,
"author_profile": "https://Stackoverflow.com/users/11433",
"pm_score": 1,
"selected": false,
"text": "start = getTimer();\n//thread is a ui component added to system manager that is redrawn each frame\nvar fr:Number = Math.floor(1000 / thread.systemManager.stage.frameRate);\ndue = start + fr;\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
70,258 |
<p>I am trying to build gdb for armv6 architecture. I will be compiling this package on a Fedora Linux-Intel x86 box. I read the process of installing the gdb, like</p>
<ol>
<li><p>Download the source pachage</p></li>
<li><p>run <code>configure -host</code></p></li>
<li><p><code>make</code></p></li>
</ol>
<p>But I got lost in the process because I was not able to make out what will be the host, target, needed for the <code>configure</code> script. </p>
<p>I need to basically be able to debug programs running on armv6 architecture board which runs linux kernel 2.6.21.5-cfs-v19. The gdb executable which I intend to obtain after compilation of the source also needs to be able to run on above mentioned configuration.</p>
<p>Now to get a working gdb executable for this configuration what steps should I follow? </p>
|
[
{
"answer_id": 9198236,
"author": "nodakai",
"author_id": 1190965,
"author_profile": "https://Stackoverflow.com/users/1190965",
"pm_score": 1,
"selected": false,
"text": "arm-linux arm-elf arm-elf arm-eabi"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2759376/"
] |
70,272 |
<p>I have an application with one form in it, and on the Load method I need to hide the form. </p>
<p>The form will display itself when it has a need to (think along the lines of a outlook 2003 style popup), but I can' figure out how to hide the form on load without something messy.</p>
<p>Any suggestions?</p>
|
[
{
"answer_id": 70282,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": -1,
"selected": false,
"text": "public Form1()\n{\n InitializeComponent();\n Hide(); // Also Visible = false can be used\n}\n\nprivate void Form1_Load(object sender, EventArgs e)\n{\n Thread.Sleep(10000);\n Show(); // Or visible = true;\n}\n"
},
{
"answer_id": 70296,
"author": "Grokys",
"author_id": 6448,
"author_profile": "https://Stackoverflow.com/users/6448",
"pm_score": 8,
"selected": true,
"text": "Application.Run(new MainForm());\n Form.Show() Form.Hide()"
},
{
"answer_id": 189045,
"author": "Tute",
"author_id": 4386,
"author_profile": "https://Stackoverflow.com/users/4386",
"pm_score": 5,
"selected": false,
"text": "private void MainForm_Load(object sender, EventArgs e)\n{\n if (Settings.Instance.HideAtStartup)\n {\n BeginInvoke(new MethodInvoker(delegate\n {\n Hide();\n }));\n }\n}\n"
},
{
"answer_id": 403898,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "using System.Windows.Forms;\n\nnamespace HideWindows\n{\n public class HideForm : Form\n {\n public HideForm()\n {\n Opacity = 0;\n ShowInTaskbar = false;\n }\n\n public new void Show()\n {\n Opacity = 100;\n ShowInTaskbar = true;\n\n Show(this);\n }\n }\n}\n namespace HideWindows\n{\n public partial class Form1 : HideForm\n {\n public Form1()\n {\n InitializeComponent();\n }\n }\n}\n"
},
{
"answer_id": 1173347,
"author": "Jon Onstott",
"author_id": 132374,
"author_profile": "https://Stackoverflow.com/users/132374",
"pm_score": -1,
"selected": false,
"text": "Me.Opacity = 0\nMe.ShowInTaskbar = false\n Me.Opacity = 100\nMe.ShowInTaskbar = true\n"
},
{
"answer_id": 2447201,
"author": "kilsek",
"author_id": 293971,
"author_profile": "https://Stackoverflow.com/users/293971",
"pm_score": 0,
"selected": false,
"text": "static void Main()\n{\n Application.EnableVisualStyles();\n Application.SetCompatibleTextRenderingDefault(false);\n MainUIForm mainUiForm = new MainUIForm();\n mainUiForm.Visible = false;\n Application.Run();\n}\n"
},
{
"answer_id": 4210040,
"author": "Paul Aicher",
"author_id": 511439,
"author_profile": "https://Stackoverflow.com/users/511439",
"pm_score": 7,
"selected": false,
"text": "private bool allowshowdisplay = false;\n protected override void SetVisibleCore(bool value)\n{ \n base.SetVisibleCore(allowshowdisplay ? value : allowshowdisplay);\n}\n private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)\n{\n if (e.Button == System.Windows.Forms.MouseButtons.Left)\n {\n this.allowshowdisplay = true;\n this.Visible = !this.Visible; \n }\n}\n"
},
{
"answer_id": 5342362,
"author": "Jeff",
"author_id": 556470,
"author_profile": "https://Stackoverflow.com/users/556470",
"pm_score": 4,
"selected": false,
"text": " this.WindowState = FormWindowState.Minimized;\n this.ShowInTaskbar = false;\n if (!this.ShowInTaskbar)\n this.ShowInTaskbar = true;\n\n if (this.WindowState == FormWindowState.Minimized)\n this.WindowState = FormWindowState.Normal;\n"
},
{
"answer_id": 11831856,
"author": "Chriz",
"author_id": 1579761,
"author_profile": "https://Stackoverflow.com/users/1579761",
"pm_score": 4,
"selected": false,
"text": " protected override void OnLoad(EventArgs e)\n {\n Visible = false; // Hide form window.\n ShowInTaskbar = false; // Remove from taskbar.\n Opacity = 0;\n\n base.OnLoad(e);\n }\n"
},
{
"answer_id": 13785671,
"author": "echoen",
"author_id": 1889095,
"author_profile": "https://Stackoverflow.com/users/1889095",
"pm_score": 2,
"selected": false,
"text": " this.visible=false;\n /* to the InitializeComponent() code just before the */\n this.Load += new System.EventHandler(this.DebugOnOff_Load);\n this.visible=false;\n/* to the start of the load event, you get a\nsimple perfect working solution :) */ \nprivate void\nDebugOnOff_Load(object sender, EventArgs e)\n{\nthis.Visible = false;\n}\n"
},
{
"answer_id": 17342392,
"author": "steve_k",
"author_id": 1577871,
"author_profile": "https://Stackoverflow.com/users/1577871",
"pm_score": -1,
"selected": false,
"text": "Private Sub InitializeComponent()\n.\n.\n.\nMe.Location=New Point(-2000,-2000)\n.\n.\n.\nEnd Sub\n"
},
{
"answer_id": 36010671,
"author": "George",
"author_id": 4365852,
"author_profile": "https://Stackoverflow.com/users/4365852",
"pm_score": 2,
"selected": false,
"text": " public frmMain()\n {\n Program.MainForm = this;\n InitializeComponent();\n\n this.WindowState = FormWindowState.Minimized;\n this.ShowInTaskbar = false;\n }\n\nprivate void frmMain_Load(object sender, EventArgs e)\n {\n //Do heavy things here\n\n //At the end do this\n this.WindowState = FormWindowState.Maximized;\n this.ShowInTaskbar = true;\n }\n"
},
{
"answer_id": 40298412,
"author": "Metallic Skeleton",
"author_id": 4002198,
"author_profile": "https://Stackoverflow.com/users/4002198",
"pm_score": 3,
"selected": false,
"text": " protected override void OnLoad(EventArgs e)\n {\n Visible = false; // Hide form window.\n ShowInTaskbar = false; // Remove from taskbar.\n Opacity = 0;\n\n base.OnLoad(e);\n }\n"
},
{
"answer_id": 42573333,
"author": "Willy David Jr",
"author_id": 6542896,
"author_profile": "https://Stackoverflow.com/users/6542896",
"pm_score": 1,
"selected": false,
"text": "[STAThread]\n static void Main()\n {\n try\n {\n frmBase frm = new frmBase(); \n Application.Run();\n }\n"
},
{
"answer_id": 44384424,
"author": "LKane",
"author_id": 8118322,
"author_profile": "https://Stackoverflow.com/users/8118322",
"pm_score": 1,
"selected": false,
"text": "protected override void OnVisibleChanged(EventArgs e)\n{\n this.Visible = false;\n\n base.OnVisibleChanged(e);\n}\n public partial class MainForm : Form\n{\npublic bool hideForm = true;\n...\npublic MainForm (bool hideForm)\n {\n this.hideForm = hideForm;\n InitializeComponent();\n }\n...\nprotected override void OnVisibleChanged(EventArgs e)\n {\n if (this.hideForm)\n this.Visible = false;\n\n base.OnVisibleChanged(e);\n }\n...\n}\n"
},
{
"answer_id": 52763389,
"author": "Plague",
"author_id": 10490551,
"author_profile": "https://Stackoverflow.com/users/10490551",
"pm_score": 2,
"selected": false,
"text": "FormName FormName = new FormName ();\n\nFormName.ShowInTaskbar = false;\nFormName.Opacity = 0;\nFormName.Show();\nFormName.Hide();\n var principalForm = Application.OpenForms.OfType<FormName>().Single();\nprincipalForm.ShowInTaskbar = true;\nprincipalForm.Opacity = 100;\nprincipalForm.Show();\n"
},
{
"answer_id": 56698263,
"author": "Muhammad Rashed Nadeem",
"author_id": 1161905,
"author_profile": "https://Stackoverflow.com/users/1161905",
"pm_score": 0,
"selected": false,
"text": " static void Main()\n {\n Application.EnableVisualStyles();\n Application.SetCompatibleTextRenderingDefault(false);\n Form1 form1 = new Form1();\n form1.Visible = false;\n Application.Run();\n\n }\n private void ExitToolStripMenuItem_Click(object sender, EventArgs e)\n {\n this.Close();\n Application.Exit();\n }\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1500/"
] |
70,303 |
<p>I have a structure in C#:</p>
<pre><code>public struct UserInfo
{
public string str1
{
get;
set;
}
public string str2
{
get;
set;
}
}
</code></pre>
<p>The only rule is that <code>UserInfo(str1="AA", str2="BB").Equals(UserInfo(str1="BB", str2="AA"))</code></p>
<p>How to override the GetHashCode function for this structure? </p>
|
[
{
"answer_id": 70323,
"author": "VolkerK",
"author_id": 4833,
"author_profile": "https://Stackoverflow.com/users/4833",
"pm_score": 0,
"selected": false,
"text": "\nreturn str1.GetHashCode() ^ str1.GetHashCode()\n"
},
{
"answer_id": 70336,
"author": "Artem Tikhomirov",
"author_id": 2313,
"author_profile": "https://Stackoverflow.com/users/2313",
"pm_score": 1,
"selected": false,
"text": "(((long)str1.GetHashCode()) + ((long)str2.GetHashCode())).GetHashCode()\n"
},
{
"answer_id": 70373,
"author": "Omer van Kloeten",
"author_id": 4979,
"author_profile": "https://Stackoverflow.com/users/4979",
"pm_score": 0,
"selected": false,
"text": "if (str1 == null)\n if (str2 == null)\n return 0;\n else\n return str2.GetHashCode();\nelse\n if (str2 == null)\n return str1.GetHashCode();\n else\n return ((ulong)str1.GetHashCode() | ((ulong)str2.GetHashCode() << 32)).GetHashCode();\n"
},
{
"answer_id": 70375,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 7,
"selected": true,
"text": "GetHashCode GetHashCode GetHashCode Equals return str1.GetHashCode() ^ str2.GetHashCode() \n ^"
},
{
"answer_id": 70383,
"author": "Grokys",
"author_id": 6448,
"author_profile": "https://Stackoverflow.com/users/6448",
"pm_score": 2,
"selected": false,
"text": "return str1.GetHashCode() + str2.GetHashCode();\n return unchecked(str1.GetHashCode() + str2.GetHashCode());\n"
},
{
"answer_id": 70512,
"author": "Roger Willcocks",
"author_id": 11511,
"author_profile": "https://Stackoverflow.com/users/11511",
"pm_score": -1,
"selected": false,
"text": "if (null != str1) {\n return str1.GetHashCode();\n}\nif (null != str2) {\n return str2.GetHashCode();\n}\n//Not sure what you would put here, some constant value will do\nreturn 0;\n"
},
{
"answer_id": 70615,
"author": "user11556",
"author_id": 11556,
"author_profile": "https://Stackoverflow.com/users/11556",
"pm_score": 2,
"selected": false,
"text": "public override int GetHashCode() \n{ \n unchecked \n { \n return(str1 != null ? str1.GetHashCode() : 0) ^ (str2 != null ? str2.GetHashCode() : 0); \n } \n}\n"
},
{
"answer_id": 70739,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "public override int GetHashCode()\n{\n unchecked\n {\n return (str1 ?? String.Empty).GetHashCode() +\n (str2 ?? String.Empty).GetHashCode();\n }\n}\n"
},
{
"answer_id": 1027782,
"author": "Tomáš Kafka",
"author_id": 38729,
"author_profile": "https://Stackoverflow.com/users/38729",
"pm_score": 5,
"selected": false,
"text": "^"
},
{
"answer_id": 21604191,
"author": "Jani Hyytiäinen",
"author_id": 611056,
"author_profile": "https://Stackoverflow.com/users/611056",
"pm_score": 2,
"selected": false,
"text": "public int GetHashCode()\n{\n unchecked\n {\n int hashCode;\n\n // String properties\n hashCode = (hashCode * 397) ^ (str1!= null ? str1.GetHashCode() : 0);\n hashCode = (hashCode * 397) ^ (str2!= null ? str1.GetHashCode() : 0);\n\n // int properties\n hashCode = (hashCode * 397) ^ intProperty;\n return hashCode;\n }\n}\n"
},
{
"answer_id": 23545115,
"author": "Daniel Lidström",
"author_id": 286406,
"author_profile": "https://Stackoverflow.com/users/286406",
"pm_score": 2,
"selected": false,
"text": "return string.Format(\"{0}/{1}\", str1, str2).GetHashCode();\n null"
},
{
"answer_id": 67469888,
"author": "Pablo Retyk",
"author_id": 30729,
"author_profile": "https://Stackoverflow.com/users/30729",
"pm_score": 1,
"selected": false,
"text": "return (str1, str2).GetHashCode();\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70303",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3834/"
] |
70,313 |
<p>Working on implementing TFS throughout our organization. It is easy to integrate with <code>.NET</code> projects and any platform that uses Eclipse or a derivative of Eclipse for editing.<br>
What's the best way to use TFS version control with Xcode (now that I find out we need to write some iPhone apps)?</p>
|
[
{
"answer_id": 19292666,
"author": "Indra",
"author_id": 1699323,
"author_profile": "https://Stackoverflow.com/users/1699323",
"pm_score": 1,
"selected": false,
"text": "/users/{myuseraccount}/git-tf export JAVA_HOME=/Library/Java/Home\nexport PATH=$PATH:$JAVA_HOME/bin:/git_t\nexport PATH=\"/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/\":$PATH\nexport PATH=\"/Users/{myuseraccount}//Git-Tf/\":$PATH\n cd “/users/{myuseraccount}/documents/xCode Projects/testproject1/” - git remote add origin url//companyName.visualstudio.com/DefaultCollection/_git/xyz\n git push -u origin --all\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
70,318 |
<p>Experienced with Rails / ActiveRecord 2.1.1</p>
<ul>
<li>You create a first version with (for example) ruby script\generate scaffold product title:string description:text image_url:string</li>
<li>This create (for example) a migration file called 20080910122415_create_products.rb</li>
<li>You apply the migration with rake db:migrate</li>
<li>Now, you add a field to the product table with ruby script\generate migration add_price_to_product price:decimal</li>
<li>This create a migration file called 20080910125745_add_price_to_product.rb</li>
<li>If you try to run rake db:migrate, it will actually revert the first migration, not apply the next one! So your product table will get destroyed!</li>
<li>But if you ran rake alone, it would have told you that one migration was pending</li>
</ul>
<p>Pls note that applying rake db:migrate (once the table has been destroyed) will apply all migrations in order.</p>
<p>The only workaround I found is to specify the version of the new migration as in: </p>
<pre><code>rake db:migrate version=20080910125745
</code></pre>
<p>So I'm wondering: is this an expected new behavior?</p>
|
[
{
"answer_id": 70771,
"author": "Jean",
"author_id": 7898,
"author_profile": "https://Stackoverflow.com/users/7898",
"pm_score": 2,
"selected": true,
"text": "rake db:migrate:up \n rake db:migrate \n desc \"Migrate the database through scripts in db/migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false.\"\ntask :migrate => :environment do\n ActiveRecord::Migration.verbose = ENV[\"VERBOSE\"] ? ENV[\"VERBOSE\"] == \"true\" : true\n ActiveRecord::Migrator.migrate(\"db/migrate/\", ENV[\"VERSION\"] ? ENV[\"VERSION\"].to_i : nil)\n Rake::Task[\"db:schema:dump\"].invoke if ActiveRecord::Base.schema_format == :ruby\nend\n echo %Version% #=> V3.5.0f\n ENV[\"VERSION\"] # => V3.5.0f\nENV[\"VERSION\"].to_i #=>0 not nil !\n ActiveRecord::Migrator.migrate(\"db/migrate/\", 0)\n class Migrator#:nodoc:\n class << self\n def migrate(migrations_path, target_version = nil)\n case\n when target_version.nil? then up(migrations_path, target_version)\n when current_version > target_version then down(migrations_path, target_version)\n else up(migrations_path, target_version)\n end\n end\n rake db:migrate VERSION=0 rake db:migrate:down"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70318",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11477/"
] |
70,324 |
<p>What is the main difference between an inner class and a static nested class in Java? Does design / implementation play a role in choosing one of these?</p>
|
[
{
"answer_id": 70339,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 3,
"selected": false,
"text": "public class A {\n public class B {\n }\n}\n public class A {\n}\n\nA anon = new A() { /* You could change behavior of A here */ };\n"
},
{
"answer_id": 70349,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 3,
"selected": false,
"text": "public class Outer {\n public class Inner {}\n\n public static class Nested {}\n}\n"
},
{
"answer_id": 70358,
"author": "Martin",
"author_id": 11357,
"author_profile": "https://Stackoverflow.com/users/11357",
"pm_score": 12,
"selected": true,
"text": "OuterClass.StaticNestedClass\n OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();\n class OuterClass {\n ...\n class InnerClass {\n ...\n }\n}\n OuterClass outerObject = new OuterClass()\nOuterClass.InnerClass innerObject = outerObject.new InnerClass();\n class A {\n int t() { return 1; }\n static A a = new A() { int t() { return 2; } };\n}\n new A() { ... }"
},
{
"answer_id": 70613,
"author": "jrudolph",
"author_id": 7647,
"author_profile": "https://Stackoverflow.com/users/7647",
"pm_score": 7,
"selected": false,
"text": "public class Container {\n public class Item{\n Object data;\n public Container getContainer(){\n return Container.this;\n }\n public Item(Object data) {\n super();\n this.data = data;\n }\n\n }\n\n public static Item create(Object data){\n // does not compile since no instance of Container is available\n return new Item(data);\n }\n public Item createSubItem(Object data){\n // compiles, since 'this' Container is available\n return new Item(data);\n }\n}\n Container.this // class version 49.0 (49)\n// access flags 33\npublic class Container$Item {\n\n // compiled from: Container.java\n // access flags 1\n public INNERCLASS Container$Item Container Item\n\n // access flags 0\n Object data\n\n // access flags 4112\n final Container this$0\n\n // access flags 1\n public getContainer() : Container\n L0\n LINENUMBER 7 L0\n ALOAD 0: this\n GETFIELD Container$Item.this$0 : Container\n ARETURN\n L1\n LOCALVARIABLE this Container$Item L0 L1 0\n MAXSTACK = 1\n MAXLOCALS = 1\n\n // access flags 1\n public <init>(Container,Object) : void\n L0\n LINENUMBER 12 L0\n ALOAD 0: this\n ALOAD 1\n PUTFIELD Container$Item.this$0 : Container\n L1\n LINENUMBER 10 L1\n ALOAD 0: this\n INVOKESPECIAL Object.<init>() : void\n L2\n LINENUMBER 11 L2\n ALOAD 0: this\n ALOAD 2: data\n PUTFIELD Container$Item.data : Object\n RETURN\n L3\n LOCALVARIABLE this Container$Item L0 L3 0\n LOCALVARIABLE data Object L0 L3 2\n MAXSTACK = 2\n MAXLOCALS = 3\n}\n Container this$0 OuterClass.InnerClass innerObject = outerObject.new InnerClass();\n new InnerClass(outerObject)\n"
},
{
"answer_id": 70687,
"author": "Jegschemesch",
"author_id": 1586,
"author_profile": "https://Stackoverflow.com/users/1586",
"pm_score": 9,
"selected": false,
"text": "package pizza;\n\npublic class Rhino {\n\n ...\n\n public static class Goat {\n ...\n }\n}\n package pizza;\n\npublic class Rhino {\n\n public class Goat {\n ...\n }\n\n private void jerry() {\n Goat g = new Goat();\n }\n}\n Rhino rhino = new Rhino();\nRhino.Goat goat = rhino.new Goat();\n public class Rhino {\n\n private String barry;\n\n public class Goat {\n public void colin() {\n System.out.println(barry);\n }\n }\n}\n new *ParentClassName*(*constructorArgs*) {*members*}\n new *InterfaceName*() {*members*}\n"
},
{
"answer_id": 2523233,
"author": "HippoMan",
"author_id": 302506,
"author_profile": "https://Stackoverflow.com/users/302506",
"pm_score": 4,
"selected": false,
"text": "public class C0 {\n\n static C0 instance = null;\n\n // Uncomment the following line and a null pointer exception will be\n // generated before anything gets printed.\n //public static final String outerItem = instance.makeString(98.6);\n\n public C0() {\n instance = this;\n }\n\n public String makeString(int i) {\n return ((new Integer(i)).toString());\n }\n\n public String makeString(double d) {\n return ((new Double(d)).toString());\n }\n\n public static final class nested {\n public static final String innerItem = instance.makeString(42);\n }\n\n static public void main(String[] argv) {\n System.out.println(\"start\");\n // Comment out this line and a null pointer exception will be\n // generated after \"start\" prints and before the following\n // try/catch block even gets entered.\n new C0();\n try {\n System.out.println(\"retrieve item: \" + nested.innerItem);\n }\n catch (Exception e) {\n System.out.println(\"failed to retrieve item: \" + e.toString());\n }\n System.out.println(\"finish\");\n }\n}\n"
},
{
"answer_id": 2574123,
"author": "tejas",
"author_id": 308651,
"author_profile": "https://Stackoverflow.com/users/308651",
"pm_score": 4,
"selected": false,
"text": "outerclass outerobject=new outerobject();\nouterclass.innerclass innerobjcet=outerobject.new innerclass(); \n class outerclass A {\n static class nestedclass B {\n static int x = 10;\n }\n}\n outerclass.nestedclass.x; i.e. System.out.prinltn( outerclass.nestedclass.x);\n"
},
{
"answer_id": 4460365,
"author": "sactiw",
"author_id": 416369,
"author_profile": "https://Stackoverflow.com/users/416369",
"pm_score": 5,
"selected": false,
"text": "new YourClass(){}; class [Anonymous] extends YourClass {} new YourInterface(){}; class [Anonymous] implements YourInterface {}"
},
{
"answer_id": 9904357,
"author": "hqt",
"author_id": 1192728,
"author_profile": "https://Stackoverflow.com/users/1192728",
"pm_score": 2,
"selected": false,
"text": " public static class A {} //ERROR\n\n public class A {\n public class B {\n public static class C {} //ERROR\n }\n }\n\n public class A {\n public static class B {} //COMPILE !!!\n\n }\n"
},
{
"answer_id": 18721137,
"author": "Sohi",
"author_id": 1802850,
"author_profile": "https://Stackoverflow.com/users/1802850",
"pm_score": 0,
"selected": false,
"text": "OuterClass.InnerClass inner = new OuterClass().new InnerClass();\n OuterClass.InnerClass inner = new OuterClass.InnerClass();\n"
},
{
"answer_id": 19438489,
"author": "Thalaivar",
"author_id": 337128,
"author_profile": "https://Stackoverflow.com/users/337128",
"pm_score": 5,
"selected": false,
"text": "private, package, protected, public public public class OuterClass {\n public static class Inner1 {\n }\n public class Inner2 {\n }\n}\n Inner1 Inner2 Inner2 Inner1 Class A Class B Class B Class A Class B Class A OuterClass outer = new OuterClass();\nOuterClass.Inner2 inner = outer.new Inner2();\n OuterClass.Inner2 inner = new OuterClass().new Inner2();\n OuterClass.Inner1 nestedObject = new OuterClass.Inner1();\n"
},
{
"answer_id": 19977690,
"author": "Ankit Jain",
"author_id": 1423581,
"author_profile": "https://Stackoverflow.com/users/1423581",
"pm_score": 3,
"selected": false,
"text": "class A\n{\n class B\n {\n // static int x; not allowed here….. \n }\n static class C\n {\n static int x; // allowed here\n }\n}\n\nclass Test\n{\n public static void main(String… str)\n {\n A o=new A();\n A.B obj1 =o.new B();//need of inclosing instance\n\n A.C obj2 =new A.C();\n\n // not need of reference of object of outer class….\n }\n}\n"
},
{
"answer_id": 31537275,
"author": "VeKe",
"author_id": 1878022,
"author_profile": "https://Stackoverflow.com/users/1878022",
"pm_score": 3,
"selected": false,
"text": "class OuterClass {\n/* some code here...*/\n class InnerClass { }\n/* some code here...*/\n}\n class EnclosingClass {\n static class Nested {\n void someMethod() { System.out.println(\"hello SO\"); }\n }\n}\n class NonEnclosingClass {\n\n public static void main(String[] args) {\n /*instantiate the Nested class that is a static\n member of the EnclosingClass class:\n */\n\n EnclosingClass.Nested n = new EnclosingClass.Nested(); \n n.someMethod(); //prints out \"hello\"\n }\n}\n class EnclosingClass {\n\n static class Nested {\n void anotherMethod() { System.out.println(\"hi again\"); } \n }\n\n public static void main(String[] args) {\n //access enclosed class:\n\n Nested n = new Nested(); \n n.anotherMethod(); //prints out \"hi again\"\n }\n\n}\n"
},
{
"answer_id": 33781508,
"author": "Adelin",
"author_id": 1170677,
"author_profile": "https://Stackoverflow.com/users/1170677",
"pm_score": 3,
"selected": false,
"text": "public class Outer {\n\n\n public class Inner {\n\n }\n\n\n public Inner inner(){\n return new Inner();\n }\n\n @Override\n protected void finalize() throws Throwable {\n // as you know finalize is called by the garbage collector due to destroying an object instance\n System.out.println(\"I am destroyed !\");\n }\n}\n\n\npublic static void main(String arg[]) {\n\n Outer outer = new Outer();\n Outer.Inner inner = outer.new Inner();\n\n // out instance is no more used and should be garbage collected !!!\n // However this will not happen as inner instance is still alive i.e used, not null !\n // and outer will be kept in memory until inner is destroyed\n outer = null;\n\n //\n // inner = null;\n\n //kick out garbage collector\n System.gc();\n\n}\n // inner = null; Outer.Inner i = new Outer.Inner();"
},
{
"answer_id": 34551507,
"author": "Behzad Bahmanyar",
"author_id": 5079879,
"author_profile": "https://Stackoverflow.com/users/5079879",
"pm_score": 5,
"selected": false,
"text": "Outerclass.InnerClass innerObject = outerObject.new Innerclass();\n OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();\n"
},
{
"answer_id": 40937372,
"author": "Pankti",
"author_id": 5095067,
"author_profile": "https://Stackoverflow.com/users/5095067",
"pm_score": 2,
"selected": false,
"text": "class Test{\n private static int x = 1;\n static class A{\n private static int y = 2;\n public static int getZ(){\n return B.z+x;\n }\n }\n static class B{\n private static int z = 3;\n public static int getY(){\n return A.y;\n }\n }\n}\n\nclass TestDemo{\n public static void main(String[] args){\n Test t = new Test();\n System.out.println(Test.A.getZ());\n System.out.println(Test.B.getY());\n }\n}\n class Test{\n private int i = 10;\n class A{\n private int i =20;\n void display(){\n int i = 30;\n System.out.println(i);\n System.out.println(this.i);\n System.out.println(Test.this.i);\n }\n }\n}\n"
},
{
"answer_id": 41453771,
"author": "Pritam Banerjee",
"author_id": 1475228,
"author_profile": "https://Stackoverflow.com/users/1475228",
"pm_score": 2,
"selected": false,
"text": "static nested class inner class public class OuterClass {\n private String someVariable = \"Non Static\";\n\n private static String anotherStaticVariable = \"Static\"; \n\n OuterClass(){\n\n }\n\n //Nested classes are static\n static class StaticNestedClass{\n private static String privateStaticNestedClassVariable = \"Private Static Nested Class Variable\"; \n\n //can access private variables declared in the outer class\n public static void getPrivateVariableofOuterClass(){\n System.out.println(anotherStaticVariable);\n }\n }\n\n //non static\n class InnerClass{\n\n //can access private variables of outer class\n public String getPrivateNonStaticVariableOfOuterClass(){\n return someVariable;\n }\n }\n\n public static void accessStaticClass(){\n //can access any variable declared inside the Static Nested Class \n //even if it private\n String var = OuterClass.StaticNestedClass.privateStaticNestedClassVariable; \n System.out.println(var);\n }\n\n}\n public class OuterClassTest {\n public static void main(String[] args) {\n\n //access the Static Nested Class\n OuterClass.StaticNestedClass.getPrivateVariableofOuterClass();\n\n //test the private variable declared inside the static nested class\n OuterClass.accessStaticClass();\n /*\n * Inner Class Test\n * */\n\n //Declaration\n\n //first instantiate the outer class\n OuterClass outerClass = new OuterClass();\n\n //then instantiate the inner class\n OuterClass.InnerClass innerClassExample = outerClass. new InnerClass();\n\n //test the non static private variable\n System.out.println(innerClassExample.getPrivateNonStaticVariableOfOuterClass()); \n\n }\n\n}\n"
},
{
"answer_id": 42949189,
"author": "roottraveller",
"author_id": 5167682,
"author_profile": "https://Stackoverflow.com/users/5167682",
"pm_score": 3,
"selected": false,
"text": "public class InnerClassTest {\n public static void main(String args[]) { \n //creating local inner class inside method i.e. main() \n class Local {\n public void name() {\n System.out.println(\"Example of Local class in Java\");\n\n }\n } \n //creating instance of local inner class\n Local local = new Local();\n local.name(); //calling method from local inner class\n\n //Creating anonymous inner class in Java for implementing thread\n Thread anonymous = new Thread(){\n @Override\n public void run(){\n System.out.println(\"Anonymous class example in java\");\n }\n };\n anonymous.start();\n\n //example of creating instance of inner class\n InnerClassTest test = new InnerClassTest();\n InnerClassTest.Inner inner = test.new Inner();\n inner.name(); //calling method of inner class\n }\n\n //Creating Inner class in Java\n private class Inner{\n public void name(){\n System.out.println(\"Inner class example in java\");\n }\n }\n}\n public class NestedStaticExample {\n public static void main(String args[]){ \n StaticNested nested = new StaticNested();\n nested.name();\n } \n //static nested class in java\n private static class StaticNested{\n public void name(){\n System.out.println(\"static nested class example in java\");\n }\n }\n}\n"
},
{
"answer_id": 46664397,
"author": "Ashish Sharma",
"author_id": 7503961,
"author_profile": "https://Stackoverflow.com/users/7503961",
"pm_score": -1,
"selected": false,
"text": " class Outter1 {\n\n String OutStr;\n\n Outter1(String str) {\n OutStr = str;\n }\n\n public void NonStaticMethod(String st) {\n\n String temp1 = \"ashish\";\n final String tempFinal1 = \"ashish\"; \n\n // below static attribute not permitted\n // static String tempStatic1 = \"static\"; \n\n // below static with final attribute not permitted \n // static final String tempStatic1 = \"ashish\"; \n\n // synchronized keyword is not permitted below \n class localInnerNonStatic1 { \n\n synchronized public void innerMethod(String str11) {\n str11 = temp1 +\" sharma\";\n System.out.println(\"innerMethod ===> \"+str11);\n }\n\n /* \n // static method with final not permitted\n public static void innerStaticMethod(String str11) { \n\n str11 = temp1 +\" india\";\n System.out.println(\"innerMethod ===> \"+str11);\n }*/\n }\n\n // static class not permitted below\n // static class localInnerStatic1 { } \n\n }\n\n public static void StaticMethod(String st) {\n\n String temp1 = \"ashish\";\n final String tempFinal1 = \"ashish\"; \n\n // static attribute not permitted below\n //static String tempStatic1 = \"static\"; \n\n // static with final attribute not permitted below\n // static final String tempStatic1 = \"ashish\"; \n\n class localInnerNonStatic1 {\n public void innerMethod(String str11) {\n str11 = temp1 +\" sharma\";\n System.out.println(\"innerMethod ===> \"+str11);\n }\n\n /*\n // static method with final not permitted\n public static void innerStaticMethod(String str11) { \n str11 = temp1 +\" india\";\n System.out.println(\"innerMethod ===> \"+str11);\n }*/\n }\n\n // static class not permitted below\n // static class localInnerStatic1 { } \n\n }\n\n // synchronized keyword is not permitted\n static class inner1 { \n\n static String temp1 = \"ashish\";\n String tempNonStatic = \"ashish\";\n // class localInner1 {\n\n public void innerMethod(String str11) {\n str11 = temp1 +\" sharma\";\n str11 = str11+ tempNonStatic +\" sharma\";\n System.out.println(\"innerMethod ===> \"+str11);\n }\n\n public static void innerStaticMethod(String str11) {\n // error in below step\n str11 = temp1 +\" india\"; \n //str11 = str11+ tempNonStatic +\" sharma\";\n System.out.println(\"innerMethod ===> \"+str11);\n }\n //}\n }\n\n //synchronized keyword is not permitted below\n class innerNonStatic1 { \n\n//This is important we have to keep final with static modifier in non\n// static innerclass below\n static final String temp1 = \"ashish\"; \n String tempNonStatic = \"ashish\";\n // class localInner1 {\n\n synchronized public void innerMethod(String str11) {\n tempNonStatic = tempNonStatic +\" ...\";\n str11 = temp1 +\" sharma\";\n str11 = str11+ tempNonStatic +\" sharma\";\n System.out.println(\"innerMethod ===> \"+str11);\n }\n\n /*\n // error in below step\n public static void innerStaticMethod(String str11) { \n // error in below step\n // str11 = tempNonStatic +\" india\"; \n str11 = temp1 +\" india\";\n System.out.println(\"innerMethod ===> \"+str11);\n }*/\n //}\n }\n }\n"
},
{
"answer_id": 53737273,
"author": "Mithun Debnath",
"author_id": 4046145,
"author_profile": "https://Stackoverflow.com/users/4046145",
"pm_score": 1,
"selected": false,
"text": "class OuterClass {\n...\nclass NestedClass {\n ...\n }\n}\n OuterClass.StaticNestedClass nestedObject =\n new OuterClass.StaticNestedClass(); \n OuterClass.InnerClass innerObject = new OuterClass().new InnerClass();\n"
},
{
"answer_id": 55014075,
"author": "Leogao",
"author_id": 10312263,
"author_profile": "https://Stackoverflow.com/users/10312263",
"pm_score": 3,
"selected": false,
"text": "public class BankAccount {\n\n private long accountNumber;\n private String owner;\n ...\n\n public static class Builder {\n\n private long accountNumber;\n private String owner;\n ...\n\n static public Builder(long accountNumber) {\n this.accountNumber = accountNumber;\n }\n\n public Builder withOwner(String owner){\n this.owner = owner;\n return this; \n }\n\n ...\n public BankAccount build(){\n BankAccount account = new BankAccount(); \n account.accountNumber = this.accountNumber;\n account.owner = this.owner;\n ...\n return account;\n }\n }\n}\n\n public class MyClass extends Applet {\n ...\n someObject.addMouseListener(new MyAdapter());\n ...\n class MyAdapter extends MouseAdapter {\n public void mouseClicked(MouseEvent e) {\n ...// Event listener implementation goes here...\n ...// change some outer class instance property depend on the event\n }\n }\n}\n"
},
{
"answer_id": 59220181,
"author": "yoAlex5",
"author_id": 4770877,
"author_profile": "https://Stackoverflow.com/users/4770877",
"pm_score": 3,
"selected": false,
"text": "static nested non-static nested static nested"
},
{
"answer_id": 67084223,
"author": "JCvanDamme",
"author_id": 4275167,
"author_profile": "https://Stackoverflow.com/users/4275167",
"pm_score": 0,
"selected": false,
"text": "Bank Bank.CreditCard setLimit(...) Bank.CreditCard limit Bank.CreditCard public class Bank {\n\n // maximum limit as per current bank policy\n // is subject to change\n private int maxLimit = 7000;\n\n // ------- PUBLIC METHODS ---------\n\n public CreditCard issueCard(\n final String firstName,\n final String lastName\n ) {\n final String number = this.generateNumber();\n final int expiryDate = this.generateExpiryDate();\n final int CVV = this.generateCVV();\n return new CreditCard(firstName, lastName, number, expiryDate, CVV);\n }\n\n\n public boolean setLimit(\n final CreditCard creditCard,\n final int limit\n ) {\n if (limit <= this.maxLimit) { // check against current bank policy limit\n creditCard.setLimit(limit); // access private method Bank.CreditCard.setLimit(int)\n return true;\n }\n return false;\n }\n\n // ------- PRIVATE METHODS ---------\n\n private String generateNumber() {\n return \"1234-5678-9101-1123\"; // the numbers should be unique for each card\n }\n\n\n private int generateExpiryDate() {\n return 202405; // date is YYYY=2024, MM=05\n }\n\n\n private int generateCVV() {\n return 123; // is in real-life less predictable\n }\n\n\n // ------- PUBLIC STATIC NESTED CLASS ---------\n\n public static final class CreditCard {\n private final String firstName;\n private final String lastName;\n private final String number;\n private final int expiryDate;\n private final int CVV;\n\n private int balance;\n private int limit = 100; // default limit\n\n // the constructor is final but is accessible from outer class\n private CreditCard(\n final String firstName,\n final String lastName,\n final String number,\n final int expiryDate,\n final int CVV\n ) {\n this.firstName = firstName;\n this.lastName = lastName;\n this.number = number;\n this.expiryDate = expiryDate;\n this.CVV = CVV;\n }\n\n // ------- PUBLIC METHODS ---------\n\n public String getFirstName() {\n return this.firstName;\n }\n\n public String getLastName() {\n return this.lastName;\n }\n\n public String getNumber() {\n return this.number;\n }\n\n public int getExpiryDate() {\n return this.expiryDate;\n }\n\n // returns true if financial transaction is successful\n // otherwise false\n public boolean charge(final int amount) {\n final int newBalance = this.balance - amount;\n if (newBalance < -this.limit) {\n return false;\n }\n this.balance = newBalance;\n return true;\n }\n\n // ------- PRIVATE METHODS ---------\n\n private int getCVV() {\n return this.CVV;\n }\n\n private int getBalance() {\n return this.balance;\n }\n\n private void setBalance(final int balance) {\n this.balance = balance;\n }\n\n private int getLimit() {\n return limit;\n }\n\n private void setLimit(final int limit) {\n this.limit = limit;\n }\n }\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11193/"
] |
70,347 |
<p>Are System.IO.Compression.GZipStream or System.IO.Compression.Deflate compatible with zlib compression?</p>
|
[
{
"answer_id": 72820,
"author": "Isak Savo",
"author_id": 8521,
"author_profile": "https://Stackoverflow.com/users/8521",
"pm_score": 3,
"selected": false,
"text": "FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);\nusing (GZipStream gzStream = new GZipStream(fs, CompressionMode.Compress))\n{\n XmlSerializer serializer = new XmlSerializer(typeof(MyDataType));\n serializer.Serialize(gzStream, myData);\n}\n FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);\nusing (Stream input = new GZipStream(fs, CompressionMode.Decompress))\n{\n XmlSerializer serializer = new XmlSerializer(typeof(MyDataType));\n myData = (MyDataType) serializer.Deserialize(input);\n}\n"
},
{
"answer_id": 2331025,
"author": "Blake Ramsdell",
"author_id": 234999,
"author_profile": "https://Stackoverflow.com/users/234999",
"pm_score": 4,
"selected": false,
"text": "0x78 0x01 CM CINFO FCHECK DeflateStream DeflateStream public class Adler32Computer\n{\n private int a = 1;\n private int b = 0;\n\n public int Checksum\n {\n get\n {\n return ((b * 65536) + a);\n }\n }\n\n private static readonly int Modulus = 65521;\n\n public void Update(byte[] data, int offset, int length)\n {\n for (int counter = 0; counter < length; ++counter)\n {\n a = (a + (data[offset + counter])) % Modulus;\n b = (b + a) % Modulus;\n }\n }\n}\n"
},
{
"answer_id": 29936729,
"author": "VirtualVDX",
"author_id": 2386688,
"author_profile": "https://Stackoverflow.com/users/2386688",
"pm_score": 1,
"selected": false,
"text": "System.IO.Compression.DeflateStream"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3279/"
] |
70,366 |
<p>When trying to commit to a cvs branch after adding a new file I get this error</p>
<pre><code>Assertion failed: key != NULL, file hash.c, line 317
</code></pre>
<p>Any idea how to fix it so I can check my code in?<br>
Both server and client are Linux and there are pre-commits involved.</p>
|
[
{
"answer_id": 70576,
"author": "Bert F",
"author_id": 11296,
"author_profile": "https://Stackoverflow.com/users/11296",
"pm_score": 1,
"selected": false,
"text": "cvs: hash.c:312: findnode: Assertion `key != ((void *)0)' failed.\ncvs [server aborted]: received abort signal\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7873/"
] |
70,377 |
<p>Is there any way to prevent Visual Studio from creating a VSMacros80 folder in my default project directory?</p>
|
[
{
"answer_id": 70505,
"author": "xsl",
"author_id": 11387,
"author_profile": "https://Stackoverflow.com/users/11387",
"pm_score": 0,
"selected": false,
"text": "Tools->Options->Addin/Macro Security %ALLUSERSPROFILE%\\Application Data\\Microsoft\\MsEnvShared\\Addins\n%APPDATA%\\Microsoft\\MsEnvShared\\Addins\n%VSAPPDATA%\\Addins\n%VSCOMMONAPPDATA%\\Addins\n%VSMYDOCUMENTS%\\Addins\n"
},
{
"answer_id": 71150,
"author": "xsl",
"author_id": 11387,
"author_profile": "https://Stackoverflow.com/users/11387",
"pm_score": 5,
"selected": true,
"text": "C:\\dev C:\\dev\\ VSMacros80"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11387/"
] |
70,386 |
<p>There are three places where menus show up in the new MFC functionality (Feature Pack):</p>
<ul>
<li>In menu bars (CMFCMenuBar)</li>
<li>In popup menus (CMFCPopupMenu)</li>
<li>In the 'dropdown menu' version of CMFCButton</li>
</ul>
<p>I want to put icons (high-color and with transparancy) in the menus in all of them. I have found CFrameWndEx::OnDrawMenuImage() which I can use to custom draw the icons in front of the menu bar items. It's not very convenient, having to implement icon drawing in 2008, but it works. For the others I haven't found a solution yet. Is there an automagic way to set icons for menus?</p>
|
[
{
"answer_id": 1213583,
"author": "foraidt",
"author_id": 27596,
"author_profile": "https://Stackoverflow.com/users/27596",
"pm_score": 3,
"selected": true,
"text": "MainFrm.h:\nclass CMainFrame\n{\n //... \n CMFCToolBar m_wndToolBar;\n CMFCToolBar m_wndInvisibleToolBar;\n //...\n};\n\nMainFrm.cpp:\nint CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)\n{\n //...\n\n // Normal, visible toolbar\n if(m_wndToolBar.Create(this,\n TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))\n {\n VERIFY( m_wndToolBar.LoadToolBar(\n theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME) );\n\n // Only the docking makes the toolbar visible\n m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);\n DockPane(&m_wndToolBar);\n }\n\n // Invisible toolbar; simply calling Create(this) seems to be enough\n if(m_wndInvisibleToolBar.Create(this))\n {\n // Just load, no docking and stuff\n VERIFY( m_wndInvisibleToolBar.LoadToolBar(IDR_OTHERTOOLBAR) );\n }\n}\n IDR_MAINFRAME IDR_MAINFRAME_256 IDR_OTHERTOOLBAR"
},
{
"answer_id": 1239950,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "CMFCToolBar::AddToolBarForImageCollection(UINT uiResID,\n UINT uiBmpResID=0,\n UINT uiColdResID=0,\n UINT uiMenuResID=0,\n UINT uiDisabledResID=0,\n UINT uiMenuDisabledResID=0);\n CMFCToolBar::AddToolBarForImageCollection(IDR_TOOLBAROWNBITMAP_256);\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70386",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11449/"
] |
70,389 |
<p>I have apache 2.2 and tomcat 5.5 running on a Windows XP machine.</p>
<p>Which tomcat/apache connector is the easiest to set up and is well documented? </p>
|
[
{
"answer_id": 70432,
"author": "Chris Broadfoot",
"author_id": 3947,
"author_profile": "https://Stackoverflow.com/users/3947",
"pm_score": 0,
"selected": false,
"text": "mod_jk mod_proxy"
},
{
"answer_id": 70553,
"author": "Brian Matthews",
"author_id": 1969,
"author_profile": "https://Stackoverflow.com/users/1969",
"pm_score": 4,
"selected": true,
"text": "mod_proxy_ajp httpd.conf mod_proxy mod_proxy_ajp"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8633/"
] |
70,397 |
<p>So I'm working on a Rails app to get the feeling for the whole thing. I've got a <code>Product</code> model that's a standard ActiveRecord model. However, I also want to get some additional product info from Amazon ECS. So my complete model gets some of its info from the database and some from the web service. My question is, should I:</p>
<ol>
<li><p>Make two models a Product and a ProductAWS, and then tie them together at the controller level.</p></li>
<li><p>Have the Product ActiveRecord model contain a ProductAWS object that does all the AWS stuff?</p></li>
<li><p>Just add all the AWS functionality to my Product model.</p></li>
<li><p>???</p></li>
</ol>
|
[
{
"answer_id": 70457,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "composed_of"
},
{
"answer_id": 76143,
"author": "Pete",
"author_id": 13472,
"author_profile": "https://Stackoverflow.com/users/13472",
"pm_score": 2,
"selected": true,
"text": " class Product < ActiveRecord::Base\n has_one :aws_item\n end \n class AWSItem \n belongs_to :product\n end\n class Product < ActiveRecord::Base\nend \nclass AWSItem < Product\n def do_amazon_stuff\n ... \n end\nend\n class Product < ActiveRecord::Base\n\nend\n\nclass ItemFetcher < BackgrounDRb::Rails\n def do_work\n # .... Make a cached copy of your ECS catalog here. \n # Copy the Amazon stuff into your local model\n end\nend\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11284/"
] |
70,402 |
<p>I was asked this question during an interview. They're both O(nlogn) and yet most people use Quicksort instead of Mergesort. Why is that?</p>
|
[
{
"answer_id": 70631,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 9,
"selected": true,
"text": "std::sort"
},
{
"answer_id": 15790254,
"author": "appbootup",
"author_id": 1155801,
"author_profile": "https://Stackoverflow.com/users/1155801",
"pm_score": 2,
"selected": false,
"text": "It is proved that for the Dual-Pivot Quicksort the average number of\ncomparisons is 2*n*ln(n), the average number of swaps is 0.8*n*ln(n),\nwhereas classical Quicksort algorithm has 2*n*ln(n) and 1*n*ln(n)\nrespectively. Full mathematical proof see in attached proof.txt\nand proof_add.txt files. Theoretical results are also confirmed\nby experimental counting of the operations.\n"
},
{
"answer_id": 60760652,
"author": "Himanshu Kansal",
"author_id": 3165873,
"author_profile": "https://Stackoverflow.com/users/3165873",
"pm_score": 3,
"selected": false,
"text": "O(n^2)"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1688440/"
] |
70,405 |
<p>I'm doing simple string input parsing and I am in need of a string tokenizer. I am new to C# but have programmed Java, and it seems natural that C# should have a string tokenizer. Does it? Where is it? How do I use it?</p>
|
[
{
"answer_id": 70436,
"author": "Davy Landman",
"author_id": 11098,
"author_profile": "https://Stackoverflow.com/users/11098",
"pm_score": 8,
"selected": true,
"text": "class ExampleClass\n{\n public ExampleClass()\n {\n string exampleString = \"there is a cat\";\n // Split string on spaces. This will separate all the words in a string\n string[] words = exampleString.Split(' ');\n foreach (string word in words)\n {\n Console.WriteLine(word);\n // there\n // is\n // a\n // cat\n }\n }\n}\n"
},
{
"answer_id": 70463,
"author": "Paul Shannon",
"author_id": 11503,
"author_profile": "https://Stackoverflow.com/users/11503",
"pm_score": -1,
"selected": false,
"text": "string.SplitByMyTokens();\n"
},
{
"answer_id": 1205918,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "Regex.Split(string,\"#|#\");"
},
{
"answer_id": 18905125,
"author": "demongolem",
"author_id": 236247,
"author_profile": "https://Stackoverflow.com/users/236247",
"pm_score": 5,
"selected": false,
"text": "str.Split(new char[] { ' ', '.', '?' })\n str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries)\n"
},
{
"answer_id": 30768986,
"author": "Skyler",
"author_id": 4997033,
"author_profile": "https://Stackoverflow.com/users/4997033",
"pm_score": 2,
"selected": false,
"text": "_words = new List<string>(YourText.ToLower().Trim('\\n', '\\r').Split(' ').\n Select(x => new string(x.Where(Char.IsLetter).ToArray()))); \n _words = new List<string>(YourText.Trim('\\n', '\\r').Split(' ').\n Select(x => new string(x.Where(Char.IsLetterOrDigit).ToArray()))); \n"
},
{
"answer_id": 39299866,
"author": "neronovs",
"author_id": 5771796,
"author_profile": "https://Stackoverflow.com/users/5771796",
"pm_score": 2,
"selected": false,
"text": "Regex.Split(string, pattern);\n string pattern"
},
{
"answer_id": 41133477,
"author": "Nigel Thomas",
"author_id": 5221568,
"author_profile": "https://Stackoverflow.com/users/5221568",
"pm_score": -1,
"selected": false,
"text": "private static List<String> Tokenise(string value, char seperator)\n{\n List<string> result = new List<string>();\n value = value.Replace(\" \", \" \").Replace(\" \", \" \").Trim();\n StringBuilder sb = new StringBuilder();\n bool insideQuote = false;\n foreach(char c in value.ToCharArray())\n {\n if(c == '\"')\n {\n insideQuote = !insideQuote;\n }\n if((c == seperator) && !insideQuote)\n {\n if (sb.ToString().Trim().Length > 0)\n {\n result.Add(sb.ToString().Trim());\n sb.Clear();\n }\n }\n else\n {\n sb.Append(c);\n }\n }\n if (sb.ToString().Trim().Length > 0)\n {\n result.Add(sb.ToString().Trim());\n }\n\n return result;\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70405",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/432/"
] |
70,417 |
<p>I have the following code:</p>
<pre><code>Dim obj As New Access.Application
obj.OpenCurrentDatabase (CurrentProject.Path & "\Working.mdb")
obj.Run "Routine"
obj.CloseCurrentDatabase
Set obj = Nothing
</code></pre>
<p>The problem I'm experimenting is a pop-up that tells me Access can't set the focus on the other database. As you can see from the code, I want to run a Subroutine in another mdb. Any other way to achieve this will be appreciated.</p>
<p>I'm working with MS Access 2003.</p>
<p>This is an intermittent error. As this is production code that will be run only once a month, it's extremely difficult to reproduce, and I can't give you the exact text and number at this time. It is the second month this happened.</p>
<p>I suspect this may occur when someone is working with this or the other database.</p>
<p>The dataflow is to update all 'projects' once a month in one database and then make this information available in the other database.</p>
<p>Maybe, it's because of the first line in the 'Routines' code:
If vbNo = MsgBox("Do you want to update?", vbYesNo, "Update") Then
Exit Function
End If</p>
<p>I'll make another subroutine without the MsgBox.</p>
<p>I've been able to reproduce this behaviour. It happens when the focus has to shift to the called database, but the user sets the focus ([ALT]+[TAB]) on the first database. The 'solution' was to educate the user.</p>
<hr>
<p>This is an intermittent error. As this is production code that will be run only once a month, it's extremely difficult to reproduce, and I can't give you the exact text and number at this time. It is the second month this happened.</p>
<p>I suspect this may occur when someone is working with this or the other database.</p>
<p>The dataflow is to update all 'projects' once a month in one database and then make this information available in the other database.</p>
<p>Maybe, it's because of the first line in the 'Routines' code:
If vbNo = MsgBox("Do you want to update?", vbYesNo, "Update") Then
Exit Function
End If</p>
<p>I'll make another subroutine without the MsgBox.</p>
<hr>
<p>I've tried this in our development database and it works. This doesn't mean anything as the other code also workes fine in development.</p>
|
[
{
"answer_id": 70436,
"author": "Davy Landman",
"author_id": 11098,
"author_profile": "https://Stackoverflow.com/users/11098",
"pm_score": 8,
"selected": true,
"text": "class ExampleClass\n{\n public ExampleClass()\n {\n string exampleString = \"there is a cat\";\n // Split string on spaces. This will separate all the words in a string\n string[] words = exampleString.Split(' ');\n foreach (string word in words)\n {\n Console.WriteLine(word);\n // there\n // is\n // a\n // cat\n }\n }\n}\n"
},
{
"answer_id": 70463,
"author": "Paul Shannon",
"author_id": 11503,
"author_profile": "https://Stackoverflow.com/users/11503",
"pm_score": -1,
"selected": false,
"text": "string.SplitByMyTokens();\n"
},
{
"answer_id": 1205918,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "Regex.Split(string,\"#|#\");"
},
{
"answer_id": 18905125,
"author": "demongolem",
"author_id": 236247,
"author_profile": "https://Stackoverflow.com/users/236247",
"pm_score": 5,
"selected": false,
"text": "str.Split(new char[] { ' ', '.', '?' })\n str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries)\n"
},
{
"answer_id": 30768986,
"author": "Skyler",
"author_id": 4997033,
"author_profile": "https://Stackoverflow.com/users/4997033",
"pm_score": 2,
"selected": false,
"text": "_words = new List<string>(YourText.ToLower().Trim('\\n', '\\r').Split(' ').\n Select(x => new string(x.Where(Char.IsLetter).ToArray()))); \n _words = new List<string>(YourText.Trim('\\n', '\\r').Split(' ').\n Select(x => new string(x.Where(Char.IsLetterOrDigit).ToArray()))); \n"
},
{
"answer_id": 39299866,
"author": "neronovs",
"author_id": 5771796,
"author_profile": "https://Stackoverflow.com/users/5771796",
"pm_score": 2,
"selected": false,
"text": "Regex.Split(string, pattern);\n string pattern"
},
{
"answer_id": 41133477,
"author": "Nigel Thomas",
"author_id": 5221568,
"author_profile": "https://Stackoverflow.com/users/5221568",
"pm_score": -1,
"selected": false,
"text": "private static List<String> Tokenise(string value, char seperator)\n{\n List<string> result = new List<string>();\n value = value.Replace(\" \", \" \").Replace(\" \", \" \").Trim();\n StringBuilder sb = new StringBuilder();\n bool insideQuote = false;\n foreach(char c in value.ToCharArray())\n {\n if(c == '\"')\n {\n insideQuote = !insideQuote;\n }\n if((c == seperator) && !insideQuote)\n {\n if (sb.ToString().Trim().Length > 0)\n {\n result.Add(sb.ToString().Trim());\n sb.Clear();\n }\n }\n else\n {\n sb.Append(c);\n }\n }\n if (sb.ToString().Trim().Length > 0)\n {\n result.Add(sb.ToString().Trim());\n }\n\n return result;\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11498/"
] |
70,450 |
<p>I'm already using <a href="http://www.matasano.com/log/958/enough-with-the-rainbow-tables-what-you-need-to-know-about-secure-password-schemes/" rel="nofollow noreferrer">salted hashing</a> to store passwords in my database, which means that I should be immune to <a href="https://en.wikipedia.org/wiki/Rainbow_table" rel="nofollow noreferrer">rainbow table</a> attacks.</p>
<p>I had a thought, though: what if someone does get hold of my database? It contains the users' email addresses. I can't really hash these, because I'll be using them to send notification emails, etc..</p>
<p>Should I encrypt them?</p>
|
[
{
"answer_id": 769493,
"author": "Arjan",
"author_id": 84237,
"author_profile": "https://Stackoverflow.com/users/84237",
"pm_score": 2,
"selected": false,
"text": "SELECT * FROM"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70450",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8446/"
] |
70,453 |
<p>For writing scripts for process automisation in Linux platform, which scripting language will be better? Shell script, Perl or Python or is there anything else? I am new to all of them. So, am just thinking to which one to go for?</p>
|
[
{
"answer_id": 70659,
"author": "stephanea",
"author_id": 8776,
"author_profile": "https://Stackoverflow.com/users/8776",
"pm_score": -1,
"selected": false,
"text": "promp> bash file\n"
},
{
"answer_id": 70789,
"author": "Eric Wilhelm",
"author_id": 11580,
"author_profile": "https://Stackoverflow.com/users/11580",
"pm_score": 3,
"selected": false,
"text": "'use warnings' 'use strict' 'system($command, @and_args)'"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70453",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11372/"
] |
70,455 |
<p>I want to port data from one server's database to another server's database.
The databases are both on a different mssql 2005 server.
Replication is probably not an option since the destination database is generated from scratch on a [time interval] basis.</p>
<p>Preferebly I would do something like</p>
<pre><code>insert *
from db1/table1
into db2/table2
where rule1 = true
</code></pre>
<p>It's obvious that connection credentials would go in somehwere in this script.</p>
|
[
{
"answer_id": 70525,
"author": "Matthew Pelser",
"author_id": 6331,
"author_profile": "https://Stackoverflow.com/users/6331",
"pm_score": 6,
"selected": true,
"text": "Select * From ServerName.DbName.SchemaName.TableName\n"
},
{
"answer_id": 70817,
"author": "kristof",
"author_id": 3241,
"author_profile": "https://Stackoverflow.com/users/3241",
"pm_score": 1,
"selected": false,
"text": "select columnName1, columnName2, etc from serverName.databaseName.schemaName.tableName"
},
{
"answer_id": 18659242,
"author": "Ardalan Shahgholi",
"author_id": 2063547,
"author_profile": "https://Stackoverflow.com/users/2063547",
"pm_score": 3,
"selected": false,
"text": "EXEC sp_configure 'show advanced options', 1\nGO\nRECONFIGURE\nGO\n\nEXEC sp_configure 'Ad Hoc Distributed Queries', 1\nGO\nRECONFIGURE\nGO\n\n\nSELECT *\nFROM OPENDATASOURCE('SQLOLEDB',\n 'Data Source=<Ip Of Your Server>;\n User ID=<SQL User Name>;Password=<SQL password>').<DataBase name>.<SchemaName>.<Table Or View Name>\n\nGo\n"
},
{
"answer_id": 39628957,
"author": "Ahmed Tambe",
"author_id": 6861533,
"author_profile": "https://Stackoverflow.com/users/6861533",
"pm_score": -1,
"selected": false,
"text": "CREATE VIEW newR1 \nAS\nSELECT * from OPENQUERY ([INSTANCE_NAME], 'select * from DbName.SchemaName.TableName')\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
70,471 |
<p>So, I have willfully kept myself a Java n00b until recently, and my first real exposure brought about a minor shock: Java does not have C# style properties!</p>
<p>Ok, I can live with that. However, I can also swear that I have seen property getter/setter code in Java in one codebase, but I cannot remember where. How was that achieved? Is there a language extension for that? Is it related to NetBeans or something?</p>
|
[
{
"answer_id": 70519,
"author": "Mark Embling",
"author_id": 6844,
"author_profile": "https://Stackoverflow.com/users/6844",
"pm_score": 2,
"selected": false,
"text": "public string getMyString() {\n // return it here\n}\n\npublic void setMyString(string myString) {\n // set it here\n}\n"
},
{
"answer_id": 70530,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 3,
"selected": false,
"text": "private int foo;\npublic int getFoo() {\n return foo;\n}\npublic void setFoo(int newFoo) {\n foo = newFoo;\n}\n int foo\n .foo getFoo setFoo"
},
{
"answer_id": 70535,
"author": "Calum",
"author_id": 8434,
"author_profile": "https://Stackoverflow.com/users/8434",
"pm_score": 7,
"selected": true,
"text": "get set // Getter for \"awesomeString\"\npublic String getAwesomeString() {\n return awesomeString;\n}\n\n// Setter for \"awesomeString\"\npublic void setAwesomeString( String awesomeString ) {\n this.awesomeString = awesomeString;\n}\n is has get public boolean isAwesome();\n\npublic boolean hasAwesomeStuff();\n"
},
{
"answer_id": 72826,
"author": "Scott Stanchfield",
"author_id": 12541,
"author_profile": "https://Stackoverflow.com/users/12541",
"pm_score": 1,
"selected": false,
"text": "@Bean(properties = {\n @Property(name=\"name\", bound=true),\n @Property(name=\"age,type=int.class)\n})\npublic class Person extends PersonGen {\n}\n"
},
{
"answer_id": 18496921,
"author": "dantuch",
"author_id": 575659,
"author_profile": "https://Stackoverflow.com/users/575659",
"pm_score": 3,
"selected": false,
"text": "public class Animal {\n\n @Getter @Setter private String name;\n @Getter @Setter private String gender;\n @Getter @Setter private String species;\n}\n"
},
{
"answer_id": 18496962,
"author": "Aleks-Daniel Jakimenko-A.",
"author_id": 2698019,
"author_profile": "https://Stackoverflow.com/users/2698019",
"pm_score": 5,
"selected": false,
"text": "@Getter @Setter int awesomeInteger = 5;\n getAwesomeInteger setAwesomeInteger"
},
{
"answer_id": 20781926,
"author": "th1rdey3",
"author_id": 1682148,
"author_profile": "https://Stackoverflow.com/users/1682148",
"pm_score": 2,
"selected": false,
"text": "out ref System.MarshalByRefObject MarshalByRefObject System.DateTime Now Environment TickCount"
},
{
"answer_id": 28183669,
"author": "LEMUEL ADANE",
"author_id": 1347816,
"author_profile": "https://Stackoverflow.com/users/1347816",
"pm_score": 2,
"selected": false,
"text": "public class Person {\n private String firstName = \"\";\n private Integer age = 0;\n\n public String firstName() { return firstName; } // getter\n public void firstName(String val) { firstName = val; } // setter\n\n public Integer age() { return age; } // getter\n public void age(Integer val) { age = val; } //setter\n\n public static void main(String[] args) {\n Person p = new Person();\n\n //set\n p.firstName(\"Lemuel\");\n p.age(40);\n\n //get\n System.out.println(String.format(\"I'm %s, %d yearsold\",\n p.firstName(),\n p.age());\n }\n}\n"
},
{
"answer_id": 48844944,
"author": "Patrick PIGNOL",
"author_id": 9254419,
"author_profile": "https://Stackoverflow.com/users/9254419",
"pm_score": 1,
"selected": false,
"text": "public class MyClass\n{\n private int aMyAttribute;\n public MyClass()\n {\n this.aMyAttribute = 0;\n }\n public void mMyAttribute(int pMyAttributeParameter)\n {\n this.aMyAttribute = pMyAttributeParameter;\n }\n public int mMyAttribute()\n {\n return this.aMyAttribute;\n }\n}\n//usage :\nint vIndex = 1;\nMyClass vClass = new MyClass();\nvClass.mMyAttribute(vIndex);\nvIndex = 0;\nvIndex = vClass.mMyAttribute();\n// vIndex == 1\n"
},
{
"answer_id": 59087540,
"author": "Bradley Willcott",
"author_id": 12349591,
"author_profile": "https://Stackoverflow.com/users/12349591",
"pm_score": 0,
"selected": false,
"text": " public class Test {\n private String _testField;\n\n public String testProperty {\n get {\n return _testField;\n }\n set {\n _testField = value;\n }\n }\n }\n\n public class TestUser {\n private Test test;\n\n public TestUser() {\n test = new Test();\n\n test.testProperty = \"Just something to store\";\n System.out.printLn(test.testProperty);\n }\n }\n public class IntReturn {\n public int val;\n}\n\npublic class StringReturn {\n public String val;\n}\n StringReturn sRtn = new StringReturn()\n\nif(add(2, 3, sRtn)){\n System.out.println(\"Value greater than zero\");\n}\n\npublic boolean add(final int a, final int b, final StringReturn sRtn){\n int rtn = a + b;\n sRtn.val = \"\" + rtn;\n return rtn > 0; // Just something to use the return for.\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70471",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/227/"
] |
70,501 |
<p>I have a method in .NET (C#) which returns <code>string[][]</code>. When using RegAsm or TlbExp (from the .NET 2.0 SDK) to create a COM type library for the containing assembly, I get the following warning:</p>
<blockquote>
<p>WARNING: There is no marshaling support for nested arrays.</p>
</blockquote>
<p>This warning results in the method in question not being exported into the generated type library. I've been told there's ways around this using Variant as the COM return type, and then casting/etc on the COM client side. For this particular assembly, the target client audience is VB6. <b>But how do you actually do this on the .NET side?</b></p>
<p><i>Note</i>: I have an existing legacy DLL (with its exported type library) where the return type is Variant, but this DLL (and the .tlb) is generated using pre-.NET legacy tools, so I can't use them. </p>
<p>Would it help at all if the assembly was written in VB.NET instead?</p>
|
[
{
"answer_id": 74711,
"author": "Euro Micelli",
"author_id": 2230,
"author_profile": "https://Stackoverflow.com/users/2230",
"pm_score": 3,
"selected": true,
"text": "string [,] myReturnValue = new string[rowCount,colCount];\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70501",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7724/"
] |
70,513 |
<p>This question is overflow from the following question:</p>
<p><a href="https://stackoverflow.com/questions/70096/how-do-i-programmatically-convert-mp3-to-an-itunes-playable-aacm4a-file">How do I programmatically convert mp3 to an itunes-playable aac/m4a file?</a></p>
<p>Anyway, I learned how to create an aac file and then i found out that an aac is not just an m4a file with a different file extension. In fact, I need to somehow wrap the aac into an m4a container. Ideally I'd be able to simply make a call to the command line.</p>
|
[
{
"answer_id": 6302358,
"author": "djeikyb",
"author_id": 659715,
"author_profile": "https://Stackoverflow.com/users/659715",
"pm_score": 5,
"selected": false,
"text": "ffmpeg MP4Box ffmpeg -i input.aac -codec: copy output.m4a\n MP4Box -add input.aac#audio output.m4a\n"
},
{
"answer_id": 22367988,
"author": "Alastair",
"author_id": 1105203,
"author_profile": "https://Stackoverflow.com/users/1105203",
"pm_score": 2,
"selected": false,
"text": "avconv -i input.aac -acodec copy output.m4a"
},
{
"answer_id": 47745203,
"author": "Damian Höster",
"author_id": 9081508,
"author_profile": "https://Stackoverflow.com/users/9081508",
"pm_score": 1,
"selected": false,
"text": "mp4 aac m4a"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
70,516 |
<p>I have the ISO week and year but how do I correctly convert that into two dates representing the start and end of that week?</p>
|
[
{
"answer_id": 6302358,
"author": "djeikyb",
"author_id": 659715,
"author_profile": "https://Stackoverflow.com/users/659715",
"pm_score": 5,
"selected": false,
"text": "ffmpeg MP4Box ffmpeg -i input.aac -codec: copy output.m4a\n MP4Box -add input.aac#audio output.m4a\n"
},
{
"answer_id": 22367988,
"author": "Alastair",
"author_id": 1105203,
"author_profile": "https://Stackoverflow.com/users/1105203",
"pm_score": 2,
"selected": false,
"text": "avconv -i input.aac -acodec copy output.m4a"
},
{
"answer_id": 47745203,
"author": "Damian Höster",
"author_id": 9081508,
"author_profile": "https://Stackoverflow.com/users/9081508",
"pm_score": 1,
"selected": false,
"text": "mp4 aac m4a"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/966/"
] |
70,524 |
<p>I'm looking at Rails development as a backend to a Flex application and am trying to figure out the communication layer between the Rails app and the Flash Player. All of the things I am finding suggest using SOAP web services to communicate.</p>
<p>However, Flash supports AMF which is nice and fast (and native). Is there any way of communicating over AMF from a Rails app, whilst supporting all the "nice" things about AMF (automatic type conversion, data push etc).</p>
|
[
{
"answer_id": 1709178,
"author": "Kevin Marvin",
"author_id": 207932,
"author_profile": "https://Stackoverflow.com/users/207932",
"pm_score": 0,
"selected": false,
"text": "def people\n render :xml => Person.all.to_xml\nend\n def people\n render :xml => Person.all.to_xml.target!\nend\n <mx:HTTPService id=\"theservice\" url=\"http://localhost:3000/svc/add_person\" method=\"POST\">\n <mx:request>\n <person>\n <first>Firstname</first>\n <last>Lastname</last>\n </person>\n </request>\n</HTTPService>\n def add_person\n p=Person.create(params[:person])\n render :xml => {:result => \"Success\"}.to_xml.target!\nend\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4787/"
] |
70,528 |
<p>Python gives us the ability to create 'private' methods and variables within a class by prepending double underscores to the name, like this: <code>__myPrivateMethod()</code>. How, then, can one explain this</p>
<pre><code>>>>> class MyClass:
... def myPublicMethod(self):
... print 'public method'
... def __myPrivateMethod(self):
... print 'this is private!!'
...
>>> obj = MyClass()
>>> obj.myPublicMethod()
public method
>>> obj.__myPrivateMethod()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: MyClass instance has no attribute '__myPrivateMethod'
>>> dir(obj)
['_MyClass__myPrivateMethod', '__doc__', '__module__', 'myPublicMethod']
>>> obj._MyClass__myPrivateMethod()
this is private!!
</code></pre>
<p>What's the deal?!</p>
<p>I'll explain this a little for those who didn't quite get that.</p>
<pre><code>>>> class MyClass:
... def myPublicMethod(self):
... print 'public method'
... def __myPrivateMethod(self):
... print 'this is private!!'
...
>>> obj = MyClass()
</code></pre>
<p>I create a class with a public method and a private method and instantiate it.</p>
<p>Next, I call its public method.</p>
<pre><code>>>> obj.myPublicMethod()
public method
</code></pre>
<p>Next, I try and call its private method.</p>
<pre><code>>>> obj.__myPrivateMethod()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: MyClass instance has no attribute '__myPrivateMethod'
</code></pre>
<p>Everything looks good here; we're unable to call it. It is, in fact, 'private'. Well, actually it isn't. Running <code>dir()</code> on the object reveals a new magical method that Python creates magically for all of your 'private' methods.</p>
<pre><code>>>> dir(obj)
['_MyClass__myPrivateMethod', '__doc__', '__module__', 'myPublicMethod']
</code></pre>
<p>This new method's name is always an underscore, followed by the class name, followed by the method name.</p>
<pre><code>>>> obj._MyClass__myPrivateMethod()
this is private!!
</code></pre>
<p>So much for encapsulation, eh?</p>
<p>In any case, I'd always heard Python doesn't support encapsulation, so why even try? What gives?</p>
|
[
{
"answer_id": 70900,
"author": "Alya",
"author_id": 9464,
"author_profile": "https://Stackoverflow.com/users/9464",
"pm_score": 10,
"selected": true,
"text": ">>> class Foo(object):\n... def __init__(self):\n... self.__baz = 42\n... def foo(self):\n... print self.__baz\n... \n>>> class Bar(Foo):\n... def __init__(self):\n... super(Bar, self).__init__()\n... self.__baz = 21\n... def bar(self):\n... print self.__baz\n...\n>>> x = Bar()\n>>> x.foo()\n42\n>>> x.bar()\n21\n>>> print x.__dict__\n{'_Bar__baz': 21, '_Foo__baz': 42}\n"
},
{
"answer_id": 80000,
"author": "Ross",
"author_id": 14794,
"author_profile": "https://Stackoverflow.com/users/14794",
"pm_score": 4,
"selected": false,
"text": "from* from bar import *\n"
},
{
"answer_id": 3147548,
"author": "arun",
"author_id": 379816,
"author_profile": "https://Stackoverflow.com/users/379816",
"pm_score": 8,
"selected": false,
"text": "import re\nimport inspect\n\nclass MyClass:\n\n def __init__(self):\n pass\n\n def private_function(self):\n try:\n function_call = inspect.stack()[1][4][0].strip()\n\n # See if the function_call has \"self.\" in the beginning\n matched = re.match( '^self\\.', function_call)\n if not matched:\n print 'This is a private function. Go away.'\n return\n except:\n print 'This is a private function. Go away.'\n return\n\n # This is the real function, only accessible inside the class #\n print 'Hey, welcome in to the function.'\n\n def public_function(self):\n # I can call a private function from inside the class\n self.private_function()\n\n### End ###\n"
},
{
"answer_id": 39123423,
"author": "Alberto",
"author_id": 1735667,
"author_profile": "https://Stackoverflow.com/users/1735667",
"pm_score": 2,
"selected": false,
"text": ">>> class Foo:\n def __init__(self):\n pass\n def __privateMethod(self):\n return 3\n def invoke(self):\n return self.__privateMethod()\n\n\n>>> help(Foo)\nHelp on class Foo in module __main__:\n\nclass Foo(builtins.object)\n | Methods defined here:\n |\n | __init__(self)\n |\n | invoke(self)\n |\n | ----------------------------------------------------------------------\n | Data descriptors defined here:\n |\n | __dict__\n | dictionary for instance variables (if defined)\n |\n | __weakref__\n | list of weak references to the object (if defined)\n\n >>> f = Foo()\n >>> f.invoke()\n 3\n >>> f.__privateMethod()\n Traceback (most recent call last):\n File \"<pyshell#47>\", line 1, in <module>\n f.__privateMethod()\n AttributeError: 'Foo' object has no attribute '__privateMethod'\n"
},
{
"answer_id": 50052800,
"author": "Afshin Amiri",
"author_id": 6244155,
"author_profile": "https://Stackoverflow.com/users/6244155",
"pm_score": 3,
"selected": false,
"text": "obj._MyClass__myPrivateMethod()\n"
},
{
"answer_id": 54179468,
"author": "user200783",
"author_id": 200783,
"author_profile": "https://Stackoverflow.com/users/200783",
"pm_score": 1,
"selected": false,
"text": "self self"
},
{
"answer_id": 64985332,
"author": "Moradnejad",
"author_id": 2419960,
"author_profile": "https://Stackoverflow.com/users/2419960",
"pm_score": 4,
"selected": false,
"text": "__name _classname__name classname __name _classname__name class Cat:\n def __init__(self, name='unnamed'):\n self.name = name\n def __print_my_name(self):\n print(self.name)\n \n \ntom = Cat()\ntom.__print_my_name() #Error\ntom._Cat__print_my_name() #Prints name\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70528",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1943957/"
] |
70,529 |
<p>In order to know how many times a pattern exists in current buffer, I do:</p>
<pre><code>:%s/pattern-here/pattern-here/g
</code></pre>
<p>It gives the number of occurrences of the pattern, but is obviously cumbersome and also has the side-effect of setting the 'changed' status.</p>
<p>Is there a more elegant way to count?</p>
|
[
{
"answer_id": 70657,
"author": "Bruno De Fraine",
"author_id": 6918,
"author_profile": "https://Stackoverflow.com/users/6918",
"pm_score": 8,
"selected": true,
"text": ":%s/pattern-here//gn\n"
},
{
"answer_id": 70690,
"author": "Ilya",
"author_id": 6807,
"author_profile": "https://Stackoverflow.com/users/6807",
"pm_score": 3,
"selected": false,
"text": ":!cat %| grep -c \"pattern\"\n"
},
{
"answer_id": 8073228,
"author": "rdeits",
"author_id": 641846,
"author_profile": "https://Stackoverflow.com/users/641846",
"pm_score": -1,
"selected": false,
"text": "vimgrep pattern %\n (1 of 37)\n"
},
{
"answer_id": 14635785,
"author": "konyak",
"author_id": 1408866,
"author_profile": "https://Stackoverflow.com/users/1408866",
"pm_score": 3,
"selected": false,
"text": ":help count-items\n :set report=0\n:%s/your_word/&/g # returns the count without substitution\n :%s/your_word/&/gn # returns the count, n flag avoids substitution\n"
},
{
"answer_id": 32634262,
"author": "Sagar Jain",
"author_id": 3345302,
"author_profile": "https://Stackoverflow.com/users/3345302",
"pm_score": 1,
"selected": false,
"text": ":%s/<c-r><c-w>//gn\n :h c_ctrl-r_ctrl-w"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70529",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6984/"
] |
70,537 |
<p>I have heard there is a way to cheat single inheritance and implement multiple inheritance in Java. Does anyone know how to implement this(with out using interface)?</p>
<p>Just out of curiosity ;-)</p>
|
[
{
"answer_id": 70564,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 1,
"selected": false,
"text": "interface"
},
{
"answer_id": 46753756,
"author": "Abdur Rehman Khalid",
"author_id": 8066227,
"author_profile": "https://Stackoverflow.com/users/8066227",
"pm_score": -1,
"selected": false,
"text": "public class parents implements first, second{\n\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70537",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11193/"
] |
70,560 |
<p>When entering a question, stackoverflow presents you with a list of questions that it thinks likely to cover the same topic. I have seen similar features on other sites or in other programs, too (Help file systems, for example), but I've never programmed something like this myself. Now I'm curious to know what sort of algorithm one would use for that.</p>
<p>The first approach that comes to my mind is splitting the phrase into words and look for phrases containing these words. Before you do that, you probably want to throw away insignificant words (like 'the', 'a', 'does' etc), and then you will want to rank the results.</p>
<p>Hey, wait - let's do that for web pages, and then we can have a ... watchamacallit ... - a "search engine", and then we can sell ads, and then ...</p>
<p>No, seriously, what are the common ways to solve this problem?</p>
|
[
{
"answer_id": 70656,
"author": "Antti Rasinen",
"author_id": 8570,
"author_profile": "https://Stackoverflow.com/users/8570",
"pm_score": 5,
"selected": true,
"text": "[2 0 0 ... 70k zeroes ... 0].\n"
},
{
"answer_id": 73842199,
"author": "Subhradeep Biswas",
"author_id": 20080779,
"author_profile": "https://Stackoverflow.com/users/20080779",
"pm_score": 0,
"selected": false,
"text": "#from sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nimport nltk\nnltk.download('stopwords')\ns=set(stopwords.words('english'))\n\ntrain_x_cleaned = []\nfor i in train_x:\n sentence = filter(lambda w: not w in s,i.split(\",\"))\n train_x_cleaned.append(' '.join(sentence))\n\nvectorizer = TfidfVectorizer(binary=True)\ntrain_x_vectors = vectorizer.fit_transform(train_x_cleaned)\n\nprint(vectorizer.get_feature_names_out())\nprint(train_x_vectors.toarray())\n\nfrom sklearn import svm\n\nclf_svm = svm.SVC(kernel='linear')\nclf_svm.fit(train_x_vectors, train_y)\n\ntest_x = vectorizer.transform([\"test phrase 1\", \"test phrase 2\", \"test phrase 3\"])\nprint (type(test_x))\nclf_svm.predict(test_x)\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2077/"
] |
70,575 |
<p>Is there any need of Virtual Constructors? If so can any one post a scenario?</p>
|
[
{
"answer_id": 70634,
"author": "Mark Ingram",
"author_id": 986,
"author_profile": "https://Stackoverflow.com/users/986",
"pm_score": 3,
"selected": false,
"text": "class A\n{\n ~A();\n}\n\nclass B : public A\n{\n ~B();\n}\n\nA* pB = new B();\ndelete pB; // NOTE: WILL NOT CALL B's destructor\n\nclass A\n{\n virtual ~A();\n}\n\nclass B : public A\n{\n virtual ~B();\n}\n\nA* pB = new B();\ndelete pB; // NOTE: WILL CALL B's destructor\n"
},
{
"answer_id": 70693,
"author": "Tim Jarvis",
"author_id": 10387,
"author_profile": "https://Stackoverflow.com/users/10387",
"pm_score": 2,
"selected": false,
"text": "type\n MyMetaTypeRef = class of MyBaseClass;\n\nvar\n theRef : MyMetaTypeRef;\n inst : MyBaseClass;\nbegin \n theRef := GetTheMetaTypeFromAFactory(); \n inst := theRef.Create(); // Use polymorphic behaviour to create the class\n"
},
{
"answer_id": 70822,
"author": "easeout",
"author_id": 10906,
"author_profile": "https://Stackoverflow.com/users/10906",
"pm_score": 0,
"selected": false,
"text": "Superclass *object = NULL;\nif (condition) {\n object = new Subclass1();\n}\nelse {\n object = new Subclass2();\n}\nobject.setMeUp(args);\n"
},
{
"answer_id": 11664488,
"author": "Homer6",
"author_id": 278976,
"author_profile": "https://Stackoverflow.com/users/278976",
"pm_score": -1,
"selected": false,
"text": "#include <iostream>\n#include <vector>\n\nclass Animal {\n\n public:\n\n Animal(){\n std::cout << \"Animal Constructor Invoked.\" << std::endl;\n }\n\n virtual void eat() {\n std::cout << \"I eat like a generic animal.\\n\";\n }\n\n //always make destructors virtual in base classes\n virtual ~Animal() {\n\n }\n\n};\n\nclass Wolf : public Animal {\n\n public:\n\n Wolf(){\n std::cout << \"Wolf Constructor Invoked.\" << std::endl;\n }\n\n void eat() {\n std::cout << \"I eat like a wolf!\" << std::endl;\n }\n\n};\n\n\nint main() {\n\n Wolf wolf;\n std::cout << \"-------------\" << std::endl;\n wolf.eat();\n\n}\n Animal Constructor Invoked.\nWolf Constructor Invoked.\n-------------\nI eat like a wolf!\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70575",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11554/"
] |
70,579 |
<p>When creating the <code>id</code> attributes for HTML elements, what rules are there for the value?</p>
|
[
{
"answer_id": 70599,
"author": "Mr Shark",
"author_id": 6093,
"author_profile": "https://Stackoverflow.com/users/6093",
"pm_score": 6,
"selected": false,
"text": "[A-Za-z][-A-Za-z0-9_:.]*\n"
},
{
"answer_id": 70894,
"author": "pdc",
"author_id": 8925,
"author_profile": "https://Stackoverflow.com/users/8925",
"pm_score": 5,
"selected": false,
"text": "id id name"
},
{
"answer_id": 72577,
"author": "Michael Thompson",
"author_id": 12276,
"author_profile": "https://Stackoverflow.com/users/12276",
"pm_score": 7,
"selected": false,
"text": "#my.cool:thing { ... /* some rules */ ... }\n"
},
{
"answer_id": 79022,
"author": "dgvid",
"author_id": 9897,
"author_profile": "https://Stackoverflow.com/users/9897",
"pm_score": 12,
"selected": true,
"text": "<div id=\"first.name\"></div> #first\\.name $('#first\\\\.name'). $('#first.name') first name first-name firstName FirstName first_name id=\"firstName\" #FirstName { color: red }"
},
{
"answer_id": 431712,
"author": "Álvaro González",
"author_id": 13508,
"author_profile": "https://Stackoverflow.com/users/13508",
"pm_score": 6,
"selected": false,
"text": "var name = 'O'Hara';\n"
},
{
"answer_id": 3193773,
"author": "blacksun1",
"author_id": 385410,
"author_profile": "https://Stackoverflow.com/users/385410",
"pm_score": 5,
"selected": false,
"text": "<html>\n<head>\n<title>Cake</title>\n<style type=\"text/css\">\n #i\\.Really\\.Like\\.Cake {\n color: green;\n }\n #i\\:Really\\:Like\\:Cake {\n color: blue;\n }\n</style>\n</head>\n<body>\n <div id=\"i.Really.Like.Cake\">Cake</div>\n <div id=\"testResultPeriod\"></div>\n\n <div id=\"i:Really:Like:Cake\">Cake</div>\n <div id=\"testResultColon\"></div>\n <script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\"></script>\n <script type=\"text/javascript\">\n $(function() {\n var testPeriod = $(\"#i\\\\.Really\\\\.Like\\\\.Cake\");\n $(\"#testResultPeriod\").html(\"found \" + testPeriod.length + \" result.\");\n\n var testColon = $(\"#i\\\\:Really\\\\:Like\\\\:Cake\");\n $(\"#testResultColon\").html(\"found \" + testColon.length + \" result.\");\n });\n </script>\n</body>\n</html>\n"
},
{
"answer_id": 14394034,
"author": "Zaheer Ahmed",
"author_id": 821057,
"author_profile": "https://Stackoverflow.com/users/821057",
"pm_score": 6,
"selected": false,
"text": "[A-Za-z][-A-Za-z0-9_:.]*\n - _ : . : . . :"
},
{
"answer_id": 16331721,
"author": "Web Designer cum Promoter",
"author_id": 1012591,
"author_profile": "https://Stackoverflow.com/users/1012591",
"pm_score": 3,
"selected": false,
"text": "# : . * ! <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>."
},
{
"answer_id": 18453687,
"author": "Sergio",
"author_id": 2256325,
"author_profile": "https://Stackoverflow.com/users/2256325",
"pm_score": 5,
"selected": false,
"text": "id id"
},
{
"answer_id": 19963415,
"author": "Anthony",
"author_id": 1678151,
"author_profile": "https://Stackoverflow.com/users/1678151",
"pm_score": 4,
"selected": false,
"text": "<div id=\"maintenance.instrumentNumber\">############0218</div>\n #maintenance\\.instrumentNumber{word-wrap:break-word;}\n"
},
{
"answer_id": 31773673,
"author": "Michael Benjamin",
"author_id": 3597276,
"author_profile": "https://Stackoverflow.com/users/3597276",
"pm_score": 6,
"selected": false,
"text": "<div id=\"999\"> ... </div>\n<div id=\"#%LV-||\"> ... </div>\n<div id=\"____V\"> ... </div>\n<div id=\"⌘⌥\"> ... </div>\n<div id=\"♥\"> ... </div>\n<div id=\"{}\"> ... </div>\n<div id=\"©\"> ... </div>\n<div id=\"♤₩¤☆€~¥\"> ... </div>\n <div id=\"9lions\"> ... </div>\n id id class"
},
{
"answer_id": 38396827,
"author": "Bhavin Solanki",
"author_id": 3270866,
"author_profile": "https://Stackoverflow.com/users/3270866",
"pm_score": 4,
"selected": false,
"text": "ASCII letters and digits, '_', '-' and '.' HTML 4 HTML 5"
},
{
"answer_id": 56597185,
"author": "Dev pokhariya",
"author_id": 7179457,
"author_profile": "https://Stackoverflow.com/users/7179457",
"pm_score": 3,
"selected": false,
"text": "<span id=\"testID2\"></span>\n<span id=\"test-ID2\"></span>\n<span id=\"test_ID2\"></span>\n<span id=\"test:ID2\"></span>\n<span id=\"test.ID2\"></span>\n . :before :after"
},
{
"answer_id": 57837637,
"author": "NVRM",
"author_id": 2494754,
"author_profile": "https://Stackoverflow.com/users/2494754",
"pm_score": 3,
"selected": false,
"text": "const target = document.querySelector(\"div\").id\n\nconsole.log(\"Div id:\", target )\n\ndocument.getElementById(target).style.background = \"chartreuse\" div {\n border: 5px blue solid;\n width: 100%;\n height: 200px\n} <div id=\"H̹̙̦̮͉̩̗̗ͧ̇̏̊̾Eͨ͆͒̆ͮ̃͏̷̮̣̫̤̣Cͯ̂͐͏̨̛͔̦̟͈̻O̜͎͍͙͚̬̝̣̽ͮ͐͗̀ͤ̍̀͢M̴̡̲̭͍͇̼̟̯̦̉̒͠Ḛ̛̙̞̪̗ͥͤͩ̾͑̔͐ͅṮ̴̷̷̗̼͍̿̿̓̽͐H̙̙̔̄͜\"></div>"
},
{
"answer_id": 66589027,
"author": "Danny '365CSI' Engelman",
"author_id": 2520800,
"author_profile": "https://Stackoverflow.com/users/2520800",
"pm_score": 1,
"selected": false,
"text": "<div id=\"ONE\"></div>\n<div id=\"ONE\"></div>\n<div id=\"ONE\"></div>\n<script>\n document.body.append( document.querySelectorAll(\"#ONE\").length , ' DIVs!')\n document.body.append( ' in a ', typeof ONE )\n console.log( ONE ); // a global var !!\n</script> ONE document.querySelector(\"#ONE\")"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6093/"
] |
70,600 |
<p>I'm trying to find a way of finding out who is downloading what image from an image gallery. Users can download using a button beside the thumbnail or right click and use the "save link as" Is it possible to relate a user session or ID to a "save link as" action from all browsers using either PHP or JavaScript.</p>
|
[
{
"answer_id": 70664,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "$file = $_GET['file'];\nupdateFileCount($file);\nheader('Content-Type: image/jpeg');\nsendFile($file);\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
70,602 |
<p>I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008) by downloading and installing the client administration tools and Visual Studio 2008 on my laptop.</p>
<p>The installation footprint for Oracle Client tools was over 200Mb, and quite long winded.</p>
<p>Does anyone know what the minimum workable footprint is? I am hoping that it's a single DLL and a register command, but I have the feeling I need to install an oracle home, and set various environment variables.</p>
<p>I am using Oracle.DataAccess in my code.</p>
|
[
{
"answer_id": 70901,
"author": "Mac",
"author_id": 8696,
"author_profile": "https://Stackoverflow.com/users/8696",
"pm_score": 7,
"selected": true,
"text": "sales-server:1521/sales.us.acme.com"
},
{
"answer_id": 6608906,
"author": "kol",
"author_id": 600135,
"author_profile": "https://Stackoverflow.com/users/600135",
"pm_score": 4,
"selected": false,
"text": "using Oracle.DataAccess.Client; OracleConnection OracleCommand OracleDataReader"
},
{
"answer_id": 23161879,
"author": "DavidRR",
"author_id": 1497596,
"author_profile": "https://Stackoverflow.com/users/1497596",
"pm_score": 3,
"selected": false,
"text": "System.Data.OracleClient 1,036,288 2013-10-11 oci.dll\n 348,160 2013-10-11 ociw32.dll\n 1,290,240 2013-09-21 orannzsbb11.dll\n 562,688 2013-10-11 oraocci11.dll\n36,286,464 2013-10-11 oraociicus11.dll\n 691,712 2013-10-09 oci.dll\n 482,304 2013-10-09 ociw32.dll\n 1,603,072 2013-09-10 orannzsbb11.dll\n 1,235,456 2013-10-09 oraocci11.dll\n45,935,104 2013-10-09 oraociicus11.dll\n using System;\nusing System.Data;\nusing System.Data.OracleClient;\n\nclass TestOracleInstantClient\n{\n static public void Main(string[] args)\n {\n const string host = \"yourhost.yourdomain.com\";\n const string serviceName = \"yourservice.yourdomain.com\";\n const string userId = \"foo\";\n const string password = \"bar\";\n\n var conn = new OracleConnection();\n\n // Construct a connection string using Method 1 or 2.\n conn.ConnectionString =\n GetConnectionStringMethod1(host, serviceName, userId, password);\n\n try\n {\n conn.Open();\n Console.WriteLine(\"Connection succeeded.\");\n // Do something with the connection.\n conn.Close();\n }\n catch (Exception e)\n {\n Console.WriteLine(\"Connection failed: \" + e.Message);\n }\n }\n\n static private string GetConnectionStringMethod1(\n string host,\n string serviceName,\n string userId,\n string password\n )\n {\n string format =\n \"SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)\" +\n \"(HOST={0})(PORT=1521))\" +\n \"(CONNECT_DATA=(SERVER=DEDICATED)\" +\n \"(SERVICE_NAME={1})));\" +\n \"uid={2};\" +\n \"pwd={3};\"; // assumes port is 1521 (the default)\n\n return String.Format(format, host, serviceName, userId, password);\n }\n\n static private string GetConnectionStringMethod2(\n string host,\n string serviceName,\n string userId,\n string password\n )\n {\n string format =\n \"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)\" +\n \"(HOST={0})(PORT=1521))\" +\n \"(CONNECT_DATA=(SERVER=DEDICATED)\" +\n \"(SERVICE_NAME={1})));\" +\n \"User Id={2};\" +\n \"Password={3};\"; // assumes port is 1521 (the default)\n\n return String.Format(format, host, serviceName, userId, password);\n }\n}\n"
},
{
"answer_id": 26469797,
"author": "ecoe",
"author_id": 1080804,
"author_profile": "https://Stackoverflow.com/users/1080804",
"pm_score": 4,
"selected": false,
"text": "Oracle.ManagedDataAccess.dll Oracle.ManagedDataAccess.dll Oracle.ManagedDataAccessDTC.dll"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6910/"
] |
70,614 |
<p>I've just introduced a friend to <strong>GNU Screen</strong> and they're having a hard time getting used to it. That makes me think about the essential things he needs to know about the excellent <strong>Screen</strong> utility, the same things that you'd think worthwhile to teach someone, a beginner, from the ground up. What are some analogies and handy tips for remembering binds, etc.?</p>
<p>It would be awesome.</p>
|
[
{
"answer_id": 70683,
"author": "agnul",
"author_id": 6069,
"author_profile": "https://Stackoverflow.com/users/6069",
"pm_score": 5,
"selected": false,
"text": "^A ^A ^A ^A s ^A q ^A a"
},
{
"answer_id": 70765,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 8,
"selected": true,
"text": "Screen ^A ^W - window list, where am I\n^A ^C - create new window\n^A space - next window\n^A p - previous window\n^A ^A - switch to previous screen (toggle)\n^A [0-9] - go to window [0-9]\n^A esc - copy mode, which I use for scrollback\n ^Q ^A ^Q"
},
{
"answer_id": 70882,
"author": "Roel",
"author_id": 11449,
"author_profile": "https://Stackoverflow.com/users/11449",
"pm_score": 5,
"selected": false,
"text": "[roel@roel ~]$ cat .screenrc\n# Here comes the pain...\ncaption always \"%{=b dw}:%{-b dw}:%{=b dk}[ %{-b dw}%{-b dg}$USER%{-b dw}@%{-b dg}%H %{=b dk}] [ %= %?%{-b dg}%-Lw%?%{+b dk}(%{+b dw}%n:%t%{+b dk})%?(%u)%?%{-b dw}%?%{-b dg}%+Lw%? %{=b dk}]%{-b dw}:%{+b dw}:\"\n\nbacktick 2 5 5 $HOME/scripts/meminfo\nhardstatus alwayslastline \"%{+b dw}:%{-b dw}:%{+b dk}[%{-b dg} %0C:%s%a %{=b dk}]-[ %{-b dw}Load%{+b dk}:%{-b dg}%l %{+b dk}] [%{-b dg}%2`%{+b dk}] %=[ %{-b dg}%1`%{=b dk} ]%{-b dw}:%{+b dw}:%<\"\n\nsorendition \"-b dw\"\n[roel@roel ~]$ cat ~/scripts/meminfo\n#!/bin/sh\nRAM=`cat /proc/meminfo | grep \"MemFree\" | awk -F\" \" '{print $2}'`\nSWAP=`cat /proc/meminfo | grep \"SwapFree\" | awk -F\" \" '{print $2}'`\necho -n \"${RAM}kb/ram ${SWAP}kb/swap\"\n[roel@roel ~]$\n"
},
{
"answer_id": 70985,
"author": "Andrew Johnson",
"author_id": 5109,
"author_profile": "https://Stackoverflow.com/users/5109",
"pm_score": 4,
"selected": false,
"text": "escape ^bB\n"
},
{
"answer_id": 157174,
"author": "Zsolt Botykai",
"author_id": 11621,
"author_profile": "https://Stackoverflow.com/users/11621",
"pm_score": 3,
"selected": false,
"text": "bind s\n .screenrc C-a S C-a s"
},
{
"answer_id": 563876,
"author": "David Dean",
"author_id": 67829,
"author_profile": "https://Stackoverflow.com/users/67829",
"pm_score": 2,
"selected": false,
"text": ".screenrc .screenrc shelltitle \"$ |bash\" # Make screen assign window titles automatically\nhardstatus alwayslastline \"%w\" # Show all window titles at bottom line of term\n"
},
{
"answer_id": 1236687,
"author": "staticsan",
"author_id": 28832,
"author_profile": "https://Stackoverflow.com/users/28832",
"pm_score": 3,
"selected": false,
"text": ".screenrc bind ! select 11\nbind @ select 12\nbind \\# select 13\nbind $ select 14\nbind % select 15\nbind \\^ select 16\nbind & select 17\nbind * select 18\nbind ( select 19\nbind ) select 10\n"
},
{
"answer_id": 1680589,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "ssh #!/bin/sh\n# scr - Runs a command in a fresh screen\n#\n# Get the current directory and the name of command\n\nwd=`pwd`\ncmd=$1\nshift\n\n# We can tell if we are running inside screen by looking\n# for the STY environment variable. If it is not set we\n# only need to run the command, but if it is set then\n# we need to use screen.\n\nif [ -z \"$STY\" ]; then\n $cmd $*\nelse\n # Screen needs to change directory so that\n # relative file names are resolved correctly.\n screen -X chdir $wd\n\n # Ask screen to run the command\n if [ $cmd == \"ssh\" ]; then\n screen -X screen -t \"\"${1##*@}\"\" $cmd $*\n else\n screen -X screen -t \"$cmd $*\" $cmd $*\n fi\nfi\n vim() {\n scr vim $*\n}\n\nman() {\n scr man $*\n}\n\ninfo() {\n scr info $*\n}\n\nwatch() {\n scr watch $*\n}\n\nssh() {\n scr ssh $*\n}\n"
},
{
"answer_id": 4651572,
"author": "bambams",
"author_id": 149184,
"author_profile": "https://Stackoverflow.com/users/149184",
"pm_score": 1,
"selected": false,
"text": "screen -d -RR function mkscreen\n{\n local add=n\n\n if [ \"$1\" == '-a' ]; then\n add=y\n shift;\n fi\n\n local name=$1;\n shift;\n local command=\"$*\";\n\n if [ -z \"$name\" -o -z \"$command\" ]; then\n echo 'Usage: mkscreen [ -a ] name command\n\n -a Add to .bashrc.' 1>&2;\n return 1;\n fi\n\n if [ $add == y ]; then\n echo \"mkscreen $name $command\" >> $HOME/.bashrc;\n fi\n\n alias $name=\"/usr/bin/screen -d -RR -S $name $command\";\n\n return 0;\n}\n\nfunction rmscreen\n{\n local delete=n\n\n if [ \"$1\" == '-d' ]; then\n delete=y\n shift;\n fi\n\n local name=$1;\n\n if [ -z \"$name\" ]; then\n echo 'Usage: rmscreen [ -d ] name\n\n -d Delete from .bashrc.' 1>&2;\n return 1;\n fi\n\n if [ $delete == y ]; then\n sed -i -r \"/^mkscreen $name .*/d\" $HOME/.bashrc;\n fi\n\n unalias $name;\n\n return 0;\n}\n /usr/bin/screen -d -RR -S $name $command mkscreen irc /usr/bin/irssi\n irc mkscreen perlipc perldoc perlipc\nperlipc # Start reading the perldoc, ^A d to detach.\n...\n# Later, when I'm done reading it, or at least finished\n# with the alias, I remove it.\nrmscreen perlipc \n alias sls='/usr/bin/screen -ls'\n sls"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6414/"
] |
70,625 |
<p>How would you refactor these two classes to abstract out the similarities? An abstract class? Simple inheritance? What would the refactored class(es) look like?</p>
<pre><code>public class LanguageCode
{
/// <summary>
/// Get the lowercase two-character ISO 639-1 language code.
/// </summary>
public readonly string Value;
public LanguageCode(string language)
{
this.Value = new CultureInfo(language).TwoLetterISOLanguageName;
}
public static LanguageCode TryParse(string language)
{
if (language == null)
{
return null;
}
if (language.Length > 2)
{
language = language.Substring(0, 2);
}
try
{
return new LanguageCode(language);
}
catch (ArgumentException)
{
return null;
}
}
}
public class RegionCode
{
/// <summary>
/// Get the uppercase two-character ISO 3166 region/country code.
/// </summary>
public readonly string Value;
public RegionCode(string region)
{
this.Value = new RegionInfo(region).TwoLetterISORegionName;
}
public static RegionCode TryParse(string region)
{
if (region == null)
{
return null;
}
if (region.Length > 2)
{
region = region.Substring(0, 2);
}
try
{
return new RegionCode(region);
}
catch (ArgumentException)
{
return null;
}
}
}
</code></pre>
|
[
{
"answer_id": 70667,
"author": "Ben",
"author_id": 5005,
"author_profile": "https://Stackoverflow.com/users/5005",
"pm_score": 0,
"selected": false,
"text": "Locale"
},
{
"answer_id": 70673,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 0,
"selected": false,
"text": "public class TwoLetterCode {\n public readonly string Value;\n public static TwoLetterCode TryParseSt(string tlc) {\n if (tlc == null)\n {\n return null;\n }\n\n if (tlc.Length > 2)\n {\n tlc = tlc.Substring(0, 2);\n }\n\n try\n {\n return new TwoLetterCode(tlc);\n }\n catch (ArgumentException)\n {\n return null;\n }\n }\n}\n//Likewise for Region\npublic class LanguageCode : TwoLetterCode {\n public LanguageCode(string language)\n {\n this.Value = new CultureInfo(language).TwoLetterISOLanguageName;\n }\n public static LanguageCode TryParse(string language) {\n return (LanguageCode)TwoLetterCode.TryParseSt(language);\n }\n}\n"
},
{
"answer_id": 70684,
"author": "Steve Cooper",
"author_id": 6722,
"author_profile": "https://Stackoverflow.com/users/6722",
"pm_score": 0,
"selected": false,
"text": "AbstractCode<T> protected T GetConstructor(string code);\n protected override RegionCode GetConstructor(string code)\n{\n return new RegionCode(code);\n}\n string GetIsoName(string code) protected override GetIsoName(string code)\n{\n return new RegionCode(code).TowLetterISORegionName;\n}\n"
},
{
"answer_id": 70777,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 1,
"selected": true,
"text": "public class TwoLetterCode<T>\n{\n private readonly string value;\n\n public TwoLetterCode(string value, Func<string, string> predicate)\n {\n this.value = predicate(value);\n }\n\n public static T TryParse(string value, Func<string, T> predicate)\n {\n if (value == null)\n {\n return default(T);\n }\n\n if (value.Length > 2)\n {\n value = value.Substring(0, 2);\n }\n\n try\n {\n return predicate(value);\n }\n catch (ArgumentException)\n {\n return default(T);\n }\n }\n\n public string Value { get { return this.value; } }\n}\n\npublic class LanguageCode : TwoLetterCode<LanguageCode> {\n public LanguageCode(string language)\n : base(language, v => new CultureInfo(v).TwoLetterISOLanguageName)\n {\n }\n\n public static LanguageCode TryParse(string language)\n {\n return TwoLetterCode<LanguageCode>.TryParse(language, v => new LanguageCode(v));\n }\n}\n\npublic class RegionCode : TwoLetterCode<RegionCode>\n{\n public RegionCode(string language)\n : base(language, v => new CultureInfo(v).TwoLetterISORegionName)\n {\n }\n\n public static RegionCode TryParse(string language)\n {\n return TwoLetterCode<RegionCode>.TryParse(language, v => new RegionCode(v));\n }\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11574/"
] |
70,653 |
<p>I'm looking for a python library that will help me to create an authentication method for a desktop app I'm writing.
I have found several method in web framework such as django or turbogears.</p>
<p>I just want a kind of username-password association stored into a local file.
I can write it by myself, but I'm really it already exists and will be a better solution (I'm not very fluent with encryption).</p>
|
[
{
"answer_id": 70832,
"author": "Tony Meyer",
"author_id": 4966,
"author_profile": "https://Stackoverflow.com/users/4966",
"pm_score": 0,
"selected": false,
"text": "import pickle\nimport hashlib\n\n# Load from disk\npwd_file = \"mypasswords\"\nif os.path.exists(pwd_file):\n pwds = pickle.load(open(pwd_file, \"rb\"))\nelse:\n pwds = {}\n\n# Save to disk\npickle.dump(pwds, open(pwd_file, \"wb\"))\n\n# Add password\npwds[username] = hashlib.sha256(password).hexdigest()\n\n# Check password\nif pwds[username] = hashlib.sha256(password).hexdigest():\n print \"Good\"\nelse:\n print \"No match\"\n"
},
{
"answer_id": 70915,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 1,
"selected": true,
"text": "try:\n from hashlib import sha as hasher\nexcept ImportError:\n # You could probably exclude the try/except bit,\n # but older Python distros dont have hashlib.\n try:\n import sha as hasher\n except ImportError:\n import md5 as hasher\n\n\ndef hash_password(password):\n \"\"\"Returns the hashed version of a string\n \"\"\"\n return hasher.new( str(password) ).hexdigest()\n\ndef load_auth_file(path):\n \"\"\"Loads a comma-seperated file.\n Important: make sure the username\n doesn't contain any commas!\n \"\"\"\n # Open the file, or return an empty auth list.\n try:\n f = open(path)\n except IOError:\n print \"Warning: auth file not found\"\n return {}\n\n ret = {}\n for line in f.readlines():\n split_line = line.split(\",\")\n if len(split_line) > 2:\n print \"Warning: Malformed line:\"\n print split_line\n continue # skip it..\n else:\n username, password = split_line\n ret[username] = password\n #end if\n #end for\n return ret\n\ndef main():\n auth_file = \"/home/blah/.myauth.txt\"\n u = raw_input(\"Username:\")\n p = raw_input(\"Password:\") # getpass is probably better..\n if auth_file.has_key(u.strip()):\n if auth_file[u] == hash_password(p):\n # The hash matches the stored one\n print \"Welcome, sir!\"\n ~/.myauth.txt"
},
{
"answer_id": 80008,
"author": "tim.tadh",
"author_id": 14107,
"author_profile": "https://Stackoverflow.com/users/14107",
"pm_score": 4,
"selected": false,
"text": "def hash_password(password):\n \"\"\"Returns the hashed version of a string\n \"\"\"\n return hasher.new( str(password) ).hexdigest()\n #note I am using the Python Cryptography Toolkit\nfrom Crypto.Hash import SHA256\n\nHASH_REPS = 50000\n\ndef __saltedhash(string, salt):\n sha256 = SHA256.new()\n sha256.update(string)\n sha256.update(salt)\n for x in xrange(HASH_REPS): \n sha256.update(sha256.digest())\n if x % 10: sha256.update(salt)\n return sha256\n\ndef saltedhash_bin(string, salt):\n \"\"\"returns the hash in binary format\"\"\"\n return __saltedhash(string, salt).digest()\n\ndef saltedhash_hex(string, salt):\n \"\"\"returns the hash in hex format\"\"\"\n return __saltedhash(string, salt).hexdigest()\n"
},
{
"answer_id": 1992484,
"author": "Dustin Getz",
"author_id": 20003,
"author_profile": "https://Stackoverflow.com/users/20003",
"pm_score": 0,
"selected": false,
"text": "import hashlib\nimport random\n\ndef gen_salt():\n salt_seed = str(random.getrandbits(128))\n salt = hashlib.sha256(salt_seed).hexdigest()\n return salt\n\ndef hash_password(password, salt):\n h = hashlib.sha256()\n h.update(salt)\n h.update(password)\n return h.hexdigest()\n\n#in datastore\npassword_stored_hash = \"41e2282a9c18a6c051a0636d369ad2d4727f8c70f7ddeebd11e6f49d9e6ba13c\"\nsalt_stored = \"fcc64c0c2bc30156f79c9bdcabfadcd71030775823cb993f11a4e6b01f9632c3\"\n\npassword_supplied = 'password'\n\npassword_supplied_hash = hash_password(password_supplied, salt_stored)\nauthenticated = (password_supplied_hash == password_stored_hash)\nprint authenticated #True\n"
},
{
"answer_id": 10495626,
"author": "Anoop Augustine",
"author_id": 1322161,
"author_profile": "https://Stackoverflow.com/users/1322161",
"pm_score": -1,
"selected": false,
"text": ">>> import md5\n>>> hh = md5.new()\n>>> hh.update('anoop')\n>>> hh.digest\n<built-in method digest of _hashlib.HASH object at 0x01FE1E40>\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70653",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11563/"
] |
70,668 |
<p>What is the best way to backup VMWare Servers (1.0.x)?
The virtual machines in question are our development environment, and run isololated from the main network (so you can't just copy data from virtual to real servers).</p>
<p>The image files are normally in use and locked when the server is running, so it is difficult to back these up with the machines running.</p>
<p>Currently: I manually pause the servers when I leave and have a scheduled task that runs at midnight to robocopy the images to a remote NAS. </p>
<p>Is there a better way to do this, ideally without having to remember to pause the virtual machines?</p>
|
[
{
"answer_id": 70740,
"author": "John Stauffer",
"author_id": 5874,
"author_profile": "https://Stackoverflow.com/users/5874",
"pm_score": 4,
"selected": true,
"text": "Usage: /usr/bin/vmware-cmd <options> <vm-cfg-path> <vm-action> <arguments>\n /usr/bin/vmware-cmd -s <options> <server-action> <arguments>\n\n Options:\n Connection Options:\n -H <host> specifies an alternative host (if set, -U and -P must also be set)\n -O <port> specifies an alternative port\n -U <username> specifies a user\n -P <password> specifies a password\n General Options:\n -h More detailed help.\n -q Quiet. Minimal output\n -v Verbose.\n\n Server Operations:\n /usr/bin/vmware-cmd -l \n /usr/bin/vmware-cmd -s register <config_file_path>\n /usr/bin/vmware-cmd -s unregister <config_file_path>\n /usr/bin/vmware-cmd -s getresource <variable>\n /usr/bin/vmware-cmd -s setresource <variable> <value>\n\n VM Operations:\n /usr/bin/vmware-cmd <cfg> getconnectedusers\n /usr/bin/vmware-cmd <cfg> getstate\n /usr/bin/vmware-cmd <cfg> start <powerop_mode>\n /usr/bin/vmware-cmd <cfg> stop <powerop_mode>\n /usr/bin/vmware-cmd <cfg> reset <powerop_mode>\n /usr/bin/vmware-cmd <cfg> suspend <powerop_mode>\n /usr/bin/vmware-cmd <cfg> setconfig <variable> <value>\n /usr/bin/vmware-cmd <cfg> getconfig <variable>\n /usr/bin/vmware-cmd <cfg> setguestinfo <variable> <value>\n /usr/bin/vmware-cmd <cfg> getguestinfo <variable>\n /usr/bin/vmware-cmd <cfg> getid\n /usr/bin/vmware-cmd <cfg> getpid\n /usr/bin/vmware-cmd <cfg> getproductinfo <prodinfo>\n /usr/bin/vmware-cmd <cfg> connectdevice <device_name>\n /usr/bin/vmware-cmd <cfg> disconnectdevice <device_name>\n /usr/bin/vmware-cmd <cfg> getconfigfile\n /usr/bin/vmware-cmd <cfg> getheartbeat\n /usr/bin/vmware-cmd <cfg> getuptime\n /usr/bin/vmware-cmd <cfg> getremoteconnections\n /usr/bin/vmware-cmd <cfg> gettoolslastactive\n /usr/bin/vmware-cmd <cfg> getresource <variable>\n /usr/bin/vmware-cmd <cfg> setresource <variable> <value>\n /usr/bin/vmware-cmd <cfg> setrunasuser <username> <password>\n /usr/bin/vmware-cmd <cfg> getrunasuser\n /usr/bin/vmware-cmd <cfg> getcapabilities\n /usr/bin/vmware-cmd <cfg> addredo <disk_device_name>\n /usr/bin/vmware-cmd <cfg> commit <disk_device_name> <level> <freeze> <wait>\n /usr/bin/vmware-cmd <cfg> answer\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11538/"
] |
70,681 |
<p>Is there a way to make psycopg and postgres deal with errors without having to reestablish the connection, like MySQLdb? The commented version of the below works with MySQLdb, the comments make it work with Psycopg2:</p>
<pre><code>results = {'felicitas': 3, 'volumes': 8, 'acillevs': 1, 'mosaics': 13, 'perat\xe9': 1, 'representative': 6....}
for item in sorted(results):
try:
cur.execute("""insert into resultstab values ('%s', %d)""" % (item, results[item]))
print item, results[item]
# conn.commit()
except:
# conn=psycopg2.connect(user='bvm', database='wdb', password='redacted')
# cur=conn.cursor()
print 'choked on', item
continue
</code></pre>
<p>This must slow things down, could anyone give a suggestion for passing over formatting errors? Obviously the above chokes on apostrophes, but is there a way to make it pass over that without getting something like the following, or committing, reconnecting, etc?:</p>
<pre><code>agreement 19
agreements 1
agrees 1
agrippa 9
choked on agrippa's
choked on agrippina
</code></pre>
|
[
{
"answer_id": 70740,
"author": "John Stauffer",
"author_id": 5874,
"author_profile": "https://Stackoverflow.com/users/5874",
"pm_score": 4,
"selected": true,
"text": "Usage: /usr/bin/vmware-cmd <options> <vm-cfg-path> <vm-action> <arguments>\n /usr/bin/vmware-cmd -s <options> <server-action> <arguments>\n\n Options:\n Connection Options:\n -H <host> specifies an alternative host (if set, -U and -P must also be set)\n -O <port> specifies an alternative port\n -U <username> specifies a user\n -P <password> specifies a password\n General Options:\n -h More detailed help.\n -q Quiet. Minimal output\n -v Verbose.\n\n Server Operations:\n /usr/bin/vmware-cmd -l \n /usr/bin/vmware-cmd -s register <config_file_path>\n /usr/bin/vmware-cmd -s unregister <config_file_path>\n /usr/bin/vmware-cmd -s getresource <variable>\n /usr/bin/vmware-cmd -s setresource <variable> <value>\n\n VM Operations:\n /usr/bin/vmware-cmd <cfg> getconnectedusers\n /usr/bin/vmware-cmd <cfg> getstate\n /usr/bin/vmware-cmd <cfg> start <powerop_mode>\n /usr/bin/vmware-cmd <cfg> stop <powerop_mode>\n /usr/bin/vmware-cmd <cfg> reset <powerop_mode>\n /usr/bin/vmware-cmd <cfg> suspend <powerop_mode>\n /usr/bin/vmware-cmd <cfg> setconfig <variable> <value>\n /usr/bin/vmware-cmd <cfg> getconfig <variable>\n /usr/bin/vmware-cmd <cfg> setguestinfo <variable> <value>\n /usr/bin/vmware-cmd <cfg> getguestinfo <variable>\n /usr/bin/vmware-cmd <cfg> getid\n /usr/bin/vmware-cmd <cfg> getpid\n /usr/bin/vmware-cmd <cfg> getproductinfo <prodinfo>\n /usr/bin/vmware-cmd <cfg> connectdevice <device_name>\n /usr/bin/vmware-cmd <cfg> disconnectdevice <device_name>\n /usr/bin/vmware-cmd <cfg> getconfigfile\n /usr/bin/vmware-cmd <cfg> getheartbeat\n /usr/bin/vmware-cmd <cfg> getuptime\n /usr/bin/vmware-cmd <cfg> getremoteconnections\n /usr/bin/vmware-cmd <cfg> gettoolslastactive\n /usr/bin/vmware-cmd <cfg> getresource <variable>\n /usr/bin/vmware-cmd <cfg> setresource <variable> <value>\n /usr/bin/vmware-cmd <cfg> setrunasuser <username> <password>\n /usr/bin/vmware-cmd <cfg> getrunasuser\n /usr/bin/vmware-cmd <cfg> getcapabilities\n /usr/bin/vmware-cmd <cfg> addredo <disk_device_name>\n /usr/bin/vmware-cmd <cfg> commit <disk_device_name> <level> <freeze> <wait>\n /usr/bin/vmware-cmd <cfg> answer\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11596/"
] |
70,682 |
<p>I am looking for details of the VTable structure, order and contents, and the location of the vtable pointers within objects. </p>
<p>Ideally, this will cover single inheritance, multiple inheritance, and virtual inheritance.</p>
<p>References to external documentation would also be appreciated</p>
<p>Documentation of GCC 4.0x class layout is <a href="http://www.cse.wustl.edu/~mdeters/seminar/fall2005/mi.html#virtual" rel="noreferrer">here</a> and the Itanium, and more broadly GNU, ABI layout documents are <a href="http://www.codesourcery.com/public/cxx-abi/abi.html#general" rel="noreferrer">here</a>. </p>
|
[
{
"answer_id": 28155780,
"author": "LThode",
"author_id": 3657206,
"author_profile": "https://Stackoverflow.com/users/3657206",
"pm_score": 4,
"selected": false,
"text": "-fdump-class-hierarchy struct Base\n{\n virtual ~Base() {}\n virtual void f() = 0;\n};\n\nstruct OtherBase\n{\n virtual ~OtherBase() {}\n virtual void g() {}\n};\n\nstruct Derived: public Base\n{\n virtual ~Derived() {}\n virtual void f() {}\n};\n\nstruct MultiplyDerived: public Base, public OtherBase\n{\n virtual ~MultiplyDerived() {}\n virtual void f() {}\n virtual void g() {}\n};\n\nstruct OtherDerived: public Base\n{\n virtual ~OtherDerived() {}\n virtual void f() {}\n};\n\nstruct DiamondDerived: public Derived, public OtherDerived\n{\n virtual ~DiamondDerived() {}\n virtual void f() {}\n};\n\nstruct VirtuallyDerived: virtual public Base\n{\n virtual ~VirtuallyDerived() {}\n virtual void f() {}\n};\n\nstruct OtherVirtuallyDerived: virtual public Base\n{\n virtual ~OtherVirtuallyDerived() {}\n virtual void f() {}\n};\n\nstruct VirtuallyDiamondDerived: public VirtuallyDerived, public OtherVirtuallyDerived\n{\n virtual ~VirtuallyDiamondDerived() {}\n virtual void f() {}\n};\n\nstruct DoublyVirtuallyDiamondDerived: virtual public VirtuallyDerived, virtual public OtherVirtuallyDerived\n{\n virtual ~DoublyVirtuallyDiamondDerived() {}\n virtual void f() {}\n};\n\nstruct MixedVirtuallyDerived: virtual public Base, public OtherBase\n{\n virtual ~MixedVirtuallyDerived() {}\n};\n\nstruct MixedVirtuallyDiamondDerived: public VirtuallyDerived, public MixedVirtuallyDerived\n{\n virtual ~MixedVirtuallyDiamondDerived() {}\n virtual void f() {}\n virtual void g() {}\n};\n\nstruct VirtuallyMultiplyDerived: virtual public Base, virtual public OtherBase\n{\n virtual ~VirtuallyMultiplyDerived() {}\n};\n\nstruct OtherVirtuallyMultiplyDerived: virtual public Base, virtual public OtherBase\n{\n virtual ~OtherVirtuallyMultiplyDerived() {}\n};\n\nstruct MultiplyVirtuallyDiamondDerived: public VirtuallyMultiplyDerived, public OtherVirtuallyMultiplyDerived\n{\n virtual ~MultiplyVirtuallyDiamondDerived() {}\n virtual void f() {}\n virtual void g() {}\n};\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8516/"
] |
70,689 |
<p>What is an efficient way to implement a singleton design pattern in Java?</p>
|
[
{
"answer_id": 70824,
"author": "Jonathan",
"author_id": 1772,
"author_profile": "https://Stackoverflow.com/users/1772",
"pm_score": 7,
"selected": false,
"text": "public class A { \n\n private static final A INSTANCE = new A();\n\n private A() {}\n\n public static A getInstance() {\n return INSTANCE;\n }\n}\n"
},
{
"answer_id": 70829,
"author": "Aleksi Yrttiaho",
"author_id": 11427,
"author_profile": "https://Stackoverflow.com/users/11427",
"pm_score": 4,
"selected": false,
"text": "public class Singleton {\n private final static Singleton INSTANCE = new Singleton();\n\n private Singleton() {}\n\n public static Singleton getInstance() { return Singleton.INSTANCE; }\n\n protected Object clone() {\n throw new CloneNotSupportedException();\n }\n}\n public class Singleton {\n private static Singleton instance = null;\n\n private Singleton() {}\n\n public static Singleton getInstance() {\n if(null == instance) {\n synchronized(Singleton.class) {\n if(null == instance) {\n instance = new Singleton();\n }\n }\n }\n return instance;\n }\n\n protected Object clone() {\n throw new CloneNotSupportedException();\n }\n}\n"
},
{
"answer_id": 70835,
"author": "Stu Thompson",
"author_id": 2961,
"author_profile": "https://Stackoverflow.com/users/2961",
"pm_score": 7,
"selected": false,
"text": "class Foo {\n private static volatile Bar bar = null;\n public static Bar getBar() {\n if (bar == null) {\n synchronized(Foo.class) {\n if (bar == null)\n bar = new Bar();\n }\n }\n return bar;\n }\n}\n volatile"
},
{
"answer_id": 71399,
"author": "Stephen Denne",
"author_id": 11721,
"author_profile": "https://Stackoverflow.com/users/11721",
"pm_score": 11,
"selected": true,
"text": "public enum Foo {\n INSTANCE;\n}\n public enum Elvis {\n INSTANCE;\n private final String[] favoriteSongs =\n { \"Hound Dog\", \"Heartbreak Hotel\" };\n public void printFavorites() {\n System.out.println(Arrays.toString(favoriteSongs));\n }\n}\n"
},
{
"answer_id": 71683,
"author": "Benno Richters",
"author_id": 3565,
"author_profile": "https://Stackoverflow.com/users/3565",
"pm_score": 7,
"selected": false,
"text": "class Bar {\n private static class BarHolder {\n public static Bar bar = new Bar();\n }\n\n public static Bar getBar() {\n return BarHolder.bar;\n }\n}\n"
},
{
"answer_id": 73763,
"author": "Roel Spilker",
"author_id": 12634,
"author_profile": "https://Stackoverflow.com/users/12634",
"pm_score": 8,
"selected": false,
"text": "public enum Foo {\n INSTANCE;\n}\n public final class Foo {\n\n private static final Foo INSTANCE = new Foo();\n\n private Foo() {\n if (INSTANCE != null) {\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n return INSTANCE;\n }\n\n public Object clone() throws CloneNotSupportedException{\n throw new CloneNotSupportedException(\"Cannot clone instance of this class\");\n }\n}\n final private static final Foo public static Foo getInstance() private static class public final class Foo {\n\n private static class FooLoader {\n private static final Foo INSTANCE = new Foo();\n }\n\n private Foo() {\n if (FooLoader.INSTANCE != null) {\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n return FooLoader.INSTANCE;\n }\n}\n private static final Foo INSTANCE = new Foo(); public final class Foo implements Serializable {\n\n private static final long serialVersionUID = 1L;\n\n private static class FooLoader {\n private static final Foo INSTANCE = new Foo();\n }\n\n private Foo() {\n if (FooLoader.INSTANCE != null) {\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n return FooLoader.INSTANCE;\n }\n\n @SuppressWarnings(\"unused\")\n private Foo readResolve() {\n return FooLoader.INSTANCE;\n }\n}\n readResolve()"
},
{
"answer_id": 74905,
"author": "Georgi",
"author_id": 13209,
"author_profile": "https://Stackoverflow.com/users/13209",
"pm_score": -1,
"selected": false,
"text": "static Foo foo = new Foo(); public class Singleton {\n\n private static Singleton instance = null;\n\n static {\n instance = new Singleton();\n // do some of your instantiation stuff here\n }\n\n private Singleton() {\n if(instance!=null) {\n throw new ErrorYouWant(\"Singleton double-instantiation, should never happen!\");\n }\n }\n\n public static getSingleton() {\n return instance;\n }\n\n}\n"
},
{
"answer_id": 6918352,
"author": "Onur",
"author_id": 776658,
"author_profile": "https://Stackoverflow.com/users/776658",
"pm_score": 2,
"selected": false,
"text": "public static final INSTANCE == ....\nprivate Object readResolve() {\n return INSTANCE; // Original singleton instance.\n} \n"
},
{
"answer_id": 14372745,
"author": "NullPoiиteя",
"author_id": 1723893,
"author_profile": "https://Stackoverflow.com/users/1723893",
"pm_score": 3,
"selected": false,
"text": "/**\n* Singleton pattern example using a Java Enum\n*/\npublic enum Singleton {\n INSTANCE;\n public void execute (String arg) {\n // Perform operation here\n }\n}\n Singleton.INSTANCE getInstance() ObjectOutputStream ObjectInputStream java.lang.Enum.valueOf writeObject readObject readObjectNoData writeReplace readResolve serialPersistentFields serialVersionUID serialVersionUID 0L Serializable readObject() readResolve() // readResolve to prevent another instance of Singleton\n private Object readResolve(){\n return INSTANCE;\n }\n"
},
{
"answer_id": 14917772,
"author": "Abhijit Gaikwad",
"author_id": 403872,
"author_profile": "https://Stackoverflow.com/users/403872",
"pm_score": 4,
"selected": false,
"text": " /**\n * Singleton pattern example using Java Enum\n */\n public enum EasySingleton {\n INSTANCE;\n }\n /**\n * Singleton pattern example with Double checked Locking\n */\n public class DoubleCheckedLockingSingleton {\n private static volatile DoubleCheckedLockingSingleton INSTANCE;\n\n private DoubleCheckedLockingSingleton() {}\n\n public static DoubleCheckedLockingSingleton getInstance() {\n if(INSTANCE == null) {\n synchronized(DoubleCheckedLockingSingleton.class) {\n // Double checking Singleton instance\n if(INSTANCE == null) {\n INSTANCE = new DoubleCheckedLockingSingleton();\n }\n }\n }\n return INSTANCE;\n }\n }\n /**\n * Singleton pattern example with static factory method\n */\n\n public class Singleton {\n // Initialized during class loading\n private static final Singleton INSTANCE = new Singleton();\n\n // To prevent creating another instance of 'Singleton'\n private Singleton() {}\n\n public static Singleton getSingleton() {\n return INSTANCE;\n }\n }\n"
},
{
"answer_id": 16580366,
"author": "Ajinkya",
"author_id": 705773,
"author_profile": "https://Stackoverflow.com/users/705773",
"pm_score": 7,
"selected": false,
"text": "public class Foo {\n\n // It will be our sole hero\n private static final Foo INSTANCE = new Foo();\n\n private Foo() {\n if (INSTANCE != null) {\n // SHOUT\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n return INSTANCE;\n }\n}\n class Foo {\n\n // Our now_null_but_going_to_be sole hero\n private static Foo INSTANCE = null;\n\n private Foo() {\n if (INSTANCE != null) {\n // SHOUT\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n // Creating only when required.\n if (INSTANCE == null) {\n INSTANCE = new Foo();\n }\n return INSTANCE;\n }\n}\n class Foo {\n\n private static Foo INSTANCE = null;\n\n // TODO Add private shouting constructor\n\n public static Foo getInstance() {\n // No more tension of threads\n synchronized (Foo.class) {\n if (INSTANCE == null) {\n INSTANCE = new Foo();\n }\n }\n return INSTANCE;\n }\n}\n class Foo {\n\n // Pay attention to volatile\n private static volatile Foo INSTANCE = null;\n\n // TODO Add private shouting constructor\n\n public static Foo getInstance() {\n if (INSTANCE == null) { // Check 1\n synchronized (Foo.class) {\n if (INSTANCE == null) { // Check 2\n INSTANCE = new Foo();\n }\n }\n }\n return INSTANCE;\n }\n}\n class Foo implements Serializable {\n\n private static final long serialVersionUID = 1L;\n\n private static volatile Foo INSTANCE = null;\n\n // The rest of the things are same as above\n\n // No more fear of serialization\n @SuppressWarnings(\"unused\")\n private Object readResolve() {\n return INSTANCE;\n }\n}\n readResolve() public final class Foo implements Serializable {\n\n private static final long serialVersionUID = 1L;\n\n // Wrapped in a inner static class so that loaded only when required\n private static class FooLoader {\n\n // And no more fear of threads\n private static final Foo INSTANCE = new Foo();\n }\n\n // TODO add private shouting construcor\n\n public static Foo getInstance() {\n return FooLoader.INSTANCE;\n }\n\n // Damn you serialization\n @SuppressWarnings(\"unused\")\n private Foo readResolve() {\n return FooLoader.INSTANCE;\n }\n}\n private static final Foo INSTANCE = new Foo(); FooLoader public enum Foo {\n INSTANCE;\n}\n public class Foo {\n\n // It will be our sole hero\n private static final Foo INSTANCE = new Foo();\n}\n"
},
{
"answer_id": 19562324,
"author": "rohan kamat",
"author_id": 2335562,
"author_profile": "https://Stackoverflow.com/users/2335562",
"pm_score": 1,
"selected": false,
"text": "public class Singleton {\n private static Singleton singleInstance = new Singleton();\n private Singleton() {}\n public static Singleton getSingleInstance() {\n return singleInstance;\n }\n}\n"
},
{
"answer_id": 19849576,
"author": "somenath mukhopadhyay",
"author_id": 873952,
"author_profile": "https://Stackoverflow.com/users/873952",
"pm_score": -1,
"selected": false,
"text": "public class Singleton {\n\n private static final Singleton INSTANCE = new Singleton();\n\n private Singleton() {\n if (INSTANCE != null)\n throw new IllegalStateException(“Already instantiated...”);\n }\n\n\n public synchronized static Singleton getInstance() {\n return INSTANCE;\n }\n\n}\n"
},
{
"answer_id": 27793921,
"author": "shikjohari",
"author_id": 2595642,
"author_profile": "https://Stackoverflow.com/users/2595642",
"pm_score": 0,
"selected": false,
"text": "public enum Singleton {\n INSTANCE;\n}\n"
},
{
"answer_id": 29389322,
"author": "coderz",
"author_id": 3275167,
"author_profile": "https://Stackoverflow.com/users/3275167",
"pm_score": 4,
"selected": false,
"text": "public class MySingleton {\n private static MySingleton instance = null;\n private MySingleton() {}\n public static synchronized MySingleton getInstance() {\n if(instance == null) {\n instance = new MySingleton();\n }\n return instance;\n }\n}\n synchronized public class MySingleton {\n private MySingleton() {}\n private static class MySingletonHolder {\n public final static MySingleton instance = new MySingleton();\n }\n public static MySingleton getInstance() {\n return MySingletonHolder.instance;\n }\n}\n"
},
{
"answer_id": 32906229,
"author": "Dan Moldovan",
"author_id": 2725534,
"author_profile": "https://Stackoverflow.com/users/2725534",
"pm_score": 2,
"selected": false,
"text": "public enum SingletonEnum {\n INSTANCE;\n public void doSomething(){\n System.out.println(\"This is a singleton\");\n }\n}\n public class Singleton {\n\n private static volatile Singleton instance = null;\n\n private Singleton() {\n }\n\n public static Singleton getInstance() {\n if (instance == null) {\n synchronized (Singleton.class){\n if (instance == null) {\n instance = new Singleton();\n }\n }\n }\n return instance;\n }\n}\n public class Singleton {\n\n private static final Singleton instance = new Singleton();\n\n private Singleton() {\n }\n\n public static Singleton getInstance() {\n return instance;\n }\n\n public void doSomething(){\n System.out.println(\"This is a singleton\");\n }\n\n}\n"
},
{
"answer_id": 37305099,
"author": "Nicolas Filotto",
"author_id": 1997376,
"author_profile": "https://Stackoverflow.com/users/1997376",
"pm_score": 2,
"selected": false,
"text": "public class Singleton {\n // It must be static and final to prevent later modification\n private static final Singleton INSTANCE = new Singleton();\n /** The constructor must be private to prevent external instantiation */\n private Singleton(){}\n /** The public static method allowing to get the instance */\n public static Singleton getInstance() {\n return INSTANCE;\n }\n}\n public class Singleton {\n // The constructor must be private to prevent external instantiation\n private Singleton(){}\n /** The public static method allowing to get the instance */\n public static Singleton getInstance() {\n return SingletonHolder.INSTANCE;\n }\n /**\n * The static inner class responsible for creating your instance only on demand,\n * because the static fields of a class are only initialized when the class\n * is explicitly called and a class initialization is synchronized such that only\n * one thread can perform it, this rule is also applicable to inner static class\n * So here INSTANCE will be created only when SingletonHolder.INSTANCE\n * will be called\n */\n private static class SingletonHolder {\n private static final Singleton INSTANCE = new Singleton();\n }\n}\n"
},
{
"answer_id": 38942086,
"author": "user3792852",
"author_id": 3792852,
"author_profile": "https://Stackoverflow.com/users/3792852",
"pm_score": 2,
"selected": false,
"text": "public class SingletonImpl {\n\n private static SingletonImpl instance;\n\n public static SingletonImpl getInstance() {\n if (instance == null) {\n instance = new SingletonImpl();\n }\n return instance;\n }\n\n public static void setInstance(SingletonImpl impl) {\n instance = impl;\n }\n\n public void a() {\n System.out.println(\"Default Method\");\n }\n}\n setInstance public class SingletonMock extends SingletonImpl {\n\n @Override\n public void a() {\n System.out.println(\"Mock Method\");\n }\n\n}\n public class SingletonImpl {\n\n private static final SingletonImpl instance = new SingletonImpl();\n\n private static SingletonImpl alt;\n\n public static void setInstance(SingletonImpl inst) {\n alt = inst;\n }\n\n public static SingletonImpl getInstance() {\n if (alt != null) {\n return alt;\n }\n return instance;\n }\n\n public void a() {\n System.out.println(\"Default Method\");\n }\n}\n\npublic class SingletonMock extends SingletonImpl {\n\n @Override\n public void a() {\n System.out.println(\"Mock Method\");\n }\n\n}\n"
},
{
"answer_id": 39098595,
"author": "Dheeraj Sachan",
"author_id": 3314058,
"author_profile": "https://Stackoverflow.com/users/3314058",
"pm_score": 3,
"selected": false,
"text": " public class Test {\n private static final Test test = new Test();\n\n private Test() {\n }\n\n public static Test getTest() {\n return test;\n }\n }\n public class Test {\n private static volatile Test test;\n\n private Test() {\n }\n\n public static Test getTest() {\n if(test == null) {\n synchronized(Test.class) {\n if(test == null) {\n test = new Test();\n }\n }\n }\n return test;\n }\n }\n public class Test {\n\n private Test() {\n }\n\n private static class TestHolder {\n private static final Test test = new Test();\n }\n\n public static Test getInstance() {\n return TestHolder.test;\n }\n }\n public enum MySingleton {\n INSTANCE;\n\n private MySingleton() {\n System.out.println(\"Here\");\n }\n }\n"
},
{
"answer_id": 45062746,
"author": "Michael Andrews",
"author_id": 1829927,
"author_profile": "https://Stackoverflow.com/users/1829927",
"pm_score": 4,
"selected": false,
"text": "public class MySingleton {\n\n private static MySingleton INSTANCE;\n\n public static MySingleton getInstance() {\n if (INSTANCE == null) {\n INSTANCE = new MySingleton();\n }\n return INSTANCE;\n }\n ...\n}\n private static MySingleton INSTANCE;\n\npublic static synchronized MySingleton getInstance() {\n if (INSTANCE == null) {\n INSTANCE = new MySingleton();\n }\n return INSTANCE;\n}\n private static MySingleton INSTANCE;\n\npublic static MySingleton getInstance() {\n if (INSTANCE == null) {\n synchronize(MySingleton.class) {\n INSTANCE = new MySingleton();\n }\n }\n return INSTANCE;\n}\n private static MySingleton INSTANCE;\n\npublic static MySingleton getInstance() {\n if (INSTANCE == null) {\n synchronized(MySingleton.class) {\n if (INSTANCE == null) {\n INSTANCE = createInstance();\n }\n }\n }\n return INSTANCE;\n}\n private static volatile MySingleton INSTANCE;\n\npublic static MySingleton getInstance() {\n if (INSTANCE == null) {\n synchronized(MySingleton.class) {\n if (INSTANCE == null) {\n INSTANCE = createInstance();\n }\n }\n }\n return INSTANCE;\n}\n private static volatile MySingleton INSTANCE;\n\npublic static MySingleton getInstance() {\n MySingleton result = INSTANCE;\n if (result == null) {\n synchronized(MySingleton.class) {\n result = INSTANCE;\n if (result == null) {\n INSTANCE = result = createInstance();\n }\n }\n }\n return result;\n}\n"
},
{
"answer_id": 52265460,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "public class Singleton<T> implements Supplier<T> {\n\n private boolean initialized;\n private Supplier<T> singletonSupplier;\n\n public Singleton(T singletonValue) {\n this.singletonSupplier = () -> singletonValue;\n }\n\n public Singleton(Supplier<T> supplier) {\n this.singletonSupplier = () -> {\n // The initial supplier is temporary; it will be replaced after initialization\n synchronized (supplier) {\n if (!initialized) {\n T singletonValue = supplier.get();\n // Now that the singleton value has been initialized,\n // replace the blocking supplier with a non-blocking supplier\n singletonSupplier = () -> singletonValue;\n initialized = true;\n }\n return singletonSupplier.get();\n }\n };\n }\n\n @Override\n public T get() {\n return singletonSupplier.get();\n }\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11581/"
] |
70,694 |
<p>I am trying to create a Task Scheduler task to start my SQL Server 2005 instance every morning, because something stops it every night. This is a temporary solution until I can diagnose the stoppage.</p>
<p>I created a task to run under my admin user, and to start the program, <em>cmd</em> with the arguments <em>/c net start mssqlserver</em>. When I manually run the command, in a console under my admin user, it runs, but when I try to manually execute the task, it logs the following message, and the service remains stopped:</p>
<p><em>action "C:\Windows\system32\cmd.EXE" with return code 2</em>.</p>
<p>Any suggestions?</p>
|
[
{
"answer_id": 70824,
"author": "Jonathan",
"author_id": 1772,
"author_profile": "https://Stackoverflow.com/users/1772",
"pm_score": 7,
"selected": false,
"text": "public class A { \n\n private static final A INSTANCE = new A();\n\n private A() {}\n\n public static A getInstance() {\n return INSTANCE;\n }\n}\n"
},
{
"answer_id": 70829,
"author": "Aleksi Yrttiaho",
"author_id": 11427,
"author_profile": "https://Stackoverflow.com/users/11427",
"pm_score": 4,
"selected": false,
"text": "public class Singleton {\n private final static Singleton INSTANCE = new Singleton();\n\n private Singleton() {}\n\n public static Singleton getInstance() { return Singleton.INSTANCE; }\n\n protected Object clone() {\n throw new CloneNotSupportedException();\n }\n}\n public class Singleton {\n private static Singleton instance = null;\n\n private Singleton() {}\n\n public static Singleton getInstance() {\n if(null == instance) {\n synchronized(Singleton.class) {\n if(null == instance) {\n instance = new Singleton();\n }\n }\n }\n return instance;\n }\n\n protected Object clone() {\n throw new CloneNotSupportedException();\n }\n}\n"
},
{
"answer_id": 70835,
"author": "Stu Thompson",
"author_id": 2961,
"author_profile": "https://Stackoverflow.com/users/2961",
"pm_score": 7,
"selected": false,
"text": "class Foo {\n private static volatile Bar bar = null;\n public static Bar getBar() {\n if (bar == null) {\n synchronized(Foo.class) {\n if (bar == null)\n bar = new Bar();\n }\n }\n return bar;\n }\n}\n volatile"
},
{
"answer_id": 71399,
"author": "Stephen Denne",
"author_id": 11721,
"author_profile": "https://Stackoverflow.com/users/11721",
"pm_score": 11,
"selected": true,
"text": "public enum Foo {\n INSTANCE;\n}\n public enum Elvis {\n INSTANCE;\n private final String[] favoriteSongs =\n { \"Hound Dog\", \"Heartbreak Hotel\" };\n public void printFavorites() {\n System.out.println(Arrays.toString(favoriteSongs));\n }\n}\n"
},
{
"answer_id": 71683,
"author": "Benno Richters",
"author_id": 3565,
"author_profile": "https://Stackoverflow.com/users/3565",
"pm_score": 7,
"selected": false,
"text": "class Bar {\n private static class BarHolder {\n public static Bar bar = new Bar();\n }\n\n public static Bar getBar() {\n return BarHolder.bar;\n }\n}\n"
},
{
"answer_id": 73763,
"author": "Roel Spilker",
"author_id": 12634,
"author_profile": "https://Stackoverflow.com/users/12634",
"pm_score": 8,
"selected": false,
"text": "public enum Foo {\n INSTANCE;\n}\n public final class Foo {\n\n private static final Foo INSTANCE = new Foo();\n\n private Foo() {\n if (INSTANCE != null) {\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n return INSTANCE;\n }\n\n public Object clone() throws CloneNotSupportedException{\n throw new CloneNotSupportedException(\"Cannot clone instance of this class\");\n }\n}\n final private static final Foo public static Foo getInstance() private static class public final class Foo {\n\n private static class FooLoader {\n private static final Foo INSTANCE = new Foo();\n }\n\n private Foo() {\n if (FooLoader.INSTANCE != null) {\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n return FooLoader.INSTANCE;\n }\n}\n private static final Foo INSTANCE = new Foo(); public final class Foo implements Serializable {\n\n private static final long serialVersionUID = 1L;\n\n private static class FooLoader {\n private static final Foo INSTANCE = new Foo();\n }\n\n private Foo() {\n if (FooLoader.INSTANCE != null) {\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n return FooLoader.INSTANCE;\n }\n\n @SuppressWarnings(\"unused\")\n private Foo readResolve() {\n return FooLoader.INSTANCE;\n }\n}\n readResolve()"
},
{
"answer_id": 74905,
"author": "Georgi",
"author_id": 13209,
"author_profile": "https://Stackoverflow.com/users/13209",
"pm_score": -1,
"selected": false,
"text": "static Foo foo = new Foo(); public class Singleton {\n\n private static Singleton instance = null;\n\n static {\n instance = new Singleton();\n // do some of your instantiation stuff here\n }\n\n private Singleton() {\n if(instance!=null) {\n throw new ErrorYouWant(\"Singleton double-instantiation, should never happen!\");\n }\n }\n\n public static getSingleton() {\n return instance;\n }\n\n}\n"
},
{
"answer_id": 6918352,
"author": "Onur",
"author_id": 776658,
"author_profile": "https://Stackoverflow.com/users/776658",
"pm_score": 2,
"selected": false,
"text": "public static final INSTANCE == ....\nprivate Object readResolve() {\n return INSTANCE; // Original singleton instance.\n} \n"
},
{
"answer_id": 14372745,
"author": "NullPoiиteя",
"author_id": 1723893,
"author_profile": "https://Stackoverflow.com/users/1723893",
"pm_score": 3,
"selected": false,
"text": "/**\n* Singleton pattern example using a Java Enum\n*/\npublic enum Singleton {\n INSTANCE;\n public void execute (String arg) {\n // Perform operation here\n }\n}\n Singleton.INSTANCE getInstance() ObjectOutputStream ObjectInputStream java.lang.Enum.valueOf writeObject readObject readObjectNoData writeReplace readResolve serialPersistentFields serialVersionUID serialVersionUID 0L Serializable readObject() readResolve() // readResolve to prevent another instance of Singleton\n private Object readResolve(){\n return INSTANCE;\n }\n"
},
{
"answer_id": 14917772,
"author": "Abhijit Gaikwad",
"author_id": 403872,
"author_profile": "https://Stackoverflow.com/users/403872",
"pm_score": 4,
"selected": false,
"text": " /**\n * Singleton pattern example using Java Enum\n */\n public enum EasySingleton {\n INSTANCE;\n }\n /**\n * Singleton pattern example with Double checked Locking\n */\n public class DoubleCheckedLockingSingleton {\n private static volatile DoubleCheckedLockingSingleton INSTANCE;\n\n private DoubleCheckedLockingSingleton() {}\n\n public static DoubleCheckedLockingSingleton getInstance() {\n if(INSTANCE == null) {\n synchronized(DoubleCheckedLockingSingleton.class) {\n // Double checking Singleton instance\n if(INSTANCE == null) {\n INSTANCE = new DoubleCheckedLockingSingleton();\n }\n }\n }\n return INSTANCE;\n }\n }\n /**\n * Singleton pattern example with static factory method\n */\n\n public class Singleton {\n // Initialized during class loading\n private static final Singleton INSTANCE = new Singleton();\n\n // To prevent creating another instance of 'Singleton'\n private Singleton() {}\n\n public static Singleton getSingleton() {\n return INSTANCE;\n }\n }\n"
},
{
"answer_id": 16580366,
"author": "Ajinkya",
"author_id": 705773,
"author_profile": "https://Stackoverflow.com/users/705773",
"pm_score": 7,
"selected": false,
"text": "public class Foo {\n\n // It will be our sole hero\n private static final Foo INSTANCE = new Foo();\n\n private Foo() {\n if (INSTANCE != null) {\n // SHOUT\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n return INSTANCE;\n }\n}\n class Foo {\n\n // Our now_null_but_going_to_be sole hero\n private static Foo INSTANCE = null;\n\n private Foo() {\n if (INSTANCE != null) {\n // SHOUT\n throw new IllegalStateException(\"Already instantiated\");\n }\n }\n\n public static Foo getInstance() {\n // Creating only when required.\n if (INSTANCE == null) {\n INSTANCE = new Foo();\n }\n return INSTANCE;\n }\n}\n class Foo {\n\n private static Foo INSTANCE = null;\n\n // TODO Add private shouting constructor\n\n public static Foo getInstance() {\n // No more tension of threads\n synchronized (Foo.class) {\n if (INSTANCE == null) {\n INSTANCE = new Foo();\n }\n }\n return INSTANCE;\n }\n}\n class Foo {\n\n // Pay attention to volatile\n private static volatile Foo INSTANCE = null;\n\n // TODO Add private shouting constructor\n\n public static Foo getInstance() {\n if (INSTANCE == null) { // Check 1\n synchronized (Foo.class) {\n if (INSTANCE == null) { // Check 2\n INSTANCE = new Foo();\n }\n }\n }\n return INSTANCE;\n }\n}\n class Foo implements Serializable {\n\n private static final long serialVersionUID = 1L;\n\n private static volatile Foo INSTANCE = null;\n\n // The rest of the things are same as above\n\n // No more fear of serialization\n @SuppressWarnings(\"unused\")\n private Object readResolve() {\n return INSTANCE;\n }\n}\n readResolve() public final class Foo implements Serializable {\n\n private static final long serialVersionUID = 1L;\n\n // Wrapped in a inner static class so that loaded only when required\n private static class FooLoader {\n\n // And no more fear of threads\n private static final Foo INSTANCE = new Foo();\n }\n\n // TODO add private shouting construcor\n\n public static Foo getInstance() {\n return FooLoader.INSTANCE;\n }\n\n // Damn you serialization\n @SuppressWarnings(\"unused\")\n private Foo readResolve() {\n return FooLoader.INSTANCE;\n }\n}\n private static final Foo INSTANCE = new Foo(); FooLoader public enum Foo {\n INSTANCE;\n}\n public class Foo {\n\n // It will be our sole hero\n private static final Foo INSTANCE = new Foo();\n}\n"
},
{
"answer_id": 19562324,
"author": "rohan kamat",
"author_id": 2335562,
"author_profile": "https://Stackoverflow.com/users/2335562",
"pm_score": 1,
"selected": false,
"text": "public class Singleton {\n private static Singleton singleInstance = new Singleton();\n private Singleton() {}\n public static Singleton getSingleInstance() {\n return singleInstance;\n }\n}\n"
},
{
"answer_id": 19849576,
"author": "somenath mukhopadhyay",
"author_id": 873952,
"author_profile": "https://Stackoverflow.com/users/873952",
"pm_score": -1,
"selected": false,
"text": "public class Singleton {\n\n private static final Singleton INSTANCE = new Singleton();\n\n private Singleton() {\n if (INSTANCE != null)\n throw new IllegalStateException(“Already instantiated...”);\n }\n\n\n public synchronized static Singleton getInstance() {\n return INSTANCE;\n }\n\n}\n"
},
{
"answer_id": 27793921,
"author": "shikjohari",
"author_id": 2595642,
"author_profile": "https://Stackoverflow.com/users/2595642",
"pm_score": 0,
"selected": false,
"text": "public enum Singleton {\n INSTANCE;\n}\n"
},
{
"answer_id": 29389322,
"author": "coderz",
"author_id": 3275167,
"author_profile": "https://Stackoverflow.com/users/3275167",
"pm_score": 4,
"selected": false,
"text": "public class MySingleton {\n private static MySingleton instance = null;\n private MySingleton() {}\n public static synchronized MySingleton getInstance() {\n if(instance == null) {\n instance = new MySingleton();\n }\n return instance;\n }\n}\n synchronized public class MySingleton {\n private MySingleton() {}\n private static class MySingletonHolder {\n public final static MySingleton instance = new MySingleton();\n }\n public static MySingleton getInstance() {\n return MySingletonHolder.instance;\n }\n}\n"
},
{
"answer_id": 32906229,
"author": "Dan Moldovan",
"author_id": 2725534,
"author_profile": "https://Stackoverflow.com/users/2725534",
"pm_score": 2,
"selected": false,
"text": "public enum SingletonEnum {\n INSTANCE;\n public void doSomething(){\n System.out.println(\"This is a singleton\");\n }\n}\n public class Singleton {\n\n private static volatile Singleton instance = null;\n\n private Singleton() {\n }\n\n public static Singleton getInstance() {\n if (instance == null) {\n synchronized (Singleton.class){\n if (instance == null) {\n instance = new Singleton();\n }\n }\n }\n return instance;\n }\n}\n public class Singleton {\n\n private static final Singleton instance = new Singleton();\n\n private Singleton() {\n }\n\n public static Singleton getInstance() {\n return instance;\n }\n\n public void doSomething(){\n System.out.println(\"This is a singleton\");\n }\n\n}\n"
},
{
"answer_id": 37305099,
"author": "Nicolas Filotto",
"author_id": 1997376,
"author_profile": "https://Stackoverflow.com/users/1997376",
"pm_score": 2,
"selected": false,
"text": "public class Singleton {\n // It must be static and final to prevent later modification\n private static final Singleton INSTANCE = new Singleton();\n /** The constructor must be private to prevent external instantiation */\n private Singleton(){}\n /** The public static method allowing to get the instance */\n public static Singleton getInstance() {\n return INSTANCE;\n }\n}\n public class Singleton {\n // The constructor must be private to prevent external instantiation\n private Singleton(){}\n /** The public static method allowing to get the instance */\n public static Singleton getInstance() {\n return SingletonHolder.INSTANCE;\n }\n /**\n * The static inner class responsible for creating your instance only on demand,\n * because the static fields of a class are only initialized when the class\n * is explicitly called and a class initialization is synchronized such that only\n * one thread can perform it, this rule is also applicable to inner static class\n * So here INSTANCE will be created only when SingletonHolder.INSTANCE\n * will be called\n */\n private static class SingletonHolder {\n private static final Singleton INSTANCE = new Singleton();\n }\n}\n"
},
{
"answer_id": 38942086,
"author": "user3792852",
"author_id": 3792852,
"author_profile": "https://Stackoverflow.com/users/3792852",
"pm_score": 2,
"selected": false,
"text": "public class SingletonImpl {\n\n private static SingletonImpl instance;\n\n public static SingletonImpl getInstance() {\n if (instance == null) {\n instance = new SingletonImpl();\n }\n return instance;\n }\n\n public static void setInstance(SingletonImpl impl) {\n instance = impl;\n }\n\n public void a() {\n System.out.println(\"Default Method\");\n }\n}\n setInstance public class SingletonMock extends SingletonImpl {\n\n @Override\n public void a() {\n System.out.println(\"Mock Method\");\n }\n\n}\n public class SingletonImpl {\n\n private static final SingletonImpl instance = new SingletonImpl();\n\n private static SingletonImpl alt;\n\n public static void setInstance(SingletonImpl inst) {\n alt = inst;\n }\n\n public static SingletonImpl getInstance() {\n if (alt != null) {\n return alt;\n }\n return instance;\n }\n\n public void a() {\n System.out.println(\"Default Method\");\n }\n}\n\npublic class SingletonMock extends SingletonImpl {\n\n @Override\n public void a() {\n System.out.println(\"Mock Method\");\n }\n\n}\n"
},
{
"answer_id": 39098595,
"author": "Dheeraj Sachan",
"author_id": 3314058,
"author_profile": "https://Stackoverflow.com/users/3314058",
"pm_score": 3,
"selected": false,
"text": " public class Test {\n private static final Test test = new Test();\n\n private Test() {\n }\n\n public static Test getTest() {\n return test;\n }\n }\n public class Test {\n private static volatile Test test;\n\n private Test() {\n }\n\n public static Test getTest() {\n if(test == null) {\n synchronized(Test.class) {\n if(test == null) {\n test = new Test();\n }\n }\n }\n return test;\n }\n }\n public class Test {\n\n private Test() {\n }\n\n private static class TestHolder {\n private static final Test test = new Test();\n }\n\n public static Test getInstance() {\n return TestHolder.test;\n }\n }\n public enum MySingleton {\n INSTANCE;\n\n private MySingleton() {\n System.out.println(\"Here\");\n }\n }\n"
},
{
"answer_id": 45062746,
"author": "Michael Andrews",
"author_id": 1829927,
"author_profile": "https://Stackoverflow.com/users/1829927",
"pm_score": 4,
"selected": false,
"text": "public class MySingleton {\n\n private static MySingleton INSTANCE;\n\n public static MySingleton getInstance() {\n if (INSTANCE == null) {\n INSTANCE = new MySingleton();\n }\n return INSTANCE;\n }\n ...\n}\n private static MySingleton INSTANCE;\n\npublic static synchronized MySingleton getInstance() {\n if (INSTANCE == null) {\n INSTANCE = new MySingleton();\n }\n return INSTANCE;\n}\n private static MySingleton INSTANCE;\n\npublic static MySingleton getInstance() {\n if (INSTANCE == null) {\n synchronize(MySingleton.class) {\n INSTANCE = new MySingleton();\n }\n }\n return INSTANCE;\n}\n private static MySingleton INSTANCE;\n\npublic static MySingleton getInstance() {\n if (INSTANCE == null) {\n synchronized(MySingleton.class) {\n if (INSTANCE == null) {\n INSTANCE = createInstance();\n }\n }\n }\n return INSTANCE;\n}\n private static volatile MySingleton INSTANCE;\n\npublic static MySingleton getInstance() {\n if (INSTANCE == null) {\n synchronized(MySingleton.class) {\n if (INSTANCE == null) {\n INSTANCE = createInstance();\n }\n }\n }\n return INSTANCE;\n}\n private static volatile MySingleton INSTANCE;\n\npublic static MySingleton getInstance() {\n MySingleton result = INSTANCE;\n if (result == null) {\n synchronized(MySingleton.class) {\n result = INSTANCE;\n if (result == null) {\n INSTANCE = result = createInstance();\n }\n }\n }\n return result;\n}\n"
},
{
"answer_id": 52265460,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "public class Singleton<T> implements Supplier<T> {\n\n private boolean initialized;\n private Supplier<T> singletonSupplier;\n\n public Singleton(T singletonValue) {\n this.singletonSupplier = () -> singletonValue;\n }\n\n public Singleton(Supplier<T> supplier) {\n this.singletonSupplier = () -> {\n // The initial supplier is temporary; it will be replaced after initialization\n synchronized (supplier) {\n if (!initialized) {\n T singletonValue = supplier.get();\n // Now that the singleton value has been initialized,\n // replace the blocking supplier with a non-blocking supplier\n singletonSupplier = () -> singletonValue;\n initialized = true;\n }\n return singletonSupplier.get();\n }\n };\n }\n\n @Override\n public T get() {\n return singletonSupplier.get();\n }\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8741/"
] |
70,705 |
<p>In my day job I, and others on my team write a lot of hardware models in Verilog-AMS, a language supported primarily by commercial vendors and a few opensource simulator projects.
One thing that would make supporting each others code more helpful would be a LINTER that would check our code for common problems and assist with enforcing a shared code formatting style.
I of course want to be able to add my own rules and, after I prove their utility to myself, promote them to the rest of the team..
I don't mind doing the work that has to be done, but of course also want to leverage the work of other existing projects. </p>
<p>Does having the allowed language syntax in a yacc or bison format give me a leg up?
or should I just suck each language statement into a perl string, and use pattern matching to find the things I don't like? </p>
<p>(most syntax and compilation errors are easily caught by the commercial tools.. but we have some of our own extentions.) </p>
|
[
{
"answer_id": 70723,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 0,
"selected": false,
"text": "yacc bison"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6314/"
] |
70,721 |
<p>Last Friday where I work, an oracle client was upgarded and our IIS server from version 9 to version 10. Now that its on version 10, we are seeing a lot of connections being open up to the database. It is opening up so many connections that we cannot log onto the database using tools like PlSQL developer or Toad. We never had an issue like this when the oracle client was at version 9. Because of the number of clients that exists on this particular box, i dont think it will be possible to revert back to the Oracle 9 client.
Is anyone aware of this problem or know of any possible work arounds?</p>
<p>Any help is greatly appreciated</p>
|
[
{
"answer_id": 70723,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 0,
"selected": false,
"text": "yacc bison"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11612/"
] |
70,724 |
<p>In my job we have to deploy an application on various environments. It's a standard WAR file which needs a bit of configuration, deployed on Tomcat 6.</p>
<p>Is there any way of creating a 'deployment package' with Tomcat so that you just extract it and it sets up Tomcat as well as your application? I'm not sure that creating a .zip file with the Tomcat folder would work! It certainly wouldn't install the service.</p>
<p>Suggestions welcome!</p>
<p>I should note that - at the moment - all apps are deployed on Windows servers.</p>
<p>Thanks,
Phill</p>
|
[
{
"answer_id": 70723,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 0,
"selected": false,
"text": "yacc bison"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
70,732 |
<p>Lasty, I tried to implements an hybrid structure in Java, something that looks like:</p>
<pre><code>public class MapOfSet<K, V extends HasKey<K>> implements Set<V>, Map<K, Set<V>>
</code></pre>
<p>Where HasKey is the following interface:</p>
<pre><code>public interface HasKey<K> {
public K getKey();
}
</code></pre>
<p>Unfortunately, there are some conflicts between methos signature of the Set interface and the Map interface in Java. I've finally chosen to implements only the Set interface and to add the Map method without implementing this interface.</p>
<p>Do you see a nicer solution?</p>
<p>In response to the first comments, here is my goal:</p>
<blockquote>
<p>Have a set structure and be able to efficiently access to a subset of values of this set, corresponding to a given key value.
At the beginning I instantiated a map and a set, but I tried to joined the two structures to optimize performances.</p>
</blockquote>
|
[
{
"answer_id": 70772,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 2,
"selected": false,
"text": "Map Set SingleEntryMap put(K key, V value) public final class KeyedSets<K, V> implements Map<K,Set<V>> {\n private final Map<K, Set<V>> internalMap = new TreeMap<K, Set<V>>;\n // delegate methods go here\n public Set<V> getSortedSuperset() {\n final Set<V> superset = new TreeSet<V>();\n for (final Map.Entry<K, V> entry : internalMap.entrySet()) {\n superset.addAll(entry.getValue());\n }\n return superset;\n }\n}\n"
},
{
"answer_id": 70962,
"author": "jrudolph",
"author_id": 7647,
"author_profile": "https://Stackoverflow.com/users/7647",
"pm_score": 2,
"selected": true,
"text": "public interface GroupedSet<K, V extends HasKey<K>> extends Set<V>{\n Set<V> havingKey(K k);\n}\n Map<K,Set<V>> asMap();\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1730/"
] |
70,742 |
<p>I administrate several Oracle Apps environment, and currently check profile options in lots of environments by loading up forms in each environment, and manually checking each variable, which requires a lot of time.</p>
<p>Is there a snippet of code which will list profile options and at what level and who they are applied to?</p>
|
[
{
"answer_id": 71141,
"author": "Sten Vesterli",
"author_id": 9363,
"author_profile": "https://Stackoverflow.com/users/9363",
"pm_score": 2,
"selected": true,
"text": "APPLSYS.FND_PROFILE_OPTIONS FND_PROFILE_OPTION_VALUES"
},
{
"answer_id": 71387,
"author": "Jonathan",
"author_id": 6910,
"author_profile": "https://Stackoverflow.com/users/6910",
"pm_score": 0,
"selected": false,
"text": "SELECT SUBSTR(e.profile_option_name,1,30) PROFILE,\n DECODE(a.level_id,10001,'Site',10002,'Application',10003,'Responsibility',10004,'User') L,\n DECODE(a.level_id,10001,'Site',10002,c.application_short_name,10003,b.responsibility_name,10004,d.user_name) LValue,\n NVL(a.profile_option_value,'Is Null') Value,\n SUBSTR(a.last_update_date,1,25) UPDATED_DATE\nFROM fnd_profile_option_values a\nINNER JOIN fnd_profile_options e ON a.profile_option_id = e.profile_option_id \nLEFT OUTER JOIN fnd_responsibility_tl b ON a.level_value = b.responsibility_id\nLEFT OUTER JOIN fnd_application c ON a.level_value = c.application_id\nLEFT OUTER JOIN fnd_user d ON a.level_value = d.user_id\nWHERE e.profile_option_name LIKE '%&1%'\nORDER BY profile_option_name;\n"
},
{
"answer_id": 6454817,
"author": "caodan740",
"author_id": 812300,
"author_profile": "https://Stackoverflow.com/users/812300",
"pm_score": 0,
"selected": false,
"text": "SELECT SUBSTR(e.profile_option_name,1,30) PROFILE,\n DECODE(a.level_id,10001,'Site',10002,'Application',10003,'Responsibility',10004,'User') L,\n DECODE(a.level_id,10001,'Site',10002,c.application_short_name,10003,b.responsibility_name,10004,d.user_name) LValue,\n NVL(a.profile_option_value,'Is Null') Value,\n SUBSTR(a.last_update_date,1,25) UPDATED_DATE\nFROM fnd_profile_option_values a\nINNER JOIN fnd_profile_options e ON a.profile_option_id = e.profile_option_id \nLEFT OUTER JOIN fnd_responsibility_tl b ON a.level_value = b.responsibility_id\nLEFT OUTER JOIN fnd_application c ON a.level_value = c.application_id\nLEFT OUTER JOIN fnd_user d ON a.level_value = d.user_id\nWHERE e.profile_option_name LIKE '%&1%'\nORDER BY profile_option_name;\n"
},
{
"answer_id": 7261709,
"author": "SJ-Admin",
"author_id": 922224,
"author_profile": "https://Stackoverflow.com/users/922224",
"pm_score": 1,
"selected": false,
"text": "SELECT FP.LEVEL_ID \"Level ID\", \n FPO.PROFILE_OPTION_NAME \"PROFILE NAME\",\n FP.LEVEL_VALUE \"LEVEL VALUE\",\n DECODE (FP.LEVEL_ID,\n 10001,\n 'SITE',\n 10002,\n 'APPLICATION',\n 10003,\n 'RESPONSIBILITY',\n 10004,\n 'USER')\n \"LEVEL\",\n DECODE (FP.LEVEL_ID,\n 10001,\n 'SITE',\n 10002,\n APPLICATION_SHORT_NAME,\n 10003,\n RESPONSIBILITY_NAME,\n 10004,\n FL.USER_NAME)\n LVALUE,\n FPO.USER_PROFILE_OPTION_NAME \"PROFILE DESCRIPTION\",\n FP.PROFILE_OPTION_VALUE \"PROFILE VALUE\",\n FU.USER_NAME \"USER NAME\",\n FU.LAST_UPDATE_DATE\nFROM FND_PROFILE_OPTIONS_VL FPO,\n FND_PROFILE_OPTION_VALUES FP,\n FND_RESPONSIBILITY_TL,\n FND_APPLICATION FA,\n FND_USER FL,\n FND_USER FU\nWHERE FPO.APPLICATION_ID = FP.APPLICATION_ID\n AND FPO.PROFILE_OPTION_ID = FP.PROFILE_OPTION_ID\n AND FP.LEVEL_VALUE = FL.USER_ID(+)\n AND FP.LEVEL_VALUE = RESPONSIBILITY_ID(+)\n AND FP.LEVEL_VALUE = FA.APPLICATION_ID(+)\n AND FU.USER_ID = FP.LAST_UPDATED_BY\n AND FP.PROFILE_OPTION_VALUE IS NOT NULL\n AND (UPPER (FP.Profile_Option_Value) LIKE UPPER ('%&1%')\n OR UPPER (FP.Profile_Option_Value) LIKE UPPER ('%&2%'))\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6910/"
] |
70,756 |
<p>This confusion arises as most people are trained to evaluate arithmetic expressions as per <a href="http://en.wikipedia.org/wiki/PEMDAS#Mnemonics" rel="nofollow noreferrer">PEDMAS or BODMAS rule</a> whereas arithmetic expressions in programming languages like C# do not work in the same way.</p>
<p>What are your takes on it?</p>
|
[
{
"answer_id": 70861,
"author": "jrudolph",
"author_id": 7647,
"author_profile": "https://Stackoverflow.com/users/7647",
"pm_score": 2,
"selected": false,
"text": "!person.isMarried && person.age == 25 + 2 * 5\n 1 + 2 + 3 + 4\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4021/"
] |
70,758 |
<p>I know you can put <% if %> statements in the ItemTemplate to hide controls but the column is still there.
You cannot put <% %> statements into the LayoutTemplate which is where the column headings are declared, hence the problem.
Does anyone know of a better way?</p>
|
[
{
"answer_id": 71015,
"author": "Jason",
"author_id": 7391,
"author_profile": "https://Stackoverflow.com/users/7391",
"pm_score": 0,
"selected": false,
"text": "style='display: <%#Eval(\"DisplayStyle\") %>;'\n"
},
{
"answer_id": 71261,
"author": "Dean Poulin",
"author_id": 5462,
"author_profile": "https://Stackoverflow.com/users/5462",
"pm_score": 1,
"selected": false,
"text": "visible ='<%# %>' <asp:ListView ID=\"ListView1\" runat=\"server\" DataSourceID=\"MyDataSource\" ItemPlaceholderID=\"itemPlaceHolder\">\n <LayoutTemplate>\n <table>\n <asp:PlaceHolder ID=\"itemPlaceHolder\" runat=\"server\" />\n </table>\n </LayoutTemplate>\n <ItemTemplate>\n <tr>\n <td runat=\"server\" id=\"myCol\" visible='<%# (bool)Eval(\"IsSuperCool\") %>'>\n <%# Eval(\"SuperCoolIcon\") %>\n </td>\n <td>\n <%# Eval(\"Name\") %>\n </td>\n <td>\n <%# Eval(\"Age\") %>\n </td>\n </tr>\n </ItemTemplate>\n</asp:ListView>\n"
},
{
"answer_id": 76264,
"author": "Dean Poulin",
"author_id": 5462,
"author_profile": "https://Stackoverflow.com/users/5462",
"pm_score": 5,
"selected": true,
"text": " <asp:ListView ID=\"ListView1\" runat=\"server\" DataSourceID=\"MyDataSource\" ItemPlaceholderID=\"itemPlaceHolder\" OnDataBound=\"ListView1_DataBound\">\n <LayoutTemplate>\n <table border=\"1\">\n <tr>\n <td>Name</td>\n <td>Age</td>\n <td runat=\"server\" id=\"tdIsSuperCool\">IsSuperCool</td>\n </tr>\n <asp:PlaceHolder ID=\"itemPlaceHolder\" runat=\"server\" />\n </table>\n </LayoutTemplate>\n <ItemTemplate>\n <tr>\n <td><%# Eval(\"Name\") %></td>\n <td><%# Eval(\"Age\") %></td>\n <td runat=\"server\" id=\"myCol\" visible='<%# (bool)Eval(\"IsSuperCool\") %>'>true</td>\n </tr>\n </ItemTemplate>\n </asp:ListView>\n <asp:ObjectDataSource \n ID=\"MyDataSource\" \n runat=\"server\" \n DataObjectTypeName=\"BusinessLogicLayer.Thing\" \n SelectMethod=\"SelectThings\"\n TypeName=\"BusinessLogicLayer.MyObjectDataSource\" />\n /// <summary>\n/// Handles the DataBound event of the ListView1 control.\n/// </summary>\n/// <param name=\"sender\">The source of the event.</param>\n/// <param name=\"e\">The <see cref=\"System.EventArgs\"/> instance containing the event data.</param>\nprotected void ListView1_DataBound(object sender, EventArgs e)\n{\n ListView1.FindControl(\"tdIsSuperCool\").Visible = false;\n}\n"
},
{
"answer_id": 118758,
"author": "Fred",
"author_id": 9012,
"author_profile": "https://Stackoverflow.com/users/9012",
"pm_score": 2,
"selected": false,
"text": " foreach (ListViewItem item in ListView1.Items)\n {\n ((Panel)item.FindControl(\"myPanel\")).Visible= False;\n }\n"
},
{
"answer_id": 41151941,
"author": "jason",
"author_id": 1709186,
"author_profile": "https://Stackoverflow.com/users/1709186",
"pm_score": 1,
"selected": false,
"text": "<script type=\"text/javascript\" src=\"Scripts/jquery-1.7.1.min.js\" ></script>\n <style>\n .hide {\n display:none;\n }\n .show {\n display:block;\n }\n </style>\n <th runat=\"server\" data-prop='authcheck' id=\"tdcommentsHeader\" >Comments</th>\n <asp:HiddenField runat=\"server\" ID=\"IsAuthorized\" Value=\"false\" />\n <script type=\"text/javascript\">\n $(document).ready(function () {\n var isauth = $(\"[id='IsAuthorized']\").val();\n if (isauth===\"false\") {\n $(\"[data-prop='authcheck']\").addClass('hide');\n //$(\"[id*='tdcomments']\").addClass('hide'); \n }\n });\n </script>\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70758",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10186/"
] |
70,773 |
<p>What are the pros / cons of using <code>pthread_cond_wait</code> or using a semaphore ?
I am waiting for a state change like this :</p>
<pre><code>pthread_mutex_lock(&cam->video_lock);
while(cam->status == WAIT_DISPLAY) {
pthread_cond_wait(&cam->video_cond, &cam->video_lock);
}
pthread_mutex_unlock(&cam->video_lock);
</code></pre>
<p>Using a properly initialised semaphore, I think I could do it like this :</p>
<pre><code>while(cam->status == WAIT_DISPLAY) {
sem_wait(&some_semaphore);
}
</code></pre>
<p>What are the pros and cons of each method ?</p>
|
[
{
"answer_id": 71301,
"author": "freespace",
"author_id": 8297,
"author_profile": "https://Stackoverflow.com/users/8297",
"pm_score": 4,
"selected": false,
"text": "m s m m s c s m c m c m pthread_cond_broadcast"
},
{
"answer_id": 434872,
"author": "Blaisorblade",
"author_id": 53974,
"author_profile": "https://Stackoverflow.com/users/53974",
"pm_score": 3,
"selected": false,
"text": "pthread_cond_broadcast"
},
{
"answer_id": 71291384,
"author": "Abhishek Sagar",
"author_id": 756120,
"author_profile": "https://Stackoverflow.com/users/756120",
"pm_score": 0,
"selected": false,
"text": "while(cam->status == WAIT_DISPLAY) {\n sem_wait(&some_semaphore);\n}\n"
}
] |
2008/09/16
|
[
"https://Stackoverflow.com/questions/70773",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11589/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.