qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
100,820
|
<p>I have a JSF woodstock table with checkboxes. When a row is selected I want to do some processing with those items. I managed to get a selection of RowKey objects but can't find out how to get the original objects I put in back. The table is populated by an ObjectListDataProvider.</p>
|
[
{
"answer_id": 3472860,
"author": "Nikordaris",
"author_id": 300269,
"author_profile": "https://Stackoverflow.com/users/300269",
"pm_score": 0,
"selected": false,
"text": "<ui:radioButton id=\"radioButton1\" name=\"radioButton-group1\" valueChangeListener=\"#{MyBeanPage.radioButton1_processValueChange}\" />\n public void radioButton1_processValueChange(ValueChangeEvent event) {\n TableRowDataProvider trdp = (TableRowDataProvider)getValue(\"#{currentRow}\");\n setCurrentRowKey(trdp.getTableRow()); //Sets an instance variable for the RowKey\n}\n /*getObjectListDataProviderImpl() returns the implementation of \n *ObjectListDataProvider for your dynamic data.\n */\ngetObjectListDataProviderImpl().getObject(getCurrentRowKey()); \n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18702/"
] |
100,824
|
<p>The code below shows a sample that I've used recently to explain the different behaviour of structs and classes to someone brand new to development. Is there a better way of doing so? (Yes - the code uses public fields - that's purely for brevity)</p>
<pre><code>namespace StructsVsClasses
{
class Program
{
static void Main(string[] args)
{
sampleStruct struct1 = new sampleStruct();
struct1.IntegerValue = 3;
Console.WriteLine("struct1.IntegerValue: {0}", struct1.IntegerValue);
sampleStruct struct2 = struct1;
Console.WriteLine();
Console.WriteLine("struct1.IntegerValue: {0}", struct1.IntegerValue);
Console.WriteLine("struct2.IntegerValue: {0}", struct2.IntegerValue);
struct1.IntegerValue = 5;
Console.WriteLine();
Console.WriteLine("struct1.IntegerValue: {0}", struct1.IntegerValue);
Console.WriteLine("struct2.IntegerValue: {0}", struct2.IntegerValue);
sampleClass class1 = new sampleClass();
class1.IntegerValue = 3;
Console.WriteLine();
Console.WriteLine("class1.IntegerValue: {0}", class1.IntegerValue);
sampleClass class2 = class1;
Console.WriteLine();
Console.WriteLine("class1.IntegerValue: {0}", class1.IntegerValue);
Console.WriteLine("class2.IntegerValue: {0}", class2.IntegerValue);
class1.IntegerValue = 5;
Console.WriteLine();
Console.WriteLine("class1.IntegerValue: {0}", class1.IntegerValue);
Console.WriteLine("class2.IntegerValue: {0}", class2.IntegerValue);
Console.ReadKey();
}
}
struct sampleStruct
{
public int IntegerValue;
}
class sampleClass
{
public int IntegerValue;
}
}
</code></pre>
|
[
{
"answer_id": 101153,
"author": "Hallgrim",
"author_id": 15454,
"author_profile": "https://Stackoverflow.com/users/15454",
"pm_score": 2,
"selected": true,
"text": "class PointClass {\n int double X;\n int double Y;\n}\n\nclass Circle {\n PointClass Center = new PointClass() { X = 0, Y = 0; }\n}\n\nstatic void Main() {\n Circle c = new Circle();\n Console.WriteLine(c.Center.X);\n c.Center.X = 42;\n Console.WriteLine(c.Center.X);\n}\n 0\n42\n struct Point {\n int double X;\n int double Y;\n}\n\nclass Circle {\n PointStruct Center = new PointStruct() { X = 0, Y = 0; }\n}\n\nstatic void Main() {\n Circle c = new Circle();\n Console.WriteLine(c.Center.X);\n c.Center.X = 42;\n Console.WriteLine(c.Center.X);\n}\n 0\n0\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7872/"
] |
100,829
|
<p>I'm trying to write a script to allow me to log in to a console servers 48 ports so that I can quickly determine what devices are connected to each serial line.</p>
<p>Essentially I want to be able to have a script that, given a list of hosts/ports, telnets to the first device in the list and leaves me in interactive mode so that I can log in and confirm the device, then when I close the telnet session, connects to the next session in the list.</p>
<p>The problem I'm facing is that if I start a telnet session from within an executable bash script, the session terminates immediately, rather than waiting for input.</p>
<p>For example, given the following code:</p>
<pre><code>$ cat ./telnetTest.sh
#!/bin/bash
while read line
do
telnet $line
done
$
</code></pre>
<p>When I run the command 'echo "hostname" | testscript.sh' I receive the following output:</p>
<pre><code>$ echo "testhost" | ./telnetTest.sh
Trying 192.168.1.1...
Connected to testhost (192.168.1.1).
Escape character is '^]'.
Connection closed by foreign host.
$
</code></pre>
<p>Does anyone know of a way to stop the telnet session being closed automatically?</p>
|
[
{
"answer_id": 100879,
"author": "user11323",
"author_id": 11323,
"author_profile": "https://Stackoverflow.com/users/11323",
"pm_score": 3,
"selected": false,
"text": "#!/usr/bin/expect -f\nspawn telnet $host_name\nexpect {\n \"T0>\" {}\n -re \"Connection refused|No route to host|Invalid argument|lookup failure\"\n {send_user \"\\r******* connection error, bye.\\n\";exit}\n default {send_user \"\\r******* connection error (telnet timeout),\n bye.\\n\";exit}\n}\nsend \"command\\n\"\nexpect -timeout 1 \"something\"\n"
},
{
"answer_id": 100897,
"author": "mweerden",
"author_id": 4285,
"author_profile": "https://Stackoverflow.com/users/4285",
"pm_score": 0,
"selected": false,
"text": "telnet echo echo telnet echo \"testhost\" { echo \"testhost\"; cat; } telnet netcat"
},
{
"answer_id": 101016,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 4,
"selected": true,
"text": "telnet /dev/tty #!/bin/bash\n\nfor HOST in `cat`\ndo\n echo Connecting to $HOST...\n telnet $HOST </dev/tty\ndone\n"
},
{
"answer_id": 101819,
"author": "stephanea",
"author_id": 8776,
"author_profile": "https://Stackoverflow.com/users/8776",
"pm_score": 0,
"selected": false,
"text": "for i in adele betty\ndo\nssh all@$i\ndone\n"
},
{
"answer_id": 102126,
"author": "Murali Suriar",
"author_id": 6306,
"author_profile": "https://Stackoverflow.com/users/6306",
"pm_score": 1,
"selected": false,
"text": "#!/bin/bash\n\nTTY=`tty` # Find out what tty we have been invoked from.\nfor i in `cat hostnames.csv` # List of hosts/ports\ndo\n # Separate port/host into separate variables\n host=`echo $i | awk -F, '{ print $1 }'`\n port=`echo $i | awk -F, '{ print $2 }'`\n telnet $host $port < $TTY # Connect to the current device\ndone\n"
},
{
"answer_id": 1661098,
"author": "Prashant Ghodke",
"author_id": 200933,
"author_profile": "https://Stackoverflow.com/users/200933",
"pm_score": 1,
"selected": false,
"text": "Test3.sh #!/bin/sh\n\n#SSG_details is file from which script will read ip adress and uname/password\n#to telnet.\n\nSSG_detail=/opt/Telnet/SSG_detail.txt\n\ncat $SSG_detail | while read ssg_det ; do\n\n ssg_ip=`echo $ssg_det|awk '{print $1}'`\n ssg_user=`echo $ssg_det|awk '{print $2}'`\n ssg_pwd=`echo $ssg_det|awk '{print $3}'`\n\n\n echo \" IP to telnet:\" $ssg_ip\n echo \" ssg_user:\" $ssg_user\n echo \" ssg_pwd:\" $ssg_pwd\n\n sh /opt/Telnet/Call_Telenet.sh $ssg_ip $ssg_user $ssg_pwd \n\ndone\n\n\nexit 0\n Call_Telenet.sh #!/bin/sh\n\nDELAY=1 \nCOMM1='config t' #/* 1st commands to be run*/\nCOMM2='show run'\nCOMM3=''\nCOMM4=''\nCOMM5='exit'\nCOMM6='wr'\nCOMM7='ssg service-cache refresh all'\nCOMM8='exit' #/* 8th command to be run */\n\n\ntelnet $1 >> $logfile 2>> $logfile |&\nsleep $DELAY\necho -p $2 >> $logfile 2>> $logfile\nsleep $DELAY\necho -p $3 >> $logfile 2>> $logfile\nsleep $DELAY\necho -p $4 >> $logfile 2>> $logfile\nsleep $DELAY\necho -p $5 >> $logfile 2>> $logfile\nsleep $DELAY\n\nsleep $DELAY\nsleep $DELAY\nsleep $DELAY\necho -p $COMM7 >> $logfile 2>> $logfile\nsleep $DELAY\necho -p $COMM8 >> $logfile 2>> $logfile\nsleep $DELAY\n\nexit 0\n $> ./test3.sh \n"
},
{
"answer_id": 1661161,
"author": "mouviciel",
"author_id": 45249,
"author_profile": "https://Stackoverflow.com/users/45249",
"pm_score": 0,
"selected": false,
"text": "xterm -e telnet $host $port\n"
},
{
"answer_id": 7426783,
"author": "Graham",
"author_id": 946149,
"author_profile": "https://Stackoverflow.com/users/946149",
"pm_score": 0,
"selected": false,
"text": "#!/bin/sh\n( echo open hostname\nsleep 5\necho username\nsleep 1\necho password\nsleep 1\necho some more output, etc. ) | telnet\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6306/"
] |
100,841
|
<p>I've had a bug in our software that occurs when I receive a connection timeout. These errors are very rare (usually when my connection gets dropped by our internal network). How can I generate this kind of effect artificially so I can test our software? </p>
<p>If it matters the app is written in C++/MFC using CAsyncSocket classes.</p>
<p><strong>Edit:</strong></p>
<p>I've tried using a non-existent host, and I get the socket error:</p>
<blockquote>
<p>WSAEINVAL (10022) Invalid argument</p>
</blockquote>
<p>My next attempt was to use <a href="https://stackoverflow.com/questions/100841?sort=oldest#100859">Alexander</a>'s suggestion of connecting to a different port, e.g. 81 (on my own server though). That worked great. Exactly the same as a dropped connection (60 second wait, then error). Thank you!</p>
|
[
{
"answer_id": 16048032,
"author": "Henrik Heimbuerger",
"author_id": 6278,
"author_profile": "https://Stackoverflow.com/users/6278",
"pm_score": 4,
"selected": false,
"text": "Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import socket\n>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) \n>>> s.bind(('localhost', 9000))\n>>> s.listen(0)\n>>> (clientsocket, address) = s.accept()\n localhost:9000 accept() clientsocket recv()"
},
{
"answer_id": 21905365,
"author": "amenthes",
"author_id": 2413043,
"author_profile": "https://Stackoverflow.com/users/2413043",
"pm_score": 3,
"selected": false,
"text": "200:b@100:dr"
},
{
"answer_id": 37465639,
"author": "Tom Chamberlain",
"author_id": 1708697,
"author_profile": "https://Stackoverflow.com/users/1708697",
"pm_score": 6,
"selected": false,
"text": "nc -l 8099\n"
},
{
"answer_id": 39441583,
"author": "Timothy Moody",
"author_id": 1359863,
"author_profile": "https://Stackoverflow.com/users/1359863",
"pm_score": 2,
"selected": false,
"text": "{\n \"timeout_length\": 15000\n}\n {\n \"response\": \"ok\"\n}\n"
},
{
"answer_id": 40459270,
"author": "speedplane",
"author_id": 234270,
"author_profile": "https://Stackoverflow.com/users/234270",
"pm_score": 6,
"selected": false,
"text": "example.com:81 google.com:81 example.com"
},
{
"answer_id": 55386474,
"author": "jdi",
"author_id": 496445,
"author_profile": "https://Stackoverflow.com/users/496445",
"pm_score": 1,
"selected": false,
"text": "ssh -L 12345:realserver.com:80 localhost\n ssh -L 12345:localhost:8080 localhost\n"
},
{
"answer_id": 56459603,
"author": "AndyTheEntity",
"author_id": 2047472,
"author_profile": "https://Stackoverflow.com/users/2047472",
"pm_score": 7,
"selected": false,
"text": "https://httpstat.us/504?sleep=60000"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100841",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/986/"
] |
100,853
|
<p>While editing an aspx file I found both these opening tags used for seemingly the same thing. Is there a difference and if yes, what is it?</p>
|
[
{
"answer_id": 100888,
"author": "Johannes Hädrich",
"author_id": 18246,
"author_profile": "https://Stackoverflow.com/users/18246",
"pm_score": 5,
"selected": true,
"text": "<%= <% Repsonse.Write() <%=myProperty + \" additional Text\" %>\n <%#"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5018/"
] |
100,854
|
<p>I have C++ project (VS2005) which includes header file with version number in #define directive. Now I need to include exactly the same number in twin C# project. What is the best way to do it?</p>
<p>I'm thinking about including this file as a resource, then parse it at a runtime with regex to recover version number, but maybe there's a better way, what do you think?</p>
<p>I cannot move version outside .h file, also build system depends on it and the C# project is one which should be adapted.</p>
|
[
{
"answer_id": 100913,
"author": "Skizz",
"author_id": 1898,
"author_profile": "https://Stackoverflow.com/users/1898",
"pm_score": 2,
"selected": false,
"text": "// version header file\n#define Version \"1.01\"\n\n// C# code\n#include \"version.h\"\n// somewhere in a class\nstring version = Version;\n // C# code\n// somewhere in a class\nstring version = \"1.01\";\n"
},
{
"answer_id": 254653,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 0,
"selected": false,
"text": "# translate the #defines in messages.h file into consts in MessagesDotH.cs\n\nimport re\nimport os\nimport stat\n\ndef convert_h_to_cs(fin, fout):\n for line in fin:\n m = re.match(r\"^#define (.*) \\\"(.*)\\\"\", line)\n if m != None:\n if m.group() != None:\n fout.write( \"public const string \" \\\n + m.group(1) \\\n + \" = \\\"\" \\\n + m.group(2) \\\n + \"\\\";\\n\" )\n if re.match(r\"^//\", line) != None:\n fout.write(line)\n\nfin = open ('..\\common_cpp\\messages.h')\nfout = open ('..\\user_setup\\MessagesDotH.cs.tmp','w')\n\nfout.write( 'using System;\\n' )\nfout.write( 'namespace xrisk { class MessagesDotH {\\n' )\n\nconvert_h_to_cs(fin, fout)\n\nfout.write( '}}' )\n\nfout.close()\n\ns1 = open('..\\user_setup\\MessagesDotH.cs.tmp').read()\n\ns2 = open('..\\user_setup\\MessagesDotH.cs').read()\n\nif s1 != s2:\n os.chmod('..\\user_setup\\MessagesDotH.cs', stat.S_IWRITE)\n print 'deleting old MessagesDotH.cs'\n os.remove('..\\user_setup\\MessagesDotH.cs')\n print 'remaming tmp to MessagesDotH.cs'\n os.rename('..\\user_setup\\MessagesDotH.cs.tmp','..\\user_setup\\MessagesDotH.cs')\nelse:\n print 'no differences. using same MessagesDotH.cs'\n"
},
{
"answer_id": 5638890,
"author": "gbjbaanb",
"author_id": 13744,
"author_profile": "https://Stackoverflow.com/users/13744",
"pm_score": 3,
"selected": false,
"text": "<#@ template language=\"C#v3.5\" hostspecific=\"True\" debug=\"True\" #>\n<#@ output extension=\"cs\" #>\n<#@ assembly name=\"System.Core.dll\" #>\n<#@ import namespace=\"System\" #>\n<#@ import namespace=\"System.Collections.Generic\" #>\n<#@ import namespace=\"System.IO\" #>\n\n<#\nstring input_file = this.Host.ResolvePath(\"resource.h\"); <---- change this\nStreamReader defines = new StreamReader(input_file);\n#>\n//------------------------------------------------------------------------------\n// This code was generated by template for T4\n// Generated at <#=DateTime.Now#>\n//------------------------------------------------------------------------------\n\nnamespace Constants\n{\n public class <#=System.IO.Path.GetFileNameWithoutExtension(input_file)#>\n {\n<#\n // constants definitions\n\n while (defines.Peek() >= 0)\n {\n string def = defines.ReadLine();\n string[] parts;\n if (def.Length > 3 && def.StartsWith(\"#define\"))\n {\n parts = def.Split(null as char[], StringSplitOptions.RemoveEmptyEntries);\n try {\n Int32 numval = Convert.ToInt32(parts[2]);\n #>\n public static const int <#=parts[1]#> = <#=parts[2]#>;\n<#\n }\n catch (FormatException e) {\n #>\n public static const string <#=parts[1]#> = \"<#=parts[2]#>\";\n<#\n }\n }\n } #> \n }\n}\n"
},
{
"answer_id": 36436268,
"author": "JKoplo",
"author_id": 2125462,
"author_profile": "https://Stackoverflow.com/users/2125462",
"pm_score": 1,
"selected": false,
"text": "<#@ template language=\"C#\" hostspecific=\"True\" debug=\"True\" #>\n<#@ output extension=\"cs\" #>\n<#@ assembly name=\"System.Core.dll\" #>\n<#@ import namespace=\"System\" #>\n<#@ import namespace=\"System.Collections.Generic\" #>\n<#@ import namespace=\"System.IO\" #>\n<#\nstring hPath = Host.ResolveAssemblyReference(\"$(ProjectDir)\") + \"ProgramData\\\\DeltaTau\\\\\"; \nstring[] hFiles = System.IO.Directory.GetFiles(hPath, \"*.h\", System.IO.SearchOption.AllDirectories);\nvar namespaceName = System.Runtime.Remoting.Messaging.CallContext.LogicalGetData(\"NamespaceHint\");\n#>\n//------------------------------------------------------------------------------\n// This code was generated by template for T4\n// Generated at <#=DateTime.Now#>\n//------------------------------------------------------------------------------\n\nnamespace <#=namespaceName#>\n{\n<#foreach (string input_file in hFiles)\n{\nStreamReader defines = new StreamReader(input_file);\n#>\n public class <#=System.IO.Path.GetFileNameWithoutExtension(input_file)#>\n {\n<# // constants definitions\n\n while (defines.Peek() >= 0)\n {\n string def = defines.ReadLine();\n string[] parts;\n if (def.Length > 3 && def.StartsWith(\"#define\"))\n {\n def = def.TrimEnd(';');\n parts = def.Split(null as char[], StringSplitOptions.RemoveEmptyEntries);\n Int32 intVal;\n double dblVal;\n if (Int32.TryParse(parts[2], out intVal))\n {\n #>\n public static readonly int <#=parts[1]#> = <#=parts[2]#>; \n<#\n }\n else if (Double.TryParse(parts[2], out dblVal))\n {\n #>\n public static readonly double <#=parts[1]#> = <#=parts[2]#>; \n<#\n }\n else\n {\n #>\n public static readonly string <#=parts[1]#> = \"<#=parts[2]#>\";\n<# \n }\n }\n } #>\n }\n<#}#> \n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7162/"
] |
100,860
|
<p>As most of you would know, if I drop a file named app_offline.htm in the root of an asp.net application, it takes the application offline <a href="http://asp-net-whidbey.blogspot.com/2006/04/aspnet-20-features-appofflinehtm.html" rel="nofollow noreferrer">as detailed here</a>.</p>
<p>You would also know, that while this is great, IIS actually returns a 404 code when this is in process and Microsoft is not going to do anything about it <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=319986" rel="nofollow noreferrer">as mentioned here</a>.</p>
<p>Now, since Asp.Net in general is so extensible, I am thinking that shouldn't there be a way to over ride this status code to return a 503 instead? The problem is, I don't know where to start looking to make this change.</p>
<p>HELP!</p>
|
[
{
"answer_id": 100881,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 1,
"selected": false,
"text": "<httpRuntime enable = \"False\"/>\n"
},
{
"answer_id": 100928,
"author": "mdb",
"author_id": 8562,
"author_profile": "https://Stackoverflow.com/users/8562",
"pm_score": 4,
"selected": true,
"text": "CheckApplicationEnabled() HttpRuntime.cs Public Sub ProcessRequest(ByVal ctx As System.Web.HttpContext) Implements IHttpHandler.ProcessRequest\n If IO.File.Exists(ctx.Server.MapPath(\"/app_unavailable.htm\")) Then\n ctx.Response.Status = \"503 Unavailable (in Maintenance Mode)\"\n ctx.Response.Write(String.Format(\"<html><h1>{0}</h1></html>\", ctx.Response.Status))\n ctx.Response.End()\n End If\nEnd Sub\n"
},
{
"answer_id": 5729751,
"author": "Glen",
"author_id": 484110,
"author_profile": "https://Stackoverflow.com/users/484110",
"pm_score": 0,
"selected": false,
"text": "<httpRuntime enable=\"false\" />\n<customErrors mode=\"On\" defaultRedirect=\"/maintainance.aspx\"/>\n <%@Page Language=\"C#\"%>\n<% \n Response.StatusCode = 503;\n Response.Write(\"App offline for maintainance\"); \n%>\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/380/"
] |
100,898
|
<p>What's the best / simplest / most accurate way to detect the browser of a user?</p>
<p>Ease of extendability and implementation is a plus.</p>
<p>The less technologies used, the better.</p>
<p>The solution can be server side, client side, or both. The results should eventually end up at the server, though.</p>
<p>The solution can be framework agnostic.</p>
<p>The solution will only be used for reporting purposes.</p>
|
[
{
"answer_id": 100908,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 3,
"selected": false,
"text": "$.browser alert($.browser.name); // Alerts Firefox for me\n"
},
{
"answer_id": 100918,
"author": "Twan",
"author_id": 6702,
"author_profile": "https://Stackoverflow.com/users/6702",
"pm_score": 1,
"selected": false,
"text": "define(\"BROWSER_OPERA\",\"Opera\");\ndefine(\"BROWSER_IE\",\"IE\");\ndefine(\"BROWSER_OMNIWEB\",\"Omniweb\");\ndefine(\"BROWSER_KONQUEROR\",\"Konqueror\");\ndefine(\"BROWSER_SAFARI\",\"Safari\");\ndefine(\"BROWSER_MOZILLA\",\"Mozilla\");\ndefine(\"BROWSER_OTHER\",\"other\");\n\n$aBrowsers = array\n(\n array(\"regexp\" => \"@Opera(/| )([0-9].[0-9]{1,2})@\", \"browser\" => BROWSER_OPERA, \"index\" => 2),\n array(\"regexp\" => \"@MSIE ([0-9].[0-9]{1,2})@\", \"browser\" => BROWSER_IE, \"index\" => 1),\n array(\"regexp\" => \"@OmniWeb/([0-9].[0-9]{1,2})@\", \"browser\" => BROWSER_OMNIWEB, \"index\" => 1),\n array(\"regexp\" => \"@(Konqueror/)(.*)(;)@\", \"browser\" => BROWSER_KONQUEROR, \"index\" => 2),\n array(\"regexp\" => \"@Safari/([0-9]*)@\", \"browser\" => BROWSER_SAFARI, \"index\" => 1),\n array(\"regexp\" => \"@Mozilla/([0-9].[0-9]{1,2})@\", \"browser\" => BROWSER_MOZILLA, \"index\" => 1)\n);\n\nforeach($aBrowsers as $aBrowser)\n{\n if (preg_match($aBrowser[\"regexp\"], $_SERVER[\"HTTP_USER_AGENT\"], $aBrowserVersion))\n {\n define(\"BROWSER_AGENT\",$aBrowser[\"browser\"]);\n define(\"BROWSER_VERSION\",$aBrowserVersion[$aBrowser[\"index\"]]);\n break;\n }\n}\n"
},
{
"answer_id": 100925,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 5,
"selected": true,
"text": "if (element.setCapture) element.setCapture()\n"
},
{
"answer_id": 100947,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 2,
"selected": false,
"text": "\"typeof foo == 'undefined'\""
},
{
"answer_id": 105286,
"author": "Toby Mills",
"author_id": 12377,
"author_profile": "https://Stackoverflow.com/users/12377",
"pm_score": -1,
"selected": false,
"text": "<!--[if lte IE 6]><link href=\"/style.css\" rel=\"stylesheet\" type=\"text/css\" /><![endif]-->\n <!--[if eq IE 7]> = Equal too IE 7\n<!--[if gt IE 6]> = Greater than IE 6\n <head>"
},
{
"answer_id": 132928,
"author": "Jrgns",
"author_id": 6681,
"author_profile": "https://Stackoverflow.com/users/6681",
"pm_score": 0,
"selected": false,
"text": "window.addEvent('domready', function() {\n if (BrowserDetect) {\n var q_data = 'ajax=true&browser=' + BrowserDetect.browser + '&version=' + BrowserDetect.version + '&os=' + BrowserDetect.OS;\n var query = 'record_browser.php'\n var req = new Request.JSON({url: query, onComplete: setSelectWithJSON, data: q_data}).post();\n }\n});\n record_browser.php record_browser.php session_id user_id CREATE TABLE `browser_detects` (\n `id` int(11) NOT NULL auto_increment,\n `session` varchar(255) NOT NULL default '',\n `user_id` int(11) NOT NULL default '0',\n `browser` varchar(255) NOT NULL default '',\n `version` varchar(255) NOT NULL default '',\n `os` varchar(255) NOT NULL default '',\n PRIMARY KEY (`id`),\n UNIQUE KEY `sessionUnique` (`session`)\n)\n if ($_SERVER['REQUEST_METHOD'] == 'POST') {\n $session = session_id();\n $user_id = isset($user_id) ? $user_id ? 0;\n $browser = isset($_POST['browser']) ? $_POST['browser'] ? '';\n $version = isset($_POST['version']) ? $_POST['version'] ? '';\n $os = isset($_POST['os']) ? $_POST['os'] ? '';\n $q = $conn->prepare('INSERT INTO browser_detects (`session`, `user`, `browser`, `version`, `os`) VALUES (:session :user, :browser, :version, :os)');\n $q->execute(array(\n ':session' => $session,\n ':user' => $user_id,\n ':browser' => $browser,\n ':version' => $version,\n ':os' => $os\n ));\n}\n"
},
{
"answer_id": 748659,
"author": "scunliffe",
"author_id": 6144,
"author_profile": "https://Stackoverflow.com/users/6144",
"pm_score": 0,
"selected": false,
"text": "<script>\n if('\\v'=='v'){\n alert('I am IE');\n } else {\n alert('NOT IE');\n }\n</script>\n"
},
{
"answer_id": 2999361,
"author": "Chuck Le Butt",
"author_id": 199700,
"author_profile": "https://Stackoverflow.com/users/199700",
"pm_score": 0,
"selected": false,
"text": "<script type=\"text/javascript\">\n // </) || [])[1];\n this.safari = /webkit/.test(userAgent) && !/chrome/.test(userAgent);\n this.opera = /opera/.test(userAgent);\n this.msie = /msie/.test(userAgent) && !/opera/.test(userAgent);\n this.mozilla = /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent);\n this.chrome = /chrome/.test(userAgent);\n }\n }); \n // ]]>\n</script>\n var UserBrowser = new BrowserCheck();\n if ((UserBrowser.msie == true) && (UserBrowser.version == 8))\n"
},
{
"answer_id": 4650781,
"author": "SoftwareARM",
"author_id": 570304,
"author_profile": "https://Stackoverflow.com/users/570304",
"pm_score": 0,
"selected": false,
"text": "StringBuilder strb = new StringBuilder();\nstrb.AppendFormat ( \"User Agent: {0}{1}\", Request.ServerVariables[\"http_user_agent\"].ToString(), Environment.NewLine );\nstrb.AppendFormat ( \"Browser: {0}{1}\", Request.Browser.Browser.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Version: {0}{1}\", Request.Browser.Version.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Major Version: {0}{1}\", Request.Browser.MajorVersion.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Minor Version: {0}{1}\", Request.Browser.MinorVersion.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Platform: {0}{1}\", Request.Browser.Platform.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"ECMA Script version: {0}{1}\", Request.Browser.EcmaScriptVersion.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Type: {0}{1}\", Request.Browser.Type.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"-------------------------------------------------------------------------------{0}\", Environment.NewLine );\nstrb.AppendFormat ( \"ActiveX Controls: {0}{1}\", Request.Browser.ActiveXControls.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Background Sounds: {0}{1}\", Request.Browser.BackgroundSounds.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"AOL: {0}{1}\", Request.Browser.AOL.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Beta: {0}{1}\", Request.Browser.Beta.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"CDF: {0}{1}\", Request.Browser.CDF.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"ClrVersion: {0}{1}\", Request.Browser.ClrVersion.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Cookies: {0}{1}\", Request.Browser.Cookies.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Crawler: {0}{1}\", Request.Browser.Crawler.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Frames: {0}{1}\", Request.Browser.Frames.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Tables: {0}{1}\", Request.Browser.Tables.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"JavaApplets: {0}{1}\", Request.Browser.JavaApplets.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"JavaScript: {0}{1}\", Request.Browser.JavaScript.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"MSDomVersion: {0}{1}\", Request.Browser.MSDomVersion.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"TagWriter: {0}{1}\", Request.Browser.TagWriter.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"VBScript: {0}{1}\", Request.Browser.VBScript.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"W3CDomVersion: {0}{1}\", Request.Browser.W3CDomVersion.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Win16: {0}{1}\", Request.Browser.Win16.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"Win32: {0}{1}\", Request.Browser.Win32.ToString ( ), Environment.NewLine );\nstrb.AppendFormat ( \"-------------------------------------------------------------------------------{0}\", Environment.NewLine );\nstrb.AppendFormat ( \"MachineName: {0}{1}\", Environment.MachineName, Environment.NewLine );\nstrb.AppendFormat ( \"OSVersion: {0}{1}\", Environment.OSVersion, Environment.NewLine );\nstrb.AppendFormat ( \"ProcessorCount: {0}{1}\", Environment.ProcessorCount, Environment.NewLine );\nstrb.AppendFormat ( \"UserName: {0}{1}\", Environment.UserName, Environment.NewLine );\nstrb.AppendFormat ( \"Version: {0}{1}\", Environment.Version, Environment.NewLine );\nstrb.AppendFormat ( \"UserInteractive: {0}{1}\", Environment.UserInteractive, Environment.NewLine );\nstrb.AppendFormat ( \"UserDomainName: {0}{1}\", Environment.UserDomainName, Environment.NewLine );\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6681/"
] |
100,904
|
<p>Per man pages, snprintf is returning number of bytes written from glibc version 2.2 onwards. But on lower versions of libc2.2 and HP-UX, it returns a positive integer, which could lead to a buffer overflow.</p>
<p>How can one overcome this and write portable code?</p>
<p>Edit : For want of more clarity</p>
<p>This code is working perfectly in lib 2.3</p>
<pre><code> if ( snprintf( cmd, cmdLen + 1, ". %s%s", myVar1, myVar2 ) != cmdLen )
{
fprintf( stderr, "\nError: Unable to copy bmake command!!!");
returnCode = ERR_COPY_FILENAME_FAILED;
}
</code></pre>
<p>It returns the length of the string (10) on Linux. But the same code is returning a positive number that is greater than the number of characters printed on HP-UX machine. Hope this explanation is fine.</p>
|
[
{
"answer_id": 100936,
"author": "finnw",
"author_id": 12048,
"author_profile": "https://Stackoverflow.com/users/12048",
"pm_score": 0,
"selected": false,
"text": "int my_snprintf(char *buf, size_t n, const char *fmt, ...)\n{\n va_list va;\n int nchars;\n FILE *tf = tmpfile();\n\n va_start(va, n);\n nchars = vfprintf(tf, fmt, va);\n if (nchars >= (int) n)\n nchars = (int) n - 1;\n va_end(va);\n memset(buf, 0, 1 + (size_t) nchars);\n\n if (nchars > 0)\n {\n rewind(tf);\n fread(buf, 1, (size_t) nchars, tf);\n }\n\n fclose(tf);\n\n return nchars; \n}\n"
},
{
"answer_id": 100991,
"author": "INS",
"author_id": 13136,
"author_profile": "https://Stackoverflow.com/users/13136",
"pm_score": 3,
"selected": true,
"text": " while (1) {\n /* Try to print in the allocated space. */\n va_start(ap, fmt);\n n = vsnprintf (p, size, fmt, ap);\n va_end(ap);\n /* If that worked, return the string. */\n if (n > -1 && n < size)\n return p;\n /* Else try again with more space. */\n if (n > -1) /* glibc 2.1 */\n size = n+1; /* precisely what is needed */\n else /* glibc 2.0 */\n size *= 2; /* twice the old size */\n if ((np = realloc (p, size)) == NULL) {\n free(p);\n return NULL;\n } else {\n p = np;\n }\n }\n"
},
{
"answer_id": 102484,
"author": "Frosty",
"author_id": 7476,
"author_profile": "https://Stackoverflow.com/users/7476",
"pm_score": 1,
"selected": false,
"text": "int ret = snprintf(cmd, cmdLen + 1, \". %s%s\", myVar1, myVar2 ) == -1)\nif(ret == -1 || ret > cmdLen)\n{\n //output was truncated\n}\nelse\n{\n //everything is groovy\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18657/"
] |
100,917
|
<p>I'm trying to read data from a Delphi DBIV database, every time I access the database it creates a Paradox.lck and a Pdoxusrs.lck file. I'm using only a TQuery Object to do this (nothing else). can I access a Delphi DBIV database without it creating these lock files?</p>
|
[
{
"answer_id": 100936,
"author": "finnw",
"author_id": 12048,
"author_profile": "https://Stackoverflow.com/users/12048",
"pm_score": 0,
"selected": false,
"text": "int my_snprintf(char *buf, size_t n, const char *fmt, ...)\n{\n va_list va;\n int nchars;\n FILE *tf = tmpfile();\n\n va_start(va, n);\n nchars = vfprintf(tf, fmt, va);\n if (nchars >= (int) n)\n nchars = (int) n - 1;\n va_end(va);\n memset(buf, 0, 1 + (size_t) nchars);\n\n if (nchars > 0)\n {\n rewind(tf);\n fread(buf, 1, (size_t) nchars, tf);\n }\n\n fclose(tf);\n\n return nchars; \n}\n"
},
{
"answer_id": 100991,
"author": "INS",
"author_id": 13136,
"author_profile": "https://Stackoverflow.com/users/13136",
"pm_score": 3,
"selected": true,
"text": " while (1) {\n /* Try to print in the allocated space. */\n va_start(ap, fmt);\n n = vsnprintf (p, size, fmt, ap);\n va_end(ap);\n /* If that worked, return the string. */\n if (n > -1 && n < size)\n return p;\n /* Else try again with more space. */\n if (n > -1) /* glibc 2.1 */\n size = n+1; /* precisely what is needed */\n else /* glibc 2.0 */\n size *= 2; /* twice the old size */\n if ((np = realloc (p, size)) == NULL) {\n free(p);\n return NULL;\n } else {\n p = np;\n }\n }\n"
},
{
"answer_id": 102484,
"author": "Frosty",
"author_id": 7476,
"author_profile": "https://Stackoverflow.com/users/7476",
"pm_score": 1,
"selected": false,
"text": "int ret = snprintf(cmd, cmdLen + 1, \". %s%s\", myVar1, myVar2 ) == -1)\nif(ret == -1 || ret > cmdLen)\n{\n //output was truncated\n}\nelse\n{\n //everything is groovy\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100917",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
100,948
|
<p>I installed MySQL via <a href="http://en.wikipedia.org/wiki/MacPorts" rel="noreferrer">MacPorts</a>. What is the command I need to stop the server (I need to test how my application behave when MySQL is dead)?</p>
|
[
{
"answer_id": 100953,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 4,
"selected": false,
"text": "sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop\n"
},
{
"answer_id": 100958,
"author": "Bartosz Blimke",
"author_id": 18715,
"author_profile": "https://Stackoverflow.com/users/18715",
"pm_score": 1,
"selected": false,
"text": "sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql.plist \n sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5-devel.plist \n mysql5-devel"
},
{
"answer_id": 100970,
"author": "John Montgomery",
"author_id": 5868,
"author_profile": "https://Stackoverflow.com/users/5868",
"pm_score": 2,
"selected": false,
"text": "ps -Af\n kill <pid> <pid>"
},
{
"answer_id": 102094,
"author": "mloughran",
"author_id": 18751,
"author_profile": "https://Stackoverflow.com/users/18751",
"pm_score": 10,
"selected": true,
"text": "brew services start mysql\nbrew services stop mysql\nbrew services restart mysql\n sudo port load mysql57-server\nsudo port unload mysql57-server\n sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop\nsudo /Library/StartupItems/MySQLCOM/MySQLCOM start\nsudo /Library/StartupItems/MySQLCOM/MySQLCOM restart\n"
},
{
"answer_id": 2052686,
"author": "katy lavallee",
"author_id": 111362,
"author_profile": "https://Stackoverflow.com/users/111362",
"pm_score": 4,
"selected": false,
"text": "sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper stop"
},
{
"answer_id": 3524087,
"author": "zack",
"author_id": 126600,
"author_profile": "https://Stackoverflow.com/users/126600",
"pm_score": 4,
"selected": false,
"text": "sudo <path to mysql>/support-files/mysql.server start\nsudo <path to mysql>/support-files/mysql.server stop\n sudo /Library/StartupItems/MySQLCOM/MySQLCOM start\nsudo /Library/StartupItems/MySQLCOM/MySQLCOM stop<br>\nsudo /Library/StartupItems/MySQLCOM/MySQLCOM restart\n sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist\n"
},
{
"answer_id": 6533179,
"author": "Allisone",
"author_id": 317083,
"author_profile": "https://Stackoverflow.com/users/317083",
"pm_score": 2,
"selected": false,
"text": "sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist\nsudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist\n"
},
{
"answer_id": 8913870,
"author": "pjammer",
"author_id": 156561,
"author_profile": "https://Stackoverflow.com/users/156561",
"pm_score": 7,
"selected": false,
"text": "/usr/local/bin/mysql.server start\n /usr/local/bin/mysql.server restart\n /usr/local/bin/mysql.server stop\n"
},
{
"answer_id": 14849461,
"author": "Manuel_B",
"author_id": 1059979,
"author_profile": "https://Stackoverflow.com/users/1059979",
"pm_score": 0,
"selected": false,
"text": "sudo launchctl unload -w /opt/local/etc/LaunchDaemons/org.macports.mysql55-server/org.macports.mysql55-server.plist\n sudo launchctl unload -w /opt/local/etc/LaunchDaemons/org.macports.mysql5/org.macports.mysql5.plist \n ps ax | grep mysql\n sudo tail -n 100 /opt/local/var/db/mysql55/<MyName>-MacBook-Pro.local.err\n...\n130213 08:56:41 mysqld_safe mysqld from pid file /opt/local/var/db/mysql55/<MyName>-MacBook-Pro.local.pid ended\n sudo tail -n 100 /opt/local/var/db/mysql5/<MyName>-MacBook-Pro.local.err\n...\n130213 09:23:57 mysqld ended\n"
},
{
"answer_id": 17525998,
"author": "Steve",
"author_id": 1433158,
"author_profile": "https://Stackoverflow.com/users/1433158",
"pm_score": 4,
"selected": false,
"text": "sudo mysqladmin shutdown --user=*user* --password=*password*\n"
},
{
"answer_id": 33144436,
"author": "sweetfa",
"author_id": 490614,
"author_profile": "https://Stackoverflow.com/users/490614",
"pm_score": 2,
"selected": false,
"text": "launchctl unload /System/Library/LaunchDaemons/org.mysql.mysqld.plist\n"
},
{
"answer_id": 36145691,
"author": "Duc Chi",
"author_id": 5849920,
"author_profile": "https://Stackoverflow.com/users/5849920",
"pm_score": 3,
"selected": false,
"text": "sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist\nsudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysql.plist\n"
},
{
"answer_id": 37211622,
"author": "Jan",
"author_id": 977017,
"author_profile": "https://Stackoverflow.com/users/977017",
"pm_score": 6,
"selected": false,
"text": "homebrew brew services restart mysql\nbrew services start mysql\nbrew services stop mysql\n brew services list\n"
},
{
"answer_id": 51239170,
"author": "bronze man",
"author_id": 1586797,
"author_profile": "https://Stackoverflow.com/users/1586797",
"pm_score": 1,
"selected": false,
"text": "mv /usr/local/Cellar/mysql/5.7.16/bin/mysqld /usr/local/Cellar/mysql/5.7.16/bin/mysqld.bak\nmysql.server stop\n Jul 9 14:10:54 xxx com.apple.xpc.launchd[1] (homebrew.mxcl.mysql[78049]): Service exited with abnormal code: 1\nJul 9 14:10:54 xxx com.apple.xpc.launchd[1] (homebrew.mxcl.mysql): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.\n"
},
{
"answer_id": 61183721,
"author": "Abhijeet Khangarot",
"author_id": 7088648,
"author_profile": "https://Stackoverflow.com/users/7088648",
"pm_score": 5,
"selected": false,
"text": "brew stop"
},
{
"answer_id": 63554833,
"author": "Szekelygobe",
"author_id": 6792829,
"author_profile": "https://Stackoverflow.com/users/6792829",
"pm_score": 0,
"selected": false,
"text": "/usr/local/mysql/support-files/mysql.server start /usr/local/mysql/support-files/mysql.server restart /usr/local/mysql/support-files/mysql.server stop"
},
{
"answer_id": 65072168,
"author": "codeaprendiz",
"author_id": 5761011,
"author_profile": "https://Stackoverflow.com/users/5761011",
"pm_score": 2,
"selected": false,
"text": "sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysql.plist\n sudo pkill mysqld\n"
},
{
"answer_id": 68468566,
"author": "Gediminas",
"author_id": 1412149,
"author_profile": "https://Stackoverflow.com/users/1412149",
"pm_score": 2,
"selected": false,
"text": "ls /Library/LaunchDaemons | grep mysql\n sudo launchctl unload /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist\n MacOS Settings > MySQL > Stop MySQL Server \n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7473/"
] |
100,959
|
<p>I am aware of <a href="http://cocoamysql.sourceforge.net/" rel="noreferrer">CocoaMySQL</a> but I have not seen a Mac GUI for SQLite, is there one?</p>
<p>My Google search didn't turn up any Mac related GUI's which is why I'm asking here rather than Google.</p>
|
[
{
"answer_id": 10430316,
"author": "Joony",
"author_id": 448287,
"author_profile": "https://Stackoverflow.com/users/448287",
"pm_score": 7,
"selected": false,
"text": "Application supports iTunes file sharing"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1384652/"
] |
100,976
|
<p>I have an application in which a gecko browser is embedded. The application is crashing when I try to access any https url's because nss is not properly initialised at this point. The crash is in PK11_TokenExists(). I want to block my browser from rendering https sites. If a user clicks on a https link I can block that load in OnStartURI() of nsIURIContentListener.But if the user types in say orkut.com I wont know in OnStartURI() whether its a http url or a https one(i.e. whether it will use SSL or not). I wanted to know how I can block https url's in such cases? </p>
<p>Thanks
jbsp72</p>
|
[
{
"answer_id": 2418646,
"author": "NineBerry",
"author_id": 101087,
"author_profile": "https://Stackoverflow.com/users/101087",
"pm_score": 1,
"selected": false,
"text": "OnStateChange nsIWebProgressListener aStateFlags STATE_IS_DOCUMENT STATE_START aRequest nsIRequest nsIChannel URI cancel aRequest NS_BINDING_ABORTED"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100976",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
100,990
|
<p>How could I get the Fault Detail sent by a SoapFaultClientException ?
I use a WebServiceTemplate as shown below :</p>
<pre><code>WebServiceTemplate ws = new WebServiceTemplate();
ws.setMarshaller(client.getMarshaller());
ws.setUnmarshaller(client.getUnMarshaller());
try {
MyResponse resp = (MyResponse) = ws.marshalSendAndReceive(WS_URI, req);
} catch (SoapFaultClientException e) {
SoapFault fault = e.getSoapFault();
SoapFaultDetail details = e.getSoapFault().getFaultDetail();
//details always NULL ? Bug?
}
</code></pre>
<p>The Web Service Fault sent seems correct :</p>
<pre><code><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>Validation error</faultstring>
<faultactor/>
<detail>
<ws:ValidationError xmlns:ws="http://ws.x.y.com">ERR_UNKNOWN</ws:ValidationError>
</detail>
</soapenv:Fault>
</soapenv:Body>
</code></pre>
<p></p>
<p>Thanks</p>
<p>Willome</p>
|
[
{
"answer_id": 11082098,
"author": "holmis83",
"author_id": 1463522,
"author_profile": "https://Stackoverflow.com/users/1463522",
"pm_score": 3,
"selected": false,
"text": "private Element getDetail(SoapFaultClientException e) throws TransformerException {\n TransformerFactory transformerFactory = TransformerFactory.newInstance();\n Transformer transformer = transformerFactory.newTransformer();\n DOMResult result = new DOMResult();\n transformer.transform(e.getSoapFault().getSource(), result);\n NodeList nl = ((Document)result.getNode()).getElementsByTagName(\"detail\");\n return (Element)nl.item(0);\n}\n"
},
{
"answer_id": 37047393,
"author": "Premek",
"author_id": 1151925,
"author_profile": "https://Stackoverflow.com/users/1151925",
"pm_score": 3,
"selected": false,
"text": "WebServiceTemplate webServiceTemplate = getWebServiceTemplate();\nwebServiceTemplate.setCheckConnectionForFault(false);\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100990",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18714/"
] |
100,993
|
<p>I'm new to both Web Services and RMI and I wonder which is the better way to do remoting between different web applications, when these applications are all written in Java, that is when different programming languages don't matter (which would be the advantage of WS).</p>
<p>While on the one hand I would guess that there's a performance overhead when using web services (does anyone have some numbers to prove that?), on the other hand it seems to me that web services are much more loosely coupled and can be used to implement a more service-oriented architecture (SOA) (which isn't possible with RMI, right?).</p>
<p>Although this is quite a general question, what's your opinion?</p>
<p>Thanks</p>
|
[
{
"answer_id": 36574041,
"author": "Steve O 1969",
"author_id": 5605103,
"author_profile": "https://Stackoverflow.com/users/5605103",
"pm_score": 1,
"selected": false,
"text": "org.springframework.remoting.rmi.RmiServiceExporter\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/100993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18722/"
] |
101,012
|
<p>Our rails app is designed as a single code base linking to multiple client databases. Based on the subdomain the app determines which db to connect to.</p>
<p>We use liquid templates to customise the presentation for each client. We are unable to customise the generic 'We're Sorry, somethign went wrong..' message for each client.</p>
<p>Can anyone recommend an approach that would allow us to do this.</p>
<p>Thanks</p>
<p>DOm</p>
|
[
{
"answer_id": 101027,
"author": "mislav",
"author_id": 11687,
"author_profile": "https://Stackoverflow.com/users/11687",
"pm_score": 4,
"selected": true,
"text": "rescue_from class ApplicationController < ActionController::Base\n rescue_from MyAppError, :with => :show_errors\n\n def show_errors\n render :action => \"...\"\n end\nend\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
101,029
|
<p>Do you know of any compilers that only requires one or two clicks on the source code to compile? Having to configure it to do it doesn't count, nor does having to go to a terminal and write a word or two.</p>
<p>Extra points are given if you can give your own view as to why so few compilers have a gui included, or just a send to compiler listing in explorer!</p>
<p>The reason is that I want to be able to send source to my non-programming friends. Some have sparc computers, some have x64 with multiple cores and so on. </p>
<p>Then they would be able to compile the code and then remove it, saving just the binary that is optimized for their computer.</p>
|
[
{
"answer_id": 101173,
"author": "Jez",
"author_id": 15478,
"author_profile": "https://Stackoverflow.com/users/15478",
"pm_score": 0,
"selected": false,
"text": "make"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17500/"
] |
101,033
|
<p>I want to create a stored procedure with one argument which will return different sets of records depending on the argument. What is the way to do this? Can I call it from plain SQL?</p>
|
[
{
"answer_id": 101064,
"author": "Thilo",
"author_id": 14955,
"author_profile": "https://Stackoverflow.com/users/14955",
"pm_score": 5,
"selected": false,
"text": "create function test_cursor \n return sys_refcursor\n is\n c_result sys_refcursor;\n begin\n open c_result for\n select * from dual;\n return c_result;\n end;\n"
},
{
"answer_id": 101178,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 6,
"selected": false,
"text": "SQL> create type emp_obj is object (empno number, ename varchar2(10));\n 2 /\n\nType created.\n\nSQL> create type emp_tab is table of emp_obj;\n 2 /\n\nType created.\n\nSQL> create or replace function all_emps return emp_tab\n 2 is\n 3 l_emp_tab emp_tab := emp_tab();\n 4 n integer := 0;\n 5 begin\n 6 for r in (select empno, ename from emp)\n 7 loop\n 8 l_emp_tab.extend;\n 9 n := n + 1;\n 10 l_emp_tab(n) := emp_obj(r.empno, r.ename);\n 11 end loop;\n 12 return l_emp_tab;\n 13 end;\n 14 /\n\nFunction created.\n\nSQL> select * from table (all_emps);\n\n EMPNO ENAME\n---------- ----------\n 7369 SMITH\n 7499 ALLEN\n 7521 WARD\n 7566 JONES\n 7654 MARTIN\n 7698 BLAKE\n 7782 CLARK\n 7788 SCOTT\n 7839 KING\n 7844 TURNER\n 7902 FORD\n 7934 MILLER\n"
},
{
"answer_id": 105867,
"author": "John Smithers",
"author_id": 1069,
"author_profile": "https://Stackoverflow.com/users/1069",
"pm_score": 2,
"selected": false,
"text": "create or replace procedure myprocedure(retval in out sys_refcursor) is\nbegin\n open retval for\n select TABLE_NAME from user_tables;\nend myprocedure;\n\n declare \n myrefcur sys_refcursor;\n tablename user_tables.TABLE_NAME%type;\n begin\n myprocedure(myrefcur);\n loop\n fetch myrefcur into tablename;\n exit when myrefcur%notfound;\n dbms_output.put_line(tablename);\n end loop;\n close myrefcur;\n end;\n"
},
{
"answer_id": 14760504,
"author": "Mohsen Heydari",
"author_id": 2039695,
"author_profile": "https://Stackoverflow.com/users/2039695",
"pm_score": 3,
"selected": false,
"text": "create type array\nas table of number;\n\n\ncreate function gen_numbers(n in number default null)\nreturn array\nPIPELINED\nas\nbegin\n for i in 1 .. nvl(n,999999999)\n loop\n pipe row(i);\n end loop;\n return;\nend;\n select * from TABLE(gen_numbers(3));\n 1\n 2\n 3\n select * from TABLE(gen_numbers)\n where rownum <= 3;\n 1\n 2\n 3\n"
},
{
"answer_id": 26362189,
"author": "S. Mayol",
"author_id": 4066742,
"author_profile": "https://Stackoverflow.com/users/4066742",
"pm_score": 2,
"selected": false,
"text": "create procedure <procedure_name>(p_cur out sys_refcursor) as begin open p_cur for select * from <table_name> end;\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
101,038
|
<p>I have a Win32 TreeCtrl where the user can rename the tree labels. I process the TVN_ENDLABELEDIT message to do this.</p>
<p>In certain cases I need to change the text that the user entered. Basically the user can enter a short name during edit and I want to replace it with a longer text.</p>
<p>To do this I change the pszText member of the TVITEM struct I received during TVN_ENDLABELEDIT. I do a pointer replace here, as the original memory may be too small to do a simple strcpy like operation.</p>
<p>However I do not know how to deallocate the original pszText member. Basically because it's unknown if that was created with malloc() or new ... therefore I cannot call the appropriate deallocator. Obviously Win32 won't call the deallocator for the old pszText because the pointer has been replaced. So if I don't deallocate, there will be a memory leak.</p>
<p>Any idea how Win32 allocate these structs and what is the proper way to handle the above situation?</p>
|
[
{
"answer_id": 101088,
"author": "ChrisN",
"author_id": 3853,
"author_profile": "https://Stackoverflow.com/users/3853",
"pm_score": 2,
"selected": false,
"text": "LPSTR_TEXTCALLBACK pszText TVN_ENDLABELEDIT TreeView_SetItem"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101038",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
101,046
|
<p>I cannot understand the Oracle documentation. :-(</p>
<p>Does anybody know how to fetch multiple rows of simple data from Oracle via OCI?</p>
<p>I currently use <code>OCIDefineByPos</code> to define single variables (I only need to do this for simple integers -- <code>SQLT_INT</code>/4-byte ints) and then fetch a single row at a time with <code>OCIStmtExecute</code>/<code>OCIStmtFetch2</code>.</p>
<p>This is OK for small amounts of data but it takes around .5ms per row, so when reading a few ten thousand rows this is too slow.</p>
<p>I just don't understand the documentation for <code>OCIBindArrayOfStruct</code>. How can I fetch a few thousand rows at a time?</p>
|
[
{
"answer_id": 101088,
"author": "ChrisN",
"author_id": 3853,
"author_profile": "https://Stackoverflow.com/users/3853",
"pm_score": 2,
"selected": false,
"text": "LPSTR_TEXTCALLBACK pszText TVN_ENDLABELEDIT TreeView_SetItem"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101046",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6525/"
] |
101,055
|
<p>What makes a language a scripting language? I've heard some people say "when it gets interpreted instead of compiled". That would make PHP (for example) a scripting language. Is that the only criterion? Or are there other criteria?</p>
<h3>See also:</h3>
<ul>
<li><a href="https://stackoverflow.com/questions/98268/whats-the-difference-between-a-script-and-an-application">What’s the difference between a “script” and an “application”?</a></li>
</ul>
|
[
{
"answer_id": 101075,
"author": "Grey Panther",
"author_id": 1265,
"author_profile": "https://Stackoverflow.com/users/1265",
"pm_score": 3,
"selected": false,
"text": "perl my_source.pl"
},
{
"answer_id": 1281922,
"author": "Paul Biggar",
"author_id": 104021,
"author_profile": "https://Stackoverflow.com/users/104021",
"pm_score": 4,
"selected": false,
"text": "A language which is described as a scripting language.\n A Practical Solution for Scripting Language Compilers\n Paul Biggar, Edsko de Vries and David Gregg\n SAC '09: ACM Symposium on Applied Computing (2009), (March 2009)\n"
},
{
"answer_id": 2875142,
"author": "Jörg W Mittag",
"author_id": 2988,
"author_profile": "https://Stackoverflow.com/users/2988",
"pm_score": 4,
"selected": false,
"text": "File Directory find"
},
{
"answer_id": 3075096,
"author": "Justin L.",
"author_id": 292731,
"author_profile": "https://Stackoverflow.com/users/292731",
"pm_score": 2,
"selected": false,
"text": "alert() alert() <script>\nvar x = 4\nalert(x)\n</script>\n <script>"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101055",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6400/"
] |
101,066
|
<p><strong>EDIT</strong></p>
<p>What small things which are too easy to overlook do I need to do before deploying a rails application? </p>
<p>I have set up <a href="https://stackoverflow.com/questions/101275/what-do-i-need-to-do-on-deployment-of-a-rails-application">another question</a> for any task that takes more than a minute or two, and so ought to be scheduled into a deployment process. In this question I'm mostly concerned with on-line config options and similar, that can be done, but are often left out in during the development cycle because they don't make any difference until deployment</p>
|
[
{
"answer_id": 101315,
"author": "Laurie Young",
"author_id": 7473,
"author_profile": "https://Stackoverflow.com/users/7473",
"pm_score": 4,
"selected": true,
"text": "rake gems:unpack config/environment.rb app/controllers/application.rb filter_parameter_logging :password, :password_confirmation"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7473/"
] |
101,070
|
<p>If you are writing a <em>simple</em> little loop, what <em>should</em> you name the counter?</p>
<p><em>Provide example loops!</em></p>
|
[
{
"answer_id": 101071,
"author": "just mike",
"author_id": 12293,
"author_profile": "https://Stackoverflow.com/users/12293",
"pm_score": 4,
"selected": false,
"text": "i j k x y r c w h // recommended style ● // \"typical\" single-letter style\n ●\nfor (ii=0; ii<10; ++ii) { ● for (i=0; i<10; ++i) {\n for (jj=0; jj<10; ++jj) { ● for (j=0; j<10; ++j) {\n mm[ii][jj] = ii * jj; ● m[i][j] = i * j;\n } ● }\n} ● } i"
},
{
"answer_id": 101098,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 0,
"selected": false,
"text": "$_"
},
{
"answer_id": 101113,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 3,
"selected": false,
"text": "i j i"
},
{
"answer_id": 101114,
"author": "m_pGladiator",
"author_id": 446104,
"author_profile": "https://Stackoverflow.com/users/446104",
"pm_score": 5,
"selected": false,
"text": "for(int i = 0; i < ElementsList.size(); i++) {\n Element element = ElementsList.get(i);\n someProcessing(element);\n ....\n}\n for(Element element: ElementsList) for(Element element: ElementsList) {\n someProcessing(element);\n ....\n}\n"
},
{
"answer_id": 101220,
"author": "Jez",
"author_id": 15478,
"author_profile": "https://Stackoverflow.com/users/15478",
"pm_score": 2,
"selected": false,
"text": "i j k n i j k foreach foreach widget in widgets do\n foo(widget)\nend\n widget widgets"
},
{
"answer_id": 101239,
"author": "Paul Stephenson",
"author_id": 5536,
"author_profile": "https://Stackoverflow.com/users/5536",
"pm_score": 6,
"selected": false,
"text": "i int values[MAX_ROWS][MAX_COLS];\n\nint sum_of_all_values()\n{\n int i, j, total;\n\n total = 0;\n for (i = 0; i < MAX_COLS; i++)\n for (j = 0; j < MAX_ROWS; j++)\n total += values[i][j];\n return total;\n}\n int values[MAX_ROWS][MAX_COLS];\n\nint sum_of_all_values()\n{\n int row_num, col_num, total;\n\n total = 0;\n for (row_num = 0; row_num < MAX_COLS; row_num++)\n for (col_num = 0; col_num < MAX_ROWS; col_num++)\n total += values[row_num][col_num];\n return total;\n}\n row_num row_num col_num r c i j rr cc r c row col row_num col_num row iRow iCol i Row Col row_num < MAX_COLS iRow < MAX_COLS row_num row_idx"
},
{
"answer_id": 101643,
"author": "Davy Landman",
"author_id": 11098,
"author_profile": "https://Stackoverflow.com/users/11098",
"pm_score": 2,
"selected": false,
"text": "for (int currentItemIndex = 0; currentItemIndex < list.Length; currentItemIndex++)\n{\n ...\n}\n Item currentItem = list[currentItemIndex];\n for (int currentItemIndex = 0; currentItemIndex < list.Length; currentItemIndex++)\n{\n Item currentItem = list[currentItemIndex];\n ...\n}\n foreach (Item currentItem in list)\n{\n ...\n}\n"
},
{
"answer_id": 101644,
"author": "Ande Turner",
"author_id": 4857,
"author_profile": "https://Stackoverflow.com/users/4857",
"pm_score": 4,
"selected": false,
"text": "i for (int i = 0; i < LOOP_LENGTH; i++) {\n\n // LOOP_BODY\n}\n for (int iRow = 0; iRow < ROWS; iRow++) {\n\n for (int iColumn = 0; iColumn < COLUMNS; iColumn++) {\n\n // LOOP_BODY\n }\n}\n foreach Object for (Object something : somethings) {\n\n // LOOP_BODY\n}\n for iter for (Iterator iter = collection.iterator(); iter.hasNext(); /* N/A */) {\n\n Object object = iter.next();\n\n // LOOP_BODY\n}\n while /* LOOP_DESCRIPTION */ {\n\n Iterator iter = collection.iterator();\n\n while (iter.hasNext()) {\n\n // LOOP_BODY\n }\n}\n"
},
{
"answer_id": 104673,
"author": "Jon Ericson",
"author_id": 1438,
"author_profile": "https://Stackoverflow.com/users/1438",
"pm_score": 1,
"selected": false,
"text": "foreach (@item){\n $item_count{$_}++;\n}\n for (@item){\n print;\n}\n for (1..100){\n print \"$_*$_\\n\";\n}\n foreach $car (@cars){\n for (@{$car->{tires}}){\n check_pressure($_);\n }\n}\n"
},
{
"answer_id": 106074,
"author": "Ande Turner",
"author_id": 4857,
"author_profile": "https://Stackoverflow.com/users/4857",
"pm_score": 1,
"selected": false,
"text": "/*LOOP_DESCRIPTION*/ {\n\n int i;\n\n for (i = 0; i < LOOP_LENGTH; i++) {\n\n // loop body\n } \n}\n /*LOOP_DESCRIPTION*/ {\n\n int row, column;\n\n for (row = 0; row < ROWS; row++) {\n\n for (column = 0; column < COLUMNS; column++) {\n\n // loop body\n }\n } \n}\n"
},
{
"answer_id": 108882,
"author": "Tim Gradwell",
"author_id": 16676,
"author_profile": "https://Stackoverflow.com/users/16676",
"pm_score": 0,
"selected": false,
"text": "iRow iCol iCar"
},
{
"answer_id": 109415,
"author": "Ed L",
"author_id": 13099,
"author_profile": "https://Stackoverflow.com/users/13099",
"pm_score": 0,
"selected": false,
"text": "for x in width:\n for y in height:\n do_something_interesting(x,y)\n"
},
{
"answer_id": 115104,
"author": "Derek Clegg",
"author_id": 19783,
"author_profile": "https://Stackoverflow.com/users/19783",
"pm_score": 1,
"selected": false,
"text": "i jj kappa for (i = 0; i < count; i++) ...\n count for (y = 0; y < height; y++)\n for (x = 0; x < width; x++)\n ...\n"
},
{
"answer_id": 131236,
"author": "Riddari",
"author_id": 2145,
"author_profile": "https://Stackoverflow.com/users/2145",
"pm_score": 0,
"selected": false,
"text": "for(lcObject = 0; lcObject < Collection.length(); lcObject++)\n{\n //do stuff\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12293/"
] |
101,072
|
<p>Was this an oversight? Or is it to do with the JVM?</p>
|
[
{
"answer_id": 692078,
"author": "David Citron",
"author_id": 5309,
"author_profile": "https://Stackoverflow.com/users/5309",
"pm_score": 6,
"selected": true,
"text": "Object myObj = new Object();\n myObj Object myObj null null"
},
{
"answer_id": 6227525,
"author": "Stephen C",
"author_id": 139985,
"author_profile": "https://Stackoverflow.com/users/139985",
"pm_score": 2,
"selected": false,
"text": "NullPointerException"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4857/"
] |
101,079
|
<p>I used to work in a place where a common practice was to use Pair Programming. I remember how many small things we could learn from each other when working together on the code. Picking up new shortcuts, code snippets etc. with time significantly improved our efficiency of writing code.</p>
<p>Since I started working with SQL Server I have been left on my own. The best habits I would normally pick from working together with other people which I cannot do now.</p>
<p>So here is the question:</p>
<ul>
<li>What are you tips on efficiently
writing TSQL code using SQL Server
Management Studio? </li>
<li>Please keep the
tips to 2 – 3 things/shortcuts that
you think improve you speed of
coding </li>
<li>Please stay within the scope
of TSQL and SQL Server Management
Studio 2005/2008 If the feature is
specific to the version of
Management Studio please indicate:
e.g. “Works with SQL Server 2008
only"</li>
</ul>
<p><strong>EDIT:</strong></p>
<p>I am afraid that I could have been misunderstood by some of you.
I am not looking for tips for writing efficient TSQL code but rather for advice on how to efficiently use Management Studio to speed up the coding process itself. </p>
<p>The type of answers that I am looking for are: </p>
<ul>
<li>use of templates, </li>
<li>keyboard-shortcuts, </li>
<li>use of IntelliSense plugins etc. </li>
</ul>
<p>Basically those little things that make the coding experience a bit more efficient and pleasant.</p>
|
[
{
"answer_id": 101091,
"author": "Galwegian",
"author_id": 3201,
"author_profile": "https://Stackoverflow.com/users/3201",
"pm_score": 5,
"selected": false,
"text": "DELETE BEGIN TRANSACTION COMMIT"
},
{
"answer_id": 102316,
"author": "HLGEM",
"author_id": 9034,
"author_profile": "https://Stackoverflow.com/users/9034",
"pm_score": 2,
"selected": false,
"text": "select t1.field1,t2.field2\n--update t\n--set field1 = t2.field2 \nfrom mytable t1\njoin myothertable t2 on t1.idfield =t2.idfield\nwhere t2.field1 >10\n\nselect t1.* \n--delete t1\nfrom mytable t1\njoin myothertable t2 on t1.idfield =t2.idfield\nwhere t2.field1 = 'test'\n select t1.field1,t2.field2\nupdate t\nset field1 = t2.field2 \n--select t1.field1,t2.field2\nfrom mytable t1\njoin myothertable t2 on t1.idfield =t2.idfield\nwhere t2.field1 >10\n"
},
{
"answer_id": 106042,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 4,
"selected": false,
"text": "SELECT\nt.a\n,t.b\n,t.c\n,t.d\nFROM t\n"
},
{
"answer_id": 785395,
"author": "Jon M",
"author_id": 74152,
"author_profile": "https://Stackoverflow.com/users/74152",
"pm_score": 3,
"selected": false,
"text": "DRAG"
},
{
"answer_id": 1469301,
"author": "Joe Phillips",
"author_id": 20471,
"author_profile": "https://Stackoverflow.com/users/20471",
"pm_score": 0,
"selected": false,
"text": "Open New Query"
},
{
"answer_id": 1469310,
"author": "Joe Phillips",
"author_id": 20471,
"author_profile": "https://Stackoverflow.com/users/20471",
"pm_score": 0,
"selected": false,
"text": "SELECT INTO"
},
{
"answer_id": 8429167,
"author": "Abhimanyu Shukla",
"author_id": 967346,
"author_profile": "https://Stackoverflow.com/users/967346",
"pm_score": 1,
"selected": false,
"text": "SSMSToolsPack"
},
{
"answer_id": 9632292,
"author": "Andrei Rantsevich",
"author_id": 1249405,
"author_profile": "https://Stackoverflow.com/users/1249405",
"pm_score": 2,
"selected": false,
"text": "select * from"
},
{
"answer_id": 9673394,
"author": "JNK",
"author_id": 397952,
"author_profile": "https://Stackoverflow.com/users/397952",
"pm_score": 1,
"selected": false,
"text": "ALT+SHIFT"
},
{
"answer_id": 10828090,
"author": "PollusB",
"author_id": 259405,
"author_profile": "https://Stackoverflow.com/users/259405",
"pm_score": 1,
"selected": false,
"text": "CREATE PROC upsert_Table1(@col1 int, @col2 varchar(200), @col3 float, etc.)\nAS\nBEGIN\n UPDATE table1 SET col1 = @col1, col2 = @col2, col3 = @col3, etc.\n IF @@error <> 0\n INSERT Table1 (col1, col2, col3, etc.)\n VALUES(@col1, @col2, @col3, etc.)\nEND\nGO\nCREATE PROC delete_Table1(@col1)\nAS DELETE FROM Table1 WHERE col1 = @col1\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3241/"
] |
101,096
|
<p>I have an Exchange mailbox linked as a table in an MS Access app. This is primarily used for reading, but I would also like to be able to "move" messages to another folder. </p>
<p>Unfortunately this is not as simple as writing in a second linked mailbox, because apparently I can not edit some fields. Some critical fields like the To: field are unavailable, as I get the following error </p>
<p><em>"Field 'To' is based on an expression and cannot be edited".</em> </p>
<p>Using <em>CreateObject("Outlook.Application")</em> instead is not an option here, because as far as I know, this gives a security dialog when called from Access.</p>
<p>Any solutions?*</p>
|
[
{
"answer_id": 102406,
"author": "Fionnuala",
"author_id": 2548,
"author_profile": "https://Stackoverflow.com/users/2548",
"pm_score": 1,
"selected": false,
"text": " Set oApp = CreateObject(\"Outlook.Application\")\n\nSet oNS = oApp.GetNamespace(\"MAPI\")\n\nSet oMailItems = oNS.GetDefaultFolder(olFolderInbox)\nSet itm = oMailItems.Items(6)\nitm.Move oNS.GetDefaultFolder(olFolderDeletedItems)\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
101,100
|
<p>Can anyone recommend a simple API that will allow me to use read a CSV input file, do some simple transformations, and then write it.</p>
<p>A quick google has found <a href="http://flatpack.sourceforge.net/" rel="noreferrer">http://flatpack.sourceforge.net/</a> which looks promising.</p>
<p>I just wanted to check what others are using before I couple myself to this API.</p>
|
[
{
"answer_id": 105649,
"author": "Jay R.",
"author_id": 5074,
"author_profile": "https://Stackoverflow.com/users/5074",
"pm_score": 6,
"selected": false,
"text": "import au.com.bytecode.opencsv.CSVReader;"
},
{
"answer_id": 2146086,
"author": "kbg",
"author_id": 258315,
"author_profile": "https://Stackoverflow.com/users/258315",
"pm_score": 5,
"selected": false,
"text": "public class UserBean {\n String username, password, street, town;\n int zip;\n\n public String getPassword() { return password; }\n public String getStreet() { return street; }\n public String getTown() { return town; }\n public String getUsername() { return username; }\n public int getZip() { return zip; }\n public void setPassword(String password) { this.password = password; }\n public void setStreet(String street) { this.street = street; }\n public void setTown(String town) { this.town = town; }\n public void setUsername(String username) { this.username = username; }\n public void setZip(int zip) { this.zip = zip; }\n}\n username, password, date, zip, town\nKlaus, qwexyKiks, 17/1/2007, 1111, New York\nOufu, bobilop, 10/10/2007, 4555, New York\n class ReadingObjects {\n public static void main(String[] args) throws Exception{\n ICsvBeanReader inFile = new CsvBeanReader(new FileReader(\"foo.csv\"), CsvPreference.EXCEL_PREFERENCE);\n try {\n final String[] header = inFile.getCSVHeader(true);\n UserBean user;\n while( (user = inFile.read(UserBean.class, header, processors)) != null) {\n System.out.println(user.getZip());\n }\n } finally {\n inFile.close();\n }\n }\n}\n final CellProcessor[] processors = new CellProcessor[] {\n new Unique(new StrMinMax(5, 20)),\n new StrMinMax(8, 35),\n new ParseDate(\"dd/MM/yyyy\"),\n new Optional(new ParseInt()),\n null\n};\n"
},
{
"answer_id": 6437500,
"author": "Dhananjay Joshi",
"author_id": 815077,
"author_profile": "https://Stackoverflow.com/users/815077",
"pm_score": 3,
"selected": false,
"text": "/ ************ For Reading ***************/\n\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\n\nimport com.csvreader.CsvReader;\n\npublic class CsvReaderExample {\n\n public static void main(String[] args) {\n try {\n\n CsvReader products = new CsvReader(\"products.csv\");\n\n products.readHeaders();\n\n while (products.readRecord())\n {\n String productID = products.get(\"ProductID\");\n String productName = products.get(\"ProductName\");\n String supplierID = products.get(\"SupplierID\");\n String categoryID = products.get(\"CategoryID\");\n String quantityPerUnit = products.get(\"QuantityPerUnit\");\n String unitPrice = products.get(\"UnitPrice\");\n String unitsInStock = products.get(\"UnitsInStock\");\n String unitsOnOrder = products.get(\"UnitsOnOrder\");\n String reorderLevel = products.get(\"ReorderLevel\");\n String discontinued = products.get(\"Discontinued\");\n\n // perform program logic here\n System.out.println(productID + \":\" + productName);\n }\n\n products.close();\n\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n } catch (IOException e) {\n e.printStackTrace();\n }\n\n }\n\n}\n /************* For Writing ***************************/\n\nimport java.io.File;\nimport java.io.FileWriter;\nimport java.io.IOException;\n\nimport com.csvreader.CsvWriter;\n\npublic class CsvWriterAppendExample {\n\n public static void main(String[] args) {\n\n String outputFile = \"users.csv\";\n\n // before we open the file check to see if it already exists\n boolean alreadyExists = new File(outputFile).exists();\n\n try {\n // use FileWriter constructor that specifies open for appending\n CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ',');\n\n // if the file didn't already exist then we need to write out the header line\n if (!alreadyExists)\n {\n csvOutput.write(\"id\");\n csvOutput.write(\"name\");\n csvOutput.endRecord();\n }\n // else assume that the file already has the correct header line\n\n // write out a few records\n csvOutput.write(\"1\");\n csvOutput.write(\"Bruce\");\n csvOutput.endRecord();\n\n csvOutput.write(\"2\");\n csvOutput.write(\"John\");\n csvOutput.endRecord();\n\n csvOutput.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n\n }\n}\n"
},
{
"answer_id": 6657525,
"author": "gnat",
"author_id": 839601,
"author_profile": "https://Stackoverflow.com/users/839601",
"pm_score": 4,
"selected": false,
"text": "+ maven\n\n+ maven - release version // had some cryptic issues at _Hudson_ with snapshot references => prefer to be on a safe side\n\n+ code examples\n\n+ open source // as in \"can hack myself if needed\"\n\n+ understandable javadoc // as opposed to eg javadocs of _genjava gj-csv_\n\n+ compact API // YAGNI (note *flatpack* seems to have much richer API than OpenCSV)\n\n- reference to specification used // I really like it when people can explain what they're doing\n\n- reference to _RFC 4180_ support // would qualify as simplest form of specification to me\n\n- releases changelog // absence is quite a pity, given how simple it'd be to get with maven-changes-plugin // _flatpack_, for comparison, has quite helpful changelog\n\n+ bug tracking\n\n+ active // as in \"can submit a bug and expect a fixed release soon\"\n\n+ positive feedback // Recommended By 51 users at sourceforge (as of now)\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101100",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10171/"
] |
101,125
|
<p>Is there a way to check if the user has a different version of the CSS cached by their browser and if so force their browser to pull the new version?</p>
|
[
{
"answer_id": 101131,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 0,
"selected": false,
"text": "<body class=\"style2\">\n\n<body class=\"style1\">\n"
},
{
"answer_id": 101188,
"author": "David Heggie",
"author_id": 4309,
"author_profile": "https://Stackoverflow.com/users/4309",
"pm_score": 0,
"selected": false,
"text": "<?php\nif($_GET['admin_page']) {\n $body_id = 'admin';\n} else {\n $body_id = 'normal';\n}\n?>\n...\n<body id=\"<?php echo $body_id; ?>\">\n...\n</body>\n body#admin h1 {\n color: red;\n}\n\nbody#normal h1 {\n color: blue;\n}\n <FilesMatch \"\\.(css)$\">\nHeader set Cache-Control \"max-age=0, private, no-store, no-cache, must-revalidate\"\n</FilesMatch>\n"
},
{
"answer_id": 101200,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 1,
"selected": false,
"text": "public class CSSLink : System.Web.UI.Control\n{\n\n protected override void Render(System.Web.UI.HtmlTextWriter writer)\n {\n\n if ( ... querystring params == ... )\n writer.WriteLine(\"<link href=\\\"/styles/css1.css\\\" type=\\\"text/css\\\" rel=\\\"stylesheet\\\" />\")\n else\n writer.WriteLine(\"<link href=\\\"/styles/css2.css\\\" type=\\\"text/css\\\" rel=\\\"stylesheet\\\" />\")\n\n }\n\n}\n <%@ Register TagPrefix=\"mycontrols\" Namespace=\"MyNamespace\" Assembly=\"MyAssembly\" %>\n...\n<head runat=\"server\">\n ...\n <mycontrols:CSSLink id=\"masterCSSLink\" runat=\"server\" />\n</head>\n...\n"
},
{
"answer_id": 515904,
"author": "jeroen",
"author_id": 42139,
"author_profile": "https://Stackoverflow.com/users/42139",
"pm_score": 6,
"selected": true,
"text": "<link href=\"mystyle.css?SOME_UNIQUE_TEXT\" type=\"text/css\" rel=\"stylesheet\" />\n"
},
{
"answer_id": 540867,
"author": "Leandro López",
"author_id": 22695,
"author_profile": "https://Stackoverflow.com/users/22695",
"pm_score": 2,
"selected": false,
"text": "<link href=\"StyleSelector.aspx?foo=bar&baz=foz\" type=\"text/css\" rel=\"stylesheet\" />\n <%@ Page Language=\"cs\" AutoEventWireup=\"false\" Inherits=\"Demo.StyleSelector\" Codebehind=\"StyleSelector.aspx.cs\" %>\n using System.IO;\n\nnamespace Demo\n{\n public partial class StyleSelector : System.Web.UI.Page\n {\n public StyleSelector()\n {\n Me.Load += New EventHandler(doLoad);\n }\n\n protected void doLoad(object sender, System.EventArgs e)\n {\n // Make sure you add this line\n Response.ContentType = \"text/css\";\n\n string cssFileName = Request.QueryString(\"foo\");\n\n // I'm assuming you have your CSS in a css/ folder\n Response.WriteFile(\"css/\" + cssFileName + \".css\");\n }\n }\n}\n IHttpModule IHttpHandler"
},
{
"answer_id": 61276089,
"author": "focus.style",
"author_id": 3187127,
"author_profile": "https://Stackoverflow.com/users/3187127",
"pm_score": 0,
"selected": false,
"text": "<link href=\"mystyle.css?v=DIGIT\" type=\"text/css\" rel=\"stylesheet\" /> \n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
101,128
|
<p>How do I read text from the (windows) clipboard with python?</p>
|
[
{
"answer_id": 101167,
"author": "Sakin",
"author_id": 12818,
"author_profile": "https://Stackoverflow.com/users/12818",
"pm_score": 8,
"selected": true,
"text": "import win32clipboard\n\n# set clipboard data\nwin32clipboard.OpenClipboard()\nwin32clipboard.EmptyClipboard()\nwin32clipboard.SetClipboardText('testing 123')\nwin32clipboard.CloseClipboard()\n\n# get clipboard data\nwin32clipboard.OpenClipboard()\ndata = win32clipboard.GetClipboardData()\nwin32clipboard.CloseClipboard()\nprint data\n"
},
{
"answer_id": 11096779,
"author": "born",
"author_id": 1441864,
"author_profile": "https://Stackoverflow.com/users/1441864",
"pm_score": 4,
"selected": false,
"text": "import win32clipboard\n\nwin32clipboard.OpenClipboard()\nc = win32clipboard.GetClipboardData()\nwin32clipboard.EmptyClipboard()\nc = c.replace('\\n', ' ')\nc = c.replace('\\r', ' ')\nwhile c.find(' ') != -1:\n c = c.replace(' ', ' ')\nwin32clipboard.SetClipboardText(c)\nwin32clipboard.CloseClipboard()\n"
},
{
"answer_id": 23285159,
"author": "kichik",
"author_id": 492773,
"author_profile": "https://Stackoverflow.com/users/492773",
"pm_score": 5,
"selected": false,
"text": "ctypes import ctypes\n\nCF_TEXT = 1\n\nkernel32 = ctypes.windll.kernel32\nkernel32.GlobalLock.argtypes = [ctypes.c_void_p]\nkernel32.GlobalLock.restype = ctypes.c_void_p\nkernel32.GlobalUnlock.argtypes = [ctypes.c_void_p]\nuser32 = ctypes.windll.user32\nuser32.GetClipboardData.restype = ctypes.c_void_p\n\ndef get_clipboard_text():\n user32.OpenClipboard(0)\n try:\n if user32.IsClipboardFormatAvailable(CF_TEXT):\n data = user32.GetClipboardData(CF_TEXT)\n data_locked = kernel32.GlobalLock(data)\n text = ctypes.c_char_p(data_locked)\n value = text.value\n kernel32.GlobalUnlock(data_locked)\n return value\n finally:\n user32.CloseClipboard()\n\nprint(get_clipboard_text())\n"
},
{
"answer_id": 23844754,
"author": "kmonsoor",
"author_id": 617185,
"author_profile": "https://Stackoverflow.com/users/617185",
"pm_score": 6,
"selected": false,
"text": "from tkinter import Tk # Python 3\n#from Tkinter import Tk # for Python 2.x\nTk().clipboard_get()\n"
},
{
"answer_id": 27995097,
"author": "user136036",
"author_id": 2441026,
"author_profile": "https://Stackoverflow.com/users/2441026",
"pm_score": 3,
"selected": false,
"text": "# Python 3\nimport tkinter\n\nr = tkinter.Tk()\ntext = r.clipboard_get()\nr.withdraw()\nr.update()\nr.destroy()\n"
},
{
"answer_id": 36886989,
"author": "Dan",
"author_id": 2084578,
"author_profile": "https://Stackoverflow.com/users/2084578",
"pm_score": 3,
"selected": false,
"text": "import clipboard\nclipboard.copy(\"this text is now in the clipboard\")\nprint clipboard.paste() \n"
},
{
"answer_id": 38171680,
"author": "np8",
"author_id": 3015186,
"author_profile": "https://Stackoverflow.com/users/3015186",
"pm_score": 6,
"selected": false,
"text": "pip install pyperclip import pyperclip\n \ns = pyperclip.paste()\npyperclip.copy(s)\n \n# the type of s is string\n"
},
{
"answer_id": 49646482,
"author": "Paul Sumpner",
"author_id": 1429282,
"author_profile": "https://Stackoverflow.com/users/1429282",
"pm_score": 4,
"selected": false,
"text": "try:\n # Python3\n import tkinter as tk\nexcept ImportError:\n # Python2\n import Tkinter as tk\n\ndef getClipboardText():\n root = tk.Tk()\n # keep the window from showing\n root.withdraw()\n return root.clipboard_get()\n"
},
{
"answer_id": 56947041,
"author": "see2",
"author_id": 11691686,
"author_profile": "https://Stackoverflow.com/users/11691686",
"pm_score": 1,
"selected": false,
"text": "Import pyautogui\npyautogui.hotkey('ctrl', 'v')\n"
},
{
"answer_id": 67323780,
"author": "kirgizmustafa17",
"author_id": 11804828,
"author_profile": "https://Stackoverflow.com/users/11804828",
"pm_score": 2,
"selected": false,
"text": "from tkinter import Tk, TclError\nfrom time import sleep\n\nwhile True:\n try:\n clipboard = Tk().clipboard_get()\n print(clipboard)\n sleep(5)\n except TclError:\n print(\"Clipboard is empty.\")\n sleep(5)\n"
},
{
"answer_id": 70248479,
"author": "asdf101",
"author_id": 12337195,
"author_profile": "https://Stackoverflow.com/users/12337195",
"pm_score": 0,
"selected": false,
"text": ">>> from pandas.io.clipboard import clipboard_get, clipboard_set\n>>> clipboard_get()\n'from pandas.io.clipboard import clipboard_get, clipboard_set'\n>>> clipboard_set(\"Hello clipboard!\")\n>>> clipboard_get()\n'Hello clipboard!'\n"
},
{
"answer_id": 70254906,
"author": "Athii",
"author_id": 2197624,
"author_profile": "https://Stackoverflow.com/users/2197624",
"pm_score": 1,
"selected": false,
"text": "import pandas as pd\ndf = pd.read_clipboard()\n"
},
{
"answer_id": 71168816,
"author": "东临碣石",
"author_id": 14817883,
"author_profile": "https://Stackoverflow.com/users/14817883",
"pm_score": 1,
"selected": false,
"text": "import subprocess\n\ndef getClipboard():\n ret = subprocess.getoutput(\"powershell.exe -Command Get-Clipboard\")\n return ret\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17493/"
] |
101,145
|
<p>How can someone validate that a specific element exists in an XML file? Say I have an ever changing XML file and I need to verify every element exists before reading/parsing it. </p>
|
[
{
"answer_id": 101160,
"author": "Chris James",
"author_id": 3193,
"author_profile": "https://Stackoverflow.com/users/3193",
"pm_score": 6,
"selected": false,
"text": "if(doc.SelectSingleNode(\"//mynode\")==null)....\n"
},
{
"answer_id": 6649224,
"author": "sangam",
"author_id": 47043,
"author_profile": "https://Stackoverflow.com/users/47043",
"pm_score": 3,
"selected": false,
"text": "doc.Load(xmlPath);\n XmlNodeList node = doc.SelectNodes(\"//Nodes/Node\");\n foreach (XmlNode chNode in node)\n {\n try{\n if (chNode[\"innerNode\"]==null)\n return true; //node exists\n //if ... check for any other nodes you need to\n }catch(Exception e){return false; //some node doesn't exists.}\n }\n"
},
{
"answer_id": 10154151,
"author": "Priyadarshi Kunal",
"author_id": 188936,
"author_profile": "https://Stackoverflow.com/users/188936",
"pm_score": 0,
"selected": false,
"text": "public boolean envParamExists(String xmlFilePath, String paramName){\n try{\n Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(xmlFilePath));\n doc.getDocumentElement().normalize();\n if(doc.getElementsByTagName(paramName).getLength()>0)\n return true;\n else\n return false;\n }catch (Exception e) {\n //error handling\n }\n return false;\n}\n"
},
{
"answer_id": 12130206,
"author": "siddharth",
"author_id": 1150659,
"author_profile": "https://Stackoverflow.com/users/1150659",
"pm_score": 2,
"selected": false,
"text": "sangam if (chNode[\"innerNode\"][\"innermostNode\"]==null)\n return true; //node *parentNode*/innerNode/innermostNode exists\n"
},
{
"answer_id": 12815870,
"author": "jomsk1e",
"author_id": 1638261,
"author_profile": "https://Stackoverflow.com/users/1638261",
"pm_score": 2,
"selected": false,
"text": "using (XmlTextReader reader = new XmlTextReader(xmlPath))\n{\n while (reader.Read())\n {\n if (reader.NodeType == XmlNodeType.Element)\n { \n //do your code here\n }\n }\n}\n"
},
{
"answer_id": 26961433,
"author": "user4258853",
"author_id": 4258853,
"author_profile": "https://Stackoverflow.com/users/4258853",
"pm_score": 3,
"selected": false,
"text": "XmlNodeList YOURTEMPVARIABLE = doc.GetElementsByTagName(\"YOUR_ELEMENTNAME\");\n\n if (YOURTEMPVARIABLE.Count > 0 )\n {\n doctype = YOURTEMPVARIABLE[0].InnerXml;\n\n }\n else\n {\n doctype = \"\";\n }\n"
},
{
"answer_id": 37634639,
"author": "Mazinger",
"author_id": 3648561,
"author_profile": "https://Stackoverflow.com/users/3648561",
"pm_score": 0,
"selected": false,
"text": "XmlNodeList NodoEstudios = DocumentoXML.SelectNodes(\"//ALUMNOS/ALUMNO[@id=\\\"\" + Id + \"\\\"]/estudios\");\n\nstring Proyecto = \"\";\n\nforeach(XmlElement ElementoProyecto in NodoEstudios)\n{\n XmlNodeList EleProyecto = ElementoProyecto.GetElementsByTagName(\"proyecto\");\n Proyecto = (EleProyecto[0] == null)?\"\": EleProyecto[0].InnerText;\n}\n"
},
{
"answer_id": 41354369,
"author": "Sumit",
"author_id": 7347910,
"author_profile": "https://Stackoverflow.com/users/7347910",
"pm_score": 0,
"selected": false,
"text": " using (XmlReader xmlReader = XmlReader.Create(new StringReader(\"XMLSTRING\")))\n {\n\n if (xmlReader.ReadToFollowing(\"XMLNODE\")) \n\n {\n string nodeValue = xmlReader.ReadElementString(\"XMLNODE\"); \n }\n } \n"
},
{
"answer_id": 52558533,
"author": "Jiving Rockabilly",
"author_id": 4921102,
"author_profile": "https://Stackoverflow.com/users/4921102",
"pm_score": 0,
"selected": false,
"text": " foreach (XmlNode txElement in txElements)\n {\n var txStatus = txElement.SelectSingleNode(\".//ns:TxSts\", nsmgr).InnerText ?? string.Empty;\n var endToEndId = txElement.SelectSingleNode(\".//ns:OrgnlEndToEndId\", nsmgr).InnerText ?? string.Empty;\n var paymentAmount = txElement.SelectSingleNode(\".//ns:InstdAmt\", nsmgr).InnerText ?? string.Empty;\n var paymentAmountCcy = txElement.SelectSingleNode(\".//ns:InstdAmt\", nsmgr).Attributes[\"Ccy\"].Value ?? string.Empty;\n var clientId = txElement.SelectSingleNode(\".//ns:OrgnlEndToEndId\", nsmgr).InnerText ?? string.Empty;\n var bankSortCode = txElement.SelectSingleNode(\".//ns:OrgnlEndToEndId\", nsmgr).InnerText ?? string.Empty; \n\n //TODO finish Object creation and Upsert DB\n }\n"
},
{
"answer_id": 54802098,
"author": "Mir Saleem",
"author_id": 11094573,
"author_profile": "https://Stackoverflow.com/users/11094573",
"pm_score": -1,
"selected": false,
"text": "If StrComp(xmlnode(i).ChildNodes.Item(xmlnode(i).ChildNodes.Count - 1).Name.ToString(), \"ERNO\", CompareMethod.Text) = 0 Then\n xmlnode(i).ChildNodes.Item(xmlnode(i).ChildNodes.Count - 1).InnerText = c\n Else\n elem = xmldoc.CreateElement(\"ERNo\")\n elem.InnerText = c.ToString\n root.ChildNodes(i).AppendChild(elem)\n End If\n"
},
{
"answer_id": 63112427,
"author": "fredm73",
"author_id": 5253084,
"author_profile": "https://Stackoverflow.com/users/5253084",
"pm_score": 0,
"selected": false,
"text": " string name = \"some node name\";\n var xDoc = XDocument.Load(\"yourFile\");\n var docRoot = xDoc.Element(\"your docs root name\");\n\n var aNode = docRoot.Elements().Where(x => x.Name == name).FirstOrDefault();\n if (aNode == null)\n {\n return $\"file has no {name}\";\n }\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
101,151
|
<p>I have the following scenario:</p>
<pre>
public class CarManager
{
..
public long AddCar(Car car)
{
try
{
string username = _authorizationManager.GetUsername();
...
long id = _carAccessor.AddCar(username, car.Id, car.Name, ....);
if(id == 0)
{
throw new Exception("Car was not added");
}
return id;
} catch (Exception ex) {
throw new AddCarException(ex);
}
}
public List AddCars(List cars)
{
List ids = new List();
foreach(Car car in cars)
{
ids.Add(AddCar(car));
}
return ids;
}
}
</pre>
<p>I am mocking out _reportAccessor, _authorizationManager etc.</p>
<p>Now I want to unittest the CarManager class.
Should I have multiple tests for AddCar() such as </p>
<pre>
AddCarTest()
AddCarTestAuthorizationManagerException()
AddCarTestCarAccessorNoId()
AddCarTestCarAccessorException()
</pre>
<p>For AddCars() should I repeat all previous tests as AddCars() calls AddCar() - it seems like repeating oneself? Should I perhaps not be calling AddCar() from AddCars()? < p/></p>
<p>Please help.</p>
|
[
{
"answer_id": 101438,
"author": "Josh Freed",
"author_id": 14548,
"author_profile": "https://Stackoverflow.com/users/14548",
"pm_score": 1,
"selected": false,
"text": "AddCarTestAuthorizationManagerException() AddCarTestCarAccessorNoId() AddCarTestCarAccessorException() AddCars() AddCar() AddCar() AddCars() AddCar() AddCars() AddCar()"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15771/"
] |
101,156
|
<p>I need to count and check how much of some images is placed in folder od web server.
Example- images get names from <code>user_id</code>, and on example I have <code>user_id 27</code>, and my images are:</p>
<pre><code>27_1.jpg, 27_2.jpg, 27_3.jpg, ...
</code></pre>
<p>How to check and write to database this thing?</p>
<p>Thanks</p>
|
[
{
"answer_id": 101230,
"author": "hometoast",
"author_id": 2009,
"author_profile": "https://Stackoverflow.com/users/2009",
"pm_score": 2,
"selected": false,
"text": "IO.Directory.GetFiles(\"\\translated\\path\",\"27_*.jpg\").Count()\n"
},
{
"answer_id": 101236,
"author": "WebDude",
"author_id": 15360,
"author_profile": "https://Stackoverflow.com/users/15360",
"pm_score": 0,
"selected": false,
"text": "public File[] GetUserFiles(int userId)\n{\n List<File> files = new List<File>();\n\n DirectoryInfo di = new DirectoryInfo(@\"c:\\folderyoulookingfor\");\n foreach(File f in di.GetFiles())\n {\n if(f.ToString().StartsWith(userId.ToString()))\n files.Add(f);\n }\n return file.ToArray();\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/205368/"
] |
101,162
|
<p>How do you return a serialized JSON object to the client side using ASP.NET MVC via an AJAX call?</p>
|
[
{
"answer_id": 101256,
"author": "David Bick",
"author_id": 4914,
"author_profile": "https://Stackoverflow.com/users/4914",
"pm_score": 6,
"selected": true,
"text": "public ActionResult MyAction()\n{\n ... // Populate myObject\n return new JsonResult{ Data = myObject };\n}\n $.getJSON(\"/controllerName/MyAction\", callbackFunction);\n callbackFunction"
},
{
"answer_id": 102693,
"author": "Matt",
"author_id": 17803,
"author_profile": "https://Stackoverflow.com/users/17803",
"pm_score": 3,
"selected": false,
"text": "public ActionResult MyAction()\n{\n return Json(new {Data = myObject});\n}\n"
},
{
"answer_id": 24030151,
"author": "Md Nazmoon Noor",
"author_id": 870118,
"author_profile": "https://Stackoverflow.com/users/870118",
"pm_score": 0,
"selected": false,
"text": "public JsonResult Foo()\n{\n return Json(\"Secrets\", JsonRequestBehavior.AllowGet);\n}\n"
},
{
"answer_id": 45564416,
"author": "Thisara Subath",
"author_id": 6602130,
"author_profile": "https://Stackoverflow.com/users/6602130",
"pm_score": 2,
"selected": false,
"text": " public JsonResult ASD()\n {\n string aaa = \"Hi There is a sample Json\";\n return Json(aaa);\n }\n"
},
{
"answer_id": 50997671,
"author": "Oshada Ekanayake",
"author_id": 4904744,
"author_profile": "https://Stackoverflow.com/users/4904744",
"pm_score": 1,
"selected": false,
"text": "using System.Web.Script.Serialization;\n\npublic ActionResult MyAction(string myParam)\n{\n\n return new JavaScriptSerializer().Serialize(myObject);\n}\n $.ajax({\n type: 'POST',\n url: '@Url.Action(\"MyAction\",\"MyMethod\")',\n dataType: 'json',\n contentType: \"application/json; charset=utf-8\",\n data: JSON.stringify({ \"myParam\": \"your data\" }),\n success: function(data)\n {\n console.log(data)\n },\n error: function (request, status, error) {\n\n }\n});\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101162",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
101,174
|
<p>In Python there is a really neat function called <code>zip</code> which can be used to iterate through two lists at the same time:</p>
<pre><code>list1 = [1, 2, 3]
list2 = ["a", "b", "c"]
for v1, v2 in zip(list1, list2):
print v1 + " " + v2
</code></pre>
<p>The above code should produce the following:</p>
<pre>1 a
2 b
3 c</pre>
<p>I wonder if there is a method like it available in .Net? I'm thinking about writing it myself, but there is no point if it's already available.</p>
|
[
{
"answer_id": 101207,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 3,
"selected": false,
"text": "class Pair<T1, T2>\n{\n public T1 First { get; set;}\n public T2 Second { get; set;}\n}\n\nstatic IEnumerable<Pair<T1, T2>> Zip<T1, T2>(IEnumerable<T1> first, IEnumerable<T2> second)\n{\n if (first.Count() != second.Count())\n throw new ArgumentException(\"Blah blah\");\n\n using (IEnumerator<T1> e1 = first.GetEnumerator())\n using (IEnumerator<T2> e2 = second.GetEnumerator())\n {\n while (e1.MoveNext() && e2.MoveNext())\n {\n yield return new Pair<T1, T2>() {First = e1.Current, Second = e2.Current};\n }\n }\n}\n\n...\n\nvar ints = new int[] {1, 2, 3};\nvar strings = new string[] {\"A\", \"B\", \"C\"};\n\nforeach (var pair in Zip(ints, strings))\n{\n Console.WriteLine(pair.First + \":\" + pair.Second);\n}\n"
},
{
"answer_id": 101222,
"author": "Matt Howells",
"author_id": 16881,
"author_profile": "https://Stackoverflow.com/users/16881",
"pm_score": 6,
"selected": true,
"text": "IEnumerable<TResult> Zip<TResult,T1,T2>\n (IEnumerable<T1> a,\n IEnumerable<T2> b,\n Func<T1,T2,TResult> combine)\n{\n using (var f = a.GetEnumerator())\n using (var s = b.GetEnumerator())\n {\n while (f.MoveNext() && s.MoveNext())\n yield return combine(f.Current, s.Current);\n }\n}\n"
},
{
"answer_id": 101227,
"author": "Cameron MacFarland",
"author_id": 3820,
"author_profile": "https://Stackoverflow.com/users/3820",
"pm_score": 3,
"selected": false,
"text": "public static IEnumerable<TResult> Zip<T1, T2, TResult>(this IEnumerable<T1> source1, IEnumerable<T2> source2, Func<T1, T2, TResult> combine)\n{\n using (IEnumerator<T1> data1 = source1.GetEnumerator())\n using (IEnumerator<T2> data2 = source2.GetEnumerator())\n while (data1.MoveNext() && data2.MoveNext())\n {\n yield return combine(data1.Current, data2.Current);\n }\n}\n int[] list1 = new int[] {1, 2, 3};\nstring[] list2 = new string[] {\"a\", \"b\", \"c\"};\n\nforeach (var result in list1.Zip(list2, (i, s) => i.ToString() + \" \" + s))\n Console.WriteLine(result);\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16047/"
] |
101,180
|
<p>I need to communicate with an XML-RPC server from a .NET 2.0 client. Can you recommend any libraries?</p>
<p>EDIT: Having tried XML-RPC.Net, I like the way it generates dynamic proxies, it is very neat. Unfortunately, as always, things are not so simple. I am accessing an XML-RPC service which uses the unorthodox technique of having object names in the names of the methods, like so:</p>
<pre><code>object1.object2.someMethod(string1)
</code></pre>
<p>This means I can't use the attributes to set the names of my methods, as they are not known until run-time. If you start trying to get closer to the raw calls, XML-RPC.Net starts to get pretty messy.</p>
<p>So, anyone know of a simple and straightforward XML-RPC library that'll just let me do (pseudocode):</p>
<pre><code>x = new xmlrpc(host, port)
x.makeCall("methodName", "arg1");
</code></pre>
<p>I had a look at a thing by Michael somebody on Codeproject, but there are no unit tests and the code looks pretty dire.</p>
<p>Unless someone has a better idea looks like I am going to have to start an open source project myself!</p>
|
[
{
"answer_id": 375036,
"author": "Troy J. Farrell",
"author_id": 26244,
"author_profile": "https://Stackoverflow.com/users/26244",
"pm_score": 3,
"selected": true,
"text": "ISumAndDiff proxy = (ISumAndDiff)XmlRpcProxyGen.Create(typeof(ISumAndDiff));\nproxy.XmlRpcMethod = \"Id1234_SumAndDifference\"\nproxy.SumAndDifference(3, 4);\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16881/"
] |
101,184
|
<p>I'm building an installer for an application. The user gets to select a datasource they have configured and nominate what type of database it is. I want to confirm that the database type is indeed Oracle, and if possible, what version of Oracle they are running by sending a SQL statement to the datasource.</p>
|
[
{
"answer_id": 101197,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 9,
"selected": true,
"text": "select * from v$version;\n BANNER\n----------------------------------------------------------------\nOracle Database 10g Release 10.2.0.3.0 - 64bit Production\nPL/SQL Release 10.2.0.3.0 - Production\nCORE 10.2.0.3.0 Production\nTNS for Solaris: Version 10.2.0.3.0 - Production\nNLSRTL Version 10.2.0.3.0 - Production\n"
},
{
"answer_id": 101240,
"author": "Peter Lang",
"author_id": 17343,
"author_profile": "https://Stackoverflow.com/users/17343",
"pm_score": 3,
"selected": false,
"text": "SELECT * FROM v$version;\n SET SERVEROUTPUT ON\nEXEC dbms_output.put_line( dbms_db_version.version );\n"
},
{
"answer_id": 101248,
"author": "Lawrence",
"author_id": 17621,
"author_profile": "https://Stackoverflow.com/users/17621",
"pm_score": 6,
"selected": false,
"text": "select * from v$version;\n Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production\nPL/SQL Release 11.1.0.6.0 - Production\nCORE 11.1.0.6.0 Production\nTNS for Solaris: Version 11.1.0.6.0 - Production\nNLSRTL Version 11.1.0.6.0 - Production\n select * from product_component_version;\n PRODUCT VERSION STATUS\nNLSRTL 11.1.0.6.0 Production\nOracle Database 11g Enterprise Edition 11.1.0.6.0 64bit Production\nPL/SQL 11.1.0.6.0 Production\nTNS for Solaris: 11.1.0.6.0 Production\n"
},
{
"answer_id": 8135737,
"author": "Ugur",
"author_id": 611688,
"author_profile": "https://Stackoverflow.com/users/611688",
"pm_score": 5,
"selected": false,
"text": "SQL> SELECT version FROM v$instance;\nVERSION\n-----------------\n11.2.0.3.0\n"
},
{
"answer_id": 16966359,
"author": "user2460369",
"author_id": 2460369,
"author_profile": "https://Stackoverflow.com/users/2460369",
"pm_score": -1,
"selected": false,
"text": "CREATE FUNCTION fn_which_edition\n RETURN VARCHAR2\n IS\n\n /*\n\n Purpose: determine which database edition\n\n MODIFICATION HISTORY\n Person Date Comments\n --------- ------ -------------------------------------------\n dcox 6/6/2013 Initial Build\n\n */\n\n -- Banner\n CURSOR c_get_banner\n IS\n SELECT banner\n FROM v$version\n WHERE UPPER(banner) LIKE UPPER('Oracle Database%');\n\n vrec_banner c_get_banner%ROWTYPE; -- row record\n v_database VARCHAR2(32767); --\n\nBEGIN\n -- Get banner to get edition\n OPEN c_get_banner;\n FETCH c_get_banner INTO vrec_banner;\n CLOSE c_get_banner;\n\n -- Check for Database type\n IF INSTR( UPPER(vrec_banner.banner), 'EXPRESS') > 0\n THEN\n v_database := 'EXPRESS';\n ELSIF INSTR( UPPER(vrec_banner.banner), 'STANDARD') > 0\n THEN\n v_database := 'STANDARD';\n ELSIF INSTR( UPPER(vrec_banner.banner), 'PERSONAL') > 0\n THEN\n v_database := 'PERSONAL';\n ELSIF INSTR( UPPER(vrec_banner.banner), 'ENTERPRISE') > 0\n THEN\n v_database := 'ENTERPRISE';\n ELSE\n v_database := 'UNKNOWN';\n END IF;\n\n RETURN v_database;\nEXCEPTION\n WHEN OTHERS\n THEN\n RETURN 'ERROR:' || SQLERRM(SQLCODE);\nEND fn_which_edition; -- function fn_which_edition\n/\n"
},
{
"answer_id": 23002006,
"author": "user3362908",
"author_id": 3362908,
"author_profile": "https://Stackoverflow.com/users/3362908",
"pm_score": 2,
"selected": false,
"text": "strings -a $ORACLE_HOME/bin/oracle |grep RDBMS | grep RELEASE\n"
},
{
"answer_id": 36998091,
"author": "Jack",
"author_id": 4652311,
"author_profile": "https://Stackoverflow.com/users/4652311",
"pm_score": 2,
"selected": false,
"text": "Select * from v$version;\n Select @@VERSION as Version\n Show variables LIKE \"%version%\";\n"
},
{
"answer_id": 53619137,
"author": "Pancho",
"author_id": 3051627,
"author_profile": "https://Stackoverflow.com/users/3051627",
"pm_score": 0,
"selected": false,
"text": "select edition,version from v$instance\n"
},
{
"answer_id": 55711356,
"author": "Lova Chittumuri",
"author_id": 5256337,
"author_profile": "https://Stackoverflow.com/users/5256337",
"pm_score": 0,
"selected": false,
"text": "set serveroutput on;\nBEGIN \nDBMS_OUTPUT.PUT_LINE(DBMS_DB_VERSION.VERSION || '.' || DBMS_DB_VERSION.RELEASE); \nEND;\n SQL> select *\n 2 from v$version;\n"
},
{
"answer_id": 63905716,
"author": "Prokhozhii",
"author_id": 8848025,
"author_profile": "https://Stackoverflow.com/users/8848025",
"pm_score": 0,
"selected": false,
"text": "select version\n , regexp_substr(banner, '[^[:space:]]+', 1, 4) as edition \nfrom v$instance\n , v$version where regexp_like(banner, 'edition', 'i');\n"
},
{
"answer_id": 64331709,
"author": "santosh tiwary",
"author_id": 9912306,
"author_profile": "https://Stackoverflow.com/users/9912306",
"pm_score": 2,
"selected": false,
"text": "SQL> SELECT * FROM v$version;\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10750/"
] |
101,195
|
<p>I'm playing with the wonderful <a href="http://hudson.gotdns.com/wiki/display/HUDSON/FindBugs+Plugin" rel="nofollow noreferrer">FindBugs plugin</a> for <a href="http://hudson-ci.org/" rel="nofollow noreferrer">Hudson</a>. Ideally, I'd like to have the build fail if FindBugs finds any problems. Is this possible?</p>
<p>Please, don't try and tell me that "0 warnings" is unrealistic with FindBugs. We've been using FindBugs from Ant for a while and we usually do maintain 0 warnings. We achieve this through the use of general exclude filters and specific/targeted annotations.</p>
|
[
{
"answer_id": 142245,
"author": "Tom",
"author_id": 22850,
"author_profile": "https://Stackoverflow.com/users/22850",
"pm_score": 2,
"selected": false,
"text": "<findbugs ... warningsProperty=\"findbugsFailure\"/> <fail if=\"findbugsFailure\">"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101195",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
101,196
|
<p>Is there a way to trigger a garbage collection in a .NET process from another process or from inside WinDBG?</p>
<p>There are the Managed Debugging Assistants that force a collection as you move across a native/managed boundary, and <a href="http://en.wikipedia.org/wiki/AQtime" rel="noreferrer">AQTime</a> seems to have button that suggests it does this, but I can't find any documentation on how to do it.</p>
|
[
{
"answer_id": 35159075,
"author": "Eric Boumendil",
"author_id": 249742,
"author_profile": "https://Stackoverflow.com/users/249742",
"pm_score": 4,
"selected": false,
"text": "PerfView.exe ForceGC [ProcessName | Process ID] /AcceptEULA\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5764/"
] |
101,198
|
<p>I'm building an installer for an application. The user gets to select a datasource they have configured and nominate what type of database it is. I want to confirm that the database type is indeed Postgres, and if possible, what version of Postgres they are running by sending a SQL statement to the datasource.</p>
|
[
{
"answer_id": 101210,
"author": "Galwegian",
"author_id": 3201,
"author_profile": "https://Stackoverflow.com/users/3201",
"pm_score": 2,
"selected": false,
"text": "SELECT version();\n"
},
{
"answer_id": 101214,
"author": "Matthias Kestenholz",
"author_id": 317346,
"author_profile": "https://Stackoverflow.com/users/317346",
"pm_score": 3,
"selected": true,
"text": "mk=# SELECT version();\n version \n-----------------------------------------------------------------------------------------------\n PostgreSQL 8.3.3 on i486-pc-linux-gnu, compiled by GCC cc (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)\n(1 row)\n mysql> select version();\n+--------------------------------+\n| version() |\n+--------------------------------+\n| 5.0.32-Debian_7etch1~bpo.1-log | \n+--------------------------------+\n1 row in set (0.01 sec)\n"
},
{
"answer_id": 101215,
"author": "Neall",
"author_id": 619,
"author_profile": "https://Stackoverflow.com/users/619",
"pm_score": 2,
"selected": false,
"text": "SELECT version();\n version\n-----------------------------------------------------------------------------------------------\nPostgreSQL 8.3.3 on i486-pc-linux-gnu, compiled by GCC cc (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)\n"
},
{
"answer_id": 101218,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 2,
"selected": false,
"text": "select version()\n"
},
{
"answer_id": 101253,
"author": "Milen A. Radev",
"author_id": 15785,
"author_profile": "https://Stackoverflow.com/users/15785",
"pm_score": 2,
"selected": false,
"text": "SHOW server_version;"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10750/"
] |
101,212
|
<p>Net::HTTP can be rather cumbersome for the standard use case!</p>
|
[
{
"answer_id": 101542,
"author": "Aaron Hinni",
"author_id": 12086,
"author_profile": "https://Stackoverflow.com/users/12086",
"pm_score": 3,
"selected": false,
"text": "gem install rest-open-uri\n response = open('https://wherever/foo',\n :method => :put,\n :http_basic_authentication => ['my-user', 'my-passwd'],\n :body => 'payload')\n\nputs response.read\n"
},
{
"answer_id": 101680,
"author": "Clinton Dreisbach",
"author_id": 6262,
"author_profile": "https://Stackoverflow.com/users/6262",
"pm_score": 4,
"selected": false,
"text": "require 'rubygems'\nrequire 'httparty'\n\nclass Representative\n include HTTParty\n format :xml\n\n def self.find_by_zip(zip)\n get('http://whoismyrepresentative.com/whoismyrep.php', :query => {:zip => zip})\n end\nend\n\nputs Representative.find_by_zip(46544).inspect\n# {\"result\"=>{\"n\"=>\"1\", \"rep\"=>{\"name\"=>\"Joe Donnelly\", \"district\"=>\"2\", \"office\"=>\"1218 Longworth\", \"phone\"=>\"(202) 225-3915\", \"link\"=>\"http://donnelly.house.gov/\", \"state\"=>\"IN\"}}}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18751/"
] |
101,223
|
<p>I have a pivot table on an olap cube. I can go into a page field and manually deselect multiple items. How can I do this in VBA based on a list of items I need excluded? (n.b. I do not have a corrresponding list of items I need included)</p>
<p>I know how to exclude these items in other ways, by altering the underlying query for example. I specifically want to replicate the user action of deselecting items in the pivot.</p>
|
[
{
"answer_id": 101464,
"author": "juan",
"author_id": 1782,
"author_profile": "https://Stackoverflow.com/users/1782",
"pm_score": 0,
"selected": false,
"text": "((MOE.PivotField)pivotTableObject.PivotFields(\"[NAME]\")).Delete();\n"
},
{
"answer_id": 102734,
"author": "Hobbo",
"author_id": 6387,
"author_profile": "https://Stackoverflow.com/users/6387",
"pm_score": 0,
"selected": false,
"text": "PivotField.CubeField.EnableMultiplePageItems = True\nfirstTime = True\nFor Each member In dimensionMembers\n If Not HiddenMembers.Exists(member) Then\n 'firstTime = true is the equivalent of unchecking \n ' the root node of the items treeview\n PivotField.CubeField.AddPageItem \"[Dimension].[\" & member & \"]\", firstTime\n firstTime = False\n End If\nNext\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6387/"
] |
101,238
|
<p>I've got many assemblies/projects in the same c#/.net solution. A setting needs to be saved by people using the web application gui, and then a console app and some test projects need to access the same file. Where should I put the file and how to access it?</p>
<p>I've tried using "AppDomain.CurrentDomain.BaseDirectory" but that ends up being different for my assemblies. Also the "System.Reflection.Assembly.Get*Assembly.Location" fail to give me what I need.</p>
<p>Maybe this isn't something I should but in a file, but rather the database? But it feels so complicated doing that for a few lines of configuration.</p>
|
[
{
"answer_id": 101287,
"author": "Pop Catalin",
"author_id": 4685,
"author_profile": "https://Stackoverflow.com/users/4685",
"pm_score": 2,
"selected": false,
"text": " Path.Combine(\n Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),\n \"[Company Name]\\[Application Suite]\");\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101238",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3397/"
] |
101,244
|
<pre><code>/etc/init.d/*
/etc/rc{1-5}.d/*
</code></pre>
|
[
{
"answer_id": 101246,
"author": "px.",
"author_id": 18769,
"author_profile": "https://Stackoverflow.com/users/18769",
"pm_score": 2,
"selected": false,
"text": "/sbin/chkconfig /sbin/chkconfig /etc/rc.d/init.d/"
},
{
"answer_id": 101277,
"author": "dsm",
"author_id": 7780,
"author_profile": "https://Stackoverflow.com/users/7780",
"pm_score": 1,
"selected": true,
"text": "init /etc/init.d init 3 rc3.d"
},
{
"answer_id": 186350,
"author": "jtimberman",
"author_id": 7672,
"author_profile": "https://Stackoverflow.com/users/7672",
"pm_score": 1,
"selected": false,
"text": "# chkconfig: - 85 15\n# description: Apache is a World Wide Web server. It is used to serve \\\n# HTML files and CGI.\n# processname: httpd\n# config: /etc/httpd/conf/httpd.conf\n# config: /etc/sysconfig/httpd\n# pidfile: /var/run/httpd.pid\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18769/"
] |
101,258
|
<p>I want to search for <code>$maximumTotalAllowedAfterFinish</code> and replace it with <code>$minimumTotalAllowedAfterFinish</code>. Instead of typing the long text:</p>
<pre><code>:%s/$maximumTotalAllowedAfterFinish/$minimumTotalAllowedAfterFinish/g
</code></pre>
<p>Is there a way to COPY these long variable names down into the search line, since, on the command line I can't type "<code>p</code>" to paste?</p>
|
[
{
"answer_id": 101281,
"author": "Johannes Hoff",
"author_id": 3102,
"author_profile": "https://Stackoverflow.com/users/3102",
"pm_score": 4,
"selected": false,
"text": "q: Enter"
},
{
"answer_id": 101285,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 2,
"selected": false,
"text": ": \"add@a\n a :%s/$maximumTotalAllowedAfterFinish/$minimumTotalAllowedAfterFinish/g\n q:"
},
{
"answer_id": 101292,
"author": "WMR",
"author_id": 2844,
"author_profile": "https://Stackoverflow.com/users/2844",
"pm_score": 8,
"selected": true,
"text": "{0-9a-z\"%#:-=.} :he cmdline-editing\n"
},
{
"answer_id": 101312,
"author": "Ned",
"author_id": 1105,
"author_profile": "https://Stackoverflow.com/users/1105",
"pm_score": 6,
"selected": false,
"text": ":help c_<C-R>"
},
{
"answer_id": 101682,
"author": "Zsolt Botykai",
"author_id": 11621,
"author_profile": "https://Stackoverflow.com/users/11621",
"pm_score": 2,
"selected": false,
"text": "s/foo/bar/gci\n \"ayy a :[OPTIONAL_RANGE]@a\n"
},
{
"answer_id": 43527298,
"author": "Jason",
"author_id": 2218905,
"author_profile": "https://Stackoverflow.com/users/2218905",
"pm_score": 5,
"selected": false,
"text": "v y / Ctrl + R + 0"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] |
101,265
|
<p>Inspired by another question asking about the missing <code>Zip</code> function:</p>
<p>Why is there no <code>ForEach</code> extension method on the <code>IEnumerable</code> interface? Or anywhere? The only class that gets a <code>ForEach</code> method is <code>List<></code>. Is there a reason why it's missing, maybe performance?</p>
|
[
{
"answer_id": 101278,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 6,
"selected": false,
"text": "public static void ForEach<T>(\n this IEnumerable<T> source,\n Action<T> action)\n{\n foreach (T element in source) \n action(element);\n}\n"
},
{
"answer_id": 101303,
"author": "Aaron Powell",
"author_id": 11388,
"author_profile": "https://Stackoverflow.com/users/11388",
"pm_score": 4,
"selected": false,
"text": "public static void ForEach<T>(this IEnumerable<T> col, Action<T> action)\n{\n if (action == null)\n {\n throw new ArgumentNullException(\"action\");\n }\n foreach (var item in col)\n {\n action(item);\n }\n}\n"
},
{
"answer_id": 101313,
"author": "Coincoin",
"author_id": 42,
"author_profile": "https://Stackoverflow.com/users/42",
"pm_score": 9,
"selected": true,
"text": "foreach list.ForEach( item =>\n{\n item.DoSomething();\n} );\n foreach(Item item in list)\n{\n item.DoSomething();\n}\n ForEach() ForEach()"
},
{
"answer_id": 101331,
"author": "TraumaPony",
"author_id": 18658,
"author_profile": "https://Stackoverflow.com/users/18658",
"pm_score": 2,
"selected": false,
"text": "Seq.iter doSomething myIEnumerable"
},
{
"answer_id": 101781,
"author": "user18784",
"author_id": 18784,
"author_profile": "https://Stackoverflow.com/users/18784",
"pm_score": 2,
"selected": false,
"text": "foreach(X x in Y) \n IEnumerator<int> enumerator = list.GetEnumerator();\nwhile (enumerator.MoveNext())\n{\n int i = enumerator.Current;\n\n Console.WriteLine(i);\n}\n"
},
{
"answer_id": 102092,
"author": "Scott Dorman",
"author_id": 1559,
"author_profile": "https://Stackoverflow.com/users/1559",
"pm_score": 3,
"selected": false,
"text": "collection.Where(i => i.Name = \"hello\").Select(i => i.FullName);\n <T <T"
},
{
"answer_id": 102512,
"author": "Chris Zwiryk",
"author_id": 734,
"author_profile": "https://Stackoverflow.com/users/734",
"pm_score": 5,
"selected": false,
"text": "foreach foreach public static int ForEach<T>(this IEnumerable<T> list, Action<int, T> action)\n{\n if (action == null) throw new ArgumentNullException(\"action\");\n\n var index = 0;\n\n foreach (var elem in list)\n action(index++, elem);\n\n return index;\n}\n var people = new[] { \"Moe\", \"Curly\", \"Larry\" };\npeople.ForEach((i, p) => Console.WriteLine(\"Person #{0} is {1}\", i, p));\n Person #0 is Moe\nPerson #1 is Curly\nPerson #2 is Larry\n"
},
{
"answer_id": 216654,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 4,
"selected": false,
"text": ".ToList().ForEach(x => ...) .ForEach()"
},
{
"answer_id": 216668,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 6,
"selected": false,
"text": "// Possibly call this \"Do\"\nIEnumerable<T> Apply<T> (this IEnumerable<T> source, Action<T> action)\n{\n foreach (var e in source)\n {\n action(e);\n yield return e;\n }\n}\n MySequence\n .Apply(...)\n .Apply(...)\n .Apply(...);\n .ForEach() .ToList() // possibly call this \"Realize\"\nIEnumerable<T> Done<T> (this IEnumerable<T> source)\n{\n foreach (var e in source)\n {\n // do nothing\n ;\n }\n\n return source;\n}\n"
},
{
"answer_id": 255500,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "Action<> Action<> Action<blah,blah> f = { foo };\n\nList1.ForEach(p => f(p))\nList2.ForEach(p => f(p))\n"
},
{
"answer_id": 14997597,
"author": "Martijn",
"author_id": 381801,
"author_profile": "https://Stackoverflow.com/users/381801",
"pm_score": 3,
"selected": false,
"text": "Select IEnumerable<string> people = new List<string>(){\"alica\", \"bob\", \"john\", \"pete\"};\npeople.Select(p => { Console.WriteLine(p); return p; });\n Count() static IEnumerable<T> WithLazySideEffect(this IEnumerable<T> src, Action<T> action) {\n return src.Select(i => { action(i); return i; } );\n}\n people.WithLazySideEffect(p => Console.WriteLine(p))"
},
{
"answer_id": 20873090,
"author": "Dave Clausen",
"author_id": 394007,
"author_profile": "https://Stackoverflow.com/users/394007",
"pm_score": 3,
"selected": false,
"text": "ForEach Pipe"
},
{
"answer_id": 35456376,
"author": "fredefox",
"author_id": 1021134,
"author_profile": "https://Stackoverflow.com/users/1021134",
"pm_score": 2,
"selected": false,
"text": "private static IEnumerable<T> ForEach<T>(IEnumerable<T> xs, Action<T> f) {\n foreach (var x in xs) {\n f(x); yield return x;\n }\n}\n"
},
{
"answer_id": 67588800,
"author": "Liran Barniv",
"author_id": 1552782,
"author_profile": "https://Stackoverflow.com/users/1552782",
"pm_score": 0,
"selected": false,
"text": "public static class EnumerableExtension\n{\n public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)\n {\n source.All(x =>\n {\n action.Invoke(x);\n return true;\n });\n }\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3820/"
] |
101,267
|
<p>When I used to write libraries in C/C++ I got into the habit of having a method to return the compile date/time. This was always a compiled into the library so would differentiate builds of the library. I got this by returning a #define in the code:</p>
<p>C++:</p>
<pre><code>#ifdef _BuildDateTime_
char* SomeClass::getBuildDateTime() {
return _BuildDateTime_;
}
#else
char* SomeClass::getBuildDateTime() {
return "Undefined";
}
#endif
</code></pre>
<p>Then on the compile I had a '-D_BuildDateTime_=<code>Date</code>' in the build script.</p>
<p>Is there any way to achieve this or similar in Java without needing to remember to edit any files manually or distributing any seperate files.</p>
<p>One suggestion I got from a co-worker was to get the ant file to create a file on the classpath and to package that into the JAR and have it read by the method. </p>
<p>Something like (assuming the file created was called 'DateTime.dat'):</p>
<pre><code>// I know Exceptions and proper open/closing
// of the file are not done. This is just
// to explain the point!
String getBuildDateTime() {
return new BufferedReader(getClass()
.getResourceAsStream("DateTime.dat")).readLine();
}
</code></pre>
<p>To my mind that's a hack and could be circumvented/broken by someone having a similarly named file <em>outside</em> the JAR, but on the classpath.</p>
<p>Anyway, my question is whether there is any way to inject a constant into a class at compile time</p>
<p>EDIT</p>
<p>The reason I consider using an externally generated file in the JAR a hack is because this <em>is</em>) a library and will be embedded in client apps. These client apps may define their own classloaders meaning I can't rely on the standard JVM class loading rules.</p>
<p>My personal preference would be to go with using the date from the JAR file as suggested by serg10.</p>
|
[
{
"answer_id": 101293,
"author": "basszero",
"author_id": 287,
"author_profile": "https://Stackoverflow.com/users/287",
"pm_score": 1,
"selected": false,
"text": "Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(\"META-INF/MANIFEST.MF\");\n"
},
{
"answer_id": 101334,
"author": "MB.",
"author_id": 11961,
"author_profile": "https://Stackoverflow.com/users/11961",
"pm_score": 1,
"selected": false,
"text": "public String getBuildDateTime() {\n return \"@BUILD_DATE_TIME@\";\n}\n"
},
{
"answer_id": 101376,
"author": "Karl",
"author_id": 17613,
"author_profile": "https://Stackoverflow.com/users/17613",
"pm_score": 4,
"selected": false,
"text": "class Version... {\n public static String tstamp() {\n return \"@BUILDTIME@\";\n }\n}\n <copy src=\"templatefile\" dst=\"Version.java\" filtering=\"true\">\n <filter token=\"BUILDTIME\" value=\"${build.tstamp}\" />\n</copy>\n"
},
{
"answer_id": 102747,
"author": "serg10",
"author_id": 1853,
"author_profile": "https://Stackoverflow.com/users/1853",
"pm_score": 5,
"selected": true,
"text": "import java.util.jar.*;\n\n...\n\nJarFile myJar = new JarFile(\"nameOfJar.jar\"); // various constructors available\nManifest manifest = myJar.getManifest();\nMap<String,Attributes> manifestContents = manifest.getAttributes();\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18744/"
] |
101,268
|
<p>What are the lesser-known but useful features of the Python programming language?</p>
<ul>
<li>Try to limit answers to Python core.</li>
<li>One feature per answer.</li>
<li>Give an example and short description of the feature, not just a link to documentation.</li>
<li>Label the feature using a title as the first line.</li>
</ul>
<h2>Quick links to answers:</h2>
<ul>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#111176">Argument Unpacking</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#112303">Braces</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#101945">Chaining Comparison Operators</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#101447">Decorators</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#113198">Default Argument Gotchas / Dangers of Mutable Default arguments</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#102062">Descriptors</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#111970">Dictionary default <code>.get</code> value</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#102065">Docstring Tests</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python/112316#112316">Ellipsis Slicing Syntax</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#117116">Enumeration</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#114420">For/else</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#102202">Function as iter() argument</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#101310">Generator expressions</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#101276"><code>import this</code></a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#102037">In Place Value Swapping</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#101840">List stepping</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#112286"><code>__missing__</code> items</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#101537">Multi-line Regex</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#113164">Named string formatting</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#101549">Nested list/generator comprehensions</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#108297">New types at runtime</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#113833"><code>.pth</code> files</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#1024693">ROT13 Encoding</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#143636">Regex Debugging</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#101739">Sending to Generators</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#168270">Tab Completion in Interactive Interpreter</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#116480">Ternary Expression</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#114157"><code>try/except/else</code></a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#3267903">Unpacking+<code>print()</code> function</a></li>
<li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python#109182"><code>with</code> statement</a></li>
</ul>
|
[
{
"answer_id": 101276,
"author": "cleg",
"author_id": 29503,
"author_profile": "https://Stackoverflow.com/users/29503",
"pm_score": 7,
"selected": false,
"text": "import this\n# btw look at this module's source :)\n"
},
{
"answer_id": 101280,
"author": "Oko",
"author_id": 9402,
"author_profile": "https://Stackoverflow.com/users/9402",
"pm_score": 3,
"selected": false,
"text": "foo = []\nfor x in xrange(10):\n if x % 2 == 0:\n foo.append(x)\n foo = [x for x in xrange(10) if x % 2 == 0]\n"
},
{
"answer_id": 101310,
"author": "freespace",
"author_id": 8297,
"author_profile": "https://Stackoverflow.com/users/8297",
"pm_score": 9,
"selected": false,
"text": "x=(n for n in foo if bar(n))\n for n in x:\n x = [n for n in foo if bar(n)]\n >>> n = ((a,b) for a in range(0,2) for b in range(4,6))\n>>> for i in n:\n... print i \n\n(0, 4)\n(0, 5)\n(1, 4)\n(1, 5)\n"
},
{
"answer_id": 101447,
"author": "DzinX",
"author_id": 18745,
"author_profile": "https://Stackoverflow.com/users/18745",
"pm_score": 8,
"selected": false,
"text": "print_args >>> def print_args(function):\n>>> def wrapper(*args, **kwargs):\n>>> print 'Arguments:', args, kwargs\n>>> return function(*args, **kwargs)\n>>> return wrapper\n\n>>> @print_args\n>>> def write(text):\n>>> print text\n\n>>> write('foo')\nArguments: ('foo',) {}\nfoo\n"
},
{
"answer_id": 101537,
"author": "MvdD",
"author_id": 18044,
"author_profile": "https://Stackoverflow.com/users/18044",
"pm_score": 8,
"selected": false,
"text": ">>> pattern = \"\"\"\n... ^ # beginning of string\n... M{0,4} # thousands - 0 to 4 M's\n... (CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's),\n... # or 500-800 (D, followed by 0 to 3 C's)\n... (XC|XL|L?X{0,3}) # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's),\n... # or 50-80 (L, followed by 0 to 3 X's)\n... (IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's),\n... # or 5-8 (V, followed by 0 to 3 I's)\n... $ # end of string\n... \"\"\"\n>>> re.search(pattern, 'M', re.VERBOSE)\n >>> p = re.compile(r'(?P<word>\\b\\w+\\b)')\n>>> m = p.search( '(((( Lots of punctuation )))' )\n>>> m.group('word')\n'Lots'\n re.VERBOSE >>> pattern = (\n... \"^\" # beginning of string\n... \"M{0,4}\" # thousands - 0 to 4 M's\n... \"(CM|CD|D?C{0,3})\" # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's),\n... # or 500-800 (D, followed by 0 to 3 C's)\n... \"(XC|XL|L?X{0,3})\" # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's),\n... # or 50-80 (L, followed by 0 to 3 X's)\n... \"(IX|IV|V?I{0,3})\" # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's),\n... # or 5-8 (V, followed by 0 to 3 I's)\n... \"$\" # end of string\n... )\n>>> print pattern\n\"^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$\"\n"
},
{
"answer_id": 101549,
"author": "Rafał Dowgird",
"author_id": 12166,
"author_profile": "https://Stackoverflow.com/users/12166",
"pm_score": 7,
"selected": false,
"text": "[(i,j) for i in range(3) for j in range(i) ] \n((i,j) for i in range(4) for j in range(i) )\n"
},
{
"answer_id": 101731,
"author": "Ber",
"author_id": 11527,
"author_profile": "https://Stackoverflow.com/users/11527",
"pm_score": 5,
"selected": false,
"text": "attrgetter() itemgetter() operator"
},
{
"answer_id": 101739,
"author": "Rafał Dowgird",
"author_id": 12166,
"author_profile": "https://Stackoverflow.com/users/12166",
"pm_score": 8,
"selected": false,
"text": "def mygen():\n \"\"\"Yield 5 until something else is passed back via send()\"\"\"\n a = 5\n while True:\n f = (yield a) #yield a and possibly get f in return\n if f is not None: \n a = f #store the new value\n >>> g = mygen()\n>>> g.next()\n5\n>>> g.next()\n5\n>>> g.send(7) #we send this back to the generator\n7\n>>> g.next() #now it will yield 7 until we send something else\n7\n"
},
{
"answer_id": 101778,
"author": "Kevin Little",
"author_id": 14028,
"author_profile": "https://Stackoverflow.com/users/14028",
"pm_score": 1,
"selected": false,
"text": ">>> x=[1,1,2,'a','a',3]\n>>> y = [ _x for _x in x if not _x in locals()['_[1]'] ]\n>>> y\n[1, 2, 'a', 3]\n"
},
{
"answer_id": 101840,
"author": "Rafał Dowgird",
"author_id": 12166,
"author_profile": "https://Stackoverflow.com/users/12166",
"pm_score": 8,
"selected": false,
"text": "a = [1,2,3,4,5]\n>>> a[::2] # iterate over the whole list in 2-increments\n[1,3,5]\n x[::-1] >>> a[::-1]\n[5,4,3,2,1]\n"
},
{
"answer_id": 101892,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 5,
"selected": false,
"text": ">>> print \"Hello \" \"World\"\nHello World\n hello = \"Greaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Hello \" \\\n \"Word\"\n hello = (\"Greaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Hello \" \n \"Word\")\n"
},
{
"answer_id": 101919,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 6,
"selected": false,
"text": "class C(object):\n def __init__(self, foo, bar):\n self.foo = foo # read-write property\n self.bar = bar # simple attribute\n\n def _set_foo(self, value):\n self._foo = value\n\n def _get_foo(self):\n return self._foo\n\n def _del_foo(self):\n del self._foo\n\n # any of fget, fset, fdel and doc are optional,\n # so you can make a write-only and/or delete-only property.\n foo = property(fget = _get_foo, fset = _set_foo,\n fdel = _del_foo, doc = 'Hello, I am foo!')\n\nclass D(C):\n def _get_foo(self):\n return self._foo * 2\n\n def _set_foo(self, value):\n self._foo = value / 2\n\n foo = property(fget = _get_foo, fset = _set_foo,\n fdel = C.foo.fdel, doc = C.foo.__doc__)\n class C(object):\n def __init__(self, foo, bar):\n self.foo = foo # read-write property\n self.bar = bar # simple attribute\n\n @property\n def foo(self):\n '''Hello, I am foo!'''\n\n return self._foo\n\n @foo.setter\n def foo(self, value):\n self._foo = value\n\n @foo.deleter\n def foo(self):\n del self._foo\n\nclass D(C):\n @C.foo.getter\n def foo(self):\n return self._foo * 2\n\n @foo.setter\n def foo(self, value):\n self._foo = value / 2\n"
},
{
"answer_id": 101945,
"author": "Thomas Wouters",
"author_id": 17624,
"author_profile": "https://Stackoverflow.com/users/17624",
"pm_score": 10,
"selected": false,
"text": ">>> x = 5\n>>> 1 < x < 10\nTrue\n>>> 10 < x < 20 \nFalse\n>>> x < 10 < x*10 < 100\nTrue\n>>> 10 > x <= 9\nTrue\n>>> 5 == x > 4\nTrue\n 1 < x True True < 10 True 1 < x and x < 10 x < 10 and 10 < x * 10 and x*10 < 100"
},
{
"answer_id": 102006,
"author": "Thomas Wouters",
"author_id": 17624,
"author_profile": "https://Stackoverflow.com/users/17624",
"pm_score": 7,
"selected": false,
"text": "# Python 2 syntax\ntry:\n some_operation()\nexcept SomeError, e:\n if is_fatal(e):\n raise\n handle_nonfatal(e)\n\n# Python 3 syntax\ntry:\n some_operation()\nexcept SomeError as e:\n if is_fatal(e):\n raise\n handle_nonfatal(e)\n"
},
{
"answer_id": 102037,
"author": "Lucas S.",
"author_id": 7363,
"author_profile": "https://Stackoverflow.com/users/7363",
"pm_score": 8,
"selected": false,
"text": ">>> a = 10\n>>> b = 5\n>>> a, b\n(10, 5)\n\n>>> a, b = b, a\n>>> a, b\n(5, 10)\n a b a b"
},
{
"answer_id": 102062,
"author": "Nick Johnson",
"author_id": 12030,
"author_profile": "https://Stackoverflow.com/users/12030",
"pm_score": 7,
"selected": false,
"text": "__get__ __set__ __delete__ class Property(object):\n def __init__(self, fget):\n self.fget = fget\n\n def __get__(self, obj, type):\n if obj is None:\n return self\n return self.fget(obj)\n class MyClass(object):\n @Property\n def foo(self):\n return \"Foo!\"\n"
},
{
"answer_id": 102065,
"author": "Pierre-Jean Coudert",
"author_id": 8450,
"author_profile": "https://Stackoverflow.com/users/8450",
"pm_score": 7,
"selected": false,
"text": "def factorial(n):\n \"\"\"Return the factorial of n, an exact integer >= 0.\n\n If the result is small enough to fit in an int, return an int.\n Else return a long.\n\n >>> [factorial(n) for n in range(6)]\n [1, 1, 2, 6, 24, 120]\n >>> factorial(-1)\n Traceback (most recent call last):\n ...\n ValueError: n must be >= 0\n\n Factorials of floats are OK, but the float must be an exact integer:\n \"\"\"\n\n import math\n if not n >= 0:\n raise ValueError(\"n must be >= 0\")\n if math.floor(n) != n:\n raise ValueError(\"n must be exact integer\")\n if n+1 == n: # catch a value like 1e300\n raise OverflowError(\"n too large\")\n result = 1\n factor = 2\n while factor <= n:\n result *= factor\n factor += 1\n return result\n\ndef _test():\n import doctest\n doctest.testmod() \n\nif __name__ == \"__main__\":\n _test()\n"
},
{
"answer_id": 102202,
"author": "mbac32768",
"author_id": 18446,
"author_profile": "https://Stackoverflow.com/users/18446",
"pm_score": 8,
"selected": false,
"text": "def seek_next_line(f):\n for c in iter(lambda: f.read(1),'\\n'):\n pass\n iter(callable, until_value) callable until_value"
},
{
"answer_id": 103198,
"author": "pi.",
"author_id": 15274,
"author_profile": "https://Stackoverflow.com/users/15274",
"pm_score": 3,
"selected": false,
"text": "from collections import defaultdict\n def defaultdict(type_):\n class Dict(dict):\n def __getitem__(self, key):\n return self.setdefault(key, type_())\n return Dict()\n d = defaultdict(list)\nfor stuff in lots_of_stuff:\n d[stuff.name].append(stuff)\n def defaultdict(default_factory, *args, **kw): \n\n class defaultdict(dict):\n\n def __missing__(self, key):\n if default_factory is None:\n raise KeyError(key)\n return self.setdefault(key, default_factory())\n\n def __getitem__(self, key):\n try:\n return dict.__getitem__(self, key)\n except KeyError:\n return self.__missing__(key)\n\n return defaultdict(*args, **kw)\n"
},
{
"answer_id": 105325,
"author": "davidavr",
"author_id": 8247,
"author_profile": "https://Stackoverflow.com/users/8247",
"pm_score": 5,
"selected": false,
"text": ">>> \n"
},
{
"answer_id": 106868,
"author": "Jeremy Cantrell",
"author_id": 18866,
"author_profile": "https://Stackoverflow.com/users/18866",
"pm_score": 4,
"selected": false,
"text": ">>> def jim(phrase):\n... return 'Jim says, \"%s\".' % phrase\n>>> def say_something(person, phrase):\n... print person(phrase)\n\n>>> say_something(jim, 'hey guys')\n'Jim says, \"hey guys\".'\n"
},
{
"answer_id": 108297,
"author": "Torsten Marek",
"author_id": 9567,
"author_profile": "https://Stackoverflow.com/users/9567",
"pm_score": 8,
"selected": false,
"text": ">>> NewType = type(\"NewType\", (object,), {\"x\": \"hello\"})\n>>> n = NewType()\n>>> n.x\n\"hello\"\n >>> class NewType(object):\n>>> x = \"hello\"\n>>> n = NewType()\n>>> n.x\n\"hello\"\n NewType class"
},
{
"answer_id": 108312,
"author": "Torsten Marek",
"author_id": 9567,
"author_profile": "https://Stackoverflow.com/users/9567",
"pm_score": 5,
"selected": false,
"text": "if for >>> [(x, y) for x in range(4) if x % 2 == 1 for y in range(4)]\n[(1, 0), (1, 1), (1, 2), (1, 3), (3, 0), (3, 1), (3, 2), (3, 3)]\n"
},
{
"answer_id": 109182,
"author": "Ycros",
"author_id": 10495,
"author_profile": "https://Stackoverflow.com/users/10495",
"pm_score": 7,
"selected": false,
"text": "with __future__ from __future__ import with_statement\n\nwith open('foo.txt', 'w') as f:\n f.write('hello!')\n __enter__ __exit__ __exit__ with"
},
{
"answer_id": 111176,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 8,
"selected": false,
"text": "* ** def draw_point(x, y):\n # do some magic\n\npoint_foo = (3, 4)\npoint_bar = {'y': 3, 'x': 2}\n\ndraw_point(*point_foo)\ndraw_point(**point_bar)\n"
},
{
"answer_id": 111970,
"author": "Amandasaurus",
"author_id": 161922,
"author_profile": "https://Stackoverflow.com/users/161922",
"pm_score": 7,
"selected": false,
"text": "sum[value] = sum.get(value, 0) + 1"
},
{
"answer_id": 112274,
"author": "Armin Ronacher",
"author_id": 19990,
"author_profile": "https://Stackoverflow.com/users/19990",
"pm_score": 2,
"selected": false,
"text": "exec >>> def f():\n... exec \"a = 42\"\n... return a\n... \n>>> def g():\n... a = 42\n... return a\n... \n>>> import dis\n>>> dis.dis(f)\n 2 0 LOAD_CONST 1 ('a = 42')\n 3 LOAD_CONST 0 (None)\n 6 DUP_TOP \n 7 EXEC_STMT \n\n 3 8 LOAD_NAME 0 (a)\n 11 RETURN_VALUE \n>>> dis.dis(g)\n 2 0 LOAD_CONST 1 (42)\n 3 STORE_FAST 0 (a)\n\n 3 6 LOAD_FAST 0 (a)\n 9 RETURN_VALUE \n"
},
{
"answer_id": 112286,
"author": "Armin Ronacher",
"author_id": 19990,
"author_profile": "https://Stackoverflow.com/users/19990",
"pm_score": 8,
"selected": false,
"text": "__missing__ >>> class MyDict(dict):\n... def __missing__(self, key):\n... self[key] = rv = []\n... return rv\n... \n>>> m = MyDict()\n>>> m[\"foo\"].append(1)\n>>> m[\"foo\"].append(2)\n>>> dict(m)\n{'foo': [1, 2]}\n collections defaultdict >>> from collections import defaultdict\n>>> m = defaultdict(list)\n>>> m[\"foo\"].append(1)\n>>> m[\"foo\"].append(2)\n>>> dict(m)\n{'foo': [1, 2]}\n d[a_key]"
},
{
"answer_id": 112296,
"author": "Armin Ronacher",
"author_id": 19990,
"author_profile": "https://Stackoverflow.com/users/19990",
"pm_score": 3,
"selected": false,
"text": "__dict__ >>> class User(object):\n... def _get_username(self):\n... return self.__dict__['username']\n... def _set_username(self, value):\n... print 'username set'\n... self.__dict__['username'] = value\n... username = property(_get_username, _set_username)\n... del _get_username, _set_username\n... \n>>> u = User()\n>>> u.username = \"foo\"\nusername set\n>>> u.__dict__\n{'username': 'foo'}\n dir()"
},
{
"answer_id": 112303,
"author": "eduffy",
"author_id": 7536,
"author_profile": "https://Stackoverflow.com/users/7536",
"pm_score": 8,
"selected": false,
"text": "from __future__ import braces\n"
},
{
"answer_id": 112306,
"author": "Armin Ronacher",
"author_id": 19990,
"author_profile": "https://Stackoverflow.com/users/19990",
"pm_score": 4,
"selected": false,
"text": "__slots__ class Point(object):\n __slots__ = ('x', 'y')\n >>> p = Point()\n>>> p.x = 3\n>>> p.y = 5\n>>> dict((k, getattr(p, k)) for k in p.__slots__)\n{'y': 5, 'x': 3}\n __reduce_ex__ copy >>> p.__reduce_ex__(2)[2][1]\n{'y': 5, 'x': 3}\n"
},
{
"answer_id": 112316,
"author": "Armin Ronacher",
"author_id": 19990,
"author_profile": "https://Stackoverflow.com/users/19990",
"pm_score": 6,
"selected": false,
"text": ">>> class C(object):\n... def __getitem__(self, item):\n... return item\n... \n>>> C()[1:2, ..., 3]\n(slice(1, 2, None), Ellipsis, 3)\n"
},
{
"answer_id": 112325,
"author": "Armin Ronacher",
"author_id": 19990,
"author_profile": "https://Stackoverflow.com/users/19990",
"pm_score": 3,
"selected": false,
"text": ">>> class C(object):\n... id = id\n... \n>>> C().id()\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nTypeError: id() takes exactly one argument (0 given)\n >>> from types import MethodType\n>>> class bind(object):\n... def __init__(self, callable):\n... self.callable = callable\n... def __get__(self, obj, type=None):\n... if obj is None:\n... return self\n... return MethodType(self.callable, obj, type)\n... \n>>> class C(object):\n... id = bind(id)\n... \n>>> C().id()\n7414064\n"
},
{
"answer_id": 113164,
"author": "Pasi Savolainen",
"author_id": 20195,
"author_profile": "https://Stackoverflow.com/users/20195",
"pm_score": 7,
"selected": false,
"text": ">>> print \"The %(foo)s is %(bar)i.\" % {'foo': 'answer', 'bar':42}\nThe answer is 42.\n\n>>> foo, bar = 'question', 123\n\n>>> print \"The %(foo)s is %(bar)i.\" % locals()\nThe question is 123.\n >>> print(\"The {foo} is {bar}\".format(foo='answer', bar=42))\n"
},
{
"answer_id": 113198,
"author": "Jason Baker",
"author_id": 2147,
"author_profile": "https://Stackoverflow.com/users/2147",
"pm_score": 8,
"selected": false,
"text": ">>> def foo(x=[]):\n... x.append(1)\n... print x\n... \n>>> foo()\n[1]\n>>> foo()\n[1, 1]\n>>> foo()\n[1, 1, 1]\n >>> def foo(x=None):\n... if x is None:\n... x = []\n... x.append(1)\n... print x\n>>> foo()\n[1]\n>>> foo()\n[1]\n"
},
{
"answer_id": 113319,
"author": "ianb",
"author_id": 20218,
"author_profile": "https://Stackoverflow.com/users/20218",
"pm_score": 5,
"selected": false,
"text": ">>> (a, (b, c), d) = [(1, 2), (3, 4), (5, 6)]\n>>> a\n(1, 2)\n>>> b\n3\n>>> c, d\n(4, (5, 6))\n >>> def addpoints((x1, y1), (x2, y2)):\n... return (x1+x2, y1+y2)\n>>> addpoints((5, 0), (3, 5))\n(8, 5)\n"
},
{
"answer_id": 113472,
"author": "Paddy3118",
"author_id": 10562,
"author_profile": "https://Stackoverflow.com/users/10562",
"pm_score": 3,
"selected": false,
"text": ">>> t1 = (0,1,2,3)\n>>> t2 = (7,6,5,4)\n>>> [t1,t2] == zip(*zip(t1,t2))\nTrue\n"
},
{
"answer_id": 114157,
"author": "Constantin",
"author_id": 20310,
"author_profile": "https://Stackoverflow.com/users/20310",
"pm_score": 7,
"selected": false,
"text": "try:\n put_4000000000_volts_through_it(parrot)\nexcept Voom:\n print \"'E's pining!\"\nelse:\n print \"This parrot is no more!\"\nfinally:\n end_sketch()\n"
},
{
"answer_id": 114420,
"author": "rlerallut",
"author_id": 20055,
"author_profile": "https://Stackoverflow.com/users/20055",
"pm_score": 8,
"selected": false,
"text": "for i in foo:\n if i == 0:\n break\nelse:\n print(\"i was never 0\")\n found = False\nfor i in foo:\n if i == 0:\n found = True\n break\nif not found: \n print(\"i was never 0\")\n"
},
{
"answer_id": 116280,
"author": "lacker",
"author_id": 2652,
"author_profile": "https://Stackoverflow.com/users/2652",
"pm_score": 6,
"selected": false,
"text": ">>> dir(\"foo\")\n['__add__', '__class__', '__contains__', (snipped a bunch), 'title',\n 'translate', 'upper', 'zfill']\n >>> help(\"foo\".upper)\n Help on built-in function upper:\n\nupper(...)\n S.upper() -> string\n\n Return a copy of the string S converted to uppercase.\n"
},
{
"answer_id": 116391,
"author": "amix",
"author_id": 20081,
"author_profile": "https://Stackoverflow.com/users/20081",
"pm_score": 2,
"selected": false,
"text": "class AttrDict(dict):\n\n def __getattr__(self, name):\n if name in self:\n return self[name]\n raise AttributeError('%s not found' % name)\n\n def __setattr__(self, name, value):\n self[name] = value\n\n def __delattr__(self, name):\n del self[name]\n\nperson = AttrDict({'name': 'John Doe', 'age': 66})\nprint person['name']\nprint person.name\n\nperson.name = 'Frodo G'\nprint person.name\n\ndel person.age\n\nprint person\n"
},
{
"answer_id": 116440,
"author": "amix",
"author_id": 20081,
"author_profile": "https://Stackoverflow.com/users/20081",
"pm_score": 5,
"selected": false,
"text": "a = [(2, \"b\"), (1, \"a\"), (2, \"a\"), (3, \"c\")]\nprint sorted(a)\n#[(1, 'a'), (2, 'a'), (2, 'b'), (3, 'c')]\n"
},
{
"answer_id": 116480,
"author": "tghw",
"author_id": 2363,
"author_profile": "https://Stackoverflow.com/users/2363",
"pm_score": 7,
"selected": false,
"text": "x = 3 if (y == 1) else 2\n x = 3 if (y == 1) else 2 if (y == -1) else 1\n (func1 if y == 1 else func2)(arg1, arg2) \n x = (class1 if y == 1 else class2)(arg1, arg2)\n"
},
{
"answer_id": 116724,
"author": "tghw",
"author_id": 2363,
"author_profile": "https://Stackoverflow.com/users/2363",
"pm_score": 3,
"selected": false,
"text": "getattr getattr class FogBugz:\n ...\n\n def __getattr__(self, name):\n # Let's leave the private stuff to Python\n if name.startswith(\"__\"):\n raise AttributeError(\"No such attribute '%s'\" % name)\n\n if not self.__handlerCache.has_key(name):\n def handler(**kwargs):\n return self.__makerequest(name, **kwargs)\n self.__handlerCache[name] = handler\n return self.__handlerCache[name]\n ...\n FogBugz.search(q='bug') search getattr makerequest"
},
{
"answer_id": 117116,
"author": "Dave",
"author_id": 4072,
"author_profile": "https://Stackoverflow.com/users/4072",
"pm_score": 9,
"selected": false,
"text": "\n>>> a = ['a', 'b', 'c', 'd', 'e']\n>>> for index, item in enumerate(a): print index, item\n...\n0 a\n1 b\n2 c\n3 d\n4 e\n>>>\n enumerate"
},
{
"answer_id": 118202,
"author": "Alexander Kojevnikov",
"author_id": 712,
"author_profile": "https://Stackoverflow.com/users/712",
"pm_score": 4,
"selected": false,
"text": ">>> 'ham' if True else 'spam'\n'ham'\n>>> 'ham' if False else 'spam'\n'spam'\n >>> True and 'ham' or 'spam'\n'ham'\n>>> False and 'ham' or 'spam'\n'spam'\n >>> [] if True else 'spam'\n[]\n>>> True and [] or 'spam'\n'spam'\n"
},
{
"answer_id": 118312,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 4,
"selected": false,
"text": ">>> dict([ ('foo','bar'),('a',1),('b',2) ])\n{'a': 1, 'b': 2, 'foo': 'bar'}\n\n>>> names = ['Bob', 'Marie', 'Alice']\n>>> ages = [23, 27, 36]\n>>> dict(zip(names, ages))\n{'Alice': 36, 'Bob': 23, 'Marie': 27}\n"
},
{
"answer_id": 120074,
"author": "Rafał Dowgird",
"author_id": 12166,
"author_profile": "https://Stackoverflow.com/users/12166",
"pm_score": 2,
"selected": false,
"text": ">>> l=[(1,2),(3,4)]\n>>> [a+b for a,b in l ] \n[3,7]\n d = { 'x':'y', 'f':'e'}\nfor name, value in d.items(): # one can also use iteritems()\n print \"name:%s, value:%s\" % (name,value)\n name:x, value:y\nname:f, value:e\n"
},
{
"answer_id": 120247,
"author": "csl",
"author_id": 21028,
"author_profile": "https://Stackoverflow.com/users/21028",
"pm_score": 3,
"selected": false,
"text": "def foo(a, b, c):\n print a, b, c\n\nbar = (3, 14, 15)\nfoo(*bar)\n 3 14 15\n"
},
{
"answer_id": 122577,
"author": "Constantin",
"author_id": 20310,
"author_profile": "https://Stackoverflow.com/users/20310",
"pm_score": 2,
"selected": false,
"text": "empty_tuple = ()\nempty_list = []\nempty_dict = {}\nempty_string = ''\nempty_set = set()\nif empty_tuple or empty_list or empty_dict or empty_string or empty_set:\n print 'Never happens!'\n s = t or \"Default value\" # s will be assigned \"Default value\"\n # if t is false/empty/none\n"
},
{
"answer_id": 125185,
"author": "Dan Udey",
"author_id": 21450,
"author_profile": "https://Stackoverflow.com/users/21450",
"pm_score": 2,
"selected": false,
"text": ">>> x = 5\n>>> y = 10\n>>> \n>>> def sq(x):\n... return x * x\n... \n>>> def plus(x):\n... return x + x\n... \n>>> (sq,plus)[y>x](y)\n20\n (sq,plus)[y>x](y)[4](x)\n"
},
{
"answer_id": 135024,
"author": "Torsten Marek",
"author_id": 9567,
"author_profile": "https://Stackoverflow.com/users/9567",
"pm_score": 4,
"selected": false,
"text": ">>> a = range(10)\n>>> a\n[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n>>> a[:5] = [42]\n>>> a\n[42, 5, 6, 7, 8, 9]\n>>> a[:1] = range(5)\n>>> a\n[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n>>> del a[::2]\n>>> a\n[1, 3, 5, 7, 9]\n>>> a[::2] = a[::-2]\n>>> a\n[9, 3, 5, 7, 1]\n s[start:stop:step]"
},
{
"answer_id": 141900,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": ">>> dict(foo=1, bar=2)\n{'foo': 1, 'bar': 2}\n"
},
{
"answer_id": 143636,
"author": "BatchyX",
"author_id": 22985,
"author_profile": "https://Stackoverflow.com/users/22985",
"pm_score": 9,
"selected": false,
"text": "re.DEBUG re.compile >>> re.compile(\"^\\[font(?:=(?P<size>[-+][0-9]{1,2}))?\\](.*?)[/font]\",\n re.DEBUG)\nat at_beginning\nliteral 91\nliteral 102\nliteral 111\nliteral 110\nliteral 116\nmax_repeat 0 1\n subpattern None\n literal 61\n subpattern 1\n in\n literal 45\n literal 43\n max_repeat 1 2\n in\n range (48, 57)\nliteral 93\nsubpattern 2\n min_repeat 0 65535\n any None\nin\n literal 47\n literal 102\n literal 111\n literal 110\n literal 116\n [] [/font] >>> re.compile(\"\"\"\n ^ # start of a line\n \\[font # the font tag\n (?:=(?P<size> # optional [font=+size]\n [-+][0-9]{1,2} # size specification\n ))?\n \\] # end of tag\n (.*?) # text between the tags\n \\[/font\\] # end of the tag\n \"\"\", re.DEBUG|re.VERBOSE|re.DOTALL)\n"
},
{
"answer_id": 143659,
"author": "spiv",
"author_id": 22701,
"author_profile": "https://Stackoverflow.com/users/22701",
"pm_score": 6,
"selected": false,
"text": "encode decode str unicode u = s.encode('utf8') >>> s = 'a' * 100\n>>> s.encode('zlib')\n'x\\x9cKL\\xa4=\\x00\\x00zG%\\xe5'\n >>> 'Hello world'.encode('base64')\n'SGVsbG8gd29ybGQ=\\n'\n>>> 'SGVsbG8gd29ybGQ=\\n'.decode('base64')\n'Hello world'\n >>> 'Secret message'.encode('rot13')\n'Frperg zrffntr'\n"
},
{
"answer_id": 168270,
"author": "mjard",
"author_id": 10357,
"author_profile": "https://Stackoverflow.com/users/10357",
"pm_score": 7,
"selected": false,
"text": "try:\n import readline\nexcept ImportError:\n print \"Unable to load readline module.\"\nelse:\n import rlcompleter\n readline.parse_and_bind(\"tab: complete\")\n\n\n>>> class myclass:\n... def function(self):\n... print \"my function\"\n... \n>>> class_instance = myclass()\n>>> class_instance.<TAB>\nclass_instance.__class__ class_instance.__module__\nclass_instance.__doc__ class_instance.function\n>>> class_instance.f<TAB>unction()\n"
},
{
"answer_id": 171767,
"author": "Constantin",
"author_id": 20310,
"author_profile": "https://Stackoverflow.com/users/20310",
"pm_score": 5,
"selected": false,
"text": "from goto import goto, label\nfor i in range(1, 10):\n for j in range(1, 20):\n for k in range(1, 30):\n print i, j, k\n if k == 3:\n goto .end # breaking out from a deeply nested loop\nlabel .end\nprint \"Finished\"\n"
},
{
"answer_id": 196225,
"author": "pixelbeat",
"author_id": 4421,
"author_profile": "https://Stackoverflow.com/users/4421",
"pm_score": 2,
"selected": false,
"text": "{\n \"name1\": \"value1\",\n \"name2\": \"value2\"\n}\n config = eval(open(\"filename\").read())\n"
},
{
"answer_id": 196275,
"author": "ironfroggy",
"author_id": 19687,
"author_profile": "https://Stackoverflow.com/users/19687",
"pm_score": 3,
"selected": false,
"text": "def create_printers(n):\n for i in xrange(n):\n def printer(i=i): # Doesn't work without the i=i\n print i\n yield printer\n"
},
{
"answer_id": 205889,
"author": "Martin Beckett",
"author_id": 10897,
"author_profile": "https://Stackoverflow.com/users/10897",
"pm_score": 4,
"selected": false,
"text": "''.join(list_of_strings)\n"
},
{
"answer_id": 210921,
"author": "zaphod",
"author_id": 13871,
"author_profile": "https://Stackoverflow.com/users/13871",
"pm_score": 2,
"selected": false,
"text": "class MyClass(object):\n def __init__(self):\n\n privateData = {}\n\n self.publicData = 123\n\n def privateMethod(k):\n print privateData[k] + self.publicData\n\n def privilegedMethod():\n privateData['foo'] = \"hello \"\n privateMethod('foo')\n\n self.privilegedMethod = privilegedMethod\n\n def publicMethod(self):\n print self.publicData\n >>> obj = MyClass()\n>>> obj.publicMethod()\n123\n>>> obj.publicData = 'World'\n>>> obj.publicMethod()\nWorld\n>>> obj.privilegedMethod()\nhello World\n>>> obj.privateMethod()\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nAttributeError: 'MyClass' object has no attribute 'privateMethod'\n>>> obj.privateData\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nAttributeError: 'MyClass' object has no attribute 'privateData'\n privateMethod privateData dir() __init__ privilegedMethod nonlocal"
},
{
"answer_id": 215326,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "funcs = [] \nfor k in range(10):\n funcs.append( lambda: k)\n\n>>> funcs[0]()\n9\n>>> funcs[7]()\n9\n funcs = [] \nfor k in range(10):\n funcs.append( lambda k = k: k)\n\n>>> funcs[0]()\n0\n>>> funcs[7]()\n7\n"
},
{
"answer_id": 218177,
"author": "Tupteq",
"author_id": 29564,
"author_profile": "https://Stackoverflow.com/users/29564",
"pm_score": 2,
"selected": false,
"text": ">>> class C(object):\n... def fun(self):\n... print \"C.a\", self\n...\n>>> inst = C()\n>>> inst.fun() # C.a method is executed\nC.a <__main__.C object at 0x00AE74D0>\n>>> instancemethod = type(C.fun)\n>>>\n>>> def fun2(self):\n... print \"fun2\", self\n...\n>>> inst.fun = instancemethod(fun2, inst, C) # Now we are replace C.a by fun2\n>>> inst.fun() # ... and fun2 is executed\nfun2 <__main__.C object at 0x00AE74D0>\n C.a fun2() inst self new >>> def fun3(self):\n... print \"fun3\", self\n...\n>>> import new\n>>> inst.fun = new.instancemethod(fun3, inst, C)\n>>> inst.fun()\nfun3 <__main__.C object at 0x00AE74D0>\n"
},
{
"answer_id": 221874,
"author": "Jake",
"author_id": 10675,
"author_profile": "https://Stackoverflow.com/users/10675",
"pm_score": 5,
"selected": false,
"text": "def unique(my_list):\n return [x for x in my_list if x not in locals()['_[1]']]\n"
},
{
"answer_id": 224747,
"author": "monkut",
"author_id": 24718,
"author_profile": "https://Stackoverflow.com/users/24718",
"pm_score": 6,
"selected": false,
"text": ">>> x = [1,2,1,1,2,3,4] \n>>> \n>>> set(x) \nset([1, 2, 3, 4]) \n>>>\n>>> for i in set(x):\n... print i\n...\n1\n2\n3\n4\n >>> len(set([1,2,1,1,2,3,4]))\n4\n >>> set([1,2,3,4]).issubset([0,1,2,3,4,5])\nTrue\n myset = {1,2,3,4}\n {x for x in stuff}\n"
},
{
"answer_id": 261833,
"author": "utku_karatas",
"author_id": 14716,
"author_profile": "https://Stackoverflow.com/users/14716",
"pm_score": 5,
"selected": false,
"text": ">>> import pprint \n>>> stuff = sys.path[:]\n>>> stuff.insert(0, stuff)\n>>> pprint.pprint(stuff)\n[<Recursion on list with id=869440>,\n '',\n '/usr/local/lib/python1.5',\n '/usr/local/lib/python1.5/test',\n '/usr/local/lib/python1.5/sunos5',\n '/usr/local/lib/python1.5/sharedmodules',\n '/usr/local/lib/python1.5/tkinter']\n"
},
{
"answer_id": 299781,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": ">>> from functools import partial\n>>> bound_func = partial(range, 0, 10)\n>>> bound_func()\n[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n>>> bound_func(2)\n[0, 2, 4, 6, 8]\n"
},
{
"answer_id": 322868,
"author": "M. Utku ALTINKAYA",
"author_id": 40948,
"author_profile": "https://Stackoverflow.com/users/40948",
"pm_score": -1,
"selected": false,
"text": "is_ok() and \"Yes\" or \"No\"\n"
},
{
"answer_id": 326615,
"author": "Steen",
"author_id": 1448983,
"author_profile": "https://Stackoverflow.com/users/1448983",
"pm_score": 3,
"selected": false,
"text": "dict.get() In [1]: test = { 1 : 'a' }\n\nIn [2]: test[2]\n---------------------------------------------------------------------------\n<type 'exceptions.KeyError'> Traceback (most recent call last)\n\n<ipython console> in <module>()\n\n<type 'exceptions.KeyError'>: 2\n\nIn [3]: test.get( 2 )\n\nIn [4]: test.get( 1 )\nOut[4]: 'a'\n\nIn [5]: test.get( 2 ) == None\nOut[5]: True\n In [6]: test.get( 2, 'Some' ) == 'Some'\nOut[6]: True\n setdefault( >>> a = {}\n>>> b = a.setdefault('foo', 'bar')\n>>> a\n{'foo': 'bar'}\n>>> b\n'bar\n"
},
{
"answer_id": 326893,
"author": "FA.",
"author_id": 33281,
"author_profile": "https://Stackoverflow.com/users/33281",
"pm_score": 6,
"selected": false,
"text": "a = [(1,2), (3,4), (5,6)]\nzip(*a)\n# [(1, 3, 5), (2, 4, 6)]\n"
},
{
"answer_id": 373949,
"author": "Abgan",
"author_id": 46308,
"author_profile": "https://Stackoverflow.com/users/46308",
"pm_score": 6,
"selected": false,
"text": "round() >>> str(round(1234.5678, -2))\n'1200.0'\n>>> str(round(1234.5678, 2))\n'1234.57'\n round() str() 1234.5700000000001 decimal"
},
{
"answer_id": 393927,
"author": "James Brady",
"author_id": 29903,
"author_profile": "https://Stackoverflow.com/users/29903",
"pm_score": 5,
"selected": false,
"text": "$ python\nPython 2.5.1 (r251:54863, Jan 17 2008, 19:35:17) \n[GCC 4.0.1 (Apple Inc. build 5465)] on darwin\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> shared_var = \"Set in main console\"\n>>> import code\n>>> ic = code.InteractiveConsole({ 'shared_var': shared_var })\n>>> try:\n... ic.interact(\"My custom console banner!\")\n... except SystemExit, e:\n... print \"Got SystemExit!\"\n... \nMy custom console banner!\n>>> shared_var\n'Set in main console'\n>>> shared_var = \"Set in sub-console\"\n>>> import sys\n>>> sys.exit()\nGot SystemExit!\n>>> shared_var\n'Set in main console'\n"
},
{
"answer_id": 405085,
"author": "Kiv",
"author_id": 49559,
"author_profile": "https://Stackoverflow.com/users/49559",
"pm_score": 7,
"selected": false,
"text": "set >>> a = set([1,2,3,4])\n>>> b = set([3,4,5,6])\n>>> a | b # Union\n{1, 2, 3, 4, 5, 6}\n>>> a & b # Intersection\n{3, 4}\n>>> a < b # Subset\nFalse\n>>> a - b # Difference\n{1, 2}\n>>> a ^ b # Symmetric Difference\n{1, 2, 5, 6}\n"
},
{
"answer_id": 405094,
"author": "Benjamin Peterson",
"author_id": 33795,
"author_profile": "https://Stackoverflow.com/users/33795",
"pm_score": 3,
"selected": false,
"text": ">>> class A(object):\n... def a_method(self):\n... print(\"A\")\n... \n>>> class B(object):\n... def b_method(self):\n... print(\"B\")\n... \n>>> class MROMagicMeta(type):\n... def mro(cls):\n... return (cls, B, object)\n... \n>>> class C(A, metaclass=MROMagicMeta):\n... def c_method(self):\n... print(\"C\")\n... \n>>> cls = C()\n>>> cls.c_method()\nC\n>>> cls.a_method()\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nAttributeError: 'C' object has no attribute 'a_method'\n>>> cls.b_method()\nB\n>>> type(cls).__bases__\n(<class '__main__.A'>,)\n>>> type(cls).__mro__\n(<class '__main__.C'>, <class '__main__.B'>, <class 'object'>)\n"
},
{
"answer_id": 407695,
"author": "Christian Oudard",
"author_id": 3757,
"author_profile": "https://Stackoverflow.com/users/3757",
"pm_score": 3,
"selected": false,
"text": "reversed() for i in reversed([1, 2, 3]):\n print(i)\n 3\n2\n1\n reversed()"
},
{
"answer_id": 407754,
"author": "sprintf",
"author_id": 50712,
"author_profile": "https://Stackoverflow.com/users/50712",
"pm_score": 3,
"selected": false,
"text": ">>> import this\nThe Zen of Python, by Tim Peters\n\nBeautiful is better than ugly.\nExplicit is better than implicit.\nSimple is better than complex.\nComplex is better than complicated.\nFlat is better than nested.\nSparse is better than dense.\nReadability counts.\nSpecial cases aren't special enough to break the rules.\nAlthough practicality beats purity.\nErrors should never pass silently.\nUnless explicitly silenced.\nIn the face of ambiguity, refuse the temptation to guess.\nThere should be one-- and preferably only one --obvious way to do it.\nAlthough that way may not be obvious at first unless you're Dutch.\nNow is better than never.\nAlthough never is often better than *right* now.\nIf the implementation is hard to explain, it's a bad idea.\nIf the implementation is easy to explain, it may be a good idea.\nNamespaces are one honking great idea -- let's do more of those!\n"
},
{
"answer_id": 585473,
"author": "Mykola Kharechko",
"author_id": 69885,
"author_profile": "https://Stackoverflow.com/users/69885",
"pm_score": 3,
"selected": false,
"text": "\n>>> a1 = -5; b1 = 256\n>>> a2 = -5; b2 = 256\n>>> id(a1) == id(a2), id(b1) == id(b2)\n(True, True)\n>>>\n>>> c1 = -6; d1 = 257\n>>> c2 = -6; d2 = 257\n>>> id(c1) == id(c2), id(d1) == id(d2)\n(False, False)\n>>>\n \n>>> a = [1,2,3]; a_id = id(a)\n>>> b = [1,2,3]; b_id = id(b)\n>>> del a; del b\n>>> c = [1,2,3]; id(c) == b_id\nTrue\n>>> d = [1,2,3]; id(d) == a_id\nTrue\n>>>\n"
},
{
"answer_id": 603391,
"author": "lprsd",
"author_id": 55562,
"author_profile": "https://Stackoverflow.com/users/55562",
"pm_score": 3,
"selected": false,
"text": "In [15]: t1 = (1, 2, 3)\n\nIn [16]: t2 = (4, 5, 6)\n\nIn [17]: dict (zip(t1,t2))\nOut[17]: {1: 4, 2: 5, 3: 6}\n"
},
{
"answer_id": 603408,
"author": "lprsd",
"author_id": 55562,
"author_profile": "https://Stackoverflow.com/users/55562",
"pm_score": 2,
"selected": false,
"text": "In [18]: a = True\n\nIn [19]: a and 3 or 4\nOut[19]: 3\n\nIn [20]: a = False\n\nIn [21]: a and 3 or 4\nOut[21]: 4\n In [22]: a = 5 if True else '6'\n\n In [23]: a\n Out[23]: 5\n >>> def foo(): \n... print \"foo\"\n... return 0\n...\n>>> def bar(): \n... print \"bar\"\n... return 1\n...\n>>> 1 and foo() or bar()\nfoo\nbar\n1\n >>> (1 and [foo()] or [bar()])[0]\nfoo\n0\n >>> foo() if True or bar()\nfoo\n0\n"
},
{
"answer_id": 652687,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 2,
"selected": false,
"text": "spam ctypes >>> import __hello__\nHello world...\n>>> type(__hello__)\n<type 'module'>\n>>> from __phello__ import spam\nHello world...\nHello world...\n>>> type(spam)\n<type 'module'>\n>>> help(spam)\nHelp on module __phello__.spam in __phello__:\n\nNAME\n __phello__.spam\n\nFILE\n c:\\python26\\<frozen>\n"
},
{
"answer_id": 804238,
"author": "Scott Kirkwood",
"author_id": 95818,
"author_profile": "https://Stackoverflow.com/users/95818",
"pm_score": 6,
"selected": false,
"text": "import re\n\ndef Main(haystack):\n # List of from replacements, can be a regex\n finds = ('Hello', 'there', 'Bob')\n replaces = ('Hi,', 'Fred,', 'how are you?')\n\n def ReplaceFunction(matchobj):\n for found, rep in zip(matchobj.groups(), replaces):\n if found != None:\n return rep\n\n # log error\n return matchobj.group(0)\n\n named_groups = [ '(%s)' % find for find in finds ]\n ret = re.sub('|'.join(named_groups), ReplaceFunction, haystack)\n print ret\n\nif __name__ == '__main__':\n str = 'Hello there Bob'\n Main(str)\n # Prints 'Hi, Fred, how are you?'\n"
},
{
"answer_id": 938602,
"author": "Tom",
"author_id": 115846,
"author_profile": "https://Stackoverflow.com/users/115846",
"pm_score": 5,
"selected": false,
"text": "str = \"I'm a string 'but still I can use quotes' inside myself!\"\nstr = \"\"\" For some messy multi line strings.\nSuch as\n<html>\n<head> ... </head>\"\"\"\n str2 = r\"\\n\" \nprint str2\n>> \\n\n"
},
{
"answer_id": 967971,
"author": "Ken Arnold",
"author_id": 69707,
"author_profile": "https://Stackoverflow.com/users/69707",
"pm_score": 4,
"selected": false,
"text": "%debug pylab"
},
{
"answer_id": 967998,
"author": "Ken Arnold",
"author_id": 69707,
"author_profile": "https://Stackoverflow.com/users/69707",
"pm_score": 3,
"selected": false,
"text": ">>> from a_package import a_module\n>>> cls = a_module.SomeClass\n>>> obj = cls()\n>>> obj.method()\n(old method output)\n >>> reload(a_module)\n>>> a_module.SomeClass is cls\nFalse # Because it just got freshly created by reload.\n>>> obj.method()\n(old method output)\n >>> obj.__class__ is cls\nTrue # it's the old class object\n>>> obj.__class__ = a_module.SomeClass # pick up the new class\n>>> obj.method()\n(new method output)\n pickle"
},
{
"answer_id": 1013448,
"author": "Markus",
"author_id": 125185,
"author_profile": "https://Stackoverflow.com/users/125185",
"pm_score": 4,
"selected": false,
"text": "def doNothing():\n pass\n\ndoNothing.monkeys = 4\nprint doNothing.monkeys\n4\n"
},
{
"answer_id": 1013470,
"author": "Markus",
"author_id": 125185,
"author_profile": "https://Stackoverflow.com/users/125185",
"pm_score": 3,
"selected": false,
"text": "class countCalls(object):\n \"\"\" decorator replaces a function with a \"countCalls\" instance\n which behaves like the original function, but keeps track of calls\n\n >>> @countCalls\n ... def doNothing():\n ... pass\n >>> doNothing()\n >>> doNothing()\n >>> print doNothing.timesCalled\n 2\n \"\"\"\n def __init__ (self, functionToTrack):\n self.functionToTrack = functionToTrack\n self.timesCalled = 0\n def __call__ (self, *args, **kwargs):\n self.timesCalled += 1\n return self.functionToTrack(*args, **kwargs)\n"
},
{
"answer_id": 1013517,
"author": "Markus",
"author_id": 125185,
"author_profile": "https://Stackoverflow.com/users/125185",
"pm_score": 2,
"selected": false,
"text": "def threadify(function):\n \"\"\"\n exceptionally simple threading decorator. Just:\n >>> @threadify\n ... def longOperation(result):\n ... time.sleep(3)\n ... return result\n >>> A= longOperation(\"A has finished\")\n >>> B= longOperation(\"B has finished\")\n\n A doesn't have a result yet:\n >>> print A.result\n None\n\n until we wait for it:\n >>> print A.awaitResult()\n A has finished\n\n we could also wait manually - half a second more should be enough for B:\n >>> time.sleep(0.5); print B.result\n B has finished\n \"\"\"\n class thr (threading.Thread,object):\n def __init__(self, *args, **kwargs):\n threading.Thread.__init__ ( self ) \n self.args, self.kwargs = args, kwargs\n self.result = None\n self.start()\n def awaitResult(self):\n self.join()\n return self.result \n def run(self):\n self.result=function(*self.args, **self.kwargs)\n return thr\n"
},
{
"answer_id": 1024693,
"author": "André",
"author_id": 9683,
"author_profile": "https://Stackoverflow.com/users/9683",
"pm_score": 8,
"selected": false,
"text": "#!/usr/bin/env python\n# -*- coding: rot13 -*-\n\ncevag \"Uryyb fgnpxbiresybj!\".rapbqr(\"rot13\")\n"
},
{
"answer_id": 1088213,
"author": "Steven Sproat",
"author_id": 108560,
"author_profile": "https://Stackoverflow.com/users/108560",
"pm_score": 2,
"selected": false,
"text": "class Bleh:\n pass\n class Blah:\n pass\n Bleh = Blah\n"
},
{
"answer_id": 1338523,
"author": "Greg",
"author_id": 105101,
"author_profile": "https://Stackoverflow.com/users/105101",
"pm_score": 2,
"selected": false,
"text": ">>> def addInts(x,y): \n... return x + y\n>>> addInts.params = ['integer','integer']\n>>> addInts.returnType = 'integer'\n"
},
{
"answer_id": 1399564,
"author": "Busted Keaton",
"author_id": 164711,
"author_profile": "https://Stackoverflow.com/users/164711",
"pm_score": 2,
"selected": false,
"text": ">>> class C():\n def getMontys(self):\n self.montys = ['Cleese','Palin','Idle','Gilliam','Jones','Chapman']\n return self.montys\n\n\n>>> c = C()\n>>> getattr(c,'getMontys')()\n['Cleese', 'Palin', 'Idle', 'Gilliam', 'Jones', 'Chapman']\n>>> \n"
},
{
"answer_id": 1592819,
"author": "six8",
"author_id": 185316,
"author_profile": "https://Stackoverflow.com/users/185316",
"pm_score": 2,
"selected": false,
"text": ">>> 'key' in { 'key' : 1 }\nTrue\n\n>>> d = dict(key=1, key2=2)\n>>> if 'key' in d:\n... print 'Yup'\n... \nYup\n"
},
{
"answer_id": 1602751,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "def makeMeANewClass(parent, value):\n class IAmAnObjectToo(parent):\n def theValue(self):\n return value\n return IAmAnObjectToo\n\nKlass = makeMeANewClass(str, \"fred\")\no = Klass()\nprint isinstance(o, str) # => True\nprint o.theValue() # => fred\n"
},
{
"answer_id": 1631763,
"author": "Denis Otkidach",
"author_id": 168352,
"author_profile": "https://Stackoverflow.com/users/168352",
"pm_score": 4,
"selected": false,
"text": "super() class A(object):\n @property\n def prop(self):\n return {'a': 1}\n\nclass B(A):\n @property\n def prop(self):\n return dict(super(B, self).prop, b=2)\n test.py python -i test.py -i >>> B().prop\n{'a': 1, 'b': 2}\n"
},
{
"answer_id": 1667256,
"author": "Amol",
"author_id": 91966,
"author_profile": "https://Stackoverflow.com/users/91966",
"pm_score": 3,
"selected": false,
"text": "x = ... if ... else ... x = ... and ... or ... x = 3 if (y == 1) else 2\n x = y == 1 and 3 or 2\n x = ... and ... or ... x = 0 if True else 1 # sets x equal to 0\n x = True and 0 or 1 # sets x equal to 1\n"
},
{
"answer_id": 1687543,
"author": "u0b34a0f6ae",
"author_id": 137317,
"author_profile": "https://Stackoverflow.com/users/137317",
"pm_score": 4,
"selected": false,
"text": ">>> s = u'10585'\n>>> s\nu'\\uff11\\uff10\\uff15\\uff18\\uff15'\n>>> print s\n10585\n>>> int(s)\n10585\n>>> float(s)\n10585.0\n"
},
{
"answer_id": 1823597,
"author": "Noctis Skytower",
"author_id": 216356,
"author_profile": "https://Stackoverflow.com/users/216356",
"pm_score": 5,
"selected": false,
"text": ">>> a, *b = range(5)\n>>> a, b\n(0, [1, 2, 3, 4])\n>>> *a, b = range(5)\n>>> a, b\n([0, 1, 2, 3], 4)\n>>> a, *b, c = range(5)\n>>> a, b, c\n(0, [1, 2, 3], 4)\n"
},
{
"answer_id": 1853593,
"author": "jpsimons",
"author_id": 205934,
"author_profile": "https://Stackoverflow.com/users/205934",
"pm_score": 6,
"selected": false,
"text": "class='<% isSelected ? \"selected\" : \"\" %>'\n class='<% \"selected\" * isSelected %>'\n"
},
{
"answer_id": 1853633,
"author": "jpsimons",
"author_id": 205934,
"author_profile": "https://Stackoverflow.com/users/205934",
"pm_score": 4,
"selected": false,
"text": "index = (index + increment) % WINDOW_SIZE\n"
},
{
"answer_id": 1958325,
"author": "Martin Thurau",
"author_id": 20247,
"author_profile": "https://Stackoverflow.com/users/20247",
"pm_score": 0,
"selected": false,
"text": "kwargs = {}\nkwargs[str(\"%s__icontains\" % field)] = some_value\nsome_function(**kwargs)\n result = model_class.objects.filter(**kwargs)\n"
},
{
"answer_id": 1983078,
"author": "Xavier Martinez-Hidalgo",
"author_id": 25996,
"author_profile": "https://Stackoverflow.com/users/25996",
"pm_score": 4,
"selected": false,
"text": ">>> int('10', 0)\n10\n>>> int('0x10', 0)\n16\n>>> int('010', 0) # does not work on Python 3.x\n8\n>>> int('0o10', 0) # Python >=2.6 and Python 3.x\n8\n>>> int('0b10', 0) # Python >=2.6 and Python 3.x\n2\n"
},
{
"answer_id": 1983095,
"author": "Xavier Martinez-Hidalgo",
"author_id": 25996,
"author_profile": "https://Stackoverflow.com/users/25996",
"pm_score": 4,
"selected": false,
"text": "itertools.chain() >>> from itertools import *\n>>> l = [[1, 2], [3, 4]]\n>>> list(chain(*l))\n[1, 2, 3, 4]\n"
},
{
"answer_id": 2060871,
"author": "Chinmay Kanchi",
"author_id": 148765,
"author_profile": "https://Stackoverflow.com/users/148765",
"pm_score": 3,
"selected": false,
"text": "__dict__ class Foo(object):\n def __init__(self, arg1, arg2, **kwargs):\n #do stuff with arg1 and arg2\n self.__dict__.update(kwargs)\n\nf = Foo('arg1', 'arg2', bar=20, baz=10)\n#now f is a Foo object with two extra attributes\n struct class struct(object):\n def __init__(**kwargs):\n self.__dict__.update(kwargs)\n\ns = struct(foo=10, bar=11, baz=\"i'm a string!')\n"
},
{
"answer_id": 2060945,
"author": "Chinmay Kanchi",
"author_id": 148765,
"author_profile": "https://Stackoverflow.com/users/148765",
"pm_score": 4,
"selected": false,
"text": ">>> FOO, BAR, BAZ = range(3)\n>>> FOO\n0\n class Colors(object):\n RED, GREEN, BLUE, YELLOW = (255,0,0), (0,255,0), (0,0,255), (0,255,255)\n\n#now Colors.RED is a 3-tuple that returns the 24-bit 8bpp RGB \n#value for saturated red\n"
},
{
"answer_id": 2259080,
"author": "Thomas Wouters",
"author_id": 17624,
"author_profile": "https://Stackoverflow.com/users/17624",
"pm_score": 4,
"selected": false,
"text": ">>> import sys\n>>> import ham\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nImportError: No module named ham\n\n# Make the 'ham' module available -- as a non-module object even!\n>>> sys.modules['ham'] = 'ham, eggs, saussages and spam.'\n>>> import ham\n>>> ham\n'ham, eggs, saussages and spam.'\n\n# Now remove it again.\n>>> sys.modules['ham'] = None\n>>> import ham\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nImportError: No module named ham\n >>> import os\n# Stop future imports of 'os'.\n>>> sys.modules['os'] = None\n>>> import os\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nImportError: No module named os\n# Our old imported module is still available.\n>>> os\n<module 'os' from '/usr/lib/python2.5/os.pyc'>\n import None sys.modules import sys.modules import"
},
{
"answer_id": 2482459,
"author": "evilpie",
"author_id": 297734,
"author_profile": "https://Stackoverflow.com/users/297734",
"pm_score": 4,
"selected": false,
"text": "if isinstance (number, float) or isinstance (number, int): \n print \"yaay\"\n if isinstance (number, (float, int)): \n print \"yaay\"\n"
},
{
"answer_id": 2582013,
"author": "haridsv",
"author_id": 95750,
"author_profile": "https://Stackoverflow.com/users/95750",
"pm_score": 2,
"selected": false,
"text": ">>> foo = bar = baz = 1\n>>> foo, bar, baz\n(1, 1, 1)\n"
},
{
"answer_id": 2582046,
"author": "haridsv",
"author_id": 95750,
"author_profile": "https://Stackoverflow.com/users/95750",
"pm_score": 3,
"selected": false,
"text": "def dumpstacks(signal, frame):\n id2name = dict([(th.ident, th.name) for th in threading.enumerate()])\n code = []\n for threadId, stack in sys._current_frames().items():\n code.append(\"\\n# Thread: %s(%d)\" % (id2name[threadId], threadId))\n for filename, lineno, name, line in traceback.extract_stack(stack):\n code.append('File: \"%s\", line %d, in %s' % (filename, lineno, name))\n if line:\n code.append(\" %s\" % (line.strip()))\n print \"\\n\".join(code)\n\nimport signal\nsignal.signal(signal.SIGQUIT, dumpstacks)\n"
},
{
"answer_id": 2830047,
"author": "L̲̳o̲̳̳n̲̳̳g̲̳̳p̲̳o̲̳̳k̲̳̳e̲̳̳",
"author_id": 80243,
"author_profile": "https://Stackoverflow.com/users/80243",
"pm_score": -1,
"selected": false,
"text": "def g():\n print 'hi!'\n\ndef f(): (\n g()\n)\n\n>>> f()\nhi!\n"
},
{
"answer_id": 2898562,
"author": "L̲̳o̲̳̳n̲̳̳g̲̳̳p̲̳o̲̳̳k̲̳̳e̲̳̳",
"author_id": 80243,
"author_profile": "https://Stackoverflow.com/users/80243",
"pm_score": 3,
"selected": false,
"text": ">>> class A(object): pass\n>>> a = A()\n>>> setattr(a, \"can't touch this\", 123)\n>>> dir(a)\n['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', \"can't touch this\"]\n>>> a.can't touch this # duh\n File \"<stdin>\", line 1\n a.can't touch this\n ^\nSyntaxError: EOL while scanning string literal\n>>> getattr(a, \"can't touch this\")\n123\n>>> setattr(a, \"__class__.__name__\", \":O\")\n>>> a.__class__.__name__\n'A'\n>>> getattr(a, \"__class__.__name__\")\n':O'\n"
},
{
"answer_id": 2916508,
"author": "Evgeny",
"author_id": 331701,
"author_profile": "https://Stackoverflow.com/users/331701",
"pm_score": 4,
"selected": false,
"text": ">>> a = {}\n>>> b = {}\n>>> a['b'] = b\n>>> b['a'] = a\n>>> print a\n{'b': {'a': {...}}}\n"
},
{
"answer_id": 3143595,
"author": "David Z",
"author_id": 56541,
"author_profile": "https://Stackoverflow.com/users/56541",
"pm_score": 4,
"selected": false,
"text": ">>> i = (1,2,3,4,5,6,7,8,9,10) # or any iterable object\n>>> iterators = [iter(i)] * 2\n>>> iterators[0].next()\n1\n>>> iterators[1].next()\n2\n>>> iterators[0].next()\n3\n itertools def grouper(n, iterable, fillvalue=None):\n \"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx\"\n args = [iter(iterable)] * n\n return izip_longest(fillvalue=fillvalue, *args)\n"
},
{
"answer_id": 3244390,
"author": "Marcin Swiderski",
"author_id": 391336,
"author_profile": "https://Stackoverflow.com/users/391336",
"pm_score": 4,
"selected": false,
"text": ">>> s = \"Hello World\"\n>>> s[::-1]\n'dlroW olleH'\n>>> a = (1,2,3,4,5,6)\n>>> a[::-1]\n(6, 5, 4, 3, 2, 1)\n>>> a = [5,4,3,2,1]\n>>> a[::-1]\n[1, 2, 3, 4, 5]\n"
},
{
"answer_id": 3254039,
"author": "Giampaolo Rodolà",
"author_id": 376587,
"author_profile": "https://Stackoverflow.com/users/376587",
"pm_score": 5,
"selected": false,
"text": ">>> range(10)\n[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n>>> _\n[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n>>>\n"
},
{
"answer_id": 3265438,
"author": "Daniel Hepper",
"author_id": 211960,
"author_profile": "https://Stackoverflow.com/users/211960",
"pm_score": 3,
"selected": false,
"text": ">>> x = [1,2,3]\n>>> y = x[:]\n>>> y.pop()\n3\n>>> y\n[1, 2]\n>>> x\n[1, 2, 3]\n >>> x = [1,2,3]\n>>> y = x\n>>> y[:] = [4,5,6]\n>>> x\n[4, 5, 6]\n"
},
{
"answer_id": 3267903,
"author": "Wayne Werner",
"author_id": 344286,
"author_profile": "https://Stackoverflow.com/users/344286",
"pm_score": 2,
"selected": false,
"text": "# in 2.6 <= python < 3.0, 3.0 + the print function is native\nfrom __future__ import print_function \n\nmylist = ['foo', 'bar', 'some other value', 1,2,3,4] \nprint(*mylist)\n"
},
{
"answer_id": 3277236,
"author": "Piotr Duda",
"author_id": 352850,
"author_profile": "https://Stackoverflow.com/users/352850",
"pm_score": 4,
"selected": false,
"text": "{ a:a for a in range(10) }\n{ a for a in range(10) }\n"
},
{
"answer_id": 3280831,
"author": "Martin",
"author_id": 338547,
"author_profile": "https://Stackoverflow.com/users/338547",
"pm_score": 3,
"selected": false,
"text": ">>> a_tuple_for_instance = (0,1,2,3,)\n>>> another_tuple = (0,1,2,3)\n>>> a_tuple_for_instance == another_tuple\nTrue\n >>> a_tuple_with_one_element = (8,)\n"
},
{
"answer_id": 3282681,
"author": "Don O'Donnell",
"author_id": 140894,
"author_profile": "https://Stackoverflow.com/users/140894",
"pm_score": 2,
"selected": false,
"text": "** Using sets to reference contents in sets of frozensets**\n >>> fabc = frozenset('abc')\n>>> fxyz = frozenset('xyz')\n>>> mset = set((fabc, fxyz))\n>>> mset\n{frozenset({'a', 'c', 'b'}), frozenset({'y', 'x', 'z'})}\n >>> abc = set('abc')\n>>> abc in mset\nTrue\n>>> mset.remove(abc)\n>>> mset\n{frozenset({'y', 'x', 'z'})}\n elem __contains__() remove() discard() elem elem >>> mdict = {fabc:1, fxyz:2}\n>>> fabc in mdict\nTrue\n>>> abc in mdict\nTraceback (most recent call last):\nFile \"<interactive input>\", line 1, in <module>\nTypeError: unhashable type: 'set'\n"
},
{
"answer_id": 3310122,
"author": "Remco Wendt",
"author_id": 216255,
"author_profile": "https://Stackoverflow.com/users/216255",
"pm_score": 5,
"selected": false,
"text": "textwrap.dedent import unittest, textwrap\n\nclass XMLTests(unittest.TestCase):\n def test_returned_xml_value(self):\n returned_xml = call_to_function_that_returns_xml()\n expected_value = textwrap.dedent(\"\"\"\\\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n <root_node>\n <my_node>my_content</my_node>\n </root_node>\n \"\"\")\n\n self.assertEqual(expected_value, returned_xml)\n"
},
{
"answer_id": 3312925,
"author": "hughdbrown",
"author_id": 10293,
"author_profile": "https://Stackoverflow.com/users/10293",
"pm_score": 3,
"selected": false,
"text": "def eras(n):\n last = n + 1\n sieve = [0,0] + list(range(2, last))\n sqn = int(round(n ** 0.5))\n it = (i for i in xrange(2, sqn + 1) if sieve[i])\n for i in it:\n sieve[i*i:last:i] = [0] * (n//i - i + 1)\n return filter(None, sieve)\n"
},
{
"answer_id": 3326757,
"author": "David Z",
"author_id": 56541,
"author_profile": "https://Stackoverflow.com/users/56541",
"pm_score": 5,
"selected": false,
"text": ">>> f = lambda: 'foo'\n>>> f()\n'foo'\n *args **kwargs >>> g = lambda *args, **kwargs: args[0], kwargs['thing']\n>>> g(1, 2, 3, thing='stuff')\n(1, 'stuff')\n"
},
{
"answer_id": 3342952,
"author": "sa125",
"author_id": 187907,
"author_profile": "https://Stackoverflow.com/users/187907",
"pm_score": 6,
"selected": false,
"text": ">>> sql = \"select * from some_table \\\nwhere id > 10\"\n>>> print sql\nselect * from some_table where id > 10\n >>> sql = \"\"\"select * from some_table \nwhere id > 10\"\"\"\n>>> print sql\nselect * from some_table where id > 10\n >>> sql = (\"select * from some_table \" # <-- no comma, whitespace at end\n \"where id > 10 \"\n \"order by name\") \n>>> print sql\nselect * from some_table where id > 10 order by name\n \"my name is %s\" % name"
},
{
"answer_id": 3371415,
"author": "Tamás",
"author_id": 156771,
"author_profile": "https://Stackoverflow.com/users/156771",
"pm_score": 6,
"selected": false,
"text": "pow() (x ** y) % z >>> x, y, z = 1234567890, 2345678901, 17\n>>> pow(x, y, z) # almost instantaneous\n6\n (x ** y) % z"
},
{
"answer_id": 3535064,
"author": "Denilson Sá Maia",
"author_id": 124946,
"author_profile": "https://Stackoverflow.com/users/124946",
"pm_score": 3,
"selected": false,
"text": ">>> print repr(r\"aaa\\\"bbb\")\n'aaa\\\\\"bbb'\n >>> print repr(r\"C:\\\")\nSyntaxError: EOL while scanning string literal\n>>> print repr(r\"C:\\\"\")\n'C:\\\\\"'\n"
},
{
"answer_id": 3693838,
"author": "Ruslan Spivak",
"author_id": 301440,
"author_profile": "https://Stackoverflow.com/users/301440",
"pm_score": 5,
"selected": false,
"text": ">>> 'xyz' * 3\n'xyzxyzxyz'\n\n>>> [1, 2] * 3\n[1, 2, 1, 2, 1, 2]\n\n>>> (1, 2) * 3\n(1, 2, 1, 2, 1, 2)\n >>> 3 * 'xyz'\n'xyzxyzxyz'\n >>> s = 'xyz'\n>>> num = 3\n >>> s * num\n'xyzxyzxyz'\n\n>>> s.__mul__(num)\n'xyzxyzxyz'\n >>> num * s\n'xyzxyzxyz'\n\n>>> num.__mul__(s)\nNotImplemented\n >>> s.__rmul__(num)\n'xyzxyzxyz'\n"
},
{
"answer_id": 3967144,
"author": "Tamás",
"author_id": 156771,
"author_profile": "https://Stackoverflow.com/users/156771",
"pm_score": 6,
"selected": false,
"text": "enumerate enumerate enumerate >>> l = [\"spam\", \"ham\", \"eggs\"]\n>>> list(enumerate(l))\n>>> [(0, \"spam\"), (1, \"ham\"), (2, \"eggs\")]\n>>> list(enumerate(l, 1))\n>>> [(1, \"spam\"), (2, \"ham\"), (3, \"eggs\")]\n enumerate for for ri, row in enumerate(matrix):\n for ci, column in enumerate(matrix[ri:], ri):\n # ci now refers to the proper column index\n enumerate help(enumerate)"
},
{
"answer_id": 4501451,
"author": "Noufal Ibrahim",
"author_id": 229602,
"author_profile": "https://Stackoverflow.com/users/229602",
"pm_score": 4,
"selected": false,
"text": " comma_join = \",\".join\n semi_join = \";\".join\n\n print comma_join([\"foo\",\"bar\",\"baz\"])\n 'foo,bar,baz\n l = [\"item1\", \"item2\", \"item3\"]\n l = \"item1 item2 item3\".split()\n"
},
{
"answer_id": 4544088,
"author": "asmeurer",
"author_id": 161801,
"author_profile": "https://Stackoverflow.com/users/161801",
"pm_score": 4,
"selected": false,
"text": "* + - / // % ^ == < > <= >= . __mul__ __add__ __rmul__ your_object*something_else something_else*your_object . a.b b __getattr__ a(…) __call__ a[stuff] , : … del in import not __int__ __str__ __len__ __reversed__ __abs__ __pow__"
},
{
"answer_id": 4602518,
"author": "Adrien Plisson",
"author_id": 195823,
"author_profile": "https://Stackoverflow.com/users/195823",
"pm_score": 6,
"selected": false,
"text": ">>> first,second,*rest = (1,2,3,4,5,6,7,8)\n>>> first\n1\n>>> second\n2\n>>> rest\n[3, 4, 5, 6, 7, 8]\n >>> first,*rest,last = (1,2,3,4,5,6,7,8)\n>>> first\n1\n>>> rest\n[2, 3, 4, 5, 6, 7]\n>>> last\n8\n"
},
{
"answer_id": 4627428,
"author": "Ant",
"author_id": 465159,
"author_profile": "https://Stackoverflow.com/users/465159",
"pm_score": 2,
"selected": false,
"text": "count = 10 ** 5\nnums = []\nfor x in range(count):\n nums.append(x)\nnums.reverse()\n count = 10 ** 5 \nnums = [] \nfor x in range(count):\n nums.insert(0, x)\n"
},
{
"answer_id": 4630680,
"author": "Apalala",
"author_id": 545637,
"author_profile": "https://Stackoverflow.com/users/545637",
"pm_score": 3,
"selected": false,
"text": ">>> node = namedtuple('node', \"a b\")\n>>> node(1,2) + node(5,6)\n(1, 2, 5, 6)\n>>> (node(1,2), node(5,6))\n(node(a=1, b=2), node(a=5, b=6))\n>>> \n >>> from collections import namedtuple\n>>> from operator import *\n>>> mytuple = namedtuple('A', \"a b\")\n>>> yourtuple = namedtuple('Z', \"x y\")\n>>> mytuple(1,2) + yourtuple(5,6)\n(1, 2, 5, 6)\n>>> q = [mytuple(1,2), yourtuple(5,6)]\n>>> q\n[A(a=1, b=2), Z(x=5, y=6)]\n>>> reduce(operator.__add__, q)\n(1, 2, 5, 6)\n namedtuple tuple"
},
{
"answer_id": 4675525,
"author": "Apalala",
"author_id": 545637,
"author_profile": "https://Stackoverflow.com/users/545637",
"pm_score": 2,
"selected": false,
"text": "# this is \"answer42.py\"\nfrom operator import *\nfrom inspect import *\n >>> import answer42\n>>> answer42.__dict__.keys()\n['gt', 'imul', 'ge', 'setslice', 'ArgInfo', 'getfile', 'isCallable', 'getsourcelines', 'CO_OPTIMIZED', 'le', 're', 'isgenerator', 'ArgSpec', 'imp', 'lt', 'delslice', 'BlockFinder', 'getargspec', 'currentframe', 'CO_NOFREE', 'namedtuple', 'rshift', 'string', 'getframeinfo', '__file__', 'strseq', 'iconcat', 'getmro', 'mod', 'getcallargs', 'isub', 'getouterframes', 'isdatadescriptor', 'modulesbyfile', 'setitem', 'truth', 'Attribute', 'div', 'CO_NESTED', 'ixor', 'getargvalues', 'ismemberdescriptor', 'getsource', 'isMappingType', 'eq', 'index', 'xor', 'sub', 'getcomments', 'neg', 'getslice', 'isframe', '__builtins__', 'abs', 'getmembers', 'mul', 'getclasstree', 'irepeat', 'is_', 'getitem', 'indexOf', 'Traceback', 'findsource', 'ModuleInfo', 'ipow', 'TPFLAGS_IS_ABSTRACT', 'or_', 'joinseq', 'is_not', 'itruediv', 'getsourcefile', 'dis', 'os', 'iand', 'countOf', 'getinnerframes', 'pow', 'pos', 'and_', 'lshift', '__name__', 'sequenceIncludes', 'isabstract', 'isbuiltin', 'invert', 'contains', 'add', 'isSequenceType', 'irshift', 'types', 'tokenize', 'isfunction', 'not_', 'istraceback', 'getmoduleinfo', 'isgeneratorfunction', 'getargs', 'CO_GENERATOR', 'cleandoc', 'classify_class_attrs', 'EndOfBlock', 'walktree', '__doc__', 'getmodule', 'isNumberType', 'ilshift', 'ismethod', 'ifloordiv', 'formatargvalues', 'indentsize', 'getmodulename', 'inv', 'Arguments', 'iscode', 'CO_NEWLOCALS', 'formatargspec', 'iadd', 'getlineno', 'imod', 'CO_VARKEYWORDS', 'ne', 'idiv', '__package__', 'CO_VARARGS', 'attrgetter', 'methodcaller', 'truediv', 'repeat', 'trace', 'isclass', 'ior', 'ismethoddescriptor', 'sys', 'isroutine', 'delitem', 'stack', 'concat', 'getdoc', 'getabsfile', 'ismodule', 'linecache', 'floordiv', 'isgetsetdescriptor', 'itemgetter', 'getblock']\n>>> from answer42 import getmembers\n>>> getmembers\n<function getmembers at 0xb74b2924>\n>>> \n from x import * __all__ ="
},
{
"answer_id": 4775286,
"author": "Brendon Crawford",
"author_id": 552766,
"author_profile": "https://Stackoverflow.com/users/552766",
"pm_score": 3,
"selected": false,
"text": "from operator import add\nprint reduce(add, [1,2,3,4,5,6])\n"
},
{
"answer_id": 4775544,
"author": "Chmouel Boudjnah",
"author_id": 145125,
"author_profile": "https://Stackoverflow.com/users/145125",
"pm_score": 5,
"selected": false,
"text": ">>> 'str' in 'string'\nTrue\n>>> 'no' in 'yes'\nFalse\n>>> \n if 'yes'.find(\"no\") == -1:\n pass\n"
},
{
"answer_id": 4779148,
"author": "FernandoEscher",
"author_id": 176376,
"author_profile": "https://Stackoverflow.com/users/176376",
"pm_score": 3,
"selected": false,
"text": "__getattribute__ class Dummy(object):\n def __getattribute__(self, name):\n f = lambda: 'Hello with %s'%name\n return f\n >>> d = Dummy()\n>>> d.b()\n'Hello with b'\n"
},
{
"answer_id": 4958857,
"author": "Foo Bah",
"author_id": 590042,
"author_profile": "https://Stackoverflow.com/users/590042",
"pm_score": 3,
"selected": false,
"text": ">>> class foo:\n... def normal_call(self): print \"normal_call\"\n... def call(self): \n... print \"first_call\"\n... self.call = self.normal_call\n\n>>> y = foo()\n>>> y.call()\nfirst_call\n>>> y.call()\nnormal_call\n>>> y.call()\nnormal_call\n...\n"
},
{
"answer_id": 5024259,
"author": "Abbafei",
"author_id": 541412,
"author_profile": "https://Stackoverflow.com/users/541412",
"pm_score": 3,
"selected": false,
"text": "print print('We want Moshiach Now') We want Moshiach Now not not False not(False) True not 1 >>> (not 1) == 9\nFalse\n\n>>> not(1) == 9\nTrue\n not'val' False print'We want Moshiach Now' We want Moshiach Now not552"
},
{
"answer_id": 5084257,
"author": "Ivan P",
"author_id": 477396,
"author_profile": "https://Stackoverflow.com/users/477396",
"pm_score": 2,
"selected": false,
"text": "\n>>> class A:\n... def __init__(self):\n... self.__var = 5\n... def getvar(self):\n... return self.__var\n... \n>>> a = A()\n>>> a.__var\nTraceback (most recent call last):\n File \"\", line 1, in \nAttributeError: A instance has no attribute '__var'\n>>> a.getvar()\n5\n>>> dir(a)\n['_A__var', '__doc__', '__init__', '__module__', 'getvar']\n>>>\n"
},
{
"answer_id": 5202538,
"author": "armandino",
"author_id": 45112,
"author_profile": "https://Stackoverflow.com/users/45112",
"pm_score": 3,
"selected": false,
"text": ">>> foo = bar = baz = 1\n>>> foo, bar, baz\n(1, 1, 1)\n >>> foo, bar, baz = 1, 2, 3\n>>> foo, bar, baz\n(1, 2, 3)\n"
},
{
"answer_id": 5202620,
"author": "dan_waterworth",
"author_id": 393783,
"author_profile": "https://Stackoverflow.com/users/393783",
"pm_score": 4,
"selected": false,
"text": "re.Scanner"
},
{
"answer_id": 5251054,
"author": "Luper Rouch",
"author_id": 17911,
"author_profile": "https://Stackoverflow.com/users/17911",
"pm_score": 2,
"selected": false,
"text": "import os.path as op\n\nroot_dir = op.abspath(op.join(op.dirname(__file__), \"..\"))\n"
},
{
"answer_id": 5251200,
"author": "Kimvais",
"author_id": 180174,
"author_profile": "https://Stackoverflow.com/users/180174",
"pm_score": 4,
"selected": false,
"text": "$ python -m http.server\n $ wget http://<ipnumber>:8000/filename $ python -m SimpleHTTPServer\n python -m http.server 80"
},
{
"answer_id": 5446831,
"author": "Kabie",
"author_id": 260985,
"author_profile": "https://Stackoverflow.com/users/260985",
"pm_score": 2,
"selected": false,
"text": ">>> 'Unicode字符_تكوين_Variable'.isidentifier()\nTrue\n>>> Unicode字符_تكوين_Variable='Python3 rules!'\n>>> Unicode字符_تكوين_Variable\n'Python3 rules!'\n"
},
{
"answer_id": 6123240,
"author": "Rabarberski",
"author_id": 50899,
"author_profile": "https://Stackoverflow.com/users/50899",
"pm_score": 0,
"selected": false,
"text": "print \"SO\"*5 \n SOSOSOSOSO\n"
},
{
"answer_id": 6143038,
"author": "inspectorG4dget",
"author_id": 198633,
"author_profile": "https://Stackoverflow.com/users/198633",
"pm_score": 0,
"selected": false,
"text": "stdout stderr os.system commands.getoutput >>> print commands.getoutput('ls')\nmyFile1.txt myFile2.txt myFile3.txt myFile4.txt myFile5.txt\nmyFile6.txt myFile7.txt myFile8.txt myFile9.txt myFile10.txt\nmyFile11.txt myFile12.txt myFile13.txt myFile14.txt module.py\n"
},
{
"answer_id": 6338283,
"author": "Ken Arnold",
"author_id": 69707,
"author_profile": "https://Stackoverflow.com/users/69707",
"pm_score": 3,
"selected": false,
"text": "getattr getattr(obj, attribute_name, default) try:\n return obj.attribute\nexcept AttributeError:\n return default\n attribute_name class MyThing:\n pass\nclass MyOtherThing:\n pass\nif isinstance(obj, (MyThing, MyOtherThing)):\n process(obj)\n isinstance(obj, (a,b)) isinstance(obj, a) or isinstance(obj, b) class MyThing:\n processable = True\nclass MyOtherThing:\n processable = True\nif getattr(obj, 'processable', False):\n process(obj)\n class Processable:\n processable = True\n"
},
{
"answer_id": 6403350,
"author": "jassinm",
"author_id": 239007,
"author_profile": "https://Stackoverflow.com/users/239007",
"pm_score": 1,
"selected": false,
"text": "def sumprod(x,y):\n return reduce(lambda a,b:a+b, map(lambda a, b: a*b,x,y))\n In [2]: sumprod([1,2,3],[4,5,6])\nOut[2]: 32\n"
},
{
"answer_id": 6413158,
"author": "Douglas",
"author_id": 244261,
"author_profile": "https://Stackoverflow.com/users/244261",
"pm_score": 3,
"selected": false,
"text": "% python -m timeit 'r = range(0, 1000)' 'for i in r: pass'\n10000 loops, best of 3: 48.4 usec per loop\n\n% python -m timeit 'r = xrange(0, 1000)' 'for i in r: pass'\n10000 loops, best of 3: 37.4 usec per loop\n"
},
{
"answer_id": 6486393,
"author": "Elisha",
"author_id": 766068,
"author_profile": "https://Stackoverflow.com/users/766068",
"pm_score": 3,
"selected": false,
"text": ">>> a = [1,2]\n>>> a.append(a)\n>>> a\n[1, 2, [...]]\n>>> a[2]\n[1, 2, [...]]\n>>> a[2][2][2][2][2][2][2][2][2] == a\nTrue\n"
},
{
"answer_id": 6528965,
"author": "matchew",
"author_id": 638649,
"author_profile": "https://Stackoverflow.com/users/638649",
"pm_score": 2,
"selected": false,
"text": "print print>>outFile, 'I am Being Written' print write() None sys.stdout"
},
{
"answer_id": 6574805,
"author": "Roman Bodnarchuk",
"author_id": 406693,
"author_profile": "https://Stackoverflow.com/users/406693",
"pm_score": 3,
"selected": false,
"text": "string-escape unicode-escape \\n \\t string-escape >>> print s\nHello\\nStack\\toverflow\n>>> print s.decode('string-escape')\nHello\nStack overflow\n \\u01245 unicode-escape >>> s = '\\u041f\\u0440\\u0438\\u0432\\u0456\\u0442, \\u0441\\u0432\\u0456\\u0442!'\n>>> print s\n\\u041f\\u0440\\u0438\\u0432\\u0456\\u0442, \\u0441\\u0432\\u0456\\u0442!\n>>> print unicode(s)\n\\u041f\\u0440\\u0438\\u0432\\u0456\\u0442, \\u0441\\u0432\\u0456\\u0442!\n>>> print unicode(s, 'unicode-escape')\nПривіт, світ!\n"
},
{
"answer_id": 6632253,
"author": "johnsyweb",
"author_id": 78845,
"author_profile": "https://Stackoverflow.com/users/78845",
"pm_score": 3,
"selected": false,
"text": "list sum() sum() __add__ list list list Python 2.7.1 (r271:86832, May 27 2011, 21:41:45) \n[GCC 4.2.1 (Apple Inc. build 5664)] on darwin\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> l = [[1, 2, 3], [4, 5], [6], [7, 8, 9]]\n>>> sum(l, [])\n[1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
},
{
"answer_id": 6735488,
"author": "cerberos",
"author_id": 121725,
"author_profile": "https://Stackoverflow.com/users/121725",
"pm_score": 3,
"selected": false,
"text": "Borg foo class Borg:\n __shared_state = {'foo': 'bar'}\n def __init__(self):\n self.__dict__ = self.__shared_state\n # rest of your class here\n"
},
{
"answer_id": 7076512,
"author": "mdeous",
"author_id": 293050,
"author_profile": "https://Stackoverflow.com/users/293050",
"pm_score": 3,
"selected": false,
"text": ">>> import __hello__\nHello world...\n Werkzeug Werkzeug werkzeug/__init__.py 'werkzeug._internal': ['_easteregg']\n werkzeug/_internal.py _easteregg() macgybarchakku _easteregg() from werkzeug import Request, Response, run_simple\nfrom werkzeug import _easteregg\n\n@Request.application\ndef application(request):\n return Response('Hello World!')\n\nrun_simple('localhost', 8080, _easteregg(application))\n"
},
{
"answer_id": 7305174,
"author": "giodamelio",
"author_id": 375847,
"author_profile": "https://Stackoverflow.com/users/375847",
"pm_score": 0,
"selected": false,
"text": "def typePrint(object):\n print(str(object) + \" - (\" + str(type(object)) + \")\")\n >>> a = 101\n>>> typePrint(a)\n 101 - (<type 'int'>)\n"
},
{
"answer_id": 7560592,
"author": "bfontaine",
"author_id": 735926,
"author_profile": "https://Stackoverflow.com/users/735926",
"pm_score": -1,
"selected": false,
"text": "for line in open('foo'):\n print(line)\n f = open('foo', 'r')\nfor line in f.readlines():\n print(line)\nf.close()\n"
},
{
"answer_id": 7742520,
"author": "etuardu",
"author_id": 440172,
"author_profile": "https://Stackoverflow.com/users/440172",
"pm_score": 2,
"selected": false,
"text": "site._Printer license type(license)(0,open('textfile.txt').read(),0)()\n ...\nfile row 21\nfile row 22\nfile row 23\n\nHit Return for more, or q (and Return) to quit:\n"
},
{
"answer_id": 7852572,
"author": "shadowland",
"author_id": 179256,
"author_profile": "https://Stackoverflow.com/users/179256",
"pm_score": 0,
"selected": false,
"text": "import pdb; pdb.set_trace() \"\"\"\n>>> 1 in (1,2,3) \nBecomes\n>>> import pdb; pdb.set_trace(); 1 in (1,2,3)\n\"\"\"\n"
},
{
"answer_id": 8420779,
"author": "Giampaolo Rodolà",
"author_id": 376587,
"author_profile": "https://Stackoverflow.com/users/376587",
"pm_score": 0,
"selected": false,
"text": " >>> `sorted`\n'<built-in function sorted>'\n"
},
{
"answer_id": 8442263,
"author": "sransara",
"author_id": 729485,
"author_profile": "https://Stackoverflow.com/users/729485",
"pm_score": 1,
"selected": false,
"text": "bash shell scripts python -c\"import os; print(os.getcwd());\"\n"
},
{
"answer_id": 8625452,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 2,
"selected": false,
"text": "try:\n import json\nexcept ImportError:\n import simplejson as json\n iter([]).next()\nTraceback (most recent call last):\n File \"<pyshell#4>\", line 1, in <module>\n iter(a).next()\nStopIteration\n >>> try:\n... assert []\n... except AssertionError:\n... print \"This list should not be empty\"\nThis list should not be empty\n"
},
{
"answer_id": 8670760,
"author": "yoav.aviram",
"author_id": 25287,
"author_profile": "https://Stackoverflow.com/users/25287",
"pm_score": 3,
"selected": false,
"text": " >>> print round(1123.456789, 4)\n1123.4568\n >>> print round(1123.456789, 2)\n1123.46\n >>> print round(1123.456789, 0)\n1123.0\n >>> print round(1123.456789, -1)\n1120.0\n >>> print round(1123.456789, -2)\n1100.0\n >>> print int(round(1123.456789, -2))\n1100\n >>> print int(round(8359980, -2))\n8360000\n"
},
{
"answer_id": 8785858,
"author": "Srinivas Reddy Thatiparthy",
"author_id": 201393,
"author_profile": "https://Stackoverflow.com/users/201393",
"pm_score": 0,
"selected": false,
"text": ">>> from operator import add,mul\n>>> reduce(add,[1,2,3,4])\n10\n>>> reduce(mul,[1,2,3,4])\n24\n>>> reduce(add,[[1,2,3,4],[1,2,3,4]])\n[1, 2, 3, 4, 1, 2, 3, 4]\n>>> reduce(add,(1,2,3,4))\n10\n>>> reduce(mul,(1,2,3,4))\n24\n"
},
{
"answer_id": 8857541,
"author": "Perkins",
"author_id": 845159,
"author_profile": "https://Stackoverflow.com/users/845159",
"pm_score": 1,
"selected": false,
"text": "l=lambda x,y,z:x+y+z\na=1,2,3\nprint l(*a)\nprint l(*[a[0],2,3])\n a=[2,3]\nl(*(a+[3]))\n"
},
{
"answer_id": 8913428,
"author": "Justin",
"author_id": 601810,
"author_profile": "https://Stackoverflow.com/users/601810",
"pm_score": 3,
"selected": false,
"text": ">>> {i: i**2 for i in range(5)}\n{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}\n"
},
{
"answer_id": 8913512,
"author": "Justin",
"author_id": 601810,
"author_profile": "https://Stackoverflow.com/users/601810",
"pm_score": 3,
"selected": false,
"text": ">>> {i**2 for i in range(5)} \nset([0, 1, 4, 16, 9])\n"
},
{
"answer_id": 8951143,
"author": "Primal Pappachan",
"author_id": 323404,
"author_profile": "https://Stackoverflow.com/users/323404",
"pm_score": 2,
"selected": false,
"text": "for x, y in zip(s, s[1:]):\n"
},
{
"answer_id": 9116759,
"author": "Giampaolo Rodolà",
"author_id": 376587,
"author_profile": "https://Stackoverflow.com/users/376587",
"pm_score": 2,
"selected": false,
"text": ">>> float('infinity')\ninf\n>>> float('NaN')\nnan\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2679/"
] |
101,270
|
<p>I want to use Vim's quickfix features with the output from Visual Studio's devenv build process or msbuild.</p>
<p>I've created a batch file called build.bat which executes the devenv build like this:</p>
<pre><code>devenv MySln.sln /Build Debug
</code></pre>
<p>In vim I've pointed the :make command to that batch file:</p>
<pre><code>:set makeprg=build.bat
</code></pre>
<p>When I now run :make, the build executes successfully, however the errors don't get parsed out. So if I run :cl or :cn I just end up seeing all the output from devenv /Build. I should see only the errors.</p>
<p>I've tried a number of different errorformat settings that I've found on various sites around the net, but none of them have parsed out the errors correctly. Here's a few I've tried:</p>
<pre><code>set errorformat=%*\\d>%f(%l)\ :\ %t%[A-z]%#\ %m
set errorformat=\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m
set errorformat=%f(%l,%c):\ error\ %n:\ %f
</code></pre>
<p>And of course I've tried Vim's default.</p>
<p>Here's some example output from the build.bat:</p>
<pre><code>C:\TFS\KwB Projects\Thingy>devenv Thingy.sln /Build Debug
Microsoft (R) Visual Studio Version 9.0.30729.1.
Copyright (C) Microsoft Corp. All rights reserved.
------ Build started: Project: Thingy, Configuration: Debug Any CPU ------
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.Linq.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\UIAutomationProvider.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Thingy.exe /resource:obj\Debug\Thingy.g.resources /resource:obj\Debug\Thingy.Properties.Resources.resources /target:winexe App.xaml.cs Controller\FieldFactory.cs Controller\UserInfo.cs Data\ThingGatewaySqlDirect.cs Data\ThingListFetcher.cs Data\UserListFetcher.cs Gui\FieldList.xaml.cs Interfaces\IList.cs Interfaces\IListFetcher.cs Model\ComboBoxField.cs Model\ListValue.cs Model\ThingType.cs Interfaces\IThingGateway.cs Model\Field.cs Model\TextBoxField.cs Model\Thing.cs Gui\MainWindow.xaml.cs Gui\ThingWindow.xaml.cs Interfaces\IField.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs RequiredValidation.cs "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\Gui\FieldList.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\Gui\MainWindow.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\Gui\ThingWindow.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\App.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\GeneratedInternalTypeHelper.g.cs"
C:\TFS\KwB Projects\Thingy\Thingy\Controller\FieldFactory.cs(14,19): error CS0246: The type or namespace name 'IFieldNothing' could not be found (are you missing a using directive or an assembly reference?)
Compile complete -- 1 errors, 0 warnings
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
</code></pre>
<p><strong>UPDATE:</strong>
It looks like using msbuild instead of devenv is probably the right way to go (as per Jay's comment).</p>
<p>Using msbuild the makeprg would be:</p>
<pre><code>:set makeprg=msbuild\ /nologo\ /v:q
</code></pre>
<p>Sample output whould be:</p>
<pre><code>Controller\FieldFactory.cs(14,19): error CS0246: The type or namespace name 'IFieldNothing' could not be found (are you missing a using directive or an assembly reference?)
</code></pre>
<p>It looks like the tricky part here may lie in the fact that the path is relative to the .csproj file, not the .sln file which is the current directory in Vim and lies one directory above the .csproj file.</p>
<p><strong>ANSWER:</strong>
I figured it out...</p>
<pre><code>set errorformat=\ %#%f(%l\\\,%c):\ %m
</code></pre>
<p>This will capture the output for both devenv /Build and msbuild.
However, msbuild has one catch. By default, it's output doesn't include full paths. To fix this you have to add the following line to your csproj file's main PropertyGroup:</p>
<pre><code><GenerateFullPaths>True</GenerateFullPaths>
</code></pre>
|
[
{
"answer_id": 102454,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 1,
"selected": false,
"text": "msbuild MySln.sln /Configuration:Debug msbuild /?"
},
{
"answer_id": 161090,
"author": "Simon Buchan",
"author_id": 20135,
"author_profile": "https://Stackoverflow.com/users/20135",
"pm_score": 3,
"selected": false,
"text": "set errorformat=\\ %#%f(%l\\\\\\,%c):\\ %m\n devenv /Build <GenerateFullPaths>True</GenerateFullPaths>\n"
},
{
"answer_id": 3115121,
"author": "idbrii",
"author_id": 79125,
"author_profile": "https://Stackoverflow.com/users/79125",
"pm_score": 1,
"selected": false,
"text": ":help errorformat \" filename(line) : error|warning|fatal error C0000: message\nset errorformat=\\ %#%f(%l)\\ :\\ %#%t%[A-z]%#\\ %[A-Z\\ ]%#%n:\\ %m\n stats.cpp|604 error 2039| 'getMedian' : is not a member of 'Stats'\n c:\\p4\\main\\stats.cpp(604) : error C2039: 'getMedian' : is not a member of 'Stats'\n"
},
{
"answer_id": 3122220,
"author": "idbrii",
"author_id": 79125,
"author_profile": "https://Stackoverflow.com/users/79125",
"pm_score": 3,
"selected": false,
"text": ":compiler efm \" Microsoft C#\ncompiler cs\n\" Microsoft Visual C++\ncompiler msvc\n\" mono\ncompiler mcs\n\" gcc\ncompiler gcc\n makeprg"
},
{
"answer_id": 3145327,
"author": "manifest",
"author_id": 236554,
"author_profile": "https://Stackoverflow.com/users/236554",
"pm_score": 0,
"selected": false,
"text": "set autowrite\n\"2>c:\\cygwin\\home\\user\\proj/blah.cpp(1657) : error C2065: 'blah' : undeclared identifier\n\nset errorformat=%.%#>\\ %#%f(%l)\\ :\\ %#%t%[A-z]%#\\ %[A-Z\\ ]%#%n:\\ %m\nlet prg=\"devenv\"\nlet makepath=$MAKEPATH\nlet &makeprg='cmd /c \"'.prg.' '.makepath.'\"'\n export MAKEPATH=\"$(cygpath -d \"proj/VC9/some.sln\") /build \\\"Debug\\\"\"\n"
},
{
"answer_id": 3618197,
"author": "Tom Miller",
"author_id": 188810,
"author_profile": "https://Stackoverflow.com/users/188810",
"pm_score": 1,
"selected": false,
"text": "<GenerateFullPaths>True</GenerateFullPaths>\n /property:GenerateFullPaths=true makeprg :set makeprg=msbuild\\ /nologo\\ /v:q\\ /property:GenerateFullPaths=true\\\n"
},
{
"answer_id": 3621753,
"author": "Kevin Berridge",
"author_id": 4407,
"author_profile": "https://Stackoverflow.com/users/4407",
"pm_score": 6,
"selected": true,
"text": ":set errorformat=\\ %#%f(%l\\\\\\,%c):\\ %m\n:set makeprg=msbuild\\ /nologo\\ /v:q\\ /property:GenerateFullPaths=true\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4407/"
] |
101,326
|
<p>I've set up wildcard mapping on IIS 6, by adding "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll", and ensured "Verify that file exists" is not checked :</p>
<ul>
<li>on the "websites" directory in IIS</li>
<li>on the website</li>
</ul>
<p>However, after a iisreset, when I go to <a href="http://myserver/something.gif" rel="nofollow noreferrer">http://myserver/something.gif</a>, I still get IIS 404 error, not asp.net one.</p>
<p>Is there something I missed ?</p>
<p>Precisions:</p>
<ul>
<li>this is not for using ASP.NET MVC</li>
<li>i'd rather not use iis 404 custom error pages, as I have a httpmodule for logging errors (this is a low traffic internal site, so wildcard mapping performance penalty is not a problem ;))</li>
</ul>
|
[
{
"answer_id": 103661,
"author": "Christopher G. Lewis",
"author_id": 13532,
"author_profile": "https://Stackoverflow.com/users/13532",
"pm_score": 3,
"selected": true,
"text": " <system.web>\n <httpHandlers>\n <add path=\"*.gif\" verb=\"GET,HEAD\" type=\"System.Web.StaticFileHandler\" validate=\"true\"/>\n </httpHandlers>\n </system.web>\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/971/"
] |
101,329
|
<p>In particular, wouldn't there have to be some kind of function pointer in place anyway? </p>
|
[
{
"answer_id": 101349,
"author": "m_pGladiator",
"author_id": 446104,
"author_profile": "https://Stackoverflow.com/users/446104",
"pm_score": 2,
"selected": false,
"text": "virtual"
},
{
"answer_id": 101583,
"author": "Richard Corden",
"author_id": 11698,
"author_profile": "https://Stackoverflow.com/users/11698",
"pm_score": 5,
"selected": true,
"text": "struct A \n{\n void foo ();\n void bar () const;\n};\n struct A \n{\n};\n\nvoid foo (A * this);\nvoid bar (A const * this);\n struct A \n{\n virtual void foo ();\n};\n void foo (A * this) {\n void (*realFoo)(A *) = lookupVtable (this->vtable, \"foo\");\n (realFoo)(this); // Make the call to the most derived version of 'foo'\n}\n"
},
{
"answer_id": 101648,
"author": "Euro Micelli",
"author_id": 2230,
"author_profile": "https://Stackoverflow.com/users/2230",
"pm_score": 4,
"selected": false,
"text": "void CMyThingy::DoSomething(int arg);\n{\n // do something\n}\n void CMyThingy_DoSomething(CMyThingy* this, int arg)\n{\n /do something\n}\n myObj.doSomething(aValue);\n CMyThingy_DoSomething(&myObj, aValue);\n myItem this->myItem"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101329",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3153/"
] |
101,338
|
<p>Is it valid to have a 'choice' of 'group' elements when defining an XML Schema (XSD)</p>
<p>i.e. is the following valid</p>
<pre><code><xs:complexType name="HeaderType">
<xs:sequence>
<xs:element name="reservation-number" type="ReservationNumberType" minOccurs="1" maxOccurs="1" nillable="false" />
<xs:choice minOccurs="1" maxOccurs="1">
<xs:group ref="ReservationGroup" />
<xs:group ref="CancellationGroup"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</code></pre>
<p>Where an XML message can represent, for example, either a new reservation or a cancellation of an existing reservation.</p>
<p>If the message is for a reservation, then it must include all the elements defined in the ReservationGroup group.</p>
<p>If it is a cancellation, then it must include all the elements defined in the CancellationGroup group.</p>
<p>For some reason, my XML editor (Eclipse) does not like this, but does not indicate why. It shows there being an error on the line <xs:complexType name="HeaderType"> but does not say what the error is</p>
|
[
{
"answer_id": 101772,
"author": "Dunderklumpen",
"author_id": 16239,
"author_profile": "https://Stackoverflow.com/users/16239",
"pm_score": 4,
"selected": true,
"text": "<xs:group name=\"ReservationGroup\">\n <xs:sequence>\n <xs:element name=\"date\"/>\n <xs:element name=\"name\"/>\n <xs:element name=\"address\"/>\n </xs:sequence>\n</xs:group>\n\n<xs:group name=\"CancellationGroup\">\n <xs:sequence>\n <xs:element name=\"date\"/>\n <xs:element name=\"name\"/>\n <xs:element name=\"address\"/>\n </xs:sequence>\n</xs:group>\n <xs:group name=\"ReservationGroup\">\n <xs:sequence>\n <xs:element name=\"resDate\"/>\n <xs:element name=\"name\"/>\n <xs:element name=\"address\"/>\n </xs:sequence>\n</xs:group>\n\n<xs:group name=\"CancellationGroup\">\n <xs:sequence>\n <xs:element name=\"cancDate\"/>\n <xs:element name=\"name\"/>\n <xs:element name=\"address\"/>\n </xs:sequence>\n</xs:group>\n <xs:complexType name=\"HeaderType\">\n <xs:sequence>\n <xs:element name=\"reservation-number\" type=\"ReservationNumberType\" minOccurs=\"1\" maxOccurs=\"1\" nillable=\"false\" />\n <xs:choice minOccurs=\"1\" maxOccurs=\"1\">\n <xs:element name=\"reservation\" type=\"ReservationType\" />\n <xs:element name=\"cancellation\" type=\"CancellationType\" />\n </xs:choice>\n </xs:sequence>\n</xs:complexType>\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15452/"
] |
101,362
|
<p>How do you generate passwords?</p>
<ul>
<li>Random Characters?</li>
<li>Passphrases?</li>
<li>High Ascii?</li>
</ul>
<p>Something like this?</p>
<pre><code>cat /dev/urandom | strings
</code></pre>
|
[
{
"answer_id": 101368,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 4,
"selected": false,
"text": "#!/usr/bin/env python\n\nfrom random import choice\nimport getopt\nimport string\nimport sys\n\ndef GenPasswd():\n chars = string.letters + string.digits\n for i in range(8):\n newpasswd = newpasswd + choice(chars)\n return newpasswd\n\ndef GenPasswd2(length=8, chars=string.letters + string.digits):\n return ''.join([choice(chars) for i in range(length)])\n\nclass Options(object):\n pass\n\ndef main(argv):\n (optionList,args) = getopt.getopt(argv[1:],\"r:l:\",[\"repeat=\",\"length=\"])\n\n options = Options()\n options.repeat = 1\n options.length = 8\n for (key,value) in optionList:\n if key == \"-r\" or key == \"--repeat\":\n options.repeat = int(value)\n elif key == \"-l\" or key == \"--length\":\n options.length = int(value)\n\n for i in xrange(options.repeat):\n print GenPasswd2(options.length)\n\nif __name__ == \"__main__\":\n sys.exit(main(sys.argv))\n"
},
{
"answer_id": 101377,
"author": "Teifion",
"author_id": 1384652,
"author_profile": "https://Stackoverflow.com/users/1384652",
"pm_score": -1,
"selected": false,
"text": "<?php\n print md5(rand(0, 99999));\n?>\n"
},
{
"answer_id": 101489,
"author": "mloughran",
"author_id": 18751,
"author_profile": "https://Stackoverflow.com/users/18751",
"pm_score": -1,
"selected": false,
"text": "md5 random_file\n"
},
{
"answer_id": 102235,
"author": "Zack Peterson",
"author_id": 83,
"author_profile": "https://Stackoverflow.com/users/83",
"pm_score": 0,
"selected": false,
"text": "&p0pul4rw3b$ite!\n"
},
{
"answer_id": 102653,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "$ gpg --gen-random 1 20 | gpg --enarmor | sed -n 5p\n"
},
{
"answer_id": 289886,
"author": "Vatine",
"author_id": 34771,
"author_profile": "https://Stackoverflow.com/users/34771",
"pm_score": 2,
"selected": false,
"text": "dd if=/dev/urandom bs=6 count=1 | mimencode"
},
{
"answer_id": 432077,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 0,
"selected": false,
"text": "rand $ perl -E\"say map { chr(33 + rand(126-33)) } 1..31\n ET<2:k|D:!z)nBPMv+yitM8x`r.(WwO\n"
},
{
"answer_id": 432097,
"author": "Evan Fosmark",
"author_id": 49701,
"author_profile": "https://Stackoverflow.com/users/49701",
"pm_score": 2,
"selected": false,
"text": "import random\n\nlength = 12\ncharset = \"abcdefghijklmnopqrstuvwxyz0123456789\"\n\npassword = \"\"\nfor i in range(0, length):\n token += random.choice(charset)\n\nprint password\n"
},
{
"answer_id": 3992009,
"author": "Pontus",
"author_id": 333448,
"author_profile": "https://Stackoverflow.com/users/333448",
"pm_score": 0,
"selected": false,
"text": "perl -le 'print map { (a..z,A..Z,0..9)[rand 62] } 1..8'\n perl -le '@l=(\"aeiou\", \"bdfgjklmnprstv\");\n print map {(split \"\",$l[$_])[rand length $l[$_]]} split \"\", \"10110101\"'\n"
},
{
"answer_id": 4396389,
"author": "Kyle",
"author_id": 490487,
"author_profile": "https://Stackoverflow.com/users/490487",
"pm_score": 2,
"selected": false,
"text": "gpg --gen-random echo $(</dev/urandom tr -dc A-Za-z0-9 | head -c8)\n"
},
{
"answer_id": 8298104,
"author": "dan_waterworth",
"author_id": 393783,
"author_profile": "https://Stackoverflow.com/users/393783",
"pm_score": 0,
"selected": false,
"text": "$ echo `cat /etc/dictionaries-common/words | sort --random-sort | head -n 4`\nconsented upsurges whitewall balderdash\n"
},
{
"answer_id": 13134698,
"author": "Arul S",
"author_id": 1784895,
"author_profile": "https://Stackoverflow.com/users/1784895",
"pm_score": 5,
"selected": false,
"text": "cat /dev/urandom | tr -dc 'a-zA-Z0-9-!@#$%^&*()_+~' | fold -w 10 | head -n 1\n"
},
{
"answer_id": 13473730,
"author": "DNA",
"author_id": 699224,
"author_profile": "https://Stackoverflow.com/users/699224",
"pm_score": 3,
"selected": false,
"text": "head -c 32 /dev/random | base64\n = echo echo $(head -c 32 /dev/random | base64 | head -c 32)\n"
},
{
"answer_id": 14484217,
"author": "Keith Thompson",
"author_id": 827263,
"author_profile": "https://Stackoverflow.com/users/827263",
"pm_score": 0,
"selected": false,
"text": "gen-password 7bp4ssi02d4i gen-passphrase porcine volume smiled insert /dev/urandom /dev/random"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18769/"
] |
101,363
|
<p>I'm using Castle Windsor for dependency injection in my test project. I'm trying to create an instance one of my 'Repository' classes. "It works fine on my machine", but when I run a nightly build in TFS, my tests are not able to load said classes.</p>
<pre><code>private static readonly WindsorContainer _container = new WindsorContainer(new XmlInterpreter());
public void MyTestInitialize()
{
var testRepository = (IBogusRepository)_container[typeof(IBogusRepository)];
}
</code></pre>
<p>xml configuration:</p>
<pre><code><castle>
<components>
<component id="primaryBogusRepository" type="Example2008.Repository.LALALALALA, Example2008.Repository" service="Example2008.Domain.Repository.IBogusRepository, Example2008.Domain" />
<component id="primaryProductRepository" type="Example2008.Repository.ProductRepository, Example2008.Repository" service="Example2008.Domain.Repository.IProductRepository, Example2008.Domain" />
</components>
</castle>
</code></pre>
<p>When I queue a new build it produces
the following message:</p>
<blockquote>
<p>Unable to create instance of class
Example2008.Test.ActiveProductRepositoryTest. Error:
System.Configuration.ConfigurationException:
The type name
Example2008.Repository.LALALALALA,
Example2008.Repository could not be
located.</p>
<p>Castle.Windsor.Installer.DefaultComponentInstaller.ObtainType(String
typeName)
Castle.Windsor.Installer.DefaultComponentInstaller.SetUpComponents(IConfiguration[]
configurations, IWindsorContainer
container)
Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer
container, IConfigurationStore store)
Castle.Windsor.WindsorContainer.RunInstaller()
Castle.Windsor.WindsorContainer..ctor(IConfigurationInterpreter
interpreter)
Example2008.Test.ActiveProductRepositoryTest..cctor()
in d:\Code_Temp\Example Project
Nightly\Sources\Example2008.Test\ProductRepositoryTest.cs:
line 19</p>
</blockquote>
<p>From this message, it seems that my configuration is correct (it can see that I want to instantiate the concrete class 'LALALALALA', so the xml configuration has obviously been red correctly)</p>
<p>I think I have my dependencies set up correctly as well (because it works locally, even if I clean the solution and rebuild).</p>
<p>Any thoughts?</p>
<p>(using VS2008, TFS 2008.Net 3.5, Castle 1.03, by the way) </p>
|
[
{
"answer_id": 101368,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 4,
"selected": false,
"text": "#!/usr/bin/env python\n\nfrom random import choice\nimport getopt\nimport string\nimport sys\n\ndef GenPasswd():\n chars = string.letters + string.digits\n for i in range(8):\n newpasswd = newpasswd + choice(chars)\n return newpasswd\n\ndef GenPasswd2(length=8, chars=string.letters + string.digits):\n return ''.join([choice(chars) for i in range(length)])\n\nclass Options(object):\n pass\n\ndef main(argv):\n (optionList,args) = getopt.getopt(argv[1:],\"r:l:\",[\"repeat=\",\"length=\"])\n\n options = Options()\n options.repeat = 1\n options.length = 8\n for (key,value) in optionList:\n if key == \"-r\" or key == \"--repeat\":\n options.repeat = int(value)\n elif key == \"-l\" or key == \"--length\":\n options.length = int(value)\n\n for i in xrange(options.repeat):\n print GenPasswd2(options.length)\n\nif __name__ == \"__main__\":\n sys.exit(main(sys.argv))\n"
},
{
"answer_id": 101377,
"author": "Teifion",
"author_id": 1384652,
"author_profile": "https://Stackoverflow.com/users/1384652",
"pm_score": -1,
"selected": false,
"text": "<?php\n print md5(rand(0, 99999));\n?>\n"
},
{
"answer_id": 101489,
"author": "mloughran",
"author_id": 18751,
"author_profile": "https://Stackoverflow.com/users/18751",
"pm_score": -1,
"selected": false,
"text": "md5 random_file\n"
},
{
"answer_id": 102235,
"author": "Zack Peterson",
"author_id": 83,
"author_profile": "https://Stackoverflow.com/users/83",
"pm_score": 0,
"selected": false,
"text": "&p0pul4rw3b$ite!\n"
},
{
"answer_id": 102653,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "$ gpg --gen-random 1 20 | gpg --enarmor | sed -n 5p\n"
},
{
"answer_id": 289886,
"author": "Vatine",
"author_id": 34771,
"author_profile": "https://Stackoverflow.com/users/34771",
"pm_score": 2,
"selected": false,
"text": "dd if=/dev/urandom bs=6 count=1 | mimencode"
},
{
"answer_id": 432077,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 0,
"selected": false,
"text": "rand $ perl -E\"say map { chr(33 + rand(126-33)) } 1..31\n ET<2:k|D:!z)nBPMv+yitM8x`r.(WwO\n"
},
{
"answer_id": 432097,
"author": "Evan Fosmark",
"author_id": 49701,
"author_profile": "https://Stackoverflow.com/users/49701",
"pm_score": 2,
"selected": false,
"text": "import random\n\nlength = 12\ncharset = \"abcdefghijklmnopqrstuvwxyz0123456789\"\n\npassword = \"\"\nfor i in range(0, length):\n token += random.choice(charset)\n\nprint password\n"
},
{
"answer_id": 3992009,
"author": "Pontus",
"author_id": 333448,
"author_profile": "https://Stackoverflow.com/users/333448",
"pm_score": 0,
"selected": false,
"text": "perl -le 'print map { (a..z,A..Z,0..9)[rand 62] } 1..8'\n perl -le '@l=(\"aeiou\", \"bdfgjklmnprstv\");\n print map {(split \"\",$l[$_])[rand length $l[$_]]} split \"\", \"10110101\"'\n"
},
{
"answer_id": 4396389,
"author": "Kyle",
"author_id": 490487,
"author_profile": "https://Stackoverflow.com/users/490487",
"pm_score": 2,
"selected": false,
"text": "gpg --gen-random echo $(</dev/urandom tr -dc A-Za-z0-9 | head -c8)\n"
},
{
"answer_id": 8298104,
"author": "dan_waterworth",
"author_id": 393783,
"author_profile": "https://Stackoverflow.com/users/393783",
"pm_score": 0,
"selected": false,
"text": "$ echo `cat /etc/dictionaries-common/words | sort --random-sort | head -n 4`\nconsented upsurges whitewall balderdash\n"
},
{
"answer_id": 13134698,
"author": "Arul S",
"author_id": 1784895,
"author_profile": "https://Stackoverflow.com/users/1784895",
"pm_score": 5,
"selected": false,
"text": "cat /dev/urandom | tr -dc 'a-zA-Z0-9-!@#$%^&*()_+~' | fold -w 10 | head -n 1\n"
},
{
"answer_id": 13473730,
"author": "DNA",
"author_id": 699224,
"author_profile": "https://Stackoverflow.com/users/699224",
"pm_score": 3,
"selected": false,
"text": "head -c 32 /dev/random | base64\n = echo echo $(head -c 32 /dev/random | base64 | head -c 32)\n"
},
{
"answer_id": 14484217,
"author": "Keith Thompson",
"author_id": 827263,
"author_profile": "https://Stackoverflow.com/users/827263",
"pm_score": 0,
"selected": false,
"text": "gen-password 7bp4ssi02d4i gen-passphrase porcine volume smiled insert /dev/urandom /dev/random"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12756/"
] |
101,386
|
<p>Does PHP have a method of having auto-generated class variables? I <em>think</em> I've seen something like this before but I'm not certain.</p>
<pre><code>public class TestClass {
private $data = array();
public function TestClass() {
$this->data['firstValue'] = "cheese";
}
}
</code></pre>
<p>The <code>$this->data</code> array is always an associative array but they keys change from class to class. Is there any viable way to access <code>$this->data['firstValue']</code> from <code>$this->firstValue</code> without having to define the link?</p>
<p>And if it is, are there any downsides to it?</p>
<p>Or is there a static method of defining the link in a way which won't explode if the <code>$this->data</code> array doesn't contain that key?</p>
|
[
{
"answer_id": 131455,
"author": "David Stockton",
"author_id": 21897,
"author_profile": "https://Stackoverflow.com/users/21897",
"pm_score": 3,
"selected": false,
"text": "__get() public class TestClass {\n private $data = array();\n\n // Since you're using PHP5, you should be using PHP5 style constructors.\n public function __construct() {\n $this->data['firstValue'] = \"cheese\";\n }\n\n /**\n * This is the magic get function. Any class variable you try to access from \n * outside the class that is not public will go through this method. The variable\n * name will be passed in to the $param parameter. For this example, all \n * will be retrieved from the private $data array. If the variable doesn't exist\n * in the array, then the method will return null.\n *\n * @param string $param Class variable name\n *\n * @return mixed\n */\n public function __get($param) {\n if (isset($this->data[$param])) {\n return $this->data[$param];\n } else {\n return null;\n }\n }\n\n /**\n * This is the \"magic\" isset method. It is very important to implement this \n * method when using __get to change or retrieve data members from private or \n * protected members. If it is not implemented, code that checks to see if a\n * particular variable has been set will fail even though you'll be able to \n * retrieve a value for that variable.\n *\n * @param string $param Variable name to check\n * \n * @return boolean\n */\n public function __isset($param) {\n return isset($this->data[$param]);\n }\n\n /**\n * This method is required if you want to be able to set variables from outside\n * your class without providing explicit setter options. Similar to accessing\n * a variable using $foo = $object->firstValue, this method allows you to set \n * the value of a variable (any variable in this case, but it can be limited \n * by modifying this method) by doing something like:\n * $this->secondValue = 'foo';\n * \n * @param string $param Class variable name to set\n * @param mixed $value Value to set\n * \n * @return null\n */\n public function __set($param, $value) {\n $this->data[$param] = $value;\n }\n}\n __get __set __isset"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101386",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12870/"
] |
101,422
|
<p>Why does the JavaScript function <code>encodeURIComponent</code> encode spaces to the hex Unicode value <code>%20</code> instead of <code>+</code>. Should URI parameters not spaces to <code>+</code>?
</p>
|
[
{
"answer_id": 1590896,
"author": "user192649",
"author_id": 192649,
"author_profile": "https://Stackoverflow.com/users/192649",
"pm_score": 0,
"selected": false,
"text": "items = (A beautiful world)\nforeach( item in $items ) echo \"* $item\"\n render-list A beautiful world\n http://testhost/cgi-bin/render-list?A+beautiful+world\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18793/"
] |
101,427
|
<p>I was wondering are there any security concerns with adding crossdomain.xml to the root of an application server? Can it be added to any other parts of the server and are you aware of any work arounds that dont require the server to have this file in place?</p>
<p>Thanks
Damien</p>
|
[
{
"answer_id": 217651,
"author": "Ronnie Liew",
"author_id": 1987,
"author_profile": "https://Stackoverflow.com/users/1987",
"pm_score": 1,
"selected": false,
"text": "http://mysubdomain.mydomain.com/fu/bar/ http://mysubdomin.mydomain.com/crossdomain.xml"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101427",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11612/"
] |
101,439
|
<p>What is the most efficient way given to raise an integer to the power of another integer in C?</p>
<pre><code>// 2^3
pow(2,3) == 8
// 5^5
pow(5,5) == 3125
</code></pre>
|
[
{
"answer_id": 101473,
"author": "Doug T.",
"author_id": 8123,
"author_profile": "https://Stackoverflow.com/users/8123",
"pm_score": 3,
"selected": false,
"text": "struct IeeeFloat\n{\n\n unsigned int base : 23;\n unsigned int exponent : 8;\n unsigned int signBit : 1;\n};\n\n\nunion IeeeFloatUnion\n{\n IeeeFloat brokenOut;\n float f;\n};\n\ninline float twoToThe(char exponent)\n{\n // notice how the range checking is already done on the exponent var \n static IeeeFloatUnion u;\n u.f = 2.0;\n // Change the exponent part of the float\n u.brokenOut.exponent += (exponent - 1);\n return (u.f);\n}\n"
},
{
"answer_id": 101613,
"author": "Elias Yarrkov",
"author_id": 18814,
"author_profile": "https://Stackoverflow.com/users/18814",
"pm_score": 10,
"selected": true,
"text": "int ipow(int base, int exp)\n{\n int result = 1;\n for (;;)\n {\n if (exp & 1)\n result *= base;\n exp >>= 1;\n if (!exp)\n break;\n base *= base;\n }\n\n return result;\n}\n"
},
{
"answer_id": 102319,
"author": "Chris Cudmore",
"author_id": 18907,
"author_profile": "https://Stackoverflow.com/users/18907",
"pm_score": 3,
"selected": false,
"text": "int pow( int base, int exponent)\n\n{ // Does not work for negative exponents. (But that would be leaving the range of int) \n if (exponent == 0) return 1; // base case;\n int temp = pow(base, exponent/2);\n if (exponent % 2 == 0)\n return temp * temp; \n else\n return (base * temp * temp);\n}\n"
},
{
"answer_id": 108959,
"author": "Pramod",
"author_id": 1386292,
"author_profile": "https://Stackoverflow.com/users/1386292",
"pm_score": 6,
"selected": false,
"text": "x^15 = (x^7)*(x^7)*x \nx^7 = (x^3)*(x^3)*x \nx^3 = x*x*x\n n*n = n^2\nn^2*n = n^3\nn^3*n^3 = n^6\nn^6*n^6 = n^12\nn^12*n^3 = n^15\n"
},
{
"answer_id": 5345369,
"author": "Jake",
"author_id": 498804,
"author_profile": "https://Stackoverflow.com/users/498804",
"pm_score": 5,
"selected": false,
"text": "2 ** 3 == 1 << 3 == 8\n2 ** 30 == 1 << 30 == 1073741824 (A Gigabyte)\n"
},
{
"answer_id": 10517609,
"author": "user1067920",
"author_id": 1067920,
"author_profile": "https://Stackoverflow.com/users/1067920",
"pm_score": 4,
"selected": false,
"text": "private int ipow(int base, int exp)\n{\n int result = 1;\n while (exp != 0)\n {\n if ((exp & 1) == 1)\n result *= base;\n exp >>= 1;\n base *= base;\n }\n\n return result;\n}\n"
},
{
"answer_id": 10578794,
"author": "aditya",
"author_id": 1223316,
"author_profile": "https://Stackoverflow.com/users/1223316",
"pm_score": 3,
"selected": false,
"text": "pow(2,5) 1<<5"
},
{
"answer_id": 20808031,
"author": "Vaibhav Fouzdar",
"author_id": 481275,
"author_profile": "https://Stackoverflow.com/users/481275",
"pm_score": 0,
"selected": false,
"text": "public static long pow(long base, long exp){ \n if(exp ==0){\n return 1;\n }\n if(exp ==1){\n return base;\n }\n\n if(exp % 2 == 0){\n long half = pow(base, exp/2);\n return half * half;\n }else{\n long half = pow(base, (exp -1)/2);\n return base * half * half;\n } \n}\n"
},
{
"answer_id": 24299375,
"author": "Abhijit Gaikwad",
"author_id": 403872,
"author_profile": "https://Stackoverflow.com/users/403872",
"pm_score": 1,
"selected": false,
"text": "private static int pow(int base, int exponent) {\n\n int result = 1;\n if (exponent == 0)\n return result; // base case;\n\n if (exponent < 0)\n return 1 / pow(base, -exponent);\n int temp = pow(base, exponent / 2);\n if (exponent % 2 == 0)\n return temp * temp;\n else\n return (base * temp * temp);\n}\n"
},
{
"answer_id": 28301482,
"author": "kyorilys",
"author_id": 1256388,
"author_profile": "https://Stackoverflow.com/users/1256388",
"pm_score": 0,
"selected": false,
"text": "int pow(float base,float exp){\n if (exp==0)return 1;\n else if(exp>0&&exp%2==0){\n return pow(base*base,exp/2);\n }else if (exp>0&&exp%2!=0){\n return base*pow(base,exp-1);\n }\n}\n"
},
{
"answer_id": 29396800,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 2,
"selected": false,
"text": "y < 0 intmax_t intmax_t powjii(0, 0) --> 1 pow(0,negative) INTMAX_MAX intmax_t powjii(int x, int y) {\n if (y < 0) {\n switch (x) {\n case 0:\n return INTMAX_MAX;\n case 1:\n return 1;\n case -1:\n return y % 2 ? -1 : 1;\n }\n return 0;\n }\n intmax_t z = 1;\n intmax_t base = x;\n for (;;) {\n if (y % 2) {\n z *= base;\n }\n y /= 2;\n if (y == 0) {\n break; \n }\n base *= base;\n }\n return z;\n}\n for(;;) base *= base int*int"
},
{
"answer_id": 31975558,
"author": "rank1",
"author_id": 1296250,
"author_profile": "https://Stackoverflow.com/users/1296250",
"pm_score": 0,
"selected": false,
"text": "public static int Power(int base, int exp)\n{\n int tab[] = new int[exp + 1];\n tab[0] = 1;\n tab[1] = base;\n return Power(base, exp, tab);\n}\n\npublic static int Power(int base, int exp, int tab[])\n {\n if(exp == 0) return 1;\n if(exp == 1) return base;\n int i = 1;\n while(i < exp/2)\n { \n if(tab[2 * i] <= 0)\n tab[2 * i] = tab[i] * tab[i];\n i = i << 1;\n }\n if(exp <= i)\n return tab[i];\n else return tab[i] * Power(base, exp - i, tab);\n}\n"
},
{
"answer_id": 34660211,
"author": "roottraveller",
"author_id": 5167682,
"author_profile": "https://Stackoverflow.com/users/5167682",
"pm_score": 3,
"selected": false,
"text": "power() int power(int base, unsigned int exp){\n\n if (exp == 0)\n return 1;\n int temp = power(base, exp/2);\n if (exp%2 == 0)\n return temp*temp;\n else\n return base*temp*temp;\n\n}\n power() float power(float base, int exp) {\n\n if( exp == 0)\n return 1;\n float temp = power(base, exp/2); \n if (exp%2 == 0)\n return temp*temp;\n else {\n if(exp > 0)\n return base*temp*temp;\n else\n return (temp*temp)/base; //negative exponent computation \n }\n\n} \n"
},
{
"answer_id": 38984329,
"author": "MarcusJ",
"author_id": 1115761,
"author_profile": "https://Stackoverflow.com/users/1115761",
"pm_score": -1,
"selected": false,
"text": "Mask1 = 1 << (Exponent - 1);\nMask2 = Mask1 - 1;\nreturn Mask1 + Mask2;\n"
},
{
"answer_id": 49712975,
"author": "Johannes Blaschke",
"author_id": 9550561,
"author_profile": "https://Stackoverflow.com/users/9550561",
"pm_score": -1,
"selected": false,
"text": "#include <iostream>\n\ntemplate<unsigned long N>\nunsigned long inline exp_unroll(unsigned base) {\n return base * exp_unroll<N-1>(base);\n}\n template<>\nunsigned long inline exp_unroll<1>(unsigned base) {\n return base;\n}\n int main(int argc, char * argv[]) {\n std::cout << argv[1] <<\"**5= \" << exp_unroll<5>(atoi(argv[1])) << ;std::endl;\n}\n"
},
{
"answer_id": 55210943,
"author": "alx",
"author_id": 6872717,
"author_profile": "https://Stackoverflow.com/users/6872717",
"pm_score": 0,
"selected": false,
"text": "#include <stdint.h>\n\n#define SQRT_INT64_MAX (INT64_C(0xB504F333))\n\nint64_t alx_pow_s64 (int64_t base, uint8_t exp)\n{\n int_fast64_t base_;\n int_fast64_t result;\n\n base_ = base;\n\n if (base_ == 1)\n return 1;\n if (!exp)\n return 1;\n if (!base_)\n return 0;\n\n result = 1;\n if (exp & 1)\n result *= base_;\n exp >>= 1;\n while (exp) {\n if (base_ > SQRT_INT64_MAX)\n return 0;\n base_ *= base_;\n if (exp & 1)\n result *= base_;\n exp >>= 1;\n }\n\n return result;\n}\n (1 ** N) == 1\n(N ** 0) == 1\n(0 ** 0) == 1\n(0 ** N) == 0\n return 0; int64_t SQRT_INT64_MAX (int)sqrt(INT_MAX) int sqrt() int INT_MAX"
},
{
"answer_id": 67377351,
"author": "ToxicAbe",
"author_id": 4233144,
"author_profile": "https://Stackoverflow.com/users/4233144",
"pm_score": 1,
"selected": false,
"text": "// Time complexity is O(log N)\nfunc power(_ base: Int, _ exp: Int) -> Int { \n\n // 1. If the exponent is 1 then return the number (e.g a^1 == a)\n //Time complexity O(1)\n if exp == 1 { \n return base\n }\n\n // 2. Calculate the value of the number raised to half of the exponent. This will be used to calculate the final answer by squaring the result (e.g a^2n == (a^n)^2 == a^n * a^n). The idea is that we can do half the amount of work by obtaining a^n and multiplying the result by itself to get a^2n\n //Time complexity O(log N)\n let tempVal = power(base, exp/2) \n\n // 3. If the exponent was odd then decompose the result in such a way that it allows you to divide the exponent in two (e.g. a^(2n+1) == a^1 * a^2n == a^1 * a^n * a^n). If the eponent is even then the result must be the base raised to half the exponent squared (e.g. a^2n == a^n * a^n = (a^n)^2).\n //Time complexity O(1)\n return (exp % 2 == 1 ? base : 1) * tempVal * tempVal \n\n}\n"
},
{
"answer_id": 67410174,
"author": "user1095108",
"author_id": 1095108,
"author_profile": "https://Stackoverflow.com/users/1095108",
"pm_score": 1,
"selected": false,
"text": "int pow(int const x, unsigned const e) noexcept\n{\n return !e ? 1 : 1 == e ? x : (e % 2 ? x : 1) * pow(x * x, e / 2);\n //return !e ? 1 : 1 == e ? x : (((x ^ 1) & -(e % 2)) ^ 1) * pow(x * x, e / 2);\n}\n"
},
{
"answer_id": 72904144,
"author": "anatolyg",
"author_id": 509868,
"author_profile": "https://Stackoverflow.com/users/509868",
"pm_score": 0,
"selected": false,
"text": "x ** y int y y x If `x` is between -2 and 2, use special-case formulas.\nOtherwise, if `y` is between 0 and 8, use special-case formulas.\nOtherwise:\n Set x = abs(x); remember if x was negative\n If x <= 10 and y <= 19:\n Load precomputed result from a lookup table\n Otherwise:\n Set result to 0 (overflow)\n If x was negative and y is odd, negate the result\n #define POW9(x) x * x * x * x * x * x * x * x * x\n#define POW10(x) POW9(x) * x\n#define POW11(x) POW10(x) * x\n#define POW12(x) POW11(x) * x\n#define POW13(x) POW12(x) * x\n#define POW14(x) POW13(x) * x\n#define POW15(x) POW14(x) * x\n#define POW16(x) POW15(x) * x\n#define POW17(x) POW16(x) * x\n#define POW18(x) POW17(x) * x\n#define POW19(x) POW18(x) * x\n\nint mypow(int x, unsigned y)\n{\n static int table[8][11] = {\n {POW9(3), POW10(3), POW11(3), POW12(3), POW13(3), POW14(3), POW15(3), POW16(3), POW17(3), POW18(3), POW19(3)},\n {POW9(4), POW10(4), POW11(4), POW12(4), POW13(4), POW14(4), POW15(4), 0, 0, 0, 0},\n {POW9(5), POW10(5), POW11(5), POW12(5), POW13(5), 0, 0, 0, 0, 0, 0},\n {POW9(6), POW10(6), POW11(6), 0, 0, 0, 0, 0, 0, 0, 0},\n {POW9(7), POW10(7), POW11(7), 0, 0, 0, 0, 0, 0, 0, 0},\n {POW9(8), POW10(8), 0, 0, 0, 0, 0, 0, 0, 0, 0},\n {POW9(9), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n {POW9(10), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}\n };\n\n int is_neg;\n int r;\n\n switch (x)\n {\n case 0:\n return y == 0 ? 1 : 0;\n case 1:\n return 1;\n case -1:\n return y % 2 == 0 ? 1 : -1;\n case 2:\n return 1 << y;\n case -2:\n return (y % 2 == 0 ? 1 : -1) << y;\n default:\n switch (y)\n {\n case 0:\n return 1;\n case 1:\n return x;\n case 2:\n return x * x;\n case 3:\n return x * x * x;\n case 4:\n r = x * x;\n return r * r;\n case 5:\n r = x * x;\n return r * r * x;\n case 6:\n r = x * x;\n return r * r * r;\n case 7:\n r = x * x;\n return r * r * r * x;\n case 8:\n r = x * x;\n r = r * r;\n return r * r;\n default:\n is_neg = x < 0;\n if (is_neg)\n x = -x;\n if (x <= 10 && y <= 19)\n r = table[x - 3][y - 9];\n else\n r = 0;\n if (is_neg && y % 2 == 1)\n r = -r;\n return r;\n }\n }\n}\n"
},
{
"answer_id": 73215238,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": -1,
"selected": false,
"text": "gnu-GMP ______2() ______10() ( time ( jot - 1456 9999999999 6671 | pvE0 | \n\ngawk -Mbe '\nfunction ______10(_, __, ___, ____, _____, _______) {\n __ = +__\n ____ = (____+=_____=____^= \\\n (_ %=___=+___)<_)+____++^____—\n\n while (__) {\n if (_______= __%____) {\n if (__==_______) {\n return (_^__ *_____) %___\n }\n __-=_______\n _____ = (_^_______*_____) %___\n }\n __/=____\n _ = _^____%___\n }\n}\nfunction ______2(_, __, ___, ____, _____) {\n __=+__\n ____+=____=_____^=(_%=___=+___)<_\n while (__) {\n if (__ %____) {\n if (__<____) {\n return (_*_____) %___\n }\n _____ = (_____*_) %___\n --__\n }\n __/=____\n _= (_*_) %___\n }\n} \nBEGIN {\n OFMT = CONVFMT = \"%.250g\"\n\n __ = (___=_^= FS=OFS= \"=\")(_<_)\n\n _____ = __^(_=3)^--_ * ++_-(_+_)^_\n ______ = _^(_+_)-_ + _^!_\n\n _______ = int(______*_____)\n ________ = 10 ^ 5 + 1\n _________ = 8 ^ 4 * 2 - 1\n}\n GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0, GNU MP 6.2.1) ($++NF = ______10(_=$___, NR %________ +_________,_______*(_-11))) ^!___'\n out9: 48.4MiB 0:00:08 [6.02MiB/s] [6.02MiB/s] [ <=> ]\n in0: 15.6MiB 0:00:08 [1.95MiB/s] [1.95MiB/s] [ <=> ]\n( jot - 1456 9999999999 6671 | pvE 0.1 in0 | gawk -Mbe ; ) \n\n8.31s user 0.06s system 103% cpu 8.058 total\nffa16aa937b7beca66a173ccbf8e1e12 stdin\n ($++NF = ______2(_=$___, NR %________ +_________,_______*(_-11))) ^!___'\n out9: 48.4MiB 0:00:12 [3.78MiB/s] [3.78MiB/s] [<=> ]\n in0: 15.6MiB 0:00:12 [1.22MiB/s] [1.22MiB/s] [ <=> ]\n( jot - 1456 9999999999 6671 | pvE 0.1 in0 | gawk -Mbe ; ) \n\n13.05s user 0.07s system 102% cpu 12.821 total\nffa16aa937b7beca66a173ccbf8e1e12 stdin\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101439",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8123/"
] |
101,449
|
<p>I'm guessing I need to implement an <code>NVelocityViewEngine</code> and <code>NVelocityView</code> - but before I do I wanted to check to see if anyone has already done this.</p>
<p>I can't see anything in the <a href="http://mvccontrib.googlecode.com/svn/trunk/" rel="nofollow noreferrer">trunk</a> for <a href="http://www.codeplex.com/MVCContrib" rel="nofollow noreferrer">MVCContrib</a>.</p>
<p>I've already seen the post below - I'm looking specifically for something which works with Preview 5:</p>
<ul>
<li><a href="http://www.chadmyers.com/Blog/archive/2007/11/28/testing-scottgu-alternate-view-engines-with-asp.net-mvc-nvelocity.aspx" rel="nofollow noreferrer">Testing ScottGu: Alternate View Engines with ASP.NET MVC (NVelocity)</a></li>
</ul>
<p>Otherwise I'll start writing one :)</p>
|
[
{
"answer_id": 101473,
"author": "Doug T.",
"author_id": 8123,
"author_profile": "https://Stackoverflow.com/users/8123",
"pm_score": 3,
"selected": false,
"text": "struct IeeeFloat\n{\n\n unsigned int base : 23;\n unsigned int exponent : 8;\n unsigned int signBit : 1;\n};\n\n\nunion IeeeFloatUnion\n{\n IeeeFloat brokenOut;\n float f;\n};\n\ninline float twoToThe(char exponent)\n{\n // notice how the range checking is already done on the exponent var \n static IeeeFloatUnion u;\n u.f = 2.0;\n // Change the exponent part of the float\n u.brokenOut.exponent += (exponent - 1);\n return (u.f);\n}\n"
},
{
"answer_id": 101613,
"author": "Elias Yarrkov",
"author_id": 18814,
"author_profile": "https://Stackoverflow.com/users/18814",
"pm_score": 10,
"selected": true,
"text": "int ipow(int base, int exp)\n{\n int result = 1;\n for (;;)\n {\n if (exp & 1)\n result *= base;\n exp >>= 1;\n if (!exp)\n break;\n base *= base;\n }\n\n return result;\n}\n"
},
{
"answer_id": 102319,
"author": "Chris Cudmore",
"author_id": 18907,
"author_profile": "https://Stackoverflow.com/users/18907",
"pm_score": 3,
"selected": false,
"text": "int pow( int base, int exponent)\n\n{ // Does not work for negative exponents. (But that would be leaving the range of int) \n if (exponent == 0) return 1; // base case;\n int temp = pow(base, exponent/2);\n if (exponent % 2 == 0)\n return temp * temp; \n else\n return (base * temp * temp);\n}\n"
},
{
"answer_id": 108959,
"author": "Pramod",
"author_id": 1386292,
"author_profile": "https://Stackoverflow.com/users/1386292",
"pm_score": 6,
"selected": false,
"text": "x^15 = (x^7)*(x^7)*x \nx^7 = (x^3)*(x^3)*x \nx^3 = x*x*x\n n*n = n^2\nn^2*n = n^3\nn^3*n^3 = n^6\nn^6*n^6 = n^12\nn^12*n^3 = n^15\n"
},
{
"answer_id": 5345369,
"author": "Jake",
"author_id": 498804,
"author_profile": "https://Stackoverflow.com/users/498804",
"pm_score": 5,
"selected": false,
"text": "2 ** 3 == 1 << 3 == 8\n2 ** 30 == 1 << 30 == 1073741824 (A Gigabyte)\n"
},
{
"answer_id": 10517609,
"author": "user1067920",
"author_id": 1067920,
"author_profile": "https://Stackoverflow.com/users/1067920",
"pm_score": 4,
"selected": false,
"text": "private int ipow(int base, int exp)\n{\n int result = 1;\n while (exp != 0)\n {\n if ((exp & 1) == 1)\n result *= base;\n exp >>= 1;\n base *= base;\n }\n\n return result;\n}\n"
},
{
"answer_id": 10578794,
"author": "aditya",
"author_id": 1223316,
"author_profile": "https://Stackoverflow.com/users/1223316",
"pm_score": 3,
"selected": false,
"text": "pow(2,5) 1<<5"
},
{
"answer_id": 20808031,
"author": "Vaibhav Fouzdar",
"author_id": 481275,
"author_profile": "https://Stackoverflow.com/users/481275",
"pm_score": 0,
"selected": false,
"text": "public static long pow(long base, long exp){ \n if(exp ==0){\n return 1;\n }\n if(exp ==1){\n return base;\n }\n\n if(exp % 2 == 0){\n long half = pow(base, exp/2);\n return half * half;\n }else{\n long half = pow(base, (exp -1)/2);\n return base * half * half;\n } \n}\n"
},
{
"answer_id": 24299375,
"author": "Abhijit Gaikwad",
"author_id": 403872,
"author_profile": "https://Stackoverflow.com/users/403872",
"pm_score": 1,
"selected": false,
"text": "private static int pow(int base, int exponent) {\n\n int result = 1;\n if (exponent == 0)\n return result; // base case;\n\n if (exponent < 0)\n return 1 / pow(base, -exponent);\n int temp = pow(base, exponent / 2);\n if (exponent % 2 == 0)\n return temp * temp;\n else\n return (base * temp * temp);\n}\n"
},
{
"answer_id": 28301482,
"author": "kyorilys",
"author_id": 1256388,
"author_profile": "https://Stackoverflow.com/users/1256388",
"pm_score": 0,
"selected": false,
"text": "int pow(float base,float exp){\n if (exp==0)return 1;\n else if(exp>0&&exp%2==0){\n return pow(base*base,exp/2);\n }else if (exp>0&&exp%2!=0){\n return base*pow(base,exp-1);\n }\n}\n"
},
{
"answer_id": 29396800,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 2,
"selected": false,
"text": "y < 0 intmax_t intmax_t powjii(0, 0) --> 1 pow(0,negative) INTMAX_MAX intmax_t powjii(int x, int y) {\n if (y < 0) {\n switch (x) {\n case 0:\n return INTMAX_MAX;\n case 1:\n return 1;\n case -1:\n return y % 2 ? -1 : 1;\n }\n return 0;\n }\n intmax_t z = 1;\n intmax_t base = x;\n for (;;) {\n if (y % 2) {\n z *= base;\n }\n y /= 2;\n if (y == 0) {\n break; \n }\n base *= base;\n }\n return z;\n}\n for(;;) base *= base int*int"
},
{
"answer_id": 31975558,
"author": "rank1",
"author_id": 1296250,
"author_profile": "https://Stackoverflow.com/users/1296250",
"pm_score": 0,
"selected": false,
"text": "public static int Power(int base, int exp)\n{\n int tab[] = new int[exp + 1];\n tab[0] = 1;\n tab[1] = base;\n return Power(base, exp, tab);\n}\n\npublic static int Power(int base, int exp, int tab[])\n {\n if(exp == 0) return 1;\n if(exp == 1) return base;\n int i = 1;\n while(i < exp/2)\n { \n if(tab[2 * i] <= 0)\n tab[2 * i] = tab[i] * tab[i];\n i = i << 1;\n }\n if(exp <= i)\n return tab[i];\n else return tab[i] * Power(base, exp - i, tab);\n}\n"
},
{
"answer_id": 34660211,
"author": "roottraveller",
"author_id": 5167682,
"author_profile": "https://Stackoverflow.com/users/5167682",
"pm_score": 3,
"selected": false,
"text": "power() int power(int base, unsigned int exp){\n\n if (exp == 0)\n return 1;\n int temp = power(base, exp/2);\n if (exp%2 == 0)\n return temp*temp;\n else\n return base*temp*temp;\n\n}\n power() float power(float base, int exp) {\n\n if( exp == 0)\n return 1;\n float temp = power(base, exp/2); \n if (exp%2 == 0)\n return temp*temp;\n else {\n if(exp > 0)\n return base*temp*temp;\n else\n return (temp*temp)/base; //negative exponent computation \n }\n\n} \n"
},
{
"answer_id": 38984329,
"author": "MarcusJ",
"author_id": 1115761,
"author_profile": "https://Stackoverflow.com/users/1115761",
"pm_score": -1,
"selected": false,
"text": "Mask1 = 1 << (Exponent - 1);\nMask2 = Mask1 - 1;\nreturn Mask1 + Mask2;\n"
},
{
"answer_id": 49712975,
"author": "Johannes Blaschke",
"author_id": 9550561,
"author_profile": "https://Stackoverflow.com/users/9550561",
"pm_score": -1,
"selected": false,
"text": "#include <iostream>\n\ntemplate<unsigned long N>\nunsigned long inline exp_unroll(unsigned base) {\n return base * exp_unroll<N-1>(base);\n}\n template<>\nunsigned long inline exp_unroll<1>(unsigned base) {\n return base;\n}\n int main(int argc, char * argv[]) {\n std::cout << argv[1] <<\"**5= \" << exp_unroll<5>(atoi(argv[1])) << ;std::endl;\n}\n"
},
{
"answer_id": 55210943,
"author": "alx",
"author_id": 6872717,
"author_profile": "https://Stackoverflow.com/users/6872717",
"pm_score": 0,
"selected": false,
"text": "#include <stdint.h>\n\n#define SQRT_INT64_MAX (INT64_C(0xB504F333))\n\nint64_t alx_pow_s64 (int64_t base, uint8_t exp)\n{\n int_fast64_t base_;\n int_fast64_t result;\n\n base_ = base;\n\n if (base_ == 1)\n return 1;\n if (!exp)\n return 1;\n if (!base_)\n return 0;\n\n result = 1;\n if (exp & 1)\n result *= base_;\n exp >>= 1;\n while (exp) {\n if (base_ > SQRT_INT64_MAX)\n return 0;\n base_ *= base_;\n if (exp & 1)\n result *= base_;\n exp >>= 1;\n }\n\n return result;\n}\n (1 ** N) == 1\n(N ** 0) == 1\n(0 ** 0) == 1\n(0 ** N) == 0\n return 0; int64_t SQRT_INT64_MAX (int)sqrt(INT_MAX) int sqrt() int INT_MAX"
},
{
"answer_id": 67377351,
"author": "ToxicAbe",
"author_id": 4233144,
"author_profile": "https://Stackoverflow.com/users/4233144",
"pm_score": 1,
"selected": false,
"text": "// Time complexity is O(log N)\nfunc power(_ base: Int, _ exp: Int) -> Int { \n\n // 1. If the exponent is 1 then return the number (e.g a^1 == a)\n //Time complexity O(1)\n if exp == 1 { \n return base\n }\n\n // 2. Calculate the value of the number raised to half of the exponent. This will be used to calculate the final answer by squaring the result (e.g a^2n == (a^n)^2 == a^n * a^n). The idea is that we can do half the amount of work by obtaining a^n and multiplying the result by itself to get a^2n\n //Time complexity O(log N)\n let tempVal = power(base, exp/2) \n\n // 3. If the exponent was odd then decompose the result in such a way that it allows you to divide the exponent in two (e.g. a^(2n+1) == a^1 * a^2n == a^1 * a^n * a^n). If the eponent is even then the result must be the base raised to half the exponent squared (e.g. a^2n == a^n * a^n = (a^n)^2).\n //Time complexity O(1)\n return (exp % 2 == 1 ? base : 1) * tempVal * tempVal \n\n}\n"
},
{
"answer_id": 67410174,
"author": "user1095108",
"author_id": 1095108,
"author_profile": "https://Stackoverflow.com/users/1095108",
"pm_score": 1,
"selected": false,
"text": "int pow(int const x, unsigned const e) noexcept\n{\n return !e ? 1 : 1 == e ? x : (e % 2 ? x : 1) * pow(x * x, e / 2);\n //return !e ? 1 : 1 == e ? x : (((x ^ 1) & -(e % 2)) ^ 1) * pow(x * x, e / 2);\n}\n"
},
{
"answer_id": 72904144,
"author": "anatolyg",
"author_id": 509868,
"author_profile": "https://Stackoverflow.com/users/509868",
"pm_score": 0,
"selected": false,
"text": "x ** y int y y x If `x` is between -2 and 2, use special-case formulas.\nOtherwise, if `y` is between 0 and 8, use special-case formulas.\nOtherwise:\n Set x = abs(x); remember if x was negative\n If x <= 10 and y <= 19:\n Load precomputed result from a lookup table\n Otherwise:\n Set result to 0 (overflow)\n If x was negative and y is odd, negate the result\n #define POW9(x) x * x * x * x * x * x * x * x * x\n#define POW10(x) POW9(x) * x\n#define POW11(x) POW10(x) * x\n#define POW12(x) POW11(x) * x\n#define POW13(x) POW12(x) * x\n#define POW14(x) POW13(x) * x\n#define POW15(x) POW14(x) * x\n#define POW16(x) POW15(x) * x\n#define POW17(x) POW16(x) * x\n#define POW18(x) POW17(x) * x\n#define POW19(x) POW18(x) * x\n\nint mypow(int x, unsigned y)\n{\n static int table[8][11] = {\n {POW9(3), POW10(3), POW11(3), POW12(3), POW13(3), POW14(3), POW15(3), POW16(3), POW17(3), POW18(3), POW19(3)},\n {POW9(4), POW10(4), POW11(4), POW12(4), POW13(4), POW14(4), POW15(4), 0, 0, 0, 0},\n {POW9(5), POW10(5), POW11(5), POW12(5), POW13(5), 0, 0, 0, 0, 0, 0},\n {POW9(6), POW10(6), POW11(6), 0, 0, 0, 0, 0, 0, 0, 0},\n {POW9(7), POW10(7), POW11(7), 0, 0, 0, 0, 0, 0, 0, 0},\n {POW9(8), POW10(8), 0, 0, 0, 0, 0, 0, 0, 0, 0},\n {POW9(9), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},\n {POW9(10), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}\n };\n\n int is_neg;\n int r;\n\n switch (x)\n {\n case 0:\n return y == 0 ? 1 : 0;\n case 1:\n return 1;\n case -1:\n return y % 2 == 0 ? 1 : -1;\n case 2:\n return 1 << y;\n case -2:\n return (y % 2 == 0 ? 1 : -1) << y;\n default:\n switch (y)\n {\n case 0:\n return 1;\n case 1:\n return x;\n case 2:\n return x * x;\n case 3:\n return x * x * x;\n case 4:\n r = x * x;\n return r * r;\n case 5:\n r = x * x;\n return r * r * x;\n case 6:\n r = x * x;\n return r * r * r;\n case 7:\n r = x * x;\n return r * r * r * x;\n case 8:\n r = x * x;\n r = r * r;\n return r * r;\n default:\n is_neg = x < 0;\n if (is_neg)\n x = -x;\n if (x <= 10 && y <= 19)\n r = table[x - 3][y - 9];\n else\n r = 0;\n if (is_neg && y % 2 == 1)\n r = -r;\n return r;\n }\n }\n}\n"
},
{
"answer_id": 73215238,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": -1,
"selected": false,
"text": "gnu-GMP ______2() ______10() ( time ( jot - 1456 9999999999 6671 | pvE0 | \n\ngawk -Mbe '\nfunction ______10(_, __, ___, ____, _____, _______) {\n __ = +__\n ____ = (____+=_____=____^= \\\n (_ %=___=+___)<_)+____++^____—\n\n while (__) {\n if (_______= __%____) {\n if (__==_______) {\n return (_^__ *_____) %___\n }\n __-=_______\n _____ = (_^_______*_____) %___\n }\n __/=____\n _ = _^____%___\n }\n}\nfunction ______2(_, __, ___, ____, _____) {\n __=+__\n ____+=____=_____^=(_%=___=+___)<_\n while (__) {\n if (__ %____) {\n if (__<____) {\n return (_*_____) %___\n }\n _____ = (_____*_) %___\n --__\n }\n __/=____\n _= (_*_) %___\n }\n} \nBEGIN {\n OFMT = CONVFMT = \"%.250g\"\n\n __ = (___=_^= FS=OFS= \"=\")(_<_)\n\n _____ = __^(_=3)^--_ * ++_-(_+_)^_\n ______ = _^(_+_)-_ + _^!_\n\n _______ = int(______*_____)\n ________ = 10 ^ 5 + 1\n _________ = 8 ^ 4 * 2 - 1\n}\n GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0, GNU MP 6.2.1) ($++NF = ______10(_=$___, NR %________ +_________,_______*(_-11))) ^!___'\n out9: 48.4MiB 0:00:08 [6.02MiB/s] [6.02MiB/s] [ <=> ]\n in0: 15.6MiB 0:00:08 [1.95MiB/s] [1.95MiB/s] [ <=> ]\n( jot - 1456 9999999999 6671 | pvE 0.1 in0 | gawk -Mbe ; ) \n\n8.31s user 0.06s system 103% cpu 8.058 total\nffa16aa937b7beca66a173ccbf8e1e12 stdin\n ($++NF = ______2(_=$___, NR %________ +_________,_______*(_-11))) ^!___'\n out9: 48.4MiB 0:00:12 [3.78MiB/s] [3.78MiB/s] [<=> ]\n in0: 15.6MiB 0:00:12 [1.22MiB/s] [1.22MiB/s] [ <=> ]\n( jot - 1456 9999999999 6671 | pvE 0.1 in0 | gawk -Mbe ; ) \n\n13.05s user 0.07s system 102% cpu 12.821 total\nffa16aa937b7beca66a173ccbf8e1e12 stdin\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8542/"
] |
101,460
|
<p>At the moment, I am doing a number of searches which include "html" in them, for example "html rearrange". Unfortunately, I get a lot of hits from sites that include "rearrange" on a .html page but have no mention of html in the page itself.</p>
<p>Is there a way to prevent search terms from matching urls?</p>
|
[
{
"answer_id": 14548483,
"author": "Cinder",
"author_id": 1291313,
"author_profile": "https://Stackoverflow.com/users/1291313",
"pm_score": 1,
"selected": false,
"text": "rearrange intext:html"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6445/"
] |
101,461
|
<p>Most languages (Ruby included) allow number literals to be written in at least three bases: decimal, octal and hexadecimal. Numbers in decimal base is the usual thing and are written as (most) people naturally write numbers, 96 is written as <code>96</code>. Numbers prefixed by a zero are usually interpreted as octal based: 96 would be written as <code>0140</code>. Hexadecimal based numbers are usually prefixed by <code>0x</code>: 96 would be written as <code>0x60</code>.</p>
<p>The question is: can I write numbers as binary literals in Ruby? How?</p>
|
[
{
"answer_id": 101479,
"author": "Thelema",
"author_id": 12874,
"author_profile": "https://Stackoverflow.com/users/12874",
"pm_score": 3,
"selected": false,
"text": "0b01011\n"
},
{
"answer_id": 101482,
"author": "Purfideas",
"author_id": 4615,
"author_profile": "https://Stackoverflow.com/users/4615",
"pm_score": 7,
"selected": true,
"text": ">> 0b100\n=> 4\n"
},
{
"answer_id": 102350,
"author": "webmat",
"author_id": 6349,
"author_profile": "https://Stackoverflow.com/users/6349",
"pm_score": 4,
"selected": false,
"text": "0b100 #=> 4\n \"%b\" % 4 #=> \"100\"\n"
},
{
"answer_id": 1267871,
"author": "Rob",
"author_id": 386102,
"author_profile": "https://Stackoverflow.com/users/386102",
"pm_score": 4,
"selected": false,
"text": ">> easy_to_read_binary = 0b1110_0000_0000_0000\n=> 57344\n>> easy_to_read_binary.to_s(10)\n=> \"57344\"\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17801/"
] |
101,463
|
<p>I know how to change the schema of a table in SQL server 2005:</p>
<pre><code>ALTER SCHEMA NewSchama TRANSFER dbo.Table1
</code></pre>
<p>But how can i check and/or alter stored procedures that use the old schema name?</p>
<p>Sorry: I mean:
There are stored procedures that have the old schema name of the table in the sql of the stored procedure... How can i edit all the stored procedures that have the dbo.Table1 in the body of the procedure...</p>
|
[
{
"answer_id": 45588910,
"author": "Luqman Cheema",
"author_id": 4411751,
"author_profile": "https://Stackoverflow.com/users/4411751",
"pm_score": 0,
"selected": false,
"text": "CREATE SCHEMA Reporting\n ALTER SCHEMA Reporting TRANSFER dbo.Reports \n ALTER SCHEMA 'newSchema' TRANSFER 'oldSchema'.'table'\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13262/"
] |
101,470
|
<p>Does anybody know if there is a feasible way on Windows XP to programmatically create and configure a user account so that after logging in from the console (no terminal services) a specific app is launched and the user is "locked" to that app ?</p>
<p>The user should be prevented from doing anything else with the system (e.g.: no ctrl+alt+canc, no ctrl+shift+esc, no win+e, no nothing).</p>
<p>As an added optional bonus the user should be logged off when the launched app is closed and/or crashes.</p>
<p>Any existing free tool, language or any mixture of them that gets the job done would be fine (batch, VB-script, C, C++, whatever)</p>
|
[
{
"answer_id": 483553,
"author": "Chris Becke",
"author_id": 27491,
"author_profile": "https://Stackoverflow.com/users/27491",
"pm_score": 2,
"selected": false,
"text": "[SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\taskmgr.exe]\nDebugger=\"A path to an exe file that will be run instead of taskmgr.exe\"\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18780/"
] |
101,487
|
<p>I have some code which collects points (consed integers) from a loop which looks something like this:</p>
<pre><code>(loop
for x from 1 to 100
for y from 100 downto 1
collect `(,x . ,y))
</code></pre>
<p>My question is, is it correct to use <code>`(,x . ,y)</code> in this situation?</p>
<p>Edit: This sample is not about generating a table of 100x100 items, the code here just illustrate the use of two loop variables and the consing of their values. I have edited the loop to make this clear. The actual loop I use depends on several other functions (and is part of one itself) so it made more sense to replace the calls with literal integers and to pull the loop out of the function.</p>
|
[
{
"answer_id": 101503,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 1,
"selected": false,
"text": "(cons x y)\n (defun genint (stop)\n (if (= stop 1) '(1)\n (append (genint (- stop 1)) (list stop))))\n\n(defun genpairs (x y)\n (let ((row (mapcar #'(lambda (y)\n (cons x y))\n (genint y))))\n (if (= x 0) row\n (append (genpairs (- x 1) y)\n row))))\n\n(genpairs 100 100)\n"
},
{
"answer_id": 101641,
"author": "dsm",
"author_id": 7780,
"author_profile": "https://Stackoverflow.com/users/7780",
"pm_score": 3,
"selected": false,
"text": "[1]> (time\n (progn\n (loop\n for x from 1 to 100000\n for y from 1 to 100000 do\n collect (cons x y))\n ()))\nWARNING: LOOP: missing forms after DO: permitted by CLtL2, forbidden by ANSI\n CL.\nReal time: 0.469 sec.\nRun time: 0.468 sec.\nSpace: 1609084 Bytes\nGC: 1, GC time: 0.015 sec.\nNIL\n[2]> (time\n (progn\n (loop\n for x from 1 to 100000\n for y from 1 to 100000 do\n collect `(,x . ,y)) ;`\n ()))\nWARNING: LOOP: missing forms after DO: permitted by CLtL2, forbidden by ANSI\n CL.\nReal time: 0.969 sec.\nRun time: 0.969 sec.\nSpace: 10409084 Bytes\nGC: 15, GC time: 0.172 sec.\nNIL\n[3]>\n"
},
{
"answer_id": 103205,
"author": "simon",
"author_id": 14143,
"author_profile": "https://Stackoverflow.com/users/14143",
"pm_score": 2,
"selected": false,
"text": "(loop for x from 1 to 100000\n for y from 1 to 100000 do\n collect `(,x . ,y))\n (loop for x from 1 to 100\n collecting (cons x x))\n (loop for x from 1 to 100 appending \n (loop for y from 1 to 100 collecting (cons x y)))\n (let ((list nil)) \n (dotimes (n 100) ;; 0 based count, you will have to add 1 to get 1 .. 100\n (dotimes (m 100) \n (push (cons n m) list)))\n (nreverse list))\n (defun iota (n &optional (start 0))\n (let ((end (+ n start)))\n (labels ((next (n)\n (when (< n end) \n (cons n (next (1+ n))))))\n (next start))))\n (defun iota (n &optional (start 0))\n (loop repeat n \n for i from start collecting i))\n (defun iota (n &optional (start 0))\n (labels ((next (i list)\n (if (>= i (+ n start))\n nil\n (next (1+ i) (cons i list)))))\n (next start nil)))\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101487",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7780/"
] |
101,497
|
<p>I have Flex Builder 3 installed on two Windows machines and the same project on both of them. On one computer, the CSS styles I defined are shown in design view; on the other computer they are not applied. Is there any reason why it might not work on one?</p>
|
[
{
"answer_id": 101503,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 1,
"selected": false,
"text": "(cons x y)\n (defun genint (stop)\n (if (= stop 1) '(1)\n (append (genint (- stop 1)) (list stop))))\n\n(defun genpairs (x y)\n (let ((row (mapcar #'(lambda (y)\n (cons x y))\n (genint y))))\n (if (= x 0) row\n (append (genpairs (- x 1) y)\n row))))\n\n(genpairs 100 100)\n"
},
{
"answer_id": 101641,
"author": "dsm",
"author_id": 7780,
"author_profile": "https://Stackoverflow.com/users/7780",
"pm_score": 3,
"selected": false,
"text": "[1]> (time\n (progn\n (loop\n for x from 1 to 100000\n for y from 1 to 100000 do\n collect (cons x y))\n ()))\nWARNING: LOOP: missing forms after DO: permitted by CLtL2, forbidden by ANSI\n CL.\nReal time: 0.469 sec.\nRun time: 0.468 sec.\nSpace: 1609084 Bytes\nGC: 1, GC time: 0.015 sec.\nNIL\n[2]> (time\n (progn\n (loop\n for x from 1 to 100000\n for y from 1 to 100000 do\n collect `(,x . ,y)) ;`\n ()))\nWARNING: LOOP: missing forms after DO: permitted by CLtL2, forbidden by ANSI\n CL.\nReal time: 0.969 sec.\nRun time: 0.969 sec.\nSpace: 10409084 Bytes\nGC: 15, GC time: 0.172 sec.\nNIL\n[3]>\n"
},
{
"answer_id": 103205,
"author": "simon",
"author_id": 14143,
"author_profile": "https://Stackoverflow.com/users/14143",
"pm_score": 2,
"selected": false,
"text": "(loop for x from 1 to 100000\n for y from 1 to 100000 do\n collect `(,x . ,y))\n (loop for x from 1 to 100\n collecting (cons x x))\n (loop for x from 1 to 100 appending \n (loop for y from 1 to 100 collecting (cons x y)))\n (let ((list nil)) \n (dotimes (n 100) ;; 0 based count, you will have to add 1 to get 1 .. 100\n (dotimes (m 100) \n (push (cons n m) list)))\n (nreverse list))\n (defun iota (n &optional (start 0))\n (let ((end (+ n start)))\n (labels ((next (n)\n (when (< n end) \n (cons n (next (1+ n))))))\n (next start))))\n (defun iota (n &optional (start 0))\n (loop repeat n \n for i from start collecting i))\n (defun iota (n &optional (start 0))\n (labels ((next (i list)\n (if (>= i (+ n start))\n nil\n (next (1+ i) (cons i list)))))\n (next start nil)))\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15525/"
] |
101,532
|
<p>When I run a Flex application in the debug flash player I get an exception pop up as soon as something unexpected happened. However when a customer uses the application he does not use the debug flash player. In this case he does not get an exception pop up, but he UI is not working.</p>
<p>So for supportability reasons, I would like to catch any exception that can happen anywhere in the Flex UI and present an error message in a Flex internal popup. By using Java I would just encapsulate the whole UI code in a try/catch block, but with MXML applications in Flex I do not know, where I could perform such a general try/catch.</p>
|
[
{
"answer_id": 101953,
"author": "Richard Szalay",
"author_id": 3603,
"author_profile": "https://Stackoverflow.com/users/3603",
"pm_score": 7,
"selected": true,
"text": "public class UncaughtErrorEventExample extends Sprite\n{\n public function UncaughtErrorEventExample()\n {\n loaderInfo.uncaughtErrorEvents.addEventListener(\n UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);\n }\n\n private function uncaughtErrorHandler(event:UncaughtErrorEvent):void\n {\n if (event.error is Error)\n {\n var error:Error = event.error as Error;\n // do something with the error\n }\n else if (event.error is ErrorEvent)\n {\n var errorEvent:ErrorEvent = event.error as ErrorEvent;\n // do something with the error\n }\n else\n {\n // a non-Error, non-ErrorEvent type was thrown and uncaught\n }\n }\n"
},
{
"answer_id": 2500361,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": " if(loaderInfo.hasOwnProperty(\"uncaughtErrorEvents\")){\n IEventDispatcher(loaderInfo[\"uncaughtErrorEvents\"]).addEventListener(\"uncaughtError\", uncaughtErrorHandler);\n }\n"
},
{
"answer_id": 3020206,
"author": "aaaidan",
"author_id": 26331,
"author_profile": "https://Stackoverflow.com/users/26331",
"pm_score": 2,
"selected": false,
"text": "try {\n loaderInfo.uncaughtErrorEvents.addEventListener(\"uncaughtError\", onUncaughtError);\n} catch (e:ReferenceError) {\n var spl:Array = Capabilities.version.split(\" \");\n var verSpl:Array = spl[1].split(\",\");\n\n if (int(verSpl[0]) >= 10 &&\n int(verSpl[1]) >= 1) {\n // This version is 10.1 or greater - we should have been able to listen for uncaught errors...\n d.warn(\"Unable to listen for uncaught error events, despite flash version: \" + Capabilities.version);\n }\n}\n"
},
{
"answer_id": 4994963,
"author": "neave",
"author_id": 581853,
"author_profile": "https://Stackoverflow.com/users/581853",
"pm_score": 2,
"selected": false,
"text": "sprite.root.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);\n event.preventDefault();\n private function onUncaughtError(event:UncaughtErrorEvent):void\n {\n event.preventDefault();\n // do something with this error\n }\n"
},
{
"answer_id": 5899108,
"author": "Rose",
"author_id": 466884,
"author_profile": "https://Stackoverflow.com/users/466884",
"pm_score": 2,
"selected": false,
"text": "loaderInfo.UncaughtErrorEvents, root.loaderInfo.UncaughtErrorEvents sprite.root.UncaughtErrorEvents"
},
{
"answer_id": 6597046,
"author": "Jefferson",
"author_id": 831644,
"author_profile": "https://Stackoverflow.com/users/831644",
"pm_score": 2,
"selected": false,
"text": " <?xml version=\"1.0\" encoding=\"utf-8\"?>\n<mx:Application xmlns:mx=\"http://www.adobe.com/2006/mxml\" addedToStage=\"application1_addedToStageHandler(event)\">\n <mx:Script>\n <![CDATA[\n import mx.events.FlexEvent;\n \n protected function application1_addedToStageHandler(event:Event):void{ \n if(loaderInfo.hasOwnProperty(\"uncaughtErrorEvents\")){\n IEventDispatcher(loaderInfo[\"uncaughtErrorEvents\"]).addEventListener(\"uncaughtError\", uncaughtErrorHandler);\n }\n \n sdk.text = \"Flex \" + mx_internal::VERSION;\n }\n \n private function uncaughtErrorHandler(e:*):void{\n e.preventDefault();\n \n var s:String;\n\n if (e.error is Error)\n {\n var error:Error = e.error as Error;\n s = \"Uncaught Error: \" + error.errorID + \", \" + error.name + \", \" + error.message;\n }\n else\n {\n var errorEvent:ErrorEvent = e.error as ErrorEvent;\n s = \"Uncaught ErrorEvent: \" + errorEvent.text;\n }\n \n msg.text = s;\n }\n \n private function unCaught():void\n {\n var foo:String = null;\n trace(foo.length);\n }\n ]]>\n </mx:Script>\n <mx:VBox>\n <mx:Label id=\"sdk\" fontSize=\"18\"/>\n <mx:Button y=\"50\" label=\"UnCaught Error\" click=\"unCaught();\" />\n <mx:TextArea id=\"msg\" width=\"180\" height=\"70\"/>\n </mx:VBox>\n</mx:Application>\n"
},
{
"answer_id": 28863039,
"author": "Pablo",
"author_id": 3242467,
"author_profile": "https://Stackoverflow.com/users/3242467",
"pm_score": 0,
"selected": false,
"text": "loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);\n\nprivate function onUncaughtError(e:UncaughtErrorEvent):void\n{\n // Do something with your error.\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101532",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7524/"
] |
101,533
|
<p>I have created a C# class file by using a XSD-file as an input. One of my properties look like this:</p>
<pre><code> private System.DateTime timeField;
[System.Xml.Serialization.XmlElementAttribute(DataType="time")]
public System.DateTime Time {
get {
return this.timeField;
}
set {
this.timeField = value;
}
}
</code></pre>
<p>When serialized, the contents of the file now looks like this:</p>
<pre><code><Time>14:04:02.1661975+02:00</Time>
</code></pre>
<p>Is it possible, with XmlAttributes on the property, to have it render without the milliseconds and the GMT-value like this?</p>
<pre><code><Time>14:04:02</Time>
</code></pre>
<p>Is this possible, or do i need to hack together some sort of xsl/xpath-replace-magic after the class has been serialized?</p>
<p>It is not a solution to changing the object to String, because it is used like a DateTime in the rest of the application and allows us to create an xml-representation from an object by using the XmlSerializer.Serialize() method.</p>
<p>The reason I need to remove the extra info from the field is that the receiving system does not conform to the w3c-standards for the time datatype.</p>
|
[
{
"answer_id": 101667,
"author": "Matt Howells",
"author_id": 16881,
"author_profile": "https://Stackoverflow.com/users/16881",
"pm_score": 5,
"selected": false,
"text": "[XmlElement(DataType=\"string\",ElementName=\"Time\")]\npublic String TimeString\n{\n get { return this.timeField.ToString(\"yyyy-MM-dd\"); }\n set { this.timeField = DateTime.ParseExact(value, \"yyyy-MM-dd\", CultureInfo.InvariantCulture); }\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2257/"
] |
101,536
|
<p>I am looking for a drop-down JavaScript menu.</p>
<p>It should be the simplest and most elegant accessible menu that works in IE6 and Firefox 2 also.
It would be fine if it worked on an unnumbered list (<code>ul</code>) so the user can use the page without JavaScript support.</p>
<p>Which one do you recommend and where can I find the code to such a menu?</p>
|
[
{
"answer_id": 101612,
"author": "Daniel Papasian",
"author_id": 7548,
"author_profile": "https://Stackoverflow.com/users/7548",
"pm_score": 2,
"selected": false,
"text": "\njQuery.fn.ddnav = function() {\n this.wrap(\"\");\n this.each(function() {\n var sel = document.createElement('select');\n jQuery(this).find(\"li.label, li a\").each(function() {\n jQuery(\"<option>\").val(this.href ? this.href : '').html(jQuery(this).html()).appendTo(sel);\n });\n jQuery(this).hide().after(sel);\n });\n this.parent().find(\"select\").after(\"<input type=\\\"button\\\" value=\\\"Go\\\">\");\n var callback = function(button) {\n var url = jQuery(button.target).parent(\"div\").find(\"select\").val();\n if(url.length)\n window.open(url, \"_self\")\n };\n this.parent().find(\"input[type='button']\").click(callback);\n this.parent().find(\"select\").change(callback);\n return this;\n};\n \n $(\"ul.dropdown_nav\").ddnav();\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18631/"
] |
101,540
|
<p>How do I get an element or element list by it's tag name. Take for example that I want all elements from <code><h1></h1></code>.
</p>
|
[
{
"answer_id": 101563,
"author": "Matthias Kestenholz",
"author_id": 317346,
"author_profile": "https://Stackoverflow.com/users/317346",
"pm_score": 4,
"selected": true,
"text": "Array.from(document.getElementsByTagName('a')) Array.from(document.querySelectorAll('a')) Array.from()"
},
{
"answer_id": 161331,
"author": "Grant Hutchins",
"author_id": 6304,
"author_profile": "https://Stackoverflow.com/users/6304",
"pm_score": 2,
"selected": false,
"text": "$$() $$()"
},
{
"answer_id": 173372,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 1,
"selected": false,
"text": "var test = document.getElementsByTagName('a');\nalert(test.length); // n\ndocument.body.appendChild(document.createElement('a'));\nalert(test.length); // n + 1\n"
},
{
"answer_id": 12591490,
"author": "Trython",
"author_id": 1698619,
"author_profile": "https://Stackoverflow.com/users/1698619",
"pm_score": 1,
"selected": false,
"text": "$$(tag-name)[n]"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6078/"
] |
101,541
|
<p>I've got an application that uses a hibernate(annotations)/mysql combination for ORM. In that application, I got an entity with a Date field. I'm looking for a way to select on that date within a time range (so <code>hh:mm:ss</code> without the date part). </p>
<p>In MySQL there's a function <code>TIME(expression)</code> that can extract the time part and use that in the where clause, but that does not seem to be available in Hibernate without switching to native queries. Is there an option in hibernate to do this, or should I loop through the results in java and do the comparison there? Would this be much slower as the MySQL solution, since that would not use indexes anyway?</p>
|
[
{
"answer_id": 101615,
"author": "Sietse",
"author_id": 6400,
"author_profile": "https://Stackoverflow.com/users/6400",
"pm_score": 2,
"selected": false,
"text": "second(...), minute(...), hour(...), day(...), month(...), year(...)"
},
{
"answer_id": 101637,
"author": "Adam Hawkes",
"author_id": 6703,
"author_profile": "https://Stackoverflow.com/users/6703",
"pm_score": 1,
"selected": false,
"text": "Criteria criteria = session.createCriteria(MyTable.class);\ncriteria.add( \n Expression.sql(\n \"TIME( {alias}.my_date, 'hh:mm:ss') >= :1\", \n dateRangeMin, \n new StringType()\n )\n);\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3197/"
] |
101,569
|
<p>I need to write a module to detect similar documents. I have read many papers of fingerprints of documents techniques and others, but I do not know how to write code or implement such a solution. The algorithm should work for Chinese, Japanese, English and German language or be language independent. How can I accomplish this?</p>
|
[
{
"answer_id": 101605,
"author": "nosklo",
"author_id": 17160,
"author_profile": "https://Stackoverflow.com/users/17160",
"pm_score": 3,
"selected": false,
"text": "get_close_matches() >>> get_close_matches('appel', ['ape', 'apple', 'peach', 'puppy'])\n['apple', 'ape']\n"
},
{
"answer_id": 108974,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 4,
"selected": false,
"text": "from reverend.thomas import Bayes\nguesser = Bayes()\nguesser.train('french','La souris est rentrée dans son trou.')\nguesser.train('english','my tailor is rich.')\nguesser.train('french','Je ne sais pas si je viendrai demain.')\nguesser.train('english','I do not plan to update my website soon.')\n\n>>> print guesser.guess('Jumping out of cliffs it not a good idea.')\n[('english', 0.99990000000000001), ('french', 9.9999999999988987e-005)]\n\n>>> print guesser.guess('Demain il fera très probablement chaud.')\n[('french', 0.99990000000000001), ('english', 9.9999999999988987e-005)]\n"
},
{
"answer_id": 448554,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "def jaccard_similarity(doc1, doc2):\n a = sets(doc1.split())\n b = sets(doc2.split())\n similarity = float(len(a.intersection(b))*1.0/len(a.union(b))) #similarity belongs to [0,1] 1 means its exact replica.\n return similarity\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17451/"
] |
101,574
|
<p>I want a list of hyperlinks on a basic html page, which point to files on our corporate intranet.</p>
<p>When a user clicks the link, I want the file to open.
They are excel spreadsheets, and this is an intranet environment, so I can count on everyone having Excel installed.</p>
<p>I've tried two things:</p>
<ol>
<li>The obvious and simple thing:</li>
</ol>
<pre class="lang-html prettyprint-override"><code><a href="file://server/directory/file.xlsx">Click me!</a>
</code></pre>
<ol start="2">
<li>A <a href="/questions/tagged/vbscript" class="post-tag" title="show questions tagged 'vbscript'" rel="tag">vbscript</a> option that I found in a Google search:</li>
</ol>
<pre class="lang-html prettyprint-override"><code><HTML>
<HEAD>
<SCRIPT LANGUAGE=VBScript>
Dim objExcel
Sub Btn1_onclick()
call OpenWorkbook("\\server\directory\file.xlsx")
End Sub
Sub OpenWorkbook(strLocation)
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = true
objExcel.Workbooks.Open strLocation
objExcel.UserControl = true
End Sub
</SCRIPT>
<TITLE>Launch Excel</Title>
</HEAD>
<BODY>
<INPUT TYPE=BUTTON NAME=Btn1 VALUE="Open Excel File">
</BODY>
</HTML>
</code></pre>
<p>I know this is a very basic question, but I would appreciate any help I can get.</p>
<p><strong><em>Edit: Any suggestions that work in both IE and Firefox?</em></strong></p>
|
[
{
"answer_id": 101586,
"author": "diciu",
"author_id": 2811,
"author_profile": "https://Stackoverflow.com/users/2811",
"pm_score": 2,
"selected": false,
"text": "<a href=\"file://server/directory/file.xlsx\" target=\"_blank\">"
},
{
"answer_id": 101608,
"author": "Sam Reynolds",
"author_id": 9192,
"author_profile": "https://Stackoverflow.com/users/9192",
"pm_score": 1,
"selected": false,
"text": "<a href=\"file:///server/directory/file.xlsx\">Click me!</a>\n"
},
{
"answer_id": 101660,
"author": "David Heggie",
"author_id": 4309,
"author_profile": "https://Stackoverflow.com/users/4309",
"pm_score": 5,
"selected": true,
"text": "<a href=\"file://///SERVER/directory/file.ext\">file.ext</a>\n"
},
{
"answer_id": 101714,
"author": "Orion Adrian",
"author_id": 7756,
"author_profile": "https://Stackoverflow.com/users/7756",
"pm_score": 0,
"selected": false,
"text": "file:// fileserver://"
},
{
"answer_id": 70994151,
"author": "Roger Dueck",
"author_id": 1488762,
"author_profile": "https://Stackoverflow.com/users/1488762",
"pm_score": 0,
"selected": false,
"text": "<a href=\"smb://server/location\">open file</a>\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/672/"
] |
101,597
|
<p>Let's say I have the following HTML:</p>
<pre><code><table id="foo">
<th class="sortasc">Header</th>
</table>
<table id="bar">
<th class="sortasc">Header</th>
</table>
</code></pre>
<p>I know that I can do the following to get all of the <strong>th</strong> elements that have class="sortasc"</p>
<pre><code>$$('th.sortasc').each()
</code></pre>
<p>However that gives me the <strong>th</strong> elements from both table <em>foo</em> and table <em>bar</em>.</p>
<p>How can I tell it to give me just the th elements from table <em>foo</em>?</p>
|
[
{
"answer_id": 101762,
"author": "levik",
"author_id": 4465,
"author_profile": "https://Stackoverflow.com/users/4465",
"pm_score": 2,
"selected": false,
"text": "var table = document.getElementById('tableId');\nvar headers = table.getElementsByTagName('th');\nvar headersIWant = [];\nfor (var i = 0; i < headers.length; i++) {\n if ((' ' + headers[i].className + ' ').indexOf(' sortasc ') >= 0) {\n headersIWant.push(headers[i]);\n }\n}\nreturn headersIWant;\n"
},
{
"answer_id": 102666,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 0,
"selected": false,
"text": "<table id=\"foo\">\n <th class=\"sortasc\">Header</th>\n <tr><td>\n <table id=\"nestedFoo\">\n <th class=\"sortasc\">Nested Header</th>\n </table>\n </td></tr>\n</table>\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101597",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/305/"
] |
101,604
|
<p>I decided to try <a href="http://www.screwturn.eu/" rel="nofollow noreferrer">http://www.screwturn.eu/</a> wiki as a code snippet storage utility. So far I am very impressed, but what irkes me is that when I copy paste my code that I want to save, '<'s and '[' (<a href="http://en.wikipedia.org/wiki/Character_encodings_in_HTML#Character_references" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Character_encodings_in_HTML#Character_references</a>) invariably screw up the output as the wiki interprets them as either wiki or HTML tags.</p>
<p>Does anyone know a way around this? Or failing that, know of a simple utility that would take C++ code and convert it to HTML safe code?</p>
|
[
{
"answer_id": 101650,
"author": "oglester",
"author_id": 2017,
"author_profile": "https://Stackoverflow.com/users/2017",
"pm_score": 0,
"selected": false,
"text": "> <"
},
{
"answer_id": 101651,
"author": "The Brawny Man",
"author_id": 11936,
"author_profile": "https://Stackoverflow.com/users/11936",
"pm_score": 0,
"selected": false,
"text": "<pre>\n if (foo <= bar) {\n do_something();\n }\n</pre>\n"
},
{
"answer_id": 101653,
"author": "Chris M.",
"author_id": 6747,
"author_profile": "https://Stackoverflow.com/users/6747",
"pm_score": 0,
"selected": false,
"text": "<esc></esc>"
},
{
"answer_id": 107577,
"author": "bk1e",
"author_id": 8090,
"author_profile": "https://Stackoverflow.com/users/8090",
"pm_score": -1,
"selected": false,
"text": "< > < > unsigned int maskedValue = value&mask;\n &mask; & & [ ] ??( ??)"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101604",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18664/"
] |
101,647
|
<p>How do you schedule a task in Windows XP to run when you shutdown windows. Such that I want to run a simple command line program I wrote in c# everytime I shut down windows. There doesn't seem to be an option in scheduled tasks to perform this task when my computer shuts down.</p>
|
[
{
"answer_id": 101679,
"author": "Neil Neyman",
"author_id": 3240,
"author_profile": "https://Stackoverflow.com/users/3240",
"pm_score": 3,
"selected": false,
"text": "c:\\directory\\myProgram.exe\nC:\\WINDOWS\\system32\\shutdown.exe -s -f -t 0\n"
},
{
"answer_id": 45770722,
"author": "Matthew Smith",
"author_id": 8330563,
"author_profile": "https://Stackoverflow.com/users/8330563",
"pm_score": 2,
"selected": false,
"text": "c:\\windows\\system32\\shutdown -s -f -t 00\n"
},
{
"answer_id": 65984406,
"author": "Ste",
"author_id": 8262102,
"author_profile": "https://Stackoverflow.com/users/8262102",
"pm_score": 2,
"selected": false,
"text": "<QueryList>\n <Query Id=\"0\" Path=\"System\">\n <Select Path=\"System\">\n *[System[Provider[@Name='User32'] and (Level=4 or Level=0) and (EventID=1074)]]\n and \n *[EventData[Data[@Name='param5'] and (Data='power off')]]\n </Select>\n </Query>\n</QueryList>\n - <Event xmlns=\"http://schemas.microsoft.com/win/2004/08/events/event\">\n- <System>\n <Provider Name=\"User32\" Guid=\"{xxxxx-xxxxxxxxxxx-xxxxxxxxxxxxxx-x-x}\" EventSourceName=\"User32\" /> \n <EventID Qualifiers=\"32768\">1074</EventID> \n <Version>0</Version> \n <Level>4</Level> \n <Task>0</Task> \n <Opcode>0</Opcode> \n <Keywords>0x8080000000000000</Keywords> \n <TimeCreated SystemTime=\"2021-01-19T18:23:32.6133523Z\" /> \n <EventRecordID>26696</EventRecordID> \n <Correlation /> \n <Execution ProcessID=\"1056\" ThreadID=\"11288\" /> \n <Channel>System</Channel> \n <Computer>DESKTOP-REDACTED</Computer> \n <Security UserID=\"x-x-x-xx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxx\" /> \n </System>\n- <EventData>\n <Data Name=\"param1\">Explorer.EXE</Data> \n <Data Name=\"param2\">DESKTOP-REDACTED</Data> \n <Data Name=\"param3\">Other (Unplanned)</Data> \n <Data Name=\"param4\">0x0</Data> \n <Data Name=\"param5\">power off</Data> \n <Data Name=\"param6\" /> \n <Data Name=\"param7\">DESKTOP-REDACTED\\username</Data> \n </EventData>\n </Event>\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6204/"
] |
101,664
|
<p>Is there a setting in ReSharper 4 (or even Visual Studio itself...) that forces a warning if I forget to wrap code in a <code>using</code> block, or omit the proper Dispose call in a <code>finally</code> block?</p>
|
[
{
"answer_id": 102576,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 2,
"selected": false,
"text": "Dispose() DEBUG"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1853/"
] |
101,693
|
<p>I get an error everytime I upload my webapp to the provider. Because of the customErrors mode, all I see is the default "Runtime error" message, instructing me to turn off customErrors to view more about the error.</p>
<p>Exasperated, I've set my web.config to look like this:</p>
<pre><code><?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
</code></pre>
<p>And still, all I get is the stupid remote errors page with no useful info on it.
What else can I do to turn customErrors OFF ?!</p>
|
[
{
"answer_id": 352626,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 8,
"selected": true,
"text": "<system.web> <deployment retail=\"true\" />\n <deployment retail=\"false\" />\n machine.config %windir%\\Microsoft.NET\\Framework\\[version]\\config\\machine.config\n %windir%\\Microsoft.NET\\Framework64\\[version]\\config\\machine.config \n"
},
{
"answer_id": 423873,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": " <customErrors mode=\"RemoteOnly\" defaultRedirect=\"GenericErrorPage.htm\">\n <error statusCode=\"403\" redirect=\"NoAccess.htm\" />\n <error statusCode=\"404\" redirect=\"FileNotFound.htm\" />\n </customErrors>\n"
},
{
"answer_id": 891429,
"author": "Cyberherbalist",
"author_id": 16964,
"author_profile": "https://Stackoverflow.com/users/16964",
"pm_score": 6,
"selected": false,
"text": "<system.web>\n <customErrors mode=\"Off\"/>\n</system.web>\n <customErrors mode=\"Off\"/>\n"
},
{
"answer_id": 7974132,
"author": "Rubens Farias",
"author_id": 113794,
"author_profile": "https://Stackoverflow.com/users/113794",
"pm_score": 3,
"selected": false,
"text": "C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\web.config <customErrors mode=\"Off\" />"
},
{
"answer_id": 30345352,
"author": "Serj Sagan",
"author_id": 550975,
"author_profile": "https://Stackoverflow.com/users/550975",
"pm_score": 3,
"selected": false,
"text": "web.config <configuration> \n <system.webServer> \n <httpErrors existingResponse=\"PassThrough\"/> \n </system.webServer> \n<configuration>\n"
},
{
"answer_id": 39451354,
"author": "Rich Hildebrand",
"author_id": 1854364,
"author_profile": "https://Stackoverflow.com/users/1854364",
"pm_score": 0,
"selected": false,
"text": "<compilation xdt:Transform=\"RemoveAttributes(debug)\" />\n"
},
{
"answer_id": 40089265,
"author": "EM0",
"author_id": 1536933,
"author_profile": "https://Stackoverflow.com/users/1536933",
"pm_score": 0,
"selected": false,
"text": "Application_Error Server.ClearError();\nResponse.Redirect(\"/Home/Error\");\n customErrors=\"On\""
},
{
"answer_id": 42647751,
"author": "Dongolo Jeno",
"author_id": 5525054,
"author_profile": "https://Stackoverflow.com/users/5525054",
"pm_score": 3,
"selected": false,
"text": "<httpErrors errorMode=\"Custom\" existingResponse=\"Replace\">\n <remove statusCode=\"404\" />\n <remove statusCode=\"500\" />\n <error statusCode=\"404\" responseMode=\"ExecuteURL\" path=\"/Error/NotFound\" />\n <error statusCode=\"500\" responseMode=\"ExecuteURL\" path=\"/Error/Internal\" />\n</httpErrors>\n"
},
{
"answer_id": 43383794,
"author": "Niraj Trivedi",
"author_id": 3839344,
"author_profile": "https://Stackoverflow.com/users/3839344",
"pm_score": 0,
"selected": false,
"text": "Exception type: HttpException \nException message: The target principal name is incorrect. Cannot generate SSPI context.\nat System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app)\nat System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)\nat System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)\nat System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)\nat System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)\n\nThe target principal name is incorrect. Cannot generate SSPI context.\n"
},
{
"answer_id": 64405451,
"author": "J. Gwinner",
"author_id": 5937168,
"author_profile": "https://Stackoverflow.com/users/5937168",
"pm_score": -1,
"selected": false,
"text": "display_errors: On\n display_startup_errors: On\n"
},
{
"answer_id": 69007785,
"author": "kaung htet naing",
"author_id": 1157593,
"author_profile": "https://Stackoverflow.com/users/1157593",
"pm_score": 0,
"selected": false,
"text": "<log4net debug=\"true\">\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3263/"
] |
101,708
|
<p>In VB.net I'm using the TcpClient to retrieve a string of data. I'm constantly checking the .Connected property to verify if the client is connected but even if the client disconnects this still returns true. What can I use as a workaround for this?</p>
<p>This is a stripped down version of my current code:</p>
<pre><code>Dim client as TcpClient = Nothing
client = listener.AcceptTcpClient
do while client.connected = true
dim stream as networkStream = client.GetStream()
dim bytes(1024) as byte
dim numCharRead as integer = stream.Read(bytes,0,bytes.length)
dim strRead as string = System.Text.Encoding.ASCII.GetString(bytes,0,i)
loop
</code></pre>
<p>I would have figured at least the GetStream() call would throw an exception if the client was disconnected but I've closed the other app and it still doesn't... </p>
<p>Thanks. </p>
<p><strong>EDIT</strong>
Polling the Client.Available was suggested but that doesn't solve the issue. If the client is not 'acutally' connected available just returns 0.</p>
<p>The key is that I'm trying to allow the connection to stay open and allow me to receive data multiple times over the same socket connection. </p>
|
[
{
"answer_id": 3783019,
"author": "Sean P",
"author_id": 240405,
"author_profile": "https://Stackoverflow.com/users/240405",
"pm_score": 1,
"selected": false,
"text": "if (client.Client.Poll(0, SelectMode.SelectRead))\n{\n byte[] checkConn = new byte[1];\n\n if (client.Client.Receive(checkConn, SocketFlags.Peek) == 0)\n throw new IOException();\n}\n"
},
{
"answer_id": 54497655,
"author": "MJ-",
"author_id": 11006514,
"author_profile": "https://Stackoverflow.com/users/11006514",
"pm_score": -1,
"selected": false,
"text": "Sub Ping()\n Send(\"Stil here?\")\nEnd Sub\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77830/"
] |
101,709
|
<p>I am implementing a comment control that allows a person to select comments and have them sent to specified departments. The email needs to be formatted in a specific way, and I was wondering what the best way to do this would be.</p>
<p>Should I just hard code all of the style information into one massive method, or should I try and create a separate file and read it in, and then replace certain tags with the relevant information?</p>
|
[
{
"answer_id": 101760,
"author": "Matt Howells",
"author_id": 16881,
"author_profile": "https://Stackoverflow.com/users/16881",
"pm_score": 0,
"selected": false,
"text": "<p>Dear |FIRST_NAME|,\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101709",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12096/"
] |
101,718
|
<p>What is the best way to draw a variable width line without using glLineWidth?
Just draw a rectangle?
Various parallel lines?
None of the above?</p>
|
[
{
"answer_id": 102156,
"author": "Ozgur Ozcitak",
"author_id": 976,
"author_profile": "https://Stackoverflow.com/users/976",
"pm_score": 4,
"selected": false,
"text": "// Draws a line between (x1,y1) - (x2,y2) with a start thickness of t1 and\n// end thickness t2.\nvoid DrawLine(float x1, float y1, float x2, float y2, float t1, float t2)\n{\n float angle = atan2(y2 - y1, x2 - x1);\n float t2sina1 = t1 / 2 * sin(angle);\n float t2cosa1 = t1 / 2 * cos(angle);\n float t2sina2 = t2 / 2 * sin(angle);\n float t2cosa2 = t2 / 2 * cos(angle);\n\n glBegin(GL_TRIANGLES);\n glVertex2f(x1 + t2sina1, y1 - t2cosa1);\n glVertex2f(x2 + t2sina2, y2 - t2cosa2);\n glVertex2f(x2 - t2sina2, y2 + t2cosa2);\n glVertex2f(x2 - t2sina2, y2 + t2cosa2);\n glVertex2f(x1 - t2sina1, y1 + t2cosa1);\n glVertex2f(x1 + t2sina1, y1 - t2cosa1);\n glEnd();\n}\n"
},
{
"answer_id": 3314379,
"author": "bobobobo",
"author_id": 111307,
"author_profile": "https://Stackoverflow.com/users/111307",
"pm_score": 3,
"selected": false,
"text": "width1 width2 // find line between p1 and p2\nVector p1p2 = p2 - p1 ;\n\n// find a perpendicular\nVector perp = p1p2.perpendicular().normalize()\n\n// Walk from p1 to A\nVector A = p1 + perp*(width1/2)\nVector B = p1 - perp*(width1/2)\n\nVector C = p2 - perp*(width2/2)\nVector D = p2 - perp*(width2/2)\n\n// wind triangles\nTriangle( A, B, D )\nTriangle( B, D, C )\n"
},
{
"answer_id": 4121312,
"author": "jpap",
"author_id": 500309,
"author_profile": "https://Stackoverflow.com/users/500309",
"pm_score": 2,
"selected": false,
"text": "(x1,y1) -> (x2,y2) width (0., -0.5) -> (1., 0.5) glTranslatef(...) (x1,y1) glScalef(...) length width length = sqrt( (x2-x1)^2 + (y2-y1)^2 ) glRotatef(...) angle angle = atan2(y2-y1, x2-x1) GL_TRIANGLE_STRIP glPushMatrix() glPopMatrix()"
},
{
"answer_id": 5877446,
"author": "House",
"author_id": 737147,
"author_profile": "https://Stackoverflow.com/users/737147",
"pm_score": 2,
"selected": false,
"text": "import java.awt.Color;\nimport org.lwjgl.opengl.GL11;\nimport org.lwjgl.util.vector.Vector2f;\npublic static void DrawThickLine(int startScreenX, int startScreenY, int endScreenX, int endScreenY, Color color, float alpha, float width) {\n\n Vector2f start = new Vector2f(startScreenX, startScreenY);\n Vector2f end = new Vector2f(endScreenX, endScreenY);\n\n float dx = startScreenX - endScreenX;\n float dy = startScreenY - endScreenY;\n\n Vector2f rightSide = new Vector2f(dy, -dx);\n if (rightSide.length() > 0) {\n rightSide.normalise();\n rightSide.scale(width / 2);\n }\n Vector2f leftSide = new Vector2f(-dy, dx);\n if (leftSide.length() > 0) {\n leftSide.normalise();\n leftSide.scale(width / 2);\n }\n\n Vector2f one = new Vector2f();\n Vector2f.add(leftSide, start, one);\n\n Vector2f two = new Vector2f();\n Vector2f.add(rightSide, start, two);\n\n Vector2f three = new Vector2f();\n Vector2f.add(rightSide, end, three);\n\n Vector2f four = new Vector2f();\n Vector2f.add(leftSide, end, four);\n\n GL11.glBegin(GL11.GL_QUADS);\n GL11.glColor4f(color.getRed(), color.getGreen(), color.getBlue(), alpha);\n GL11.glVertex3f(one.x, one.y, 0);\n GL11.glVertex3f(two.x, two.y, 0);\n GL11.glVertex3f(three.x, three.y, 0);\n GL11.glVertex3f(four.x, four.y, 0);\n GL11.glColor4f(1, 1, 1, 1);\n GL11.glEnd();\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101718",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12423/"
] |
101,742
|
<p>I have a Google App Engine app - <a href="http://mylovelyapp.appspot.com/" rel="noreferrer">http://mylovelyapp.appspot.com/</a>
It has a page - mylovelypage</p>
<p>For the moment, the page just does <code>self.response.out.write('OK')</code></p>
<p>If I run the following Python at my computer:</p>
<pre><code>import urllib2
f = urllib2.urlopen("http://mylovelyapp.appspot.com/mylovelypage")
s = f.read()
print s
f.close()
</code></pre>
<p>it prints "OK"</p>
<p>the problem is if I add <code>login:required</code> to this page in the app's yaml</p>
<p>then this prints out the HTML of the Google Accounts login page</p>
<p>I've tried "normal" authentication approaches. e.g.</p>
<pre><code>passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(None,
uri='http://mylovelyapp.appspot.com/mylovelypage',
user='billy.bob@gmail.com',
passwd='billybobspasswd')
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
</code></pre>
<p>But it makes no difference - I still get the login page's HTML back.</p>
<p>I've tried <a href="http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html" rel="noreferrer">Google's ClientLogin auth API</a>, but I can't get it to work.</p>
<pre><code>h = httplib2.Http()
auth_uri = 'https://www.google.com/accounts/ClientLogin'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
myrequest = "Email=%s&Passwd=%s&service=ah&source=DALELANE-0.0" % ("billy.bob@gmail.com", "billybobspassword")
response, content = h.request(auth_uri, 'POST', body=myrequest, headers=headers)
if response['status'] == '200':
authtok = re.search('Auth=(\S*)', content).group(1)
headers = {}
headers['Authorization'] = 'GoogleLogin auth=%s' % authtok.strip()
headers['Content-Length'] = '0'
response, content = h.request("http://mylovelyapp.appspot.com/mylovelypage",
'POST',
body="",
headers=headers)
while response['status'] == "302":
response, content = h.request(response['location'], 'POST', body="", headers=headers)
print content
</code></pre>
<p>I do seem to be able to get some token correctly, but attempts to use it in the header when I call 'mylovelypage' still just return me the login page's HTML. :-( </p>
<p>Can anyone help, please?</p>
<p>Could I use the <a href="http://code.google.com/p/gdata-python-client/" rel="noreferrer">GData client library</a> to do this sort of thing? From
what I've read, I think it should be able to access App Engine apps,
but I haven't been any more successful at getting the authentication working for App Engine stuff there either </p>
<p>Any pointers to samples, articles, or even just keywords I should be
searching for to get me started, would be very much appreciated.</p>
<p>Thanks!</p>
|
[
{
"answer_id": 103410,
"author": "dalelane",
"author_id": 477,
"author_profile": "https://Stackoverflow.com/users/477",
"pm_score": 5,
"selected": false,
"text": "import os\nimport urllib\nimport urllib2\nimport cookielib\n\nusers_email_address = \"billy.bob@gmail.com\"\nusers_password = \"billybobspassword\"\n\ntarget_authenticated_google_app_engine_uri = 'http://mylovelyapp.appspot.com/mylovelypage'\nmy_app_name = \"yay-1.0\"\n\n\n\n# we use a cookie to authenticate with Google App Engine\n# by registering a cookie handler here, this will automatically store the \n# cookie returned when we use urllib2 to open http://currentcost.appspot.com/_ah/login\ncookiejar = cookielib.LWPCookieJar()\nopener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))\nurllib2.install_opener(opener)\n\n#\n# get an AuthToken from Google accounts\n#\nauth_uri = 'https://www.google.com/accounts/ClientLogin'\nauthreq_data = urllib.urlencode({ \"Email\": users_email_address,\n \"Passwd\": users_password,\n \"service\": \"ah\",\n \"source\": my_app_name,\n \"accountType\": \"HOSTED_OR_GOOGLE\" })\nauth_req = urllib2.Request(auth_uri, data=authreq_data)\nauth_resp = urllib2.urlopen(auth_req)\nauth_resp_body = auth_resp.read()\n# auth response includes several fields - we're interested in \n# the bit after Auth= \nauth_resp_dict = dict(x.split(\"=\")\n for x in auth_resp_body.split(\"\\n\") if x)\nauthtoken = auth_resp_dict[\"Auth\"]\n\n#\n# get a cookie\n# \n# the call to request a cookie will also automatically redirect us to the page\n# that we want to go to\n# the cookie jar will automatically provide the cookie when we reach the \n# redirected location\n\n# this is where I actually want to go to\nserv_uri = target_authenticated_google_app_engine_uri\n\nserv_args = {}\nserv_args['continue'] = serv_uri\nserv_args['auth'] = authtoken\n\nfull_serv_uri = \"http://mylovelyapp.appspot.com/_ah/login?%s\" % (urllib.urlencode(serv_args))\n\nserv_req = urllib2.Request(full_serv_uri)\nserv_resp = urllib2.urlopen(serv_req)\nserv_resp_body = serv_resp.read()\n\n# serv_resp_body should contain the contents of the \n# target_authenticated_google_app_engine_uri page - as we will have been \n# redirected to that page automatically \n#\n# to prove this, I'm just gonna print it out\nprint serv_resp_body\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/477/"
] |
101,752
|
<p>I used <code>git pull</code> and had a merge conflict:</p>
<pre><code>unmerged: some_file.txt
You are in the middle of a conflicted merge.
</code></pre>
<p>How do I abandon my changes to the file and keep only the pulled changes?</p>
|
[
{
"answer_id": 101773,
"author": "David Precious",
"author_id": 4040,
"author_profile": "https://Stackoverflow.com/users/4040",
"pm_score": 7,
"selected": false,
"text": "git reset git revert svn revert git revert git reset svn revert"
},
{
"answer_id": 102309,
"author": "Pat Notz",
"author_id": 825,
"author_profile": "https://Stackoverflow.com/users/825",
"pm_score": 11,
"selected": false,
"text": "pull HEAD HEAD^ git reset --hard HEAD\n git pull --strategy=theirs remote_branch\n git fetch origin\ngit reset --hard origin\n"
},
{
"answer_id": 107860,
"author": "CB Bailey",
"author_id": 19563,
"author_profile": "https://Stackoverflow.com/users/19563",
"pm_score": 6,
"selected": false,
"text": "git mergetool git show # common base:\ngit show :1:_widget.html.erb\n\n# 'ours'\ngit show :2:_widget.html.erb\n\n# 'theirs'\ngit show :3:_widget.html.erb\n git show :3:_widget.html.erb >_widget.html.erb\ngit add _widget.html.erb\n git checkout --theirs _widget.html.erb\n"
},
{
"answer_id": 2534968,
"author": "Carl",
"author_id": 13760,
"author_profile": "https://Stackoverflow.com/users/13760",
"pm_score": 11,
"selected": false,
"text": "git reset --merge git merge --abort git merge --abort git reset --merge MERGE_HEAD MERGE_HEAD git stash git stash pop"
},
{
"answer_id": 3240453,
"author": "Alain O'Dea",
"author_id": 154527,
"author_profile": "https://Stackoverflow.com/users/154527",
"pm_score": 4,
"selected": false,
"text": "git stash\ngit merge --abort\ngit stash pop\n"
},
{
"answer_id": 3269841,
"author": "Alain O'Dea",
"author_id": 154527,
"author_profile": "https://Stackoverflow.com/users/154527",
"pm_score": 4,
"selected": false,
"text": "git checkout git checkout --theirs _widget.html.erb\n"
},
{
"answer_id": 13352008,
"author": "ignis",
"author_id": 778990,
"author_profile": "https://Stackoverflow.com/users/778990",
"pm_score": 9,
"selected": false,
"text": "git merge --abort\n git merge --abort git merge --abort git reset --merge MERGE_HEAD"
},
{
"answer_id": 29412774,
"author": "Martin G",
"author_id": 3545094,
"author_profile": "https://Stackoverflow.com/users/3545094",
"pm_score": 6,
"selected": false,
"text": "git reset --merge git merge --abort git merge --abort git reset --merge MERGE_HEAD MERGE_HEAD git reset --merge git merge --abort git reset --merge"
},
{
"answer_id": 47026373,
"author": "Malcolm Boekhoff",
"author_id": 1388639,
"author_profile": "https://Stackoverflow.com/users/1388639",
"pm_score": 2,
"selected": false,
"text": "git reset *currentBranchIntoWhichYouMerged* -- *fileToBeReset*\n"
},
{
"answer_id": 49763085,
"author": "Nirav Mehta",
"author_id": 3875543,
"author_profile": "https://Stackoverflow.com/users/3875543",
"pm_score": 5,
"selected": false,
"text": "git reset --hard HEAD\ngit pull --strategy=theirs remote_branch\ngit fetch origin\ngit reset --hard origin\n git reset --hard HEAD\ngit reset --hard origin\n"
},
{
"answer_id": 62588633,
"author": "Hanzla Habib",
"author_id": 3946527,
"author_profile": "https://Stackoverflow.com/users/3946527",
"pm_score": 6,
"selected": false,
"text": "git merge --abort\n git reset --merge\n git reset --hard\n"
},
{
"answer_id": 65019148,
"author": "DARK_C0D3R",
"author_id": 8865579,
"author_profile": "https://Stackoverflow.com/users/8865579",
"pm_score": 6,
"selected": false,
"text": "git merge --abort\n git checkout --ours file1 file2 ...\n git checkout --theirs file1 file2 ...\n"
},
{
"answer_id": 67916591,
"author": "sastorsl",
"author_id": 2045924,
"author_profile": "https://Stackoverflow.com/users/2045924",
"pm_score": 3,
"selected": false,
"text": "git merge --abort # Checkout the topic branch\ngit checkout topic-branch-1\n\n# Create a _test_ branch on top of this\ngit checkout -b test\n\n# Attempt to merge master\ngit merge master\n\n# If it fails you can abandon the merge\ngit merge --abort\ngit checkout -\ngit branch -D test # we don't care about this branch really...\n # Checkout the topic branch\ngit checkout topic-branch-1\n\n# Create a _test_ branch on top of this\ngit checkout -b test\n\n# Attempt to merge master\ngit merge master\n\n# resolve conflicts, run it through tests, etc\n# then\ngit commit <conflict-resolving>\n\n# You *could* now even create a separate test branch on top of master\n# and see if you are able to merge\ngit checkout master\ngit checkout -b master-test\ngit merge test\n"
},
{
"answer_id": 68576346,
"author": "Daniel",
"author_id": 11952668,
"author_profile": "https://Stackoverflow.com/users/11952668",
"pm_score": 4,
"selected": false,
"text": "git checkout -f master git checkout side-branch"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18666/"
] |
101,754
|
<p>We are working on an <a href="http://en.wikipedia.org/wiki/S60_%28software_platform%29" rel="noreferrer">S60</a> version and this platform has a nice Python API..</p>
<p>However, there is nothing official about Python on Android, but since <a href="http://en.wikipedia.org/wiki/Jython" rel="noreferrer">Jython</a> exists, is there a way to let the snake and the robot work together??</p>
|
[
{
"answer_id": 973765,
"author": "unmounted",
"author_id": 11596,
"author_profile": "https://Stackoverflow.com/users/11596",
"pm_score": 8,
"selected": false,
"text": "import android\ndroid = android.Android()\ncode = droid.scanBarcode()\nisbn = int(code['result']['SCAN_RESULT'])\nurl = \"http://books.google.com?q=%d\" % isbn\ndroid.startActivity('android.intent.action.VIEW', url)\n"
},
{
"answer_id": 9773282,
"author": "Carl Smith",
"author_id": 1253428,
"author_profile": "https://Stackoverflow.com/users/1253428",
"pm_score": 6,
"selected": false,
"text": "android Android from android import Android\n\ndroid = Android()\ndroid.ttsSpeak('hello world') # example using the text to speech facade\n let droid = new Android();\ndroid.ttsSpeak(\"hello from js\");\n"
},
{
"answer_id": 27913916,
"author": "Anzel",
"author_id": 3849456,
"author_profile": "https://Stackoverflow.com/users/3849456",
"pm_score": 6,
"selected": false,
"text": "ui.widgets"
},
{
"answer_id": 41762766,
"author": "Adrian Stanculescu",
"author_id": 3434918,
"author_profile": "https://Stackoverflow.com/users/3434918",
"pm_score": 6,
"selected": false,
"text": "apt install python apt install python2"
},
{
"answer_id": 43427053,
"author": "pz64_",
"author_id": 6737471,
"author_profile": "https://Stackoverflow.com/users/6737471",
"pm_score": 5,
"selected": false,
"text": "pkg install python\n The Scripting Layer for Android, SL4A, is an open source application that allows programs written in a range of interpreted languages to run on Android. It also provides a high level API that allows these programs to interact with the Android device, making it easy to do stuff like accessing sensor data, sending an SMS, rendering user interfaces and so on. python-for-android is an open source build tool to let you package Python code into standalone android APKs. These can be passed around, installed, or uploaded to marketplaces such as the Play Store just like any other Android app. This tool was originally developed for the Kivy cross-platform graphical framework, but now supports multiple bootstraps and can be easily extended to package other types of Python apps for Android. BeeWare allows you to write your app in Python and release it on multiple platforms. No need to rewrite the app in multiple programming languages. It means no issues with build tools, environments, compatibility, etc."
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9951/"
] |
101,767
|
<p>I'm trying to use cygwin as a build environment under Windows. I have some dependencies on 3rd party packages, for example, GTK+. </p>
<p>Normally when I build under Linux, in my Makefile I can add a call to pkg-config as an argument to gcc, so it comes out like so:</p>
<pre>
gcc example.c `pkg-config --libs --cflags gtk+-2.0`
</pre>
<p>This works fine under Linux, but in cygwin I get:</p>
<pre>
:Invalid argument
make: *** [example] Error 1
</pre>
<p>Right now, I am just manually running pkg-config and pasting the output into the Makefile, which is truly terrible. Is there a good way to workaround or fix for this issue?</p>
<p>Make isn't the culprit. I can copy and paste the command line that make uses to call gcc, and that by itself will run gcc, which halts with ": Invalid argument". </p>
<p>I wrote a small test program to print out command line arguments:</p>
<pre><code>for (i = 0; i < argc; i++)
printf("'%s'\n", argv[i]);
</code></pre>
<p>Notice the single quotes.</p>
<pre>
$ pkg-config --libs gtk+-2.0
-Lc:/mingw/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpang
owin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-
2.0 -lglib-2.0 -lintl
</pre>
<p>Running through the test program:</p>
<pre>
$ ./t `pkg-config --libs gtk+-2.0`
'C:\cygwin\home\smo\pvm\src\t.exe'
'-Lc:/mingw/lib'
'-lgtk-win32-2.0'
'-lgdk-win32-2.0'
'-latk-1.0'
'-lgdk_pixbuf-2.0'
'-lpangowin32-1.0'
'-lgdi32'
'-lpangocairo-1.0'
'-lpango-1.0'
'-lcairo'
'-lgobject-2.0'
'-lgmodule-2.0'
'-lglib-2.0'
'-lintl'
'
</pre>
<p>Notice the one single quote on the last line. It looks like argc is one greater than it should be, and argv[argc - 1] is null. Running the same test on Linux does not have this result.</p>
<p>That said, is there, say, some way I could have the Makefile store the result of pkg-config into a variable, and then use that variable, rather than using the back-tick operator?</p>
|
[
{
"answer_id": 102136,
"author": "Tobias Kunze",
"author_id": 6070,
"author_profile": "https://Stackoverflow.com/users/6070",
"pm_score": 2,
"selected": false,
"text": "which make\nmake --version\n"
},
{
"answer_id": 102543,
"author": "Tobias Kunze",
"author_id": 6070,
"author_profile": "https://Stackoverflow.com/users/6070",
"pm_score": 2,
"selected": false,
"text": "make -d\n"
},
{
"answer_id": 106475,
"author": "Adam Mitz",
"author_id": 2574,
"author_profile": "https://Stackoverflow.com/users/2574",
"pm_score": 1,
"selected": false,
"text": "GTK_LIBS = $(patsubst -Lc:/%,-L/cygdrive/c/%,$(shell pkg-config --libs gtk+-2.0))\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16080/"
] |
101,777
|
<p>Let's say I have this code:</p>
<pre><code>if (md5($_POST[$foo['bar']]) == $somemd5) {
doSomethingWith(md5($_POST[$foo['bar']]);
}
</code></pre>
<p>I could shorten that down by doing:</p>
<pre><code>$value = md5($_POST[$foo['bar']];
if ($value == $somemd5) {
doSomethingWith($value);
}
</code></pre>
<p>But is there any pre-set variable that contains the first or second condition of the current if? Like for instance:</p>
<pre><code>if (md5($_POST[$foo['bar']]) == $somemd5) {
doSomethingWith($if1);
}
</code></pre>
<p>May be a unnecessary way of doing it, but I'm just wondering.</p>
|
[
{
"answer_id": 101867,
"author": "Paweł Hajdan",
"author_id": 9403,
"author_profile": "https://Stackoverflow.com/users/9403",
"pm_score": 1,
"selected": false,
"text": " doSomethingWith($value);\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101777",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15214/"
] |
101,783
|
<p>Anyone happen to have a sample script for recursing a given directory in a filesystem with Powershell? Ultimately what I'm wanting to do is create a script that will generate NSIS file lists for me given a directory. Something very similar to what was done <a href="http://blogs.oracle.com/duffblog/2006/12/dynamic_file_list_with_nsis.html" rel="nofollow noreferrer">here</a> with a BASH script.</p>
|
[
{
"answer_id": 106413,
"author": "halr9000",
"author_id": 6637,
"author_profile": "https://Stackoverflow.com/users/6637",
"pm_score": 2,
"selected": false,
"text": "$path = \"c:\\path\\to\\program\"\n$installFiles = \"installfiles_list.txt\"\n$uninstFiles = \"uninstfiles_list.txt\"\n$files = get-childitem -path $path -recurse | where-object { ! $_.psIsContainer } # won't include dirs\n$filepath = $files | foreach-object { $_.FullName }\n$filepath | set-content $installFiles -encoding ASCII\n$filepath[($filepath.length-1)..0] | set-content $uninstFiles -encoding ASCII\n"
},
{
"answer_id": 151396,
"author": "Emperor XLII",
"author_id": 2495,
"author_profile": "https://Stackoverflow.com/users/2495",
"pm_score": 3,
"selected": true,
"text": "-recurse Get-ChildItem function Get-InstallFiles {\n param( [string]$path )\n\n $allItems = Get-ChildItem -path $path -recurse\n $directories = $allItems | ? { $_.PSIsContainer } | % { $_.FullName }\n $installFiles = $allItems | ? { -not $_.PSIsContainer } | % { $_.FullName }\n $uninstallFiles = $installFiles[-1..-$installFiles.Length]\n\n $result = New-Object PSObject\n $result | Add-Member NoteProperty Directories $directories\n $result | Add-Member NoteProperty InstallFiles $installFiles\n $result | Add-Member NoteProperty UninstallFiles $uninstallFiles\n return $result\n}\n $files = Get-InstallFiles 'C:\\some\\directory'\n$files.InstallFiles | Set-Content 'installfiles.txt'\n$files.UninstallFiles + $files.Directories | Set-Content 'uninstallfiles.txt'\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18831/"
] |
101,806
|
<p>I am working on an application that installs a system wide keyboard
hook. I do not want to install this hook when I am running a debug
build from inside the visual studio (or else it would hang the studio
and eventually the system), and I can avoid this by checking if the
DEBUG symbol is defined.</p>
<p>However, when I debug the <em>release</em> version of the application, is
there a way to detect that it has been started from inside visual
studio to avoid the same problem? It is very annoying to have to
restart the studio/the computer, just because I had been working on
the release build, and want to fix some bugs using the debugger having
forgotten to switch back to the debug build. </p>
<p>Currently I use something like this to check for this scenario:</p>
<pre><code>System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
string moduleName = currentProcess.MainModule.ModuleName;
bool launchedFromStudio = moduleName.Contains(".vshost");
</code></pre>
<p>I would call this the "brute force way", which works in my setting, but I would like to know whether there's another (better) way of detecting this scenario.</p>
|
[
{
"answer_id": 101812,
"author": "TraumaPony",
"author_id": 18658,
"author_profile": "https://Stackoverflow.com/users/18658",
"pm_score": 7,
"selected": true,
"text": "System.Diagnostics.Debugger.IsAttached"
},
{
"answer_id": 101915,
"author": "William Casarin",
"author_id": 10486,
"author_profile": "https://Stackoverflow.com/users/10486",
"pm_score": 4,
"selected": false,
"text": "if( IsDebuggerPresent() )\n{\n ...\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17378/"
] |
101,825
|
<p>That is, I'd like to have a tuple of values.</p>
<p>The use case on my mind:</p>
<pre><code>Dictionary<Pair<string, int>, object>
</code></pre>
<p>or</p>
<pre><code>Dictionary<Triple<string, int, int>, object>
</code></pre>
<p>Are there built-in types like Pair or Triple? Or what's the best way of implementing it?</p>
<p><strong>Update</strong> There are some general-purpose tuples implementations described in the answers, but for tuples used as keys in dictionaries you should additionaly verify correct calculation of the hash code. Some more info on that in another <a href="https://stackoverflow.com/questions/102690/how-does-c-figure-out-the-hash-code-for-an-object">question</a>.</p>
<p><strong>Update 2</strong> I guess it is also worth reminding, that when you use some value as a key in dictionary, it should be immutable.</p>
|
[
{
"answer_id": 101858,
"author": "Timothy Carter",
"author_id": 4660,
"author_profile": "https://Stackoverflow.com/users/4660",
"pm_score": 4,
"selected": false,
"text": "public struct Pair<T1, T2>\n{\n public T1 First;\n public T2 Second;\n}\n\npublic struct Triple<T1, T2, T3>\n{\n public T1 First;\n public T2 Second;\n public T3 Third;\n}\n"
},
{
"answer_id": 101861,
"author": "Jonas Lincoln",
"author_id": 17436,
"author_profile": "https://Stackoverflow.com/users/17436",
"pm_score": 0,
"selected": false,
"text": "Dictionary<KeyValuePair<string, int>, object>\n"
},
{
"answer_id": 101866,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 0,
"selected": false,
"text": "public class Triple<T, U, V>\n{\n public T First {get;set;}\n public U Second {get;set;}\n public V Third {get;set;}\n}\n"
},
{
"answer_id": 101926,
"author": "Seb Nilsson",
"author_id": 2429,
"author_profile": "https://Stackoverflow.com/users/2429",
"pm_score": 2,
"selected": false,
"text": "int id = 33;\nstring description = \"This is a custom solution\";\nDateTime created = DateTime.Now;\n\nKeyValuePair<int, KeyValuePair<string, DateTime>> triple =\n new KeyValuePair<int, KeyValuePair<string, DateTime>>();\ntriple.Key = id;\ntriple.Value.Key = description;\ntriple.Value.Value = created;\n KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string, string> quadruple =\n new KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string, string>();\n"
},
{
"answer_id": 102744,
"author": "Maxime Labelle",
"author_id": 18865,
"author_profile": "https://Stackoverflow.com/users/18865",
"pm_score": 4,
"selected": false,
"text": "int id = 33;\nstring description = \"This is a custom solution\";\nDateTime created = DateTime.Now;\n\nKeyValuePair<int, KeyValuePair<string, DateTime>> triple =\n new KeyValuePair<int, KeyValuePair<string, DateTime>>();\ntriple.Key = id;\ntriple.Value.Key = description;\ntriple.Value.Value = created;\n KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string>, string> quadruple =\n new KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string>, string>();\nKeyValuePair<KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string>, string>, string> quintuple =\n new KeyValuePair<KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string>, string>, string>();\n struct Pair<T, R>\n{\n private T first_;\n private R second_;\n\n public T First\n {\n get { return first_; }\n set { first_ = value; }\n }\n\n public R Second\n {\n get { return second_; }\n set { second_ = value; }\n }\n}\n"
},
{
"answer_id": 103348,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 2,
"selected": false,
"text": "KeyValuePair<TKey,TValue> public Tuple<int, string, int> GetSomething() \n{\n //do stuff to get your multi-value return\n}\n\n//then call it:\nvar retVal = GetSomething();\n\n//problem is what does this mean?\nretVal.Item1 / retVal.Item3; \n//what are item 1 and 3?\n class CustomRetVal {\n int CurrentIndex { get; set; }\n string Message { get; set; }\n int CurrentTotal { get; set; }\n}\n\nvar retVal = GetSomething();\n\n//get % progress\nretVal.CurrentIndex / retVal.CurrentTotal;\n"
},
{
"answer_id": 2562496,
"author": "mafu",
"author_id": 39590,
"author_profile": "https://Stackoverflow.com/users/39590",
"pm_score": 2,
"selected": false,
"text": "List<T>"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2351099/"
] |
101,850
|
<p>Take this code:</p>
<pre><code><?php
if (isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
}
if ($action) {
echo $action;
}
else {
echo 'No variable';
}
?>
</code></pre>
<p>And then access the file with ?action=test
Is there any way of preventing $action from automatically being declared by the GET? Other than of course adding</p>
<pre><code>&& !isset($_GET['action'])
</code></pre>
<p>Why would I want the variable to be declared for me?</p>
|
[
{
"answer_id": 101879,
"author": "owenmarshall",
"author_id": 9806,
"author_profile": "https://Stackoverflow.com/users/9806",
"pm_score": 6,
"selected": true,
"text": "register_globals"
},
{
"answer_id": 101898,
"author": "Lucas Oman",
"author_id": 6726,
"author_profile": "https://Stackoverflow.com/users/6726",
"pm_score": 2,
"selected": false,
"text": "register_globals"
},
{
"answer_id": 101908,
"author": "Johannes Hädrich",
"author_id": 18246,
"author_profile": "https://Stackoverflow.com/users/18246",
"pm_score": 1,
"selected": false,
"text": "error_reporting = E_ALL \n"
},
{
"answer_id": 104365,
"author": "Bob Fanger",
"author_id": 19165,
"author_profile": "https://Stackoverflow.com/users/19165",
"pm_score": 2,
"selected": false,
"text": "ini_set('register_globals', false) php_flag register_globals Off\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101850",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15214/"
] |
101,868
|
<p>Is there any easy to install/use (on unix) database migration tools like Rails Migrations? I really like the idea, but installing ruby/rails purely to manage my database migrations seems overkill.</p>
|
[
{
"answer_id": 102353,
"author": "Otto",
"author_id": 9594,
"author_profile": "https://Stackoverflow.com/users/9594",
"pm_score": 1,
"selected": false,
"text": "rake db/migrate activerecord actviesupport railties"
},
{
"answer_id": 104903,
"author": "Ryan McGeary",
"author_id": 8985,
"author_profile": "https://Stackoverflow.com/users/8985",
"pm_score": 6,
"selected": true,
"text": "db/migrate database.yml require 'active_record'\nrequire 'yaml'\n\ndesc \"Migrate the database through scripts in db/migrate. Target specific version with VERSION=x\"\ntask :migrate => :environment do\n ActiveRecord::Migrator.migrate('db/migrate', ENV[\"VERSION\"] ? ENV[\"VERSION\"].to_i : nil)\nend\n\ntask :environment do\n ActiveRecord::Base.establish_connection(YAML::load(File.open('database.yml')))\n ActiveRecord::Base.logger = Logger.new(STDOUT)\nend\n adapter: mysql\nencoding: utf8\ndatabase: test_database\nusername: root\npassword:\nhost: localhost\n rake migrate"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3839/"
] |
101,877
|
<p>How can I add Page transitions effects like IE in Safari for web pages?</p>
|
[
{
"answer_id": 101961,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 3,
"selected": true,
"text": "var xmlhttp;\nvar timerId = 0;\nvar op = 1;\n\nfunction getPageFx() {\n url = \"/transpage2.html\";\n if (window.XMLHttpRequest) {\n xmlhttp = new XMLHttpRequest()\n xmlhttp.onreadystatechange=xmlhttpChange\n xmlhttp.open(\"GET\",url,true)\n xmlhttp.send(null)\n } else getPageIE();\n}\n\nfunction xmlhttpChange() {\n// if xmlhttp shows \"loaded\"\n if (xmlhttp.readyState == 4) {\n // if \"OK\"\n if (xmlhttp.status == 200) {\n if (timerId != 0)\n window.clearTimeout(timerId);\n timerId = window.setTimeout(\"trans();\",100);\n } else {\n alert(xmlhttp.status)\n }\n }\n}\n\nfunction trans() {\n op -= .1;\n document.body.style.opacity = op;\n if(op < .4) {\n window.clearTimeout(timerId);\n timerId = 0; document.body.style.opacity = 1;\n document.open();\n document.write(xmlhttp.responseText);\n document.close();\n return;\n }\n timerId = window.setTimeout(\"trans();\",100);\n}\n\nfunction getPageIE() {\n window.location.href = \"transpage2.html\";\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101877",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/191/"
] |
101,880
|
<ul>
<li>I start up my application which uses a Jetty server, using port 9000.</li>
<li>I then shut down my application with Ctrl-C</li>
<li>I check with "netstat -a" and see that the port 9000 is no longer being used.</li>
<li>I restart my application and get:</li>
</ul>
<blockquote>
<pre><code>[ERROR,9/19 15:31:08] java.net.BindException: Only one usage of each socket address (protocol/network address/port) is normally permitted
[TRACE,9/19 15:31:08] java.net.BindException: Only one usage of each socket address (protocol/network address/port) is normally permitted
[TRACE,9/19 15:31:08] at java.net.PlainSocketImpl.convertSocketExceptionToIOException(PlainSocketImpl.java:75)
[TRACE,9/19 15:31:08] at sun.nio.ch.Net.bind(Net.java:101)
[TRACE,9/19 15:31:08] at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:126)
[TRACE,9/19 15:31:08] at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:77)
[TRACE,9/19 15:31:08] at org.mortbay.jetty.nio.BlockingChannelConnector.open(BlockingChannelConnector.java:73)
[TRACE,9/19 15:31:08] at org.mortbay.jetty.AbstractConnector.doStart(AbstractConnector.java:285)
[TRACE,9/19 15:31:08] at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
[TRACE,9/19 15:31:08] at org.mortbay.jetty.Server.doStart(Server.java:233)
[TRACE,9/19 15:31:08] at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
[TRACE,9/19 15:31:08] at ...
</code></pre>
</blockquote>
<p>Is this a Java bug? Can I avoid it somehow before starting the Jetty server?</p>
<p><strong>Edit #1</strong> Here is our code for creating our BlockingChannelConnector, note the "setReuseAddress(true)":</p>
<blockquote>
<pre><code> connector.setReuseAddress( true );
connector.setPort( port );
connector.setStatsOn( true );
connector.setMaxIdleTime( 30000 );
connector.setLowResourceMaxIdleTime( 30000 );
connector.setAcceptQueueSize( maxRequests );
connector.setName( "Blocking-IO Connector, bound to host " + connector.getHost() );
</code></pre>
</blockquote>
<p>Could it have something to do with the idle time?</p>
<p><strong>Edit #2</strong> Next piece of the puzzle that may or may not help: when running the application in Debug Mode (Eclipse) the server starts up without a problem!!! But the problem described above occurs reproducibly when running the application in Run Mode or as a built jar file. Whiskey Tango Foxtrot?</p>
<p><strong>Edit #3 (4 days later)</strong> - still have the issue. Any thoughts?</p>
|
[
{
"answer_id": 101906,
"author": "freespace",
"author_id": 8297,
"author_profile": "https://Stackoverflow.com/users/8297",
"pm_score": 1,
"selected": false,
"text": "setReuseAddress(true) bind()"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6583/"
] |
101,893
|
<p>This concept is a new one for me -- I first came across it at the <a href="http://developer.yahoo.com/yui/articles/hosting/#configure" rel="nofollow noreferrer">YUI dependency configurator</a>. Basically, instead of having multiple requests for many files, the files are chained into one http request to cut down on page load time.</p>
<p>Anyone know how to implement this on a LAMP stack? (I saw a similar question was asked already, but it <a href="https://stackoverflow.com/questions/47937/combining-and-caching-multiple-javascript-files-in-aspnet">seems to be ASP specific</a>.</p>
<p>Thanks!</p>
<p>Update: Both answers are helpful...(my rep isn't high enough to comment yet so I'm adding some parting thoughts here). I also came <a href="http://www.artzstudio.com/2008/08/using-modconcat-to-speed-up-render-start/" rel="nofollow noreferrer">across another blog post</a> with PHP-specific examples that might be useful. David's build answer, though, is making me consider a different approach. Thanks, David!</p>
|
[
{
"answer_id": 101941,
"author": "David McLaughlin",
"author_id": 3404,
"author_profile": "https://Stackoverflow.com/users/3404",
"pm_score": 4,
"selected": true,
"text": "perl build-project-master.pl core.js class1.js etc.js /path/to/live/js/file.js\n"
},
{
"answer_id": 14414073,
"author": "Jonathan Berger",
"author_id": 518222,
"author_profile": "https://Stackoverflow.com/users/518222",
"pm_score": 0,
"selected": false,
"text": "gem install juicer"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13243/"
] |
101,935
|
<p>Is there a way (without installing any libraries) of validating XML using a custom DTD in PHP?</p>
|
[
{
"answer_id": 101962,
"author": "owenmarshall",
"author_id": 9806,
"author_profile": "https://Stackoverflow.com/users/9806",
"pm_score": 4,
"selected": true,
"text": "<?php\n$dom = new DOMDocument;\n$dom->Load('book.xml');\nif ($dom->validate()) {\n echo \"This document is valid!\\n\";\n}\n?>\n"
},
{
"answer_id": 5183358,
"author": "PayamRWD",
"author_id": 526385,
"author_profile": "https://Stackoverflow.com/users/526385",
"pm_score": 1,
"selected": false,
"text": "<?php\n\n$dom = new DOMDocument; <br/>\n$dom->Load('template-format.xml');<br/>\nif ($dom->validate()) { <br/>\n echo \"This document is valid!\\n\"; <br/>\n}\n\n?>\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n<!-- DTD to Validate against (format example) -->\n\n<!DOCTYPE template-format [ <br/>\n <!ELEMENT template-format (template)> <br/>\n <!ELEMENT template (background-color, color, font-size, header-image)> <br/>\n <!ELEMENT background-color (#PCDATA)> <br/>\n <!ELEMENT color (#PCDATA)> <br/>\n <!ELEMENT font-size (#PCDATA)> <br/>\n <!ELEMENT header-image (#PCDATA)> <br/>\n]>\n\n<!-- XML example -->\n\n<template-format>\n\n<template>\n\n<background-color></background-color> <br/>\n<color></color> <br/>\n<font-size></font-size> <br/>\n<header-image></header-image> <br/>\n\n</template> \n\n</template-format>\n"
},
{
"answer_id": 6532933,
"author": "Søren Jacobi",
"author_id": 822761,
"author_profile": "https://Stackoverflow.com/users/822761",
"pm_score": 2,
"selected": false,
"text": "$xml = '<?xml version=\"1.0\"?>\n <!DOCTYPE note SYSTEM \"note.dtd\">\n <note>\n <to>Tove</to>\n <from>Jani</from>\n <heading>Reminder</heading>\n <body>Don\\'t forget me this weekend!</body>\n </note>';\n\n$dtd = '<!ELEMENT note (to,from,heading,body)>\n <!ELEMENT to (#PCDATA)>\n <!ELEMENT from (#PCDATA)>\n <!ELEMENT heading (#PCDATA)>\n <!ELEMENT body (#PCDATA)>';\n\n\n$root = 'note';\n\n$systemId = 'data://text/plain;base64,'.base64_encode($dtd);\n\n$old = new DOMDocument;\n$old->loadXML($xml);\n\n$creator = new DOMImplementation;\n$doctype = $creator->createDocumentType($root, null, $systemId);\n$new = $creator->createDocument(null, null, $doctype);\n$new->encoding = \"utf-8\";\n\n$oldNode = $old->getElementsByTagName($root)->item(0);\n$newNode = $new->importNode($oldNode, true);\n$new->appendChild($newNode);\n\nif (@$new->validate()) {\n echo \"Valid\";\n} else {\n echo \"Not valid\";\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101935",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18856/"
] |
101,949
|
<p>I am using WPF and I have an image of an 8.5" * 11" piece of paper on a Canvas. I am then rotating the image using a RotateTransform, with the axis being in the middle of the page (that is, RotateTransformOrigin="0.5,0.5"). How can I find the actual location on the canvas of the corners of the image?</p>
|
[
{
"answer_id": 106585,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": 0,
"selected": false,
"text": "_image.TranslatePoint(new Point(0, 0), _canvas);\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101949",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18153/"
] |
101,958
|
<p>I recently discovered that our company has a set of coding guidelines (hidden away in a document management system where no one can find it). It generally seems pretty sensible, and keeps away from the usual religious wars about where to put '{'s and whether to use hard tabs. However, it does suggest that "lines SHOULD NOT contain embedded multiple spaces". By which it means don't do this sort of thing:</p>
<pre><code>foo = 1;
foobar = 2;
bar = 3;
</code></pre>
<p>Or this:</p>
<pre><code>if ( test_one ) return 1;
else if ( longer_test ) return 2;
else if ( shorter ) return 3;
else return 4;
</code></pre>
<p>Or this:</p>
<pre><code>thing foo_table[] =
{
{ "aaaaa", 0 },
{ "aa", 1 },
// ...
}
</code></pre>
<p>The justification for this is that changes to one line often require every line to be edited. That makes it more effort to change, and harder to understand diffs.</p>
<p>I'm torn. On the one hand, lining up like this can make repetitive code much easier to read. On the other hand, it does make diffs harder to read.</p>
<p>What's your view on this?</p>
|
[
{
"answer_id": 101984,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 5,
"selected": false,
"text": "gofmt rustfmt"
},
{
"answer_id": 102048,
"author": "Onorio Catenacci",
"author_id": 2820,
"author_profile": "https://Stackoverflow.com/users/2820",
"pm_score": 4,
"selected": false,
"text": "Employee.Name = \"Andrew Nelson\"\nEmployee.Bdate = \"1/1/56\"\nEmployee.Rank = \"Senator\"\nCurrentEmployeeRecord = 0\n\nFor CurrentEmployeeRecord From LBound(EmployeeArray) To UBound(EmployeeArray) \n. . .\n Employee.Name = \"Andrew Nelson\"\nEmployee.Bdate = \"1/1/56\"\nEmployee.Rank = \"Senator\"\nCurrentEmployeeRecord = 0\n\nFor CurrentEmployeeRecord From LBound(EmployeeArray) To UBound(EmployeeArray) \n. . .\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101958",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1105/"
] |
101,986
|
<p>A sysadmin teacher told me one day that I should learn to use "make" because I could use it for a lot of other things that just triggering complilations.</p>
<p>I never got the chance to talk longer about it. Do you have any good example ?</p>
<p>As a bonus, isn't it this tool deprecated, and what are modern alternatives (for the compilation purpose and others) ?</p>
|
[
{
"answer_id": 102051,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 0,
"selected": false,
"text": "postfix squid POSTMAP=/usr/sbin/postmap\nPOSTFIX=/usr/sbin/postfix\n\nHASHES=transport access virtual canonical relocated annoying_senders\nBTREES=clients_welcome\n\nHASHES_DB=${HASHES:=.db}\nBTREES_DB=${BTREES:=.db}\n\nall: ${BTREES_DB} ${HASHES_DB} aliases.db\n echo \\= Done\n\n${HASHES_DB}: %.db: %\n echo . Rebuilding $< hash...\n ${POSTMAP} $<\n\n${BTREES_DB}: %.db: %\n echo . Rebuilding $< btree...\n ${POSTMAP} $<\n\naliases.db: aliases\n echo . Rebuilding aliases...\n /usr/bin/newaliases\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/101986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9951/"
] |
102,003
|
<p>The default 64 MB max heap memory can be small for a large Java application. Are there any applet parameter to increment this for a signed applet?</p>
<p>For a Java program this is a simple command line parameter but how this work for an applet in the browser.</p>
|
[
{
"answer_id": 4149222,
"author": "Mayur",
"author_id": 503789,
"author_profile": "https://Stackoverflow.com/users/503789",
"pm_score": 2,
"selected": false,
"text": "j2se version=\"1.6+\" initial-heap-size=\"256m\" max-heap-size=\"1024m\"\n href=\"http://java.sun.com/products/autodl/j2se\" /\"\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/102003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12631/"
] |
102,009
|
<p>In C++, when is it best to use the stack? When is it best to use the heap?</p>
|
[
{
"answer_id": 102145,
"author": "Doug T.",
"author_id": 8123,
"author_profile": "https://Stackoverflow.com/users/8123",
"pm_score": 4,
"selected": false,
"text": "int main()\n{ \n if (...)\n {\n int i = 0;\n }\n // I know that i is no longer needed here, so declaring i in the above block \n // limits the scope appropriately\n}\n Object* CreateObject();\n\nint main()\n{\n Object* obj = CreateObject();\n // I can continue to manipulate object and I decide when I'm done with it\n\n // ..\n // I'm done\n delete obj;\n // .. keep going if you wish\n return 0;\n}\n\nObject* CreateObject()\n{\n Object* returnValue = new Object();\n // ... do a bunch of stuff to returnValue\n return returnValue;\n // Note the object created via new here doesn't go away, its passed back using \n // a pointer\n}\n int main()\n{\n boost::shared_ptr<Object> obj = CreateObject();\n // I can continue to manipulate object and I decide when I'm done with it\n\n // ..\n // I'm done, manually delete\n obj.reset(NULL);\n // .. keep going if you wish\n // here, if you forget to delete obj, the shared_ptr's destructor will note\n // that if no other shared_ptr's point to this memory \n // it will automatically get deleted.\n return 0;\n}\n\nboost::shared_ptr<Object> CreateObject()\n{\n boost::shared_ptr<Object> returnValue(new Object());\n // ... do a bunch of stuff to returnValue\n return returnValue;\n // Note the object created via new here doesn't go away, its passed back to \n // the receiving shared_ptr, shared_ptr knows that another reference exists\n // to this memory, so it shouldn't delete the memory\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/102009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/75350/"
] |
102,049
|
<p>For example:</p>
<pre><code>me$ FOO="BAR * BAR"
me$ echo $FOO
BAR file1 file2 file3 file4 BAR
</code></pre>
<p>and using the <code>\</code> escape character:</p>
<pre><code>me$ FOO="BAR \* BAR"
me$ echo $FOO
BAR \* BAR
</code></pre>
<p>I'm obviously doing something stupid.</p>
<p>How do I get the output <code>BAR * BAR</code>?</p>
|
[
{
"answer_id": 102073,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 3,
"selected": false,
"text": "FOO='BAR * BAR'\necho \"$FOO\"\n"
},
{
"answer_id": 102074,
"author": "Rafał Dowgird",
"author_id": 12166,
"author_profile": "https://Stackoverflow.com/users/12166",
"pm_score": 2,
"selected": false,
"text": "echo \"$FOO\"\n"
},
{
"answer_id": 102075,
"author": "finnw",
"author_id": 12048,
"author_profile": "https://Stackoverflow.com/users/12048",
"pm_score": 8,
"selected": true,
"text": "$FOO me$ FOO=\"BAR * BAR\"\nme$ echo \"$FOO\"\nBAR * BAR\n"
},
{
"answer_id": 102241,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 2,
"selected": false,
"text": "printf echo FOO=\"BAR * BAR\"\nprintf %s \"$FOO\"\n"
},
{
"answer_id": 104023,
"author": "mithu",
"author_id": 16618,
"author_profile": "https://Stackoverflow.com/users/16618",
"pm_score": 7,
"selected": false,
"text": "me$ FOO=\"BAR * BAR\"\nme$ echo $FOO\n me$ echo BAR * BAR\n me$ echo BAR file1 file2 file3 file4 BAR\n echo BAR * BAR me$ FOO=\"BAR \\* BAR\"\nme$ echo $FOO\n me$ echo BAR \\* BAR\n me$ echo BAR \\* BAR\n"
},
{
"answer_id": 13484149,
"author": "Alex Just Alex",
"author_id": 1840401,
"author_profile": "https://Stackoverflow.com/users/1840401",
"pm_score": 6,
"selected": false,
"text": "$ echo \"$FOO\"\n #!/bin/bash\ncurl_opts=\"-s --noproxy * -O\"\ncurl $curl_opts \"$1\"\n * curl \\* $curl_opts curl curl: option -s --noproxy * -O: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information\n bash $GLOBIGNORE set -f #!/bin/bash\nGLOBIGNORE=\"*\"\ncurl_opts=\"-s --noproxy * -O\"\ncurl $curl_opts \"$1\" ## no filename expansion\n me$ FOO=\"BAR * BAR\"\n\nme$ echo $FOO\nBAR file1 file2 file3 file4 BAR\n\nme$ set -f\nme$ echo $FOO\nBAR * BAR\n\nme$ set +f\nme$ GLOBIGNORE=*\nme$ echo $FOO\nBAR * BAR\n"
},
{
"answer_id": 65161851,
"author": "INS",
"author_id": 13136,
"author_profile": "https://Stackoverflow.com/users/13136",
"pm_score": 2,
"selected": false,
"text": "me$ FOO=\"BAR \\x2A BAR\" # 2A is hex code for *\nme$ echo -e $FOO\nBAR * BAR\nme$ \n SYNOPSIS\n echo [SHORT-OPTION]... [STRING]...\n echo LONG-OPTION\n\nDESCRIPTION\n Echo the STRING(s) to standard output.\n\n -n do not output the trailing newline\n\n -e enable interpretation of backslash escapes\n\n -E disable interpretation of backslash escapes (default)\n\n --help display this help and exit\n\n --version\n output version information and exit\n\n If -e is in effect, the following sequences are recognized:\n\n \\\\ backslash\n\n ...\n\n \\0NNN byte with octal value NNN (1 to 3 digits)\n\n \\xHH byte with hexadecimal value HH (1 to 2 digits)\n 051 41 29 ) 151 105 69 i\n 052 42 2A * 152 106 6A j\n 053 43 2B + 153 107 6B k\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/102049",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2108/"
] |
102,055
|
<p>I am trying to make a div, that when you click it turns into an input box, and focuses it. I am using prototype to achieve this. This works in both Chrome and Firefox, but not in IE. IE refuses to focus the newly added input field, even if I set a 1 second timeout.</p>
<p>Basically the code works like this:</p>
<pre><code>var viewElement = new Element("div").update("text");
var editElement = new Element("input", {"type":"text"});
root.update(viewElement);
// pseudo shortcut for the sake of information:
viewElementOnClick = function(event) {
root.update(editElement);
editElement.focus();
}
</code></pre>
<p>The above example is a shortened version of the actual code, the actual code works fine except the focus bit in IE.</p>
<p>Are there limitations on the focus function in IE? Do I need to place the input in a form?</p>
|
[
{
"answer_id": 102152,
"author": "17 of 26",
"author_id": 2284,
"author_profile": "https://Stackoverflow.com/users/2284",
"pm_score": 3,
"selected": true,
"text": "setTimeout(\"setFocus\", 0);\n\nfunction setFocus()\n{\n editElement.focus();\n}\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/102055",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3355/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.