qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
257,551
|
<p>I have a method that, given an angle for North and an angle for a bearing, returns a compass point value from 8 possible values (North, NorthEast, East, etc.). I want to create a unit test that gives decent coverage of this method, providing different values for North and Bearing to ensure I have adequate coverage to give me confidence that my method is working.</p>
<p>My original attempt generated all possible whole number values for North from -360 to 360 and tested each Bearing value from -360 to 360. However, my test code ended up being another implementation of the code I was testing. This left me wondering what the best test would be for this such that my test code isn't just going to contain the same errors that my production code might.</p>
<p>My current solution is to spend time writing an XML file with data points and expected results, which I can read in during the test and use to validate the method but this seems exceedingly time consuming. I don't want to write a file that contains the same range of values that my original test contained (that would be a lot of XML) but I do want to include enough to adequately test the method.</p>
<ul>
<li>How do I test a method without just reimplementing the method?</li>
<li>How do I achieve adequate coverage to have confidence in the method I am testing without having to have test points for all possible inputs and results?</li>
</ul>
<p>Obviously, don't dwell too much on my specific example as this applies to many situations where there are complex calculations and ranges of data to be tested.</p>
<p>NOTE: I am using Visual Studio and C#, but I believe this question is language-agnostic.</p>
|
[
{
"answer_id": 257574,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "def testCase215n( self ):\n self.fixture.setCourse( 215 )\n self.fixture.setBearing( 45 )\n self.fixture.calculate()\n self.assertEquals( \"N\", self.fixture.compass() )\n"
},
{
"answer_id": 267726,
"author": "Olie",
"author_id": 34820,
"author_profile": "https://Stackoverflow.com/users/34820",
"pm_score": 0,
"selected": false,
"text": "array colors = { red, orange, yellow, green, blue, brown, black, white }\nfor north = -360 to 361\n for bearing = -361 to 361\n theColor = colors[dirFunction(north, bearing)] // dirFunction is the one being tested\n setColor (theColor)\n drawLine (centerX, centerY,\n centerX + (cos(north + bearing) * radius),\n centerY + (sin(north + bearing) * radius))\n Verify Resulting Circle against rotated reference diagram.\n"
}
] |
2008/11/02
|
[
"https://Stackoverflow.com/questions/257551",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23234/"
] |
257,552
|
<p>Does anyone know of a simple way for a C++ program to communicate directly with a MySQL database? I have looked at MySQL++ and found it to be very confusing. If anyone knows of a very simple way of doing this, please let me know.</p>
<p>Thanks</p>
<p>P.S. I am developing on a Windows machine. PHP and MySQL web web application setup. C++ setup to talk to the serial port. Thus why I need a way for C++ to talk to the MySQL database directly.</p>
|
[
{
"answer_id": 257675,
"author": "MattyT",
"author_id": 7405,
"author_profile": "https://Stackoverflow.com/users/7405",
"pm_score": 3,
"selected": false,
"text": "int id = ...;\nstring name;\nint salary;\n\nsql << \"select name, salary from persons where id = \" << id, into(name), into(salary);\n"
}
] |
2008/11/02
|
[
"https://Stackoverflow.com/questions/257552",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
257,563
|
<p>hey, I'm very new to all this so please excuse stupidity :)</p>
<pre><code>import os
import MySQLdb
import time
db = MySQLdb.connect(host="localhost", user="root", passwd="********", db="workspace")
cursor = db.cursor()
tailoutputfile = os.popen('tail -f syslog.log')
while 1:
x = tailoutputfile.readline()
if len(x)==0:
break
y = x.split()
if y[2] == 'BAD':
timestring = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
cursor.execute("INSERT INTO releases (date, cat, name) values (timestring, y[4], y[7]")
if y[2] == 'GOOD':
print y[4] + '\t' + y[7]
</code></pre>
<p>so i run the program and this is the error message I am getting</p>
<pre><code>user@machine:~/$ python reader.py
Traceback (most recent call last):
File "reader.py", line 17, in ?
cursor.execute("INSERT INTO releases (date, cat, name) values (timestring, y[4], y[7]")
File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 163, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[4], y[7]' at line 1")
user@machine:~/$
</code></pre>
<p>So i'm assuming that the error is obviously coming from the SQL Statement </p>
<pre><code>cursor.execute("INSERT INTO releases (date, cat, name) values (timestring, y[4], y[7]")
</code></pre>
<p>Here is an example of what y[4] and y[7] will look like. </p>
<pre><code>YES Mail.Sent.To.User:user@work.com.11.2.2008:23.17
</code></pre>
<p>Is this error happening because I should be escaping those values before I try and Insert them into the Database?
Or am I completely missing the point??</p>
<p>Any help would be appreciated!
thanks in advance. </p>
|
[
{
"answer_id": 257570,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": 2,
"selected": false,
"text": " cursor.execute(\"INSERT INTO releases (date, cat, name) values (timestring, y[4], y[7]\")\n cursor.execute(\"INSERT INTO releases (date, cat, name) values (timestring, '%s', '%s')\" % (y[4], y[7]))\n query = \"INSERT INTO releases (date, cat, name) values (timestring, '%s', '%s')\" % (y[4], y[7])\nprint query\ncursor.execute(query)\n"
},
{
"answer_id": 257614,
"author": "bobince",
"author_id": 18936,
"author_profile": "https://Stackoverflow.com/users/18936",
"pm_score": 4,
"selected": true,
"text": "cursor.execute(\"INSERT INTO releases (date, cat, name) VALUES ('%s', '%s', '%s')\" % (timestring, y[4], y[7]))\n cursor.execute('INSERT INTO releases (date, cat, name) VALUES (%s, %s, %s)', (timestring, y[4], y[7]))\n"
},
{
"answer_id": 298414,
"author": "slav0nic",
"author_id": 2201031,
"author_profile": "https://Stackoverflow.com/users/2201031",
"pm_score": 1,
"selected": false,
"text": "cursor.execute('INSERT INTO releases (date, cat, name) VALUES (%s, %s, %s)', (timestring, y[4], y[7]))\n"
}
] |
2008/11/02
|
[
"https://Stackoverflow.com/questions/257563",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33512/"
] |
257,566
|
<p>I am attempting to use a Stream Result to return an image from a struts2 application. I seem to be having problem with configuring the action. Here is the configuration:</p>
<pre><code> <result name="success" type="stream">
<param name="contentType">image/jpeg</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">filename="${filename}"</param>
<param name="bufferSize">1024</param>
</result>
</code></pre>
<p>The problem seem to be the inputName parameter which according to the docs is:</p>
<blockquote>
<p>the name of the InputStream property from the chained action (default = inputStream).</p>
</blockquote>
<p>I am not sure what name I should put there. The error I get is: </p>
<blockquote>
<p>Can not find a java.io.InputStream with the name [inputStream] in the invocation stack.</p>
</blockquote>
<p>Has anyone used this before? Any advice?</p>
<p>Thanks.</p>
|
[
{
"answer_id": 257646,
"author": "Vincent Ramdhanie",
"author_id": 27439,
"author_profile": "https://Stackoverflow.com/users/27439",
"pm_score": 4,
"selected": true,
"text": "InputStream InputStream"
},
{
"answer_id": 826627,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "<param name=\"contentDisposition\">attachment; filename=\"${filename}\"</param>\n"
}
] |
2008/11/02
|
[
"https://Stackoverflow.com/questions/257566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27439/"
] |
257,577
|
<p>Im thinking of updating my practices, and looking for a little help and advice!</p>
<p>I do a lot of work on sites that run joomla, oscommerce, drupal etc and so I have created a lot of custom components/plugins and hacks etc. Currently each site has its own folder on my xampp setup. What I would like to do is have a default setup of (for example) a Joomla setup and when I make changes updates, I can do something which updates all the other folders that contain joomla, almost like an auto update?</p>
<p>Im also looking at using Aptana IDE more and SVN service such as <a href="http://unfuddle.com/" rel="nofollow noreferrer">unfuddle</a> to share my work with others, but I have not used SVN before and not sure if its possible to do the above using SVN?</p>
<p>It would be great to be able to work on a main/core item and send the updates to both local updates and to actual servers, without having to maintain lots of different individual sites.</p>
<p>Suggestions?</p>
|
[
{
"answer_id": 257617,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 3,
"selected": true,
"text": "checkout export"
}
] |
2008/11/02
|
[
"https://Stackoverflow.com/questions/257577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28241/"
] |
257,583
|
<p>I need to schedule several different pages on several different sites to be run at certain times, usually once a night. Is there any software out there to do this? it would be nice if it called the page and then recorded the response and whether the called page was successful run or not. I was using Helm on a different box and it had a nice Web Scheduler module but Helm is not an option for this machine. This is a Window Server 2008 box.</p>
|
[
{
"answer_id": 259414,
"author": "JoshBaltzell",
"author_id": 29997,
"author_profile": "https://Stackoverflow.com/users/29997",
"pm_score": 4,
"selected": true,
"text": "webrun.vbs http://website.com/page.aspx\n dim URL, oArgs \n\nSet oArgs = WScript.Arguments \n\n if oArgs.Count = 0 then \n msgbox(\"Error: Must supply URL\") \n wscript.quit 1 \n end if \n\nURL = oArgs(0) \n\n on error resume next \nSet objXML = CreateObject(\"MSXML2.ServerXMLHTTP\") \n\n if err then \n msgbox(\"Error: \" & err.description) \n wscript.quit 1 \n end if \n\n' Call the remote machine the request \n objXML.open \"GET\", URL, False \n\n objXML.send() \n\n' return the response \n 'msgbox objXML.responSetext \n\n' clean up \n Set objXML = Nothing \n"
},
{
"answer_id": 268908,
"author": "Slee",
"author_id": 34548,
"author_profile": "https://Stackoverflow.com/users/34548",
"pm_score": 0,
"selected": false,
"text": "Call LogEntry()\nSub LogEntry()\n\n'Force the script to finish on an error.\nOn Error Resume Next\n\n'Declare variables\nDim objRequest\nDim URLs\nURLs = Wscript.Arguments(0)\nSet objRequest = CreateObject(\"Microsoft.XMLHTTP\")\n\n'Open the HTTP request and pass the URL to the objRequest object\nobjRequest.open \"POST\", URLs, false\n\n'Send the HTML Request\nobjRequest.Send\n\nSet objRequest = Nothing\nWScript.Quit\n\nEnd Sub\n"
},
{
"answer_id": 6466307,
"author": "Matthijs",
"author_id": 813867,
"author_profile": "https://Stackoverflow.com/users/813867",
"pm_score": 1,
"selected": false,
"text": "dim URL, oArgs, objXML\nSet oArgs = WScript.Arguments\nURL = oArgs(0)\n\non error resume next\n\nSet objXML = CreateObject(\"Microsoft.XMLDOM\")\nobjXML.async = \"false\"\nobjXML.load(URL)\nSet objXML = Nothing\n"
}
] |
2008/11/02
|
[
"https://Stackoverflow.com/questions/257583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34548/"
] |
257,587
|
<p>How can I bring my WPF application to the front of the desktop? So far I've tried:</p>
<pre><code>SwitchToThisWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle, true);
SetWindowPos(new WindowInteropHelper(Application.Current.MainWindow).Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
SetForegroundWindow(new WindowInteropHelper(Application.Current.MainWindow).Handle);
</code></pre>
<p>None of which are doing the job (<code>Marshal.GetLastWin32Error()</code> is saying these operations completed successfully, and the P/Invoke attributes for each definition do have <code>SetLastError=true</code>).</p>
<p>If I create a new blank WPF application, and call <code>SwitchToThisWindow</code> with a timer, it works exactly as expected, so I'm not sure why it's not working in my original case.</p>
<p><strong>Edit</strong>: I'm doing this in conjunction with a global hotkey.</p>
|
[
{
"answer_id": 257741,
"author": "Factor Mystic",
"author_id": 1569,
"author_profile": "https://Stackoverflow.com/users/1569",
"pm_score": 3,
"selected": true,
"text": "void hotkey_execute()\n{\n IntPtr handle = new WindowInteropHelper(Application.Current.MainWindow).Handle;\n BackgroundWorker bg = new BackgroundWorker();\n bg.DoWork += new DoWorkEventHandler(delegate\n {\n Thread.Sleep(10);\n SwitchToThisWindow(handle, true);\n });\n bg.RunWorkerAsync();\n}\n"
},
{
"answer_id": 383708,
"author": "Morten Christiansen",
"author_id": 4055,
"author_profile": "https://Stackoverflow.com/users/4055",
"pm_score": 8,
"selected": false,
"text": "myWindow.Activate();\n myWindow.TopMost = true;\n"
},
{
"answer_id": 1565204,
"author": "Amir",
"author_id": 189704,
"author_profile": "https://Stackoverflow.com/users/189704",
"pm_score": 5,
"selected": false,
"text": "private void Window_ContentRendered(object sender, EventArgs e)\n{\n this.Topmost = false;\n}\n\nprivate void Window_Initialized(object sender, EventArgs e)\n{\n this.Topmost = true;\n}\n protected override void OnContentRendered(EventArgs e)\n{\n base.OnContentRendered(e);\n Topmost = false;\n}\n\nprotected override void OnInitialized(EventArgs e)\n{\n base.OnInitialized(e);\n Topmost = true;\n}\n"
},
{
"answer_id": 3886715,
"author": "Seth",
"author_id": 339831,
"author_profile": "https://Stackoverflow.com/users/339831",
"pm_score": 3,
"selected": false,
"text": "void Window_Loaded(object sender, RoutedEventArgs e)\n{\n // make sure the window is normal or maximised\n // this was the core of the problem for me;\n // even though the default was \"Normal\", starting it via shell minimised it\n this.WindowState = WindowState.Normal;\n\n // only required for some scenarios\n this.Activate();\n}\n"
},
{
"answer_id": 4157347,
"author": "rahmud",
"author_id": 504840,
"author_profile": "https://Stackoverflow.com/users/504840",
"pm_score": 2,
"selected": false,
"text": "public partial class Form1 : Form\n{\n [DllImportAttribute(\"User32.dll\")]\n private static extern int FindWindow(String ClassName, String WindowName);\n [DllImportAttribute(\"User32.dll\")]\n private static extern int SetForegroundWindow(int hWnd);\n foreach (Process proc in Process.GetProcesses())\n {\n tx = proc.MainWindowTitle.ToString();\n if (tx.IndexOf(\"Title of Your app WITHOUT FIRST LETTER\") > 0)\n {\n tx = proc.MainWindowTitle;\n hWnd = proc.Handle.ToInt32(); break;\n }\n }\n hWnd = FindWindow(null, tx);\n if (hWnd > 0)\n {\n SetForegroundWindow(hWnd);\n }\n"
},
{
"answer_id": 4831839,
"author": "Jader Dias",
"author_id": 48465,
"author_profile": "https://Stackoverflow.com/users/48465",
"pm_score": 8,
"selected": false,
"text": "if (!Window.IsVisible)\n{\n Window.Show();\n}\n\nif (Window.WindowState == WindowState.Minimized)\n{\n Window.WindowState = WindowState.Normal;\n}\n\nWindow.Activate();\nWindow.Topmost = true; // important\nWindow.Topmost = false; // important\nWindow.Focus(); // important\n"
},
{
"answer_id": 7559766,
"author": "Hertzel Guinness",
"author_id": 293974,
"author_profile": "https://Stackoverflow.com/users/293974",
"pm_score": 5,
"selected": false,
"text": "DoOnProcess public class MoveToForeground\n{\n [DllImportAttribute(\"User32.dll\")]\n private static extern int FindWindow(String ClassName, String WindowName);\n\n const int SWP_NOMOVE = 0x0002;\n const int SWP_NOSIZE = 0x0001; \n const int SWP_SHOWWINDOW = 0x0040;\n const int SWP_NOACTIVATE = 0x0010;\n [DllImport(\"user32.dll\", EntryPoint = \"SetWindowPos\")]\n public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);\n\n public static void DoOnProcess(string processName)\n {\n var allProcs = Process.GetProcessesByName(processName);\n if (allProcs.Length > 0)\n {\n Process proc = allProcs[0];\n int hWnd = FindWindow(null, proc.MainWindowTitle.ToString());\n // Change behavior by settings the wFlags params. See http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx\n SetWindowPos(new IntPtr(hWnd), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE);\n }\n }\n}\n"
},
{
"answer_id": 11552906,
"author": "Zodman",
"author_id": 117797,
"author_profile": "https://Stackoverflow.com/users/117797",
"pm_score": 5,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Windows.Interop;\nusing System.Runtime.InteropServices;\n\nnamespace System.Windows\n{\n public static class SystemWindows\n {\n #region Constants\n\n const UInt32 SWP_NOSIZE = 0x0001;\n const UInt32 SWP_NOMOVE = 0x0002;\n const UInt32 SWP_SHOWWINDOW = 0x0040;\n\n #endregion\n\n /// <summary>\n /// Activate a window from anywhere by attaching to the foreground window\n /// </summary>\n public static void GlobalActivate(this Window w)\n {\n //Get the process ID for this window's thread\n var interopHelper = new WindowInteropHelper(w);\n var thisWindowThreadId = GetWindowThreadProcessId(interopHelper.Handle, IntPtr.Zero);\n\n //Get the process ID for the foreground window's thread\n var currentForegroundWindow = GetForegroundWindow();\n var currentForegroundWindowThreadId = GetWindowThreadProcessId(currentForegroundWindow, IntPtr.Zero);\n\n //Attach this window's thread to the current window's thread\n AttachThreadInput(currentForegroundWindowThreadId, thisWindowThreadId, true);\n\n //Set the window position\n SetWindowPos(interopHelper.Handle, new IntPtr(0), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);\n\n //Detach this window's thread from the current window's thread\n AttachThreadInput(currentForegroundWindowThreadId, thisWindowThreadId, false);\n\n //Show and activate the window\n if (w.WindowState == WindowState.Minimized) w.WindowState = WindowState.Normal;\n w.Show();\n w.Activate();\n }\n\n #region Imports\n\n [DllImport(\"user32.dll\")]\n private static extern IntPtr GetForegroundWindow();\n\n [DllImport(\"user32.dll\")]\n private static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);\n\n [DllImport(\"user32.dll\")]\n private static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);\n\n [DllImport(\"user32.dll\")]\n public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);\n\n #endregion\n }\n}\n"
},
{
"answer_id": 11991009,
"author": "Omzig",
"author_id": 1178375,
"author_profile": "https://Stackoverflow.com/users/1178375",
"pm_score": 3,
"selected": false,
"text": "<Window .... \n Topmost=\"True\" \n .... \n ContentRendered=\"mainWindow_ContentRendered\"> .... </Window>\n private void mainWindow_ContentRendered(object sender, EventArgs e)\n{\n this.Topmost = false;\n this.Activate();\n _UsernameTextBox.Focus();\n}\n"
},
{
"answer_id": 26023969,
"author": "Chris",
"author_id": 1421982,
"author_profile": "https://Stackoverflow.com/users/1421982",
"pm_score": 0,
"selected": false,
"text": " this.Hide();\n this.Show();\n"
},
{
"answer_id": 27420355,
"author": "Jamaxack",
"author_id": 2077676,
"author_profile": "https://Stackoverflow.com/users/2077676",
"pm_score": 3,
"selected": false,
"text": " if (!WindowName.IsVisible)\n {\n WindowName.Show();\n WindowName.Activate();\n }\n"
},
{
"answer_id": 36740759,
"author": "Contango",
"author_id": 107409,
"author_profile": "https://Stackoverflow.com/users/107409",
"pm_score": 4,
"selected": false,
"text": "window.Focus() window.Focus() window.Activate() window.ShowActivated = false Visibility.Visible window.Show() window.Hide() UserControl Loaded <UserControl x:Class=\"...\"\n ...\n attachedProperties:EnsureWindowInForeground.EnsureWindowInForeground=\n \"{Binding EnsureWindowInForeground, Mode=OneWay}\">\n public static class HideAndShowWindowHelper\n{\n /// <summary>\n /// Intent: Ensure that small notification window is on top of other windows.\n /// </summary>\n /// <param name=\"window\"></param>\n public static void ShiftWindowIntoForeground(Window window)\n {\n try\n {\n // Prevent the window from grabbing focus away from other windows the first time is created.\n window.ShowActivated = false;\n\n // Do not use .Show() and .Hide() - not compatible with Citrix!\n if (window.Visibility != Visibility.Visible)\n {\n window.Visibility = Visibility.Visible;\n }\n\n // We can't allow the window to be maximized, as there is no de-maximize button!\n if (window.WindowState == WindowState.Maximized)\n {\n window.WindowState = WindowState.Normal;\n }\n\n window.Topmost = true;\n }\n catch (Exception)\n {\n // Gulp. Avoids \"Cannot set visibility while window is closing\".\n }\n }\n\n /// <summary>\n /// Intent: Ensure that small notification window can be hidden by other windows.\n /// </summary>\n /// <param name=\"window\"></param>\n public static void ShiftWindowIntoBackground(Window window)\n {\n try\n {\n // Prevent the window from grabbing focus away from other windows the first time is created.\n window.ShowActivated = false;\n\n // Do not use .Show() and .Hide() - not compatible with Citrix!\n if (window.Visibility != Visibility.Collapsed)\n {\n window.Visibility = Visibility.Collapsed;\n }\n\n // We can't allow the window to be maximized, as there is no de-maximize button!\n if (window.WindowState == WindowState.Maximized)\n {\n window.WindowState = WindowState.Normal;\n }\n\n window.Topmost = false;\n }\n catch (Exception)\n {\n // Gulp. Avoids \"Cannot set visibility while window is closing\".\n }\n }\n}\n private ToastView _toastViewWindow;\nprivate void ShowWindow()\n{\n if (_toastViewWindow == null)\n {\n _toastViewWindow = new ToastView();\n _dialogService.Show<ToastView>(this, this, _toastViewWindow, true);\n }\n ShiftWindowOntoScreenHelper.ShiftWindowOntoScreen(_toastViewWindow);\n HideAndShowWindowHelper.ShiftWindowIntoForeground(_toastViewWindow);\n}\n\nprivate void HideWindow()\n{\n if (_toastViewWindow != null)\n {\n HideAndShowWindowHelper.ShiftWindowIntoBackground(_toastViewWindow);\n }\n}\n"
},
{
"answer_id": 42050523,
"author": "Matrix",
"author_id": 3779636,
"author_profile": "https://Stackoverflow.com/users/3779636",
"pm_score": 2,
"selected": false,
"text": "Activated=\"Window_Activated\"\n public MainWindow()\n{\n InitializeComponent();\n this.LocationChanged += (sender, e) => this.Window_Activated(sender, e);\n}\n private void Window_Activated(object sender, EventArgs e)\n{\n if (Application.Current.Windows.Count > 1)\n {\n foreach (Window win in Application.Current.Windows)\n try\n {\n if (!win.Equals(this))\n {\n if (!win.IsVisible)\n {\n win.ShowDialog();\n }\n\n if (win.WindowState == WindowState.Minimized)\n {\n win.WindowState = WindowState.Normal;\n }\n\n win.Activate();\n win.Topmost = true;\n win.Topmost = false;\n win.Focus();\n }\n }\n catch { }\n }\n else\n this.Focus();\n}\n"
},
{
"answer_id": 43379830,
"author": "d.moncada",
"author_id": 701560,
"author_profile": "https://Stackoverflow.com/users/701560",
"pm_score": 2,
"selected": false,
"text": "protected override void OnStartup(object sender, StartupEventArgs e)\n{\n DisplayRootViewFor<IMainWindowViewModel>();\n\n Application.MainWindow.Topmost = true;\n Application.MainWindow.Activate();\n Application.MainWindow.Activated += OnMainWindowActivated;\n}\n\nprivate static void OnMainWindowActivated(object sender, EventArgs e)\n{\n var window = sender as Window;\n if (window != null)\n {\n window.Activated -= OnMainWindowActivated;\n window.Topmost = false;\n window.Focus();\n }\n}\n"
},
{
"answer_id": 44054778,
"author": "Mike",
"author_id": 7612816,
"author_profile": "https://Stackoverflow.com/users/7612816",
"pm_score": -1,
"selected": false,
"text": "using System.Windows.Forms;\n namespace YourNamespace{\n public static class WindowsFormExtensions {\n public static void PutOnTop(this Form form) {\n form.Show();\n form.Activate();\n }// END PutOnTop() \n }// END class\n }// END namespace\n namespace YourNamespace{\n public partial class FormName : Form {\n public FormName(){\n this.PutOnTop();\n InitalizeComponents();\n }// END Constructor\n } // END Form \n}// END namespace\n"
},
{
"answer_id": 70382243,
"author": "Alex Martin",
"author_id": 2237888,
"author_profile": "https://Stackoverflow.com/users/2237888",
"pm_score": 0,
"selected": false,
"text": "public partial class MainWindow : Window\n{\n protected override void OnContentRendered(EventArgs e)\n {\n base.OnContentRendered(e);\n\n Topmost = true;\n Topmost = false;\n }\n protected override void OnInitialized(EventArgs e)\n {\n base.OnInitialized(e);\n\n Topmost = true;\n Topmost = false;\n }\n\n ....\n}\n"
}
] |
2008/11/02
|
[
"https://Stackoverflow.com/questions/257587",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1569/"
] |
257,605
|
<p>I'm currently working on a small project with OCaml; a simple mathematical expression simplifier. I'm supposed to find certain patterns inside an expression, and simplify them so the number of parenthesis inside the expression decreases. So far I've been able to implement most rules except two, for which I've decided to create a recursive, pattern-matching "filter" function. The two rules I need to implement are:</p>
<p>-Turn all expressions of the form a - (b + c) or similar into a - b - c</p>
<p>-Turn all expressions of the form a / (b * c) or similar into a / b / c</p>
<p>...which I suspect would be fairly simple, and once I've managed to implement one, I can implement the other easily. However, I'm having trouble with the recursive pattern-matching function. My type expression is this:</p>
<pre><code>type expr =
| Var of string (* variable *)
| Sum of expr * expr (* sum *)
| Diff of expr * expr (* difference *)
| Prod of expr * expr (* product *)
| Quot of expr * expr (* quotient *)
;;
</code></pre>
<p>And what I'm mainly having trouble on, is in the match expression. For example, I'm trying something like this:</p>
<pre><code>let rec filter exp =
match exp with
| Var v -> Var v
| Sum(e1, e2) -> Sum(e1, e2)
| Prod(e1, e2) -> Prod(e1, e2)
| Diff(e1, e2) ->
match e2 with
| Sum(e3, e4) -> filter (diffRule e2)
| Diff(e3, e4) -> filter (diffRule e2)
| _ -> filter e2
| Quot(e1, e2) -> ***this line***
match e2 with
| Quot(e3, e4) -> filter (quotRule e2)
| Prod(e3, e4) -> filter (quotRule e2)
| _ -> filter e2
;;
</code></pre>
<p>However, it seems that the match expression on the marked line is being recognized as being part of the previous "inner match" instead of the "principal match", so all "Quot(...)" expressions are never recognized. Is it even possible to have match expressions inside other match expressions like this? And what would be the correct way to end the inner match so I can continue matching the other possibilities?</p>
<p>Ignore the logic, since it's pretty much what I came up with first, it's just that I haven't been able to try it since I have to deal with this "match" error first, although any recommendation on how to handle the recursiveness or the logic would be welcome.</p>
|
[
{
"answer_id": 257627,
"author": "vog",
"author_id": 19163,
"author_profile": "https://Stackoverflow.com/users/19163",
"pm_score": 7,
"selected": true,
"text": "begin end let rec filter exp =\n match exp with\n | Var v -> Var v\n | Sum (e1, e2) -> Sum (e1, e2)\n | Prod (e1, e2) -> Prod (e1, e2)\n | Diff (e1, e2) ->\n (match e2 with\n | Sum (e3, e4) -> filter (diffRule e2)\n | Diff (e3, e4) -> filter (diffRule e2)\n | _ -> filter e2)\n | Quot (e1, e2) ->\n (match e2 with\n | Quot (e3, e4) -> filter (quotRule e2)\n | Prod (e3, e4) -> filter (quotRule e2)\n | _ -> filter e2)\n;;\n | let rec filter exp =\n match exp with\n | Var v -> Var v\n | Sum (e1, e2) -> Sum (e1, e2)\n | Prod (e1, e2) -> Prod (e1, e2)\n | Diff (e1, (Sum (e3, e4) | Diff (e3, e4) as e2)) -> filter (diffRule e2)\n | Diff (e1, e2) -> filter e2\n | Quot (e1, (Quot (e3, e4) | Prod (e3, e4) as e2)) -> filter (quotRule e2)\n | Quot (e1, e2) -> filter e2\n;;\n _ (e3,e4) let rec filter exp =\n match exp with\n | Var v -> Var v\n | Sum (e1, e2) -> Sum (e1, e2)\n | Prod (e1, e2) -> Prod (e1, e2)\n | Diff (_, (Sum _ | Diff _ as e2)) -> filter (diffRule e2)\n | Diff (_, e2) -> filter e2\n | Quot (_, (Quot _ | Prod _ as e2)) -> filter (quotRule e2)\n | Quot (_, e2) -> filter e2\n;;\n Var Sum Prod let rec filter exp =\n match exp with\n | Var _ | Sum _ | Prod _ as e -> e\n | Diff (_, (Sum _ | Diff _ as e2)) -> filter (diffRule e2)\n | Diff (_, e2) -> filter e2\n | Quot (_, (Quot _ | Prod _ as e2)) -> filter (quotRule e2)\n | Quot (_, e2) -> filter e2\n;;\n e2 e match function let rec filter = function\n | Var _ | Sum _ | Prod _ as e -> e\n | Diff (_, (Sum _ | Diff _ as e)) -> filter (diffRule e)\n | Diff (_, e) -> filter e\n | Quot (_, (Quot _ | Prod _ as e)) -> filter (quotRule e)\n | Quot (_, e) -> filter e\n;;\n"
},
{
"answer_id": 264060,
"author": "zrr",
"author_id": 34515,
"author_profile": "https://Stackoverflow.com/users/34515",
"pm_score": 3,
"selected": false,
"text": "let rec filter = function\n| Var _ | Sum _ | Prod _ as e -> e\n| Diff (_, (Sum _ | Diff _) as e) -> filter (diffRule e)\n| Diff (_,e) -> e\n| Quot (_, (Quot _| Prod _) as e) -> filter (quoteRule e)\n| Quot (_,e) -> filter e\n;;\n"
}
] |
2008/11/02
|
[
"https://Stackoverflow.com/questions/257605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9506/"
] |
257,609
|
<p>I am trying to interpret HttpReferer strings in our server logs. It seems like there is quite a high number of empty values.</p>
<p>I am wondering how many of these empty values are due to direct hits from people entering our URL directly into a browser and how many might be due to some kind of blocking utility that prevents the Referer from being sent.</p>
<p>I really have no idea how many people are using tools or browsers or 'anonymizers' that might block the refer. Any input?</p>
|
[
{
"answer_id": 257657,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": -1,
"selected": false,
"text": "3rd-party => site # referrer preferred blank\nlocal => local # referrer preferred kept\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] |
257,616
|
<p>This is the <code>PATH</code> variable without sudo:</p>
<pre><code>$ echo 'echo $PATH' | sh
/opt/local/ruby/bin:/usr/bin:/bin
</code></pre>
<p>This is the <code>PATH</code> variable with sudo:</p>
<pre><code>$ echo 'echo $PATH' | sudo sh
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
</code></pre>
<p>As far as I can tell, <code>sudo</code> is supposed to leave <code>PATH</code> untouched. What's going on? How do I change this? (This is on Ubuntu 8.04).</p>
<p>UPDATE: as far as I can see, none of the scripts started as root change <code>PATH</code> in any way.</p>
<p>From <code>man sudo</code>: </p>
<blockquote>
<p>To prevent command spoofing, sudo
checks ``.'' and ``'' (both denoting
current directory) last when searching
for a command in the user's PATH (if
one or both are in the PATH). <strong>Note,
however, that the actual PATH
environment variable is not modified
and is passed unchanged to the program
that sudo executes.</strong></p>
</blockquote>
|
[
{
"answer_id": 257644,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 5,
"selected": false,
"text": "PATH man sudo cat >> test.sh\nenv | grep \"MYEXAMPLE\" ;\n^D\n sh test.sh \nMYEXAMPLE=1 sh test.sh\n# MYEXAMPLE=1\nMYEXAMPLE=1 sudo sh test.sh \nMYEXAMPLE=1 sudo MYEXAMPLE=2 sh test.sh \n# MYEXAMPLE=2\n # ( From the build Script )\n....\nROOTPATH=$(cleanpath /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin${ROOTPATH:+:${ROOTPATH}})\n....\neconf --with-secure-path=\"${ROOTPATH}\" \n"
},
{
"answer_id": 257666,
"author": "pixelbeat",
"author_id": 4421,
"author_profile": "https://Stackoverflow.com/users/4421",
"pm_score": 8,
"selected": false,
"text": "alias sudo='sudo env PATH=$PATH'\n sudo su -p\n"
},
{
"answer_id": 375780,
"author": "Tyler Rick",
"author_id": 47185,
"author_profile": "https://Stackoverflow.com/users/47185",
"pm_score": 4,
"selected": false,
"text": "Defaults secure_path=\"/bin:/usr/bin:/usr/local/bin\"\n visudo: unknown defaults entry `secure_path' referenced near line 10\n mv /usr/bin/sudo /usr/bin/sudo.orig\n #!/bin/bash\n/usr/bin/sudo.orig env PATH=$PATH \"$@\"\n sudo -E Defaults env_reset Defaults !env_reset env_reset #Defaults env_reset Defaults env_keep += \"PATH\""
},
{
"answer_id": 1072871,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "root@sphinx:~# cat /etc/sudoers | grep -v -e '^$' -e '^#'\nDefaults env_reset\nDefaults secure_path=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/grub-1.96/sbin:/opt/grub-1.96/bin\"\nroot ALL=(ALL) ALL\n%admin ALL=(ALL) ALL\nroot@sphinx:~# cat /etc/apt/sources.list\ndeb http://au.archive.ubuntu.com/ubuntu/ jaunty main restricted universe\ndeb-src http://au.archive.ubuntu.com/ubuntu/ jaunty main restricted universe\n\ndeb http://au.archive.ubuntu.com/ubuntu/ jaunty-updates main restricted universe\ndeb-src http://au.archive.ubuntu.com/ubuntu/ jaunty-updates main restricted universe\n\ndeb http://security.ubuntu.com/ubuntu jaunty-security main restricted universe\ndeb-src http://security.ubuntu.com/ubuntu jaunty-security main restricted universe\n\ndeb http://au.archive.ubuntu.com/ubuntu/ karmic main restricted universe\ndeb-src http://au.archive.ubuntu.com/ubuntu/ karmic main restricted universe\n\ndeb http://au.archive.ubuntu.com/ubuntu/ karmic-updates main restricted universe\ndeb-src http://au.archive.ubuntu.com/ubuntu/ karmic-updates main restricted universe\n\ndeb http://security.ubuntu.com/ubuntu karmic-security main restricted universe\ndeb-src http://security.ubuntu.com/ubuntu karmic-security main restricted universe\nroot@sphinx:~# \n\nroot@sphinx:~# cat /etc/apt/preferences \nPackage: sudo\nPin: release a=karmic-security\nPin-Priority: 990\n\nPackage: sudo\nPin: release a=karmic-updates\nPin-Priority: 960\n\nPackage: sudo\nPin: release a=karmic\nPin-Priority: 930\n\nPackage: *\nPin: release a=jaunty-security\nPin-Priority: 900\n\nPackage: *\nPin: release a=jaunty-updates\nPin-Priority: 700\n\nPackage: *\nPin: release a=jaunty\nPin-Priority: 500\n\nPackage: *\nPin: release a=karmic-security\nPin-Priority: 450\n\nPackage: *\nPin: release a=karmic-updates\nPin-Priority: 250\n\nPackage: *\nPin: release a=karmic\nPin-Priority: 50\nroot@sphinx:~# apt-cache policy sudo\nsudo:\n Installed: 1.7.0-1ubuntu2\n Candidate: 1.7.0-1ubuntu2\n Package pin: 1.7.0-1ubuntu2\n Version table:\n *** 1.7.0-1ubuntu2 930\n 50 http://au.archive.ubuntu.com karmic/main Packages\n 100 /var/lib/dpkg/status\n 1.6.9p17-1ubuntu3 930\n 500 http://au.archive.ubuntu.com jaunty/main Packages\nroot@sphinx:~# echo $PATH\n/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/grub-1.96/sbin:/opt/grub-1.96/bin\nroot@sphinx:~# exit\nexit\nabolte@sphinx:~$ echo $PATH\n/home/abolte/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/grub-1.96/sbin:/opt/grub-1.96/bin:/opt/chromium-17593:/opt/grub-1.96/sbin:/opt/grub-1.96/bin:/opt/xpra-0.0.6/bin\nabolte@sphinx:~$ \n"
},
{
"answer_id": 1910765,
"author": "daggerok",
"author_id": 232487,
"author_profile": "https://Stackoverflow.com/users/232487",
"pm_score": 2,
"selected": false,
"text": "# cat .bash_profile | grep PATH\nPATH=$HOME/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin\nexport PATH\n\n# cat /etc/sudoers | grep Defaults\nDefaults requiretty\nDefaults env_reset\nDefaults env_keep = \"SOME_PARAM1 SOME_PARAM2 ... PATH\"\n"
},
{
"answer_id": 4572018,
"author": "Jacob",
"author_id": 559461,
"author_profile": "https://Stackoverflow.com/users/559461",
"pm_score": 7,
"selected": false,
"text": "visudo"
},
{
"answer_id": 6629081,
"author": "inman320",
"author_id": 508884,
"author_profile": "https://Stackoverflow.com/users/508884",
"pm_score": 1,
"selected": false,
"text": "Defaults env_reset\n Defaults !env_reset\n Defaults env_keep = \"LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASURE MENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL L ANGUAGE LINGUAS XDG_SESSION_COOKIE\"\n"
},
{
"answer_id": 6995257,
"author": "temp_sny",
"author_id": 885815,
"author_profile": "https://Stackoverflow.com/users/885815",
"pm_score": 2,
"selected": false,
"text": "env_keep /etc/sudoers Defaults env_keep = \"LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASURE MENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL L ANGUAGE LINGUAS XDG_SESSION_COOKIE\" Defaults env_keep = \"LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASURE MENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL L ANGUAGE LINGUAS XDG_SESSION_COOKIE PATH\""
},
{
"answer_id": 8447577,
"author": "Arnout Engelen",
"author_id": 354132,
"author_profile": "https://Stackoverflow.com/users/354132",
"pm_score": 4,
"selected": false,
"text": "Defaults env_reset\n exempt_group env_keep /sbin /usr/sbin Defaults secure_path=\"/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin\"\n"
},
{
"answer_id": 9373574,
"author": "axsuul",
"author_id": 178110,
"author_profile": "https://Stackoverflow.com/users/178110",
"pm_score": 4,
"selected": false,
"text": "sudo -i \n PATH"
},
{
"answer_id": 29262399,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": " sudo mv $HOME/bash/script.sh /usr/sbin/ \n"
},
{
"answer_id": 44497759,
"author": "Deepak Dixit",
"author_id": 5347555,
"author_profile": "https://Stackoverflow.com/users/5347555",
"pm_score": 0,
"selected": false,
"text": "User | Value of $PATH\n--------------------------\nroot /var/www\nuser1 /var/www/user1\nuser2 /var/www/html/private\n user@localhost$ whoami\nusername\nuser@localhost$ sudo whoami\nroot\nuser@localhost$ \n"
},
{
"answer_id": 70147138,
"author": "Walt Howard",
"author_id": 1211859,
"author_profile": "https://Stackoverflow.com/users/1211859",
"pm_score": 0,
"selected": false,
"text": "# personal ls\nusermod -a -G sudo ${USER}\n/bin/ls\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/136/"
] |
257,645
|
<p>For a random event generator I'm writing I need a simple algorithm to generate random ranges. </p>
<p>So, for example:</p>
<p>I may say I want 10 random intervals, between 1/1 and 1/7, with no overlap, in the states (1,2,3) where state 1 events add up to 1 day, state 2 events add up to 2 days and state 3 events add up to the rest. </p>
<p>Or in code: </p>
<pre><code>struct Interval
{
public DateTime Date;
public long Duration;
public int State;
}
struct StateSummary
{
public int State;
public long TotalSeconds;
}
public Interval[] GetRandomIntervals(DateTime start, DateTime end, StateSummary[] sums, int totalEvents)
{
// insert your cool algorithm here
}
</code></pre>
<p>I'm working on this now, but in case someone beats me to a solution (or knows of an elegant pre-existing algorithm) I'm posting this on SO. </p>
|
[
{
"answer_id": 257931,
"author": "Charlie",
"author_id": 18529,
"author_profile": "https://Stackoverflow.com/users/18529",
"pm_score": 0,
"selected": false,
"text": "public static Interval[] GetRandomIntervals( DateTime start, DateTime end,\n StateSummary[] states, int totalIntervals )\n{\n Random r = new Random();\n\n // stores the number of intervals to generate for each state\n int[] intervalCounts = new int[states.Length];\n\n int intervalsTemp = totalIntervals;\n\n // assign at least one interval for each of the states\n for( int i = 0; i < states.Length; i++ )\n intervalCounts[i] = 1;\n intervalsTemp -= states.Length;\n\n // assign remaining intervals randomly to the various states\n while( intervalsTemp > 0 )\n {\n int iState = r.Next( states.Length );\n intervalCounts[iState] += 1;\n intervalsTemp -= 1;\n }\n\n // make a scratch copy of the state array\n StateSummary[] statesTemp = (StateSummary[])states.Clone();\n\n List<Interval> result = new List<Interval>();\n DateTime next = start;\n while( result.Count < totalIntervals )\n {\n // figure out which state this interval will go in (this could\n // be made more efficient, but it works just fine)\n int iState = r.Next( states.Length );\n if( intervalCounts[iState] < 1 )\n continue;\n intervalCounts[iState] -= 1;\n\n // determine how long the interval should be\n int length;\n if( intervalCounts[iState] == 0 )\n {\n // last one for this state, use up all remaining time\n length = statesTemp[iState].TotalSeconds;\n }\n else\n {\n // use up at least one second of the remaining time, but\n // leave some time for the remaining intervals\n int maxLength = statesTemp[iState].TotalSeconds -\n intervalCounts[iState];\n length = r.Next( 1, maxLength + 1 );\n }\n\n // keep track of how much time is left to assign for this state\n statesTemp[iState].TotalSeconds -= length;\n\n // add a new interval\n Interval interval = new Interval();\n interval.State = states[iState].State;\n interval.Date = next;\n interval.Duration = length;\n result.Add( interval );\n\n // update the start time for the next interval\n next += new TimeSpan( 0, 0, length );\n }\n\n return result.ToArray();\n}\n"
},
{
"answer_id": 258008,
"author": "Sam Saffron",
"author_id": 17174,
"author_profile": "https://Stackoverflow.com/users/17174",
"pm_score": 1,
"selected": true,
"text": "public class Interval\n{\n public Interval(int state)\n {\n this.State = state;\n this.Duration = -1; \n this.Date = DateTime.MinValue;\n }\n public DateTime Date;\n public long Duration; \n public int State; \n}\n\nclass StateSummary\n{\n public StateSummary(StateEnum state, long totalSeconds)\n { \n State = (int)state;\n TotalSeconds = totalSeconds;\n }\n public int State;\n public long TotalSeconds; \n}\n\nInterval[] GetRandomIntervals(DateTime start, DateTime end, StateSummary[] sums, int totalEvents)\n{\n Random r = new Random(); \n ArrayList intervals = new ArrayList();\n\n for (int i=0; i < sums.Length; i++)\n {\n intervals.Add(new Interval(sums[i].State));\n }\n\n for (int i=0; i < totalEvents - sums.Length; i++)\n {\n intervals.Add(new Interval(sums[r.Next(0,sums.Length)].State));\n }\n\n Hashtable eventCounts = new Hashtable();\n foreach (Interval interval in intervals)\n {\n if (eventCounts[interval.State] == null) \n {\n eventCounts[interval.State] = 1; \n }\n else \n {\n eventCounts[interval.State] = ((int)eventCounts[interval.State]) + 1;\n }\n }\n\n foreach(StateSummary sum in sums)\n {\n long avgDuration = sum.TotalSeconds / (int)eventCounts[sum.State];\n foreach (Interval interval in intervals) \n {\n if (interval.State == sum.State)\n {\n long offset = ((long)(r.NextDouble() * avgDuration)) - (avgDuration / 2); \n interval.Duration = avgDuration + offset; \n }\n }\n } \n\n // cap the durations. \n Hashtable eventTotals = new Hashtable();\n foreach (Interval interval in intervals)\n {\n if (eventTotals[interval.State] == null) \n {\n eventTotals[interval.State] = interval.Duration; \n }\n else \n {\n eventTotals[interval.State] = ((long)eventTotals[interval.State]) + interval.Duration;\n }\n }\n\n foreach(StateSummary sum in sums)\n {\n long diff = sum.TotalSeconds - (long)eventTotals[sum.State];\n if (diff != 0)\n {\n long diffPerInterval = diff / (int)eventCounts[sum.State]; \n long mod = diff % (int)eventCounts[sum.State];\n bool first = true;\n foreach (Interval interval in intervals) \n {\n if (interval.State == sum.State)\n {\n interval.Duration += diffPerInterval;\n if (first) \n {\n interval.Duration += mod;\n first = false;\n }\n\n }\n }\n }\n }\n\n Shuffle(intervals);\n\n DateTime d = start; \n foreach (Interval interval in intervals) \n {\n interval.Date = d; \n d = d.AddSeconds(interval.Duration);\n }\n\n return (Interval[])intervals.ToArray(typeof(Interval));\n}\n\npublic static ICollection Shuffle(ICollection c)\n{\n Random rng = new Random();\n object[] a = new object[c.Count];\n c.CopyTo(a, 0);\n byte[] b = new byte[a.Length];\n rng.NextBytes(b);\n Array.Sort(b, a);\n return new ArrayList(a);\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257645",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17174/"
] |
257,653
|
<p>Having a problem trying to create a function, as part of a BizTalk helper class that returns a value of type (Microsoft.XLANGs.BaseTypes.XLANGMessage). The function code is as follows:</p>
<pre><code>public XLANGMessage UpdateXML (XLANGMessage inputFile)
{
XmlDocument xDoc = new XmlDocument();
XLANGMessage outputFile;
xDoc = (System.Xml.XmlDocument) inputFile[0].RetrieveAs(typeof(System.Xml.XmlDocument));
// Modify xDoc document code here
outputFile[0].LoadFrom(xDoc.ToString());
return outputFile;
}
</code></pre>
<p>This code does not build as I receive an error stating "Use of unassigned local variable
'outputFile'. I have tried to initialize the 'outputFile' using the new keyword ( = new ....), but that also results in a build error.</p>
<p>What am I doing wrong?</p>
|
[
{
"answer_id": 257702,
"author": "David Hall",
"author_id": 2660,
"author_profile": "https://Stackoverflow.com/users/2660",
"pm_score": 3,
"selected": true,
"text": "XLANGMessage outputFile;\n XLANGMessage outputFile = null;\n TypeOf typeof XMLDocument XLANGMessage XLANGMessage"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257653",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3810/"
] |
257,658
|
<p>I've automated my Ubuntu installation - I've got Python code that runs automatically (after a clean install, but before the first user login - it's in a temporary /etc/init.d/ script) that sets up everything from Apache & its configuration to my personal Gnome preferences. It's the latter that's giving me trouble.</p>
<p>This worked fine in Ubuntu 8.04 (Hardy), but when I use this with 8.10 (Intrepid), the first time I try to access gconf, I get this exception:</p>
<p>Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash. See <a href="http://www.gnome.org/projects/gconf/" rel="nofollow noreferrer">http://www.gnome.org/projects/gconf/</a> for information. (Details - 1: <strong>Not running within active session</strong>)</p>
<p>Yes, right, there's no Gnome session when this is running, because the user hasn't logged in yet - however, this worked before; this appears to be new with Intrepid's Gnome (2.24?).</p>
<p>Short of modifying the gconf's XML files directly, is there a way to make some sort of proxy Gnome session? Or, any other suggestions?</p>
<p>(More details: this is python code that runs as root, but setuid's & setgid's to be me before setting my preferences using the "gconf" module from the python-gconf package.)</p>
|
[
{
"answer_id": 260731,
"author": "Jeremy Visser",
"author_id": 10839,
"author_profile": "https://Stackoverflow.com/users/10839",
"pm_score": 3,
"selected": false,
"text": "import dbus\ndummy_bus = dbus.SessionBus()\n dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ExecFailed: dbus-launch failed to autolaunch D-Bus session: Autolaunch error: X11 initialization failed.\n $ dbus-launch \nDBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-eAmT3q94u0,guid=c250f62d3c4739dcc9a12d48490fc268\nDBUS_SESSION_BUS_PID=15836\n export DBUS_SESSION_BUS_ADDRESS=blahblah... gconftool-2 --spawn dbus-launch gconftool-2 --direct dbus-launch bash #!/bin/bash\n\neval `dbus-launch --sh-syntax`\n\nexport DBUS_SESSION_BUS_ADDRESS\nexport DBUS_SESSION_BUS_PID\n\ndo_other_stuff_here\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1452/"
] |
257,659
|
<p>I am wondering how to get a process run at the command line to use less processing power. The problem I'm having is the the process is basically taking over the CPU and taking MySQL and the rest of the server with it. Everything is becoming very slow.</p>
<p>I have used <code>nice</code> before but haven't had much luck with it. If it is the answer, how would you use it?</p>
<p>I have also thought of putting in <code>sleep</code> commands, but it'll still be using up memory so it's not the best option.</p>
<p>Is there another solution?</p>
<p>It doesn't matter to me how long it runs for, within reason.</p>
<p>If it makes a difference, the script is a PHP script, but I'm running it at the command line as it already takes 30+ minutes to run.</p>
<p>Edit: the process is a migration script, so I really don't want to spend too much time optimizing it as it only needs to be run for testing purposes and once to go live. Just for testing, it keeps bring the server to pretty much a halt...and it's a shared server.</p>
|
[
{
"answer_id": 257667,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 0,
"selected": false,
"text": "while true; do done\n top"
},
{
"answer_id": 257669,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 2,
"selected": false,
"text": "nice renice"
},
{
"answer_id": 257670,
"author": "hayalci",
"author_id": 16084,
"author_profile": "https://Stackoverflow.com/users/16084",
"pm_score": 3,
"selected": true,
"text": " nice -n 19 <command>\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
257,685
|
<p>I have a program that uses save files. It needs to load the newest save file, but fall back on the next newest if that one is unavailable or corrupted. Can I use the windows file creation timestamp to tell the order of when they were created, or is this unreliable? I am asking because the "changed" timestamps seem unreliable. I can embed the creation time/date in the name if I have to, but it would be easier to use the file system dates if possible.</p>
|
[
{
"answer_id": 257704,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 2,
"selected": false,
"text": "2008_12_31_24_60_60_1000 \n 2008/\n2008/12/\n2008/12/31\n2008/12/31/00-12/\n2008/12/31/13-24/24_60_60_1000 \n 2008/\n2008/12_31/\n"
},
{
"answer_id": 54534266,
"author": "lewis",
"author_id": 10895985,
"author_profile": "https://Stackoverflow.com/users/10895985",
"pm_score": 0,
"selected": false,
"text": "Path.Combine(ArchivedPath, currentDate + \" \" + fileInfo.Name))\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
257,699
|
<p>As I don't use vi all that much and certainly not for my primary editor, I can't remember any of the vi commands. Does anyone have a recommendation for a quick start guide or command summary?</p>
|
[
{
"answer_id": 257700,
"author": "Dustin Getz",
"author_id": 20003,
"author_profile": "https://Stackoverflow.com/users/20003",
"pm_score": 2,
"selected": false,
"text": "vim-tutor"
},
{
"answer_id": 257713,
"author": "Ali Afshar",
"author_id": 28380,
"author_profile": "https://Stackoverflow.com/users/28380",
"pm_score": 0,
"selected": false,
"text": "<ESC>:he<Return>\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6040/"
] |
257,730
|
<p>Considering the criteria listed below, which of Python, Groovy or Ruby would you use?</p>
<ul>
<li><em>Criteria (Importance out of 10, 10 being most important)</em></li>
<li>Richness of API/libraries available (eg. maths, plotting, networking) (9)</li>
<li>Ability to embed in desktop (java/c++) applications (8)</li>
<li>Ease of deployment (8)</li>
<li>Ability to interface with DLLs/Shared Libraries (7)</li>
<li>Ability to generate GUIs (7)</li>
<li>Community/User support (6)</li>
<li>Portability (6)</li>
<li>Database manipulation (3)</li>
<li>Language/Semantics (2)</li>
</ul>
|
[
{
"answer_id": 258333,
"author": "Chris Brooks",
"author_id": 27812,
"author_profile": "https://Stackoverflow.com/users/27812",
"pm_score": 2,
"selected": false,
"text": "// process all files printing out full name (. and .. auto excluded)\n\nnew File(basedir).eachFile{ f->\n\n if (f.isFile()) println f.canonicalPath\n}\n"
},
{
"answer_id": 792223,
"author": "Florin",
"author_id": 34565,
"author_profile": "https://Stackoverflow.com/users/34565",
"pm_score": 3,
"selected": false,
"text": "File.metaClass.invokeMethod = { String name, args ->\n System.out.print (\"Call to $name intercepted...\");\n File.metaClass.getMetaMethod(name, args).invoke(delegate, args);\n}\n\nnew File(\"c:/temp\").eachFile{\n if (it.isFile()) println it.canonicalPath\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24376/"
] |
257,735
|
<p>I'm looking to create a Visual Studio 2008 template that will create a basic project and based on remove certain files/folders based on options the user enters.</p>
<p>Right now, I have followed some tutorials online which have let me create the form to query the user and pass the data into an IWizard class, but I don't know what to do from there.</p>
<p>The tutorials provide a sample to do some simple substitution:
code:</p>
<pre><code>Form1 form = new Form1();
DialogResult dlg = form.ShowDialog();
if (dlg == DialogResult.OK)
{
foreach (KeyValuePair<string, string> pair in form.Parameters)
{
if (!replacementsDictionary.ContainsKey(pair.Key))
replacementsDictionary.Add(pair.Key, pair.Value);
else
replacementsDictionary[pair.Key] = pair.Value;
}
}
form.Close();
</code></pre>
<p>but I'm looking to selectively include files based on the user settings, and if possible, selectively include code sections in a file based on settings.</p>
<p>Is there a clever way to do this, or will I manually have to delete project files in the IWizard:ProjectFinishedGenerating()?</p>
|
[
{
"answer_id": 666235,
"author": "mackenir",
"author_id": 25457,
"author_profile": "https://Stackoverflow.com/users/25457",
"pm_score": 3,
"selected": true,
"text": "ShouldAddProjectItem ProjectFinishedGenerating ProjectItem file = project.ProjectItems.Item(\"File.cs\");\nfile.Remove();\n"
},
{
"answer_id": 2922315,
"author": "Roger Lipscombe",
"author_id": 8446,
"author_profile": "https://Stackoverflow.com/users/8446",
"pm_score": 1,
"selected": false,
"text": "$if$ <ItemGroup>\n <Reference Include=\"System\"/>\n $if$ ($targetframeworkversion$ >= 3.5)\n <Reference Include=\"System.Core\"/>\n <Reference Include=\"System.Xml.Linq\"/>\n <Reference Include=\"System.Data.DataSetExtensions\"/>\n $endif$\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257735",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33536/"
] |
257,740
|
<p>Basically I'm trying to change the <code>Canvas.Left</code> property of an Ellipse Silverlight control in C#. Here is how I'm accessing the control:</p>
<pre><code>Ellipse c1 = this.FindName("Circle1") as Ellipse;
</code></pre>
<p>How would I then set the <code>Canvas.Left</code> property?</p>
<p>Thanks,</p>
<p>Jeff</p>
|
[
{
"answer_id": 257749,
"author": "Bill Reiss",
"author_id": 18967,
"author_profile": "https://Stackoverflow.com/users/18967",
"pm_score": 0,
"selected": false,
"text": "double left=50;\nc1.SetValue(Canvas.LeftProperty, left);\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12172/"
] |
257,752
|
<p>I have whitespace characters showing in the Visual Studio code editor, and I'd like to remove them.</p>
|
[
{
"answer_id": 72883944,
"author": "AlainD",
"author_id": 2377399,
"author_profile": "https://Stackoverflow.com/users/2377399",
"pm_score": 0,
"selected": false,
"text": "Visual Studio 2019 Edit > Advanced > View White Space Tools > Options > Environment > Fonts and Colors > Visible White Space"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
257,753
|
<p>As the question implies, I'm looking for a way to programmatically screen grab a given panorama, I.E set a longitude and latitude and POV (pitch, yaw and zoom) and save the grab to the server. So far the most promise has been shown by </p>
<ol>
<li><p>Using .net to control the google earth com api (<a href="http://earth.google.com/comapi/index.html" rel="nofollow noreferrer">http://earth.google.com/comapi/index.html</a>), however I am unable to find a definitive answer on whether on not the street view layer is accessible via this means. </p></li>
<li><p>Embed the street view swf inside another swf that opens a socket to the web server to listen for requests, and passing commands (such as adjusting lat/lng and POV) to the street view swf and screen grabbing the view and saving it back to the server. The swf would either be running on the webserver or another server. </p></li>
</ol>
<p>Questions about reliability and scalability come into play with both of these solutions. Has anyone got any further suggestions or ideas? The solution doesn't have to be real time, its assumed that some asynchronous "behind the scenes" processing will be happening.</p>
|
[
{
"answer_id": 12885558,
"author": "shreks7",
"author_id": 1147466,
"author_profile": "https://Stackoverflow.com/users/1147466",
"pm_score": 2,
"selected": false,
"text": "http://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,%20-73.988354&fov=90&heading=235&pitch=10&sensor=false\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257753",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28416/"
] |
257,767
|
<p>I have a largish Mercurial repository that I've decided would be better as several smaller repositories. Is there a way that I can split the repository and have each piece retain its revision history?</p>
|
[
{
"answer_id": 257927,
"author": "Ry4an Brase",
"author_id": 8992,
"author_profile": "https://Stackoverflow.com/users/8992",
"pm_score": 7,
"selected": true,
"text": "--filemap exclude path/you/do/not/want\nrename path/you/do/want .\n"
},
{
"answer_id": 47349707,
"author": "KalenGi",
"author_id": 212076,
"author_profile": "https://Stackoverflow.com/users/212076",
"pm_score": 0,
"selected": false,
"text": "new-repo.filemap include vendor/FooBackend\nrename vendor/FooBackend .\n rewrite-old-repo.filemap exclude vendor/FooBackend\n hg convert /path/to/current/repo /path/to/new/repo --filemap new-repo.filemap\n hg update hg convert /path/to/current/repo /path/to/rewritten/repo --filemap rewrite-old-repo.filemap\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/207/"
] |
257,768
|
<p>I'm looking to create a virtual printer that passes data to my .NET application. I want to then create an installer that installs both the printer and the .NET application. It would we really nice to be able to write it all in C#, but I have a feeling that this will require a printer driver to be written is unmanaged code. Does anyone know of a fairly clean tutorial or example of how to do this?</p>
|
[
{
"answer_id": 40370083,
"author": "Ogglas",
"author_id": 3850405,
"author_profile": "https://Stackoverflow.com/users/3850405",
"pm_score": 4,
"selected": false,
"text": "Desktop development with C++ .zip <UnzipFolder>\\print\\XPSDrvSmpl XPSDrvSmpl.sln"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30889/"
] |
257,793
|
<p>I recently switched my hosting provider and due to the time zone that the server is now in, my code has stopped working. </p>
<p>The hosting server reports in Pacific time, However, my code needs to work with GMT as my site is for the UK market. So, all my displays and searches need to be in the format dd/MM/yyyy</p>
<p>How can I account for the difference? </p>
<p>For instance, when I do a DateTime.Parse("03/11/2008") it fail as I assume the 'Parse' is against the servers settings. I also get "String was not recognized as a valid DateTime." throughout my code. </p>
|
[
{
"answer_id": 257807,
"author": "Ray",
"author_id": 233,
"author_profile": "https://Stackoverflow.com/users/233",
"pm_score": 2,
"selected": false,
"text": "DateTime.Parse(\"28/11/2008\", new CultureInfo(\"en-GB\"))\n"
},
{
"answer_id": 257825,
"author": "Pavel Chuchuva",
"author_id": 14131,
"author_profile": "https://Stackoverflow.com/users/14131",
"pm_score": 4,
"selected": true,
"text": "<globalization> <system.web> <system.web>\n <globalization culture=\"en-gb\"/>\n <!-- ... -->\n</system.web>\n"
},
{
"answer_id": 32817459,
"author": "Mukklan",
"author_id": 4316363,
"author_profile": "https://Stackoverflow.com/users/4316363",
"pm_score": 0,
"selected": false,
"text": "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9; IE=8; IE=7; IE=EDGE\" / >\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26300/"
] |
257,795
|
<p>I'm trying to add an header file to dev-C++ but when I compile it it doesn't work.
Here are my exact steps (for my example, I'm trying to get mysql.h to work):</p>
<ol>
<li>copy "mysql.h" into c:\dev-c++\includes</li>
<li>check that in dev-C++ tools > compiler options > directories > c includes and c++ includes have the path to "c:\dev-c++\includes"</li>
<li>include #include at the top of my file</li>
<li>compiled</li>
</ol>
<p>This is what the dev-C++ compiler told me:</p>
<pre><code>13 C:\Documents and Settings\Steve\Desktop\server code\setup1\main.c `mysql' undeclared (first use in this function)
</code></pre>
<p>As well as other errors due to not locating the header file</p>
<p>Are the steps I've outlined correct? Or is there something else I need to do to get the header files to compile.</p>
<p>P.S. I tried doing the same with VS2008 (put mysql.h in the vs2008 include folder, etc)
but still have the same error. I would like to stick with Dev-c++ if possible.</p>
|
[
{
"answer_id": 257800,
"author": "jpoh",
"author_id": 4368,
"author_profile": "https://Stackoverflow.com/users/4368",
"pm_score": 2,
"selected": false,
"text": "#include \"mysql.h\"\n #include <mysql>\n"
},
{
"answer_id": 45390104,
"author": "Ritesh Aggarwal",
"author_id": 8240164,
"author_profile": "https://Stackoverflow.com/users/8240164",
"pm_score": 0,
"selected": false,
"text": "#include<iostream>\n using namespace std;\n\n namespace Ritesh\n {\n int a;\n int b;\n void sum();\n }\n void Ritesh::sum()\n {\n cout<<a+b;\n }\n #include<iostream>\n#include \"Ritesh.h\"\n using namespace std;\n using namespace Ritesh;\n int main()\n {\n a=4;b=6;\n sum();\n }\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257795",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28462/"
] |
257,797
|
<p>I wrote a C++ project in VS2005, and used lots of STL container with its plus-in STL. However, I found STL in VS2005 does not have a hash_map in it, I want to use SGI hash_map. How can I change my project to use SGI STL?</p>
<p>Thanks for Brian's method, it works! And it's simple.</p>
|
[
{
"answer_id": 257799,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 3,
"selected": true,
"text": "#include <hash_map>\nstdext::hash_map\n"
},
{
"answer_id": 258225,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 0,
"selected": false,
"text": "unordered_map #include <tr1/unordered_map>\nstd::tr1::unordered_map mymap;\n <hash_map> hash_map <ext/hash_map> <tr1/unordered_map>"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257797",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25749/"
] |
257,801
|
<p>Here's the scenario:</p>
<p>I have a textbox and a button on a web page. When the button is clicked, I want a popup window to open (using Thickbox) that will show all items that match the value entered in the textbox. I am currently using the IFrame implementation of Thickbox. The problem is that the URL to show is hardcoded into the "alt' attribute of the button. What I really need is for the "alt" attribute to pass along the value in the textbox to the popup.</p>
<p>Here is the code so far:</p>
<pre><code><input type="textbox" id="tb" />
<input alt="Search.aspx?KeepThis=true&TB_iframe=true&height=500&width=700" class="thickbox" title="Search" type="button" value="Search" />
</code></pre>
<p>Ideally, I would like to put the textbox value into the Search.aspx url but I can't seem to figure out how to do that. My current alternative is to use jQuery to set the click function of the Search button to call a web service that will set some values in the ASP.NET session. The Search.aspx page will then use the session variables to do the search. However, this is a bit flaky since it seems like there will always be the possibility that the search executes before the session variables are set.</p>
|
[
{
"answer_id": 257852,
"author": "Ricky",
"author_id": 653,
"author_profile": "https://Stackoverflow.com/users/653",
"pm_score": 0,
"selected": false,
"text": "$('input#tb').blur(function(){ \n var url = $('input.thickbox').attr('alt');\n var tbVal = $(this).val();\n\n // add the textbox value into the query string here\n // url = ..\n\n $('input.thickbox').attr('alt', url);\n\n});\n"
},
{
"answer_id": 257957,
"author": "Scott Evernden",
"author_id": 11397,
"author_profile": "https://Stackoverflow.com/users/11397",
"pm_score": 4,
"selected": true,
"text": "tb_show() ... onclick = \"doSearch()\" ...\n\nfunction doSearch()\n{\n tb_show(caption, 'Search.aspx?KeepThis=true&q=\\\"' +\n $('input#tb').val() +\n '\\\"&TB_iframe=true&height=500&width=700');\n}\n"
},
{
"answer_id": 681151,
"author": "TheAlbear",
"author_id": 27922,
"author_profile": "https://Stackoverflow.com/users/27922",
"pm_score": 0,
"selected": false,
"text": "button1.Attributes.Add(\"alt\", \"Search.aspx?KeepThis=true&TB_iframe=true&height=500&width=700\");\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257801",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1574/"
] |
257,805
|
<p>I'm having a hard time understanding some git/DCVS concepts. Here's what happened:</p>
<ol>
<li>I created a git project, and imported it from an SVN repo</li>
<li>I made some commits</li>
<li>I wanted to experiment something, so I created a branch called <strong>constants-update</strong></li>
<li>I switched to <strong>constants-update</strong>branch, moved some files, deleted others and added many more</li>
<li>I committed to this branch</li>
<li>Now I'm trying to switch to my master branch using <code>git checkout master</code></li>
<li>I got this error: <strong>error: You have local changes to 'src/groovy/Constants.groovy'; cannot switch branches.</strong></li>
</ol>
<p>My understanding of DCVS is that I can switch branches at will, even if some branch has more or less files than the others, as long as I commit my files. I've tried committing with <code>git commit -a</code> and switching to master branch, but I have the same error. </p>
<p>As a side note, when I commit git warns me that LF will be replaced by CRLF and warns me about some trailing whitespaces also; after I commit I do a <code>git status</code> and a bunch of files always appear as <code>#modified ...</code>.</p>
<p>Is this related to git/<strong>windows</strong>, or I do not understand correctly what it is supposed to happen? I just want to switch to my master branch <strong>without losing my changes</strong> in the other branch.</p>
|
[
{
"answer_id": 258295,
"author": "Miguel Ping",
"author_id": 22992,
"author_profile": "https://Stackoverflow.com/users/22992",
"pm_score": 3,
"selected": true,
"text": ".git/hooks/pre-commit # # if (/\\s$/) {\n# bad_line(\"trailing whitespace\", $_);\n# }\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257805",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22992/"
] |
257,806
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/216007/how-to-determine-total-number-of-open-active-connections-in-ms-sql-server-2005">How to determine total number of open/active connections in ms sql server 2005</a> </p>
</blockquote>
<p>In Oracle, there's a view called V$SESSION that lists all active sessions in database. Is there any similar view in SQL Server 2005?</p>
|
[
{
"answer_id": 782634,
"author": "Gavin",
"author_id": 78216,
"author_profile": "https://Stackoverflow.com/users/78216",
"pm_score": 3,
"selected": false,
"text": "sp_who"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10629/"
] |
257,843
|
<p>We have an application that does single sign-on using a centralized authentication server (CAS). We'd like to do single sign-out, such that if the user logs out of one application (say a front-end portal), the user is automatically signed out of all applications using the same single sign-on ticket.</p>
<p>The expectation would be that each application would register a sign-out hook (URL) with the CAS at the time of logon to that application. When the CAS receives the sign out request from one of the applications, it invokes the sign-out hook for all the application sharing the SSO ticket.</p>
<p>My question is this: is there a way to abandon an InProc session from a different session? I presume, since the HTTP request will be coming from the CAS server, that it will get its own session, but it is the session of the user that I want to terminate. I have pretty good idea of how to do this using a separate session state server, but I'd like to know if it is possible using InProc session state.</p>
|
[
{
"answer_id": 882702,
"author": "John Leidegren",
"author_id": 58961,
"author_profile": "https://Stackoverflow.com/users/58961",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Reflection;\nusing System.Web;\n\nobject obj = typeof(HttpRuntime).GetProperty(\"CacheInternal\", \n BindingFlags.NonPublic | BindingFlags.Static)\n .GetValue(null, null);\n\nif (obj != null)\n{\n MethodInfo remove = obj.GetType()\n .GetMethod(\"Remove\", BindingFlags.NonPublic | BindingFlags.Instance, \n Type.DefaultBinder, new Type[] { typeof(string) }, null);\n\n object proc = remove.Invoke(obj, new object[] { \"j\" + state.SessionID });\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257843",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12950/"
] |
257,844
|
<p>How can I <strong>quickly</strong> create a large file on a Linux (<a href="http://en.wikipedia.org/wiki/Red_Hat_Linux" rel="noreferrer">Red Hat Linux</a>) system?</p>
<p><a href="http://en.wikipedia.org/wiki/Dd_%28Unix%29" rel="noreferrer">dd</a> will do the job, but reading from <code>/dev/zero</code> and writing to the drive can take a long time when you need a file several hundreds of GBs in size for testing... If you need to do that repeatedly, the time really adds up.</p>
<p>I don't care about the contents of the file, I just want it to be created quickly. How can this be done?</p>
<p>Using a sparse file won't work for this. I need the file to be allocated disk space.</p>
|
[
{
"answer_id": 257849,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 8,
"selected": false,
"text": "xfs_mkfile 10240m 10Gigfile fallocate -l 10G 10Gigfile mkfile 10240m 10Gigfile prealloc 10Gigfile 10737418240 mkfile <size> dd -n -n xfs_mkfile fallocate"
},
{
"answer_id": 257865,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 2,
"selected": false,
"text": "ln /home/bigfiles/1024M-A /home/oracle/logfile"
},
{
"answer_id": 257975,
"author": "Zoredache",
"author_id": 20267,
"author_profile": "https://Stackoverflow.com/users/20267",
"pm_score": 6,
"selected": false,
"text": "dd if=/dev/zero of=filename bs=1 count=1 seek=1048575\n"
},
{
"answer_id": 3530654,
"author": "kiv",
"author_id": 426314,
"author_profile": "https://Stackoverflow.com/users/426314",
"pm_score": 7,
"selected": false,
"text": "truncate -s 10M output.file\n ### BEFORE\n$ df -h | grep lvm\n/dev/mapper/lvm--raid0-lvm0\n 7.2T 6.6T 232G 97% /export/lvm-raid0\n\n$ truncate -s 500M 500MB.file\n\n### AFTER\n$ df -h | grep lvm\n/dev/mapper/lvm--raid0-lvm0\n 7.2T 6.6T 232G 97% /export/lvm-raid0\n $ rsync -aHAxvP --numeric-ids --delete --info=progress2 \\\n root@mulder.bub.lan:/export/lvm-raid0/500MB.file \\\n /export/raid1/\nreceiving incremental file list\n500MB.file\n 524,288,000 100% 41.40MB/s 0:00:12 (xfr#1, to-chk=0/1)\n\nsent 30 bytes received 524,352,082 bytes 38,840,897.19 bytes/sec\ntotal size is 524,288,000 speedup is 1.00\n"
},
{
"answer_id": 5688625,
"author": "Franta",
"author_id": 2512257,
"author_profile": "https://Stackoverflow.com/users/2512257",
"pm_score": 9,
"selected": false,
"text": "dd fallocate fallocate -l 10G gentoo_root.img\n"
},
{
"answer_id": 9393456,
"author": "Sepero",
"author_id": 1225603,
"author_profile": "https://Stackoverflow.com/users/1225603",
"pm_score": 5,
"selected": false,
"text": "#kilobytes\ndd if=/dev/zero of=filename bs=1 count=0 seek=200K\n\n#megabytes\ndd if=/dev/zero of=filename bs=1 count=0 seek=200M\n\n#gigabytes\ndd if=/dev/zero of=filename bs=1 count=0 seek=200G\n\n#terabytes\ndd if=/dev/zero of=filename bs=1 count=0 seek=200T\n"
},
{
"answer_id": 10317205,
"author": "Humungous Hippo",
"author_id": 1356398,
"author_profile": "https://Stackoverflow.com/users/1356398",
"pm_score": 4,
"selected": false,
"text": "#include < stdio.h >\n#include < stdlib.h >\n\nint main() {\n int i;\n FILE *fp;\n\n fp=fopen(\"bigfakefile.txt\",\"w\");\n\n for(i=0;i<(1024*1024);i++) {\n fseek(fp,(1024*1024),SEEK_CUR);\n fprintf(fp,\"C\");\n }\n}\n"
},
{
"answer_id": 11779492,
"author": "Dan McAllister",
"author_id": 1571677,
"author_profile": "https://Stackoverflow.com/users/1571677",
"pm_score": 8,
"selected": false,
"text": "dd if=/dev/zero of=./gentoo_root.img bs=4k iflag=fullblock,count_bytes count=10G\n truncate -s 10G gentoo_root.img\n fallocate -l 10G gentoo_root.img\n"
},
{
"answer_id": 20541029,
"author": "Yogesh",
"author_id": 1514461,
"author_profile": "https://Stackoverflow.com/users/1514461",
"pm_score": 3,
"selected": false,
"text": "#yes >> myfile\n #>myfile\n"
},
{
"answer_id": 27714438,
"author": "user79878",
"author_id": 79878,
"author_profile": "https://Stackoverflow.com/users/79878",
"pm_score": 2,
"selected": false,
"text": "fallocate // include stdlib.h, stdio.h, and stdint.h\nint32_t buf[256]; // Block size.\nfor (int i = 0; i < 256; ++i)\n{\n buf[i] = rand(); // random to be non-compressible.\n}\nFILE* file = fopen(\"/file/on/your/system\", \"wb\");\nint blocksToWrite = 1024 * 1024; // 1 GB\nfor (int i = 0; i < blocksToWrite; ++i)\n{\n fwrite(buf, sizeof(int32_t), 256, file);\n}\n dd if=/dev/urandom of=outputfile bs=1024 count = XX"
},
{
"answer_id": 32803609,
"author": "max",
"author_id": 1896222,
"author_profile": "https://Stackoverflow.com/users/1896222",
"pm_score": 5,
"selected": false,
"text": "dd if=/dev/zero of=filename bs=1G count=1\n"
},
{
"answer_id": 65733550,
"author": "TarithJ",
"author_id": 14412197,
"author_profile": "https://Stackoverflow.com/users/14412197",
"pm_score": -1,
"selected": false,
"text": "$ trash-dump --filename=\"huge\" --seed=1232 --noBytes=1000000000\n"
},
{
"answer_id": 71944464,
"author": "Mike S",
"author_id": 3768749,
"author_profile": "https://Stackoverflow.com/users/3768749",
"pm_score": 0,
"selected": false,
"text": "cd /dev/shm\ndate\ntime yes $(for ((i=32;i<127;i++)) do printf \"\\\\$(printf %03o \"$i\")\"; done) | head -c 1073741824 > ascii1g_file.txt\ndate\n\nWed Apr 20 12:30:13 CDT 2022\n\nreal 0m0.773s\nuser 0m0.060s\nsys 0m1.195s\nWed Apr 20 12:30:14 CDT 2022\n cp ascii1gfile.txt /home/greygnome/\nuptime; free -m; sync; echo 1 > /proc/sys/vm/drop_caches; free -m; date; dd if=/home/greygnome/ascii1gfile.txt of=/dev/shm/outfile bs=16384 2>&1; date; rm -f /dev/shm/outfile \n tcpdump -i em1 -w /dev/shm/dump.pcap\n fallocate"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17007/"
] |
257,872
|
<p>I want to force Apache to use HTTPS for a particular URL in the following form:</p>
<pre><code>https://www.example.com/signup/*
</code></pre>
<p>so</p>
<p>if someone goes to any of the following example URLs directly, Apache will forward the URL over to the HTTPS equivalent site.</p>
<p>e.g.</p>
<pre><code>http://www.example.com/signup --> https://www.example.com/signup
http://www.example.com/signup/basic+plan --> https://www.example.com/signup/basic+plan
http://www.example.com/signup/premium --> https://www.example.com/signup/premium
</code></pre>
<p>Anyone know how?</p>
<p>Thanks in advance</p>
|
[
{
"answer_id": 257878,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 2,
"selected": false,
"text": "Redirect 301 /signup https://www.example.com/signup\n"
},
{
"answer_id": 257932,
"author": "Murat Ayfer",
"author_id": 25910,
"author_profile": "https://Stackoverflow.com/users/25910",
"pm_score": 2,
"selected": false,
"text": "RewriteEngine On \nRewriteCond %{SERVER_PORT} 80 \nRewriteCond %{REQUEST_URI} ^/somefolder/?\nRewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]\n"
},
{
"answer_id": 258923,
"author": "Timmy_",
"author_id": 33554,
"author_profile": "https://Stackoverflow.com/users/33554",
"pm_score": 3,
"selected": false,
"text": "RewriteCond %{SERVER_PORT} 80 \nRewriteCond %{REQUEST_URI} ^/somefolder/?\nRewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]\n"
},
{
"answer_id": 693182,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<Directory \"/var/www/html\">\n RewriteEngine on\n Options +FollowSymLinks\n Order allow,deny\n Allow from all\n RewriteCond %{SERVER_PORT} !^443$\n RewriteRule \\.(gif|jpg|jpeg|jpe|png|css|js)$ - [S=1]\n RewriteRule ^checkout(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]\n</Directory>\n RewriteRule ^(checkout|login)(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]\n RewriteCond %{SERVER_PORT} ^443$\nRewriteRule \\.(gif|jpg|jpeg|jpe|png|css|js)$ - [S=1]\nRewriteRule !^(checkout|login)(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R]\n"
},
{
"answer_id": 51480769,
"author": "RobbySherwood",
"author_id": 3320453,
"author_profile": "https://Stackoverflow.com/users/3320453",
"pm_score": 0,
"selected": false,
"text": "<If \"%{HTTPS} != 'on'\">\n Redirect 301 /your/path https://www.example.com/your/path\n</If>\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33554/"
] |
257,877
|
<p>I want to trim trailing whitespace at the end of all XHTML paragraphs. I am using Ruby with the REXML library.</p>
<p>Say I have the following in a valid XHTML file:</p>
<pre><code><p>hello <span>world</span> a </p>
<p>Hi there </p>
<p>The End </p>
</code></pre>
<p>I want to end up with this:</p>
<pre><code><p>hello <span>world</span> a</p>
<p>Hi there</p>
<p>The End</p>
</code></pre>
<p>So I was thinking I could use XPath to get just the text nodes that I want, then trim the text, which would allow me to end up with what I want (previous).</p>
<p>I started with the following XPath:</p>
<pre><code>//root/p/child::text()
</code></pre>
<p>Of course, the problem here is that it returns all text nodes that are children of all p-tags. Which is this:</p>
<pre><code>'hello '
' a '
'Hi there '
'The End '
</code></pre>
<p>Trying the following XPath gives me the last text node of the last paragraph, not the last text node of each paragraph that is a child of the root node.</p>
<pre><code>//root/p/child::text()[last()]
</code></pre>
<p>This only returns: <code>'The End '</code></p>
<p>What I would like to get from the XPath is therefore:</p>
<pre><code>' a '
'Hi there '
'The End '
</code></pre>
<p>Can I do this with XPath? Or should I maybe be looking at using regular expressions (That's probably more of a headache than XPath)?</p>
|
[
{
"answer_id": 258030,
"author": "AmbroseChapel",
"author_id": 242241,
"author_profile": "https://Stackoverflow.com/users/242241",
"pm_score": 1,
"selected": false,
"text": "normalize-space()"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257877",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5758/"
] |
257,901
|
<p>I'm using this script to display all the images in a folder, but I can't figure out how to get each image's file name to display underneath it. Any suggestions?</p>
<pre><code><?php
$dirname = "images";
$images = scandir($dirname);
$ignore = Array(".", "..", "otherfiletoignore");
foreach($images as $curimg){
if (!in_array($curimg, $ignore)) {
echo "<img src='images/$curimg' /><br />\n";
}
}
?>
</code></pre>
|
[
{
"answer_id": 257904,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 4,
"selected": true,
"text": "echo \"<img src='images/$curimg' /><br />$curimg<br />\\n\";\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257901",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32972/"
] |
257,902
|
<p>I have seen lots of chat examples in Erlang but what about lists, like a work queue? If I want to build a work queue system, like a project management system, is it possible to re-order messages in a process mailbox or do I have to use message priorities? Are there examples of workflow systems built in Erlang?</p>
|
[
{
"answer_id": 258348,
"author": "Adam Lindberg",
"author_id": 2457,
"author_profile": "https://Stackoverflow.com/users/2457",
"pm_score": 4,
"selected": true,
"text": "receive\n {important, Msg} ->\n handle(Msg)\nafter 0 ->\n ok\nend,\nreceive\n OtherMsg ->\n handle(Msg)\nend\n receive\n {important, Msg} ->\n handle(Msg);\n OtherMsg ->\n handle(Msg)\nend\n {important, Msg}"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32829/"
] |
257,906
|
<p>The activity monitor in sql2k8 allows us to see the most expensive queries. Ok, that's cool, but is there a way I can log this info or get this info via query analyser? I don't really want to have the Sql Management console open and me looking at the activity monitor dashboard.</p>
<p>I want to figure out which queries are poorly written/schema is poorly designed, etc.</p>
<p>Thanks heaps for any help!</p>
|
[
{
"answer_id": 257944,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 7,
"selected": true,
"text": " RPC:Completed\n SP:Completed\n SP:StmtCompleted\n SQL:BatchCompleted\n SQL:StmtCompleted\n SELECT DB_ID('dbname') @ID=2 SELECT * INTO TraceTable\nFROM ::fn_trace_gettable('C:\\location of your trace output.trc', default)\n SELECT COUNT(*) AS TotalExecutions, \n EventClass, CAST(TextData as nvarchar(2000))\n ,SUM(Duration) AS DurationTotal\n ,SUM(CPU) AS CPUTotal\n ,SUM(Reads) AS ReadsTotal\n ,SUM(Writes) AS WritesTotal\nFROM TraceTable\nGROUP BY EventClass, CAST(TextData as nvarchar(2000))\nORDER BY ReadsTotal DESC\n"
},
{
"answer_id": 8285345,
"author": "gngolakia",
"author_id": 1050111,
"author_profile": "https://Stackoverflow.com/users/1050111",
"pm_score": 5,
"selected": false,
"text": "SELECT TOP 10 \nSUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,\n((CASE qs.statement_end_offset\nWHEN -1 THEN DATALENGTH(qt.TEXT)\nELSE qs.statement_end_offset\nEND - qs.statement_start_offset)/2)+1),\nqs.execution_count,\nqs.total_logical_reads, \nqs.last_logical_reads,\nqs.total_logical_writes, qs.last_logical_writes,\nqs.total_worker_time,\nqs.last_worker_time,\nqs.total_elapsed_time/1000000 total_elapsed_time_in_S,\nqs.last_elapsed_time/1000000 last_elapsed_time_in_S,\nqs.last_execution_time,qp.query_plan\nFROM sys.dm_exec_query_stats qs\nCROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt\nCROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp\nORDER BY qs.total_logical_reads DESC \n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30674/"
] |
257,933
|
<p>Here's the sit:</p>
<ul>
<li>I have a JSF component which is basically a list of 'documents'</li>
<li>I have any number of document viewer components on the same page.</li>
<li>None of these components "know" about each other. In other words, they cannot be configured at design time to link to each other or anything like that.</li>
</ul>
<p>When the user clicks a document link I wish each one of the document viewer components to be notified.</p>
<p>Basically the idea would be to have the document viewers publish the fact that they listen for a certain type of event ("DocumentSelectedEvent" say) which the doc list component would fire.</p>
<p>I can think of ways of doing this that are not JSF specific, but I'm wondering if the JSF event model can handle that sort of thing.</p>
<p>Anyone have any ideas?</p>
|
[
{
"answer_id": 273367,
"author": "branchgabriel",
"author_id": 30807,
"author_profile": "https://Stackoverflow.com/users/30807",
"pm_score": 0,
"selected": false,
"text": " /**\n * Handle document click value change.\n * \n * @param valueChangedEvent the value changed event\n */\n public void handleDocumentSelect(ValueChangeEvent valueChangedEvent) {\n String selectedDocument = valueChangedEvent.getNewValue();\n\n doDocViewer1DisplayMethod(selectedDocument);\n doDocViewe2DisplayMethod(selectedDocument);\n\n\n } \n <f:componentTag \n attr=xxx \n attr=xxx \n valueChangeListener=\"#{pc_BackingBean.handleDocumentSelect}\"\n onChange=submit();>\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1666/"
] |
257,992
|
<p>I am writing a console application which makes use of the F1 key (for help). Unfortunately, while Konsole (of KDE) doesn't use this key, Gnome Terminal does, so the F1 key becomes inaccessible to my application. I don't think there's a way to detect whether the F1 key is already mapped in the GUI side of things (Gnome Terminal), but if there is, the answer to that will obviate this question. :)</p>
<p>Ergo, my next best bet is to try to detect whether I am running inside Gnome Terminal. Is there some way to do that? I'm primarily interested in gleaning this from within Ruby, but if it can be done via shell or environment variables, or virtual filesystem (/proc, /dev, etc.) then that will suffice.</p>
<p>I'm hoping for a reliable way to do this, but I can settle for "best guess" approaches like grepping the environment variables for clues that can let me reasonably assume that Gnome Terminal is the wrapping terminal.</p>
<p>Extra info: other keys are also "stolen" by Gnome Terminal. I intend to display some sort of informative message about alternative keys for Gnome users.</p>
|
[
{
"answer_id": 258203,
"author": "Fusion",
"author_id": 6253,
"author_profile": "https://Stackoverflow.com/users/6253",
"pm_score": 1,
"selected": false,
"text": "ps x | grep `ps o ppid,fname | grep bash | grep -v grep | head -1 | awk '{print $1}'` | grep 'gnome-terminal' | wc -l\n"
},
{
"answer_id": 5140084,
"author": "balu",
"author_id": 490153,
"author_profile": "https://Stackoverflow.com/users/490153",
"pm_score": 0,
"selected": false,
"text": "if [[ $TERM == 'xterm' ]] ; then\n alias nw='gnome-terminal --working-directory=$PWD'\nfi\n"
},
{
"answer_id": 26428788,
"author": "blueyed",
"author_id": 15690,
"author_profile": "https://Stackoverflow.com/users/15690",
"pm_score": 3,
"selected": false,
"text": "[[ \"$COLORTERM\" == \"gnome-terminal\" ]] || [[ ${$(ps -p $(ps -p $$ -o ppid=) -o cmd=):t} == gnome-terminal* ]]\n $COLORTERM"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/257992",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28558/"
] |
258,006
|
<p>I'm trying to play a sound file from an iPhone program.</p>
<p>Here's the code:</p>
<pre><code>NSString *path = [[NSBundle mainBundle] pathForResource:@"play" ofType:@"caf"];
NSFileHandle *bodyf = [NSFileHandle fileHandleForReadingAtPath:path];
NSData *body = [bodyf availableData];
NSLog( @"length of play.caf %d",[body length] );
NSURL *url = [NSURL fileURLWithPath:path isDirectory:NO];
NSLog( [url description] );
NSLog( @"%d", AudioServicesCreateSystemSoundID((CFURLRef)url, &soundID) );
</code></pre>
<p>The first NSLog is to check that I have access to the file (I did), the second NSLog is to show the file URL, and the third NSLog returns -1500 "An unspecified error has occurred."</p>
<p>For the second NSLog, I get the following output:</p>
<p>file://localhost/Users/alan/Library/Application 敲慬楴敶瑓楲杮upport/iPhone蒠ꁻތĀ⾅獕牥⽳污湡䰯扩慲祲䄯灰楬慣楴湯匠灵潰瑲椯桐湯楓畭慬潴⽲獕牥䄯灰楬慣楴湯⽳䙂㕅㡂㤱䌭䐳ⴸ䐴䙃㠭㍃ⴷ䍁㈶㠵䙁㤴㈰䰯捯瑡䵥灡⽰汰祡挮晡imulator/User/Applications/BFE5B819-C3D8-4DCF-8C37-AC6258AF4902/LocateMe.app/play.caf</p>
<p>This is either due to my misunderstanding of the "description" method, or this contributes to the problem.</p>
<p>Any idea what is going wrong?</p>
|
[
{
"answer_id": 258046,
"author": "zoul",
"author_id": 17279,
"author_profile": "https://Stackoverflow.com/users/17279",
"pm_score": 0,
"selected": false,
"text": "NSLog EXC_BAD_ACCESS EXC_BAD_ACCESS"
},
{
"answer_id": 259630,
"author": "Chris Hanson",
"author_id": 714,
"author_profile": "https://Stackoverflow.com/users/714",
"pm_score": 2,
"selected": false,
"text": "[URL description] % NSLog(@\"%@\", URL);\n -description %@"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19391/"
] |
258,007
|
<p>How can I make the command button in my VC++ 6.0 dialog visible or invisible on load?</p>
|
[
{
"answer_id": 258031,
"author": "arul",
"author_id": 15409,
"author_profile": "https://Stackoverflow.com/users/15409",
"pm_score": 1,
"selected": false,
"text": "BOOL prevState = ShowWindow( itemHandle, SW_HIDE );\n"
},
{
"answer_id": 258209,
"author": "computinglife",
"author_id": 17224,
"author_profile": "https://Stackoverflow.com/users/17224",
"pm_score": 2,
"selected": false,
"text": "BOOL CMyDialog::OnInitDialog() \n {\n CDialog::OnInitDialog();\n\n if (ConditionShow)\n m_MyButton.ShowWindow(SW_SHOW);\n else\n m_MyButton.ShowWindow(SW_HIDE);\n\n return TRUE;\n }\n"
},
{
"answer_id": 44361551,
"author": "Mahbub Alam",
"author_id": 6659365,
"author_profile": "https://Stackoverflow.com/users/6659365",
"pm_score": 1,
"selected": false,
"text": "ShowDlgItem(Your_DLG_ITEM_ID,1); // visible = true \nShowDlgItem(Your_DLG_ITEM_ID,0); // visible = false\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
258,011
|
<p>I am using windsor DI framework in one of my MVC project. The project works fine when I tried to run from Visual Studio 2008.</p>
<p>But when i tried to run the project creating an application in IIS7 then I recieved the following error message:</p>
<blockquote>
<p>Looks like you forgot to register the http module
Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '<add
name="PerRequestLifestyle"
type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule,
Castle.MicroKernel" />' to the section on your
web.config</p>
</blockquote>
<p>But this module already exists in the httpmodule section of web.config file.</p>
<p>Does anyone know what I have to do to eliminate this problem.</p>
|
[
{
"answer_id": 258063,
"author": "yfeldblum",
"author_id": 12349,
"author_profile": "https://Stackoverflow.com/users/12349",
"pm_score": 6,
"selected": true,
"text": "system.webServer <configuration>\n <system.web>\n <httpModules>\n <add name=\"PerRequestLifestyle\" type=\"...\" />\n </httpModules>\n </system.web>\n <system.webServer>\n <modules>\n <add name=\"PerRequestLifestyle\" type=\"...\" />\n </modules>\n </system.webServer>\n</configuration>\n"
},
{
"answer_id": 4179657,
"author": "Korwin",
"author_id": 507602,
"author_profile": "https://Stackoverflow.com/users/507602",
"pm_score": 2,
"selected": false,
"text": "<system.web>\n <httpModules>\n <add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor\" />\n </httpModules>\n</system.web>\n"
},
{
"answer_id": 4968333,
"author": "David Levin",
"author_id": 571203,
"author_profile": "https://Stackoverflow.com/users/571203",
"pm_score": 6,
"selected": false,
"text": "IService Application_Start IService PerWebRequestLifestyle"
},
{
"answer_id": 7666018,
"author": "Maciorus",
"author_id": 878801,
"author_profile": "https://Stackoverflow.com/users/878801",
"pm_score": 2,
"selected": false,
"text": " <validation validateIntegratedModeConfiguration=\"false\"/>\n <system.webServer>\n <validation validateIntegratedModeConfiguration=\"false\"/>\n <modules runAllManagedModulesForAllRequests=\"true\">\n <remove name=\"PerRequestLifestyle\"/>\n <add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor\"/>\n </modules>\n</system.webServer>\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258011",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
258,020
|
<p>I've read the description of "functionoids" <a href="https://isocpp.org/wiki/faq/pointers-to-members#functionoids" rel="nofollow noreferrer">here</a>. They look like a poor-man's version of Boost::function and Boost::bind. Am I missing something? Is there a good reason to use them if you're already using Boost?</p>
|
[
{
"answer_id": 261442,
"author": "Nicola Bonelli",
"author_id": 19630,
"author_profile": "https://Stackoverflow.com/users/19630",
"pm_score": 2,
"selected": false,
"text": "tr1/boost::function tr1::function"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12193/"
] |
258,023
|
<p>I need to create a panel which should be invisible but the components inside it (for example, JTextArea, JButton, etc.) should be visible. When I click on the invisible panel, it should become visible.</p>
<p>I can only use JRE 1.4 and nothing more than that. :(</p>
<p>Any idea how to create such a transparent panel???</p>
|
[
{
"answer_id": 258040,
"author": "gizmo",
"author_id": 9396,
"author_profile": "https://Stackoverflow.com/users/9396",
"pm_score": 3,
"selected": false,
"text": "JComponent.setOpaque(false)"
},
{
"answer_id": 258041,
"author": "Peter",
"author_id": 26483,
"author_profile": "https://Stackoverflow.com/users/26483",
"pm_score": 4,
"selected": true,
"text": "setOpaque(false)\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258023",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22550/"
] |
258,028
|
<p>I recently installed VS 6.0 after installing VS 2008 and overwrite JIT settings .. when i started VS 2008 option dialog .. it said another debugger has taken over VS 2008 debugger and I asked me to reset .. so I did ..</p>
<p>Now everything works fine except javascript debugging. I am unable to debug javascript .. I can set breakpoint .. but in debug mode when I hover the breakpoint it says "The breakpoint will not currently be hit. The document is not loaded" ..</p>
<p>How can I solve this issue? Can I reset JIT Settings?</p>
|
[
{
"answer_id": 258036,
"author": "Rihan Meij",
"author_id": 29287,
"author_profile": "https://Stackoverflow.com/users/29287",
"pm_score": 2,
"selected": false,
"text": "var myFunction = new function()\n{\n debugger;\n alert('This will not properly attach the debugger');\n}\n var myFunctionThatDoesAttachTheDebugger = new function()\n{\n var x = 0;\n debugger;\n alert('this should work and attach the debugger');\n}\n javascript:debugger;\n"
},
{
"answer_id": 17257840,
"author": "Simon_Weaver",
"author_id": 16940,
"author_profile": "https://Stackoverflow.com/users/16940",
"pm_score": 0,
"selected": false,
"text": "ASP.NET Bundles BundleTable.EnableOptimizations = true;\n debugger;"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258028",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25138/"
] |
258,050
|
<p><code>CString</code> is quite handy, while <code>std::string</code> is more compatible with STL container. I am using <code>hash_map</code>. However, <code>hash_map</code> does not support <code>CString</code>s as keys, so I want to convert the <code>CString</code> into a <code>std::string</code>.</p>
<p>Writing a <code>CString</code> hash function seems to take a lot of time.</p>
<pre><code>CString -----> std::string
</code></pre>
<p>How can I do this?</p>
<pre><code>std::string -----> CString:
inline CString toCString(std::string const& str)
{
return CString(str.c_str());
}
</code></pre>
<p>Am I right?</p>
<hr />
<p><strong>EDIT:</strong></p>
<p>Here are more questions:</p>
<p>How can I convert from <code>wstring</code> to <code>CString</code> and vice versa?</p>
<pre><code>// wstring -> CString
std::wstring src;
CString result(src.c_str());
// CString -> wstring
CString src;
std::wstring des(src.GetString());
</code></pre>
<p>Is there any problem with this?</p>
<p>Additionally, how can I convert from <code>std::wstring</code> to <code>std::string</code> and vice versa?</p>
|
[
{
"answer_id": 258052,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 8,
"selected": true,
"text": "CString std::string CString cs(\"Hello\");\nstd::string s((LPCTSTR)cs);\n std::string LPCTSTR std::string LPSTR LPCSTR CT2CA CString cs (\"Hello\");\n// Convert a TCHAR string to a LPCSTR\nCT2CA pszConvertedAnsiString (cs);\n// construct a std::string using the LPCSTR input\nstd::string strStd (pszConvertedAnsiString);\n std::string CString std::string s(\"Hello\");\nCString cs(s.c_str());\n CStringT char* LPSTR wchar_t* LPWSTR CStringT CStringA wchar_t CStringW TCHAR CString char CStringT CStringT std::string NUL"
},
{
"answer_id": 258217,
"author": "OJ.",
"author_id": 611,
"author_profile": "https://Stackoverflow.com/users/611",
"pm_score": 5,
"selected": false,
"text": "std::basic_string<TCHAR> std::string"
},
{
"answer_id": 568867,
"author": "OJ.",
"author_id": 611,
"author_profile": "https://Stackoverflow.com/users/611",
"pm_score": -1,
"selected": false,
"text": "_bstr_t char wchar_t BSTR"
},
{
"answer_id": 1116184,
"author": "thehouse",
"author_id": 67013,
"author_profile": "https://Stackoverflow.com/users/67013",
"pm_score": 3,
"selected": false,
"text": "WideCharToMultiByte() #include <string>\n#include <vector>\n#include <cassert>\n#include <exception>\n\n#include <boost/system/system_error.hpp>\n#include <boost/integer_traits.hpp>\n\n/**\n * Convert a Windows wide string to a UTF-8 (multi-byte) string.\n */\nstd::string WideStringToUtf8String(const std::wstring& wide)\n{\n if (wide.size() > boost::integer_traits<int>::const_max)\n throw std::length_error(\n \"Wide string cannot be more than INT_MAX characters long.\");\n if (wide.size() == 0)\n return \"\";\n\n // Calculate necessary buffer size\n int len = ::WideCharToMultiByte(\n CP_UTF8, 0, wide.c_str(), static_cast<int>(wide.size()), \n NULL, 0, NULL, NULL);\n\n // Perform actual conversion\n if (len > 0)\n {\n std::vector<char> buffer(len);\n len = ::WideCharToMultiByte(\n CP_UTF8, 0, wide.c_str(), static_cast<int>(wide.size()),\n &buffer[0], static_cast<int>(buffer.size()), NULL, NULL);\n if (len > 0)\n {\n assert(len == static_cast<int>(buffer.size()));\n return std::string(&buffer[0], buffer.size());\n }\n }\n\n throw boost::system::system_error(\n ::GetLastError(), boost::system::system_category);\n}\n"
},
{
"answer_id": 6227932,
"author": "Salman Marvasti",
"author_id": 782787,
"author_profile": "https://Stackoverflow.com/users/782787",
"pm_score": 3,
"selected": false,
"text": "CString std::string CString someStr(\"Hello how are you\");\nstd::string std(someStr, someStr.GetLength());\n"
},
{
"answer_id": 33627524,
"author": "user5546107",
"author_id": 5546107,
"author_profile": "https://Stackoverflow.com/users/5546107",
"pm_score": -1,
"selected": false,
"text": "std::wstring CStringToWString(const CString& s)\n{\n std::string s2;\n s2 = std::string((LPCTSTR)s);\n return std::wstring(s2.begin(),s2.end());\n}\n\nCString WStringToCString(std::wstring s)\n{\n std::string s2;\n s2 = std::string(s.begin(),s.end());\n return s2.c_str();\n}\n"
},
{
"answer_id": 35925070,
"author": "Neil",
"author_id": 620612,
"author_profile": "https://Stackoverflow.com/users/620612",
"pm_score": 1,
"selected": false,
"text": "CString someStr(\"Hello how are you\");\nstd::string std(somStr, someStr.GetLength());\n unsigned char hashResult[SHA_DIGEST_LENGTH]; \nauto value = std::string(reinterpret_cast<char*>hashResult, SHA_DIGEST_LENGTH);\n"
},
{
"answer_id": 41785583,
"author": "freeze",
"author_id": 7159803,
"author_profile": "https://Stackoverflow.com/users/7159803",
"pm_score": 2,
"selected": false,
"text": "//Convert CString to std::string\ninline std::string to_string(const CString& cst)\n{\n return CT2A(cst.GetString());\n}\n"
},
{
"answer_id": 44835115,
"author": "zar",
"author_id": 841330,
"author_profile": "https://Stackoverflow.com/users/841330",
"pm_score": 0,
"selected": false,
"text": "CString std::string CString void CStringsPlayDlg::writeLog(const std::string &text)\n{\n std::string filename = \"c:\\\\test\\\\test.txt\";\n\n std::ofstream log_file(filename.c_str(), std::ios_base::out | std::ios_base::app);\n\n log_file << text << std::endl;\n}\n CString std::string firstName = \"First\";\nCString lastName = _T(\"Last\");\n\nwriteLog( firstName + \", \" + std::string( CT2A( lastName ) ) ); \n std::string CString"
},
{
"answer_id": 46798233,
"author": "u8it",
"author_id": 3546415,
"author_profile": "https://Stackoverflow.com/users/3546415",
"pm_score": 0,
"selected": false,
"text": "CString CStringA string std::string s((LPCTSTR)cs); _UNICODE _CSTRING_DISABLE_NARROW_WIDE_CONVERSION CString s1(\"SomeString\");\n string s2((CStringA)s1);\n"
},
{
"answer_id": 51945055,
"author": "Pat. ANDRIA",
"author_id": 7561697,
"author_profile": "https://Stackoverflow.com/users/7561697",
"pm_score": 2,
"selected": false,
"text": "std::string Utils::CString2String(const CString& cString) \n{\n std::string strStd;\n\n for (int i = 0; i < cString.GetLength(); ++i)\n {\n if (cString[i] <= 0x7f)\n strStd.append(1, static_cast<char>(cString[i]));\n else\n strStd.append(1, '?');\n }\n\n return strStd;\n}\n"
},
{
"answer_id": 51945363,
"author": "Amit G.",
"author_id": 706055,
"author_profile": "https://Stackoverflow.com/users/706055",
"pm_score": 2,
"selected": false,
"text": "A2CW (LPCSTR) -> (LPCWSTR) \nA2W (LPCSTR) -> (LPWSTR) \nW2CA (LPCWSTR) -> (LPCSTR) \nW2A (LPCWSTR) -> (LPSTR) \n void Example() // ** UNICODE case **\n{\n USES_CONVERSION; // (1)\n\n // CString to std::string / std::wstring\n CString strMfc{ \"Test\" }; // strMfc = L\"Test\"\n std::string strStd = W2A(strMfc); // ** Conversion Macro: strStd = \"Test\" **\n std::wstring wstrStd = strMfc.GetString(); // wsrStd = L\"Test\"\n\n // std::string to CString / std::wstring\n strStd = \"Test 2\";\n strMfc = strStd.c_str(); // strMfc = L\"Test 2\"\n wstrStd = A2W(strStd.c_str()); // ** Conversion Macro: wstrStd = L\"Test 2\" **\n\n // std::wstring to CString / std::string \n wstrStd = L\"Test 3\";\n strMfc = wstrStd.c_str(); // strMfc = L\"Test 3\"\n strStd = W2A(wstrStd.c_str()); // ** Conversion Macro: strStd = \"Test 3\" **\n}\n _convert USES_CONVERSION #ifndef _DEBUG\n #define USES_CONVERSION int _convert; (_convert); UINT _acp = ATL::_AtlGetConversionACP() /*CP_THREAD_ACP*/; (_acp); LPCWSTR _lpw; (_lpw); LPCSTR _lpa; (_lpa)\n#else\n #define USES_CONVERSION int _convert = 0; (_convert); UINT _acp = ATL::_AtlGetConversionACP() /*CP_THREAD_ACP*/; (_acp); LPCWSTR _lpw = NULL; (_lpw); LPCSTR _lpa = NULL; (_lpa)\n#endif\n"
},
{
"answer_id": 52201660,
"author": "IInspectable",
"author_id": 1889329,
"author_profile": "https://Stackoverflow.com/users/1889329",
"pm_score": 2,
"selected": false,
"text": "CString CStringA char CStringW wchar_t wchar_t char CString _UNICODE std::string wchar_t char CStringA CStringW std::wstring std::string #include <string>\n#include <atlconv.h>\n\nstd::string to_utf8(CStringW const& src_utf16)\n{\n return { CW2A(src_utf16.GetString(), CP_UTF8).m_psz };\n}\n\nstd::wstring to_utf16(CStringA const& src_utf8)\n{\n return { CA2W(src_utf8.GetString(), CP_UTF8).m_psz };\n}\n #include <string>\n#include <atlconv.h>\n\nstd::string to_std_string(CStringA const& src)\n{\n return { src.GetString(), src.GetString() + src.GetLength() };\n}\n\nstd::wstring to_std_wstring(CStringW const& src)\n{\n return { src.GetString(), src.GetString() + src.GetLength() };\n}\n"
},
{
"answer_id": 55765583,
"author": "shawon",
"author_id": 3859220,
"author_profile": "https://Stackoverflow.com/users/3859220",
"pm_score": 1,
"selected": false,
"text": "CString datasetPath;\nCT2CA st(datasetPath);\nstring dataset(st);\n"
},
{
"answer_id": 58534341,
"author": "JL Mutzz Mutz",
"author_id": 12266718,
"author_profile": "https://Stackoverflow.com/users/12266718",
"pm_score": 2,
"selected": false,
"text": "CString to std::string std::string sText(CW2A(CSText.GetString(), CP_UTF8 ));\n"
},
{
"answer_id": 69285124,
"author": "GiaMat45",
"author_id": 14877217,
"author_profile": "https://Stackoverflow.com/users/14877217",
"pm_score": 2,
"selected": false,
"text": "CString GetString() LPCWSTR LPCSTR wstring CString cs(\"Hello\");\nwstring ws = wstring(cs.GetString());\nstring s = string(ws.begin(), ws.end());\n CString cs(\"Hello\");\nstring s = string(cs.GetString());\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258050",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25749/"
] |
258,053
|
<p>In excel 2007, I have a formula in a cell like the following:</p>
<pre><code>=COUNTIFS('2008-10-31'!$C:$C;">="&'$A7)
</code></pre>
<p>Now I want to make the name of the sheet ('2008-10-31') be dependent on the value of some cell (say A1). Something like: </p>
<pre><code>=COUNTIFS(A1!$C:$C;">="&'$A7) // error
</code></pre>
<p>Is there is way to do this? Or do I have to write a VBA-Macro for it?</p>
|
[
{
"answer_id": 258090,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 3,
"selected": false,
"text": "=INDIRECT(\"SHEET2!A1\")\n=COUNTIFS(INDIRECT(A1 & \"!$C:$C\"); \">=\" & $A7)\n"
},
{
"answer_id": 258161,
"author": "dbb",
"author_id": 25675,
"author_profile": "https://Stackoverflow.com/users/25675",
"pm_score": 5,
"selected": true,
"text": "=COUNTIFS(INDIRECT(\"'\" & A1 & \"'!$C:$C\"); \">=\" & $A7)\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26070/"
] |
258,056
|
<p>I need to get the data of an particular <code><td></code>, but I don't have any <code>id</code> or <code>name</code> for that particular <code><td></code>. How do you get the contents of that <code><td></code>?</p>
<p>For example:</p>
<pre><code><table>
<tr><td>name</td><td>praveen</td></tr>
<tr><td>designation</td><td>software engineer</td></tr>
</table>
</code></pre>
<p>Is it possible to get the value "designation" from this table.. I need to extract the word "software engineer" using javascript.</p>
|
[
{
"answer_id": 258067,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 1,
"selected": false,
"text": "var tables = document.getElementById('TABLE'); // instead of document.all.tag\nvar rows;\nvar cells;\nvar maxCells = 1;\nvar designation;\nif (tables) {\n for (var t=0; t<tables.length; t++) {\n rows = tables[t].all.tags('TR');\n if (tables[t].all.tags('TABLE').length == 0) {\n for (var r=0; r<rows.length; r++) {\n if (rows[r].innerText != '') {\n cells = rows[r].all.tags('TD');\n for (var c=0; c<cells.length; c++) {\n if (cells[c].innerText == 'designation' && c<(cells.length-1)) {\n designation = cells[c+1].innerText;\n }\n }\n }\n }\n }\n }\n}\n if (/msie/i.test (navigator.userAgent)) //only override IE\n{\n document.nativeGetElementById = document.getElementById;\n document.getElementById = function(id)\n {\n var elem = document.nativeGetElementById(id);\n if(elem)\n {\n //make sure that it is a valid match on id\n if(elem.attributes['id'].value == id)\n {\n return elem;\n }\n else\n {\n //otherwise find the correct element\n for(var i=1;i<document.all[id].length;i++)\n {\n if(document.all[id][i].attributes['id'].value == id)\n {\n return document.all[id][i];\n }\n }\n }\n }\n return null;\n };\n}\n"
},
{
"answer_id": 258109,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 2,
"selected": false,
"text": "function GetTdContent(label)\n{\n var TDs = document.getElementsByTagName(\"TD\");\n var foundFlag = false;\n\n for (i = 0; i < TDs.length; i++)\n {\n if (foundFlag) return TDs[i].innerHTML;\n foundFlag = TDs[i].innerHTML.toLower() == label.toLower(); \n }\n}\n var value = GetTdContent(\"designation\");\n"
},
{
"answer_id": 258130,
"author": "Jeff Schumacher",
"author_id": 27498,
"author_profile": "https://Stackoverflow.com/users/27498",
"pm_score": 2,
"selected": false,
"text": "function GetNextChildText(tagToFind, valueToFind) {\n var nextText = \"\";\n $(tagToFind).each(function(i) {\n if ($(this).text() == valueToFind) {\n if ($(this).next() != null && $(this).next() != undefined) {\n nextText = $(this).next().text();\n }\n }\n });\n return (nextText);\n}\n var designationText = GetNextChildText('td', 'designation');\n"
},
{
"answer_id": 258918,
"author": "roenving",
"author_id": 23142,
"author_profile": "https://Stackoverflow.com/users/23142",
"pm_score": 0,
"selected": false,
"text": "<script type=\"text/javascript\">\nfunction getText(tText){\n var tds = document.getElementsByTagName(\"td\");\n for(var i=0, im=tds.length; im>i; i++){\n if(tds[i].firstChild.nodeValue == tText)\n return tds[i].nextSibling.firstChild.nodeValue;\n }\n}\n</script>\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
258,062
|
<p><em>This is javascript, but a virtually identical regex is failing in PHP too, so I don't think it's language specific</em></p>
<pre><code>var r = new RegExp(
"^(:19|20)?[0-9][0-9]" // optional 19/20 start followed by 2 numbers
+ "-" // a hyphen
+ "(:0?[1-9]|1[0-2])" // optional 0 followed by 1-9, or 10, 11, 12
+ "-" // a hyphen
+ "(:3[01]|[12][0-9]|0?[1-9])$" // you get the idea.
);
r.test("2008-07-01"); // == false
</code></pre>
<p>What on earth am I missing?</p>
|
[
{
"answer_id": 258066,
"author": "Gareth",
"author_id": 31582,
"author_profile": "https://Stackoverflow.com/users/31582",
"pm_score": 5,
"selected": true,
"text": "(?:19|20) (:19|20)"
},
{
"answer_id": 258118,
"author": "Fusion",
"author_id": 6253,
"author_profile": "https://Stackoverflow.com/users/6253",
"pm_score": 2,
"selected": false,
"text": "?: ? (:) (=) (<=)"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
258,091
|
<p>POSIX environments provide at least two ways of accessing files. There's the standard system calls <code>open()</code>, <code>read()</code>, <code>write()</code>, and friends, but there's also the option of using <code>mmap()</code> to map the file into virtual memory.</p>
<p>When is it preferable to use one over the other? What're their individual advantages that merit including two interfaces?</p>
|
[
{
"answer_id": 258097,
"author": "Don Neufeld",
"author_id": 13097,
"author_profile": "https://Stackoverflow.com/users/13097",
"pm_score": 9,
"selected": true,
"text": "mmap mmap mmap A 1MB malloc mmaps A B mmap mmap mmap mmap mmap mmap'd MAP_HASSEMAPHORE mmap mmap mmap X mmap mmap"
},
{
"answer_id": 2895799,
"author": "Patrick Schlüter",
"author_id": 146377,
"author_profile": "https://Stackoverflow.com/users/146377",
"pm_score": 6,
"selected": false,
"text": "mmap mmap mmap madvise"
},
{
"answer_id": 46442219,
"author": "Miljen Mikic",
"author_id": 1460628,
"author_profile": "https://Stackoverflow.com/users/1460628",
"pm_score": 6,
"selected": false,
"text": "mmap( ) mmap( ) read( ) write( ) read( ) write( ) lseek( ) mmap( ) mmap( ) mmap( ) mmap( )"
},
{
"answer_id": 57968212,
"author": "TrentP",
"author_id": 1934800,
"author_profile": "https://Stackoverflow.com/users/1934800",
"pm_score": 2,
"selected": false,
"text": "mmap() read() madvise() mmap()"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258091",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/101/"
] |
258,099
|
<p>What is the proper way to terminate a Swing application from the code, and what are the pitfalls?</p>
<p>I'd tried to close my application automatically after a timer fires. But just calling <code>dispose()</code> on the <code>JFrame</code> didn't do the trick - the window vanished but the application did not terminate. However when closing the window with the close button, the application does terminate. What should I do?</p>
|
[
{
"answer_id": 258102,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 4,
"selected": false,
"text": "System.exit(0);\n"
},
{
"answer_id": 258115,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 5,
"selected": false,
"text": "frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n System.exit(0) public void windowClosing(WindowEvent e) {\n displayMessage(\"WindowListener method called: windowClosing.\");\n //A pause so user can see the message before\n //the window actually closes.\n ActionListener task = new ActionListener() {\n boolean alreadyDisposed = false;\n public void actionPerformed(ActionEvent e) {\n if (frame.isDisplayable()) {\n alreadyDisposed = true;\n frame.dispose();\n }\n }\n };\n Timer timer = new Timer(500, task); //fire every half second\n timer.setInitialDelay(2000); //first delay 2 seconds\n timer.setRepeats(false);\n timer.start();\n}\n\npublic void windowClosed(WindowEvent e) {\n //This will only be seen on standard output.\n displayMessage(\"WindowListener method called: windowClosed.\");\n}\n"
},
{
"answer_id": 258146,
"author": "Vincent Ramdhanie",
"author_id": 27439,
"author_profile": "https://Stackoverflow.com/users/27439",
"pm_score": 2,
"selected": false,
"text": "import javax.swing.*;\nimport java.awt.*;\nimport java.awt.event.*;\n\npublic class ClosingFrame extends JFrame implements WindowListener{\n\npublic ClosingFrame(){\n super(\"A Frame\");\n setSize(400, 400);\n //in case the user closes the window\n setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n setVisible(true);\n //enables Window Events on this Component\n this.addWindowListener(this);\n\n //start a timer\n Thread t = new Timer();\n t.start();\n }\n\npublic void windowOpened(WindowEvent e){}\npublic void windowClosing(WindowEvent e){}\n\n //the event that we are interested in\npublic void windowClosed(WindowEvent e){\n System.exit(0);\n}\n\npublic void windowIconified(WindowEvent e){}\npublic void windowDeiconified(WindowEvent e){}\npublic void windowActivated(WindowEvent e){}\npublic void windowDeactivated(WindowEvent e){}\n\n //a simple timer \n class Timer extends Thread{\n int time = 10;\n public void run(){\n while(time-- > 0){\n System.out.println(\"Still Waiting:\" + time);\n try{\n sleep(500); \n }catch(InterruptedException e){}\n }\n System.out.println(\"About to close\");\n //close the frame\n ClosingFrame.this.processWindowEvent(\n new WindowEvent(\n ClosingFrame.this, WindowEvent.WINDOW_CLOSED));\n }\n }\n\n //instantiate the Frame\npublic static void main(String args[]){\n new ClosingFrame();\n }\n\n}\n"
},
{
"answer_id": 259283,
"author": "James Schek",
"author_id": 17871,
"author_profile": "https://Stackoverflow.com/users/17871",
"pm_score": 8,
"selected": true,
"text": "DISPOSE_ON_CLOSE EXIT_ON_CLOSE Frame.getFrames()"
},
{
"answer_id": 2582824,
"author": "Eric Sadler",
"author_id": 309737,
"author_profile": "https://Stackoverflow.com/users/309737",
"pm_score": 3,
"selected": false,
"text": "public class CloseExample extends JFrame implements ActionListener {\n\n private JButton turnOffButton;\n\n private void addStuff() {\n setDefaultCloseOperation(DISPOSE_ON_CLOSE);\n turnOffButton = new JButton(\"Exit\");\n turnOffButton.addActionListener(this);\n this.add(turnOffButton);\n }\n\n public void actionPerformed(ActionEvent quitEvent) {\n /* Iterate through and close all timers, threads, etc here */\n this.processWindowEvent(\n new WindowEvent(\n this, WindowEvent.WINDOW_CLOSING));\n }\n\n public CloseExample() {\n super(\"Close Me!\");\n addStuff();\n }\n\n public static void main(String[] args) {\n java.awt.EventQueue.invokeLater(new Runnable() {\n public void run() {\n CloseExample cTW = new CloseExample();\n cTW.setSize(200, 100);\n cTW.setLocation(300,300);\n cTW.setVisible(true);\n }\n });\n }\n}\n"
},
{
"answer_id": 6472542,
"author": "Kachwahed",
"author_id": 188311,
"author_profile": "https://Stackoverflow.com/users/188311",
"pm_score": 4,
"selected": false,
"text": " private JButton btnExit;\n ...\n btnExit = new JButton(\"Quit\"); \n btnExit.addActionListener(new ActionListener() {\n public void actionPerformed(ActionEvent e){\n Container frame = btnExit.getParent();\n do \n frame = frame.getParent(); \n while (!(frame instanceof JFrame)); \n ((JFrame) frame).dispose();\n }\n });\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21499/"
] |
258,119
|
<p>I am instantiating a class A (which I am importing from somebody
else, so I can't modify it) into my class X.</p>
<p>Is there a way I can intercept or wrap calls to methods in A?
I.e., in the code below can I call</p>
<pre><code>x.a.p1()
</code></pre>
<p>and get the output</p>
<pre><code>X.pre
A.p1
X.post
</code></pre>
<p>Many TIA!</p>
<pre><code>class A:
# in my real application, this is an imported class
# that I cannot modify
def p1(self): print 'A.p1'
class X:
def __init__(self):
self.a=A()
def pre(self): print 'X.pre'
def post(self): print 'X.post'
x=X()
x.a.p1()
</code></pre>
|
[
{
"answer_id": 258179,
"author": "Peter Hoffmann",
"author_id": 720,
"author_profile": "https://Stackoverflow.com/users/720",
"pm_score": 1,
"selected": false,
"text": "def wrapped(pre, post, f):\n def wrapper(*args, **kwargs):\n pre()\n retval = f(*args, **kwargs)\n post()\n return retval\n return wrapper\n\nclass Y:\n def __init__(self):\n self.a=A()\n self.a.p1 = wrapped(self.pre, self.post, self.a.p1)\n\n def pre(self): print 'X.pre'\n def post(self): print 'X.post'\n"
},
{
"answer_id": 258259,
"author": "Mark Harrison",
"author_id": 116,
"author_profile": "https://Stackoverflow.com/users/116",
"pm_score": 0,
"selected": false,
"text": "# Define two decorator factories.\ndef precall(pre):\n def decorator(f):\n def newf(*args, **kwargs):\n pre()\n return f(*args, **kwargs)\n return newf\n return decorator\n\ndef postcall(post):\n def decorator(f):\n def newf(*args, **kwargs):\n x = f(*args, **kwargs)\n post()\n return x\n return newf\n return decorator\n class A:\n # in my real application, this is an imported class\n # that I cannot modify\n def p1(self): print 'A.p1'\n\nclass X:\n def __init__(self):\n self.a=A()\n A.p1 = precall(self.pre)(postcall(self.post)(A.p1))\n def pre(self): print 'X.pre'\n def post(self): print 'X.post'\n\n\nx=X()\nx.a.p1()\n X.pre\nA.p1\nX.post\n"
},
{
"answer_id": 258274,
"author": "Thomas Watnedal",
"author_id": 4059,
"author_profile": "https://Stackoverflow.com/users/4059",
"pm_score": 4,
"selected": true,
"text": "from types import MethodType\n\nclass PrePostCaller:\n def __init__(self, other):\n self.other = other\n\n def pre(self): print 'pre'\n def post(self): print 'post'\n\n def __getattr__(self, name):\n if hasattr(self.other, name):\n func = getattr(self.other, name)\n return lambda *args, **kwargs: self._wrap(func, args, kwargs)\n raise AttributeError(name)\n\n def _wrap(self, func, args, kwargs):\n self.pre()\n if type(func) == MethodType:\n result = func( *args, **kwargs)\n else:\n result = func(self.other, *args, **kwargs)\n self.post()\n return result\n\n#Examples of use\nclass Foo:\n def stuff(self):\n print 'stuff'\n\na = PrePostCaller(Foo())\na.stuff()\n\na = PrePostCaller([1,2,3])\nprint a.count()\n pre\nstuff\npost\npre\npost\n0\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258119",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/116/"
] |
258,120
|
<p>Is the memory space consumed by one object with 100 attributes the same as that of 100 objects, with one attribute each?</p>
<p>How much memory is allocated for an object?<br>
How much additional space is used when adding an attribute?</p>
|
[
{
"answer_id": 258143,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 5,
"selected": false,
"text": "public class SingleByte\n{\n private byte b;\n}\n public class OneHundredBytes\n{\n private byte b00, b01, ..., b99;\n}\n SingleByte OneHundredBytes OneHundredBytes SingleByte"
},
{
"answer_id": 258150,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 8,
"selected": false,
"text": "boolean[] BitSet Instrumentation.getObjectSize() -Xmx32G -Xmx32G Integer int Integer Long Long Integer int[dim1][dim2] int[dim1][dim2] int[dim2] Object int[128][2] int[256] byte[256][1] String String String String class X { // 8 bytes for reference to the class definition\n int a; // 4 bytes\n byte b; // 1 byte\n Integer c = new Integer(); // 4 bytes for a reference\n}\n X"
},
{
"answer_id": 14501891,
"author": "catch23",
"author_id": 1498427,
"author_profile": "https://Stackoverflow.com/users/1498427",
"pm_score": 3,
"selected": false,
"text": "java.lang.Runtime.getRuntime();\n public class PerformanceTest {\n private static final long MEGABYTE = 1024L * 1024L;\n\n public static long bytesToMegabytes(long bytes) {\n return bytes / MEGABYTE;\n }\n\n public static void main(String[] args) {\n // I assume you will know how to create an object Person yourself...\n List <Person> list = new ArrayList <Person> ();\n for (int i = 0; i <= 100_000; i++) {\n list.add(new Person(\"Jim\", \"Knopf\"));\n }\n\n // Get the Java runtime\n Runtime runtime = Runtime.getRuntime();\n\n // Run the garbage collector\n runtime.gc();\n\n // Calculate the used memory\n long memory = runtime.totalMemory() - runtime.freeMemory();\n System.out.println(\"Used memory is bytes: \" + memory);\n System.out.println(\"Used memory is megabytes: \" + bytesToMegabytes(memory));\n }\n }\n"
},
{
"answer_id": 32224498,
"author": "Dmitry Spikhalskiy",
"author_id": 525203,
"author_profile": "https://Stackoverflow.com/users/525203",
"pm_score": 5,
"selected": false,
"text": "Running 64-bit HotSpot VM.\nUsing compressed oop with 3-bit shift.\nUsing compressed klass with 3-bit shift.\nObjects are 8 bytes aligned.\nField sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]\nArray element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]\n\njava.lang.Integer object internals:\n OFFSET SIZE TYPE DESCRIPTION VALUE\n 0 12 (object header) N/A\n 12 4 int Integer.value N/A\nInstance size: 16 bytes (estimated, the sample instance is not available)\nSpace losses: 0 bytes internal + 0 bytes external = 0 bytes total\n import org.openjdk.jol.info.ClassLayout;\nimport org.openjdk.jol.util.VMSupport;\n\npublic static void main(String[] args) {\n System.out.println(VMSupport.vmDetails());\n System.out.println(ClassLayout.parseClass(Integer.class).toPrintable());\n}\n <dependency>\n <groupId>org.openjdk.jol</groupId>\n <artifactId>jol-core</artifactId>\n <version>0.3.2</version>\n</dependency>\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258120",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
258,131
|
<p>I have signed numbers (2s complement) stored in 32-bit integers, and I want to extract 16-bit fields from them. Is it true that if I extract the low 16 bits from a 32-bit signed number, the result will be correct as long as the original (32-bit) number fits into 16 bits ?</p>
<p>For positive numbers it is trivially true, and it seems that for negatives as well. But can it be proven ?</p>
<p>Thanks in advance</p>
|
[
{
"answer_id": 258149,
"author": "Motti",
"author_id": 3848,
"author_profile": "https://Stackoverflow.com/users/3848",
"pm_score": 3,
"selected": true,
"text": "Nibble (-2) = 1110 => Byte(-2) = 1111_1110"
},
{
"answer_id": 258155,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 0,
"selected": false,
"text": "int negative = -4711;\nshort x = (short) negative;\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8206/"
] |
258,132
|
<p>Saving data to Postscript in my app results in a Postscript file which I can view without issues in GhostView, but when I try to print it, the printer isn't able to print it because it seems to be invalid.</p>
<p>Is there a way to validate / find errors in Postscript files without actually sending it to a printer? Preferred would be some kind of Java API/library, but a program which does the same would be fine as well.</p>
<hr>
<p><strong>Edit #1</strong> : no I don't know why it's invalid, nor even necessarily if it's invalid, but would like to be able to validate it outside of ghostview, or figure out what's going on when it can't print.</p>
<hr>
<p><strong>Answer</strong> : Well using the ps2ps trick I was able to see the output that Postscript does and there check the difference. The difference was that I am not allowed to have a decimal number for the width or height of images in the Postscript, but rather only integers. So I still didn't find a way to validate, but this way was good enough for my problem. Thanks.</p>
|
[
{
"answer_id": 258177,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 3,
"selected": true,
"text": "ps2ps -sDEVICE=pswrite ps2ps2 -sDEVICE=ps2write"
},
{
"answer_id": 2981290,
"author": "Kurt Pfeifle",
"author_id": 359307,
"author_profile": "https://Stackoverflow.com/users/359307",
"pm_score": 3,
"selected": false,
"text": "gswin32c ^\n -sDEVICE=nullpage ^\n -dNOPAUSE ^\n -dBATCH ^\n c:/path/to/file/to/be/validated.pdf-or-ps ^\n 1>validated.stdout ^\n 2>validated.stderr\n %errorlevel% validated.stderr"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6583/"
] |
258,134
|
<p>I'm doing some FK analysis of our tables by making a directed
graph representing FK dependencies and then traversing the
graph. In my code, I name everything using directed graph
terminology, but I'd like to have something a bit more
"user friendly" in the report.</p>
<p>In this scenario:</p>
<pre><code>create table t1(a varchar2(20));
alter table t1 add constraint t1_fk foreign key(a) references t2(b);
</code></pre>
<p>t1.a must exist in t2.b. So, what words should I use in the blanks?</p>
<pre><code>t1 is the _______ of t2.
t2 is the _______ of t1.
</code></pre>
<p>Many TIA!</p>
|
[
{
"answer_id": 258354,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 2,
"selected": false,
"text": "t1 is the parent of t2.\nt2 is the child of t1.\n InvoiceLineItem is a part of Invoice.\nInvoice has one or more InvoiceLineItems.\n User must belong to a Business.\nBusiness has zero or more Users.\n"
},
{
"answer_id": 42073637,
"author": "jakodev",
"author_id": 5736075,
"author_profile": "https://Stackoverflow.com/users/5736075",
"pm_score": 0,
"selected": false,
"text": "t2 t1 t1 t2 sys.foreign_keys parent_object_id referenced_object_id"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/116/"
] |
258,136
|
<p>I am investigating a production system where there are several Windows services communicating with each other through TCP/IP sockets. I'm trying to figure out which executable is listening to which IP address and which port on a given machine.</p>
<p>Other than rummaging through each windows service's obscure configuration files, is there a system tool that can more easily give me the details I want?</p>
|
[
{
"answer_id": 258140,
"author": "Zoredache",
"author_id": 20267,
"author_profile": "https://Stackoverflow.com/users/20267",
"pm_score": 2,
"selected": false,
"text": "netstat -abn\n"
},
{
"answer_id": 258153,
"author": "mkoeller",
"author_id": 33433,
"author_profile": "https://Stackoverflow.com/users/33433",
"pm_score": 6,
"selected": true,
"text": "netstat -?\n netstat -a\n netstat -o\n netstat -b \n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33404/"
] |
258,172
|
<p>I'm operating a neighbourhood <a href="http://maps.google.de/maps/ms?ie=UTF8&hl=de&msa=0&msid=101021148567197540440.00043fcffa4cdf06fb4bc&ll=51.791948,8.173571&spn=0.033976,0.058365&t=h&z=14" rel="nofollow noreferrer">WIFI network in a rural environment</a>.</p>
<p>Now I'm looking fo a monitoring tool to run on a server (Windows or Linux) which would track bandwidth, uptime (clients as well as internet connection), etc...
Most of this information is exposed via SNMP by my routers and access points, so SNMP support is required.</p>
<p>Additional features should be: </p>
<ul>
<li>Graphical data representation</li>
<li>free license</li>
</ul>
<p>So what's the best choice for me?</p>
<p><em>Edit</em> These are the tools mentioned so far:</p>
<ul>
<li><a href="http://oss.oetiker.ch/mrtg/" rel="nofollow noreferrer">MRTG</a></li>
<li><a href="http://munin.projects.linpro.no/" rel="nofollow noreferrer">Munin</a></li>
<li><a href="http://www.nagios.org/" rel="nofollow noreferrer">Nagios</a></li>
<li><a href="http://www.zenoss.com/product/core" rel="nofollow noreferrer">Zenoss Core</a></li>
<li><a href="http://www.ntop.org/" rel="nofollow noreferrer">ntop</a></li>
<li><a href="http://cacti.net/features.php" rel="nofollow noreferrer">cacti</a></li>
<li><a href="http://www.zabbix.com/" rel="nofollow noreferrer">ZABBIX</a></li>
</ul>
|
[
{
"answer_id": 258216,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 4,
"selected": true,
"text": "cfgmaker --output=mrtg_myrouter.cfg public@1.2.3.4\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258172",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33433/"
] |
258,173
|
<p>I'm doing .NET 3.5 programming in VB for a class. I have a .mdb database with 3 related tables, and a table adapter with some queries on it that look like this:</p>
<pre><code>SELECT PropertyID, Street, Unit, City, Zip, Type, Bedrooms, Bathrooms, Area, MonthlyRent
FROM tblProperties
</code></pre>
<p>Then in a form i have a DataGridView. What i want to do is take the data that is returned from the query and display it in the DGV. However, when i do this, it displays all 35 columns in the database, not the 10 i selected (The ten are the only ones that have data in them however... so it's basically a table with a bunch of blank columns).</p>
<p>My current, inelegant solution is to return the query to a DataTable, then iterate through the table's columns, deleting the one's i dont want. This is not robust, efficient, and does not like me delete the primary key column.</p>
<p>My TA suggested trying to use an untyped databinding... he said this should display only the data I pull, but neither of us has been able to figure this out yet.</p>
<p>Thank You!</p>
<p>UPDATE</p>
<p>I'm not sure what you mean by the .aspx/.aspx.vb pages, but this is the query code i have from the table adapter</p>
<pre><code>SELECT tblRent.PaymentID, tblTenant.TenantName, tblProperties.Street, tblProperties.Unit, tblProperties.City, tblRent.AmountPaid, tblRent.PaymentDate,
tblTenant.Telephone
FROM ((tblProperties INNER JOIN
tblRent ON tblProperties.PropertyID = tblRent.PropertyID) INNER JOIN
tblTenant ON tblProperties.PropertyID = tblTenant.PropertyID)
</code></pre>
<p>and here is where i use it in code:</p>
<pre><code>Public Sub getRent()
propView.DataSource = TblPropertiesTableAdapter.GetAllRentReceipts()
propView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
propView.ReadOnly = True
End Sub
</code></pre>
<p>propView is a DataGridView that does not have a DataSource selected at load</p>
|
[
{
"answer_id": 258216,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 4,
"selected": true,
"text": "cfgmaker --output=mrtg_myrouter.cfg public@1.2.3.4\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258173",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33583/"
] |
258,198
|
<p>inside my C# app I runs a 7z process to extract an archive into it's directory</p>
<p>the archive is located in a random-named directory on the %TEMP% directory for example</p>
<blockquote>
<p>C:\Documents and Settings\User\Local
Settings\Temp\vtugoyrc.fd2</p>
</blockquote>
<p>(fullPathFilename = "C:\Documents and Settings\User\Local Settings\Temp\vtugoyrc.fd2\xxx.7z")</p>
<p>my code is:</p>
<pre><code>sevenZipProcessInfo.FileName = SEVEN_ZIP_EXECUTABLE_PATH;
sevenZipProcessInfo.Arguments = "x " + fullPathFilename;
sevenZipProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;
sevenZipProcessInfo.UseShellExecute = true;
sevenZipProcessInfo.WorkingDirectory = Path.GetDirectoryName(fullPathFilename);
Process sevenZipProcess = Process.Start(sevenZipProcessInfo);
if (sevenZipProcess != null)
{
sevenZipProcess.WaitForExit();
if (sevenZipProcess.ExitCode != 0)
...exit code is 2 (fatal error by the 7z help)
</code></pre>
<p>Where can I find more elaborate documentation ?</p>
|
[
{
"answer_id": 258338,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "WaitForExit() 1>out.txt 2>&1 out.txt"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30324/"
] |
258,204
|
<p>I have a dictionary that I normally access with a key, so I need fast random access reads. However for one function I need to process every item in the dictionary where the order is important. It seems to be working OK in tests. Is it OK to depend on the order of items in a dictionary?</p>
|
[
{
"answer_id": 258221,
"author": "Eoin Campbell",
"author_id": 30155,
"author_profile": "https://Stackoverflow.com/users/30155",
"pm_score": 0,
"selected": false,
"text": "tpower Dictionary SortedDictionary Dictionary SortedDictionary"
},
{
"answer_id": 258386,
"author": "bruno conde",
"author_id": 31136,
"author_profile": "https://Stackoverflow.com/users/31136",
"pm_score": -1,
"selected": false,
"text": " IDictionary<string, int> dic = new Dictionary<string, int>(10);\n\n Console.WriteLine(\"Adding ...\");\n for (int i = 0; i < 1000000; i++)\n {\n Guid guid = Guid.NewGuid();\n dic.Add(guid.ToString(), i);\n }\n Console.WriteLine(\"Testing ...\");\n\n bool first = true;\n int lastItem = 0;\n foreach (var item in dic.Values)\n {\n if (first)\n {\n first = false;\n }\n else\n {\n if (lastItem != item - 1)\n {\n Console.WriteLine(\"Test Failed !\");\n break;\n }\n\n }\n lastItem = item;\n }\n Console.WriteLine(\"Done.\");\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18107/"
] |
258,211
|
<pre><code>#!/bin/bash
hello()
{
SRC=$1
DEST=$2
for IP in `cat /opt/ankit/configs/machine.configs` ; do
echo $SRC | grep '*' > /dev/null
if test `echo $?` -eq 0 ; then
for STAR in $SRC ; do
echo -en "$IP"
echo -en "\n\t ARG1=$STAR ARG2=$2\n\n"
done
else
echo -en "$IP"
echo -en "\n\t ARG1=$SRC ARG2=$DEST\n\n"
fi
done
}
hello $1 $2
</code></pre>
<p>The above is the shell script which I provide source (SRC) & desitnation (DEST) path. It worked fine when I did not put in a SRC path with wild card '<em>'. When I run this shell script and give '</em>'.pdf or '*'as follows:</p>
<pre><code>root@ankit1:~/as_prac# ./test.sh /home/dev/Examples/*.pdf /ankit_test/as
</code></pre>
<p>I get the following output:</p>
<pre><code>192.168.1.6
ARG1=/home/dev/Examples/case_Contact.pdf ARG2=/home/dev/Examples/case_howard_county_library.pdf
</code></pre>
<p>The DEST is /ankit_test/as but DEST also get manupulated due to '*'. The expected answer is </p>
<pre><code>ARG1=/home/dev/Examples/case_Contact.pdf ARG2=/ankit_test/as
</code></pre>
<p>So, if you understand what I am trying to do, please help me out to solve this BUG.
I'll be grateful to you.</p>
<p>Thanks in advance!!!</p>
<p>I need to know exactly how I use '*.pdf' in my program one by one without disturbing DEST.</p>
|
[
{
"answer_id": 258232,
"author": "agnul",
"author_id": 6069,
"author_profile": "https://Stackoverflow.com/users/6069",
"pm_score": 2,
"selected": false,
"text": "$ ls\none.pdf two.pdf three.pdf\n ./test.sh *.pdf /ankit__test/as\n ./test.sh one.pdf two.pdf three.pdf /ankit__test/as\n ./test.sh \\*.pdf /ankit__test/as\n"
},
{
"answer_id": 258252,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 0,
"selected": false,
"text": "$? if [ $? -eq 0 ]; then\n"
},
{
"answer_id": 258298,
"author": "dogbane",
"author_id": 7412,
"author_profile": "https://Stackoverflow.com/users/7412",
"pm_score": 2,
"selected": false,
"text": "ARG1=/home/dev/Examples/*.pdf ARG2=/ankit__test/as\n for IP in `cat /opt/ankit/configs/machine.configs`\ndo\n for i in $SRC\n do\n echo -en \"$IP\"\n echo -en \"\\n\\t ARG1=$i ARG2=$DEST\\n\\n\"\n done\ndone\n root@ankit1:~/as_prac# ./test.sh \"/home/dev/Examples/*.pdf\" /ankit__test/as\n"
},
{
"answer_id": 258309,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 1,
"selected": false,
"text": "#!/bin/bash\n\nhello() {\n\n SRC=$1\n DEST=$2\n\n while read IP ; do\n for FILE in $SRC; do\n echo -e \"$IP\"\n echo -e \"\\tARG1=$FILE ARG2=$DEST\\n\"\n done\n done < /tmp/machine.configs\n }\n\n hello \"$1\" $2\n hello $1 $SRC"
},
{
"answer_id": 258330,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 2,
"selected": false,
"text": "./test.sh /ankit_test/as /home/dev/Examples/*.pdf\n #!/bin/bash\nhello()\n{\n SRC=$1\n DEST=$2\n\n for IP in `cat /opt/ankit/configs/machine.configs` ; do\n echo -en \"$IP\"\n echo -en \"\\n\\t ARG1=$SRC ARG2=$DEST\\n\\n\"\n done\n}\n\narg2=$1\nshift\nwhile [[ \"$1\" != \"\" ]] ; do\n hello $1 $arg2\n shift\ndone\n"
},
{
"answer_id": 266187,
"author": "godbyk",
"author_id": 4214,
"author_profile": "https://Stackoverflow.com/users/4214",
"pm_score": 1,
"selected": false,
"text": "#!/bin/bash\n\nhello()\n{\n # DEST will contain the last argument\n eval DEST=\\$$#\n\n while [ $1 != $DEST ]; do\n SRC=$1\n\n for IP in `cat /opt/ankit/configs/machine.configs`; do\n echo -en \"$IP\"\n echo -en \"\\n\\t ARG1=$SRC ARG2=$DEST\\n\\n\"\n done\n\n shift || break\n done\n}\n\nhello $*\n"
},
{
"answer_id": 10163215,
"author": "dannysauer",
"author_id": 65589,
"author_profile": "https://Stackoverflow.com/users/65589",
"pm_score": 0,
"selected": false,
"text": "./test.sh /home/dev/Examples/*.pdf /ankit_test/as \n ./test.sh \"/home/dev/Examples/*.pdf\" /ankit_test/as\n echo $SRC echo \"$SRC\""
},
{
"answer_id": 11780892,
"author": "Mike L",
"author_id": 1239140,
"author_profile": "https://Stackoverflow.com/users/1239140",
"pm_score": 1,
"selected": false,
"text": "file1.txt file2.txt file3.txt\n $ ./script.sh *.txt\n $ ./script.sh file{1..3}.txt\n #!/bin/bash\n\n# store default IFS, we need to temporarily change this\nsfi=$IFS\n\n#set IFS to $'\\n\\' - new line\nIFS=$'\\n'\n\nif [[ -z $@ ]]\n then\n echo \"Error: Missing required argument\"\n echo\n exit 1\nfi\n\n# Put the file glob into an array\nfile=(\"$@\")\n\n# Now loop through them\nfor (( i=0 ; i < ${#file[*]} ; i++ ));\ndo\n\n if [ -w ${file[$i]} ]; then\n echo ${file[$i]} \" writable\" \n else\n echo ${file[$i]} \" NOT writable\"\n fi\ndone\n\n# Reset IFS to its default value\nIFS=$sfi\n file1.txt writable\nfile2.txt writable\nfile3.txt writable\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24813/"
] |
258,214
|
<p>Since version 1.5 Subversion supports to have a local caching-proxy for the main Master-repository. </p>
<p>I got the slave synced and the master replaying the commits to the slave.
Everything works fine so far, but now I am wondering how to do the authentication (working with <a href="http://blogs.open.collab.net/svn/2007/10/yesterday-at-th.html" rel="noreferrer">this</a> guide).</p>
<p>When both, the master and the slave, have authentication set, the slave asks for username/password on reads, but both ask on writes.</p>
<p>What is the way to also get authentication transparent to the user of the slave (meaning requiring only 1 authentication independent if it is read or write)?</p>
<p>I am testing with:</p>
<ul>
<li>Apache/2.2.3, Subversion 1.4.2 on the slave (Debian)</li>
<li>Apache/2.2.8, Subversion 1.5.1 (Ubuntu)</li>
</ul>
|
[
{
"answer_id": 264113,
"author": "Morgan Christiansson",
"author_id": 34516,
"author_profile": "https://Stackoverflow.com/users/34516",
"pm_score": 1,
"selected": false,
"text": "Require valid-user"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20319/"
] |
258,218
|
<p>In MSBuild, I would like to call a task that extracts all the files in all the project in a specific solution and hold these files in a property that can be passed around to other tasks (for processing etc.)</p>
<p>I was thinking something along the lines of:</p>
<pre><code><ParseSolutionFile SolutionFile="$(TheSolutionFile)">
<Output TaskParameter="FilesFound" ItemName="AllFilesInSolution"/>
</ParseSolutionFile>
<Message Text="Found $(AllFilesInSolution)" />
</code></pre>
<p>which would output the list of all files in the projects in the solution and I could use the AllFilesInSolution property as input to other analysis tasks. Is this an already existing task or do I need to build it myself? If I need to build it myself, should the task output an array of strings or of ITaskItems or something else?</p>
|
[
{
"answer_id": 261037,
"author": "sliderhouserules",
"author_id": 31385,
"author_profile": "https://Stackoverflow.com/users/31385",
"pm_score": 2,
"selected": false,
"text": "<ItemGroup>\n <Content Include=\"Default.aspx\" />\n <Content Include=\"Web.config\" />\n</ItemGroup>\n<ItemGroup>\n <Compile Include=\"Default.aspx.cs\">\n <SubType>ASPXCodeBehind</SubType>\n <DependentUpon>Default.aspx</DependentUpon>\n </Compile>\n <Compile Include=\"Default.aspx.designer.cs\">\n <DependentUpon>Default.aspx</DependentUpon>\n </Compile>\n</ItemGroup>\n<ItemGroup>\n <Folder Include=\"App_Data\\\" />\n</ItemGroup>\n <CreateItem Include=\"@(Content)\" Condition=\"'%(Extension)' == '.aspx'\">\n <Output TaskParameter=\"Include\" ItemName=\"ViewsContent\" />\n</CreateItem>\n <CreateItem Include=\"$(OutputPath)\\**\\*\">\n <Output TaskParameter=\"Include\" ItemName=\"OutputFiles\" />\n</CreateItem>\n"
},
{
"answer_id": 22701810,
"author": "BozoJoe",
"author_id": 38461,
"author_profile": "https://Stackoverflow.com/users/38461",
"pm_score": 0,
"selected": false,
"text": "<Target Name=\"CopyArtifactstoDropLocation\">\n <CreateItem Include=\"$(SolutionRoot)\\**\\*.*\">\n <Output TaskParameter=\"Include\" ItemName=\"YourFilesToCopy\" />\n </CreateItem>\n\n <Copy\n SourceFiles=\"@(YourFilesToCopy)\"\n DestinationFiles=\"@(YourFilesToCopy->'$(DropLocation)\\$(BuildNumber)\\Release\\%(RecursiveDir)%(Filename)%(Extension)')\" />\n</Target>\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9222/"
] |
258,228
|
<p>I have been bitten by something unexpected recently. I wanted to make something like that:</p>
<pre><code>try :
thing.merge(iterable) # this is an iterable so I add it to the list
except TypeError :
thing.append(iterable) # this is not iterable, so I add it
</code></pre>
<p>Well, It was working fine until I passed an object inheriting from Exception which was supposed to be added.</p>
<p>Unfortunetly, an Exception is iterable. The following code does not raise any <code>TypeError</code>:</p>
<pre><code>for x in Exception() :
print 1
</code></pre>
<p>Does anybody know why?</p>
|
[
{
"answer_id": 258234,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 2,
"selected": false,
"text": "for x in Exception(\"test\") :\n print x\n ....: \n ....: \ntest\n raise Exception(\"test\") \n\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nException: test\n print Exception(\"test\") \ntest\n for x in Exception(\"test\") :\n print x\n for x in Exception() :\n print x\n try :\n thing.merge(ExceptionLikeObject)\nexcept TypeError :\n ...\n"
},
{
"answer_id": 258930,
"author": "Brian",
"author_id": 9493,
"author_profile": "https://Stackoverflow.com/users/9493",
"pm_score": 5,
"selected": true,
"text": "Exception ___getitem__ ex.args try:\n raise \"something failed\", (42, \"some other details\")\nexcept \"something failed\", args:\n errCode, msg = args\n print \"something failed. error code %d: %s\" % (errCode, msg)\n IOError >>> list(Exception(\"test\"))\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nTypeError: 'Exception' object is not iterable\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9951/"
] |
258,231
|
<p>I have a Table called <em>Product</em> and I have the Table <em>StorageHistory</em>.</p>
<p>Now, Product contains a reference to StorageHistory in it's mappings</p>
<pre><code><set name="StorageHistories" lazy="false">
<key column="ProductId" />
<one-to-many class="StorageHistory" />
</set>
</code></pre>
<p>And it works, when I retrieve an object from the ORM I get an empty ISet.</p>
<p>What gives me a headache is how to construct the object in the first place.
When I do the following:</p>
<pre><code>var product = new Product();
session.Save(product);
</code></pre>
<p>the product.StorageHistories property is NULL and I get a NullReferenceException.
So, how do I add items to that collection, or should I go the way to add the StorageHistory items themselves to the DB?</p>
|
[
{
"answer_id": 269847,
"author": "Min",
"author_id": 14461,
"author_profile": "https://Stackoverflow.com/users/14461",
"pm_score": 0,
"selected": false,
"text": "private ISet _StorageHistories;\npublic virtual ISet StorageHistories {\n protected set { _StorageHistories = value;}\n get { if (_StorageHistories == null) _StorageHistories = new HashSet();\n return _StorageHistories;\n }\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258231",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21699/"
] |
258,251
|
<p>How do I apply 'use base' in Perl to inherit subs from some base module?</p>
<p>I'm used to C++ inheritance mechanics, and all the sites I googled for this caused more confusion then help. I want to do something like the following:</p>
<pre><code>#! /usr/bin/perl
#The base class to inherit from
use strict;
use warnings;
package 'TestBase';
#-------------------------------
sub tbSub
{
my ($self, $parm) = @_;
print "\nTestBase: $parm\n";
}
1;
</code></pre>
<p>.</p>
<pre><code>#! /usr/bin/perl
#The descendent class
use strict;
use warnings;
use base qw(TestBase);
sub main;
sub mySub;
#-------------------------------
#Entry point...
main();
#---code------------------------
sub main
{
mySub(1);
tbSub(2);
mySub(3);
}
#-------------------------------
sub mySub
{
my $parm = shift;
print "\nTester: $parm\n";
}
</code></pre>
<p>Perl complains/cannot find tbSub. </p>
|
[
{
"answer_id": 258308,
"author": "tsee",
"author_id": 13164,
"author_profile": "https://Stackoverflow.com/users/13164",
"pm_score": 2,
"selected": false,
"text": "main->tbSub(2);\n package Derived;\nuse base \"TestBase\";\n\npackage main;\nDerived->somemethod(\"foo\");\n Class->somemethod(\"foo\")\n Class::somemethod(\"Class\", \"foo\")\n"
},
{
"answer_id": 258315,
"author": "innaM",
"author_id": 7498,
"author_profile": "https://Stackoverflow.com/users/7498",
"pm_score": 6,
"selected": true,
"text": "my $foo = TestDescendent->new();\n$foo->main();\n\n\npackage TestBase;\n\nsub new {\n my $class = shift;\n return bless {}, $class;\n}\n\nsub tbSub\n{\n my ($self, $parm) = @_;\n print \"\\nTestBase: $parm\\n\";\n}\n\npackage TestDescendent;\nuse base 'TestBase';\n\nsub main {\n my $self = shift;\n $self->mySub( 1 );\n $self->tbSub( 2 );\n $self->mySub( 3 );\n}\n\nsub mySub\n{\n my $self = shift;\n my $parm = shift;\n print \"\\nTester: $parm\\n\";\n}\n\n1;\n"
},
{
"answer_id": 258320,
"author": "lexu",
"author_id": 31472,
"author_profile": "https://Stackoverflow.com/users/31472",
"pm_score": 3,
"selected": false,
"text": "#! /usr/bin/perl\n#The module to inherit from\n\npackage TestBase;\n use strict;\n use warnings;\n\n use Exporter ();\n our @ISA = qw (Exporter);\n our @EXPORT = qw (tbSub);\n\n#-------------------------------\nsub tbSub\n{\n my ($parm) = @_;\n print \"\\nTestBase: $parm\\n\";\n}\n\n1;\n #! /usr/bin/perl\n#The descendent class\nuse strict;\nuse warnings;\n\nuse TestBase; \nsub main;\nsub mySub;\n\n#-------------------------------\n#Entry point...\nmain();\n\n#---code------------------------\nsub main\n{\n\n mySub(1);\n tbSub(2);\n mySub(3);\n}\n\n#-------------------------------\nsub mySub\n{\n my $parm = shift;\n print \"\\nTester: $parm\\n\";\n}\n #! /usr/bin/perl\n#The base class to inherit from\n\npackage TestBase;\n use strict;\n use warnings;\n\n#-------------------------------\nsub new { my $s={ };\n return bless $s;\n}\nsub tbSub\n{\n my ($self,$parm) = @_;\n print \"\\nTestBase: $parm\\n\";\n}\n\n1;\n #! /usr/bin/perl\n#The descendent class\nuse strict;\nuse warnings;\n\nuse TestBase; \nsub main;\nsub mySub;\n\n#-------------------------------\n#Entry point...\nmain();\n\n#---code------------------------\nsub main\n{\n my $tb = TestBase->new();\n mySub(1);\n $tb->tbSub(2);\n mySub(3);\n}\n\n#-------------------------------\nsub mySub\n{\n my $parm = shift;\n print \"\\nTester: $parm\\n\";\n}\n"
},
{
"answer_id": 258439,
"author": "Aristotle Pagaltzis",
"author_id": 9410,
"author_profile": "https://Stackoverflow.com/users/9410",
"pm_score": 3,
"selected": false,
"text": "use base use parent"
},
{
"answer_id": 259325,
"author": "draegtun",
"author_id": 12195,
"author_profile": "https://Stackoverflow.com/users/12195",
"pm_score": 3,
"selected": false,
"text": "package TestBase;\nuse Moose;\n\nsub tbSub {\n my ($self, $parm) = @_;\n print \"\\nTestBase: $parm\\n\";\n}\n\n\npackage TestDescendent;\nuse Moose;\nextends 'TestBase';\n\nsub main {\n my $self = shift;\n $self->mySub( 1 );\n $self->tbSub( 2 );\n $self->mySub( 3 );\n}\n\nsub mySub {\n my ($self, $parm) = @_;\n print \"\\nTester: $parm\\n\";\n}\n\n\npackage main;\nmy $foo = TestDescendent->new();\n$foo->main\n"
},
{
"answer_id": 259993,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 1,
"selected": false,
"text": "-> You->do_something( @params );\n\nOR \n\n$you->do_something( @params );\n\npackage A;\n\nsub do_neat_thing { \n my ( $class_or_instance, @args ) = @_;\n my $class = ref( $class_or_instance );\n if ( $class ) {\n say \"Instance of '$class' does a neat thing.\";\n }\n else { \n say \"$class_or_instance does a neat thing.\";\n }\n}\n\n...\npackage main;\nA->do_neat_thing(); # A does a neat thing.\nmy $a_obj = A->new();\n$a_obj->do_neat_thing(); # Instance of 'A' does a neat thing.\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15161/"
] |
258,264
|
<p>Is there any way of using Memcached for fragment caching in Rails?</p>
|
[
{
"answer_id": 259239,
"author": "TonyLa",
"author_id": 1295,
"author_profile": "https://Stackoverflow.com/users/1295",
"pm_score": 3,
"selected": true,
"text": " ActionController::Base.cache_store = ActiveSupport::Cache::MemCacheStore.new()\n"
},
{
"answer_id": 1034898,
"author": "Brian Armstrong",
"author_id": 76486,
"author_profile": "https://Stackoverflow.com/users/76486",
"pm_score": 3,
"selected": false,
"text": "config.action_controller.perform_caching = true\nconfig.cache_classes = true\nconfig.cache_store = :mem_cache_store\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12037/"
] |
258,273
|
<p>Heres the link:</p>
<p><a href="http://tinyurl.com/596xva" rel="nofollow noreferrer">DAMNIE6TOHELL</a></p>
<p>As you can see if viewed in glorious 'IE6-o-color', the footer is shifting 1px over to the left.
I'm struggling to find a fix for this, I've whittled it down to a bare minimum of HTML.</p>
<p>Is it something to do with haslayout perhaps? Any help much appreciated.</p>
|
[
{
"answer_id": 258293,
"author": "yoavf",
"author_id": 1011,
"author_profile": "https://Stackoverflow.com/users/1011",
"pm_score": 2,
"selected": true,
"text": "background-position: 50% top;\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26107/"
] |
258,275
|
<p>I'm trying to run a command-line process (which is extraction of a .7z archive) on a file that lies in a temporary folder on the windows user temp directory
(C:\Documents and Settings\User\Local Settings\Temp), using Process in my c# app.</p>
<p>I think the process return error that happens because of "access denied" because I can see a win32Exception with error code 5 when I dig in the prcoess object of .NET.</p>
<p>doing the same on some other location worked fine before, so I guess maybe it's something I'm not supposed to do ? (running a process to use a file on the the %TEMP%)
perhaps I need to pass security somehow?</p>
|
[
{
"answer_id": 258276,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 1,
"selected": false,
"text": "Path.GetTempFileName() string dir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30324/"
] |
258,284
|
<p>In either a Windows or Mac OS X terminal if you type...</p>
<pre><code>nslookup -type=SRV _xmpp-server._tcp.gmail.com
</code></pre>
<p>... (for example) you will receive a bunch of SRV records relating to different google chat servers..</p>
<p>Does anyone have any experience in this area and possibly know how to service this information (hostname, port, weight, priority) using the iPhone SDK? I have experimented with the Bonjour classes, but as yet have had no luck..</p>
<p>Thanks!</p>
|
[
{
"answer_id": 258413,
"author": "Alex Reynolds",
"author_id": 19410,
"author_profile": "https://Stackoverflow.com/users/19410",
"pm_score": 0,
"selected": false,
"text": "system() NSTask NSTask Foundation dig"
},
{
"answer_id": 258799,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 5,
"selected": true,
"text": "#include <dns_sd.h>\n\nint main(int argc, char *argv[])\n{\n DNSServiceRef sdRef;\n DNSServiceErrorType res;\n\n DNSServiceQueryRecord(\n &sdRef, 0, 0,\n \"_xmpp-server._tcp.gmail.com\",\n kDNSServiceType_SRV,\n kDNSServiceClass_IN,\n callback,\n NULL\n );\n\n DNSServiceProcessResult(sdRef);\n DNSServiceRefDeallocate(sdRef);\n}\n rdata"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33604/"
] |
258,285
|
<p>I'm working through some homework and a question on a previous exam paper asks to name all of the abstract classes in a given UML diagram. Fairly straightforward, I suppose. There are one abstract class and three interfaces. Do these interfaces qualify as abstract classes, in general?</p>
|
[
{
"answer_id": 258289,
"author": "Ande Turner",
"author_id": 4857,
"author_profile": "https://Stackoverflow.com/users/4857",
"pm_score": 1,
"selected": false,
"text": ".class .java abstract class"
},
{
"answer_id": 258294,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 3,
"selected": false,
"text": "Object a = new Date();\nString s = a.toString();\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13877/"
] |
258,291
|
<p>In a visual studio project I have three layers, Data Layer, Business Layer and Presentation Layer. </p>
<p>In the Data Layer I have a few XSLT's that transform some objects into an email, all works fine but I have discovered that the XSLTs do not get built/copied when building. </p>
<p>I have currently, created a folder in the deploy location and placed the XSLT's there but I am concerned about relying on a manual process to update these. </p>
<p>Has anyone encountered a similar issue and if so how did they get around it. </p>
<p>It smacks of changing the MSBuild script to copy the build artifacts to the required location, does anyone have examples of this?</p>
<p>Thaks </p>
|
[
{
"answer_id": 258854,
"author": "jon without an h",
"author_id": 27578,
"author_profile": "https://Stackoverflow.com/users/27578",
"pm_score": 3,
"selected": true,
"text": "// To get the contents of the resource as a string:\nstring xslt = global::MyNamespace.Properties.Resources.MyXsltFile;\n// To get a Stream containing the resource:\nStream xsltStream = global::MyNamespace.Properties.Resources.ResourceManager.GetStream(\"MyXsltFile\");\n // There are numerous ways to get a reference to the Assembly ... this way works\n// when called from a class that is in your data layer. Have a look also at the\n// static methods available on the Assembly class.\nSystem.Reflection.Assembly assembly = (GetType()).Assembly;\nSystem.IO.Stream xsltStream = assembly.GetManifestResourceStream(\"My.DataLayer.Templates.Transform.xslt\");\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258291",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11802/"
] |
258,292
|
<p>Currently, I have a UIView subclass that "stamps" a single 2px by 2px CGLayerRef across the screen, up to 160 x 240 times.</p>
<p>I currently animate this by moving the UIView "up" the screen 2 pixels (actually, a UIImageView) and then drawing the next "row".</p>
<p>Would using multiple CALayer layers speed up performance of rendering this animation?</p>
<p>Are there tutorials, sample applications or code snippets for use of CALayer with the iPhone SDK? </p>
<p>The reason I ask is that most of the code snippets I find that demonstrate simple examples of CALayer employ method calls that do not work with the iPhone SDK. I appreciate any advice or pointers.</p>
|
[
{
"answer_id": 258445,
"author": "Alex Reynolds",
"author_id": 19410,
"author_profile": "https://Stackoverflow.com/users/19410",
"pm_score": 1,
"selected": false,
"text": "CAConstraintLayoutManager CAConstraint QuartzCore.h CALayer UIView UIView drawRect drawRect CGLayerRef CGLayerRef UIImageView CALayer CALayer"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19410/"
] |
258,296
|
<p>I have a models <code>A</code> and <code>B</code>, that are like this:</p>
<pre><code>class A(models.Model):
title = models.CharField(max_length=20)
(...)
class B(models.Model):
date = models.DateTimeField(auto_now_add=True)
(...)
a = models.ForeignKey(A)
</code></pre>
<p>Now I have some <code>A</code> and <code>B</code> objects, and I'd like to get a query that selects all <code>A</code> objects that have less then 2 <code>B</code> pointing at them.</p>
<p>A is something like a pool thing, and users (the B) join pool. if there's only 1 or 0 joined, the pool shouldn't be displayed at all.</p>
<p>Is it possible with such model design? Or should I modify that a bit?</p>
|
[
{
"answer_id": 258310,
"author": "Jonny Buchanan",
"author_id": 6760,
"author_profile": "https://Stackoverflow.com/users/6760",
"pm_score": 4,
"selected": true,
"text": "extra A.objects.extra(\n select={\n 'b_count': 'SELECT COUNT(*) FROM yourapp_b WHERE yourapp_b.a_id = yourapp_a.id',\n },\n where=['b_count < 2']\n)\n from django.db import connection, transaction\nfrom django.db.models.signals import post_delete, post_save\n\ndef update_b_count(instance, **kwargs):\n \"\"\"\n Updates the B count for the A related to the given B.\n \"\"\"\n if not kwargs.get('created', True) or kwargs.get('raw', False):\n return\n cursor = connection.cursor()\n cursor.execute(\n 'UPDATE yourapp_a SET b_count = ('\n 'SELECT COUNT(*) FROM yourapp_b '\n 'WHERE yourapp_b.a_id = yourapp_a.id'\n ') '\n 'WHERE id = %s', [instance.a_id])\n transaction.commit_unless_managed()\n\npost_save.connect(update_b_count, sender=B)\npost_delete.connect(update_b_count, sender=B)\n B.objects.create(a=some_a)\nif some_a.hidden and some_a.b_set.count() > 1:\n A.objects.filter(id=some_a.id).update(hidden=False)\n\n...\n\nsome_a = b.a\nsome_b.delete()\nif not some_a.hidden and some_a.b_set.count() < 2:\n A.objects.filter(id=some_a.id).update(hidden=True)\n"
},
{
"answer_id": 258329,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 2,
"selected": false,
"text": "[ a for a in A.objects.all() if a.b_set.count() < 2 ]\n A class A( models.Model ):\n ....\n def addB( self, b ):\n self.b_set.add( b )\n self.changeFlags()\n def removeB( self, b ):\n self.b_set.remove( b )\n self.changeFlags()\n def changeFlags( self ):\n if self.b_set.count() < 2: self.show= NotYet\n else: self.show= ShowNow\n Manager b_set A"
},
{
"answer_id": 6205303,
"author": "gravitron",
"author_id": 456506,
"author_profile": "https://Stackoverflow.com/users/456506",
"pm_score": 7,
"selected": false,
"text": "from django.db.models import Count\ncats = A.objects.annotate(num_b=Count('b')).filter(num_b__lt=2)\n A.objects.filter(B__is_available=True).annotate(num_b=Count('b')).filter(num_b__gt=0).order_by('-num_items')\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4172/"
] |
258,317
|
<p>I have the following snippet in one of my html pages :</p>
<pre><code><div class="inputboximage">
<div class="value2">
<input name='address1' value='Somewhere' type="text" size="26" maxlength="40" />
<br />
</div>
</div>
</code></pre>
<p>My problem is that I need the <code>inputboximage background</code> to change when I click in the <code>address1</code> text field and to revert to the original when it loses focus.</p>
<p>I have used the following :</p>
<pre><code> <script>
$(document).ready(function(){
$("input").focus(function () {
$(this.parentNode).css('background-image', 'url(images/curvedinputblue.gif)');
});
$("input").blur(function () {
$(this.parentNode).css('background-image', 'url(images/curvedinput.gif)');
});
});
</script>
</code></pre>
<p>but instead of replacing the image, it seems to be adding a background image to the value2 div as you would expect. I can use <code>parentNode.parentNode</code> in this case, but there is also a chance that the <code>inputboxImage</code> node could be further up or down the parent tree.</p>
<p>Is there a way I can change this code so that it will navigate down the parent tree until it finds a div called <code>inputboximage</code> and replace the image there?</p>
<p>Also, if I have two different div classes, <code>inputboximage</code> and <code>inputboximageLarge</code>, is there a way to modify this function so that it will work with both, replacing the background image with a different image for each one?</p>
|
[
{
"answer_id": 258319,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "$(this).parents('div.inputBoxImage').css(...)\n $(this.parentNode)"
},
{
"answer_id": 258341,
"author": "Prody",
"author_id": 21240,
"author_profile": "https://Stackoverflow.com/users/21240",
"pm_score": 2,
"selected": false,
"text": "parents"
},
{
"answer_id": 258358,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 0,
"selected": false,
"text": "<div class=\"inputboximage\" id=\"inputboximage\">\n <div class=\"value2\">\n <input name='address1' value='5 The Laurels' type=\"text\" size=\"26\" maxlength=\"40\" />\n <br />\n\n </div>\n</div>\n\n<script>\n $(document).ready(function(){\n\n $(\"input\").focus(function () {\n $('#inputboximage').css('background-image', 'url(images/curvedinputblue.gif)');\n });\n\n\n });\n</script>\n $(\"input\").focus(function () {\n $(this).parents('div.inputboximage').css('background-image', 'url(images/curvedinputblue.gif)');\n });\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24079/"
] |
258,339
|
<p>I have a GUI application that executes (in a new process) "console" applications and parse the output. To redirect the Output i set the pConsole.StartInfo.RedirectStandardOutput to true. I also subscribes to the event pConsole.Exited.</p>
<p>The problem I see is that I have to use Thread.Sleep() in the Exited event handler to get the last data.</p>
<p>My Exited event handler looks like this:</p>
<pre><code>Thread.Sleep(100); // Wait for additional data (if any).
pConsole.OutputDataReceived -= new System.Diagnostics.DataReceivedEventHandler(this.localTerminal_DataAvailableEvent);
int exit = pConsole.ExitCode;
pConsole.Dispose();
pConsole = null;
</code></pre>
<p>It seems that the Exited event executes before my last pConsole_DataAvailableEvent. Anyone knows how/why this is happening?</p>
<p>I also use a mutex/lock to make sure my Exited event is finished before I start execute my next console application.</p>
|
[
{
"answer_id": 258387,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "Join() using (Process proc = Process.Start(psi))\n {\n Thread stdErr = new Thread(DumpStream(proc.StandardError, Console.Error));\n Thread stdOut = new Thread(DumpStream(proc.StandardOutput, Console.Out));\n stdErr.Name = \"stderr reader\";\n stdOut.Name = \"stdout reader\";\n stdErr.Start();\n stdOut.Start();\n proc.WaitForExit();\n stdOut.Join();\n stdErr.Join();\n if (proc.ExitCode != 0) {...} // etc\n }\n\n static ThreadStart DumpStream(TextReader reader, TextWriter writer)\n {\n return (ThreadStart) delegate\n {\n string line;\n while ((line = reader.ReadLine()) != null) writer.WriteLine(line);\n };\n }\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258339",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
258,344
|
<p>Is it possible to define a spring-managed EJB3 hibernate listener?</p>
<p>I have this definition in my <strong>persistence.xml</strong>:</p>
<pre><code><properties>
<property name="hibernate.ejb.interceptor"
value="my.class.HibernateAuditInterceptor" />
<property name="hibernate.ejb.event.post-update"
value="my.class.HibernateAuditTrailEventListener" />
</properties>
</code></pre>
<p>But I would like to manage <code>HibernateAuditInterceptor</code> and <code>HibernateAuditTrailEventListener</code> with spring, so I can do some bean injection (ex: session-scoped bean) within these classes. Is this possible?</p>
|
[
{
"answer_id": 262992,
"author": "Chochos",
"author_id": 10165,
"author_profile": "https://Stackoverflow.com/users/10165",
"pm_score": 1,
"selected": true,
"text": "<bean id=\"mySessionFactory\" class=\"org.springframework.orm.hibernate3.LocalSessionFactoryBean\">\n <property name=\"dataSource\"ref=\"myDataSource\"/>\n <property name=\"mappingResources\">\n <list>\n <value>whatever.hbm.xml</value>\n </list>\n </property>\n <property name=\"hibernateProperties\">\n <value>\n hibernate.ejb.interceptor= my.class.HibernateAuditInterceptor\n </value>\n <value>\n hibernate.ejb.event.post-update=my.class.HibernateAuditTrailEventListener\n </value>\n </property>\n</bean>\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22992/"
] |
258,355
|
<p>I'm trying to find a way to automate some exception logging code to add to the stack information already available.</p>
<p>Is there any way to use reflection to retrieve the values of all variables on the stack (locals and parameters) - I sincerely doubt the names of the variables are available, but in many cases it would be useful to see the values.</p>
|
[
{
"answer_id": 258373,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 3,
"selected": true,
"text": " string dir = ...todo...\n try\n {\n // some code\n }\n catch (Exception ex)\n {\n ex.Data.Add(\"dir\", dir);\n throw;\n }\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5777/"
] |
258,365
|
<p>Here is the directory structure</p>
<pre><code>/domain.com
/public_html
/functions
/image
/mobile
/www
</code></pre>
<p>the /domain.com/public_html/www folder has a file index.php
the default web directory is /user/public_html/www
in the index file is an include that includes the functions with
include"../functions/function.inc"
this works without problem
when I want to link to a picture in the image folder I don't get any results
for example </p>
<pre><code><img src="../image/graphic/logo.gif" alt="alt text"/>
</code></pre>
<p>Does anybody has any idea why the link to the image does not work and how to link correctly to the image file ?</p>
<p>I tried <code><img src="<?php echo $_SERVER['PHP_SELF']; ?>../image/graphic/logo.gif" alt="alt text"/></code></p>
<p>but that gives me the same result
when I build a link around the image to get to the properties I get this as path
<a href="http://domain.com/image/pc/tattoo_small/small_2008_10_22_001.JPG" rel="noreferrer">http://domain.com/image/pc/tattoo_small/small_2008_10_22_001.JPG</a>
the path should be
<a href="http://domain.com/public_html/image/pc/tattoo_small/small_2008_10_22_001.JPG" rel="noreferrer">http://domain.com/public_html/image/pc/tattoo_small/small_2008_10_22_001.JPG</a>
when I try to browse directly to this url
<a href="http://domain.com/public_html/image/pc/tattoo_small/small_2008_10_22_001.JPG" rel="noreferrer">http://domain.com/public_html/image/pc/tattoo_small/small_2008_10_22_001.JPG</a>
I get an 404 file not found error
because the default web directory is
/domain.com/public_html/www
I tried
<a href="http://domain.com/../image/pc/tattoo_small/small_2008_10_22_001.JPG" rel="noreferrer">http://domain.com/../image/pc/tattoo_small/small_2008_10_22_001.JPG</a>
to get to the image folder but that does not help neither.</p>
<p>Anybody any ideas or is it impossible to html link to graphical files outside the default web directory ?</p>
<p>thanks for reading this far</p>
<p>Thanks for the answers so far.
I will try to solve my problem with one of the recommended solutions and report my working solution back here.
I wanted to have the image folder at the same level as the www and mobile folder because some of the images used for the pc (www) version and the mobile version are the same.
Of course it is easier to just get an image folder in the www and in the mobile folder and I think that is what I am going to do.</p>
<p>thank you everybody for the advice. The main reason why I am not going to work with a script is that a script will be a difficult solution to an easy problem and also because I don't really see how you can wrap your image in a css class and how to provide alt text for an image.</p>
|
[
{
"answer_id": 258371,
"author": "Gareth",
"author_id": 31582,
"author_profile": "https://Stackoverflow.com/users/31582",
"pm_score": 1,
"selected": false,
"text": "<img src=\"my_php_proxy.php\">\n"
},
{
"answer_id": 258380,
"author": "Aron Rotteveel",
"author_id": 11568,
"author_profile": "https://Stackoverflow.com/users/11568",
"pm_score": 5,
"selected": false,
"text": "/image.php?file=myfile.jpg\n <?php\n\n $file = basename(urldecode($_GET['file']));\n $fileDir = '/path/to/files/';\n\n if (file_exists($fileDir . $file))\n {\n // Note: You should probably do some more checks \n // on the filetype, size, etc.\n $contents = file_get_contents($fileDir . $file);\n\n // Note: You should probably implement some kind \n // of check on filetype\n header('Content-type: image/jpeg');\n\n echo $contents;\n }\n\n?>\n"
},
{
"answer_id": 258460,
"author": "ZombieSheep",
"author_id": 377,
"author_profile": "https://Stackoverflow.com/users/377",
"pm_score": 4,
"selected": false,
"text": "<IfModule mod_alias.c>\n\n Alias /images/ \"/User/Public_html/Image/\"\n\n <Directory \"/User/Public_html/Image\">\n Options Indexes MultiViews\n AllowOverride None\n Order allow,deny\n Allow from all\n </Directory>\n\n</IfModule>\n"
},
{
"answer_id": 292773,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 3,
"selected": false,
"text": "cd public_html\nln -s ../images\n Options +FollowSymlinks .htaccess"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258365",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18383/"
] |
258,367
|
<p>looking for the standard bug-proofed way to convert "long names" such as "C:\Documents and settings" to their equivalent "short names" "C:\DOCUME~1"</p>
<p>I need this to run an external process from withing my C# app. It fails if I feed it with paths in the "long name".</p>
|
[
{
"answer_id": 258382,
"author": "David Arno",
"author_id": 7122,
"author_profile": "https://Stackoverflow.com/users/7122",
"pm_score": 5,
"selected": false,
"text": " const int MAX_PATH = 255;\n\n [DllImport(\"kernel32.dll\", CharSet = CharSet.Auto)]\n public static extern int GetShortPathName(\n [MarshalAs(UnmanagedType.LPTStr)]\n string path,\n [MarshalAs(UnmanagedType.LPTStr)]\n StringBuilder shortPath,\n int shortPathLength\n );\n\n private static string GetShortPath(string path) {\n var shortPath = new StringBuilder(MAX_PATH);\n GetShortPathName(path, shortPath, MAX_PATH);\n return shortPath.ToString();\n }\n"
},
{
"answer_id": 258441,
"author": "ZombieSheep",
"author_id": 377,
"author_profile": "https://Stackoverflow.com/users/377",
"pm_score": 3,
"selected": true,
"text": "myExternalApp \"C:\\Documents And Settings\\myUser\\SomeData.file\"\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258367",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30324/"
] |
258,372
|
<p>I have a div container and have defined its style as follows:</p>
<pre><code>div#tbl-container
{
width: 600px;
overflow: auto;
scrollbar-base-color:#ffeaff
}
</code></pre>
<p>This gives me both horizontal and vertical scroll bars automatically once I populate my table which is contained by this div.
I just want only horizontal scroll bars to appear automatically. I will modify the height of the table programmatically.</p>
<p>How do I do this?</p>
|
[
{
"answer_id": 258379,
"author": "Gareth",
"author_id": 31582,
"author_profile": "https://Stackoverflow.com/users/31582",
"pm_score": 1,
"selected": false,
"text": "overflow-x scroll widths heights"
},
{
"answer_id": 258393,
"author": "bobince",
"author_id": 18936,
"author_profile": "https://Stackoverflow.com/users/18936",
"pm_score": 9,
"selected": true,
"text": "overflow: auto;\noverflow-y: hidden;\n -ms-overflow-y: hidden;\n"
},
{
"answer_id": 258400,
"author": "Tsundoku",
"author_id": 28586,
"author_profile": "https://Stackoverflow.com/users/28586",
"pm_score": 4,
"selected": false,
"text": "overflow: auto"
},
{
"answer_id": 1820365,
"author": "Dinesh Appuhamy",
"author_id": 221401,
"author_profile": "https://Stackoverflow.com/users/221401",
"pm_score": 5,
"selected": false,
"text": "<div style=\"height:250px; width:550px; overflow-x:scroll ; overflow-y: scroll; padding-bottom:10px;\"> </div>\n <div style=\"height:250px; width:550px; overflow-x:hidden; overflow-y: scroll; padding-bottom:10px;\"> </div>\n <div style=\"height:250px; width:550px; overflow-x:scroll ; overflow-y: hidden; padding-bottom:10px;\"> </div>\n"
},
{
"answer_id": 8319119,
"author": "Hoby",
"author_id": 1072366,
"author_profile": "https://Stackoverflow.com/users/1072366",
"pm_score": 6,
"selected": false,
"text": "white-space: nowrap;"
},
{
"answer_id": 11534137,
"author": "Guest",
"author_id": 1533565,
"author_profile": "https://Stackoverflow.com/users/1533565",
"pm_score": 0,
"selected": false,
"text": "overflow: auto"
},
{
"answer_id": 13814545,
"author": "joginder",
"author_id": 1893737,
"author_profile": "https://Stackoverflow.com/users/1893737",
"pm_score": 1,
"selected": false,
"text": ".box-author-txt {width:596px; float:left; padding:5px 0px 10px 10px; border:1px #dddddd solid; -moz-border-radius: 0 0 5px 5px; -webkit-border-radius: 0 0 5px 5px; -o-border-radius: 0 0 5px 5px; border-radius: 0 0 5px 5px; overflow-x: scroll; white-space: nowrap; overflow-y: hidden;}\n\n\n.box-author-txt ul{ vertical-align:top; height:auto; display: inline-block; white-space: nowrap; margin:0 9px 0 0; padding:0px;}\n.box-author-txt ul li{ list-style-type:none; width:140px; }\n"
},
{
"answer_id": 17201632,
"author": "Anudeep Sharma",
"author_id": 1069208,
"author_profile": "https://Stackoverflow.com/users/1069208",
"pm_score": 2,
"selected": false,
"text": "<div style=\"max-width:980px; overflow-x: scroll; white-space: nowrap;\">\n<table border=\"1\" style=\"cellpadding:0; cellspacing:0; border:0; width=:100%;\" >\n"
},
{
"answer_id": 25688137,
"author": "Marco Allori",
"author_id": 1059966,
"author_profile": "https://Stackoverflow.com/users/1059966",
"pm_score": 5,
"selected": false,
"text": ".container{\n padding:20px;\n border:dotted 1px;\n white-space:nowrap;\n overflow-x:auto;\n}\n\n.box{\n width:100px;\n height:180px;\n background-color: red;\n margin:10px;\n display:inline-block\n}\n"
},
{
"answer_id": 32911333,
"author": "Amélie Medem",
"author_id": 3924974,
"author_profile": "https://Stackoverflow.com/users/3924974",
"pm_score": 3,
"selected": false,
"text": "overflow-x: auto overflow-y: hidden white-space: nowrap <div class=\"container\"> \n <div class=\"inner-1\"></div>\n <div class=\"inner-2\"></div>\n <div class=\"inner-3\"></div>\n</div>\n .container {\n height: 80px;\n width: 600px;\n overflow-x: auto;\n overflow-y: hidden; \n white-space: nowrap;\n}\n.inner-1,.inner-2,.inner-3 {\n height: 60px;\n max-width: 250px;\n display: inline-block; /* this should fix it */\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13370/"
] |
258,375
|
<p>A lot of iPhone apps use a blue badge to indicate the number of items in the subviews, such as the Mail client:</p>
<p><a href="http://skitch.com/leonho/4xeu/iphoto" rel="noreferrer">iPhoto http://img.skitch.com/20081103-tjr9yupbhgr3sqfh7u56if4rsn.preview.jpg</a></p>
<p>Are there any standards way (or even an API) do this?</p>
<p>UPDATE: I have created a class called BlueBadge to do this. It is available at <a href="http://github.com/leonho/iphone-libs/tree/master" rel="noreferrer">http://github.com/leonho/iphone-libs/tree/master</a></p>
|
[
{
"answer_id": 258510,
"author": "Kristian",
"author_id": 23246,
"author_profile": "https://Stackoverflow.com/users/23246",
"pm_score": -1,
"selected": false,
"text": "NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];\nNSString *caldate = [[now \n dateWithCalendarFormat:@\"%b\" \n timeZone:nil] description];\n[self setApplicationBadge:caldate];\"\n"
},
{
"answer_id": 258591,
"author": "Ben Gottlieb",
"author_id": 6694,
"author_profile": "https://Stackoverflow.com/users/6694",
"pm_score": 6,
"selected": true,
"text": "CGContextRef context = UIGraphicsGetCurrentContext();\nfloat radius = bounds.size.height / 2.0;\nNSString *countString = [NSString stringWithFormat: @\"%d\", count];\n\nCGContextClearRect(context, bounds);\n\nCGContextSetFillColorWithColor(context, ovalColor);\nCGContextBeginPath(context);\nCGContextAddArc(context, radius, radius, radius, M_PI / 2 , 3 * M_PI / 2, NO);\nCGContextAddArc(context, bounds.size.width - radius, radius, radius, 3 * M_PI / 2, M_PI / 2, NO);\nCGContextClosePath(context);\nCGContextFillPath(context);\n\n[[UIColor whiteColor] set];\n\nUIFont *font = [UIFont boldSystemFontOfSize: 14];\nCGSize numberSize = [countString sizeWithFont: font];\n\nbounds.origin.x = (bounds.size.width - numberSize.width) / 2;\n\n[countString drawInRect: bounds withFont: font];\n"
},
{
"answer_id": 342702,
"author": "kleinman",
"author_id": 43451,
"author_profile": "https://Stackoverflow.com/users/43451",
"pm_score": 2,
"selected": false,
"text": "UITabBarItem UIImage stretchableImageWithLeftCapWidth:topCapHeight: NSString"
},
{
"answer_id": 9339418,
"author": "Yonat",
"author_id": 1176162,
"author_profile": "https://Stackoverflow.com/users/1176162",
"pm_score": 1,
"selected": false,
"text": "#import <QuartzCore/QuartzCore.h> // don't forget!\n// ...\nUILabel *badge = [[UILabel alloc] init];\nbadge.layer.backgroundColor = [UIColor blueColor].CGColor;\nbadge.layer.cornerRadius = badge.bounds.size.height / 2;\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258375",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30883/"
] |
258,376
|
<p>How would I specify a color in app.config and then convert that into an actual System.Drawing.Color object at runtime?</p>
|
[
{
"answer_id": 258403,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "Color TypeConverter static void Main()\n{\n\n Test(Color.Red);\n Test(Color.FromArgb(34,125,75));\n}\nstatic void Test(Color color)\n{\n TypeConverter converter = TypeDescriptor.GetConverter(typeof(Color));\n string s = converter.ConvertToInvariantString(color);\n Console.WriteLine(\"String: \" + s);\n Color c = (Color) converter.ConvertFromInvariantString(s);\n Console.WriteLine(\"Color: \" + c);\n Console.WriteLine(\"Are equal: \" + (c == color));\n}\n String: Red\nColor: Color [Red]\nAre equal: True\nString: 34, 125, 75\nColor: Color [A=255, R=34, G=125, B=75]\nAre equal: True\n"
},
{
"answer_id": 258414,
"author": "John Lemp",
"author_id": 12915,
"author_profile": "https://Stackoverflow.com/users/12915",
"pm_score": 2,
"selected": false,
"text": "<add key=\"SomethingsColor\" value=\"Black\" />\n Color myColor = Color.FromName(ConfigurationManager.AppSettings[\"KEY\"]);\n"
},
{
"answer_id": 258431,
"author": "NotJarvis",
"author_id": 16268,
"author_profile": "https://Stackoverflow.com/users/16268",
"pm_score": 0,
"selected": false,
"text": "private ColorInt\n\npublic Color shapeColor\n{\n get {\n return Color.FromArgb(ColorInt);\n }\n set \n {\n ColorInt = value.toargb()\n }\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1127460/"
] |
258,390
|
<p>I have a text file of URLs, about 14000. Below is a couple of examples:</p>
<p><a href="http://www.domainname.com/pagename?CONTENT_ITEM_ID=100&param2=123" rel="nofollow noreferrer">http://www.domainname.com/pagename?CONTENT_ITEM_ID=100&param2=123</a><br />
<a href="http://www.domainname.com/images?IMAGE_ID=10" rel="nofollow noreferrer">http://www.domainname.com/images?IMAGE_ID=10</a><br />
<a href="http://www.domainname.com/pagename?CONTENT_ITEM_ID=101&param2=123" rel="nofollow noreferrer">http://www.domainname.com/pagename?CONTENT_ITEM_ID=101&param2=123</a><br />
<a href="http://www.domainname.com/images?IMAGE_ID=11" rel="nofollow noreferrer">http://www.domainname.com/images?IMAGE_ID=11</a><br />
<a href="http://www.domainname.com/pagename?CONTENT_ITEM_ID=102&param2=123" rel="nofollow noreferrer">http://www.domainname.com/pagename?CONTENT_ITEM_ID=102&param2=123</a><br /></p>
<p>I have loaded the text file into a Python list and I am trying to get all the URLs with CONTENT_ITEM_ID separated off into a list of their own. What would be the best way to do this in Python?</p>
<p>Cheers</p>
|
[
{
"answer_id": 258396,
"author": "Graeme Perrow",
"author_id": 1821,
"author_profile": "https://Stackoverflow.com/users/1821",
"pm_score": 3,
"selected": false,
"text": "list2 = filter( lambda x: x.find( 'CONTENT_ITEM_ID ') != -1, list1 )\n function look_for_content_item_id( elem ):\n if elem.find( 'CONTENT_ITEM_ID') == -1:\n return 0\n return 1\nlist2 = filter( look_for_content_item_id, list1 )\n"
},
{
"answer_id": 258415,
"author": "bobince",
"author_id": 18936,
"author_profile": "https://Stackoverflow.com/users/18936",
"pm_score": 5,
"selected": true,
"text": "list2= [line for line in file if 'CONTENT_ITEM_ID' in line]\n"
},
{
"answer_id": 258491,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 3,
"selected": false,
"text": "for filtered_url in (line for line in file if 'CONTENT_ITEM_ID' in line):\n do_something_with_filtered_url(filtered_url)\n"
},
{
"answer_id": 258512,
"author": "Markus Jarderot",
"author_id": 22364,
"author_profile": "https://Stackoverflow.com/users/22364",
"pm_score": 3,
"selected": false,
"text": "ifilter from itertools import ifilter\n\nfor line in ifilter(lambda line: 'CONTENT_ITEM_ID' in line, urls):\n do_something(line)\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30786/"
] |
258,394
|
<p>I am new to Cocoa and need to capture input using scanf to run a program that requires input of four variables one at a time.</p>
<p>Is there any console, window class, canvas, memo class (as in delphi) that will llow me to do this.</p>
<p>Earl Cenac</p>
|
[
{
"answer_id": 259901,
"author": "Peter Hosey",
"author_id": 30461,
"author_profile": "https://Stackoverflow.com/users/30461",
"pm_score": 0,
"selected": false,
"text": "scanf NSString +[NSString stringWithUTF8String:] +[NSString stringWithCString:encoding:]"
},
{
"answer_id": 4533695,
"author": "Rajan",
"author_id": 554265,
"author_profile": "https://Stackoverflow.com/users/554265",
"pm_score": 1,
"selected": false,
"text": "NSString *password=@\"rajan\";\nNSString *scanpass;\nchar currentpass[10];\n\nNSLog(@\"Enter your old password tp compare\");\nscanf(\"%s\",currentpass);\nscanpass = [NSString stringWithUTF8String:currentpass];\n//if([password isEqualToString: @\"rajan\"])\nif([password isEqualToString: scanpass])\n NSLog(@\"Correct Password\");\nelse \n NSLog(@\"Wrong Password\");\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
258,397
|
<p>I am desiging a new website for my company and I am trying to implement switch navigation which is what I have used on all my sites in the past.</p>
<pre><code><?php
switch($x) {
default:
include("inc/main.php");
break;
case "products":
include("inc/products.php");
break;
}
?>
</code></pre>
<p>For some reason when I go to index.php?x=products nothing happens, it still displays inc/main.php, in other words it hasn't detected the X variable from the URL. Is this something to do with global variables?</p>
|
[
{
"answer_id": 258405,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 5,
"selected": true,
"text": "register_globals $x = $_REQUEST['x']\n $_GET GET $_REQUEST"
},
{
"answer_id": 258410,
"author": "hangy",
"author_id": 11963,
"author_profile": "https://Stackoverflow.com/users/11963",
"pm_score": 3,
"selected": false,
"text": "switch($_GET['x']) {"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258397",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26823/"
] |
258,407
|
<p>I need to convert a UNICODE_STRING structure to a simple NULL TERMINATED STRING.</p>
<pre><code>typedef
struct _UNICODE_STRING
{
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
}
UNICODE_STRING, *PUNICODE_STRING;
</code></pre>
<p>I can't find a clean sollution on MSDN about it.
Anyone been there?
I am not using .net so I need a native API sollution.</p>
<p>Thanks a lot!</p>
|
[
{
"answer_id": 9657638,
"author": "SecurityMatt",
"author_id": 1250976,
"author_profile": "https://Stackoverflow.com/users/1250976",
"pm_score": 0,
"selected": false,
"text": "WCHAR* UnicodeStringToNulTerminated(UNICODE_STRING* str)\n{\n WCHAR* result;\n if(str == NULL)\n return NULL;\n result = (WCHAR*)malloc(str->Length + 2);\n if(result == NULL)\n // raise?\n return NULL;\n memcpy(result, str->Buffer, str->Length);\n result[str->Length] = L'\\0';\n return result;\n}\n"
},
{
"answer_id": 11320148,
"author": "RectangleEquals",
"author_id": 1500110,
"author_profile": "https://Stackoverflow.com/users/1500110",
"pm_score": 2,
"selected": false,
"text": "HRESULT UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA){\n ULONG cbAnsi, cCharacters;\n DWORD dwError;\n // If input is null then just return the same. \n if (pszW == NULL) \n {\n *ppszA = NULL;\n return NOERROR;\n }\n cCharacters = wcslen(pszW)+1;\n cbAnsi = cCharacters*2;\n\n *ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);\n if (NULL == *ppszA)\n return E_OUTOFMEMORY;\n\n if (0 == WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, *ppszA, cbAnsi, NULL, NULL)) \n {\n dwError = GetLastError();\n CoTaskMemFree(*ppszA);\n *ppszA = NULL;\n return HRESULT_FROM_WIN32(dwError);\n }\n return NOERROR;\n}\n LPSTR pszstrA;\nUnicodeToAnsi(my_unicode_string.Buffer, &pszstrA);\ncout << \"My ansi string: (\" << pszstrA << \")\\r\\n\";\n"
},
{
"answer_id": 11321143,
"author": "Remy Lebeau",
"author_id": 65863,
"author_profile": "https://Stackoverflow.com/users/65863",
"pm_score": 0,
"selected": false,
"text": "#include <string>\n\nUNICODE_STRING us;\n// fill us as needed...\n\nstd::wstring ws(us.Buffer, us.Length);\n// use ws.c_str() where needed...\n"
},
{
"answer_id": 13409339,
"author": "glagolig",
"author_id": 1236546,
"author_profile": "https://Stackoverflow.com/users/1236546",
"pm_score": 1,
"selected": false,
"text": "UNICODE_STRING tmp;\n// ...\nSTRING dest; // or ANSI_STRING in kernel mode\n\nLONG (WINAPI *RtlUnicodeStringToAnsiString)(PVOID, PVOID, BOOL);\n*(FARPROC *)&RtlUnicodeStringToAnsiString = \n GetProcAddress(LoadLibraryA(\"NTDLL.DLL\"), \"RtlUnicodeStringToAnsiString\");\nif(!RtlUnicodeStringToAnsiString)\n{\n return;\n}\n\nULONG unicodeBufferSize = tmp.Length;\ndest.Buffer = (PCHAR)malloc(unicodeBufferSize+1); // that must be enough...\ndest.Length = 0;\ndest.MaximumLength = unicodeBufferSize+1;\n\nRtlUnicodeStringToAnsiString(&dest, &tmp, FALSE);\ndest.Buffer[dest.Length] = 0; // now we get it in dest.Buffer\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
258,409
|
<p>I have a 'generic' boiler plate static method for checking for InvokeRequired and invoking an associated action accordingly.</p>
<p>If an unhandled exception is raised by the action, the stack trace isn't much help because it starts from here. I can get information about the control, but that isn't always much help. I was wondering if it is possible to get 'something' useful out of the Action - other that 'Target'. (Note that the Action is often a lambda or anonymous delegate...)</p>
<pre><code> public static void Invoke(Control ctrl, Action action)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");
if (action == null)
return;
var invokeRequired = ctrl.InvokeRequired;
try
{
if (ctrl.InvokeRequired)
ctrl.Invoke(action);
else
action();
}
catch (Exception ex)
{
throw new Exception(String.Format("Invoke error, ctrl={0}, action Target={1}", ctrl.Name, action.Target), ex);
}
}
</code></pre>
<p>EDIT: In line with this answer, here is the new overload (also slightly improved)</p>
<pre><code>public static void Invoke(Control ctrl, Action action, string context)
{
if (ctrl == null)
throw new ArgumentNullException("ctrl");
if (action == null)
return; //not sure it's worththrowing an exception here...
var invokeRequired = ctrl.InvokeRequired;
try
{
if (invokeRequired)
ctrl.Invoke(action);
else
action();
}
catch (Exception ex)
{
var ps = invokeRequired ? "" : " - has the target control been initialised?";
var errmsg = String.Format("Invoke error, ctrl={0}, action Target={1}, context={2}{3}", ctrl.Name, action.Target, context, ps);
throw new Exception(errmsg, ex);
}
}
</code></pre>
|
[
{
"answer_id": 9657638,
"author": "SecurityMatt",
"author_id": 1250976,
"author_profile": "https://Stackoverflow.com/users/1250976",
"pm_score": 0,
"selected": false,
"text": "WCHAR* UnicodeStringToNulTerminated(UNICODE_STRING* str)\n{\n WCHAR* result;\n if(str == NULL)\n return NULL;\n result = (WCHAR*)malloc(str->Length + 2);\n if(result == NULL)\n // raise?\n return NULL;\n memcpy(result, str->Buffer, str->Length);\n result[str->Length] = L'\\0';\n return result;\n}\n"
},
{
"answer_id": 11320148,
"author": "RectangleEquals",
"author_id": 1500110,
"author_profile": "https://Stackoverflow.com/users/1500110",
"pm_score": 2,
"selected": false,
"text": "HRESULT UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA){\n ULONG cbAnsi, cCharacters;\n DWORD dwError;\n // If input is null then just return the same. \n if (pszW == NULL) \n {\n *ppszA = NULL;\n return NOERROR;\n }\n cCharacters = wcslen(pszW)+1;\n cbAnsi = cCharacters*2;\n\n *ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);\n if (NULL == *ppszA)\n return E_OUTOFMEMORY;\n\n if (0 == WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, *ppszA, cbAnsi, NULL, NULL)) \n {\n dwError = GetLastError();\n CoTaskMemFree(*ppszA);\n *ppszA = NULL;\n return HRESULT_FROM_WIN32(dwError);\n }\n return NOERROR;\n}\n LPSTR pszstrA;\nUnicodeToAnsi(my_unicode_string.Buffer, &pszstrA);\ncout << \"My ansi string: (\" << pszstrA << \")\\r\\n\";\n"
},
{
"answer_id": 11321143,
"author": "Remy Lebeau",
"author_id": 65863,
"author_profile": "https://Stackoverflow.com/users/65863",
"pm_score": 0,
"selected": false,
"text": "#include <string>\n\nUNICODE_STRING us;\n// fill us as needed...\n\nstd::wstring ws(us.Buffer, us.Length);\n// use ws.c_str() where needed...\n"
},
{
"answer_id": 13409339,
"author": "glagolig",
"author_id": 1236546,
"author_profile": "https://Stackoverflow.com/users/1236546",
"pm_score": 1,
"selected": false,
"text": "UNICODE_STRING tmp;\n// ...\nSTRING dest; // or ANSI_STRING in kernel mode\n\nLONG (WINAPI *RtlUnicodeStringToAnsiString)(PVOID, PVOID, BOOL);\n*(FARPROC *)&RtlUnicodeStringToAnsiString = \n GetProcAddress(LoadLibraryA(\"NTDLL.DLL\"), \"RtlUnicodeStringToAnsiString\");\nif(!RtlUnicodeStringToAnsiString)\n{\n return;\n}\n\nULONG unicodeBufferSize = tmp.Length;\ndest.Buffer = (PCHAR)malloc(unicodeBufferSize+1); // that must be enough...\ndest.Length = 0;\ndest.MaximumLength = unicodeBufferSize+1;\n\nRtlUnicodeStringToAnsiString(&dest, &tmp, FALSE);\ndest.Buffer[dest.Length] = 0; // now we get it in dest.Buffer\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11410/"
] |
258,416
|
<p>I'm looking for the .NET-preferred way of performing the same type of thing that ShellExecute does in Win32 (opening, printing, etc. for arbitrary file types).</p>
<p>I've been programming Windows for over 20 years, but I'm a complete newbie at .NET, so maybe I'm just looking in the wrong places. I'm currently using .NET 2.0 (VS C# 2005), but could use VS 2008 if need be.</p>
<p>If the only answer is to use P/Invoke, then I might be better just writing my small utility using Win32 anyway.</p>
|
[
{
"answer_id": 258465,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 5,
"selected": false,
"text": "System.Diagnostics.Process.Start(command)\n"
},
{
"answer_id": 258468,
"author": "Cyril Gupta",
"author_id": 33052,
"author_profile": "https://Stackoverflow.com/users/33052",
"pm_score": 2,
"selected": false,
"text": "System.Diagnostics.Process.Start()"
},
{
"answer_id": 72205050,
"author": "mdimai666",
"author_id": 6723966,
"author_profile": "https://Stackoverflow.com/users/6723966",
"pm_score": 0,
"selected": false,
"text": "System.Diagnostics.Process.Start(\"explorer.exe\", path);\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6111/"
] |
258,422
|
<p>Using qsort in C we pass in a comparison function e.g.</p>
<pre><code>int cmp(const void*, const void*);
</code></pre>
<p>the protoype of qsort expects a <code>int (* )(const void* , const void*)</code> so we call:</p>
<pre><code>qsort(..., cmp);
</code></pre>
<p>but it is equally valid to call:</p>
<pre><code>qsort(..., &cmp);
</code></pre>
<p>and this is what we would have to do if we passed in a static member-function in C++. Kernighan & Ritchie (2nd Edition, 5.11 "Pointers To Functions" p119) states that "since [cmp] is known to be a function, the & operator is not necessary, in the same way that it is not needed before an array name."</p>
<p>Does anyone else feel slightly uncomfortable with this (esp. regarding type-safety)?</p>
|
[
{
"answer_id": 258435,
"author": "Jeff Hillman",
"author_id": 3950,
"author_profile": "https://Stackoverflow.com/users/3950",
"pm_score": 3,
"selected": false,
"text": "int main()\n{\n int integer = 0xFFFFFF; \n void (*functionPointer)() = (void(*)())integer; \n\n functionPointer(); \n\n return 0; \n}\n"
},
{
"answer_id": 258459,
"author": "Adam Liss",
"author_id": 29157,
"author_profile": "https://Stackoverflow.com/users/29157",
"pm_score": 1,
"selected": false,
"text": "cmp"
},
{
"answer_id": 260202,
"author": "aib",
"author_id": 1088,
"author_profile": "https://Stackoverflow.com/users/1088",
"pm_score": 1,
"selected": false,
"text": "(*funcptr)(arg1, arg2);\n funcptr(arg1, arg2);\n"
},
{
"answer_id": 264142,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "void baz();\n\nvoid foo(void (&bar)()) {\n bar();\n}\n\n// doesnt work, since a reference to a function is requested. \n// you have to pass 'bar' itself, without taking its address \n// explicitely.\nfoo(&baz); \n template<typename T, int N>\nvoid ByRef(T (&foo)[N]) { \n ...\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26665/"
] |
258,425
|
<p>I have a large project for which I am attempting to use TDD.
I am using <a href="http://tut-framework.sourceforge.net/" rel="nofollow noreferrer">Tut</a> as my test framework, which has its flaws but is sufficient for what I need. </p>
<p>I need to exploit link time test seams, <strong>each test must be in its own executable</strong>. The project for this executable then launches itself as a post build step.</p>
<p>Unfortunately, this means that my Visual Studio Sln is filling up with tests, which is not scalable and also hides the actual important projects.</p>
<p>Does anyone know of a better way of running these tests?
Is it possible to hide projects from a build and yet still have them build? </p>
|
[
{
"answer_id": 258453,
"author": "sergtk",
"author_id": 13441,
"author_profile": "https://Stackoverflow.com/users/13441",
"pm_score": 3,
"selected": true,
"text": "#pragma comment(lib, \"libname\")\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258425",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1575281/"
] |
258,469
|
<p>These seem to mean the same thing. But what term is more appropriate in what context?</p>
|
[
{
"answer_id": 258474,
"author": "dove",
"author_id": 30913,
"author_profile": "https://Stackoverflow.com/users/30913",
"pm_score": 2,
"selected": false,
"text": "<property attribute=\"attributeValue\">proopertyValue</property>\n [Attribute]\npublic class Entity\n{\n private int Property{get; set;};\n"
},
{
"answer_id": 258500,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "class X( object ):\n def __init__( self ):\n self.attribute\n def getAttr( self ):\n return self.attribute\n def setAttr( self, value ):\n self.attribute= value\n property_name= property( getAttr, setAttr )\n __getattr__"
},
{
"answer_id": 10673539,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 8,
"selected": false,
"text": "element.href href element.getAttribute('href')"
},
{
"answer_id": 16120757,
"author": "smonusbonus",
"author_id": 1446150,
"author_profile": "https://Stackoverflow.com/users/1446150",
"pm_score": 5,
"selected": false,
"text": "<input type=\"checkbox\" checked=\"checked\" />\n input type \"checkbox\" checked true"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6954/"
] |
258,473
|
<p>I am trying to migrate a part of an SVN repository using <code>svnadmin dump</code>.</p>
<p>The provided svndumpfilter tool doesn't manage copy/move/rename dependencies from directories not included in the export.</p>
<p>Is there a tool which can manage these dependencies?</p>
|
[
{
"answer_id": 258498,
"author": "Davide Gualano",
"author_id": 28582,
"author_profile": "https://Stackoverflow.com/users/28582",
"pm_score": 0,
"selected": false,
"text": "http://host/project http://host/dependencies svndumpfilter include http://host/project http://host/dependencies < total.dump > project.dump\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33622/"
] |
258,481
|
<p>In any (non-web) .net project, the compiler automatically declares the DEBUG and TRACE constants, so I can use conditional compiling to, for example, handle exceptions differently in debug vs release mode.</p>
<p>For example:</p>
<pre><code>#if DEBUG
/* re-throw the exception... */
#else
/* write something in the event log... */
#endif
</code></pre>
<p>How do I obtain the same behavior in an ASP.net project?
It looks like the system.web/compilation section in the web.config could be what I need, but how do I check it programmatically?
Or am I better off declaring a DEBUG constant myself and comment it out in release builds?</p>
<p>EDIT: I'm on VS 2008</p>
|
[
{
"answer_id": 258495,
"author": "Andrew Theken",
"author_id": 32238,
"author_profile": "https://Stackoverflow.com/users/32238",
"pm_score": 4,
"selected": true,
"text": "#if DEBUG\n/* re-throw the exception... */\n#else\n/* write something in the event log... */\n#endif\n"
},
{
"answer_id": 258515,
"author": "TheCodeJunkie",
"author_id": 25319,
"author_profile": "https://Stackoverflow.com/users/25319",
"pm_score": 3,
"selected": false,
"text": "public bool IsDebugMode\n{\n get\n {\n#if DEBUG \n return true;\n#else\n return false;\n#endif\n }\n}\n"
},
{
"answer_id": 259271,
"author": "Loris",
"author_id": 23824,
"author_profile": "https://Stackoverflow.com/users/23824",
"pm_score": 3,
"selected": false,
"text": "protected bool IsDebugMode\n{\n get\n {\n System.Web.Configuration.CompilationSection tSection;\n tSection = ConfigurationManager.GetSection(\"system.web/compilation\") as System.Web.Configuration.CompilationSection;\n if (null != tSection)\n {\n return tSection.Debug;\n }\n /* Default to release behavior */\n return false;\n }\n}\n"
},
{
"answer_id": 60073084,
"author": "ShrapNull",
"author_id": 1652234,
"author_profile": "https://Stackoverflow.com/users/1652234",
"pm_score": 1,
"selected": false,
"text": "[Conditional(\"DEBUG\")]\nprivate void IsDebugCheck(ref bool isDebug)\n{\n isDebug = true;\n}\n\npublic void SomeCallingMethod()\n{ \n bool isDebug = false;\n IsDebugCheck(ref isDebug);\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258481",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23824/"
] |
258,483
|
<h2>Question</h2>
<p>I'm sure many of you have been faced by the challenge of localizing a database backend to an application. If you've not then I'd be pretty confident in saying that the odds of you having to do so in the future is quite large. I'm talking anout storing multiple translations of texts (and the same can be said for currency etc.) for your database entities.</p>
<p>For example the classic "Category" table might have a Name and a Description column which should be globalized. One way would be to do have a "Text" table for each of your entities and then do a join to retreive the values based on the provided language.</p>
<p>This leaves you with a lot of "Text" tables, one for each entity which you want to localize, with the addition of a TextType to distinguish between the various texts that it may store.</p>
<p>I'm curious if there are any, documented, best-practises / design patterns on implementing this kind of support into a SQL Server 2005/2008 datebase (I'm being specific about the RDBMS since it might contain supported keywords and such which helps with the implementation)?</p>
<h2>Thoughts on XML approach</h2>
<p>One idea I have been toying with (albeit only in my head so far) was to leverage the XML datatype introduced in SQL Server 2005. The idea was to make columns which should support localization, of the XML datatype (and bind a schema to it). The XML would contain the localized strings along with the language code / culture it was tied to.</p>
<p>Something along the lines of</p>
<pre><code>Product
ID (int, identity)
Name (XML ...)
Description (XML ...)
</code></pre>
<p>Then you would have something like this as the XML</p>
<pre><code><localization>
<text culture="sv-SE">Detta är ett namn</text>
<text culture="en-EN">This is a name</text>
</localization>
</code></pre>
<p>You could then do (This isn't production code so I'll use the *)</p>
<pre><code>SELECT *
From Product
Where Product.ID = 10
</code></pre>
<p>And you would get back the product with all localized texts which would mean you would have to do the extraction on the client-side. The biggest problem here is obviously the amount of extra data that you would have to return on each query, The benefits would be a cleaner design with no look-up tables, joins and so on. </p>
<p>Btw, what ever method I do end up using in my design I will still be using Linq To SQL (.NET Platform) to query the database (the XML approach should be a problem since it would return an XElement which could be interpreted client-side)</p>
<p>So suggestion on database localization design patterns, and possibly comments on the XML thought, would be very apprechiated.</p>
|
[
{
"answer_id": 261900,
"author": "TToni",
"author_id": 20703,
"author_profile": "https://Stackoverflow.com/users/20703",
"pm_score": 1,
"selected": false,
"text": "SELECT *\nFrom Product\nWhere Product.ID = 10 AND Product.cultureID = 1\n"
},
{
"answer_id": 261979,
"author": "Mac",
"author_id": 8696,
"author_profile": "https://Stackoverflow.com/users/8696",
"pm_score": 2,
"selected": false,
"text": "xml:lang <l10n>\n <text xml:lang=\"sv-SE\">Detta är ett namn</text>\n <text xml:lang=\"en-EN\">This is a name</text>\n</l10n>\n SELECT Name.value('(l10n/text[lang()=\"en\"])[1]', 'NVARCHAR(MAX)')\n FROM Product\n WHERE Product.ID=10;\n"
},
{
"answer_id": 865133,
"author": "Yordan Georgiev",
"author_id": 65706,
"author_profile": "https://Stackoverflow.com/users/65706",
"pm_score": 0,
"selected": false,
"text": "CREATE TABLE [dbo].[Lang_en_US_Msg](\n [MsgId] [int] IDENTITY(1,1) NOT NULL,\n [MsgKey] [varchar](200) NOT NULL,\n [MsgTxt] [varchar](2000) NOT NULL,\n [MsgDescription] [varchar](2000) NOT NULL,\n CONSTRAINT [PK_Lang_US-us__Msg] PRIMARY KEY CLUSTERED \n(\n [MsgId] ASC\n)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]\n) ON [PRIMARY]\n\nGO\n\nCREATE TABLE [dbo].[User](\n [UserId] [int] IDENTITY(1,1) NOT NULL,\n [FirstName] [varchar](50) NOT NULL,\n [MiddleName] [varchar](50) NULL,\n [LastName] [varchar](50) NULL,\n [DomainName] [varchar](50) NULL,\n CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED \n(\n [UserId] ASC\n)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]\n) ON [PRIMARY]\n\nCREATE TABLE [dbo].[UserSetting](\n [UserSettingId] [int] IDENTITY(1,1) NOT NULL,\n [UserId] [int] NOT NULL,\n [CultureInfo] [varchar](50) NOT NULL,\n [GuiLanguage] [varchar](10) NOT NULL,\n CONSTRAINT [PK_UserSetting] PRIMARY KEY CLUSTERED \n(\n [UserSettingId] ASC\n)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]\n) ON [PRIMARY]\n ALTER TABLE [dbo].[UserSetting] ADD CONSTRAINT [DF_UserSetting_CultureInfo] DEFAULT ('fi-FI') FOR [CultureInfo]\n GO\n\n CREATE TABLE [dbo].[Lang_fi_FI_Msg](\n [MsgId] [int] IDENTITY(1,1) NOT NULL,\n [MsgKey] [varchar](200) NOT NULL,\n [MsgTxt] [varchar](2000) NOT NULL,\n [MsgDescription] [varchar](2000) NOT NULL,\n [DbSysNameForExpansion] [varchar](50) NULL,\n CONSTRAINT [PK_Lang_Fi-fi__Msg] PRIMARY KEY CLUSTERED \n(\n [MsgId] ASC\n)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]\n) ON [PRIMARY]\n\nCREATE PROCEDURE [dbo].[procGui_GetPageMsgs]\n@domainUser varchar(50) , -- the domain_user performing the action \n@msgOut varchar(4000) OUT, -- the (error) msg to be shown to the user \n@debugMsgOut varchar(4000) OUT , -- this variable holds the debug msg to be shown if debug level is enabled \n@ret int OUT -- the variable indicating success or failure \n\nAS \nBEGIN -- proc start \n SET NOCOUNT ON; \n\ndeclare @procedureName varchar(200) \ndeclare @procStep varchar(4000) \n\n\nset @procedureName = ( SELECT OBJECT_NAME(@@PROCID)) \nset @msgOut = ' ' \nset @debugMsgOut = ' ' \nset @procStep = ' ' \n\n\nBEGIN TRY --begin try \nset @ret = 1 --assume false from the beginning \n\n--===============================================================\n --debug set @procStep=@procStep + 'GETTING THE GUI LANGUAGE FOR THIS USER '\n--===============================================================\n\ndeclare @guiLanguage nvarchar(10)\n\n\n\n\nif ( @domainUser is null)\n set @guiLanguage = (select Val from AppSetting where Name='guiLanguage')\nelse \n set @guiLanguage = (select GuiLanguage from UserSetting us join [User] u on u.UserId = us.UserId where u.DomainName=@domainUser)\n\nset @guiLanguage = REPLACE ( @guiLanguage , '-' , '_' ) ;\n\n\n--===============================================================\nset @procStep=@procStep + ' BUILDING THE SQL QUERY '\n--===============================================================\n\nDECLARE @sqlQuery AS nvarchar(2000)\nSET @sqlQuery = 'SELECT MsgKey , MsgTxt FROM dbo.lang_' + @guiLanguage + '_Msg'\n\n\n--===============================================================\nset @procStep=@procStep + 'EXECUTING THE SQL QUERY'\n--===============================================================\nprint @sqlQuery\n\n exec sp_executesql @sqlQuery\n\n set @debugMsgOut = @procStep\n set @ret = @@ERROR \n\n\nEND TRY --end try \n\nBEGIN CATCH \n PRINT 'In CATCH block. \n Error number: ' + CAST(ERROR_NUMBER() AS varchar(10)) + ' \n Error message: ' + ERROR_MESSAGE() + ' \n Error severity: ' + CAST(ERROR_SEVERITY() AS varchar(10)) + ' \n Error state: ' + CAST(ERROR_STATE() AS varchar(10)) + ' \n XACT_STATE: ' + CAST(XACT_STATE() AS varchar(10)); \n\nset @msgOut = 'Failed to execute ' + @sqlQuery \nset @debugMsgOut = ' Error number: ' + CAST(ERROR_NUMBER() AS varchar(10)) + \n 'Error message: ' + ERROR_MESSAGE() + 'Error severity: ' + CAST(ERROR_SEVERITY() AS varchar(10)) + \n 'Error state: ' + CAST(ERROR_STATE() AS varchar(10)) + 'XACT_STATE: ' + CAST(XACT_STATE() AS varchar(10)) \n\n--record the error in the database \n--debug \n --EXEC [dbo].[procUtils_DebugDb]\n -- @DomainUser = @domainUser,\n -- @debugmsg = @debugMsgOut,\n -- @ret = 1,\n -- @procedureName = @procedureName ,\n -- @procedureStep = @procStep\n\n -- set @ret = 1 \n\nEND CATCH \n\n\nreturn @ret \nEND --procedure end \n"
},
{
"answer_id": 1416897,
"author": "eduncan911",
"author_id": 56693,
"author_profile": "https://Stackoverflow.com/users/56693",
"pm_score": 0,
"selected": false,
"text": "Given a users culture is \"sv-se\"\nWhen the user views a post list\nIt should list posts only in \"sv-se\" culture\n SELECT * FROM Post WHERE CultureUI IN ('sv-se', 'en-us')\n"
},
{
"answer_id": 1492063,
"author": "NightOwl888",
"author_id": 181087,
"author_profile": "https://Stackoverflow.com/users/181087",
"pm_score": 0,
"selected": false,
"text": "Label1.Text = GetLocalResourceObject(\"TokenStoredInDatabase\").ToString()\n"
},
{
"answer_id": 3418944,
"author": "Rei Miyasaka",
"author_id": 388626,
"author_profile": "https://Stackoverflow.com/users/388626",
"pm_score": 0,
"selected": false,
"text": "<localization> <text culture=\"...\">"
},
{
"answer_id": 4130084,
"author": "Richard Bladh",
"author_id": 501401,
"author_profile": "https://Stackoverflow.com/users/501401",
"pm_score": 2,
"selected": false,
"text": "* id\n* price\n* stocklevel\n* active\n* name\n* shortdescription\n* longdescription\n * id\n* products_id\n* name\n* shortdescription\n* longdescription\n string query = \"\";\nif(string.IsNullOrEmpty(culture)) {\n // No culture specified, no join needed.\n query = \"SELECT p.price, p.name, p.shortdescription FROM products p WHERE p.price > ?Price\";\n} else {\n query = \"SELECT p.price, case when pg.name is null then p.name else pg.name end as 'name', case when pg.shortdescription is null then p.shortdescription else pg.shortdescription end as 'shortdescription' FROM products p\"\n + \" LEFT JOIN products_globalization pg ON pg.products_id = p.id AND pg.culture = ?Culture\"\n + \" WHERE p.price > ?Price\";\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25319/"
] |
258,486
|
<p>How to calculate the length (in pixels) of a string in Java?</p>
<p>Preferable without using Swing.</p>
<p>EDIT:
I would like to draw the string using the drawString() in Java2D
and use the length for word wrapping.</p>
|
[
{
"answer_id": 258499,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 8,
"selected": true,
"text": "Graphics.getFontMetrics FontMetrics FontMetrics.stringWidth Graphics g int width = g.getFontMetrics().stringWidth(text);\n"
},
{
"answer_id": 14832962,
"author": "Olofu Mark",
"author_id": 2055028,
"author_profile": "https://Stackoverflow.com/users/2055028",
"pm_score": 6,
"selected": false,
"text": "import java.awt.Font;\nimport java.awt.font.FontRenderContext;\nimport java.awt.geom.AffineTransform;\n\n...\n\nString text = \"Hello World\";\nAffineTransform affinetransform = new AffineTransform(); \nFontRenderContext frc = new FontRenderContext(affinetransform,true,true); \nFont font = new Font(\"Tahoma\", Font.PLAIN, 12);\nint textwidth = (int)(font.getStringBounds(text, frc).getWidth());\nint textheight = (int)(font.getStringBounds(text, frc).getHeight());\n"
},
{
"answer_id": 18450804,
"author": "Ed Poor",
"author_id": 487839,
"author_profile": "https://Stackoverflow.com/users/487839",
"pm_score": 3,
"selected": false,
"text": "import java.awt.*;\nimport java.awt.geom.*;\nimport java.awt.font.*;\n\nclass StringMetrics {\n\n Font font;\n FontRenderContext context;\n\n public StringMetrics(Graphics2D g2) {\n\n font = g2.getFont();\n context = g2.getFontRenderContext();\n }\n\n Rectangle2D getBounds(String message) {\n\n return font.getStringBounds(message, context);\n }\n\n double getWidth(String message) {\n\n Rectangle2D bounds = getBounds(message);\n return bounds.getWidth();\n }\n\n double getHeight(String message) {\n\n Rectangle2D bounds = getBounds(message);\n return bounds.getHeight();\n }\n\n}\n"
},
{
"answer_id": 44180263,
"author": "wmioduszewski",
"author_id": 2395747,
"author_profile": "https://Stackoverflow.com/users/2395747",
"pm_score": 1,
"selected": false,
"text": "private static Hashtable hash = new Hashtable();\nprivate Font font;\nprivate LineBreakMeasurer lineBreakMeasurer;\nprivate int start, end;\n\npublic PixelLengthCheck(Font font) {\n this.font = font;\n}\n\npublic boolean tryIfStringFits(String textToMeasure, Dimension areaToFit) {\n AttributedString attributedString = new AttributedString(textToMeasure, hash);\n attributedString.addAttribute(TextAttribute.FONT, font);\n AttributedCharacterIterator attributedCharacterIterator =\n attributedString.getIterator();\n start = attributedCharacterIterator.getBeginIndex();\n end = attributedCharacterIterator.getEndIndex();\n\n lineBreakMeasurer = new LineBreakMeasurer(attributedCharacterIterator,\n new FontRenderContext(null, false, false));\n\n float width = (float) areaToFit.width;\n float height = 0;\n lineBreakMeasurer.setPosition(start);\n\n while (lineBreakMeasurer.getPosition() < end) {\n TextLayout textLayout = lineBreakMeasurer.nextLayout(width);\n height += textLayout.getAscent();\n height += textLayout.getDescent() + textLayout.getLeading();\n }\n\n boolean res = height <= areaToFit.getHeight();\n\n return res;\n}\n"
},
{
"answer_id": 60643245,
"author": "John Henckel",
"author_id": 1812732,
"author_profile": "https://Stackoverflow.com/users/1812732",
"pm_score": 2,
"selected": false,
"text": "// Returns the size in PICA of the string, given space is 200 and 'W' is 1000.\n// see https://p2p.wrox.com/access/32197-calculate-character-widths.html\n\nstatic int picaSize(String s)\n{\n // the following characters are sorted by width in Arial font\n String lookup = \" .:,;'^`!|jl/\\\\i-()JfIt[]?{}sr*a\\\"ce_gFzLxkP+0123456789<=>~qvy$SbduEphonTBCXY#VRKZN%GUAHD@OQ&wmMW\";\n int result = 0;\n for (int i = 0; i < s.length(); ++i)\n {\n int c = lookup.indexOf(s.charAt(i));\n result += (c < 0 ? 60 : c) * 7 + 200;\n }\n return result;\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26567/"
] |
258,505
|
<p>Is it possible in Actionscript 3 to create a weak reference to an object, so that it can be garbage collected.</p>
<p>I'm creating some classes to make debugging easier, so I don't want the objects to hang around in memory if they are only referenced here (and of course I don't want to fill the code with callbacks to remove the objects)</p>
|
[
{
"answer_id": 258507,
"author": "Andres",
"author_id": 1815,
"author_profile": "https://Stackoverflow.com/users/1815",
"pm_score": 2,
"selected": false,
"text": "public class WeakReference\n{\n private var dic\n\n public function WeakReference(object)\n {\n this.dic = new Dictionary(true)\n this.dic[object] = true\n }\n\n public function get Value()\n {\n for (var object in this.dic)\n {\n return object\n }\n return null\n }\n}\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1815/"
] |
258,529
|
<p>Here's an interface:</p>
<pre><code>public interface Foo<T> extends Comparable<Foo<T>> {
...
}
</code></pre>
<p>And there are some classes implementing this interface:</p>
<pre><code>public class Bar extends Something implements Foo<Something> {
public Vector<Foo<Bar>> giveBar() {
...
}
}
public class Boo extends SomethingElse implements Foo<SomethingElse> {
public Vector<Foo<Boo>> giveBoo() {
...
}
}
</code></pre>
<p>Now I want to keep a bunch of Foos (that may really be Foos or Boos) inside a vector. </p>
<pre><code>Bar bar = new Bar();
Boo boo = new Boo();
Vector<Foo<?>> vector;
if (...)
vector = bar.giveBar();
else
vector = boo.giveBoo();
</code></pre>
<p>I get:</p>
<pre><code>Type mismatch: cannot convert from Vector<Foo<SomethingElse>> to Vector<Foo<?>>
</code></pre>
<p>The same goes for:</p>
<pre><code>Vector<Foo> vector;
if (...)
vector = giveBar();
else
vector = giveBoo();
</code></pre>
<p>Is a superclass that both Bar and Boo extend the only solution to this problem?</p>
|
[
{
"answer_id": 258623,
"author": "Marcus Downing",
"author_id": 1000,
"author_profile": "https://Stackoverflow.com/users/1000",
"pm_score": 4,
"selected": true,
"text": "Vector<A> vector = new Vector<B>();\n Vector<Vector<?>> vector = new Vector<Vector<String>>();\nvector.add(new Vector<Integer>());\n Vector<?> Vector<Integer> Vector<String> Vector LinkedList ArrayList"
},
{
"answer_id": 258633,
"author": "Rasmus Faber",
"author_id": 5542,
"author_profile": "https://Stackoverflow.com/users/5542",
"pm_score": 2,
"selected": false,
"text": "Vector<? extends Foo<?>> vector;\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258529",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
258,534
|
<p>I would like to know what the pros and cons are for using an Anemic Domain Model (see link below).</p>
<p><a href="http://www.martinfowler.com/bliki/AnemicDomainModel.html" rel="noreferrer" title="Fowler Article">Fowler Article</a></p>
|
[
{
"answer_id": 5847282,
"author": "Eric P",
"author_id": 221291,
"author_profile": "https://Stackoverflow.com/users/221291",
"pm_score": 7,
"selected": false,
"text": "public void Order.AddOrderLine(Product product)\n{\n OrderLines.Add(new OrderLine(product));\n}\n public void OrderService.AddOrderLine(Order order, Product product)\n{\n if (!InventoryService.Has(product)\n throw new AddProductException\n\n order.AddOrderLine(product);\n}\n"
},
{
"answer_id": 8744334,
"author": "StripLight",
"author_id": 177769,
"author_profile": "https://Stackoverflow.com/users/177769",
"pm_score": 0,
"selected": false,
"text": "isInThisState()"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10589/"
] |
258,556
|
<p>I am using the <code>OpenArgs</code> parameter to send a value when using <code>DoCmd.OpenForm</code>:</p>
<pre><code>DoCmd.OpenForm "frmSetOther", acNormal, , , acFormAdd, acDialog, "value"
</code></pre>
<p>I then use <code>Me.OpenArgs</code> inside the opened form to grab the <strong><em>value</em></strong>. It sometimes sends a <strong>Null</strong> value instead of the original string. What is wrong?</p>
|
[
{
"answer_id": 258779,
"author": "Philippe Grondier",
"author_id": 11436,
"author_profile": "https://Stackoverflow.com/users/11436",
"pm_score": 3,
"selected": true,
"text": "addPropertyToForm \"formFilter\",\"Tbl_myTable.myField LIKE 'A*'\",myFormName\n Function addPropertyToForm(_ \n x_propertyName as string, _\n x_value As Variant, _\n x_formName As String) \nAs Boolean\n\nOn Error GoTo errManager\nCurrentProject.AllForms(x_formName).Properties(x_propertyName).Value = x_value\naddPropertyToForm = True\nOn Error GoTo 0\n\nExit Function\n\nerrManager:\nIf Err.Number = 2455 Then\n CurrentProject.AllForms(x_formName).Properties.Add x_propertyName, Nz(x_value)\n Resume Next\nElse\n msgbox err.number & \". The property \" & x_propertyName & \"was not created\"\nEnd If\n\nEnd Function \n"
},
{
"answer_id": 258986,
"author": "Mathieu Pagé",
"author_id": 5861,
"author_profile": "https://Stackoverflow.com/users/5861",
"pm_score": 5,
"selected": false,
"text": "if not isnull(me.OpenArgs) then\n myvalue = me.OpenArgs\nelse\n msgbox \"Debug mode\"\n myValue = \"foo\"\nendif\n"
},
{
"answer_id": 12879186,
"author": "George Elam",
"author_id": 1744325,
"author_profile": "https://Stackoverflow.com/users/1744325",
"pm_score": 3,
"selected": false,
"text": "Arg Null string error Docmd.Close acReport, \"myReport\"\n"
},
{
"answer_id": 46089882,
"author": "Henrik Erlandsson",
"author_id": 343825,
"author_profile": "https://Stackoverflow.com/users/343825",
"pm_score": 1,
"selected": false,
"text": "Private Sub Form_Open(Cancel As Integer)\n If Not IsNull(Me.OpenArgs) Then\n Me.lblHeading.Caption = Me.OpenArgs\n End If\nEnd Sub\n"
}
] |
2008/11/03
|
[
"https://Stackoverflow.com/questions/258556",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15884/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.