qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
172,653
|
<p>Is there <strong>any</strong> way (maybe directly editing resource files) to configure a Tab Control (add/remove tabs and their captions and contents) at <strong>design time</strong> with Visual Studio 2008 without SP1 (I heard that SP1 has such feature)?
P.S.: I use c++ with wtl</p>
|
[
{
"answer_id": 172833,
"author": "Neall",
"author_id": 619,
"author_profile": "https://Stackoverflow.com/users/619",
"pm_score": 4,
"selected": false,
"text": "photos\n photoid\n caption\n filename\n date\n\ntags\n tagid\n tagname\n\nphototags\n photoid\n tagid\n"
},
{
"answer_id": 172853,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 0,
"selected": false,
"text": " public static void threadproc_tags(object obj)\n {\n System.Web.HttpApplicationState app = (System.Web.HttpApplicationState)obj;\n\n SortedDictionary<string,List<int>> tags = new SortedDictionary<string,List<int>>();\n\n // update the cache\n DbUtil dbutil = new DbUtil();\n DataSet ds = dbutil.get_dataset(\"select bg_id, bg_tags from bugs where isnull(bg_tags,'') <> ''\");\n\n foreach (DataRow dr in ds.Tables[0].Rows)\n {\n string[] labels = btnet.Util.split_string_using_commas((string) dr[1]);\n\n // for each tag label, build a list of bugids that have that label\n for (int i = 0; i < labels.Length; i++)\n {\n\n string label = normalize_tag(labels[i]);\n\n if (label != \"\")\n {\n if (!tags.ContainsKey(label))\n {\n tags[label] = new List<int>();\n }\n\n tags[label].Add((int)dr[0]);\n }\n }\n }\n\n app[\"tags\"] = tags;\n\n }\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172653",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14535/"
] |
172,658
|
<p>I'm attempting to use extension methods to add an operater overload to the C# <code>StringBuilder</code> class. Specifically, given <code>StringBuilder</code> <code>sb</code>, I'd like <code>sb += "text"</code> to become equivalent to <code>sb.Append("text")</code>.</p>
<p>Here's the syntax for creating an extension method for <code>StringBuilder</code>:</p>
<pre><code>public static class sbExtensions
{
public static StringBuilder blah(this StringBuilder sb)
{
return sb;
}
}
</code></pre>
<p>It successfully adds the <code>blah</code> extension method to the <code>StringBuilder</code>.</p>
<p>Unfortunately, operator overloading does not seem to work:</p>
<pre><code>public static class sbExtensions
{
public static StringBuilder operator +(this StringBuilder sb, string s)
{
return sb.Append(s);
}
}
</code></pre>
<p>Among other issues, the keyword <code>this</code> is not allowed in this context.</p>
<p>Are adding operator overloads via extension methods possible? If so, what's the proper way to go about it?</p>
|
[
{
"answer_id": 2194671,
"author": "Jordão",
"author_id": 31158,
"author_profile": "https://Stackoverflow.com/users/31158",
"pm_score": 6,
"selected": false,
"text": "class Program {\n\n static void Main(string[] args) {\n StringBuilder sb = new StringBuilder();\n ReceiveImportantMessage(sb);\n Console.WriteLine(sb.ToString());\n }\n\n // the important thing is to use StringBuilderWrapper!\n private static void ReceiveImportantMessage(StringBuilderWrapper sb) {\n sb += \"Hello World!\";\n }\n\n}\n\npublic class StringBuilderWrapper {\n\n public StringBuilderWrapper(StringBuilder sb) { StringBuilder = sb; }\n public StringBuilder StringBuilder { get; private set; }\n\n public static implicit operator StringBuilderWrapper(StringBuilder sb) {\n return new StringBuilderWrapper(sb);\n }\n\n public static StringBuilderWrapper operator +(StringBuilderWrapper sbw, string s) { \n sbw.StringBuilder.Append(s);\n return sbw;\n }\n\n} \n StringBuilderWrapper StringBuilder + StringBuilder ReceiveImportantMessage StringBuilderWrapper + ReceiveImportantMessage StringBuilder private static void ReceiveImportantMessage(StringBuilder sb) {\n StringBuilderWrapper sbw = sb;\n sbw += \"Hello World!\";\n }\n StringBuilder StringBuilder sb = new StringBuilder();\n StringBuilderWrapper sbw = sb;\n sbw += \"Hello World!\";\n Console.WriteLine(sb.ToString());\n IComparable"
},
{
"answer_id": 10643692,
"author": "Chuck Rostance",
"author_id": 810915,
"author_profile": "https://Stackoverflow.com/users/810915",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text; \n\nnamespace Whatever.Test\n{\n public static class Extensions\n {\n public static int Compare(this MyObject t1, MyObject t2)\n {\n if(t1.SomeValueField < t2.SomeValueField )\n return -1;\n else if (t1.SomeValueField > t2.SomeValueField )\n {\n return 1;\n }\n else\n {\n return 0;\n }\n }\n\n public static MyObject Add(this MyObject t1, MyObject t2)\n {\n var newObject = new MyObject();\n //do something \n return newObject;\n\n }\n\n public static MyObject Subtract(this MyObject t1, MyObject t2)\n {\n var newObject= new MyObject();\n //do something\n return newObject; \n }\n }\n\n\n}\n"
},
{
"answer_id": 24469649,
"author": "david van brink",
"author_id": 527531,
"author_profile": "https://Stackoverflow.com/users/527531",
"pm_score": 2,
"selected": false,
"text": "sb += (thing) sb.AppendLine sb.AppendFormat public static class SomeExtensions\n{\n public static void Line(this StringBuilder sb, string format, params object[] args)\n {\n string s = String.Format(format + \"\\n\", args);\n sb.Append(s);\n }\n}\n sb.Line(\"the first thing is {0}\", first);\nsb.Line(\"the second thing is {0}\", second);\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1388/"
] |
172,691
|
<p>I'm trying to determine if the user is using 24 hour or 12 hour time, and there doesn't seem to be a good way to figure this out other than creating an NSDateFormatter and searching the format string for the period field ('a' character)</p>
<p>Here's what I'm doing now:</p>
<pre><code>NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setTimeStyle:NSDateFormatterShortStyle];
NSRange range = [[formatter dateFormat] rangeOfString:@"a"];
BOOL is24HourFormat = range.location == NSNotFound && range.length == 0;
[formatter release];
</code></pre>
<p>Which works, but feels kinda fragile. There has to be a better way, right?</p>
|
[
{
"answer_id": 172755,
"author": "schwa",
"author_id": 23113,
"author_profile": "https://Stackoverflow.com/users/23113",
"pm_score": 3,
"selected": true,
"text": "NSLog(@\"%@\", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17188/"
] |
172,711
|
<p>This is the one thing I could never get to work.<br>
My problem is to detect the end of one day and the start of the next and then splitting the diff into each day.</p>
<p>Imagine you want to calculate a pay rate but it has to span across midnight.</p>
<p>It also applies to calculating time to run on timed system, or time diff it should've run.</p>
|
[
{
"answer_id": 172716,
"author": "UnkwnTech",
"author_id": 115,
"author_profile": "https://Stackoverflow.com/users/115",
"pm_score": 3,
"selected": false,
"text": "hoursWorked = ((stopTime - startTime)/60)/60\n <?php\n$startTime = \"12/31/2008 22:02\"; //No AM/PM we'll use 24hour system\n$endTime = \"01/01/2009 06:27\"; //Again no AM/PM and we spaned the midnight time gap.\n/*\nUse this to test for a normal shift not ocurring durring midnight.\n$startTime = \"01/01/2008 06:02\"; //No AM/PM we'll use 24hour system\n$endTime = \"01/01/2008 14:27\"; //Again no AM/PM and we spaned the midnight time gap.\n*/\n$startTime = split(' ', $startTime);\n$endTime = split(' ', $endTime);\n$startTime[1] = split(':', $startTime[1]);\n$endTime[1] = split(':', $endTime[1]);\n/*\n$startTime[0] contains the date\n$startTime[1][0] contains the hours\n$startTime[1][1] contains the minutes\nsame is true for endTime\n*/\nif($startTime[0] != $endTime[0])\n {\n if(date2epoch($endTime[0]) > date2epoch($startTime[0]))\n {\n $minutesWorked1 = (59 - $startTime[1][1]); //Calculate how many minutes have occured from begining of shift to midnight\n $minutesWorked2 = $endTime[1][1]; //Number of minute from midnight to end of shift\n $hoursWorked1 = (23 - $startTime[1][0]);//Number of hours from start of shift to midnight\n $hoursWorked2 = $endTime[1][0];//Number of minutes from midnight to end of shift\n echo 'Before midnight you worked ' . $hoursWorked1 . ':' . $minutesWorked1 . \"\\nAfter midnight you worked \" . $hoursWorked2 . ':' . $minutesWorked2 . '.';\n }\n else \n {\n //SOMETHING MAJOR BAD HAS HAPPENED WHILE LOGGING THE CLOCKINS AND CLOCKOUTS\n }\n }\nelse \n {\n echo 'Today you worked ' . ($endTime[1][0] - $startTime[1][0]) . ':' . ($endTime[1][1] - $startTime[1][1]);\n }\nfunction date2epoch($date, $format='m/d/Y')\n {\n $date = split('/', $date);\n return mktime('0', '0', '0', $date[0], $date[1], $date[2]);\n }\n?>\n"
},
{
"answer_id": 172719,
"author": "Mark Ransom",
"author_id": 5987,
"author_profile": "https://Stackoverflow.com/users/5987",
"pm_score": 2,
"selected": false,
"text": "if endtime < starttime then endtime = endtime + 24 hours\n"
},
{
"answer_id": 172729,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 2,
"selected": false,
"text": "// In UTC, preferably\nDateTime ClockIn;\nDateTime ClockOut;\n\nClockIn = ...;\nClockOut = ...;\n\nTimeSpan TimeWorked = ClockOut.Subtract(ClockIn);\nfloat HoursWorked = TimeWorked.TotalHours();\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172711",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8167/"
] |
172,720
|
<p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</strong>: When writing a program from scratch in python, what are some good ways to greatly improve performance?</p></li>
</ul>
<p>For the first question, imagine you are handed a decently written project and you need to improve performance, but you can't seem to get much of a gain through refactoring/optimization. What would you do to speed it up in this case short of rewriting it in something like C?</p>
|
[
{
"answer_id": 172726,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 4,
"selected": false,
"text": "for i in range(10000000)"
},
{
"answer_id": 172744,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 5,
"selected": false,
"text": "result = u\"\"\nfor item in my_list:\n result += unicode (item)\n \"\".join result = \"\".join (unicode (item) for item in my_list)\n"
},
{
"answer_id": 172782,
"author": "Walter",
"author_id": 23840,
"author_profile": "https://Stackoverflow.com/users/23840",
"pm_score": 2,
"selected": false,
"text": "map() reduce()"
},
{
"answer_id": 173055,
"author": "I GIVE CRAP ANSWERS",
"author_id": 25083,
"author_profile": "https://Stackoverflow.com/users/25083",
"pm_score": 5,
"selected": false,
"text": "numpy Twisted"
},
{
"answer_id": 175283,
"author": "Peter Shinners",
"author_id": 17209,
"author_profile": "https://Stackoverflow.com/users/17209",
"pm_score": 1,
"selected": false,
"text": "psyco.profile() psyco.full()"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/145/"
] |
172,739
|
<p>I am studying for cryptography and I somehow stuck on understanding how DES works. Because it is around for a long time there should be nice tutorials like fancy diagrams, videos etc around the net. I searched but with no luck. Has anyone spotted anything "easy-to-digest" for the brain?</p>
|
[
{
"answer_id": 9643405,
"author": "Filippos Pirpilidis",
"author_id": 1259305,
"author_profile": "https://Stackoverflow.com/users/1259305",
"pm_score": 1,
"selected": false,
"text": "public class Filippakoc_Des {\nstatic int[][] sb1={\n {14 , 4 , 13 , 1 , 2 , 15 , 11 , 8 , 3 , 10 , 6 , 12 , 5 , 9 , 0 , 7 },\n {0 , 15, 7 , 4 , 14, 2 , 13, 1, 10, 6, 12, 11, 9, 5, 3, 8},\n {4 , 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0},\n {15 , 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}\n};\n static int[][] sb2={\n {15 , 1 , 8 , 14, 6 , 11, 3, 4, 9 , 7 , 2, 13 , 12, 0, 5 , 10},\n {3 , 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5},\n {0 , 14, 7, 11, 10, 4, 13, 1, 5 , 8, 12, 6, 9, 3, 2, 15},\n {13 , 8 , 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0 , 5, 14, 9}\n};\n static int[][] sb3={\n {10 , 0 , 9,14, 6, 3, 15, 5, 1, 13, 12, 7 , 11, 4, 2, 8},\n {13 , 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1},\n {13 , 6, 4, 9, 8, 15, 3, 0,11, 1, 2, 12, 5, 10, 14, 7},\n {1 , 10 ,13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}\n};\n static int[][] sb4={\n { 7 , 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15},\n {13 , 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9},\n {10 , 6, 9, 0, 12, 11, 7, 13,15, 1, 3, 14, 5, 2, 8, 4},\n {3 , 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}\n};\n static int[][] sb5={\n { 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9},\n {14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6},\n {4 , 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14},\n {11, 8, 12, 7 , 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}\n};\n static int[][] sb6={\n { 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11},\n {10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8},\n {9 , 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13,11, 6},\n {4, 3, 12, 12, 9, 5, 15, 10,11, 14, 1, 7, 6, 0, 8, 13}\n};\n static int[][] sb7={\n { 4,11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1},\n {13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6},\n {1 , 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2},\n {6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}\n};\n static int[][] sb8={\n {13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3,14, 5, 0, 12, 7},\n { 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6,11, 0, 14, 9, 2},\n {7 , 11, 4, 1, 9, 12, 14, 2, 0, 6, 10,13, 15, 3, 5, 8},\n { 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}\n};\n\n public String Filippakoc_Des(String ptxt,String key,boolean encdes){\n //String a=String.format(\"%64s\", Integer.toBinaryString(255)).replace(' ', '0');\n //String b=\"1011011111001001100001110000101110110000010001110101111101001010\";\n String ipa=IPpermutation(ptxt);\n String ipb=IPpermutation(ptxt);\n String[] keys=Keygenerate(key);\n String[] rounds=new String[16];\n String cripttext=\"\";\n if(encdes==true){\n for(int i=0;i<rounds.length;i++){\n if(i<1){\n rounds[i]=round(ipa,keys[i]);\n }else{\n rounds[i]=round(rounds[i-1],keys[i]);\n }\n\n\n }\n\n cripttext=IPpermutation_(rounds[15]);\n //System.out.println(ptxt);\n //System.out.println(cripttext);\n }else{\n for(int i=rounds.length-1;i>=0;i--){\n if(i>14){\n rounds[i]=dround(ipb,keys[i]);\n }else{\n rounds[i]=dround(rounds[i+1],keys[i]);\n }\n\n }\n cripttext=IPpermutation_(rounds[0]);\n //System.out.println(ptxt);\n //System.out.println(cripttext);\n }\n\n\n return cripttext;\n\n //String a=String.format(\"%32s\", Integer.toBinaryString(255)).replace(' ', '0');\n //String b=String.format(\"%48s\", Integer.toBinaryString(21)).replace(' ', '0');\n //System.out.println(functionf(a, b));\n //System.out.println(xor(a,b));\n }\n public String Filippakoc_3des(String ptxt,String key1,String key2,String key3,boolean encdes){\n String En=\"\";\n if(encdes){\n En=Filippakoc_Des(ptxt, key1, true);\n En=En=Filippakoc_Des(En, key2, false);\n En=En=Filippakoc_Des(En, key3, true);\n }else{\n En=Filippakoc_Des(ptxt, key1, false);\n En=En=Filippakoc_Des(En, key2, true);\n En=En=Filippakoc_Des(En, key3, false);\n }\n\n return En;\n\n }\n public String round(String plain64,String keyi){\n\n String li=plain64.substring(0,32);\n String ri=plain64.substring(32);\n\n String ro=xor(li,functionf(ri,keyi));\n String lo=ri;\n String resultround=lo+ro;\n return resultround;\n }\n public String dround(String plain64,String keyi){\n String li=plain64.substring(0,32);\n String ri=plain64.substring(32);\n\n String lo=xor(ri,functionf(li,keyi));\n String ro=li;\n String resultround=lo+ro;\n return resultround;\n }\n public String xor(String a,String b){\n String res=\"\";\n for(int i=0;i<a.length();i++){\n if(a.charAt(i)=='0' && b.charAt(i)=='0'){\n res+='0';\n }else if(a.charAt(i)=='0' && b.charAt(i)=='1'){\n res+='1';\n }else if(a.charAt(i)=='1' && b.charAt(i)=='0'){\n res+='1';\n }else if(a.charAt(i)=='1' && b.charAt(i)=='1'){\n res+='0';\n }\n }\n return res;\n }\n public String sboxesrtn(int ff){\n String sb=Integer.toBinaryString(ff);\n if(ff<2){\n sb=\"000\"+sb;\n }else if(ff<4){\n sb=\"00\"+sb;\n }else if(ff<8){\n sb=\"0\"+sb;\n }\n return sb;\n }\n public String functionf(String r32,String k48){\n String r48=Epermutation(r32);\n String xorout=xor(r48, k48);\n String[] splitto6=new String[8];\n splitto6[0]=xorout.substring(0,6);\n splitto6[1]=xorout.substring(6,12);\n splitto6[2]=xorout.substring(12,18);\n splitto6[3]=xorout.substring(18,24);\n splitto6[4]=xorout.substring(24,30);\n splitto6[5]=xorout.substring(30,36);\n splitto6[6]=xorout.substring(36,42);\n splitto6[7]=xorout.substring(42);\n String rnew32=\"\";\n String row;\n String column=\"\";\n for(int i=0;i<splitto6.length;i++){\n row=\"\"+splitto6[i].charAt(0)+splitto6[i].charAt(5);\n column=splitto6[i].substring(1,5);\n //System.out.println(splitto6[i]+\" \"+row+\" \"+column);\n int irow=Integer.parseInt(row, 2);\n int icolumn=Integer.parseInt(column, 2);\n if(i==0){\n //rnew32+=Integer.toBinaryString(sb1[irow][icolumn]);\n rnew32+=String.format(\"%4s\", Integer.toBinaryString(sb1[irow][icolumn])).replace(' ', '0');\n }else if(i==1){\n rnew32+=String.format(\"%4s\", Integer.toBinaryString(sb2[irow][icolumn])).replace(' ', '0');\n }else if(i==2){\n rnew32+=String.format(\"%4s\", Integer.toBinaryString(sb3[irow][icolumn])).replace(' ', '0');\n }else if(i==3){\n rnew32+=String.format(\"%4s\", Integer.toBinaryString(sb4[irow][icolumn])).replace(' ', '0');\n }else if(i==4){\n rnew32+=String.format(\"%4s\", Integer.toBinaryString(sb5[irow][icolumn])).replace(' ', '0');\n }else if(i==5){\n rnew32+=String.format(\"%4s\", Integer.toBinaryString(sb6[irow][icolumn])).replace(' ', '0');\n }else if(i==6){\n rnew32+=String.format(\"%4s\", Integer.toBinaryString(sb7[irow][icolumn])).replace(' ', '0');\n }else if(i==7){\n rnew32+=String.format(\"%4s\", Integer.toBinaryString(sb8[irow][icolumn])).replace(' ', '0');\n }\n }\n\n\n //System.out.println(rnew32.length());\n //System.out.println(rnew32);\n // System.out.print(splitto6[0]+\" \"+splitto6[1]+\" \"+splitto6[2]+\" \"+splitto6[3]+\" \"+splitto6[4]+\" \"+splitto6[5]+\" \"+splitto6[6]+\" \"+splitto6[7]+\"\\n\");\n rnew32=Ppermutation(rnew32);\n return rnew32;\n\n }\n public String Epermutation(String r32){\n r32=\" \"+r32;\n String r48=\"\"+r32.charAt(31)+r32.charAt(1)+r32.charAt(2)+r32.charAt(3)+r32.charAt(4)+r32.charAt(5)+r32.charAt(4)+r32.charAt(5)+r32.charAt(6)+r32.charAt(7)+r32.charAt(8)+r32.charAt(9)+r32.charAt(8)+r32.charAt(9)+r32.charAt(10)+r32.charAt(11)+r32.charAt(12)+r32.charAt(13)+r32.charAt(12)+r32.charAt(13)+r32.charAt(14)+r32.charAt(15)+r32.charAt(16)+r32.charAt(17)+r32.charAt(16)+r32.charAt(17)+r32.charAt(18)+r32.charAt(19)+r32.charAt(20)+r32.charAt(21)+r32.charAt(20)+r32.charAt(21)+r32.charAt(22)+r32.charAt(23)+r32.charAt(24)+r32.charAt(25)+r32.charAt(24)+r32.charAt(25)+r32.charAt(26)+r32.charAt(27)+r32.charAt(28)+r32.charAt(29)+r32.charAt(28)+r32.charAt(29)+r32.charAt(30)+r32.charAt(31)+r32.charAt(32)+r32.charAt(1);\n return r48;\n }\n public String Ppermutation(String r32){\n r32=\" \"+r32;\n String r32p=\"\"+r32.charAt(17)+r32.charAt(7)+r32.charAt(20)+r32.charAt(21)+r32.charAt(29)+r32.charAt(12)+r32.charAt(28)+r32.charAt(17)+r32.charAt(1)+r32.charAt(15)+r32.charAt(23)+r32.charAt(26)+r32.charAt(5)+r32.charAt(18)+r32.charAt(31)+r32.charAt(10)+r32.charAt(2)+r32.charAt(8)+r32.charAt(24)+r32.charAt(14)+r32.charAt(32)+r32.charAt(27)+r32.charAt(3)+r32.charAt(9)+r32.charAt(19)+r32.charAt(13)+r32.charAt(30)+r32.charAt(6)+r32.charAt(22)+r32.charAt(11)+r32.charAt(4)+r32.charAt(25);\n return r32p;\n }\n public String IPpermutation(String r64){\n r64=\" \"+r64;\n String r64p=\"\"+r64.charAt(58)+r64.charAt(50)+r64.charAt(42)+ r64.charAt(34)+r64.charAt(26)+r64.charAt(18)+r64.charAt(10)+r64.charAt(2)\n +r64.charAt(60)+r64.charAt(52)+r64.charAt(44)+r64.charAt(36)+r64.charAt(28)+r64.charAt(20)+r64.charAt(12)+r64.charAt(4)+\n r64.charAt(62)+r64.charAt(54)+r64.charAt(46)+r64.charAt(38)+r64.charAt(30)+r64.charAt(22)+r64.charAt(14)+r64.charAt(6)+\n r64.charAt(64)+r64.charAt(56)+r64.charAt(48)+r64.charAt(40)+r64.charAt(32)+r64.charAt(24)+r64.charAt(16)+r64.charAt(8)+\n r64.charAt(57)+r64.charAt(49)+ r64.charAt(41)+r64.charAt(33)+r64.charAt(25)+r64.charAt(17)+r64.charAt(9)+r64.charAt(1)+\n r64.charAt(59)+r64.charAt(51)+r64.charAt(43)+r64.charAt(35)+r64.charAt(27)+r64.charAt(19)+r64.charAt(11)+r64.charAt(3)+\n r64.charAt(61)+r64.charAt(53)+r64.charAt(45)+r64.charAt(37)+r64.charAt(29)+r64.charAt(21)+r64.charAt(13)+r64.charAt(5)+\n r64.charAt(63)+r64.charAt(55)+r64.charAt(47)+r64.charAt(39)+r64.charAt(31)+r64.charAt(23)+r64.charAt(15)+r64.charAt(7);\n return r64p;\n }\n public String IPpermutation_(String r64){\n r64=\" \"+r64;\n String r64p=\"\"+\n r64.charAt(40)+r64.charAt(8)+r64.charAt(48)+ r64.charAt(16)+r64.charAt(56)+r64.charAt(24)+r64.charAt(64)+r64.charAt(32)+\n r64.charAt(39)+r64.charAt(7)+r64.charAt(47)+r64.charAt(15)+r64.charAt(55)+r64.charAt(23)+r64.charAt(63)+r64.charAt(31)+\n r64.charAt(38)+r64.charAt(6)+r64.charAt(46)+r64.charAt(14)+r64.charAt(54)+r64.charAt(22)+r64.charAt(62)+r64.charAt(30)+\n r64.charAt(37)+r64.charAt(5)+r64.charAt(45)+r64.charAt(13)+r64.charAt(53)+r64.charAt(21)+r64.charAt(61)+r64.charAt(29)+\n r64.charAt(36)+r64.charAt(4)+ r64.charAt(44)+r64.charAt(12)+r64.charAt(52)+r64.charAt(20)+r64.charAt(60)+r64.charAt(28)+\n r64.charAt(35)+r64.charAt(3)+r64.charAt(43)+r64.charAt(11)+r64.charAt(51)+r64.charAt(19)+r64.charAt(59)+r64.charAt(27)+\n r64.charAt(34)+r64.charAt(2)+r64.charAt(42)+r64.charAt(10)+r64.charAt(50)+r64.charAt(18)+r64.charAt(58)+r64.charAt(26)+\n r64.charAt(33)+r64.charAt(1)+r64.charAt(41)+r64.charAt(9)+r64.charAt(49)+r64.charAt(17)+r64.charAt(57)+r64.charAt(25);\n return r64p;\n }\n public String[] Keygenerate(String key){\n String[] keys=new String[16];\n String key56=pc_1(key);\n String lkey28=key56.substring(0,28);\n String rkey28=key56.substring(28);\n for(int i=0;i<keys.length;i++){\n if(i==0 || i==1 || i==8 || i==15){\n lkey28=Lbitrotate(lkey28, 1);\n rkey28=Lbitrotate(rkey28, 1);\n keys[i]=pc_2(lkey28+rkey28);\n }else{\n lkey28=Lbitrotate(lkey28, 2);\n rkey28=Lbitrotate(rkey28, 2);\n keys[i]=pc_2(lkey28+rkey28);\n }\n }\n\n return keys;\n\n}\npublic String pc_1(String key){\n String key56=\"\";\n key56=\"\"+key.charAt(56)+key.charAt(48)+key.charAt(40)+key.charAt(32)+key.charAt(24)+key.charAt(16)+key.charAt(8)+key.charAt(0)+key.charAt(57)+key.charAt(49)+key.charAt(41)+key.charAt(33)+key.charAt(25)+key.charAt(17)+key.charAt(9)+key.charAt(1)+key.charAt(58)+key.charAt(50)+key.charAt(42)+key.charAt(34)+key.charAt(26)+key.charAt(18)+key.charAt(10)+key.charAt(2)+key.charAt(59)+key.charAt(51)+key.charAt(43)+key.charAt(35)+key.charAt(62)+key.charAt(54)+key.charAt(46)+key.charAt(38)+key.charAt(30)+key.charAt(23)+key.charAt(14)+key.charAt(6)+key.charAt(61)+key.charAt(53)+key.charAt(45)+key.charAt(37)+key.charAt(29)+key.charAt(21)+key.charAt(13)+key.charAt(5)+key.charAt(60)+key.charAt(52)+key.charAt(44)+key.charAt(36)+key.charAt(28)+key.charAt(20)+key.charAt(12)+key.charAt(4)+key.charAt(27)+key.charAt(19)+key.charAt(11)+key.charAt(3);\n return key56;\n}\n public String pc_2(String key){\n String key48=\"\";\n key48=\"\"+key.charAt(13)+key.charAt(16)+key.charAt(10)+key.charAt(23)+key.charAt(0)+key.charAt(4)+key.charAt(2)+key.charAt(27)+key.charAt(14)+key.charAt(5)+key.charAt(20)+key.charAt(9)+key.charAt(22)+key.charAt(18)+key.charAt(11)+key.charAt(3)+key.charAt(25)+key.charAt(7)+key.charAt(15)+key.charAt(6)+key.charAt(26)+key.charAt(19)+key.charAt(12)+key.charAt(1)+key.charAt(40)+key.charAt(51)+key.charAt(30)+key.charAt(36)+key.charAt(46)+key.charAt(54)+key.charAt(29)+key.charAt(39)+key.charAt(50)+key.charAt(44)+key.charAt(32)+key.charAt(47)+key.charAt(43)+key.charAt(48)+key.charAt(38)+key.charAt(55)+key.charAt(33)+key.charAt(52)+key.charAt(45)+key.charAt(41)+key.charAt(49)+key.charAt(35)+key.charAt(28)+key.charAt(31);\n return key48;\n}\n\n\n public String Lbitrotate(String bin,int times){\n String binary=bin;\n String binary2=\"\";\n String binarynew=\"\";\n for(int i=0;i<times;i++){\n if(i<1){\n binary2=binary.substring(1)+binary.charAt(0);\n }else{\n binary2=binarynew.substring(1)+binarynew.charAt(0);\n }\n binarynew=binary2;\n\n }\n return binary2;\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1622/"
] |
172,748
|
<p>Is there a way to make a popup window maximised as soon as it is opened? If not that, at least make it screen-sized? This:</p>
<pre><code>window.open(src, 'newWin', 'fullscreen="yes"')
</code></pre>
<p>apparently only worked for old version of IE.</p>
|
[
{
"answer_id": 172756,
"author": "Geoff",
"author_id": 10427,
"author_profile": "https://Stackoverflow.com/users/10427",
"pm_score": 7,
"selected": true,
"text": "screen.availWidth screen.availHeight window.open()"
},
{
"answer_id": 189931,
"author": "Ray",
"author_id": 233,
"author_profile": "https://Stackoverflow.com/users/233",
"pm_score": 3,
"selected": false,
"text": "var popup = window.open(URL);\nif (popup == null)\n alert('Please change your popup settings');\nelse {\n popup.moveTo(0, 0);\n popup.resizeTo(screen.width, screen.height);\n}\n"
},
{
"answer_id": 44701800,
"author": "Jitendra Tumulu",
"author_id": 3308943,
"author_profile": "https://Stackoverflow.com/users/3308943",
"pm_score": 3,
"selected": false,
"text": "window.open(\"https://www.w3schools.com\", \"_blank\",\"toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=4000,height=4000\");\n"
},
{
"answer_id": 54388433,
"author": "SeekLoad",
"author_id": 7371886,
"author_profile": "https://Stackoverflow.com/users/7371886",
"pm_score": 2,
"selected": false,
"text": "<script language=\"JavaScript\">\nfunction Full_W_P(url) {\n params = 'width='+screen.width;\n params += ', height='+screen.height;\n params += ', top=0, left=0'\n params += ', fullscreen=yes';\n params += ', directories=no';\n params += ', location=no';\n params += ', menubar=no';\n params += ', resizable=no';\n params += ', scrollbars=no';\n params += ', status=no';\n params += ', toolbar=no';\n\n\n newwin=window.open(url,'FullWindowAll', params);\n if (window.focus) {newwin.focus()}\n return false;\n}\n</script>\n\n<input type=\"button\" value=\"Open as Full Window PopUp\" onclick=\"javascript:Full_W_P('http://www.YourLink.com');\"></input>\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3037/"
] |
172,753
|
<p>just wondering if anyone has ever tried embedding and actually integrating any js engine into the .net environment. I could find and actually use (after a <strong>LOT</strong> of pain and effort, since it's pretty outdated and not quite finished) spidermonkey-dotnet project. Anyone with experience in this area? Engines like SquirrelFish, V8.. </p>
<p>Not that I'm not satisfied with Mozilla's Spidermonkey (using it for Rails-like miniframework for custom components inside the core ASP.NET application), but I'd still love to explore a bit further with the options. The command-line solutions are not what I'd need, I cannot rely on anything else than CLR, I need to call methods from/to JavaScript/C# objects.</p>
<pre><code>// c# class
public class A
{
public string Hello(string msg)
{
return msg + " whatewer";
}
}
// js snippet
var a = new A();
console.log(a.Hello('Call me')); // i have a console.log implemented, don't worry, it's not a client-side code :)
</code></pre>
<p>Just to clarify - I'm not trying to actually program <strong>the application itself</strong> in server-side javascript. It's used solely for writing custom user subapplications (can be seen as some sort of DSL). It's much easier (and safer) to allow normal people programming in js than C#.</p>
|
[
{
"answer_id": 3560739,
"author": "Deacon Frost",
"author_id": 389762,
"author_profile": "https://Stackoverflow.com/users/389762",
"pm_score": 3,
"selected": false,
"text": "// Initialize the context\nJavascriptContext context = new JavascriptContext();\n\n// Setting the externals parameters of the context\ncontext.SetParameter(\"console\", new SystemConsole());\ncontext.SetParameter(\"message\", \"Hello World !\");\ncontext.SetParameter(\"number\", 1);\n\n// Running the script\ncontext.Run(\"var i; for (i = 0; i < 5; i++) console.Print(message + ' (' + i + ')'); number += i;\");\n\n// Getting a parameter\nConsole.WriteLine(\"number: \" + context.GetParameter(\"number\"));\n"
},
{
"answer_id": 6588605,
"author": "sanosdole",
"author_id": 543682,
"author_profile": "https://Stackoverflow.com/users/543682",
"pm_score": 2,
"selected": false,
"text": "var a=A.createA(); var a=new A()"
},
{
"answer_id": 8360394,
"author": "Simon Mourier",
"author_id": 403671,
"author_profile": "https://Stackoverflow.com/users/403671",
"pm_score": 2,
"selected": false,
"text": "Console.WriteLine(ScriptEngine.Eval(\"jscript\", \"1+2/3\"));\n"
},
{
"answer_id": 12097394,
"author": "ahmadali shafiee",
"author_id": 1003464,
"author_profile": "https://Stackoverflow.com/users/1003464",
"pm_score": -1,
"selected": false,
"text": "ASP.Net MVC4 Razor // c# class\npublic class A\n{\n public string Hello(string msg)\n {\n return msg + \" whatewer\";\n }\n}\n\n// js snippet\n<script type=\"text/javascript\">\nvar a = new A();\nconsole.log('@a.Hello('Call me')'); // i have a console.log implemented, don't worry, it's not a client-side code :)\n</script>\n Razor"
},
{
"answer_id": 14828241,
"author": "Necowood",
"author_id": 1583954,
"author_profile": "https://Stackoverflow.com/users/1583954",
"pm_score": 1,
"selected": false,
"text": "ScriptRunningMachine srm = new ScriptRunningMachine();\nsrm.Run(\" alert('hello world!'); \");\n import System.Windows.Forms.*; // import namespace\n\nvar f = new Form(); // create form\nf.click = function() { f.close(); }; // close when user clicked on form\n\nf.show(); // show \n"
},
{
"answer_id": 31548921,
"author": "sinanguler",
"author_id": 2011479,
"author_profile": "https://Stackoverflow.com/users/2011479",
"pm_score": 3,
"selected": false,
"text": ".dll .dll \\Support .dll class EvalClass { function Evaluate(expression: String) { return eval(expression); } } \n C:\\MyEval.js Cd\\ C:\\ jsc /t:library C:\\MyEval.js\n MyEval.dll MyEval.dll Microsoft.Jscript.dll Dim jScriptEvaluator As New EvalClass\nDim objResult As Object\nobjResult = jScriptEvaluator.Evaluate(“1==1 && 2==2”)\n True"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172753",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25339/"
] |
172,777
|
<p>We're all familiar with the pre- and post-increment operators, e.g.</p>
<pre><code>c++; // c = c + 1
++c; // ditto
</code></pre>
<p>and the "combined operators" which extend this principle:</p>
<pre><code>c += 5; // c = c + 5
s .= ", world"; // s = s . ", world"; e.g. PHP
</code></pre>
<p>I've often had a need for a 'post-combined operator', which would allow:</p>
<pre><code>s =. "Hello "; // s = "Hello " . s
</code></pre>
<p>Obviously, this is only really useful with non-commutable operators and the meaning is altered from pre-/post-increment, even though the syntax is borrowed.</p>
<p>Are you aware of any language that offers such an operator, and why isn't it more common?</p>
|
[
{
"answer_id": 172792,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": "a=-5; //'a = -5' or 'a =- 5'?\nb=*p; //'b = *p' or 'b =* p'?\nc=.5; //'c = .5' or 'c =. 5'?\n"
},
{
"answer_id": 172799,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 0,
"selected": false,
"text": "x=x+1;\n x+=1;\n x++;\n"
},
{
"answer_id": 172839,
"author": "Zed",
"author_id": 19202,
"author_profile": "https://Stackoverflow.com/users/19202",
"pm_score": 2,
"selected": false,
"text": "var = var op predicate '.' textvar /= newtext textobj = textobj->prepend(newtext) unshift"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172777",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5058/"
] |
172,781
|
<p>My normal work flow to create a new repository with subversion is to create a new repos, do a checkout of the repos root, create my branches tags and trunk folders and place in the trunk my initial files. Then I do a commit of this "initial import", delete the checked out repos from my hard drive and do a checkout of the trunk. Then I can start working.</p>
<p>However, when dealing with a large import, think hundreds of megs, and off-site version control hosting (http based) this initial import can take quite a while to commit. What's worse, after committing I need to checkout this massive trunk all over again.</p>
<p>Is there a way with subversion to use the local copy of the trunk without doing a checkout all over again of data that is already there?</p>
|
[
{
"answer_id": 172786,
"author": "antik",
"author_id": 1625,
"author_profile": "https://Stackoverflow.com/users/1625",
"pm_score": 1,
"selected": false,
"text": "svn add svn commit"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21406/"
] |
172,812
|
<p>I have the following style in an external CSS file called first.css</p>
<pre><code>table { width: 100%; }
</code></pre>
<p>This makes the tables fill their container. If there are only two small columns they appear too far from each other.</p>
<p>To force the columns to appear nearer I have added this style</p>
<pre><code>table { width: 50%; }
</code></pre>
<p>to a new file called second.css and linked it into the html file.</p>
<p>Is there any way to override the width property in first.css without the need to specify a width in second.css?</p>
<p>I would like the html behave as if there has never been a width property, but I do not want to modify first.css</p>
|
[
{
"answer_id": 172816,
"author": "Bobby Jack",
"author_id": 5058,
"author_profile": "https://Stackoverflow.com/users/5058",
"pm_score": 6,
"selected": true,
"text": "table { width: auto; }\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172812",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14755/"
] |
172,821
|
<p>I've got a div that contains some content that's being added and removed dynamically, so its height is changing often. I also have a div that is absolutely positioned directly underneath with javascript, so unless I can detect when the height of the div changes, I can't reposition the div below it.</p>
<p>So, how can I detect when the height of that div changes? I assume there's some jQuery event I need to use, but I'm not sure which one to hook into.</p>
|
[
{
"answer_id": 173349,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 5,
"selected": false,
"text": "$(something).bind('DOMSubtreeModified' ...\n"
},
{
"answer_id": 16654445,
"author": "Kyle",
"author_id": 1098557,
"author_profile": "https://Stackoverflow.com/users/1098557",
"pm_score": 5,
"selected": false,
"text": "$('#your-resizing-div').bind('getheight', function() {\n $('#your-resizing-div').height();\n});\n\nfunction your_function_to_load_content() {\n /*whatever your thing does*/\n $('#your-resizing-div').trigger('getheight');\n}\n"
},
{
"answer_id": 18063124,
"author": "apaul",
"author_id": 1947286,
"author_profile": "https://Stackoverflow.com/users/1947286",
"pm_score": 3,
"selected": false,
"text": ".append() $('.class1').click(function () {\n $('.class1').append(\"<div class='newClass'><h1>This is some content</h1></div>\");\n $('.class2').css('top', $('.class1').offset().top + $('.class1').outerHeight());\n});\n"
},
{
"answer_id": 18084164,
"author": "Selvakumar Arumugam",
"author_id": 297641,
"author_profile": "https://Stackoverflow.com/users/297641",
"pm_score": 6,
"selected": false,
"text": "$(function () {\n var prevHeight = $('#test').height();\n $('#test').attrchange({\n callback: function (e) {\n var curHeight = $(this).height(); \n if (prevHeight !== curHeight) {\n $('#logger').text('height changed from ' + prevHeight + ' to ' + curHeight);\n\n prevHeight = curHeight;\n } \n }\n }).resizable();\n});\n (function(e){function t(){var e=document.createElement(\"p\");var t=false;if(e.addEventListener)e.addEventListener(\"DOMAttrModified\",function(){t=true},false);else if(e.attachEvent)e.attachEvent(\"onDOMAttrModified\",function(){t=true});else return false;e.setAttribute(\"id\",\"target\");return t}function n(t,n){if(t){var r=this.data(\"attr-old-value\");if(n.attributeName.indexOf(\"style\")>=0){if(!r[\"style\"])r[\"style\"]={};var i=n.attributeName.split(\".\");n.attributeName=i[0];n.oldValue=r[\"style\"][i[1]];n.newValue=i[1]+\":\"+this.prop(\"style\")[e.camelCase(i[1])];r[\"style\"][i[1]]=n.newValue}else{n.oldValue=r[n.attributeName];n.newValue=this.attr(n.attributeName);r[n.attributeName]=n.newValue}this.data(\"attr-old-value\",r)}}var r=window.MutationObserver||window.WebKitMutationObserver;e.fn.attrchange=function(i){var s={trackValues:false,callback:e.noop};if(typeof i===\"function\"){s.callback=i}else{e.extend(s,i)}if(s.trackValues){e(this).each(function(t,n){var r={};for(var i,t=0,s=n.attributes,o=s.length;t<o;t++){i=s.item(t);r[i.nodeName]=i.value}e(this).data(\"attr-old-value\",r)})}if(r){var o={subtree:false,attributes:true,attributeOldValue:s.trackValues};var u=new r(function(t){t.forEach(function(t){var n=t.target;if(s.trackValues){t.newValue=e(n).attr(t.attributeName)}s.callback.call(n,t)})});return this.each(function(){u.observe(this,o)})}else if(t()){return this.on(\"DOMAttrModified\",function(e){if(e.originalEvent)e=e.originalEvent;e.attributeName=e.attrName;e.oldValue=e.prevValue;s.callback.call(this,e)})}else if(\"onpropertychange\"in document.body){return this.on(\"propertychange\",function(t){t.attributeName=window.event.propertyName;n.call(e(this),s.trackValues,t);s.callback.call(this,t)})}return this}})(jQuery)\n"
},
{
"answer_id": 26440831,
"author": "Marc J. Schmidt",
"author_id": 979328,
"author_profile": "https://Stackoverflow.com/users/979328",
"pm_score": 6,
"selected": false,
"text": "new ResizeSensor(jQuery('#myElement'), function() {\n console.log('myelement has been resized');\n});\n"
},
{
"answer_id": 26558390,
"author": "EFernandes",
"author_id": 1251884,
"author_profile": "https://Stackoverflow.com/users/1251884",
"pm_score": 5,
"selected": false,
"text": "MutationObserver MutationObserver // select the target node\nvar target = document.querySelector('#some-id');\n\n// create an observer instance\nvar observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(mutation) {\n console.log(mutation.type);\n }); \n});\n\n// configuration of the observer:\nvar config = { attributes: true, childList: true, characterData: true };\n\n// pass in the target node, as well as the observer options\nobserver.observe(target, config);\n\n// later, you can stop observing\nobserver.disconnect();\n"
},
{
"answer_id": 30597601,
"author": "Estefano Salazar",
"author_id": 1301550,
"author_profile": "https://Stackoverflow.com/users/1301550",
"pm_score": 2,
"selected": false,
"text": "function someJsClass()\n{\n var _resizeInterval = null;\n var _lastHeight = 0;\n var _lastWidth = 0;\n \n this.Initialize = function(){\n var _resizeInterval = setInterval(_resizeIntervalTick, 200);\n };\n \n this.Stop = function(){\n if(_resizeInterval != null)\n clearInterval(_resizeInterval);\n };\n \n var _resizeIntervalTick = function () {\n if ($(yourDiv).width() != _lastWidth || $(yourDiv).height() != _lastHeight) {\n _lastWidth = $(contentBox).width();\n _lastHeight = $(contentBox).height();\n DoWhatYouWantWhenTheSizeChange();\n }\n };\n}\n\nvar class = new someJsClass();\nclass.Initialize();"
},
{
"answer_id": 45993134,
"author": "Ronald Rivera",
"author_id": 7003737,
"author_profile": "https://Stackoverflow.com/users/7003737",
"pm_score": 0,
"selected": false,
"text": "$(element).bind('DOMSubtreeModified', function () {\n var $this = this;\n var updateHeight = function () {\n var Height = $($this).height();\n console.log(Height);\n };\n setTimeout(updateHeight, 2000);\n});"
},
{
"answer_id": 48829361,
"author": "Zac",
"author_id": 3780493,
"author_profile": "https://Stackoverflow.com/users/3780493",
"pm_score": 0,
"selected": false,
"text": "function dynamicHeight() {\n var height = jQuery('').height();\n jQuery('.edito-wrapper').css('height', editoHeight);\n}\neditoHeightSize();\n\njQuery(window).resize(function () {\n editoHeightSize();\n});\n"
},
{
"answer_id": 65132782,
"author": "gitaarik",
"author_id": 1248175,
"author_profile": "https://Stackoverflow.com/users/1248175",
"pm_score": 2,
"selected": false,
"text": "ResizeObserver const myElement = document.querySelector('#myElement');\n\nconst resizeObserver = new ResizeObserver(() => {\n console.log('size of myElement changed');\n});\n\nresizeObserver.observe(myElement);\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1384/"
] |
172,831
|
<p>If you have the following:</p>
<pre><code>$var = 3; // we'll say it's set to 3 for this example
if ($var == 4) {
// do something
} else if ($var == 5) {
// do something
} else if ($var == 2) {
// do something
} else if ($var == 3) {
// do something
} else {
// do something
}
</code></pre>
<p>If say 80% of the time <code>$var</code> is 3, do you worry about the fact that it's going through 4 if cases before finding the true case?</p>
<p>I'm thinking on a small site it's not a big deal, but what about when that if statement is going to run 1000s of times a second?</p>
<p>I'm working in PHP, but I'm thinking the language doesn't matter.</p>
|
[
{
"answer_id": 172870,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 5,
"selected": true,
"text": "if var <= 3:\n if var == 2:\n # do something\n elif var == 3:\n # do something\n else: \n raise Exception\nelse:\n if var == 4:\n # do something\n elif var == 5:\n # do something\n else:\n raise Exception\n"
},
{
"answer_id": 173029,
"author": "UnkwnTech",
"author_id": 115,
"author_profile": "https://Stackoverflow.com/users/115",
"pm_score": 0,
"selected": false,
"text": "$var = 3; // we'll say it's set to 3 for this example\nswitch($var)\n {\n case 4:\n //do something\n break;\n case 5:\n //do something\n break;\n case:\n //do something when none of the provided cases match (same as using an else{ after the elseif{\n }\n"
},
{
"answer_id": 173037,
"author": "Jon Limjap",
"author_id": 372,
"author_profile": "https://Stackoverflow.com/users/372",
"pm_score": 0,
"selected": false,
"text": "//do something"
},
{
"answer_id": 175626,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 1,
"selected": false,
"text": "our @code_blocks = (\n { 'Code Block 0' },\n { 'Code Block 1' },\n { 'Code Block 2' },\n { 'Code Block 3' },\n { 'Code Block 4' },\n { 'Code Block 5' },\n);\n\nif( 0 <= $var < @code_blocks.length ){\n @code_blocks[$var]->();\n}\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172831",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
172,841
|
<p>I have applied a <code>Formatter</code> to a <code>JFormattedTextField</code> using a <code>FormatterFactory</code>, when a user clicks into the text field I want to select the contents. </p>
<p>A focus listener does not work as expected because the formatter gets called, which eventually causes the value to be reset which ultimately de-selects the fields contents. I think what is happening is that after the value changes, the Caret moves to the rightmost position and this deselects the field.</p>
<p>Does anyone have any knowledge of how to get around this and select the fields contents correctly?</p>
|
[
{
"answer_id": 190302,
"author": "Peter",
"author_id": 26483,
"author_profile": "https://Stackoverflow.com/users/26483",
"pm_score": 3,
"selected": true,
"text": " EventQueue.invokeLater(new Runnable(){\n public void run() { yourTextField.selectAll();}\n});\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172841",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18445/"
] |
172,854
|
<p>I have a Boost unit test case which causes the object under test to throw an exception (that's the test, to cause an exception). How do I specify in the test to expect that particular exception.</p>
<p>I can specify that the test should have a certain number of failures by using BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES but that seems rather unspecific. I want to be able to say at a specific point in the test that an exception should be thrown and that it should not be counted as a failure.</p>
|
[
{
"answer_id": 172995,
"author": "jonner",
"author_id": 78437,
"author_profile": "https://Stackoverflow.com/users/78437",
"pm_score": 7,
"selected": true,
"text": "BOOST_CHECK_THROW (expression, an_exception_type);\n BOOST_WARN_THROW() BOOST_REQUIRE_THROW()"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4086/"
] |
172,875
|
<p>Basically I'm running some performance tests and don't want the external network to be the drag factor. I'm looking into ways of disabling network LAN. What is an effective way of doing it programmatically? I'm interested in c#. If anyone has a code snippet that can drive the point home that would be cool.</p>
|
[
{
"answer_id": 6170507,
"author": "Melvyn",
"author_id": 755986,
"author_profile": "https://Stackoverflow.com/users/755986",
"pm_score": 5,
"selected": false,
"text": "SelectQuery wmiQuery = new SelectQuery(\"SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL\");\nManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(wmiQuery);\nforeach (ManagementObject item in searchProcedure.Get())\n{\n if (((string)item[\"NetConnectionId\"]) == \"Local Network Connection\")\n {\n item.InvokeMethod(\"Disable\", null);\n }\n}\n"
},
{
"answer_id": 18761206,
"author": "Kamrul Hasan",
"author_id": 1557156,
"author_profile": "https://Stackoverflow.com/users/1557156",
"pm_score": 4,
"selected": false,
"text": " interfaceName is “Local Area Connection”.\n\n static void Enable(string interfaceName)\n {\n System.Diagnostics.ProcessStartInfo psi =\n new System.Diagnostics.ProcessStartInfo(\"netsh\", \"interface set interface \\\"\" + interfaceName + \"\\\" enable\");\n System.Diagnostics.Process p = new System.Diagnostics.Process();\n p.StartInfo = psi;\n p.Start();\n }\n\n static void Disable(string interfaceName)\n {\n System.Diagnostics.ProcessStartInfo psi =\n new System.Diagnostics.ProcessStartInfo(\"netsh\", \"interface set interface \\\"\" + interfaceName + \"\\\" disable\");\n System.Diagnostics.Process p = new System.Diagnostics.Process();\n p.StartInfo = psi;\n p.Start();\n }\n"
},
{
"answer_id": 18762316,
"author": "Kamrul Hasan",
"author_id": 1557156,
"author_profile": "https://Stackoverflow.com/users/1557156",
"pm_score": 1,
"selected": false,
"text": " Private Sub ToggleNetworkConnection()\n\n Try\n\n\n Const ssfCONTROLS = 3\n\n\n Dim sConnectionName = \"Local Area Connection\"\n\n Dim sEnableVerb = \"En&able\"\n Dim sDisableVerb = \"Disa&ble\"\n\n Dim shellApp = CreateObject(\"shell.application\")\n Dim WshShell = CreateObject(\"Wscript.Shell\")\n Dim oControlPanel = shellApp.Namespace(ssfCONTROLS)\n\n Dim oNetConnections = Nothing\n For Each folderitem In oControlPanel.items\n If folderitem.name = \"Network Connections\" Then\n oNetConnections = folderitem.getfolder : Exit For\n End If\n Next\n\n\n If oNetConnections Is Nothing Then\n MsgBox(\"Couldn't find 'Network and Dial-up Connections' folder\")\n WshShell.quit()\n End If\n\n\n Dim oLanConnection = Nothing\n For Each folderitem In oNetConnections.items\n If LCase(folderitem.name) = LCase(sConnectionName) Then\n oLanConnection = folderitem : Exit For\n End If\n Next\n\n\n If oLanConnection Is Nothing Then\n MsgBox(\"Couldn't find '\" & sConnectionName & \"' item\")\n WshShell.quit()\n End If\n\n\n Dim bEnabled = True\n Dim oEnableVerb = Nothing\n Dim oDisableVerb = Nothing\n Dim s = \"Verbs: \" & vbCrLf\n For Each verb In oLanConnection.verbs\n s = s & vbCrLf & verb.name\n If verb.name = sEnableVerb Then\n oEnableVerb = verb\n bEnabled = False\n End If\n If verb.name = sDisableVerb Then\n oDisableVerb = verb\n End If\n Next\n\n\n\n If bEnabled Then\n oDisableVerb.DoIt()\n Else\n oEnableVerb.DoIt()\n End If\n\n\n Catch ex As Exception\n MsgBox(ex.Message)\n End Try\n\nEnd Sub\n"
},
{
"answer_id": 46113403,
"author": "micharaze",
"author_id": 5941260,
"author_profile": "https://Stackoverflow.com/users/5941260",
"pm_score": 0,
"selected": false,
"text": "private void Enable_LocalAreaConection(bool isEnable = true)\n {\n var interfaceName = \"Local Area Connection\";\n string control;\n if (isEnable)\n control = \"enable\";\n else\n control = \"disable\";\n System.Diagnostics.ProcessStartInfo psi =\n new System.Diagnostics.ProcessStartInfo(\"netsh\", \"interface set interface \\\"\" + interfaceName + \"\\\" \" + control);\n System.Diagnostics.Process p = new System.Diagnostics.Process();\n p.StartInfo = psi;\n p.Start();\n p.WaitForExit();\n }\n"
},
{
"answer_id": 48671520,
"author": "Chris Bols",
"author_id": 9329423,
"author_profile": "https://Stackoverflow.com/users/9329423",
"pm_score": 1,
"selected": false,
"text": " static void Disable(string interfaceName)\n {\n\n //set interface name=\"Ethernet\" admin=DISABLE\n System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(\"netsh\", \"interface set interface name=\" + interfaceName + \" admin=DISABLE\");\n System.Diagnostics.Process p = new System.Diagnostics.Process();\n\n p.StartInfo = psi;\n p.Start();\n }\n\n static void Enable(string interfaceName)\n {\n System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(\"netsh\", \"interface set interface name=\" + interfaceName + \" admin=ENABLE\");\n System.Diagnostics.Process p = new System.Diagnostics.Process();\n p.StartInfo = psi;\n p.Start();\n }\n"
},
{
"answer_id": 56611141,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": " System.Diagnostics.Process.Start(\"ipconfig\", \"/release\"); //For disabling internet\n System.Diagnostics.Process.Start(\"ipconfig\", \"/renew\"); //For enabling internet\n"
},
{
"answer_id": 57653626,
"author": "FarhadMohseni",
"author_id": 6899111,
"author_profile": "https://Stackoverflow.com/users/6899111",
"pm_score": 1,
"selected": false,
"text": " static void runCmdCommad(string cmd)\n {\n System.Diagnostics.Process process = new System.Diagnostics.Process();\n System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();\n //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;\n startInfo.FileName = \"cmd.exe\";\n startInfo.Arguments = $\"/C {cmd}\";\n process.StartInfo = startInfo;\n process.Start();\n }\n static void DisableInternet(bool enable)\n {\n string disableNet = \"wmic path win32_networkadapter where PhysicalAdapter=True call disable\";\n string enableNet = \"wmic path win32_networkadapter where PhysicalAdapter=True call enable\";\n runCmdCommad(enable ? enableNet :disableNet);\n }\n"
},
{
"answer_id": 68520653,
"author": "Christopher Vickers",
"author_id": 5905688,
"author_profile": "https://Stackoverflow.com/users/5905688",
"pm_score": 0,
"selected": false,
"text": "//Disable network interface\nstatic public void Disable(string interfaceName)\n{\n System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();\n startInfo.FileName = \"netsh\";\n startInfo.Arguments = $\"interface set interface \\\"{interfaceName}\\\" disable\";\n startInfo.RedirectStandardOutput = true;\n startInfo.RedirectStandardError = true;\n startInfo.UseShellExecute = false;\n startInfo.CreateNoWindow = true;\n System.Diagnostics.Process processTemp = new System.Diagnostics.Process();\n processTemp.StartInfo = startInfo;\n processTemp.EnableRaisingEvents = true;\n try\n {\n processTemp.Start();\n }\n catch (Exception e)\n {\n throw;\n }\n}\n\n//Enable network interface\nstatic public void Enable(string interfaceName)\n{\n System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();\n startInfo.FileName = \"netsh\";\n startInfo.Arguments = $\"interface set interface \\\"{interfaceName}\\\" enable\";\n startInfo.RedirectStandardOutput = true;\n startInfo.RedirectStandardError = true;\n startInfo.UseShellExecute = false;\n startInfo.CreateNoWindow = true;\n System.Diagnostics.Process processTemp = new System.Diagnostics.Process();\n processTemp.StartInfo = startInfo;\n processTemp.EnableRaisingEvents = true;\n try\n {\n processTemp.Start();\n }\n catch (Exception e)\n {\n throw;\n }\n}\n"
}
] |
2008/10/05
|
[
"https://Stackoverflow.com/questions/172875",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
172,888
|
<p>This will hopefully be an easy one. I have an F# project (latest F# CTP) with two files (Program.fs, Stack.fs). In Stack.fs I have a simple namespace and type definition</p>
<p>Stack.fs</p>
<pre><code>namespace Col
type Stack=
...
</code></pre>
<p>Now I try to include the namespace in Program.fs by declaring</p>
<pre><code>open Col
</code></pre>
<p>This doesn't work and gives me the error "The namespace or module Col is not defined." Yet it's defined within the same project. I've got to be missing something obvious</p>
|
[
{
"answer_id": 172896,
"author": "Brian",
"author_id": 19299,
"author_profile": "https://Stackoverflow.com/users/19299",
"pm_score": 8,
"selected": true,
"text": ".fsproj"
},
{
"answer_id": 30610092,
"author": "Benj Sanders",
"author_id": 3594261,
"author_profile": "https://Stackoverflow.com/users/3594261",
"pm_score": 4,
"selected": false,
"text": "<ItemGroup>\n <Compile Include=\"Stack.fs\" />\n <Compile Include=\"Program.fs\" />\n <None Include=\"App.config\" />\n</ItemGroup>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23283/"
] |
172,895
|
<p>Is there any easy way to retrieve table creation DDL from Microsoft Access (2007) or do I have to code it myself using VBA to read the table structure? </p>
<p>I have about 30 tables that we are porting to Oracle and it would make life easier if we could create the tables from the Access definitions.</p>
|
[
{
"answer_id": 173027,
"author": "Richard A",
"author_id": 24355,
"author_profile": "https://Stackoverflow.com/users/24355",
"pm_score": 6,
"selected": true,
"text": "Option Compare Database\nPublic Function TableCreateDDL(TableDef As TableDef) As String\n\n Dim fldDef As Field\n Dim FieldIndex As Integer\n Dim fldName As String, fldDataInfo As String\n Dim DDL As String\n Dim TableName As String\n\n TableName = TableDef.Name\n TableName = Replace(TableName, \" \", \"_\")\n DDL = \"create table \" & TableName & \"(\" & vbCrLf\n With TableDef\n For FieldIndex = 0 To .Fields.Count - 1\n Set fldDef = .Fields(FieldIndex)\n With fldDef\n fldName = .Name\n fldName = Replace(fldName, \" \", \"_\")\n Select Case .Type\n Case dbBoolean\n fldDataInfo = \"nvarchar2\"\n Case dbByte\n fldDataInfo = \"number\"\n Case dbInteger\n fldDataInfo = \"number\"\n Case dbLong\n fldDataInfo = \"number\"\n Case dbCurrency\n fldDataInfo = \"number\"\n Case dbSingle\n fldDataInfo = \"number\"\n Case dbDouble\n fldDataInfo = \"number\"\n Case dbDate\n fldDataInfo = \"date\"\n Case dbText\n fldDataInfo = \"nvarchar2(\" & Format$(.Size) & \")\"\n Case dbLongBinary\n fldDataInfo = \"****\"\n Case dbMemo\n fldDataInfo = \"****\"\n Case dbGUID\n fldDataInfo = \"nvarchar2(16)\"\n End Select\n End With\n If FieldIndex > 0 Then\n DDL = DDL & \", \" & vbCrLf\n End If\n DDL = DDL & \" \" & fldName & \" \" & fldDataInfo\n Next FieldIndex\n End With\n DDL = DDL & \");\"\n TableCreateDDL = DDL\nEnd Function\n\n\nSub ExportAllTableCreateDDL()\n\n Dim lTbl As Long\n Dim dBase As Database\n Dim Handle As Integer\n\n Set dBase = CurrentDb\n\n Handle = FreeFile\n\n Open \"c:\\export\\TableCreateDDL.txt\" For Output Access Write As #Handle\n\n For lTbl = 0 To dBase.TableDefs.Count - 1\n 'If the table name is a temporary or system table then ignore it\n If Left(dBase.TableDefs(lTbl).Name, 1) = \"~\" Or _\n Left(dBase.TableDefs(lTbl).Name, 4) = \"MSYS\" Then\n '~ indicates a temporary table\n 'MSYS indicates a system level table\n Else\n Print #Handle, TableCreateDDL(dBase.TableDefs(lTbl))\n End If\n Next lTbl\n Close Handle\n Set dBase = Nothing\nEnd Sub\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24355/"
] |
172,906
|
<p>I'd like to take XML in the format below and load each code record into a domain object in my <code>BootStrap.groovy</code>. I want to preserve the formatting of each snippet of code. </p>
<h2>XML</h2>
<pre><code><records>
<code>
<language>Groovy</language>
<snippet>
println "This is Groovy"
println "A very powerful language"
</snippet>
</code>
<code>
<language>Groovy</language>
<snippet>
3.times {
println "hello"
}
</snippet>
</code>
<code>
<language>Perl</language>
<snippet>
@foo = split(",");
</snippet>
</code>
</records>
</code></pre>
<h2>Domain Object</h2>
<pre><code>Code {
String language
String snippet
}
</code></pre>
<h2>BootStrap.groovy</h2>
<pre><code>new Code(language l, snippet: x).save()
</code></pre>
|
[
{
"answer_id": 172972,
"author": "mbrevoort",
"author_id": 18228,
"author_profile": "https://Stackoverflow.com/users/18228",
"pm_score": 2,
"selected": true,
"text": "def CODE_XML = '''\n<records>\n <code>\n <language>Groovy</language>\n <snippet>\n println \"This is Groovy\"\n println \"A very powerful language\"\n </snippet>\n </code>\n <code>\n <language>Groovy</language>\n <snippet>\n 3.times {\n println \"hello\"\n }\n </snippet>\n </code>\n <code>\n <language>Perl</language>\n <snippet>\n @foo = split(\",\");\n </snippet>\n </code>\n</records>\n '''\ndef records = new XmlParser().parseText(CODE_XML)\nrecords.code.each() { code ->\n new Code(language: code.language, snippet: code.snippet).save()\n}\n"
},
{
"answer_id": 194692,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 0,
"selected": false,
"text": "xml:space=\"preserve\" <snippet>"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
172,908
|
<p>I'm trying to call a web service from Excel 2003 module.
The way i've implemented it is creating a .NET COM library with all the classes/methods i need to be exposed.
When i try to call a method that queries a web service from Excel the execution just stops on that line without any error.
May be it has to do with references? I'm using Microsoft.Web.Services2.dll. I have tried putting it in C:\WINDOWS\SYSTEM32 - no luck</p>
|
[
{
"answer_id": 175502,
"author": "Andrew Cowenhoven",
"author_id": 12281,
"author_profile": "https://Stackoverflow.com/users/12281",
"pm_score": 2,
"selected": false,
"text": "\n\n[Guid(\"123Fooetc...\")]\n [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]\n public interface IBar\n {\n [DispId(1)]\n void SomeMethod(Excel.Range someRange);\n }\n \n[Guid(\"345Fooetc..\")]\n [ClassInterface(ClassInterfaceType.None)]\n [ProgId(\"MyNameSpace.MyClass\")] \n public class MyClass : IBar\n {\n public void SomeMethod(Excel.Range someRange)\n {...}\n }\n \n string resource = yourUrl;\n using (WebClient web = new WebClient())\n {\n web.Credentials = CredentialCache.DefaultCredentials;\n someXml = web.DownloadString(resource);\n }\n return someXml; // or do something interesting with Excel range\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172908",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10793/"
] |
172,918
|
<p>I have a container div that holds two internal divs; both should take 100% width and 100% height within the container.</p>
<p>I set both internal divs to 100% height. That works fine in Firefox, however in IE the divs do not stretch to 100% height but only the height of the text inside them.</p>
<p>The following is a simplified version of my style sheet.</p>
<pre><code>#container
{
height: auto;
width: 100%;
}
#container #mainContentsWrapper
{
float: left;
height: 100%;
width: 70%;
margin: 0;
padding: 0;
}
#container #sidebarWrapper
{
float: right;
height: 100%;
width: 29.7%;
margin: 0;
padding: 0;
}
</code></pre>
<p>Is there something I am doing wrong? Or any Firefox/IE quirks I am missing out?</p>
|
[
{
"answer_id": 172923,
"author": "Jarett Millard",
"author_id": 15882,
"author_profile": "https://Stackoverflow.com/users/15882",
"pm_score": 1,
"selected": false,
"text": "html { height:100%; }\n body { height:100%; }\n"
},
{
"answer_id": 174208,
"author": "Ian Oxley",
"author_id": 1904,
"author_profile": "https://Stackoverflow.com/users/1904",
"pm_score": 0,
"selected": false,
"text": "#container {\n height:100%;\n width:100%;\n overflow:hidden;\n /* for IE */\n zoom:1;\n}\n"
},
{
"answer_id": 174611,
"author": "casademora",
"author_id": 5619,
"author_profile": "https://Stackoverflow.com/users/5619",
"pm_score": 2,
"selected": false,
"text": "#container\n{\n margin: 0 px;\n}\n"
},
{
"answer_id": 176454,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 7,
"selected": true,
"text": "#container { height: auto; }\n#container #mainContentsWrapper { height: n%; }\n#container #sidebarWrapper { height: n%; }\n #container { height: auto; }\n#container #mainContentsWrapper { height: auto; }\n#container #sidebarWrapper { height: auto; }\n html, body { height:100%; }\n#container { height:100%; }\n"
},
{
"answer_id": 1906711,
"author": "Designerfoo",
"author_id": 232030,
"author_profile": "https://Stackoverflow.com/users/232030",
"pm_score": 0,
"selected": false,
"text": "#container\n{\n height: auto;\n min-height:100%;\n width: 100%;\n}\n\n#container #mainContentsWrapper\n{\n float: left;\n\n height: auto;\n min-height:100%\n width: 70%;\n margin: 0;\n padding: 0;\n}\n\n\n#container #sidebarWrapper\n{ \n float: right;\n\n height: auto;\n min-height:100%\n width: 29.7%;\n margin: 0;\n padding: 0;\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/131/"
] |
172,921
|
<p>In order to create an arbitrary precision floating point / drop in replacement for Double, I'm trying to wrap <a href="http://www.mpfr.org/" rel="nofollow noreferrer">MPFR</a> using the FFI but despite all my efforts the simplest bit of code doesn't work. It compiles, it runs, but it crashes mockingly after pretending to work for a while. A simple C version of the code happily prints the number "1" to (640 decimal places) a total of 10,000 times. The Haskell version, when asked to do the same, silently corrupts (?) the data after only 289 print outs of "1.0000...0000" and after 385 print outs, it causes an assertion failure and bombs. I'm at a loss for how to proceed in debugging this since it "should work".</p>
<p>The code can be perused at <a href="http://hpaste.org/10923" rel="nofollow noreferrer">http://hpaste.org/10923</a> and downloaded at <a href="http://www.updike.org/mpfr-broken.tar.gz" rel="nofollow noreferrer">http://www.updike.org/mpfr-broken.tar.gz</a></p>
<p>I'm using GHC 6.83 on FreeBSD 6 and GHC 6.8.2 on Mac OS X. Note you will need MPFR (tested with 2.3.2) installed with the correct paths (change the Makefile) for libs and header files (along with those from GMP) to successfully compile this.</p>
<h2>Questions</h2>
<ul>
<li><p>Why does the C version work, but the Haskell version flake out? What else am I missing when approaching the FFI? I tried StablePtrs and had the exact same results.</p></li>
<li><p>Can someone else verify if this is a Mac/BSD only problem by compiling and running my code? (Does the C code "works" work? Does the Haskell code "noworks" work?) Can anyone on Linux and Windows attempt to compile/run and see if you get the same results?</p></li>
</ul>
<p>C code: (works.c)</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
#include <mpfr.h>
#include "mpfr_ffi.c"
int main()
{
int i;
mpfr_ptr one;
mpf_set_default_prec_decimal(640);
one = mpf_set_signed_int(1);
for (i = 0; i < 10000; i++)
{
printf("%d\n", i);
mpf_show(one);
}
}
</code></pre>
<p>Haskell code: (Main.hs --- doesn't work)</p>
<pre><code>module Main where
import Foreign.Ptr ( Ptr, FunPtr )
import Foreign.C.Types ( CInt, CLong, CULong, CDouble )
import Foreign.StablePtr ( StablePtr )
data MPFR = MPFR
foreign import ccall "mpf_set_default_prec_decimal"
c_set_default_prec_decimal :: CInt -> IO ()
setPrecisionDecimal :: Integer -> IO ()
setPrecisionDecimal decimal_digits = do
c_set_default_prec_decimal (fromInteger decimal_digits)
foreign import ccall "mpf_show"
c_show :: Ptr MPFR -> IO ()
foreign import ccall "mpf_set_signed_int"
c_set_signed_int :: CLong -> IO (Ptr MPFR)
showNums k n = do
print n
c_show k
main = do
setPrecisionDecimal 640
one <- c_set_signed_int (fromInteger 1)
mapM_ (showNums one) [1..10000]
</code></pre>
|
[
{
"answer_id": 173249,
"author": "ephemient",
"author_id": 20713,
"author_profile": "https://Stackoverflow.com/users/20713",
"pm_score": 3,
"selected": true,
"text": "$ uname -a\nLinux burnup 2.6.26-gentoo-r1 #1 SMP PREEMPT Tue Sep 9 00:05:54 EDT 2008 i686 Intel(R) Pentium(R) 4 CPU 2.80GHz GenuineIntel GNU/Linux\n$ gcc --version\ngcc (GCC) 4.2.4 (Gentoo 4.2.4 p1.0)\n$ ghc --version\nThe Glorious Glasgow Haskell Compilation System, version 6.8.3\n main = do\n setPrecisionDecimal 640\n mapM_ (const $ c_set_signed_int (fromInteger 1) >>= c_show) [1..10000]\n one ghc -C ghc -S ./noworks +RTS -H1G ./noworks +RTS -k[n]k [n]"
},
{
"answer_id": 175490,
"author": "Jared Updike",
"author_id": 2543,
"author_profile": "https://Stackoverflow.com/users/2543",
"pm_score": 1,
"selected": false,
"text": "mpfr_ptr mpf_new_mpfr() \n{ \n mpfr_ptr result = malloc(sizeof(__mpfr_struct)); \n if (result == NULL) return NULL; \n /// these three lines: \n mp_limb_t * limb = malloc(mpfr_custom_get_size(mpfr_get_default_prec())); \n mpfr_custom_init(limb, mpfr_get_default_prec()); \n mpfr_custom_init_set(result, MPFR_NAN_KIND, 0, mpfr_get_default_prec(), limb); \n return result; \n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2543/"
] |
172,934
|
<p>I need to retrieve a set of Widgets from my data access layer, grouped by widget.Manufacturer, to display in a set of nested ASP.NET ListViews.</p>
<p>The problem is that (as far as I can tell) the nested ListView approach requires me to shape the data before using it, and I can't figure out the best approach to take. The best I've been able to come up with so far is to put a LINQ query in my data access layer like so:</p>
<pre><code>var result = from widget in GetAllWidgets(int widgetTypeID)
group widget by widget.Manufacturer into groupedWidgets
let widgets = from widgetGroup in groupedWidgets
select widgetGroup
select new { Manufacturer = groupedWidgets.Key, Widgets = widgets };
</code></pre>
<p>Of course, anonymous types can't be passed around, so that doesn't work. Defining a custom class to enclose data seems like the wrong way to go. Is there some way I can perform the grouping on the ASP.NET side of things? I'm using ObjectDataSources to access the DAL.</p>
<p><b>Updated</b>: OK, I'm not creating an anonymous type anymore, and instead my DAL passes an <code>IEnumerable<IGrouping<Manufacturer, Widget>></code> to the ASP.NET page, but how can I use this in my ListViews? I need to render the following HTML (or something pretty much like it)</p>
<pre><code><ul>
<li>Foo Corp.
<ol>
<li>Baz</li>
<li>Quux</li>
</ol>
</li>
<li>Bar Corp.
<ol>
<li>Thinger</li>
<li>Whatsit</li>
</ol>
</li>
</ul>
</code></pre>
<p>Originally, I had a ListView within a ListView like so:</p>
<pre><code><asp:ListView ID="ManufacturerListView">
<LayoutTemplate>
<ul>
<asp:Placeholder ID="itemPlaceholder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><asp:Label Text='<%# Eval("Manufacturer.Name") %>' />
<li>
<asp:ListView ID="WidgetsListView" runat="server" DataSource='<%# Eval("Widgets") %>'>
<LayoutTemplate>
<ol>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</ol>
</LayoutTemplate>
<ItemTemplate>
<li><asp:Label Text='<%# Eval("Name") %>'></li>
</ItemTemplate>
</asp:ListView>
</li>
</ItemTemplate>
</asp:ListView>
</code></pre>
<p>Note how the <code>DataSource</code> property of WidgetsListView is itself databound. How can I duplicate this functionality without reshaping the data?</p>
<p>This is getting kind of complicated, sorry if I should have just made a separate question instead.</p>
|
[
{
"answer_id": 173177,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 2,
"selected": false,
"text": "List<int> myInts = new List<int>() { 1, 2, 3, 4, 5 };\nIEnumerable<IGrouping<int, int>> myGroups = myInts.GroupBy(i => i % 2);\nforeach (IGrouping<int, int> g in myGroups)\n{\n Console.WriteLine(g.Key);\n foreach (int i in g)\n {\n Console.WriteLine(\" {0}\", i);\n }\n}\nConsole.ReadLine();\n IEnumerable<IGrouping<Manufacturer, Widget>> result =\n GetAllWidgets(widgetTypeId).GroupBy(w => w.Manufacturer);\n"
},
{
"answer_id": 177279,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 5,
"selected": true,
"text": "public class CustomGroup<TKey, TValue>\n{\n public TKey Key {get;set;}\n public IEnumerable<TValue> Values {get;set;}\n}\n IEnumerable<CustomGroup<Manufacturer, Widget>> result =\n GetAllWidgets(widgetTypeId)\n .GroupBy(w => w.Manufacturer)\n .Select(g => new CustomGroup<Manufacturer, Widget>(){Key = g.Key, Values = g};\n <asp:ListView ID=\"ManufacturerListView\">\n<LayoutTemplate>\n <ul>\n <asp:Placeholder ID=\"itemPlaceholder\" runat=\"server\" />\n </ul>\n</LayoutTemplate>\n<ItemTemplate>\n <li><asp:Label Text='<%# Eval(\"Key.Name\") %>' />\n <li>\n <asp:ListView ID=\"WidgetsListView\" runat=\"server\" DataSource='<%# Eval(\"Values\") %>'>\n <LayoutTemplate>\n <ol>\n <asp:PlaceHolder runat=\"server\" ID=\"itemPlaceholder\" />\n </ol>\n </LayoutTemplate>\n <ItemTemplate>\n <li><asp:Label Text='<%# Eval(\"Name\") %>'></li>\n </ItemTemplate>\n </asp:ListView>\n </li>\n</ItemTemplate>\n</asp:ListView>\n"
},
{
"answer_id": 1304807,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "var enumerableData = myData.Tables[0].AsEnumerable();\nvar groupedData = enumerableData.GroupBy(x => x[\"GroupingColumn\"]);\n\nmyParentRepeater.DataSource = groupedData;\nmyParentRepeater.DataBind();\n <asp:Repeater ID=\"myParentRepeater\" runat=\"server\">\n <ItemTemplate>\n <h3><%#Eval(\"Key\") %></h3>\n <asp:Repeater ID=\"myChildRepeater\" runat=\"server\" DataSource='<%# Container.DataItem %>'>\n <ItemTemplate>\n <%#((DataRow)Container.DataItem)[\"ChildDataColumn1\"] %>\n <%#((DataRow)Container.DataItem)[\"ChildDataColumn2\"] %>\n </ItemTemplate>\n <SeparatorTemplate>\n <br />\n </SeparatorTemplate>\n </asp:Repeater>\n </ItemTemplate>\n</asp:Repeater>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172934",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4160/"
] |
172,935
|
<p>After understanding (quote), I'm curious as to how one might cause the statement to execute. My first thought was</p>
<pre><code>(defvar x '(+ 2 21))
`(,@x)
</code></pre>
<p>but that just evaluates to <code>(+ 2 21)</code>, or the contents of <code>x</code>. How would one run code that was placed in a list?</p>
|
[
{
"answer_id": 172939,
"author": "Rich",
"author_id": 22003,
"author_profile": "https://Stackoverflow.com/users/22003",
"pm_score": 5,
"selected": true,
"text": "(eval '(+ 2 21))"
},
{
"answer_id": 175970,
"author": "Rich",
"author_id": 22003,
"author_profile": "https://Stackoverflow.com/users/22003",
"pm_score": 0,
"selected": false,
"text": "(eval `(and ,@(loop for x from 1 upto 4 collect `(evenp ,x))))\n (eval '(and (evenp 1) (evenp 2) (evenp 3) (evenp 4)))\n (every 'evenp '(1 2 3 4))\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172935",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1256/"
] |
172,948
|
<p>Anyone have any idea how to do the following?</p>
<p>declare cursor
open cursor
fetch cursor
<< Start reading the cursor in a LOOP >>
Lets say the cursor have 10 records.
Read until 5th record then go to the 6th record and do some checking.</p>
<p>Now, is it possible to go back to 5th record from 6th record ?</p>
|
[
{
"answer_id": 173036,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 3,
"selected": false,
"text": "SQL> ed\nWrote file afiedt.buf\n\n 1 select ename,\n 2 sal,\n 3 lead(sal) over (order by ename) next_sal,\n 4 lag(sal) over (order by ename) prior_sal\n 5 from emp\n 6* order by ename\nSQL> /\n\nENAME SAL NEXT_SAL PRIOR_SAL\n---------- ---------- ---------- ----------\nADAMS 1100 1600\nALLEN 1600 2850 1100\nBLAKE 2850 2450 1600\nCLARK 2450 3000 2850\nFORD 3000 950 2450\nJAMES 950 2975 3000\nJONES 2975 5000 950\nKING 5000 1250 2975\nMARTIN 1250 1300 5000\nMILLER 1300 3000 1250\nSCOTT 3000 800 1300\n\nENAME SAL NEXT_SAL PRIOR_SAL\n---------- ---------- ---------- ----------\nSMITH 800 1500 3000\nTURNER 1500 1250 800\nWARD 1250 1500\n\n14 rows selected.\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25368/"
] |
172,957
|
<p>I just set up my new homepage at <a href="http://ritter.vg" rel="noreferrer">http://ritter.vg</a>. I'm using jQuery, but very minimally.<br>
It loads all the pages using AJAX - I have it set up to allow bookmarking by detecting the hash in the URL. </p>
<pre><code> //general functions
function getUrl(u) {
return u + '.html';
}
function loadURL(u) {
$.get(getUrl(u), function(r){
$('#main').html(r);
}
);
}
//allows bookmarking
var hash = new String(document.location).indexOf("#");
if(hash > 0)
{
page = new String(document.location).substring(hash + 1);
if(page.length > 1)
loadURL(page);
else
loadURL('news');
}
else
loadURL('news');
</code></pre>
<p>But I can't get the back and forward buttons to work. </p>
<p>Is there a way to detect when the back button has been pressed (or detect when the hash changes) without using a setInterval loop? When I tried those with .2 and 1 second timeouts, it pegged my CPU.</p>
|
[
{
"answer_id": 5708124,
"author": "Eugene Kerner",
"author_id": 597686,
"author_profile": "https://Stackoverflow.com/users/597686",
"pm_score": 1,
"selected": false,
"text": "// Add code below ...\nfunction locationHashChanged(qs)\n{\n var q = parseQs(qs);\n // ADD SOME CODE HERE TO LOAD YOUR PAGE ELEMS AS PER q !!\n // YOU SHOULD CATER FOR EACH hashQuery ATTRS COMBINATION\n // THAT IS PASSED TO changeHashValue(hashQuery)\n}\n\n// CALL THIS FROM YOUR AJAX LOAD CODE EACH LOAD ...\nfunction changeHashValue(hashQuery)\n{\n stopHashListener();\n hashValue = hashQuery;\n location.hash = hashQuery;\n startHashListener();\n}\n\n// AND DONT WORRY ABOUT ANYTHING BELOW ...\nfunction checkIfHashChanged()\n{\n var hashQuery = getHashQuery();\n if (hashQuery == hashValue)\n return;\n hashValue = hashQuery;\n locationHashChanged(hashQuery);\n}\n\nfunction parseQs(qs)\n{\n var q = {};\n var pairs = qs.split('&');\n for (var idx in pairs) {\n var arg = pairs[idx].split('=');\n q[arg[0]] = arg[1];\n }\n return q;\n}\n\nfunction startHashListener()\n{\n hashListener = setInterval(checkIfHashChanged, 1000);\n}\n\nfunction stopHashListener()\n{\n if (hashListener != null)\n clearInterval(hashListener);\n hashListener = null;\n}\n\nfunction getHashQuery()\n{\n return location.hash.replace(/^#/, '');\n}\n\nvar hashListener = null;\nvar hashValue = '';//getHashQuery();\nstartHashListener();\n"
},
{
"answer_id": 10234264,
"author": "Nikita Koksharov",
"author_id": 764206,
"author_profile": "https://Stackoverflow.com/users/764206",
"pm_score": 1,
"selected": false,
"text": "Path.map(\"#/page\").to(function(){\n alert('page!');\n});\n"
},
{
"answer_id": 13747338,
"author": "Drew Noakes",
"author_id": 24874,
"author_profile": "https://Stackoverflow.com/users/24874",
"pm_score": 6,
"selected": false,
"text": "onpopstate window.onpopstate = function(event)\n{\n alert(\"location: \" + document.location + \", state: \" + JSON.stringify(event.state));\n};\n window.addEventListener('popstate', function(event)\n{\n alert(\"location: \" + document.location + \", state: \" + JSON.stringify(event.state));\n});\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/172957",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8435/"
] |
173,005
|
<p>I want to display the TIME field from my mysql table on my website, but rather than showing 21:00:00 etc I want to show 8:00 PM. I need a function/code to do this or even any pointers in the right direction. Will mark the first reply with some code as the correct reply.</p>
|
[
{
"answer_id": 173102,
"author": "phatduckk",
"author_id": 3896,
"author_profile": "https://Stackoverflow.com/users/3896",
"pm_score": 2,
"selected": false,
"text": "UNIX_TIMESTAMP() select a, b, c, UNIX_TIMESTAMP(instime) as unixtime;\n date() <?php echo date('Y/m/d', $row->unixtime); ?>\n DATE_FORMAT() UNIX_TIMESTAMP()"
},
{
"answer_id": 1109147,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "DATE_FORMAT(<field>,'%l.%i%p') LOWER() DATE_FORMAT(<field>,'%l.%i%p')"
},
{
"answer_id": 9565940,
"author": "JDGuide",
"author_id": 1249710,
"author_profile": "https://Stackoverflow.com/users/1249710",
"pm_score": 4,
"selected": false,
"text": "SELECT DATE_FORMAT(`t`.`date_field`,'%h:%i %p') AS `date_field` FROM `table_name` AS `t`\n SELECT DATE_FORMAT(`t`.`date_field`,'%r') AS `date_field` FROM `table_name` AS `t`\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23019/"
] |
173,009
|
<p>All too often I want a WPF slider that behaves like the System.Windows.Forms.TrackBar of old. That is, I want a slider that goes from X to Y but only allows the user to move it in discrete integer positions.</p>
<p>How does one do this in WPF since the Value property on the Slider is double?</p>
|
[
{
"answer_id": 173024,
"author": "cplotts",
"author_id": 22294,
"author_profile": "https://Stackoverflow.com/users/22294",
"pm_score": 8,
"selected": false,
"text": "<Slider\n Orientation=\"Vertical\"\n Height=\"200\"\n Minimum=\"0\"\n Maximum=\"10\"\n Value=\"0\"\n IsSnapToTickEnabled=\"True\"\n TickFrequency=\"1\"\n/>\n"
},
{
"answer_id": 7057568,
"author": "Dave",
"author_id": 214071,
"author_profile": "https://Stackoverflow.com/users/214071",
"pm_score": 6,
"selected": false,
"text": "Ticks <Slider Minimum=\"1\" Maximum=\"500\" IsSnapToTickEnabled=\"True\" Ticks=\"1,100,200,350,500\" />\n"
},
{
"answer_id": 13963030,
"author": "mkjeldsen",
"author_id": 482758,
"author_profile": "https://Stackoverflow.com/users/482758",
"pm_score": 4,
"selected": false,
"text": "public int MyProperty { get; set; }\n\nprivate void slider1_ValueChanged(object sender,\n RoutedPropertyChangedEventArgs<double> e)\n{\n (sender as Slider).Value = Math.Round(e.NewValue, 0);\n}\n\n<Slider\n Name=\"slider1\"\n TickPlacement=\"TopLeft\"\n AutoToolTipPlacement=\"BottomRight\"\n ValueChanged=\"slider1_ValueChanged\"\n Value=\"{Binding MyProperty}\"\n Minimum=\"0\" Maximum=\"100\" SmallChange=\"1\" LargeChange=\"10\"\n Ticks=\"0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100\"/>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22294/"
] |
173,017
|
<p>I'm running some java processes on Windows 2003 server R2
I'm using Apache log4j-1.2.8. All my processes called via
one jar file with different parameter example</p>
<pre><code> java -jar process.jar one
java -jar process.jar two
java -jar process.jar three
</code></pre>
<p>And I config log4j.properties follow</p>
<pre><code>#===============================
# Declare Variables
#===============================
logpath=${user.dir}/log/
simple_pattern=%d{yyyy-MM-dd HH:mm:ss.SSS}%-5x - %m%n
backup_pattern='.'yyyy-MM-dd
#===============================
# PROCESS & STANDARD OUTPUT
#===============================
log4j.logger.process.Process=NULL,proclog,procstdout
log4j.appender.proclog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.proclog.File=${logpath}process.log
log4j.appender.proclog.DatePattern=${backup_pattern}
log4j.appender.proclog.layout=org.apache.log4j.PatternLayout
log4j.appender.proclog.layout.conversionPattern=${simple_pattern}
log4j.appender.procstdout=org.apache.log4j.ConsoleAppender
log4j.appender.procstdout.layout=org.apache.log4j.PatternLayout
log4j.appender.procstdout.layout.ConversionPattern=${simple_pattern}
#===============================
# ONE
#===============================
log4j.logger.process.log.One=NULL,one
log4j.appender.one=org.apache.log4j.DailyRollingFileAppender
log4j.appender.one.File=${logpath}one.log
log4j.appender.one.DatePattern=${backup_pattern}
log4j.appender.one.layout=org.apache.log4j.PatternLayout
log4j.appender.one.layout.conversionPattern=${simple_pattern}
#===============================
# TWO
#===============================
log4j.logger.process.log.Two=NULL,two
log4j.appender.two=org.apache.log4j.DailyRollingFileAppender
log4j.appender.two.File=${logpath}two.log
log4j.appender.two.DatePattern=${backup_pattern}
log4j.appender.two.layout=org.apache.log4j.PatternLayout
log4j.appender.two.layout.conversionPattern=${simple_pattern}
#===============================
# THREE
#===============================
log4j.logger.process.log.Three=NULL,three
log4j.appender.three=org.apache.log4j.DailyRollingFileAppender
log4j.appender.three.File=${logpath}three.log
log4j.appender.three.DatePattern=${backup_pattern}
log4j.appender.three.layout=org.apache.log4j.PatternLayout
log4j.appender.three.layout.conversionPattern=${simple_pattern}
</code></pre>
<p>first time I use process appender is single logger and now i separate it
to ONE, TWO and THREE logger.
my processes executed by windows schedule every 1 minute.</p>
<p><strong>So. I got Big problem
I don't know why log4j cannot generate backup files.
but when I execute manual by command line It's Ok.</strong></p>
|
[
{
"answer_id": 173084,
"author": "Fuangwith S.",
"author_id": 24550,
"author_profile": "https://Stackoverflow.com/users/24550",
"pm_score": -1,
"selected": false,
"text": "@echo off\nset CLASSPATH=.;%CLASSPATH%\nset path=C:\\j2sdk1.4.2\\bin;%path%\njavaw -jar process.jar %1\n Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.2\nCreated-By: 1.4.2 (IBM Corporation)\nMain-Class: process.Process\nClass-Path: ./lib/Utility.jar ./lib/DB2LibRAD.jar ./lib/rowset.jar ./l\n ib/log4j-1.2.8.jar ./lib/com.ibm.mq.jar .\n - process.jar\n - bgprocess.bat\n - lib <dir>\n - log4j-1.2.8.jar\n - com.ibm.mq.jar\n - connector.jar\n - DB2LibRAD.jar\n - rowset.jar\n - Utility.jar \n - log <dir>\n - one.log\n - two.log\n - three.log\n - process.log\n"
},
{
"answer_id": 173463,
"author": "skaffman",
"author_id": 21234,
"author_profile": "https://Stackoverflow.com/users/21234",
"pm_score": 0,
"selected": false,
"text": "log4j.appender.three.Append=true\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24550/"
] |
173,041
|
<p>Which of these queries is the faster?</p>
<p>NOT EXISTS:</p>
<pre><code>SELECT ProductID, ProductName
FROM Northwind..Products p
WHERE NOT EXISTS (
SELECT 1
FROM Northwind..[Order Details] od
WHERE p.ProductId = od.ProductId)
</code></pre>
<p>Or NOT IN:</p>
<pre><code>SELECT ProductID, ProductName
FROM Northwind..Products p
WHERE p.ProductID NOT IN (
SELECT ProductID
FROM Northwind..[Order Details])
</code></pre>
<p>The query execution plan says they both do the same thing. If that is the case, which is the recommended form?</p>
<p>This is based on the NorthWind database.</p>
<p>[Edit]</p>
<p>Just found this helpful article:
<a href="http://weblogs.sqlteam.com/mladenp/archive/2007/05/18/60210.aspx" rel="noreferrer">http://weblogs.sqlteam.com/mladenp/archive/2007/05/18/60210.aspx</a></p>
<p>I think I'll stick with NOT EXISTS.</p>
|
[
{
"answer_id": 173058,
"author": "oglester",
"author_id": 2017,
"author_profile": "https://Stackoverflow.com/users/2017",
"pm_score": -1,
"selected": false,
"text": "SELECT x.col\nFROM big_table x\nWHERE x.key IN( SELECT key FROM really_big_table );\n SELECT x.col\nFROM big_table x\nWHERE EXISTS( SELECT key FROM really_big_table WHERE key = x.key);\n AND id = very_limiting_criteria\n"
},
{
"answer_id": 173069,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 4,
"selected": false,
"text": "SELECT ProductID, ProductName \n FROM Northwind..Products p \n outer join Northwind..[Order Details] od on p.ProductId = od.ProductId)\nWHERE od.ProductId is null\n"
},
{
"answer_id": 173096,
"author": "Jeffrey L Whitledge",
"author_id": 10174,
"author_profile": "https://Stackoverflow.com/users/10174",
"pm_score": 3,
"selected": false,
"text": "NOT IN NOT IN NOT EXISTS NOT EXISTS"
},
{
"answer_id": 10516011,
"author": "buckley",
"author_id": 381995,
"author_profile": "https://Stackoverflow.com/users/381995",
"pm_score": 7,
"selected": false,
"text": "WHERE SomeValue NOT IN (SELECT AVal FROM t)\n WHERE SomeValue != (SELECT AVal FROM t WHERE ID=1)\nAND SomeValue != (SELECT AVal FROM t WHERE ID=2)\nAND SomeValue != (SELECT AVal FROM t WHERE ID=3)\nAND SomeValue != (SELECT AVal FROM t WHERE ID=4)\n"
},
{
"answer_id": 11074428,
"author": "Martin Smith",
"author_id": 73226,
"author_profile": "https://Stackoverflow.com/users/73226",
"pm_score": 11,
"selected": true,
"text": "NOT EXISTS NULL NOT IN NULL NOT IN NULL Products.ProductID [Order Details].ProductID NULL NOT IN SELECT ProductID,\n ProductName\nFROM Products p\nWHERE NOT EXISTS (SELECT *\n FROM [Order Details] od\n WHERE p.ProductId = od.ProductId) \n /*Not valid syntax but better reflects the plan*/ \nSELECT p.ProductID,\n p.ProductName\nFROM Products p\n LEFT ANTI SEMI JOIN [Order Details] od\n ON p.ProductId = od.ProductId \n [Order Details].ProductID NULL SELECT ProductID,\n ProductName\nFROM Products p\nWHERE NOT EXISTS (SELECT *\n FROM [Order Details] od\n WHERE p.ProductId = od.ProductId)\n AND NOT EXISTS (SELECT *\n FROM [Order Details]\n WHERE ProductId IS NULL) \n [Order Details] NULL ProductId Products.ProductID NULL SELECT ProductID,\n ProductName\nFROM Products p\nWHERE NOT EXISTS (SELECT *\n FROM [Order Details] od\n WHERE p.ProductId = od.ProductId)\n AND NOT EXISTS (SELECT *\n FROM [Order Details]\n WHERE ProductId IS NULL)\n AND NOT EXISTS (SELECT *\n FROM (SELECT TOP 1 *\n FROM [Order Details]) S\n WHERE p.ProductID IS NULL) \n NULL Products.ProductId NOT IN [Order Details] NULL NULL NOT IN NULL AdventureWorks2008 NOT IN NOT NULL NOT EXISTS NULL NOT IN Sales.SalesOrderDetail.ProductID = <correlated_product_id> WHERE Sales.SalesOrderDetail.ProductID IS NULL Sales.SalesOrderDetail NULL ProductID"
},
{
"answer_id": 17090472,
"author": "ravish.hacker",
"author_id": 1367413,
"author_profile": "https://Stackoverflow.com/users/1367413",
"pm_score": 3,
"selected": false,
"text": "SELECT * from TABLE1 WHERE Col1 NOT IN (SELECT Col1 FROM TABLE2)\n SELECT * from TABLE1 T1 WHERE NOT EXISTS (SELECT Col1 FROM TABLE2 T2 WHERE T1.Col1 = T2.Col2)\n"
},
{
"answer_id": 24616125,
"author": "Yella Chalamala",
"author_id": 3813341,
"author_profile": "https://Stackoverflow.com/users/3813341",
"pm_score": 4,
"selected": false,
"text": "Varchar NOT IN NOT EXISTS NOT EXISTS IN EXISTS"
},
{
"answer_id": 59946679,
"author": "Vlad Mihalcea",
"author_id": 1025118,
"author_profile": "https://Stackoverflow.com/users/1025118",
"pm_score": 3,
"selected": false,
"text": "student student_grade student table student_grade SELECT\n student_grade.student_id\nFROM\n student_grade\nWHERE\n student_grade.grade = 10 AND\n student_grade.class_name = 'Math'\nORDER BY\n student_grade.student_id\n student student student SELECT\n id, first_name, last_name\nFROM\n student\nWHERE EXISTS (\n SELECT 1\n FROM\n student_grade\n WHERE\n student_grade.student_id = student.id AND\n student_grade.grade = 10 AND\n student_grade.class_name = 'Math'\n)\nORDER BY id\n student student_grade SELECT\n id, first_name, last_name\nFROM\n student\nWHERE NOT EXISTS (\n SELECT 1\n FROM\n student_grade\n WHERE\n student_grade.student_id = student.id AND\n student_grade.grade < 9\n)\nORDER BY id\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173041",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9825/"
] |
173,046
|
<p>I need to create a custom volume slider for a WMP object. The current slider is complicated to modify, and use, is there a simple way to generate a slider on an HTML page that can have it's value passed to a javascript function?</p>
|
[
{
"answer_id": 173888,
"author": "olle",
"author_id": 22422,
"author_profile": "https://Stackoverflow.com/users/22422",
"pm_score": 4,
"selected": false,
"text": "<input type=\"range\">"
},
{
"answer_id": 10391073,
"author": "Martin",
"author_id": 1366768,
"author_profile": "https://Stackoverflow.com/users/1366768",
"pm_score": -1,
"selected": false,
"text": "<script>\nvar l=0;\nfunction f(i){\nim = 'i' + l;\nd=document.all[im];\nd.height=99;\ndocument.all.f1.t1.value=i;\nim = 'i' + i;\nd=document.all[im];\nd.height=1;\nl=i;\n}\n</script>\n<center>\n<form id='f1'>\n<input type=text value=0 id='t1'>\n</form>\n<script>\nfor (i=0;i<=50;i++)\n {\n s = \"<img src='j.jpg' height=99 width=9 onMouseOver='f(\" + i + \")' id='i\" + i + \"'>\";\n document.write(s);\n }\n</script>\n"
},
{
"answer_id": 14644243,
"author": "Stephane Rolland",
"author_id": 356440,
"author_profile": "https://Stackoverflow.com/users/356440",
"pm_score": 4,
"selected": false,
"text": "<input type=\"range\">\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173046",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/115/"
] |
173,056
|
<p>I've been trying to solve this, and have been getting stuck, so I thought I'd ask.</p>
<p>Imagine two ActionBeans, A and B.</p>
<p><code>A.jsp</code> has this section in it:</p>
<pre><code>...
<jsp:include page="/B.action">
<jsp:param name="ponies" value="on"/>
</jsp:include>
<jsp:include page="/B.action">
<jsp:param name="ponies" value="off"/>
</jsp:include>
...
</code></pre>
<p>Take it as read that the B ActionBean does some terribly interesting stuff depending on whether the "ponies" parameter is set to either on or off.</p>
<p>The parameter string "ponies=on" <em>is</em> visible when you debug into the request, but it's not what's getting bound into the B ActionBean. Instead what's getting bound are the parameters to the original A.action.</p>
<p>Is there some way of getting the behaviour I want, or have I missed something fundamental?</p>
|
[
{
"answer_id": 173888,
"author": "olle",
"author_id": 22422,
"author_profile": "https://Stackoverflow.com/users/22422",
"pm_score": 4,
"selected": false,
"text": "<input type=\"range\">"
},
{
"answer_id": 10391073,
"author": "Martin",
"author_id": 1366768,
"author_profile": "https://Stackoverflow.com/users/1366768",
"pm_score": -1,
"selected": false,
"text": "<script>\nvar l=0;\nfunction f(i){\nim = 'i' + l;\nd=document.all[im];\nd.height=99;\ndocument.all.f1.t1.value=i;\nim = 'i' + i;\nd=document.all[im];\nd.height=1;\nl=i;\n}\n</script>\n<center>\n<form id='f1'>\n<input type=text value=0 id='t1'>\n</form>\n<script>\nfor (i=0;i<=50;i++)\n {\n s = \"<img src='j.jpg' height=99 width=9 onMouseOver='f(\" + i + \")' id='i\" + i + \"'>\";\n document.write(s);\n }\n</script>\n"
},
{
"answer_id": 14644243,
"author": "Stephane Rolland",
"author_id": 356440,
"author_profile": "https://Stackoverflow.com/users/356440",
"pm_score": 4,
"selected": false,
"text": "<input type=\"range\">\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22419/"
] |
173,070
|
<p>I heard that you could right-shift a number by .5 instead of using Math.floor(). I decided to check its limits to make sure that it was a suitable replacement, so I checked the following values and got the following results in Google Chrome:</p>
<pre><code>
2.5 >> .5 == 2;
2.9999 >> .5 == 2;
2.999999999999999 >> .5 == 2; // 15 9s
2.9999999999999999 >> .5 == 3; // 16 9s
</code></pre>
<p>After some fiddling, I found out that the highest possible value of two which, when right-shifted by .5, would yield 2 is 2.9999999999999997779553950749686919152736663818359374999999¯ (with the 9 repeating) in Chrome and Firefox. The number is 2.9999999999999997779¯ in IE.</p>
<p>My question is: what is the significance of the number .0000000000000007779553950749686919152736663818359374? It's a very strange number and it really piqued my curiosity.</p>
<p>I've been trying to find an answer or at least some kind of pattern, but I think my problem lies in the fact that I really don't understand the bitwise operation. I understand the idea in principle, but shifting a bit sequence by .5 doesn't make any sense at all to me. Any help is appreciated.</p>
<p>For the record, the weird digit sequence changes with 2^x. The highest possible values of the following numbers that still truncate properly:</p>
<pre>
for 0: 0.9999999999999999444888487687421729788184165954589843749¯
for 1: 1.9999999999999999888977697537484345957636833190917968749¯
for 2-3: x+.99999999999999977795539507496869191527366638183593749¯
for 4-7: x+.9999999999999995559107901499373838305473327636718749¯
for 8-15: x+.999999999999999111821580299874767661094665527343749¯
...and so forth
</pre>
|
[
{
"answer_id": 173090,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 5,
"selected": false,
"text": "Math.floor() x y x Math.floor()"
},
{
"answer_id": 173092,
"author": "Rob Walker",
"author_id": 3631,
"author_profile": "https://Stackoverflow.com/users/3631",
"pm_score": 3,
"selected": false,
"text": "var x = 2.999999999999999777955395074968691915273666381835937499999;\nvar y = 2.9999999999999997779553950749686919152736663818359375;\n\ndocument.write(\"x=\" + x);\ndocument.write(\" y=\" + y);\n"
},
{
"answer_id": 173123,
"author": "Ates Goral",
"author_id": 23501,
"author_profile": "https://Stackoverflow.com/users/23501",
"pm_score": 7,
"selected": true,
"text": "2.999999 >> 0.5\n Math.floor(2.999999) >> Math.floor(0.5)\n 2 >> 0\n switch (op) {\n case JSOP_LSH:\n case JSOP_RSH:\n if (!js_DoubleToECMAInt32(cx, d, &i)) // Same as Math.floor()\n return JS_FALSE;\n if (!js_DoubleToECMAInt32(cx, d2, &j)) // Same as Math.floor()\n return JS_FALSE;\n j &= 31;\n d = (op == JSOP_LSH) ? i << j : i >> j;\n break;\n alert(2.999999999999999);\n alert(2.9999999999999999);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25357/"
] |
173,080
|
<p>What are some of the new features that can be used in .NET 2.0 that are specific to C# 3.0/3.5 after upgrading to Visual Studio 2008? Also, what are some of the features that aren't available?</p>
<p><strong>Available</strong></p>
<ul>
<li>Lambdas</li>
<li>Extension methods (by declaring an empty System.Runtime.CompilerServices.ExtensionAttribute)</li>
<li>Automatic properties</li>
<li>Object initializers</li>
<li>Collection Initializers</li>
<li>LINQ to Objects (by implementing IEnumerable extension methods, see <a href="http://www.albahari.com/nutshell/linqbridge.aspx" rel="nofollow noreferrer">LinqBridge</a>)</li>
</ul>
<p><strong>Not Available</strong></p>
<ul>
<li>Expression trees</li>
<li>WPF/Silverlight Libraries</li>
</ul>
|
[
{
"answer_id": 173088,
"author": "Curt Hagenlocher",
"author_id": 533,
"author_profile": "https://Stackoverflow.com/users/533",
"pm_score": 2,
"selected": false,
"text": "namespace System.Runtime.CompilerServices {\n [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]\n sealed class ExtensionAttribute : Attribute { }\n}\n"
},
{
"answer_id": 173114,
"author": "Lucas",
"author_id": 24231,
"author_profile": "https://Stackoverflow.com/users/24231",
"pm_score": 5,
"selected": true,
"text": "Func<..> Expression<Func<..>> System.Runtime.CompilerServices.ExtensionAttribute IEnumerable<T>"
},
{
"answer_id": 173268,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "Func Action"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18194/"
] |
173,115
|
<p>I'm currently working on the <code>Tips.js</code> from <code>mootools</code> library and my code breaks on the line that has those <code>el.$tmp</code>, and console says it's undefined</p>
<p>Can anybody help me?</p>
|
[
{
"answer_id": 242743,
"author": "Ryan",
"author_id": 32009,
"author_profile": "https://Stackoverflow.com/users/32009",
"pm_score": 2,
"selected": true,
"text": "var Garbage = {\n\n elements: [],\n\n collect: function(el){\n if (!el.$tmp){\n Garbage.elements.push(el);\n el.$tmp = {'opacity': 1};\n }\n return el;\n },\n\n trash: function(elements){\n for (var i = 0, j = elements.length, el; i < j; i++){\n if (!(el = elements[i]) || !el.$tmp) continue;\n if (el.$events) el.fireEvent('trash').removeEvents();\n for (var p in el.$tmp) el.$tmp[p] = null;\n for (var d in Element.prototype) el[d] = null;\n Garbage.elements[Garbage.elements.indexOf(el)] = null;\n el.htmlElement = el.$tmp = el = null;\n }\n Garbage.elements.remove(null);\n },\n\n empty: function(){\n Garbage.collect(window);\n Garbage.collect(document);\n Garbage.trash(Garbage.elements);\n }\n\n};\n el.$tmp = {'opacity': 1}; el.htmlElement = el.$tmp = el = null;"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24744/"
] |
173,133
|
<p>1.
How can I reinterpret cast a float to an int (or a double to a long)?</p>
<pre><code>float f = 2.0f;
int i = (int)f; // causes conversion
</code></pre>
<p>I only want to copy the bit-pattern from <code>f</code> to <code>i</code>. How can this be done?</p>
<p>2.
The implicit and explicit operators in C# uses one intermediate object because the operator function is static</p>
<pre><code>public static implicit operator MyClass(double s)
{
return new MyClass(s);
}
..
..
MyClass m = 2.2; // this code uses 'm' and one intermediate object.
</code></pre>
<p>This is fine for reference types, but for value-types which are big (say 20-30 bytes), this will cause unnecessary data copy. Is my understanding correct? And If yes, then why doesn't C# have a non-static conversion operator or user-defined assignment operator so that the conversion/assignment takes place on 'this'? If it does, whats the way to do it?</p>
|
[
{
"answer_id": 173139,
"author": "user7116",
"author_id": 7116,
"author_profile": "https://Stackoverflow.com/users/7116",
"pm_score": 3,
"selected": false,
"text": "float ff = 2.0f;\nint ii = BitConverter.ToInt32(BitConverter.GetBytes(ff), 0);\n\nfloat[] ff = new float[...];\nint[] ii = new int[ff.Length];\nBuffer.BlockCopy(ff, 0, ii, 0, ff.Length * 4); // byte-wise copy of ff into ii\n"
},
{
"answer_id": 173186,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": false,
"text": " float f = 2.0f;\n int i;\n // perform unsafe cast (preserving raw binary)\n unsafe\n {\n float* fRef = &f;\n i = *((int*)fRef);\n }\n Console.WriteLine(i);\n\n // prove same answer long-hand\n byte[] raw = BitConverter.GetBytes(f);\n int j = BitConverter.ToInt32(raw, 0); \n Console.WriteLine(j);\n"
},
{
"answer_id": 12898591,
"author": "Ani",
"author_id": 802203,
"author_profile": "https://Stackoverflow.com/users/802203",
"pm_score": 4,
"selected": false,
"text": " [StructLayout(LayoutKind.Explicit)]\n private struct IntFloat\n {\n [FieldOffset(0)]\n public int IntValue;\n [FieldOffset(0)]\n public float FloatValue;\n }\n private static float Foo(float x)\n {\n var intFloat = new IntFloat { FloatValue = x };\n var floatAsInt = intFloat.IntValue;\n ...\n"
},
{
"answer_id": 42080195,
"author": "Nick Strupat",
"author_id": 232574,
"author_profile": "https://Stackoverflow.com/users/232574",
"pm_score": 2,
"selected": false,
"text": "static unsafe TDest ReinterpretCast<TSource, TDest>(TSource source)\n{\n var tr = __makeref(source);\n TDest w = default(TDest);\n var trw = __makeref(w);\n *((IntPtr*)&trw) = *((IntPtr*)&tr);\n return __refvalue(trw, TDest);\n}\n"
},
{
"answer_id": 49409433,
"author": "Elliott Prechter",
"author_id": 9529346,
"author_profile": "https://Stackoverflow.com/users/9529346",
"pm_score": 2,
"selected": false,
"text": "public static class ReinterpretCastExtensions {\n public static unsafe float AsFloat( this int n ) => *(float*)&n;\n public static unsafe int AsInt( this float n ) => *(int*)&n;\n}\n\npublic static class MainClass {\n public static void Main( string[] args ) {\n Console.WriteLine( 1.0f.AsInt() );\n Console.WriteLine( 1.AsFloat() );\n }\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
173,144
|
<p>I want to make sure people can't type the name of a PHP script in the URL and run it. What's the best way of doing this?</p>
<p>I could set a variable in the file that will be including this file, and then check that variable in the file being included, but is there an easier way?</p>
|
[
{
"answer_id": 173152,
"author": "UnkwnTech",
"author_id": 115,
"author_profile": "https://Stackoverflow.com/users/115",
"pm_score": 4,
"selected": true,
"text": "$_SERVER['SCRIPT_FILENAME']\n"
},
{
"answer_id": 173161,
"author": "ThoriumBR",
"author_id": 16545,
"author_profile": "https://Stackoverflow.com/users/16545",
"pm_score": 0,
"selected": false,
"text": "<?php\nif (!eregi(\"modules.php\", $PHP_SELF)) {\n die (\"You can't access this file directly...\");\n}\n// more code ...\n?>\n"
},
{
"answer_id": 173192,
"author": "Eric Lamb",
"author_id": 538,
"author_profile": "https://Stackoverflow.com/users/538",
"pm_score": 0,
"selected": false,
"text": "if(!isset($in_prog)){\nexit;\n}\n"
},
{
"answer_id": 173197,
"author": "Michael Johnson",
"author_id": 17688,
"author_profile": "https://Stackoverflow.com/users/17688",
"pm_score": 2,
"selected": false,
"text": ".htaccess html php.ini $parentPath = dirname(dirname(__FILE__));\n$ourPath = $parentPath . DIRECTORY_SEPARATOR . 'include';\n\n$includePath = ini_get('include_path');\n$includePaths = explode(PATH_SEPARATOR, $includePath);\n// Put our path between 'current directory' and rest of search path\nif ($includePaths[0] == '.') { \n array_shift($includePaths);\n}\n\narray_unshift($includePaths, '.', $ourPath);\n$includePath = implode(PATH_SEPARATOR, $includePaths);\nini_set('include_path', $includePath);\n index.php #include '../includes/prepPath.inc' php.ini"
},
{
"answer_id": 173214,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 4,
"selected": false,
"text": "// index.php\nrequire_once 'includes.php';\n\n// includes.php\ndefine('IN_MY_PROJECT', true);\ninclude 'myInc.php';\n\n// myInc.php\ndefined('IN_MY_PROJECT') || die(\"No direct access, plsktnxbai\");\n"
},
{
"answer_id": 59652999,
"author": "Rafael Carneiro de Moraes",
"author_id": 5427528,
"author_profile": "https://Stackoverflow.com/users/5427528",
"pm_score": 0,
"selected": false,
"text": "$inc = get_included_files(); if(basename(__FILE__) == basename($inc[0])) exit();\n"
},
{
"answer_id": 69076588,
"author": "D.A.H",
"author_id": 2360439,
"author_profile": "https://Stackoverflow.com/users/2360439",
"pm_score": 0,
"selected": false,
"text": "// Prevent direct access, use exclusively as include only.\nif (count(get_included_files()) == 1) {\n http_response_code(403);\n die();\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/813/"
] |
173,145
|
<p>Given:</p>
<pre><code>interface I
{
}
class B: I
{
}
class C: I
{
}
class A
{
public void Method(B arg)
{
}
public void Method(C arg)
{
}
public void Method(I arg)
{
// THIS is the method I want to simplify.
if (I is B)
{
this.Method(arg as B);
}
else if (I is C)
{
this.Method(arg as C);
}
}
}
</code></pre>
<p>I know that there are better ways to design this type of interactions, but because of
details which would take too long to explain this is not possible.
Since this pattern will be duplicated MANY times, I would like to replace the
conditional logic with a generic implementation which I could use just one line.
I can't see a simple way to implement this generic method/class, but my instincts tell me it should be possible.</p>
<p>Any help would be appreciated.</p>
|
[
{
"answer_id": 173165,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "return (I is B) ? Method((B)I) : ((I is C) ? Method((C)I) : 0);\n"
},
{
"answer_id": 173167,
"author": "jop",
"author_id": 11830,
"author_profile": "https://Stackoverflow.com/users/11830",
"pm_score": 4,
"selected": false,
"text": "interface I\n{\n void Method();\n}\n\nclass B : I\n{\n public void Method() { /* previously A.Method(B) */}\n}\n\nclass C : I\n{\n public void Method() { /* previously A.Method(C) */ }\n}\n\nclass A\n{\n public void Method(I obj)\n { \n obj.Method();\n }\n}\n"
},
{
"answer_id": 173262,
"author": "Jeffrey L Whitledge",
"author_id": 10174,
"author_profile": "https://Stackoverflow.com/users/10174",
"pm_score": 1,
"selected": false,
"text": "public void Method(B arg)\n{\n if (arg == null) return;\n...\n}\npublic void Method(C arg)\n{\n if (arg == null) return;\n...\n}\n\npublic void Method(I arg)\n{\n this.Method(arg as B);\n this.Method(arg as C);\n}\n"
},
{
"answer_id": 173263,
"author": "Jonathan Allen",
"author_id": 5274,
"author_profile": "https://Stackoverflow.com/users/5274",
"pm_score": 0,
"selected": false,
"text": "Sub MethodBase(value as Object)\n CallByName(Me, \"RealMethod\", CallType.Method, value)\n"
},
{
"answer_id": 176414,
"author": "Vivek",
"author_id": 7418,
"author_profile": "https://Stackoverflow.com/users/7418",
"pm_score": 1,
"selected": false,
"text": "interface I\n{ \n} \n\nclass B : I\n{\n}\n\nclass C : I\n{\n} \n\nclass A \n{\n public void Method(B arg)\n {\n Console.WriteLine(\"I'm in B\");\n }\n\n public void Method(C arg)\n {\n Console.WriteLine(\"I'm in C\");\n }\n\n public void Method(I arg)\n {\n Type type = arg.GetType();\n\n MethodInfo method = typeof(A).GetMethod(\"Method\", new Type[] { type });\n method.Invoke(this, new I[] { arg });\n }\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25388/"
] |
173,149
|
<p>Can someone please explain how to remove the background/borders off an embedded CrystalReportViewer control in Visual Studio 2008.</p>
<p>I'm trying to remove the light gray (below the "Crystal Report" heading) and then the darker gray underneath that. I want to be left with only the white box and the report inside this.</p>
<p>This is the output I'm currently getting:</p>
<p><strong><a href="http://img411.imageshack.us/my.php?image=screenshotml3.jpg" rel="nofollow noreferrer">http://img411.imageshack.us/my.php?image=screenshotml3.jpg</a></strong></p>
<p>The HTML snippet is:</p>
<pre><code><div>
<h2>Crystal Report</h2>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" DisplayToolbar="False" />
</div>
</code></pre>
<p>The C# code snippet is: </p>
<pre><code>string strReportName = "CrystalReport";
string strReportPath = Server.MapPath(strReportName + ".rpt");
ReportDocument rptDocument = new ReportDocument();
rptDocument.Load(strReportPath);
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasDrilldownTabs = false;
CrystalReportViewer1.HasDrillUpButton = false;
CrystalReportViewer1.HasExportButton = false;
CrystalReportViewer1.HasGotoPageButton = false;
CrystalReportViewer1.HasPageNavigationButtons = false;
CrystalReportViewer1.HasPrintButton = false;
CrystalReportViewer1.HasRefreshButton = false;
CrystalReportViewer1.HasSearchButton = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.HasToggleParameterPanelButton = false;
CrystalReportViewer1.HasZoomFactorList = false;
CrystalReportViewer1.DisplayToolbar = false;
CrystalReportViewer1.EnableDrillDown = false;
CrystalReportViewer1.BestFitPage = true;
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
CrystalReportViewer1.BackColor = System.Drawing.Color.Red;
CrystalReportViewer1.BorderColor = System.Drawing.Color.Green;
CrystalReportViewer1.CssClass
CrystalReportViewer1.Height = 200;
CrystalReportViewer1.Width = 500;
CrystalReportViewer1.ReportSource = rptDocument;
</code></pre>
|
[
{
"answer_id": 173165,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "return (I is B) ? Method((B)I) : ((I is C) ? Method((C)I) : 0);\n"
},
{
"answer_id": 173167,
"author": "jop",
"author_id": 11830,
"author_profile": "https://Stackoverflow.com/users/11830",
"pm_score": 4,
"selected": false,
"text": "interface I\n{\n void Method();\n}\n\nclass B : I\n{\n public void Method() { /* previously A.Method(B) */}\n}\n\nclass C : I\n{\n public void Method() { /* previously A.Method(C) */ }\n}\n\nclass A\n{\n public void Method(I obj)\n { \n obj.Method();\n }\n}\n"
},
{
"answer_id": 173262,
"author": "Jeffrey L Whitledge",
"author_id": 10174,
"author_profile": "https://Stackoverflow.com/users/10174",
"pm_score": 1,
"selected": false,
"text": "public void Method(B arg)\n{\n if (arg == null) return;\n...\n}\npublic void Method(C arg)\n{\n if (arg == null) return;\n...\n}\n\npublic void Method(I arg)\n{\n this.Method(arg as B);\n this.Method(arg as C);\n}\n"
},
{
"answer_id": 173263,
"author": "Jonathan Allen",
"author_id": 5274,
"author_profile": "https://Stackoverflow.com/users/5274",
"pm_score": 0,
"selected": false,
"text": "Sub MethodBase(value as Object)\n CallByName(Me, \"RealMethod\", CallType.Method, value)\n"
},
{
"answer_id": 176414,
"author": "Vivek",
"author_id": 7418,
"author_profile": "https://Stackoverflow.com/users/7418",
"pm_score": 1,
"selected": false,
"text": "interface I\n{ \n} \n\nclass B : I\n{\n}\n\nclass C : I\n{\n} \n\nclass A \n{\n public void Method(B arg)\n {\n Console.WriteLine(\"I'm in B\");\n }\n\n public void Method(C arg)\n {\n Console.WriteLine(\"I'm in C\");\n }\n\n public void Method(I arg)\n {\n Type type = arg.GetType();\n\n MethodInfo method = typeof(A).GetMethod(\"Method\", new Type[] { type });\n method.Invoke(this, new I[] { arg });\n }\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
173,159
|
<p>I know what ViewData is and use it all the time, but in ASP.NET Preview 5 they introduced something new called TempData. </p>
<p>I normally strongly type my ViewData, instead of using the dictionary of objects approach.</p>
<p>So, when should I use TempData instead of ViewData?</p>
<p>Are there any best practices for this? </p>
|
[
{
"answer_id": 173650,
"author": "Dragan Panjkov",
"author_id": 481,
"author_profile": "https://Stackoverflow.com/users/481",
"pm_score": 8,
"selected": true,
"text": "TempData TempData TempData"
},
{
"answer_id": 44553266,
"author": "Ali Adravi",
"author_id": 586227,
"author_profile": "https://Stackoverflow.com/users/586227",
"pm_score": 3,
"selected": false,
"text": "ViewData public ViewDataDictionary ViewData { get; set; } ControllerBase Controller TempData TempDataDictionary public TempDataDictionary TempData { get; set; } TempDataDictionary TempData"
},
{
"answer_id": 51464675,
"author": "Hitanshi Mehta",
"author_id": 9413538,
"author_profile": "https://Stackoverflow.com/users/9413538",
"pm_score": 0,
"selected": false,
"text": "public ViewResult try1()\n {\n ViewData[\"DateTime\"] = DateTime.Now;\n ViewData[\"Name\"] = \"Mehta Hitanshi\";\n ViewData[\"Twitter\"] = \"@hitanshi\";\n ViewData[\"City\"] = \"surat\";\n return View();\n }\n <table>\n<tr>\n <th>Name</th>\n <th>Twitter</th>\n <th>Email</th>\n <th>City</th>\n <th>Mobile</th>\n</tr>\n<tr>\n <td>@ViewData[\"Name\"]</td>\n <td>@ViewData[\"Twitter\"]</td>\n <td>@ViewData[\"City\"]</td>\n</tr>\n</table> \n public ActionResult try3()\n {\n TempData[\"DateTime\"] = DateTime.Now;\n TempData[\"Name\"] = \"Ravina\";\n TempData[\"Twitter\"] = \"@silentRavina\";\n TempData[\"Email\"] = \"Ravina12@gmail.com\";\n TempData[\"City\"] = \"India\";\n TempData[\"MobNo\"] = 9998975436;\n return RedirectToAction(\"TempView1\");\n }\n public ActionResult TempView1()\n {\n return View();\n }\n <table>\n<tr>\n <th>Name</th>\n <th>Twitter</th>\n <th>Email</th>\n <th>City</th>\n <th>Mobile</th>\n</tr>\n<tr>\n <td>@TempData[\"Name\"]</td>\n <td>@TempData[\"Twitter\"]</td>\n <td>@TempData[\"Email\"]</td>\n <td>@TempData[\"City\"]</td>\n <td>@TempData[\"MobNo\"]</td>\n</tr>\n</table>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4481/"
] |
173,199
|
<p>Can someone explain the pros and cons of it and any math involved with it?</p>
|
[
{
"answer_id": 173274,
"author": "zoul",
"author_id": 17279,
"author_profile": "https://Stackoverflow.com/users/17279",
"pm_score": 1,
"selected": false,
"text": "glReadPixels"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
173,207
|
<p>I am exploring ASP.NET MVC and I wanted to add jQuery to make the site interactive. I used StringTemplate, ported to .Net, as my template engine to generate html and to send JSON. However, when I view the page, I could not see it. After debugging, I've realized that the $ is used by the StringTemplate to access property, etc and jQuery uses it too to manipulate the DOM. Gee, I've looked on other template engines and most of them uses the dollar sign :(.</p>
<p>Any alternative template engine for ASP.Net MVC? I wanted to retain jQuery because MSFT announced that it will used in the Visual Studio (2008?)</p>
<p>Thanks in Advance :)</p>
<p><strong>Update</strong></p>
<p>Please go to <a href="https://stackoverflow.com/questions/1451319/asp-net-mvc-view-engine-comparison/1451355#1451355">the answer</a> in <a href="https://stackoverflow.com/questions/1451319/asp-net-mvc-view-engine-comparison">ASP.NET MVC View Engine Comparison</a> question for a comprehensive list of Template engine for ASP.NET MVC, and their pros and cons</p>
<p><strong>Update 2</strong></p>
<p>At the end I'll just put the JavaScript code, including JQuery, in a separate script file, hence I wouldn't worry about the <code>$</code> mingling in the template file.</p>
<p><strong>Update 3</strong></p>
<p>Changed the Title to reflect what I need to resolve. After all "The Best X in Y" is very subjective question.</p>
|
[
{
"answer_id": 896129,
"author": "Robert Harvey",
"author_id": 102937,
"author_profile": "https://Stackoverflow.com/users/102937",
"pm_score": 3,
"selected": false,
"text": "jQuery(\n $(\n"
},
{
"answer_id": 2799529,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "{%carName = \"Audi R8\"/}\n\n{%string str = \"This is an $carName$\"/}\n\n$str$\n$$str$$\n This is an Audi R8\n$str$\n"
},
{
"answer_id": 5962636,
"author": "Jakub Šturc",
"author_id": 2361,
"author_profile": "https://Stackoverflow.com/users/2361",
"pm_score": 0,
"selected": false,
"text": "Template TemplateGroup"
},
{
"answer_id": 13257340,
"author": "ddotsenko",
"author_id": 366864,
"author_profile": "https://Stackoverflow.com/users/366864",
"pm_score": 0,
"selected": false,
"text": "var child = new {\n nested = \"nested value\"\n};\nvar parent = new {\n SomeValue = \"asdfadsf\"\n , down = child\n , number = 123\n};\n\nvar template = @\"This is {{#down}}{{nested}}{{/down}}. Yeah to the power of {{number}}\";\n\nstring output = Nustache.Core.Render.StringToString(template,parent);\n// output:\n// \"This is nested value. Yeah to the power of 123\"\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173207",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24755/"
] |
173,209
|
<p>Specifically, in VS 2008, I want to connect to a data source that you can have by right-clicking on the automatically-generated App_Data folder (an .mdf "database"). Seems easy, and it is once you know how.</p>
|
[
{
"answer_id": 173221,
"author": "MrBoJangles",
"author_id": 13578,
"author_profile": "https://Stackoverflow.com/users/13578",
"pm_score": 4,
"selected": true,
"text": "AttachDbFilename Data Source=.\\SQLEXPRESS;Integrated Security=True;Connect Timeout=30;User Instance=True\n <add name=\"SomeDataBase\" connectionString=\"Data Source=.\\SQLEXPRESS; \nAttachDbFilename=C:\\Development\\blahBlah\\App_Data\\SomeDataFile.mdf;\nIntegrated Security=True; Connect Timeout=30; User Instance=True\" />\n"
},
{
"answer_id": 173375,
"author": "WebDude",
"author_id": 15360,
"author_profile": "https://Stackoverflow.com/users/15360",
"pm_score": 4,
"selected": false,
"text": "Driver={SQL Native Client};Server=.\\SQLExpress;AttachDbFilename=c:\\asd\\qwe\\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;\n"
},
{
"answer_id": 1998322,
"author": "Spice",
"author_id": 243065,
"author_profile": "https://Stackoverflow.com/users/243065",
"pm_score": 2,
"selected": false,
"text": "<add name=\"Your Database\" connectionString=\"metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Expanse.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"\" providerName=\"System.Data.EntityClient\"/>\n"
},
{
"answer_id": 33353107,
"author": "Sudheesh",
"author_id": 4913768,
"author_profile": "https://Stackoverflow.com/users/4913768",
"pm_score": 1,
"selected": false,
"text": "string constr = @\"Data Source=(LocalDB)\\v11.0; AttachDbFilename=|DataDirectory|\\myData.mdf; Integrated Security=True; Connect Timeout=30;\";\nusing (SqlConnection conn = new SqlConnection(constr))\nstring constr = ConfigurationManager.ConnectionStrings[\"myData\"].ToString();\n\nusing (SqlConnection conn = new SqlConnection(constr))\n{\nsqlQuery=\" Your Query here\"\nSqlCommand com = new SqlCommand(sqlQuery, conn);\ncom.Connection.Open();\nstring strOutput = (string)com.ExecuteScalar();\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13578/"
] |
173,212
|
<p>I just moved to a new hosting company and now whenever a string gets escaped using:</p>
<pre><code>mysql_real_escape_string($str);
</code></pre>
<p>the slashes remain in the database. This is the first time I've ever seen this happen so none of my scripts use</p>
<pre><code>stripslashes()
</code></pre>
<p>anymore.</p>
<p>This is on a CentOS 4.5 64bit running php 5.2.6 as fastcgi on a lighttpd 1.4 server. I've ensured that all magic_quotes options are off and the mysql client api is 5.0.51a.</p>
<p>I have the same issue on all 6 of my webservers.</p>
<p>Any help would be appreciated.</p>
<p>Thanks.</p>
<h3>Edit:</h3>
<h3>Magic Quotes isn't on. Please don't recommend turning it off. THIS IS NOT THE ISSUE.</h3>
|
[
{
"answer_id": 173234,
"author": "Steve Obbayi",
"author_id": 11190,
"author_profile": "https://Stackoverflow.com/users/11190",
"pm_score": -1,
"selected": false,
"text": "mysql_real_escape_string($str); stripslashes()"
},
{
"answer_id": 173238,
"author": "Andy Lester",
"author_id": 8454,
"author_profile": "https://Stackoverflow.com/users/8454",
"pm_score": 4,
"selected": false,
"text": "magic_quotes_runtime set_magic_quotes_runtime(0) magic_quotes_runtime"
},
{
"answer_id": 173387,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 2,
"selected": false,
"text": ".htaccess php_flag magic_quotes off\n function getVar($key) {\n if (get_magic_quotes_gpc()) {\n return stripslashes($_POST[$key]);\n } else {\n return $_POST[$key];\n }\n}\n\n$x = getVar('x');\n mysql_real_escape_string()"
},
{
"answer_id": 175925,
"author": "troelskn",
"author_id": 18180,
"author_profile": "https://Stackoverflow.com/users/18180",
"pm_score": 0,
"selected": false,
"text": "set_magic_quotes_runtime(0) php.ini"
},
{
"answer_id": 812872,
"author": "Ryaner",
"author_id": 99215,
"author_profile": "https://Stackoverflow.com/users/99215",
"pm_score": -1,
"selected": false,
"text": "<?php\n\n$db = mysql_connect('host', 'user', 'pass');\n\n$var = $_REQUEST['var'];\necho \"1: $var :1<br />\";\necho \"2: \".stripslashes($var).\" :2<br />\";\necho \"3: \".mysql_real_escape_string($var).\" :3<br />\";\necho \"4: \".quote_smart($var).\" :4<br />\";\n\n\nfunction quote_smart($value)\n{\n // Stripslashes is gpc on\n if (get_magic_quotes_gpc())\n {\n $value = stripslashes($value);\n }\n // Quote if not a number or a numeric string\n if ( !is_numeric($value) )\n {\n $value = mysql_real_escape_string($value);\n }\n return $value;\n}\n"
},
{
"answer_id": 1932579,
"author": "Mike Weller",
"author_id": 49658,
"author_profile": "https://Stackoverflow.com/users/49658",
"pm_score": 2,
"selected": false,
"text": "mysql_real_escape_string mysql_query addslashes echo htmlentities($_GET['value']); // or $_POST, whichever is appropriate\n echo \"Magic quotes is \" . (get_magic_quotes_gpc() ? \"ON\" : \"OFF\");\n"
},
{
"answer_id": 12393430,
"author": "Milan",
"author_id": 1438675,
"author_profile": "https://Stackoverflow.com/users/1438675",
"pm_score": 0,
"selected": false,
"text": "htmlentities($inserted_value)\n"
},
{
"answer_id": 14275108,
"author": "Wijnand de Ridder",
"author_id": 1969398,
"author_profile": "https://Stackoverflow.com/users/1969398",
"pm_score": 0,
"selected": false,
"text": "mysql_real_escape_string()"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/538/"
] |
173,219
|
<p>I run php 5.2.6 as a cgi under lighttpd 1.4 and for some reason it's always running as root. All php-cgi processes in are owned by root and all files written to the file system are owned by root. </p>
<p>I've tried setting the user in lighttpd as non privileged, and confirmed, it's running right it's just php that runs as root. </p>
<p>How would I set php-cgi to run as a safer user?</p>
|
[
{
"answer_id": 173502,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 3,
"selected": true,
"text": "server.username = \"nonprivuser\"\nserver.groupname = \"nonprivgroup\"\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/538/"
] |
173,224
|
<p>I am having issues with a website that I am working on in which images and background-images fail to load in Internet Explorer 6.</p>
<p>Here is an example of a page on which you might experience this issue:</p>
<p><a href="http://www.infinitieurope.com/aboutinfiniti/environment/infiniti-environment.html" rel="nofollow noreferrer">Example Page</a></p>
<p>So far I have looked at the following possible issues and pretty much ruled them out:</p>
<ul>
<li>XML/Extraneous data in the image files (google photoshop 7 internet explorer)</li>
<li>Corrupt image files</li>
</ul>
<p>I have not ruled out invalid markup.</p>
<p>I have noticed that there are validation errors in most of the pages where this problem has been reported and I am working on getting those fixed where appropriate.</p>
<p>The behavior I see is that the page will load and all elements other than the background image render. There are no javascript errors thrown. When using Fiddler, no request for the image is made. If the browser is pointed directly to the background-image, the cache is cleared and then the browser is pointed back at the HTML page, the background-image will load inside the HTML page.</p>
<p>Does anyone have any additional suggestions for ways to attack this issue?</p>
|
[
{
"answer_id": 174406,
"author": "Matt",
"author_id": 17020,
"author_profile": "https://Stackoverflow.com/users/17020",
"pm_score": 1,
"selected": false,
"text": "div.gBodyContainer {\nbackground-image:url(/etc/medialib/europe/about_infiniti/environment.Par.7366.Image.964.992.direct.jpg); !important\n}\n"
},
{
"answer_id": 3646548,
"author": "Sorin",
"author_id": 440068,
"author_profile": "https://Stackoverflow.com/users/440068",
"pm_score": 0,
"selected": false,
"text": "display: none;"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25380/"
] |
173,246
|
<p>I have a web project where I must import text and images from a user-supplied document, and one of the possible formats is Microsoft Office 2007. There's also a need to generate documents in this format.</p>
<p>The server runs CentOS 5.2 and has PHP/Perl/Python installed. I can execute local binaries and shell scripts if I must. We use Apache 2.2 but will be switching over to Nginx once it goes live. </p>
<p>What are my options? Anyone had experience with this?</p>
|
[
{
"answer_id": 1979887,
"author": "mikemaccana",
"author_id": 123671,
"author_profile": "https://Stackoverflow.com/users/123671",
"pm_score": 3,
"selected": false,
"text": "from docx import *\ndocument = newdocument()\n\n# This location is where most document content lives \ndocbody = document.xpath('/w:document/w:body',namespaces=wordnamespaces)[0]\n\n# Append two headings\ndocbody.append(heading('Heading',1) ) \ndocbody.append(heading('Subheading',2))\ndocbody.append(paragraph('Some text')\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173246",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18406/"
] |
173,272
|
<p>I see lots of job ads for C#/.NET programmers, so I thought it could be a good idea to have had a look at it.</p>
<p>After looking at a few tutorials I found nothing really new to me. Just a language with a syntax somewhere between Java and C++ (arguably nicer than both though).</p>
<p>So, what features in particular should I look at? What are some special features? What's the reason that C#/.NET is so large? What are some killer features or perhaps some really evil language gotchas?</p>
<p>Links and code examples are very welcome.</p>
<p>I am using the Mono-implementation on Linux.</p>
|
[
{
"answer_id": 173333,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "using"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13565/"
] |
173,278
|
<p>The docs say that calling sys.exit() raises a SystemExit exception which can be caught in outer levels. I have a situation in which I want to definitively and unquestionably exit from inside a test case, however the unittest module catches SystemExit and prevents the exit. This is normally great, but the specific situation I am trying to handle is one where our test framework has detected that it is configured to point to a non-test database. In this case I want to exit and prevent any further tests from being run. Of course since unittest traps the SystemExit and continues happily on it's way, it is thwarting me.</p>
<p>The only option I have thought of so far is using ctypes or something similar to call exit(3) directly but this seems like a pretty fugly hack for something that should be really simple.</p>
|
[
{
"answer_id": 173323,
"author": "Jerub",
"author_id": 14648,
"author_profile": "https://Stackoverflow.com/users/14648",
"pm_score": 8,
"selected": true,
"text": "os._exit() import os\nos._exit(1)\n atexit"
},
{
"answer_id": 13723190,
"author": "MestreLion",
"author_id": 624066,
"author_profile": "https://Stackoverflow.com/users/624066",
"pm_score": 6,
"selected": false,
"text": "os._exit(1) finally: SystemExit try except SystemExit os._exit() sys.exit os._exit import sys, os\n\nEMERGENCY = 255 # can be any number actually\n\ntry:\n # wrap your whole code here ...\n # ... some code\n if x: sys.exit()\n # ... some more code\n if y: sys.exit(EMERGENCY) # use only for emergency exits\n ... # yes, this is valid python!\n\n # Might instead wrap all code in a function\n # It's a common pattern to exit with main's return value, if any\n sys.exit(main())\n\nexcept SystemExit as e:\n if e.code != EMERGENCY:\n raise # normal exit, let unittest catch it at the outer level\nelse:\n os._exit(EMERGENCY) # try to stop *that*!\n e.code"
},
{
"answer_id": 61923077,
"author": "Jason",
"author_id": 3745065,
"author_profile": "https://Stackoverflow.com/users/3745065",
"pm_score": -1,
"selected": false,
"text": "while True:\nprint('Type exit to exit.')\nresponse = input()\nif response == 'exit':\n quit(0)\nprint('You typed ' + response + '.')\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2168/"
] |
173,290
|
<p>I have a list string tag.</p>
<p>I am trying to initialize a dictionary with the key as the tag string and values as the array index.</p>
<pre><code>for i, ithTag in enumerate(tag):
tagDict.update(ithTag=i)
</code></pre>
<p>The above returns me {'ithTag': 608} <em>608 is the 608th index</em></p>
<p>My problem is that while the i is being interpreted as a variable, Python is treating the "ithTag" as a string instead of a variable.</p>
<p>I'm confused, it is kind of hard to google these kind of specific questions. I hope I worded the title of this question correctly,</p>
<p>Thanks!</p>
|
[
{
"answer_id": 173299,
"author": "Jerub",
"author_id": 14648,
"author_profile": "https://Stackoverflow.com/users/14648",
"pm_score": 7,
"selected": true,
"text": "for i, tag in enumerate(tag):\n tagDict[tag] = i\n"
},
{
"answer_id": 173300,
"author": "mbesso",
"author_id": 9510,
"author_profile": "https://Stackoverflow.com/users/9510",
"pm_score": 2,
"selected": false,
"text": "d = {}\nfor i, tag in enumerate(ithTag):\n d[tag] = i\n"
},
{
"answer_id": 173301,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 2,
"selected": false,
"text": "tagDict[ithTag] = i\n"
},
{
"answer_id": 173369,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 4,
"selected": false,
"text": "tagDict.update(map(reversed, enumerate(tag)))\n tagDict.update((t, i) for (i,t) in enumerate(tag))\n"
},
{
"answer_id": 179005,
"author": "Torsten Marek",
"author_id": 9567,
"author_profile": "https://Stackoverflow.com/users/9567",
"pm_score": 4,
"selected": false,
"text": "tagDict = dict((t, i) for i, t in enumerate(tag))\n"
},
{
"answer_id": 13350988,
"author": "Vanuan",
"author_id": 99024,
"author_profile": "https://Stackoverflow.com/users/99024",
"pm_score": 2,
"selected": false,
"text": "for i, ithTag in enumerate(tag):\n tagDict.update({ithTag: i})\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17085/"
] |
173,295
|
<p>How do you select a datagridview row on a right-click?</p>
|
[
{
"answer_id": 173315,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": " // Clear all the previously selected rows\n foreach (DataGridViewRow row in yourDataGridView.Rows)\n {\n row.Selected = false;\n }\n\n // Get the selected Row\n DataGridView.HitTestInfo info = yourDataGridView.HitTest( e.X, e.Y );\n\n // Set as selected\n yourDataGridView.Rows[info.RowIndex].Selected = true;\n"
},
{
"answer_id": 521173,
"author": "Brendan",
"author_id": 199,
"author_profile": "https://Stackoverflow.com/users/199",
"pm_score": 2,
"selected": false,
"text": "DataGridView MouseDown \nprivate void SubClassedGridView_MouseDown(object sender, MouseEventArgs e)\n{\n // Sets is so the right-mousedown will select a cell\n DataGridView.HitTestInfo hti = this.HitTest(e.X, e.Y);\n // Clear all the previously selected rows\n this.ClearSelection();\n\n // Set as selected\n this.Rows[hti.RowIndex].Selected = true;\n}\n"
},
{
"answer_id": 939275,
"author": "Alan Christensen",
"author_id": 84590,
"author_profile": "https://Stackoverflow.com/users/84590",
"pm_score": 5,
"selected": false,
"text": "private void dataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)\n{\n if (e.Button == MouseButtons.Right)\n {\n dataGridView.CurrentCell = dataGridView[e.ColumnIndex, e.RowIndex];\n }\n}\n"
},
{
"answer_id": 1013225,
"author": "Jürgen Steinblock",
"author_id": 98491,
"author_profile": "https://Stackoverflow.com/users/98491",
"pm_score": 0,
"selected": false,
"text": "i = e.RowIndex Me.CurrentCell = Me.Item(e.ColumnIndex, e.RowIndex) Protected Overrides Sub OnCellMouseDown(\n ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)\n\n MyBase.OnCellMouseDown(e)\n\n Select Case e.Button\n Case Windows.Forms.MouseButtons.Right\n If Me.Rows(e.RowIndex).Selected = False Then\n For i As Integer = 0 To Me.RowCount - 1\n SetSelectedRowCore(i, i = e.RowIndex)\n Next\n End If\n\n Me.CurrentCell = Me.Item(e.ColumnIndex, e.RowIndex)\n End Select\n\nEnd Sub\n"
},
{
"answer_id": 59675151,
"author": "IT Vlogs",
"author_id": 1289476,
"author_profile": "https://Stackoverflow.com/users/1289476",
"pm_score": 1,
"selected": false,
"text": "@Alan Christensen Private Sub dgvCustomers_CellMouseDown(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvCustomers.CellMouseDown\n If e.Button = MouseButtons.Right Then\n dgvCustomers.CurrentCell = dgvCustomers(e.ColumnIndex, e.RowIndex)\n End If\nEnd Sub\n"
},
{
"answer_id": 63189155,
"author": "Deluxe23",
"author_id": 10423075,
"author_profile": "https://Stackoverflow.com/users/10423075",
"pm_score": 1,
"selected": false,
"text": "If e.Button = MouseButtons.Right Then\n DataGridView1.CurrentCell = DataGridView1(e.ColumnIndex, e.RowIndex)\nEnd If\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173295",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25078/"
] |
173,305
|
<p>I have a <code>QTreeView</code> class with a context menu installed as follows:</p>
<pre><code>m_ui.tree->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui.tree, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(ShowTreeContextMenu(const QPoint&)));
...
void ShowTreeContextMenu(const QPoint& point)
{
m_treeContextMenu->exec(m_ui.tree->viewport()->mapToGlobal(point));
}
</code></pre>
<p>However when the context menu is being displayed the <code>QTreeView</code> will no longer respond to mouse clicks. Clicking on an item in the <code>QTreeView</code> while the context menu is displayed will remove the context menu but does not select the clicked item.</p>
<p>This is especially disorientating when right clicking on a new item, as the context menu pops up over the new item, but as the item was not selected the contents of the context menu are referring to the previously selected item.</p>
|
[
{
"answer_id": 173535,
"author": "Marius",
"author_id": 1585,
"author_profile": "https://Stackoverflow.com/users/1585",
"pm_score": 1,
"selected": false,
"text": "class TreeView : public QTreeView{\n Q_OBJECT\npublic:\n TreeView(QWidget *parent);\n ~TreeView();\nprotected:\n void contextMenuEvent(QContextMenuEvent *event);\n};\n\nvoid TreeView::contextMenuEvent(QContextMenuEvent *event){\n QMenu menu(this);\n menu.addAction(action1);\n menu.addAction(action2);\n //...\n menu.addAction(actionN);\n menu.exec(event->globalPos());\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173305",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6049/"
] |
173,309
|
<p>I don't have a Rails environment set up and this is actually quite hard to find a quick answer for, so I'll ask the experts.</p>
<p>When Rails creates a table based on your "model" that you have set up, does Rails create a table that mirrors this model exactly, or does it add in more fields to the table to help it work its magic? If so, what other fields does it add and why? Perhaps you could cut and paste the table structure, or simply point me to a doc or tutorial section that addresses this.</p>
|
[
{
"answer_id": 173469,
"author": "Mike Woodhouse",
"author_id": 1060,
"author_profile": "https://Stackoverflow.com/users/1060",
"pm_score": 3,
"selected": false,
"text": "ruby script/generate model User name:string\n class CreateUsers < ActiveRecord::Migration\n def self.up\n create_table :users do |t|\n t.string :name\n\n t.timestamps\n end\n end\n\n def self.down\n drop_table :users\n end\nend\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173309",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23701/"
] |
173,328
|
<p>Some of the most efficient engineers, developers and IT professionals I know usually carry around a common "toolkit" of useful programs, add-ins or utilities which help them for day-to-day debugging, developing or designing.</p>
<p>The question is:<br>
<i>What is in your utility toolkit.. What tools couldn't you live without?</i></p>
|
[
{
"answer_id": 173452,
"author": "Daren Thomas",
"author_id": 2260,
"author_profile": "https://Stackoverflow.com/users/2260",
"pm_score": 2,
"selected": false,
"text": "cmd.Cmd"
},
{
"answer_id": 173529,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 3,
"selected": false,
"text": ".svn/.hg/.git ack \"function\\s+foo\\s*\\(\" --php \n# find the definition of \"foo\" in all php files\n# decendant of the current directory \n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173328",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18471/"
] |
173,329
|
<p>I have this query in sql server 2000:</p>
<pre><code>select pwdencrypt('AAAA')
</code></pre>
<p>which outputs an encrypted string of 'AAAA':</p>
<pre>
0x0100CF465B7B12625EF019E157120D58DD46569AC7BF4118455D12625EF019E157120D58DD46569AC7BF4118455D
</pre>
<p><strong>How can I convert (decrypt) the output from its origin (which is 'AAAA')?</strong></p>
|
[
{
"answer_id": 173344,
"author": "Svet",
"author_id": 8934,
"author_profile": "https://Stackoverflow.com/users/8934",
"pm_score": 5,
"selected": true,
"text": "SELECT password_field FROM mytable WHERE password_field=pwdencrypt(userEnteredValue)\n"
},
{
"answer_id": 173351,
"author": "Anheledir",
"author_id": 5703,
"author_profile": "https://Stackoverflow.com/users/5703",
"pm_score": 1,
"selected": false,
"text": "USE TEMPDB\nGO\ndeclare @hash varbinary (255)\nCREATE TABLE tempdb..h (id_num int, hash varbinary (255))\nSET @hash = pwdencrypt('123') -- encryption\nINSERT INTO tempdb..h (id_num,hash) VALUES (1,@hash)\nSET @hash = pwdencrypt('123')\nINSERT INTO tempdb..h (id_num,hash) VALUES (2,@hash)\nSELECT TOP 1 @hash = hash FROM tempdb..h WHERE id_num = 2\nSELECT pwdcompare ('123', @hash) AS [Success of check] -- Comparison\nSELECT * FROM tempdb..h\nINSERT INTO tempdb..h (id_num,hash) \nVALUES (3,CONVERT(varbinary (255),\n0x01002D60BA07FE612C8DE537DF3BFCFA49CD9968324481C1A8A8FE612C8DE537DF3BFCFA49CD9968324481C1A8A8))\nSELECT TOP 1 @hash = hash FROM tempdb..h WHERE id_num = 3\nSELECT pwdcompare ('123', @hash) AS [Success of check] -- Comparison\nSELECT * FROM tempdb..h\nDROP TABLE tempdb..h\nGO\n"
},
{
"answer_id": 18154134,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 5,
"selected": false,
"text": "hashBytes = 0x0100 | fourByteSalt | SHA1(utf16EncodedPassword+fourByteSalt)\n fourByteSalt = 0x9A664D79;\n SHA1(\"correct horse battery staple\" + 0x9A66D79);\n=SHA1(0x63006F007200720065006300740020006200610074007400650072007900200068006F00720073006500200073007400610070006C006500 0x9A66D79)\n=0x6EDB2FA35E3B8FAB4DBA2FFB62F5426B67FE54A3\n syslogins 0x0100 9A664D79 6EDB2FA35E3B8FAB4DBA2FFB62F5426B67FE54A3 SELECT \n name, CAST(password AS varbinary(max)) AS PasswordHash\nFROM sys.syslogins\nWHERE name = 'sa'\n\nname PasswordHash\n==== ======================================================\nsa 0x01009A664D796EDB2FA35E3B8FAB4DBA2FFB62F5426B67FE54A3\n 0100 9A664D79 6EDB2FA35E3B8FAB4DBA2FFB62F5426B67FE54A3 PasswordHash SHA1(\"correct horse battery staple\" + 0x9A66D79);\n DECLARE @hash varbinary(max)\nSET @hash = 0x01009A664D796EDB2FA35E3B8FAB4DBA2FFB62F5426B67FE54A3\n--Header: 0x0100\n--Salt: 0x9A664D79\n--Hash: 0x6EDB2FA35E3B8FAB4DBA2FFB62F5426B67FE54A3\n\nDECLARE @password nvarchar(max)\nSET @password = 'password'\n\nSELECT\n @password AS CandidatePassword,\n @hash AS PasswordHash,\n \n --Header\n 0x0100\n +\n --Salt\n CONVERT(VARBINARY(4), SUBSTRING(CONVERT(NVARCHAR(MAX), @hash), 2, 2))\n +\n --SHA1 of Password + Salt\n HASHBYTES('SHA1', @password + SUBSTRING(CONVERT(NVARCHAR(MAX), @hash), 2, 2))\n hashBytes = 0x0200 | fourByteSalt | SHA512(utf16EncodedPassword+fourByteSalt)\n 0x0200 SELECT \n name, CAST(password AS varbinary(max)) AS PasswordHash\nFROM sys.syslogins\n\nname PasswordHash\n---- --------------------------------\nxkcd 0x02006A80BA229556EB280AA7818FAF63A0DA8D6B7B120C6760F0EB0CB5BB320A961B04BD0836 0C0E8CC4C326220501147D6A9ABD2A006B33DEC99FCF1A822393FC66226B7D38\n 0200 6A80BA22 9556EB280AA7818FAF63A0DA8D6B7B120C6760F0EB0CB5BB320A961B04BD0836 0C0E8CC4C326220501147D6A9ABD2A006B33DEC99FCF1A822393FC66226B7D38 6A80BA22 63006f0072007200650063007400200068006f0072007300650020006200610074007400650072007900200073007400610070006c006500 6A80BA22 9556EB280AA7818FAF63A0DA8D6B7B120C6760F0EB0CB5BB320A961B04BD0836 0C0E8CC4C326220501147D6A9ABD2A006B33DEC99FCF1A822393FC66226B7D38"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173329",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21963/"
] |
173,332
|
<p>I know there are HTML entities for 1/2, 1/4, and 3/4, but are there others? Like 1/3 or 1/8? Is there a good way to encode arbitrary fractions?</p>
|
[
{
"answer_id": 173347,
"author": "Darryl Hein",
"author_id": 5441,
"author_profile": "https://Stackoverflow.com/users/5441",
"pm_score": 1,
"selected": false,
"text": "15/16<sup>ths</sup>"
},
{
"answer_id": 173402,
"author": "scronide",
"author_id": 22844,
"author_profile": "https://Stackoverflow.com/users/22844",
"pm_score": 5,
"selected": false,
"text": "1/2 → ½ or ½\n1/4 → ¼ or ¼\n3/4 → ¾ or ¾\n1/8 → ⅛ or ⅛\n3/8 → ⅜ or ⅜\n5/8 → ⅝ or ⅝\n7/8 → ⅞ or ⅞\n1/3 → ⅓\n2/3 → ⅔\n1/5 → ⅕\n2/5 → ⅖\n3/5 → ⅗\n4/5 → ⅘\n1/6 → ⅙\n5/6 → ⅚\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7598/"
] |
173,366
|
<p>V8's documentation explains <a href="http://code.google.com/apis/v8/embed.html#dynamic" rel="noreferrer">how to create a Javascript object that wraps a C++ object</a>. The Javascript object holds on to a pointer to a C++ object instance. My question is, let's say you create the C++ object on the heap, how can you get a notification when the Javascript object is collected by the gc, so you can free the heap allocated C++ object?</p>
|
[
{
"answer_id": 176380,
"author": "Max Lybbert",
"author_id": 10593,
"author_profile": "https://Stackoverflow.com/users/10593",
"pm_score": 6,
"selected": true,
"text": "Persistent Persistent MakeWeak() Persistent::MakeWeak Persistent::MakeWeak void MakeWeak(void* parameters, WeakReferenceCallback callback);\n WeakReferenceCallback typedef void (*WeakReferenceCallback)(Persistent<Object> object,\n void* parameter);\n MakeWeak Persistent<Object> void* parameter void* parameter void CleanupV8Point(Persistent<Object> object, void*)\n{\n // do whatever cleanup on object that you're looking for\n object.destroyCppObjects();\n}\n\nParameter<ObjectTemplate> my_obj(ObjectTemplate::New());\n\n// when the Javascript part of my_obj is about to be collected\n// we'll have V8 call CleanupV8Point(my_obj)\nmy_obj.MakeWeak(NULL, &CleanupV8Point);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1892/"
] |
173,374
|
<p>Boost is a very large library with many inter-dependencies -- which also takes a long time to compile (which for me slows down our <a href="http://cruisecontrol.sourceforge.net/" rel="noreferrer"><strong>CruiseControl</strong></a> response time).</p>
<p>The only parts of boost I use are boost::regex and boost::format.</p>
<p>Is there an easy way to extract only the parts of boost necessary for a particular boost sub-library to make compilations faster?</p>
<p>EDIT: To answer the question about why we're re-building boost...</p>
<ol>
<li>Parsing the boost header files still takes a long time. I suspect if we could extract only what we need, parsing would happen faster too.</li>
<li>Our CruiseControl setup builds everything from scratch. This also makes it easier if we update the version of boost we're using. But I will investigate to see if we can change our build process to see if our build machine can build boost when changes occur and commit those changes to SVN. (My company has a policy that everything that goes out the door must be built on the "build machine".)</li>
</ol>
|
[
{
"answer_id": 173388,
"author": "JesperE",
"author_id": 13051,
"author_profile": "https://Stackoverflow.com/users/13051",
"pm_score": 2,
"selected": false,
"text": "CMakeLists.txt project( MyBoost )\n\nset(SOURCES \n boost/regex/src/c_regex_traits.cpp\n boost/regex/src/cpp_regex_traits.cpp\n boost/regex/src/cregex.cpp\n boost/regex/src/fileiter.cpp\n boost/regex/src/icu.cpp\n boost/regex/src/instances.cpp\n boost/regex/src/posix_api.cpp\n boost/regex/src/regex.cpp\n boost/regex/src/regex_debug.cpp\n boost/regex/src/regex_raw_buffer.cpp\n boost/regex/src/regex_traits_defaults.cpp\n boost/regex/src/static_mutex.cpp\n boost/regex/src/usinstances.cpp\n boost/regex/src/w32_regex_traits.cpp\n boost/regex/src/wc_regex_traits.cpp\n boost/regex/src/wide_posix_api.cpp\n boost/regex/src/winstances.cpp\n)\n\nadd_library( MyBoost STATIC ${SOURCES})\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6386/"
] |
173,389
|
<p>I've build my WinForm app on windows machine and the app is working
ok. When I user nhibernate 1.2.1 the app also worked on linux machine
using mono, but now when i upgraded app to nhibernate 2.0.1 it works
only in windows.
I've get error:
NHibernate.InvalidProxyTypeException: The following types may not be
used as proxies:
xxxx.Data.Dao.Credit : method obj_address should be virtual
......
Can anyone help me with this problem? </p>
|
[
{
"answer_id": 531023,
"author": "jrwren",
"author_id": 16998,
"author_profile": "https://Stackoverflow.com/users/16998",
"pm_score": 1,
"selected": false,
"text": "<property name=\"use_proxy_validator\">false</property> <?xml version=\"1.0\"?>\n<configuration>\n <configSections>\n <section name=\"hibernate-configuration\"\n type=\"NHibernate.Cfg.ConfigurationSectionHandler, NHibernate\" />\n </configSections>\n\n <hibernate-configuration xmlns=\"urn:nhibernate-configuration-2.2\">\n <session-factory>\n <!--\n <property name=\"dialect\">NHibernate.Dialect.MsSql2005Dialect</property>\n <property name=\"connection.provider\">NHibernate.Connection.DriverConnectionProvider</property>\n <property name=\"connection.driver_class\">NHibernate.Driver.SqlClientDriver</property>\n <property name=\"connection.connection_string\">Data Source=YOUR_DB_SERVER;Database=Northwind;User ID=YOUR_USERNAME;Password=YOUR_PASSWORD;</property>\n <property name=\"connection.isolation\">ReadCommitted</property>\n <property name=\"default_schema\">Northwind.dbo</property>\n -->\n <!--\n <property name=\"dialect\">NHibernate.Dialect.SQLiteDialect</property>\n <property name=\"connection.provider\">NHibernate.Connection.DriverConnectionProvider</property>\n <property name=\"connection.driver_class\">NHibernate.Driver.SQLiteDriver</property>\n <property name=\"connection.connection_string\">Data Source=nhibernate.db;Version=3</property>\n <property name=\"query.substitutions\">true=1;false=0</property>\n -->\n <!-- mysql\n <property name=\"dialect\">NHibernate.Dialect.MySQLDialect</property>\n <property name=\"connection.provider\">NHibernate.Connection.DriverConnectionProvider</property>\n <property name=\"connection.driver_class\">NHibernate.Driver.MySqlDataDriver</property>\n <property name=\"connection.connection_string\">Database=test</property>\n -->\n <property name=\"connection.provider\">NHibernate.Connection.DriverConnectionProvider</property>\n <property name=\"connection.driver_class\">NHibernate.Driver.NpgsqlDriver</property>\n <property name=\"connection.connection_string\">Server=localhost;database=test;User id=jrwren;password=yourpasswordhere.</property>\n <property name=\"dialect\">NHibernate.Dialect.PostgreSQLDialect</property>\n <property name=\"use_proxy_validator\">false</property>\n <!-- HBM Mapping Files -->\n <mapping assembly=\"Test.exe\" />\n </session-factory>\n </hibernate-configuration>\n\n</configuration>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
173,393
|
<p>I'm trying to use the <code>Microsoft.Sdc.Tasks.ServiceProcess.Exists</code> to check whether or not a service exists. There is no example of using it in the documentation though. Anyone have one?</p>
|
[
{
"answer_id": 173440,
"author": "Dandikas",
"author_id": 23436,
"author_profile": "https://Stackoverflow.com/users/23436",
"pm_score": 2,
"selected": false,
"text": "<target name=\"service_exists\">\n <script language=\"C#\">\n <references>\n <include name=\"System.ServiceProcess.dll\" />\n </references>\n <code><![CDATA[\n public static void ScriptMain(Project project) {\n String serviceName = project.Properties[\"service.name\"];\n project.Properties[\"service.exists\"] = \"false\";\n project.Properties[\"service.running\"] = \"false\";\n\n System.ServiceProcess.ServiceController[] scServices;\n scServices = System.ServiceProcess.ServiceController.GetServices();\n\n foreach (System.ServiceProcess.ServiceController scTemp in scServices)\n {\n if (String.Compare(scTemp.ServiceName.ToUpper(), serviceName.ToUpper()) == 0)\n {\n project.Properties[\"service.exists\"] = \"true\";\n project.Log(Level.Info, \"Service \" + serviceName + \" exists\");\n if (scTemp.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Running))\n project.Properties[\"service.running\"] = \"true\";\n project.Log(Level.Info, \"Service \" + serviceName + \" is running: \" + project.Properties[\"service.running\"]);\n return;\n }\n }\n project.Log(Level.Info, \"Service \" + serviceName + \" doesn't exist\");\n }\n ]]></code>\n </script>\n</target>\n <property name=\"service.name\" value=\"Selection.Service\" />\n<call target=\"service_exists\" />\n\n<servicecontroller action=\"Stop\" service=\"${service.name}\" machine=\"${host}\" timeout=\"60000\" if=\"${service.exists}\"/>\n\n<!-- Do something -->\n\n<servicecontroller action=\"Start\" service=\"${service.name}\" machine=\"${host}\" timeout=\"60000\" if=\"${bool::parse(service.exists) and bool::parse(service.running) == true}\"/>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] |
173,400
|
<p>PHP treats all arrays as associative, so there aren't any built in functions. Can anyone recommend a fairly efficient way to check if an array <em>"is a list"</em> (contains only numeric keys starting from 0)?</p>
<p>Basically, I want to be able to differentiate between this:</p>
<pre><code>$sequentialArray = [
'apple', 'orange', 'tomato', 'carrot'
];
</code></pre>
<p>and this:</p>
<pre><code>$assocArray = [
'fruit1' => 'apple',
'fruit2' => 'orange',
'veg1' => 'tomato',
'veg2' => 'carrot'
];
</code></pre>
|
[
{
"answer_id": 173412,
"author": "Daren Thomas",
"author_id": 2260,
"author_profile": "https://Stackoverflow.com/users/2260",
"pm_score": 0,
"selected": false,
"text": "for i in 0 to len(your_array):\n if not defined(your-array[i]):\n # this is not an array array, it's an associative array :)\n"
},
{
"answer_id": 173435,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": -1,
"selected": false,
"text": "isset($myArray[count($myArray) - 1])\n $myArray = array(\"1\" => \"apple\", \"b\" => \"banana\");\n function arrayIsAssociative($myArray) {\n foreach (array_keys($myArray) as $ind => $key) {\n if (!is_numeric($key) || (isset($myArray[$ind + 1]) && $myArray[$ind + 1] != $key + 1)) {\n return true;\n }\n }\n return false;\n}\n// this will only return true if all the keys are numeric AND sequential, which\n// is what you get when you define an array like this:\n// array(\"a\", \"b\", \"c\", \"d\", \"e\");\n function arrayIsAssociative($myArray) {\n $l = count($myArray);\n for ($i = 0; $i < $l, ++$i) {\n if (!isset($myArray[$i])) return true;\n }\n return false;\n}\n// this will return a false positive on an array like this:\n$x = array(1 => \"b\", 0 => \"a\", 2 => \"c\", 4 => \"e\", 3 => \"d\");\n"
},
{
"answer_id": 173443,
"author": "scronide",
"author_id": 22844,
"author_profile": "https://Stackoverflow.com/users/22844",
"pm_score": 0,
"selected": false,
"text": "function is_associative($arr) {\n return (array_merge($arr) !== $arr || count(array_filter($arr, 'is_string', ARRAY_FILTER_USE_KEY)) > 0);\n}\n"
},
{
"answer_id": 173479,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 11,
"selected": true,
"text": "function isAssoc(array $arr)\n{\n if (array() === $arr) return false;\n return array_keys($arr) !== range(0, count($arr) - 1);\n}\n\nvar_dump(isAssoc(['a', 'b', 'c'])); // false\nvar_dump(isAssoc([\"0\" => 'a', \"1\" => 'b', \"2\" => 'c'])); // false\nvar_dump(isAssoc([\"1\" => 'a', \"0\" => 'b', \"2\" => 'c'])); // true\nvar_dump(isAssoc([\"a\" => 'a', \"b\" => 'b', \"c\" => 'c'])); // true\n"
},
{
"answer_id": 173589,
"author": "null",
"author_id": 25411,
"author_profile": "https://Stackoverflow.com/users/25411",
"pm_score": -1,
"selected": false,
"text": "function IsAssociative($array)\n{\n return preg_match('/[a-z]/i', implode(array_keys($array)));\n}\n"
},
{
"answer_id": 173735,
"author": "Mez",
"author_id": 20010,
"author_profile": "https://Stackoverflow.com/users/20010",
"pm_score": 0,
"selected": false,
"text": "function array_isassociative($array)\n{\n // Create new Array, Make it the same size as the input array\n $compareArray = array_pad(array(), count($array), 0);\n\n // Compare the two array_keys\n return (count(array_diff_key($array, $compareArray))) ? true : false;\n\n}\n"
},
{
"answer_id": 265144,
"author": "Dave Marshall",
"author_id": 1248,
"author_profile": "https://Stackoverflow.com/users/1248",
"pm_score": 7,
"selected": false,
"text": "<?php\n$arr = array(1,2,3,4);\n$isIndexed = array_values($arr) === $arr;\n"
},
{
"answer_id": 265173,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "function isAssoc($arr)\n{\n $a = array_keys($arr);\n for($i = 0, $t = count($a); $i < $t; $i++)\n {\n if($a[$i] != $i)\n {\n return false;\n }\n }\n return true;\n}\n"
},
{
"answer_id": 524978,
"author": "Bretticus",
"author_id": 411075,
"author_profile": "https://Stackoverflow.com/users/411075",
"pm_score": -1,
"selected": false,
"text": "<?php\nvar_dump(key(array('hello'=>'world', 'hello'=>'world'))); //string(5) \"hello\"\nvar_dump(key(array('world', 'world'))); //int(0)\nvar_dump(key(array(\"0\" => 'a', \"1\" => 'b', \"2\" => 'c'))); //int(0) who makes string sequetial keys anyway????\n?>\n"
},
{
"answer_id": 652760,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "function is_assoc($array){\n $keys = array_keys($array);\n return $keys !== array_keys($keys);\n}\n"
},
{
"answer_id": 869220,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "function isHash($array) {\n if (!is_array($array)) return false;\n $diff = array_diff_assoc($array, array_values($array));\n return (empty($diff)) ? false : true;\n}\n"
},
{
"answer_id": 2444661,
"author": "dsims",
"author_id": 293640,
"author_profile": "https://Stackoverflow.com/users/293640",
"pm_score": 5,
"selected": false,
"text": "function checkAssoc($array){\n return ctype_digit( implode('', array_keys($array) ) );\n}\n"
},
{
"answer_id": 3883417,
"author": "podperson",
"author_id": 438186,
"author_profile": "https://Stackoverflow.com/users/438186",
"pm_score": 4,
"selected": false,
"text": "array_keys($obj) !== range(0, count($obj) - 1) array_values($arr) !== $arr array_keys array_values function array_type( $obj ){\n $last_key = -1;\n $type = 'index';\n foreach( $obj as $key => $val ){\n if( !is_int( $key ) || $key < 0 ){\n return 'assoc';\n }\n if( $key !== $last_key + 1 ){\n $type = 'sparse';\n }\n $last_key = $key;\n }\n return $type;\n}\n 'assoc' if"
},
{
"answer_id": 3886942,
"author": "LazNiko",
"author_id": 412686,
"author_profile": "https://Stackoverflow.com/users/412686",
"pm_score": 3,
"selected": false,
"text": "function is_asso($a){\n foreach(array_keys($a) as $key) {if (!is_int($key)) return TRUE;}\n return FALSE;\n}\n"
},
{
"answer_id": 4254008,
"author": "Captain kurO",
"author_id": 356912,
"author_profile": "https://Stackoverflow.com/users/356912",
"pm_score": 9,
"selected": false,
"text": "function has_string_keys(array $array) {\n return count(array_filter(array_keys($array), 'is_string')) > 0;\n}\n $array"
},
{
"answer_id": 4903360,
"author": "Kat Lim Ruiz",
"author_id": 603865,
"author_profile": "https://Stackoverflow.com/users/603865",
"pm_score": 2,
"selected": false,
"text": " public static function isArrayAssociative(array $array) {\n reset($array);\n return !is_int(key($array));\n }\n"
},
{
"answer_id": 5721315,
"author": "Sophie McCarrell",
"author_id": 680761,
"author_profile": "https://Stackoverflow.com/users/680761",
"pm_score": 0,
"selected": false,
"text": "<?php\n//$a is a subset of $b\nfunction isSubset($a, $b)\n{\n foreach($a =>$v)\n if(array_search($v, $b) === false)\n return false;\n\n return true;\n\n //less effecient, clearer implementation. (uses === for comparison)\n //return array_intersect($a, $b) === $a;\n}\n\nfunction isAssoc($arr)\n{\n return !isSubset(array_keys($arr), range(0, count($arr) - 1));\n}\n\nvar_dump(isAssoc(array('a', 'b', 'c'))); // false\nvar_dump(isAssoc(array(1 => 'a', 0 => 'b', 2 => 'c'))); // false\nvar_dump(isAssoc(array(\"0\" => 'a', \"1\" => 'b', \"2\" => 'c'))); // false \n//(use === in isSubset to get 'true' for above statement)\nvar_dump(isAssoc(array(\"a\" => 'a', \"b\" => 'b', \"c\" => 'c'))); // true\n?>\n"
},
{
"answer_id": 5969617,
"author": "squirrel",
"author_id": 645436,
"author_profile": "https://Stackoverflow.com/users/645436",
"pm_score": 6,
"selected": false,
"text": "function keyedNext( &$arr, &$k){\n $k = key($arr);\n return next($arr);\n}\n\nfor ($k = key(reset($my_array)); is_int($k); keyedNext($my_array,$k))\n $onlyIntKeys = is_null($k);\n"
},
{
"answer_id": 6462524,
"author": "hornetbzz",
"author_id": 461212,
"author_profile": "https://Stackoverflow.com/users/461212",
"pm_score": -1,
"selected": false,
"text": " /* Returns true if $var associative array */ \n function is_associative_array( $array ) { \n return is_array($array) && !is_numeric(implode('', array_keys($array))); \n }\n"
},
{
"answer_id": 6795076,
"author": "AL the X",
"author_id": 126992,
"author_profile": "https://Stackoverflow.com/users/126992",
"pm_score": 2,
"selected": false,
"text": "function is_associative ( $a )\n{\n return in_array(false, array_map('is_numeric', array_keys($a)));\n}\n\nassert( true === is_associative(array(1, 2, 3, 4)) );\n\nassert( false === is_associative(array('foo' => 'bar', 'bar' => 'baz')) );\n\nassert( false === is_associative(array(1, 2, 3, 'foo' => 'bar')) );\n $a = array( 1, 2, 3, 4 );\n\nunset($a[1]);\n\nassert( true === is_associative($a) );\n"
},
{
"answer_id": 6894050,
"author": "Sergey Shuchkin",
"author_id": 594867,
"author_profile": "https://Stackoverflow.com/users/594867",
"pm_score": -1,
"selected": false,
"text": "<?php\nfunction is_assoc($arr) { return (array_values($arr) !== $arr); }\n?>\n"
},
{
"answer_id": 6968499,
"author": "Alix Axel",
"author_id": 89771,
"author_profile": "https://Stackoverflow.com/users/89771",
"pm_score": 5,
"selected": false,
"text": "function isAssoc($array)\n{\n return ($array !== array_values($array));\n}\n function isAssoc($array)\n{\n $array = array_keys($array); return ($array !== array_keys($array));\n}\n"
},
{
"answer_id": 7049956,
"author": "sexytrends",
"author_id": 892971,
"author_profile": "https://Stackoverflow.com/users/892971",
"pm_score": -1,
"selected": false,
"text": "function isAssoc($arr = NULL)\n{\n if ($arr && is_array($arr))\n {\n foreach ($arr as $key => $val)\n {\n if (is_numeric($key)) { return true; }\n\n break;\n }\n }\n\n return false;\n}\n"
},
{
"answer_id": 7293257,
"author": "Galileo_Galilei",
"author_id": 627114,
"author_profile": "https://Stackoverflow.com/users/627114",
"pm_score": -1,
"selected": false,
"text": "function Is_Indexed_Arr($arr){\n $arr_copy = $arr;\n if((2*count($arr)) == count(array_merge($arr, $arr_copy))){\n return 1;\n }\n return 0;\n}\n"
},
{
"answer_id": 8542459,
"author": "GO.exe",
"author_id": 1050728,
"author_profile": "https://Stackoverflow.com/users/1050728",
"pm_score": -1,
"selected": false,
"text": "private function is_hash($array) {\n foreach($array as $key => $value) {\n return ! is_int($key);\n }\n return false;\n}\n array_keys(array(\n \"abc\" => \"gfb\",\n \"bdc\" => \"dbc\"\n )\n);\n array(\n 0 => \"abc\",\n 1 => \"bdc\"\n)\n"
},
{
"answer_id": 10614509,
"author": "KillEveryBody",
"author_id": 1211413,
"author_profile": "https://Stackoverflow.com/users/1211413",
"pm_score": 2,
"selected": false,
"text": "<?php\n\nfunction is_list($array) {\n return array_keys($array) === range(0, count($array) - 1);\n}\n\nfunction is_assoc($array) {\n return count(array_filter(array_keys($array), 'is_string')) == count($array);\n}\n\n?>\n $array = array('foo' => 'bar', 1)"
},
{
"answer_id": 11136956,
"author": "Gordon",
"author_id": 208809,
"author_profile": "https://Stackoverflow.com/users/208809",
"pm_score": 2,
"selected": false,
"text": "function array_has_numeric_keys_only(array $array)\n{\n try {\n SplFixedArray::fromArray($array, true);\n } catch (InvalidArgumentException $e) {\n return false;\n }\n return true;\n}\n SplFixedArray"
},
{
"answer_id": 11236087,
"author": "misterich",
"author_id": 293332,
"author_profile": "https://Stackoverflow.com/users/293332",
"pm_score": -1,
"selected": false,
"text": "/** \n * Checks if an array is associative by utilizing REGEX against the keys\n * @param $arr <array> Reference to the array to be checked\n * @return boolean\n */ \nprivate function isAssociativeArray( &$arr ) {\n return (bool)( preg_match( '/\\D/', implode( array_keys( $arr ) ) ) );\n}\n return array(\n \"GetInventorySummary\" => array(\n \"Filters\" => array( \n \"Filter\" => array(\n array(\n \"FilterType\" => \"Shape\",\n \"FilterValue\" => \"W\",\n ),\n array(\n \"FilterType\" => \"Dimensions\",\n \"FilterValue\" => \"8 x 10\",\n ),\n array(\n \"FilterType\" => \"Grade\",\n \"FilterValue\" => \"A992\",\n ),\n ),\n ),\n \"SummaryField\" => \"Length\",\n ),\n);\n filter return array(\n \"GetInventorySummary\" => array(\n \"Filters\" => array( \n \"Filter\" => array(\n \"foo\" => \"bar\",\n \"bar\" => \"foo\",\n ),\n ),\n \"SummaryField\" => \"Length\",\n ),\n);\n <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<GetInventorySummary>\n <Filters>\n <Filter>\n <FilterType>Shape</FilterType>\n <FilterValue>W</FilterValue>\n </Filter>\n <Filter>\n <FilterType>Dimensions</FilterType>\n <FilterValue>8 x 10</FilterValue>\n </Filter>\n <Filter>\n <FilterType>Grade</FilterType>\n <FilterValue>A992</FilterValue>\n </Filter>\n </Filters>\n <SummaryField>Length</SummaryField>\n</GetInventorySummary>\n <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<GetInventorySummary>\n <Filters>\n <Filter>\n <foo>bar</foo>\n <bar>foo</bar>\n </Filter>\n </Filters>\n <SummaryField>Length</SummaryField>\n</GetInventorySummary>\n"
},
{
"answer_id": 11495941,
"author": "Niels Ockeloen",
"author_id": 1527516,
"author_profile": "https://Stackoverflow.com/users/1527516",
"pm_score": 4,
"selected": false,
"text": "function is_indexed_array(&$arr) {\n for (reset($arr); is_int(key($arr)); next($arr));\n return is_null(key($arr));\n}\n\nfunction is_sequential_array(&$arr, $base = 0) {\n for (reset($arr), $base = (int) $base; key($arr) === $base++; next($arr));\n return is_null(key($arr));\n}\n"
},
{
"answer_id": 13522545,
"author": "Pang",
"author_id": 1402846,
"author_profile": "https://Stackoverflow.com/users/1402846",
"pm_score": 5,
"selected": false,
"text": "//! Check whether the input is an array whose keys are all integers.\n/*!\n \\param[in] $InputArray (array) Input array.\n \\return (bool) \\b true iff the input is an array whose keys are all integers.\n*/\nfunction IsArrayAllKeyInt($InputArray)\n{\n if(!is_array($InputArray))\n {\n return false;\n }\n\n if(count($InputArray) <= 0)\n {\n return true;\n }\n\n return array_unique(array_map(\"is_int\", array_keys($InputArray))) === array(true);\n}\n //! Check whether the input is an array whose keys are all strings.\n/*!\n \\param[in] $InputArray (array) Input array.\n \\return (bool) \\b true iff the input is an array whose keys are all strings.\n*/\nfunction IsArrayAllKeyString($InputArray)\n{\n if(!is_array($InputArray))\n {\n return false;\n }\n\n if(count($InputArray) <= 0)\n {\n return true;\n }\n\n return array_unique(array_map(\"is_string\", array_keys($InputArray))) === array(true);\n}\n //! Check whether the input is an array with at least one key being an integer and at least one key being a string.\n/*!\n \\param[in] $InputArray (array) Input array.\n \\return (bool) \\b true iff the input is an array with at least one key being an integer and at least one key being a string.\n*/\nfunction IsArraySomeKeyIntAndSomeKeyString($InputArray)\n{\n if(!is_array($InputArray))\n {\n return false;\n }\n\n if(count($InputArray) <= 0)\n {\n return true;\n }\n\n return count(array_unique(array_map(\"is_string\", array_keys($InputArray)))) >= 2;\n}\n //! Check whether the input is an array whose keys are numeric, sequential, and zero-based.\n/*!\n \\param[in] $InputArray (array) Input array.\n \\return (bool) \\b true iff the input is an array whose keys are numeric, sequential, and zero-based.\n*/\nfunction IsArrayKeyNumericSequentialZeroBased($InputArray)\n{\n if(!is_array($InputArray))\n {\n return false;\n }\n\n if(count($InputArray) <= 0)\n {\n return true;\n }\n\n return array_keys($InputArray) === range(0, count($InputArray) - 1);\n}\n array(0 => \"b\");\narray(13 => \"b\");\narray(-13 => \"b\"); // Negative integers are also integers.\narray(0x1A => \"b\"); // Hexadecimal notation.\n array(\"fish and chips\" => \"b\");\narray(\"\" => \"b\"); // An empty string is also a string.\narray(\"stackoverflow_email@example.com\" => \"b\"); // Strings may contain non-alphanumeric characters.\narray(\"stack\\t\\\"over\\\"\\r\\nflow's cool\" => \"b\"); // Strings may contain special characters.\narray('$tα€k↔øv∈rflöw⛄' => \"b\"); // Strings may contain all kinds of symbols.\narray(\"functіon\" => \"b\"); // You think this looks fine? Think again! (see https://stackoverflow.com/q/9246051/1402846)\narray(\"ま말轉转ДŁ\" => \"b\"); // How about Japanese/Korean/Chinese/Russian/Polish?\narray(\"fi\\x0sh\" => \"b\"); // Strings may contain null characters.\narray(file_get_contents(\"https://www.google.com/images/nav_logo114.png\") => \"b\"); // Strings may even be binary!\n array(\"13\" => \"b\") array(\"13\" => \"b\");\narray(\"-13\" => \"b\"); // Negative, ok.\n array(\"13.\" => \"b\");\narray(\"+13\" => \"b\"); // Positive, not ok.\narray(\"-013\" => \"b\");\narray(\"0x1A\" => \"b\"); // Not converted to integers even though it's a valid hexadecimal number.\narray(\"013\" => \"b\"); // Not converted to integers even though it's a valid octal number.\narray(\"18446744073709551616\" => \"b\"); // Not converted to integers as it can't fit into a 64-bit integer.\n array(\"60000000000\" => \"b\"); // Array key could be integer or string, it can fit into a 64-bit (but not 32-bit) integer.\n var_dump(array(\"2147483647\" => \"b\")) array(1) {\n [2147483647]=>\n string(1) \"b\"\n} \n array(1) {\n [\"2147483647\"]=>\n string(1) \"b\"\n}\n 2147483647"
},
{
"answer_id": 14026836,
"author": "David Farrell",
"author_id": 1822537,
"author_profile": "https://Stackoverflow.com/users/1822537",
"pm_score": 2,
"selected": false,
"text": "<?php\n/**\n * Since PHP stores all arrays as associative internally, there is no proper\n * definition of a scalar array.\n * \n * As such, developers are likely to have varying definitions of scalar array,\n * based on their application needs.\n * \n * In this file, I present 3 increasingly strict methods of determining if an\n * array is scalar.\n * \n * @author David Farrell <DavidPFarrell@gmail.com>\n */\n\n/**\n * isArrayWithOnlyIntKeys defines a scalar array as containing\n * only integer keys.\n * \n * If you are explicitly setting integer keys on an array, you\n * may need this function to determine scalar-ness.\n * \n * @param array $a\n * @return boolean\n */ \nfunction isArrayWithOnlyIntKeys(array $a)\n{\n if (!is_array($a))\n return false;\n foreach ($a as $k => $v)\n if (!is_int($k))\n return false;\n return true;\n}\n\n/**\n * isArrayWithOnlyAscendingIntKeys defines a scalar array as\n * containing only integer keys in ascending (but not necessarily\n * sequential) order.\n * \n * If you are performing pushes, pops, and unsets on your array,\n * you may need this function to determine scalar-ness.\n * \n * @param array $a\n * @return boolean\n */ \nfunction isArrayWithOnlyAscendingIntKeys(array $a)\n{\n if (!is_array($a))\n return false;\n $prev = null;\n foreach ($a as $k => $v)\n {\n if (!is_int($k) || (null !== $prev && $k <= $prev))\n return false;\n $prev = $k;\n }\n return true;\n}\n\n/**\n * isArrayWithOnlyZeroBasedSequentialIntKeys defines a scalar array\n * as containing only integer keys in sequential, ascending order,\n * starting from 0.\n * \n * If you are only performing operations on your array that are\n * guaranteed to either maintain consistent key values, or that\n * re-base the keys for consistency, then you can use this function.\n * \n * @param array $a\n * @return boolean\n */\nfunction isArrayWithOnlyZeroBasedSequentialIntKeys(array $a)\n{\n if (!is_array($a))\n return false;\n $i = 0;\n foreach ($a as $k => $v)\n if ($i++ !== $k)\n return false;\n return true;\n}\n"
},
{
"answer_id": 14977628,
"author": "Manu Manjunath",
"author_id": 495598,
"author_profile": "https://Stackoverflow.com/users/495598",
"pm_score": 3,
"selected": false,
"text": "array_values() key() $arrays = Array(\n 'Array #1' => Array(1, 2, 3, 54, 23, 212, 123, 1, 1),\n 'Array #2' => Array(\"Stack\", 1.5, 20, Array(3.4)),\n 'Array #3' => Array(1 => 4, 2 => 2),\n 'Array #4' => Array(3.0, \"2\", 3000, \"Stack\", 5 => \"4\"),\n 'Array #5' => Array(\"3\" => 4, \"2\" => 2),\n 'Array #6' => Array(\"0\" => \"One\", 1.0 => \"Two\", 2 => \"Three\"),\n 'Array #7' => Array(3 => \"asdf\", 4 => \"asdf\"),\n 'Array #8' => Array(\"apple\" => 1, \"orange\" => 2),\n);\n\nfunction is_indexed_array_1(Array &$arr) {\n return $arr === array_values($arr);\n}\n\nfunction is_indexed_array_2(Array &$arr) {\n for (reset($arr), $i = 0; key($arr) === $i++; next($arr))\n ;\n return is_null(key($arr));\n}\n\n// Method #1\n$start = microtime(true);\nfor ($i = 0; $i < 1000; $i++) {\n foreach ($arrays as $array) {\n $dummy = is_indexed_array_1($array);\n }\n}\n$end = microtime(true);\necho \"Time taken with method #1 = \".round(($end-$start)*1000.0,3).\"ms\\n\";\n\n// Method #2\n$start = microtime(true);\nfor ($i = 0; $i < 1000; $i++) {\n foreach ($arrays as $array) {\n $dummy = is_indexed_array_2($array);\n }\n}\n$end = microtime(true);\necho \"Time taken with method #1 = \".round(($end-$start)*1000.0,3).\"ms\\n\";\n array_values()"
},
{
"answer_id": 17582663,
"author": "cloudfeet",
"author_id": 472388,
"author_profile": "https://Stackoverflow.com/users/472388",
"pm_score": 2,
"selected": false,
"text": "function isNumericArray($array) {\n $count = count($array);\n for ($i = 0; $i < $count; $i++) {\n if (!isset($array[$i])) {\n return FALSE;\n }\n }\n return TRUE;\n}\n"
},
{
"answer_id": 22396003,
"author": "macki",
"author_id": 1040357,
"author_profile": "https://Stackoverflow.com/users/1040357",
"pm_score": -1,
"selected": false,
"text": "function is_array_assoc($foo) {\n if (is_array($foo)) {\n return (count(array_filter(array_keys($foo), 'is_string')) > 0);\n }\n return false;\n}\n"
},
{
"answer_id": 24650366,
"author": "Byscripts",
"author_id": 1539115,
"author_profile": "https://Stackoverflow.com/users/1539115",
"pm_score": 2,
"selected": false,
"text": "function isAssociative(array $array)\n{\n return array_keys(array_merge($array)) !== range(0, count($array) - 1);\n}\n array_merge integer array_merge([1 => 'One', 3 => 'Three', 'two' => 'Two', 6 => 'Six']);\n\n// This will returns [0 => 'One', 1 => 'Three', 'two' => 'Two', 2 => 'Six']\n ['a', 'b', 'c'] unset($a[1]) array_merge"
},
{
"answer_id": 25206156,
"author": "lazycommit",
"author_id": 501831,
"author_profile": "https://Stackoverflow.com/users/501831",
"pm_score": 2,
"selected": false,
"text": "json_encode bson_encode function isSequential($value){\n if(is_array($value) || ($value instanceof \\Countable && $value instanceof \\ArrayAccess)){\n for ($i = count($value) - 1; $i >= 0; $i--) {\n if (!isset($value[$i]) && !array_key_exists($i, $value)) {\n return false;\n }\n }\n return true;\n } else {\n throw new \\InvalidArgumentException(\n sprintf('Data type \"%s\" is not supported by method %s', gettype($value), __METHOD__)\n );\n }\n}\n"
},
{
"answer_id": 33163737,
"author": "c9s",
"author_id": 780629,
"author_profile": "https://Stackoverflow.com/users/780629",
"pm_score": 2,
"selected": false,
"text": "if (array_is_indexed($array)) { }\n if (array_is_assoc($array)) { }\n"
},
{
"answer_id": 34908614,
"author": "Loading",
"author_id": 1263456,
"author_profile": "https://Stackoverflow.com/users/1263456",
"pm_score": 3,
"selected": false,
"text": "json_encode { [ // Too short :)\nfunction is_assoc($arr) {\n ksort($arr);\n return json_encode($arr)[0] === '{';\n}\n"
},
{
"answer_id": 35858728,
"author": "Jesse",
"author_id": 268083,
"author_profile": "https://Stackoverflow.com/users/268083",
"pm_score": 3,
"selected": false,
"text": "function array_is_assoc(array $a) {\n $i = 0;\n foreach ($a as $k => $v) {\n if ($k !== $i++) {\n return true;\n }\n }\n return false;\n}\n"
},
{
"answer_id": 38183890,
"author": "nonsensei",
"author_id": 4805056,
"author_profile": "https://Stackoverflow.com/users/4805056",
"pm_score": 2,
"selected": false,
"text": "<?php\n\nfunction method_1(Array &$arr) {\n return $arr === array_values($arr);\n}\n\nfunction method_2(Array &$arr) {\n for (reset($arr), $i = 0; key($arr) !== $i++; next($arr));\n return is_null(key($arr));\n}\n\nfunction method_3(Array &$arr) {\n return array_keys($arr) === range(0, count($arr) - 1);\n}\n\nfunction method_4(Array &$arr) {\n $idx = 0;\n foreach( $arr as $key => $val ){\n if( $key !== $idx )\n return FALSE;\n $idx++;\n }\n return TRUE;\n}\n\n\n\n\nfunction benchmark(Array $methods, Array &$target){ \n foreach($methods as $method){\n $start = microtime(true);\n for ($i = 0; $i < 1000; $i++)\n $dummy = call_user_func($method, $target);\n\n $end = microtime(true);\n echo \"Time taken with $method = \".round(($end-$start)*1000.0,3).\"ms\\n\";\n }\n}\n\n\n\n$targets = [\n 'Huge array' => range(0, 30000),\n 'Small array' => range(0, 1000),\n];\n$methods = [\n 'method_1',\n 'method_2',\n 'method_3',\n 'method_4',\n];\nforeach($targets as $targetName => $target){\n echo \"==== Benchmark using $targetName ====\\n\";\n benchmark($methods, $target);\n echo \"\\n\";\n}\n ==== Benchmark using Huge array ====\nTime taken with method_1 = 5504.632ms\nTime taken with method_2 = 4509.445ms\nTime taken with method_3 = 8614.883ms\nTime taken with method_4 = 2720.934ms\n\n==== Benchmark using Small array ====\nTime taken with method_1 = 77.159ms\nTime taken with method_2 = 130.03ms\nTime taken with method_3 = 160.866ms\nTime taken with method_4 = 69.946ms\n"
},
{
"answer_id": 38471132,
"author": "Justin Levene",
"author_id": 1938802,
"author_profile": "https://Stackoverflow.com/users/1938802",
"pm_score": -1,
"selected": false,
"text": "function isAssoc($arr)\n{\n // Is it set, is an array, not empty and keys are not sequentialy numeric from 0\n return isset($arr) && is_array($arr) && count($arr)!=0 && array_keys($arr) !== range(0, count($arr) - 1);\n}\n if (isAssoc($array)) ...\n if (!isAssoc($array)) ...\n"
},
{
"answer_id": 39956857,
"author": "Haresh Vidja",
"author_id": 1793428,
"author_profile": "https://Stackoverflow.com/users/1793428",
"pm_score": -1,
"selected": false,
"text": "array_keys() array_filter() is_numeric() function isAssociative(array $array)\n {\n return count(array_filter(array_keys($array), function($v){return is_numeric($v);})) !== count($array));\n }\n"
},
{
"answer_id": 43237845,
"author": "Ben",
"author_id": 3150636,
"author_profile": "https://Stackoverflow.com/users/3150636",
"pm_score": 3,
"selected": false,
"text": "/**\n * Determines if an array is associative.\n *\n * An array is \"associative\" if it doesn't have sequential numerical keys beginning with zero.\n *\n * @param array $array\n * @return bool\n */\npublic static function isAssoc(array $array)\n{\n $keys = array_keys($array);\n\n return array_keys($keys) !== $keys;\n}\n"
},
{
"answer_id": 44793312,
"author": "voodoo417",
"author_id": 1397379,
"author_profile": "https://Stackoverflow.com/users/1397379",
"pm_score": -1,
"selected": false,
"text": "stdClass $assocArray = array('fruit1' => 'apple', \n 'fruit2' => 'orange', \n 'veg1' => 'tomato', \n 'veg2' => 'carrot');\n\n$assoc_object = (object) $assocArray;\n$isAssoc = (count($assocArray) === count (get_object_vars($assoc_object))); \nvar_dump($isAssoc); // true\n get_object_vars array object $assocArray = array('apple', 'orange', 'tomato', 'carrot');\n$assoc_object = (object) $assocArray; \n$isAssoc = (count($assocArray) === count (get_object_vars($assoc_object)));\nvar_dump($isAssoc); // false \n//...\n\n$assocArray = array( 0 => 'apple', 'orange', 'tomato', '4' => 'carrot');\n$assoc_object = (object) $assocArray; \n$isAssoc = (count($assocArray) === count (get_object_vars($assoc_object)));\nvar_dump($isAssoc); // false \n\n//... \n$assocArray = array('fruit1' => 'apple', \n NULL => 'orange', \n 'veg1' => 'tomato', \n 'veg2' => 'carrot');\n\n$assoc_object = (object) $assocArray;\n$isAssoc = (count($assocArray) === count (get_object_vars($assoc_object))); \nvar_dump($isAssoc); //false\n"
},
{
"answer_id": 48247922,
"author": "TylerY86",
"author_id": 2879498,
"author_profile": "https://Stackoverflow.com/users/2879498",
"pm_score": 2,
"selected": false,
"text": "/**\n * Tests if an array is an associative array.\n *\n * @param array $array An array to test.\n * @return boolean True if the array is associative, otherwise false.\n */\nfunction is_assoc(array &$arr) {\n // don't try to check non-arrays or empty arrays\n if (FALSE === is_array($arr) || 0 === ($l = count($arr))) {\n return false;\n }\n\n // shortcut by guessing at the beginning\n reset($arr);\n if (key($arr) !== 0) {\n return true;\n }\n\n // shortcut by guessing at the end\n end($arr);\n if (key($arr) !== $l-1) {\n return true;\n }\n\n // rely on php to optimize test by reference or fast compare\n return array_values($arr) !== $arr;\n}\n <?php\n\n// array_values\nfunction method_1(Array &$arr) {\n return $arr === array_values($arr);\n}\n\n// method_2 was DQ; did not actually work\n\n// array_keys\nfunction method_3(Array &$arr) {\n return array_keys($arr) === range(0, count($arr) - 1);\n}\n\n// foreach\nfunction method_4(Array &$arr) {\n $idx = 0;\n foreach( $arr as $key => $val ){\n if( $key !== $idx )\n return FALSE;\n ++$idx;\n }\n return TRUE;\n}\n\n// guessing\nfunction method_5(Array &$arr) {\n global $METHOD_5_KEY;\n $i = 0;\n $l = count($arr)-1;\n\n end($arr);\n if ( key($arr) !== $l )\n return FALSE;\n\n reset($arr);\n do {\n if ( $i !== key($arr) )\n return FALSE;\n ++$i;\n next($arr);\n } while ($i < $l);\n return TRUE;\n}\n\n// naieve\nfunction method_6(Array &$arr) {\n $i = 0;\n $l = count($arr);\n do {\n if ( NULL === @$arr[$i] )\n return FALSE;\n ++$i;\n } while ($i < $l);\n return TRUE;\n}\n\n// deep reference reliance\nfunction method_7(Array &$arr) {\n return array_keys(array_values($arr)) === array_keys($arr);\n}\n\n\n// organic (guessing + array_values)\nfunction method_8(Array &$arr) {\n reset($arr);\n if ( key($arr) !== 0 )\n return FALSE;\n\n end($arr);\n if ( key($arr) !== count($arr)-1 )\n return FALSE;\n\n return array_values($arr) === $arr;\n}\n\nfunction benchmark(Array &$methods, Array &$target, $expected){ \n foreach($methods as $method){\n $start = microtime(true);\n for ($i = 0; $i < 2000; ++$i) {\n //$dummy = call_user_func($method, $target);\n if ( $method($target) !== $expected ) {\n echo \"Method $method is disqualified for returning an incorrect result.\\n\";\n unset($methods[array_search($method,$methods,true)]);\n $i = 0;\n break;\n }\n }\n if ( $i != 0 ) {\n $end = microtime(true);\n echo \"Time taken with $method = \".round(($end-$start)*1000.0,3).\"ms\\n\";\n }\n }\n}\n\n\n\n$true_targets = [\n 'Giant array' => range(0, 500),\n 'Tiny array' => range(0, 20),\n];\n\n\n$g = range(0,10);\nunset($g[0]);\n\n$false_targets = [\n 'Large array 1' => range(0, 100) + ['a'=>'a'] + range(101, 200),\n 'Large array 2' => ['a'=>'a'] + range(0, 200),\n 'Tiny array' => range(0, 10) + ['a'=>'a'] + range(11, 20),\n 'Gotcha array' => $g,\n];\n\n$methods = [\n 'method_1',\n 'method_3',\n 'method_4',\n 'method_5',\n 'method_6',\n 'method_7',\n 'method_8'\n];\n\n\nforeach($false_targets as $targetName => $target){\n echo \"==== Benchmark using $targetName expecing FALSE ====\\n\";\n benchmark($methods, $target, false);\n echo \"\\n\";\n}\nforeach($true_targets as $targetName => $target){\n echo \"==== Benchmark using $targetName expecting TRUE ====\\n\";\n benchmark($methods, $target, true);\n echo \"\\n\";\n}\n"
},
{
"answer_id": 50167674,
"author": "Prathamesh Datar",
"author_id": 1262204,
"author_profile": "https://Stackoverflow.com/users/1262204",
"pm_score": -1,
"selected": false,
"text": "public function is_assoc_array($array){\n\n if(is_array($array) !== true){\n return false;\n }else{\n\n $check = json_decode(json_encode($array));\n\n if(is_object($check) === true){\n return true;\n }else{\n return false;\n }\n\n }\n\n}\n print_r((is_assoc_array(['one','two','three']))===true?'Yes':'No'); \\\\No\n print_r(is_assoc_array(['one'=>'one','two'=>'two','three'=>'three'])?'Yes':'No'); \\\\Yes\n print_r(is_assoc_array(['1'=>'one','2'=>'two','3'=>'three'])?'Yes':'No'); \\\\Yes\n print_r(is_assoc_array(['0'=>'one','1'=>'two','2'=>'three'])?'Yes':'No'); \\\\No\n"
},
{
"answer_id": 52194269,
"author": "Minwork",
"author_id": 10322539,
"author_profile": "https://Stackoverflow.com/users/10322539",
"pm_score": 1,
"selected": false,
"text": "Arr::isAssoc($array)\n Arr:isAssoc($array, true)\n"
},
{
"answer_id": 52275295,
"author": "Slayer Birden",
"author_id": 927404,
"author_profile": "https://Stackoverflow.com/users/927404",
"pm_score": 0,
"selected": false,
"text": "function isSequential(array $list): bool\n{\n $i = 0;\n $count = count($list);\n while (array_key_exists($i, $list)) {\n $i += 1;\n if ($i === $count) {\n return true;\n }\n }\n\n return false;\n}\n\n\nvar_dump(isSequential(array())); // false\nvar_dump(isSequential(array('a', 'b', 'c'))); // true\nvar_dump(isSequential(array(\"0\" => 'a', \"1\" => 'b', \"2\" => 'c'))); // true\nvar_dump(isSequential(array(\"1\" => 'a', \"0\" => 'b', \"2\" => 'c'))); // true\nvar_dump(isSequential(array(\"1a\" => 'a', \"0b\" => 'b', \"2c\" => 'c'))); // false\nvar_dump(isSequential(array(\"a\" => 'a', \"b\" => 'b', \"c\" => 'c'))); // false\n array_values array_fill(0, 1000000, uniqid()), // big numeric array PHP 7.1.16 (cli) (built: Mar 31 2018 02:59:59) ( NTS )\n\nInitial memory: 32.42 MB\nTesting my_method (isset check) - 100 iterations\n Total time: 2.57942 s\n Total memory: 32.48 MB\n\nTesting method3 (array_filter of keys) - 100 iterations\n Total time: 5.10964 s\n Total memory: 64.42 MB\n\nTesting method1 (array_values check) - 100 iterations\n Total time: 3.07591 s\n Total memory: 64.42 MB\n\nTesting method2 (array_keys comparison) - 100 iterations\n Total time: 5.62937 s\n Total memory: 96.43 MB\n echo \" Total memory: \" . number_format(memory_get_peak_usage()/1024/1024, 2) . \" MB\\n\";"
},
{
"answer_id": 52628664,
"author": "Rbgo Web",
"author_id": 3009380,
"author_profile": "https://Stackoverflow.com/users/3009380",
"pm_score": -1,
"selected": false,
"text": "/*\niszba - Is Zero Based Array\n\nDetects if an array is zero based or not.\n\nPARAMS:\n $chkvfnc\n Callback in the loop allows to check the values of each element.\n Signature:\n bool function chkvfnc($v);\n return:\n true continue looping\n false stop looping; iszba returns false too.\n\nNOTES:\n○ assert: $array is an array.\n○ May be memory efficient;\n it doesn't get extra arrays via array_keys() or ranges() into the function.\n○ Is pretty fast without a callback.\n○ With callback it's ~2.4 times slower.\n*/\nfunction iszba($array, $chkvfnc=null){\n\n $ncb = !$chkvfnc;\n $i = 0;\n\n foreach($array as $k => $v){\n if($k === $i++)\n if($ncb || $chkvfnc($v))\n continue;\n\n return false;\n }\n\n return true;\n}\n"
},
{
"answer_id": 56070491,
"author": "geilt",
"author_id": 849560,
"author_profile": "https://Stackoverflow.com/users/849560",
"pm_score": 2,
"selected": false,
"text": "public function is_sequential( $arr = [] ){\n if( !is_array( $arr ) || empty( $arr ) ) return false;\n\n $i = 0;\n\n $total = count( $arr );\n\n foreach( $arr as $key => $value ) if( $key !== $i++ ) return false;\n\n return true;\n}\n"
},
{
"answer_id": 58202788,
"author": "Aylian Craspa",
"author_id": 1640362,
"author_profile": "https://Stackoverflow.com/users/1640362",
"pm_score": 1,
"selected": false,
"text": "$y= array(5);\n$y[\"0x\"]=\"n\";\n$y[\"vbg\"]=\"12132\";\n$y[1] = \"k\";\n\nvar_dump($y); //this will output 4 element array\n\necho \"</br>\" .$y[\"0x\"].\"</br>\".$y[0];\n\nfor($x=0;$x<sizeof($y);$x++){ // this will output all index elements & gives error after that\n echo \"</br> index elements \".$y[$x];\n}\n function AssocTest(&$arr){\n if(is_array($arr)){\n\n reset($arr); // reset pointer to first element of array\n\n if(gettype(key($arr)) == \"string\"){ //get the type(nature) of first element key \n return true;\n }else{\n return false;\n }\n }else{\n return false;\n }\n}\n echo(AssocTest($y)? \"Associative array\": \"Not an Associative array/ Not an array at all\");\n $y[\"0\"]=\"n\";\n$y[\"1\"]=\"12132\";\n$y[\"22\"] = \"k\";\n\n//both will get the same output\necho \"<br/> s0 \".$y[\"22\"];\necho \"<br/> s0 \".$y[22];\n\nfor($x=0;$x<count($y);$x++){\n echo \"<br/> arr \".$y[$x]; // this will output up to 2nd element and give an error after\n\n}\n function fullAssocTest(&$arr)\n{\n if(is_array($arr)){\n return (array_keys($arr) !== range(0, count($arr) - 1));\n }\n}\n"
},
{
"answer_id": 60720565,
"author": "pilat",
"author_id": 475615,
"author_profile": "https://Stackoverflow.com/users/475615",
"pm_score": 1,
"selected": false,
"text": "$isSequential = array_keys($arr)[0] === 0 reset($arr); $isSequential = key($arr) === 0"
},
{
"answer_id": 63685462,
"author": "Manu Manjunath",
"author_id": 495598,
"author_profile": "https://Stackoverflow.com/users/495598",
"pm_score": 3,
"selected": false,
"text": "function is_sequential_array(Array &$a) {\n $n = count($a);\n for($i=0; $i<$n; $i++) {\n if(!array_key_exists($i, $a)) {\n return false;\n }\n }\n return true;\n}\n O(1) O(n) array_key_exists isset isset O(n) O(n)"
},
{
"answer_id": 63743929,
"author": "CSSBurner",
"author_id": 9858653,
"author_profile": "https://Stackoverflow.com/users/9858653",
"pm_score": -1,
"selected": false,
"text": "array_key_first() $sequentialArray = array('apple', 'orange', 'tomato', 'carrot');\n$isIndexedArray = is_int( array_key_first($sequentialArray) ); // true\n $assocArray = array('fruit1' => 'apple', \n 'fruit2' => 'orange', \n 'veg1' => 'tomato', \n 'veg2' => 'carrot');\n\n$isIndexedArray = is_int( array_key_first($assocArray) ); // false\n"
},
{
"answer_id": 63780789,
"author": "dipenparmar12",
"author_id": 8592918,
"author_profile": "https://Stackoverflow.com/users/8592918",
"pm_score": 4,
"selected": false,
"text": "/**\n * Determines if an array is associative.\n * @param array $array\n * @return bool\n */\nfunction isAssoc(array $array)\n{\n $keys = array_keys($array);\n\n return array_keys($keys) !== $keys;\n}\n"
},
{
"answer_id": 67898815,
"author": "Muhammad Dyas Yaskur",
"author_id": 2671470,
"author_profile": "https://Stackoverflow.com/users/2671470",
"pm_score": 5,
"selected": false,
"text": "array_is_list $list = [\"a\", \"b\", \"c\"];\n\narray_is_list($list); // true\n\n$notAList = [1 => \"a\", 2 => \"b\", 3 => \"c\"];\n\narray_is_list($notAList); // false\n\n$alsoNotAList = [\"a\" => \"a\", \"b\" => \"b\", \"c\" => \"c\"];\n\narray_is_list($alsoNotAList); // false\n"
},
{
"answer_id": 68531238,
"author": "dılo sürücü",
"author_id": 5582655,
"author_profile": "https://Stackoverflow.com/users/5582655",
"pm_score": -1,
"selected": false,
"text": "\nfunction is_assoc(array $array): bool\n{\n foreach ($array as $iValue) {\n if (is_array($iValue)) {\n return true;\n }\n }\n return false;\n\n}\n\n$d= is_assoc([\"id\",2,3]);\n\nvar_dump($d);\n"
},
{
"answer_id": 70613786,
"author": "PaulH",
"author_id": 4152976,
"author_profile": "https://Stackoverflow.com/users/4152976",
"pm_score": 2,
"selected": false,
"text": "Arr::isAssoc use Illuminate\\Support\\Arr;\n\n$isAssoc = Arr::isAssoc(['product' => ['name' => 'Desk', 'price' => 100]]);\n\n// true\n\n$isAssoc = Arr::isAssoc([1, 2, 3]);\n\n// false\n"
},
{
"answer_id": 71267111,
"author": "godzillante",
"author_id": 1037567,
"author_profile": "https://Stackoverflow.com/users/1037567",
"pm_score": 1,
"selected": false,
"text": "function is_associative(array $array): bool\n{\n foreach ($array as $key => $value)\n {\n if (!is_string($key)) return false;\n }\n return true;\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5291/"
] |
173,409
|
<p>I'm trying to find a way to get the execution time of a section of code in C. I've already tried both time() and clock() from time.h, but it seems that time() returns seconds and clock() seems to give me milliseconds (or centiseconds?) I would like something more precise though. Is there a way I can grab the time with at least microsecond precision?</p>
<p>This only needs to be able to compile on Linux.</p>
|
[
{
"answer_id": 173436,
"author": "Andrew Edgecombe",
"author_id": 11694,
"author_profile": "https://Stackoverflow.com/users/11694",
"pm_score": 5,
"selected": true,
"text": "clock() time() gettimeofday() struct timeval"
},
{
"answer_id": 175064,
"author": "PhirePhly",
"author_id": 20082,
"author_profile": "https://Stackoverflow.com/users/20082",
"pm_score": 4,
"selected": false,
"text": "#include <time.h>\nclock_t startm, stopm;\n#define START if ( (startm = clock()) == -1) {printf(\"Error calling clock\");exit(1);}\n#define STOP if ( (stopm = clock()) == -1) {printf(\"Error calling clock\");exit(1);}\n#define PRINTTIME printf( \"%6.3f seconds used by the processor.\", ((double)stopm-startm)/CLOCKS_PER_SEC);\n main() {\n START;\n // Do stuff you want to time\n STOP;\n PRINTTIME;\n}\n"
},
{
"answer_id": 3994482,
"author": "krakit",
"author_id": 418040,
"author_profile": "https://Stackoverflow.com/users/418040",
"pm_score": 1,
"selected": false,
"text": "gettimeofday() clock_gettime() int clock_gettime(clockid_t clk_id, struct timespec *tp);\n clk_id CLOCK_REALTIME CLOCK_PROCESS_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25295/"
] |
173,431
|
<p>I have to develop an application using C#.net that has to be run once a day. It only runs for at most one minute, so developing a Windows service is overkill and a scheduled task is the appropriate way.</p>
<p>However, I have a few questions about how the application can communicate its results:</p>
<ul>
<li>How do I indicate to the task scheduler that the task has failed? Is this via the program's exit code?</li>
<li>How do I log output information? Is console output automatically captured or do I have to write to the event viewer explicitly?</li>
</ul>
|
[
{
"answer_id": 173462,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 4,
"selected": true,
"text": "0xe0434f4d Console.WriteLine(\"blah\");"
},
{
"answer_id": 173531,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 2,
"selected": false,
"text": "Console.WriteLine(\"blah\"); StreamWriter mylog = new StreamWriter(\"mylog.log\");\n Console.SetOut(mylog);\n Console.SetError(mylog);\n Console.Out.Flush();\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9540/"
] |
173,473
|
<p>I have a generated HTML page with flash content in it. I am trying to reposition the flash content and make it "absolute". I have tried to wrap the object tags with a div tag, but to no avail. Can anyone tell me how to do this? Removing the generated positioning attributes does not work. </p>
<p>See relevant code below (it is not very neat, but this is how it is generated. I have removed most irrelevant code): </p>
<pre><code><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>* welcome *</title>
<script language="javascript">AC_FL_RunContent = 0;</script>
<script src="AC_RunActiveContent.js" language="javascript"></script>
</head>
<body bgcolor="#000000">
<script language="javascript">
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '430',
'height', '200',
'src', 'bar',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'right',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'transparent',
'devicefont', 'false',
'id', 'bar',
'bgcolor', '#000000',
'name', 'bar',
'menu', 'true',
'allowFullScreen', 'false',
'allowScriptAccess','sameDomain',
'movie', 'bar',
'salign', ''
); //end AC code
}
</script>
<noscript>
<div style = "position: absolute">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="430" height="200" id="bar" align="right">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="bar.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#000000" />
</object>
</div>
</noscript>
</code></pre>
<p>Thanks in advance!</p>
|
[
{
"answer_id": 173530,
"author": "Errico Malatesta",
"author_id": 24439,
"author_profile": "https://Stackoverflow.com/users/24439",
"pm_score": 1,
"selected": false,
"text": " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n <title>* welcome *</title>\n <script language=\"javascript\">AC_FL_RunContent = 0;</script>\n <script src=\"AC_RunActiveContent.js\" language=\"javascript\"></script>\n </head>\n <body bgcolor=\"#000000\">\n<div style = \"position: absolute\">\n <script language=\"javascript\">\n if (AC_FL_RunContent == 0) {\n alert(\"This page requires AC_RunActiveContent.js.\");\n } else {\n AC_FL_RunContent(\n...\n); //end AC code\n }\n </script>\n <noscript>\n <object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"430\" height=\"200\" id=\"bar\" align=\"right\">\n <param name=\"allowScriptAccess\" value=\"sameDomain\" />\n <param name=\"allowFullScreen\" value=\"false\" />\n <param name=\"movie\" value=\"bar.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"bgcolor\" value=\"#000000\" />\n </object>\n\n </noscript> \n</div>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25280/"
] |
173,487
|
<h1> 1st phase</h1>
<p>I have a problem shutting down my running JBoss instance under Eclipse since I changed
the JNDI port of JBoss. Of course I can shut it down from the console view but not with
the stop button (it still searches JNDI port at the default 1099 port). I'm looking
forward to any solutions. Thank you! </p>
<h2>Used environment:</h2>
<ul>
<li>JBoss 4.0.2 (using <em>default</em>)</li>
<li>Eclipse 3.4.0. (using JBoss Tools 2.1.1.GA)</li>
</ul>
<p>Default ports: 1098, 1099
Changed ports: 11098, 11099</p>
<p>I changed the following part in jbosspath/server/default/conf/jboss-service.xml:</p>
<pre><code> <!-- ==================================================================== -->
<!-- JNDI -->
<!-- ==================================================================== -->
<mbean code="org.jboss.naming.NamingService"
name="jboss:service=Naming"
xmbean-dd="resource:xmdesc/NamingService-xmbean.xml">
<!-- The call by value mode. true if all lookups are unmarshalled using
the caller's TCL, false if in VM lookups return the value by reference.
-->
<attribute name="CallByValue">false</attribute>
<!-- The listening port for the bootstrap JNP service. Set this to -1
to run the NamingService without the JNP invoker listening port.
-->
<attribute name="Port">11099</attribute>
<!-- The bootstrap JNP server bind address. This also sets the default
RMI service bind address. Empty == all addresses
-->
<attribute name="BindAddress">${jboss.bind.address}</attribute>
<!-- The port of the RMI naming service, 0 == anonymous -->
<attribute name="RmiPort">11098</attribute>
<!-- The RMI service bind address. Empty == all addresses
-->
<attribute name="RmiBindAddress">${jboss.bind.address}</attribute>
<!-- The thread pool service used to control the bootstrap lookups -->
<depends optional-attribute-name="LookupPool"
proxy-type="attribute">jboss.system:service=ThreadPool</depends>
</mbean>
<mbean code="org.jboss.naming.JNDIView"
name="jboss:service=JNDIView"
xmbean-dd="resource:xmdesc/JNDIView-xmbean.xml">
</mbean>
</code></pre>
<h2>Eclipse setup:</h2>
<p><img src="https://i.stack.imgur.com/nOlhy.png" width="500" title="jndi port to 11099" /></p>
<p><em>About my JBoss Tools preferences:</em>
I had a previous version, I got this problem, I read about some bugfix in JbossTools, so updated to 2.1.1.GA. Now the buttons changed, and I've got a new preferences view, but I cannot modify anything...seems to be abnormal as well:</p>
<p><img src="https://i.stack.imgur.com/Ocfcf.png" width="620" /></p>
<h2>Error dialog:</h2>
<p><img src="https://i.stack.imgur.com/uPPZ7.png" width="300" title="can't reach server" /></p>
<h2>The stacktrace:</h2>
<pre><code>javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1385)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at org.jboss.Shutdown.main(Shutdown.java:202)
Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:254)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1370)
... 4 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:228)
... 5 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:211)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:69)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:62)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:224)
... 5 more
Exception in thread "main"
</code></pre>
<h1> 2nd phase:</h1>
<p>After creating a new Server in File/new/other/server, it did appear in the preferences tab. Now the stop button is working (the server receives the shutdown messages without any additional modification of the jndi port -- there is no opportunity for it now) but it still throws an error message, though different, it's without exception stack trace: "Server JBoss 4.0 Server failed to stop."</p>
|
[
{
"answer_id": 173543,
"author": "huo73",
"author_id": 15657,
"author_profile": "https://Stackoverflow.com/users/15657",
"pm_score": 0,
"selected": false,
"text": "--shutdown\n -s jnp://localhost:11099 --shutdown\n"
},
{
"answer_id": 1512563,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "\n<eclipse>\\plugins\\org.eclipse.jst.server.generic.jboss_1.5.105.v200709061325\\servers\\jboss*.serverdef\n \n<property id=\"jndiPort\"\n label=\"%jndiPort\"\n type=\"string\"\n context=\"server\"\n default=\"1099\" /> \n \n <stop>\n <mainClass>org.jboss.Shutdown</mainClass>\n <workingDirectory>${serverRootDirectory}/bin</workingDirectory>\n <programArguments>-S</programArguments>\n <vmParameters></vmParameters>\n <classpathReference>jboss</classpathReference>\n </stop>\n \n <stop>\n <mainClass>org.jboss.Shutdown</mainClass>\n <workingDirectory>${serverRootDirectory}/bin</workingDirectory>\n <programArguments>-s jnp://${serverAddress}:${jndiPort}</programArguments>\n <vmParameters></vmParameters>\n <classpathReference>jboss</classpathReference>\n </stop>\n \n <jndiConnection>\n <providerUrl>jnp://${serverAddress}:${jndiPort}</providerUrl>\n<initialContextFactory>org.jnp.interfaces.NamingContextFactory</initialContextFactory>\n <jndiProperty>\n <name></name>\n <value></value>\n </jndiProperty>\n </jndiConnection>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173487",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19621/"
] |
173,498
|
<p>I am trying to take a rather large CSV file and insert it into a MySQL database for referencing in a project. I would like to use the first line of the file to create the table using proper data types and not varchar for each column. The ultimate goal is to automate this process as I have several similar files but the each has different data and a different amount of "columns" in CSV files. The problem that I am having is gettype() is returning 'string' for each column instead of int, float and string as I would like it to.</p>
<p>Platform is PHP 5, OS is ubuntu 8.04</p>
<p>here is my code so far:</p>
<pre><code><?php
// GENERATE TABLE FROM FIRST LINE OF CSV FILE
$inputFile = 'file.csv';
$tableName = 'file_csv';
$fh = fopen($inputFile, 'r');
$contents = fread($fh, 5120); // 5KB
fclose($fh);
$fileLines = explode("\n", $contents); // explode to make sure we are only using the first line.
$fieldList = explode(',', $fileLines[0]); // separate columns, put into array
echo 'CREATE TABLE IF NOT EXISTS `'.$tableName.'` ('."<br/>\n";
for($i = 0; $i <= count($fieldList); $i++)
{
switch(gettype($fieldList[$i])) {
case 'integer':
$typeInfo = 'int(11)';
break;
case 'float':
$typeInfo = 'float';
break;
case 'string':
$typeInfo = 'varchar(80)';
break;
default:
$typeInfo = 'varchar(80)';
break;
}
if(gettype($fieldList[$i]) != NULL) echo "\t".'`'.$i.'` '.$typeInfo.' NOT NULL, --'.gettype($fieldList[$i]).' '.$fieldList[$i]."<br/>\n";
}
echo ' PRIMARY KEY (`0`)'."<br/>\n";
echo ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;';
</code></pre>
<p>Example First line:
1,0,0,0,0,0,0,0,0,0,0,0,0.000000,0.000000,0,0,0,,0,0,1,0,50,'Word of Recall (OLD)',</p>
|
[
{
"answer_id": 173526,
"author": "pilsetnieks",
"author_id": 6615,
"author_profile": "https://Stackoverflow.com/users/6615",
"pm_score": 2,
"selected": false,
"text": "define('DECIMAL_SEPARATOR', '.');\n\nswitch ($fieldList[$i])\n{\n case (string)(int)$fieldList[$i]:\n $typeInfo = (strpos($fieldList[$i], DECIMAL_SEPARATOR) === false) ? 'int(11)' : 'float';\n break;\n case (string)(float)$fieldList[$i]:\n $typeInfo = 'float';\n break;\n default:\n $typeInfo = 'varchar(80)';\n break;\n}\n"
},
{
"answer_id": 173586,
"author": "Re0sless",
"author_id": 2098,
"author_profile": "https://Stackoverflow.com/users/2098",
"pm_score": 3,
"selected": true,
"text": "for($i = 0; $i <= count($fieldList); $i++)\n{\n if (is_numeric($fieldList[$i]))\n {\n if (strpos($fieldList[$i],'.') !== false){\n $fieldList[$i] = (int)$fieldList[$i];\n }else{\n $fieldList[$i] = (float)$fieldList[$i];\n }\n }\n\n switch(gettype($fieldList[$i])) {\n case 'integer':\n $typeInfo = 'int(11)';\n break;\n case 'float':\n case 'double':\n $typeInfo = 'float';\n break;\n\n case 'string':\n $typeInfo = 'varchar(80)';\n break;\n default:\n $typeInfo = 'varchar(80)';\n break;\n }\nif(gettype($fieldList[$i]) != NULL) echo \"\\t\".'`'.$i.'` '.$typeInfo.' NOT NULL, --'.gettype($fieldList[$i]).' '.$fieldList[$i].\"<br/>\\n\";\n\n}\n"
},
{
"answer_id": 173601,
"author": "Jayrox",
"author_id": 24802,
"author_profile": "https://Stackoverflow.com/users/24802",
"pm_score": 2,
"selected": false,
"text": "<?php\n\n// GENERATE TABLE FROM FIRST LINE OF CSV FILE\n\n$inputFile = 'file.csv';\n$tableName = 'file_csv';\n\n$fh = fopen($inputFile, 'r');\n $contents = fread($fh, 5120); // 5KB\nfclose($fh);\n\n$fileLines = explode(\"\\n\", $contents);\n\n$fieldList = explode(',', $fileLines[0]);\necho 'CREATE TABLE IF NOT EXISTS `'.$tableName.'` ('.\"<br/>\\n\";\nfor($i = 0; $i <= count($fieldList); $i++)\n{\n\n if(strlen($fieldList[$i]) == 0) $typeInfo = 'varchar(80)';\n if(preg_match('/[0-9]/', $fieldList[$i])) $typeInfo = 'int(11)';\n if(preg_match('/[\\.]/', $fieldList[$i])) $typeInfo = 'float';\n if(preg_match('/[a-z\\\\\\']/i', $fieldList[$i])) $typeInfo = 'varchar(80)';\n\n echo \"\\t\".'`'.$i.'` '.$typeInfo.' NOT NULL, -- '.gettype($fieldList[$i]).' '.$fieldList[$i].\"<br/>\\n\";\n}\necho ' PRIMARY KEY (`0`)'.\"<br/>\\n\";\necho ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;';\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24802/"
] |
173,503
|
<p>I've got a "little" problem with Zend Framework Zend_Pdf class. Multibyte characters are stripped from generated pdf files. E.g. when I write aąbcčdeę it becomes abcd with lithuanian letters stripped.</p>
<p>I'm not sure if it's particularly Zend_Pdf problem or php in general. </p>
<p>Source text is encoded in utf-8, as well as the php source file which does the job.</p>
<p>Thank you in advance for your help ;)</p>
<p>P.S. I run Zend Framework v. 1.6 and I use FONT_TIMES_BOLD font. FONT_TIMES_ROMAN does work</p>
|
[
{
"answer_id": 185651,
"author": "leek",
"author_id": 3765,
"author_profile": "https://Stackoverflow.com/users/3765",
"pm_score": 1,
"selected": false,
"text": "// Draw the string on the page\n$pdfPage->drawText($unicodeString, 72, 720, 'UTF-8');\n Zend_Pdf_Font::FONT_COURIER_BOLD\nZend_Pdf_Font::FONT_TIMES_BOLD\nZend_Pdf_Font::FONT_HELVETICA_BOLD\n"
},
{
"answer_id": 240749,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": true,
"text": "Zend_Pdf Zend_Pdf_Font::FONT_TIMES_BOLD $pdfDoc = new Zend_Pdf();\n$pdfPage = $pdfDoc->newPage(Zend_Pdf_Page::SIZE_LETTER);\n\n// load TTF font from Mac system library\n$font = Zend_Pdf_Font::fontWithPath('/Library/Fonts/Times New Roman Bold.ttf');\n$pdfPage->setFont($font, 36);\n\n$unicodeString = 'aąbcčdeę';\n$pdfPage->drawText($unicodeString, 72, 720, 'UTF-8');\n\n$pdfDoc->pages[] = $pdfPage;\n$pdfDoc->save('utf8.pdf');\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25413/"
] |
173,527
|
<p>I have some old rrdtool databases, for which the exact creation recipe has long been since lost. I need to create a new database with the same characteristics as the current ones. I've dumped a couple of old databases and pored over the contents but I'm not sure how to interpret the metadata. I think it appears in the following stanzas</p>
<pre><code><cf> AVERAGE </cf>
<pdp_per_row> 360 </pdp_per_row> <!-- 1800 seconds -->
<xff> 5.0000000000e-01 </xff>
</code></pre>
<p>There are four such stanzas, which correspond to the way I recall the round-robin cascading was set up. Has anyone already done this, or can give me pointers as to how to clone a new empty rrd database from an existing one? Or show me where I missed this in the documentation.</p>
|
[
{
"answer_id": 173547,
"author": "Stu Thompson",
"author_id": 2961,
"author_profile": "https://Stackoverflow.com/users/2961",
"pm_score": 3,
"selected": true,
"text": "$ rrdtool info random.rrd\nfilename = \"random.rrd\"\nrrd_version = \"0001\"\nstep = 300\nlast_update = 955892996\nds[a].type = \"GAUGE\"\nds[a].minimal_heartbeat = 600\nds[a].min = NaN\nds[a].max = NaN\nds[a].last_ds = \"UNKN\"\nds[a].value = 2.1824421548e+04\nds[a].unknown_sec = 0\nds[b].type = \"GAUGE\"\nds[b].minimal_heartbeat = 600\nds[b].min = NaN\nds[b].max = NaN\nds[b].last_ds = \"UNKN\"\nds[b].value = 3.9620838224e+03\nds[b].unknown_sec = 0\nrra[0].cf = \"AVERAGE\"\nrra[0].pdp_per_row = 1\nrra[0].cdp_prep[0].value = nan\nrra[0].cdp_prep[0].unknown_datapoints = 0\nrra[0].cdp_prep[1].value = nan\nrra[0].cdp_prep[1].unknown_datapoints = 0\n"
},
{
"answer_id": 5152325,
"author": "Lmwangi",
"author_id": 458878,
"author_profile": "https://Stackoverflow.com/users/458878",
"pm_score": 2,
"selected": false,
"text": "$ python rrdinfo-parser.py -f test.rrd\nrrdtool create test.rrd --start 920804400 --step 300 \\\nDS:speed:COUNTER:600:U:U \\\nRRA:AVERAGE:0.5:1:24 \\\nRRA:AVERAGE:0.5:6:10 \\\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18625/"
] |
173,560
|
<p>When the policy for a disk in Windows XP and Vista is set to enable write caching on the hard disk, is there a way to flush a file that has just been written, and ensure that it has been committed to disk?</p>
<p>I want to do this programmatically in C++.</p>
<p>Closing the file does perform a flush at the application level, but not at the operating system level. If the power is removed from the PC after closing the file, but before the operating system has flushed the disk write cache, the file is lost, even though it was closed.</p>
|
[
{
"answer_id": 173600,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 3,
"selected": true,
"text": ".Flush FlushFileBuffers"
},
{
"answer_id": 830228,
"author": "MSalters",
"author_id": 15416,
"author_profile": "https://Stackoverflow.com/users/15416",
"pm_score": 2,
"selected": false,
"text": "FILE_FLAG_WRITE_THROUGH FILE_FLAG_NO_BUFFERING"
},
{
"answer_id": 57079969,
"author": "Artie Leech",
"author_id": 5934381,
"author_profile": "https://Stackoverflow.com/users/5934381",
"pm_score": 0,
"selected": false,
"text": "fopen( path, \"wc\") // w - write mode, c - allow immediate commit to disk\n _flushall()\n fclose()\n FlushFileBuffers"
},
{
"answer_id": 71907272,
"author": "hillin",
"author_id": 1383540,
"author_profile": "https://Stackoverflow.com/users/1383540",
"pm_score": 0,
"selected": false,
"text": "FileOptions.WriteThrough var file = File.Open(\n \"1.txt\",\n new FileStreamOptions\n {\n Options = FileOptions.WriteThrough\n });\n\n// - OR -\nvar file = new FileStream(\n \"1.txt\", \n FileMode.Create, \n FileAccess.Write, \n FileShare.None, \n 4096, \n FileOptions.WriteThrough)\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16314/"
] |
173,579
|
<p>I am writing a very specialized app in C# that floats as a mostly transparent window over the entire desktop. I want to be able to create and pass mouse events to applications behind mine, and have them appear to operate "normally", responding to those events. It would also be preferable if the window manager could respond.</p>
<p>I am not a Windows guru, and am unsure of how to best accomplish this.</p>
<p>From this page:
<a href="http://bytes.com/forum/thread270002.html" rel="noreferrer">http://bytes.com/forum/thread270002.html</a></p>
<p>it would appear that mouse_event would be good, except that since my app is floating over everything else, I'm guessing my generated events would never make it to the other apps underneath.</p>
<p>It seems the alternative is SendMessage, but that requires a fair amount of manual manipulation of windows, and the mouse events generated aren't "authentic."</p>
<p>Any thoughts on the best way to approach this?</p>
|
[
{
"answer_id": 173800,
"author": "Garth",
"author_id": 23407,
"author_profile": "https://Stackoverflow.com/users/23407",
"pm_score": 3,
"selected": true,
"text": "protected override CreateParams CreateParams\n{\n get\n {\n CreateParams createParams = base.CreateParams;\n createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT\n\n return createParams;\n }\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23407/"
] |
173,593
|
<p>I've tried to override WndProc, but no message show up on paste event.</p>
<p>Then I tried to create custom filter and using method PreFilterMessage I was able to catch message with value 257 (KEYUP event), but that's not enough...</p>
|
[
{
"answer_id": 173610,
"author": "Goran",
"author_id": 23164,
"author_profile": "https://Stackoverflow.com/users/23164",
"pm_score": 4,
"selected": false,
"text": " protected override void OnKeyDown(KeyEventArgs e)\n {\n if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control)\n {\n MessageBox.Show(\"Hello world\");\n }\n base.OnKeyDown(e);\n }\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
173,616
|
<p>I am interested in seeing if I can improve the way we use NUnit in a Visual Studio solution containing 30+ projects.</p>
<p>First, would you have one assembly of tests for every assembly in the solution, or would you try to keep the number of test assemblies down? I started off creating many test assemblies, but I think this is costing us a lot in terms of build time.</p>
<p>Second, what strategy do you use for managing those tests that are long-running, or require special environment configuration? I would like to write an MSBuild script that automates the running of our unit tests, but it needs to skip over the tests that would take too long or would not work on the build machine.</p>
|
[
{
"answer_id": 173625,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 4,
"selected": true,
"text": "[Explicit] [Ignore] [Platform]"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7532/"
] |
173,617
|
<p>I read that you could call JavaScript code from a Java Applet by calling</p>
<pre><code>JApplet.getAppletContext().showDocument( "javascript:alert('Hello World');" );
</code></pre>
<p>However, when I do this i get the following error:</p>
<pre><code>java.net.MalformedURLException: unknown protocol: javascript
</code></pre>
<p>How do I work around this?</p>
|
[
{
"answer_id": 173743,
"author": "RuntimeException",
"author_id": 15789,
"author_profile": "https://Stackoverflow.com/users/15789",
"pm_score": 2,
"selected": false,
"text": " try {\n this.getAppletContext().showDocument(new URL(\"javascript:alert('hello world');\"));\n }catch(Exception e) {\n e.printStackTrace();\n }\n"
},
{
"answer_id": 204531,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": "final URLStreamHandler streamHandler = new URLStreamHandler() {\n\n @Override\n protected URLConnection openConnection(URL u)\n throws IOException {\n return null;\n }\n\n};\n\ntry {\n getAppletContext().showDocument(\n new URL(null, \"javascript:alert('It works!');\", streamHandler));\n} catch (MalformedURLException me) {\n //log or whatever\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20298/"
] |
173,618
|
<p>In MSVC, <a href="http://msdn.microsoft.com/en-us/library/ms679297.aspx" rel="noreferrer">DebugBreak()</a> or <a href="http://msdn.microsoft.com/fr-fr/library/f408b4et.aspx" rel="noreferrer">__debugbreak</a> cause a debugger to break. On x86 it is equivalent to writing "_asm int 3", on x64 it is something different. When compiling with gcc (or any other standard compiler) I want to do a break into debugger, too. Is there a platform independent function or intrinsic? I saw the <a href="https://stackoverflow.com/questions/37299/xcode-equivalent-of-asm-int-3-debugbreak-halt">XCode question</a> about that, but it doesn't seem portable enough.</p>
<p>Sidenote: I mainly want to implement ASSERT with that, and I understand I can use assert() for that, but I also want to write DEBUG_BREAK or something into the code.</p>
|
[
{
"answer_id": 173630,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 5,
"selected": true,
"text": "#ifdef _MSC_VER\n#define DEBUG_BREAK __debugbreak()\n#else\n...\n#endif\n DEBUG_BREAK"
},
{
"answer_id": 173656,
"author": "Hasturkun",
"author_id": 20270,
"author_profile": "https://Stackoverflow.com/users/20270",
"pm_score": 4,
"selected": false,
"text": "__builtin_trap __builtin_trap()"
},
{
"answer_id": 173660,
"author": "QAZ",
"author_id": 14260,
"author_profile": "https://Stackoverflow.com/users/14260",
"pm_score": -1,
"selected": false,
"text": "int iCrash = 13 / 0;\n BYTE bCrash = *(BYTE *)(NULL);\n"
},
{
"answer_id": 173925,
"author": "Suma",
"author_id": 16673,
"author_profile": "https://Stackoverflow.com/users/16673",
"pm_score": 2,
"selected": false,
"text": "assert(x) assert(false)"
},
{
"answer_id": 5561015,
"author": "caf",
"author_id": 134633,
"author_profile": "https://Stackoverflow.com/users/134633",
"pm_score": 6,
"selected": false,
"text": "raise(SIGTRAP);\n"
},
{
"answer_id": 34074974,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "#define __debugbreak() \\\ndo \\\n{ static bool b; \\\n while (!b) \\\n sleep(1); \\\n b = false; \\\n} while (false)\n"
},
{
"answer_id": 49079078,
"author": "nemequ",
"author_id": 501126,
"author_profile": "https://Stackoverflow.com/users/501126",
"pm_score": 5,
"selected": false,
"text": "__builtin_debugtrap __has_builtin(__builtin_debugtrap) __debugbreak __breakpoint(42) int3 .inst 0xde01 .inst 0xd4200000 .inst 0xe7f001f0 bpt __builtin_trap signal.h defined(SIGTRAP) raise(SIGTRAP) raise(SIGABRT)"
},
{
"answer_id": 57330958,
"author": "QwazyWabbit",
"author_id": 5538398,
"author_profile": "https://Stackoverflow.com/users/5538398",
"pm_score": 3,
"selected": false,
"text": " __debugbreak, \n __asm__ volatile(\"int $0x03\");\n __asm__ volatile(\".inst 0xe7f001f0\");\n"
},
{
"answer_id": 67511652,
"author": "Heath Raftery",
"author_id": 3697870,
"author_profile": "https://Stackoverflow.com/users/3697870",
"pm_score": 0,
"selected": false,
"text": "arm-none-eabi-gcc debug-trap.h debugbreak.h __builtin_trap() NRF_BREAKPOINT #if defined(__GNUC__)\n __asm__(\"BKPT 0\");\n#else\n __BKPT(0)\n#endif\n __GNUC__ __asm__(\"BKPT 0\")"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173618",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23740/"
] |
173,621
|
<p>Our svn repository has lots of branches that are branches off of sub-trees. This works OK with svn because I can check out that sub-tree in the correct spot in my working copy. However, if I check out the same branch using git, I get a working copy with only the branch sub-tree. Is it possible to make git relocate the branch so that my working copy structure is identical whether I am on trunk or a branch?</p>
<p>I realize that our svn practices clash with git's philosophy of always working on the whole tree. How do people deal with this?</p>
|
[
{
"answer_id": 176224,
"author": "Daniel Schierbeck",
"author_id": 20321,
"author_profile": "https://Stackoverflow.com/users/20321",
"pm_score": 3,
"selected": true,
"text": "svn copy"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5179/"
] |
173,641
|
<p>I'm trying to use TestDriven.Net not only to test my code, but to call a function on my code whose purpose is to print out the internal state of the code to the Debug window.</p>
<p>Here's a very simplified example of what I'm trying to do..</p>
<pre><code><TestFixture()> _
Public Class UnitTest
<Test()> _
Public Sub TestDebug()
Dim oClass1 As New Class1
Assert.AreEqual(True, oClass1.IsTrue)
Debug.WriteLine("About to call .PrintDebug()")
oClass1.PrintToDebug()
End Sub
End Class
Public Class Class1
Private _IsTrue As Boolean = True
Public ReadOnly Property IsTrue() As Boolean
Get
Return _IsTrue
End Get
End Property
Public Sub PrintToDebug()
Debug.WriteLine("Internal state of Class1: " & _IsTrue)
End Sub
End Class
</code></pre>
<p>I'm trying to test the Public interface of Class1, and somehow view the output from the <code>Class1.PrintToDebug()</code> function.</p>
<p>I've looked through the <a href="http://www.testdriven.net/quickstart.aspx" rel="nofollow noreferrer">TestDriven.Net quickstart</a>, which shows examples of using the <code>Debug.WriteLine</code> in a unit test, but strangely this doesn't work for me either - i.e. the only Output in my 'Test' window is:</p>
<pre><code>------ Test started: Assembly: ClassLibrary1.dll ------
1 passed, 0 failed, 0 skipped, took 1.19 seconds.
</code></pre>
<p>I've tried looking in the other windows (Debug and Build), the Debug window has the 'Program Output' and 'Exception Messages' options enabled.</p>
<p>I've looked for options or preferences and can't find any!</p>
<p>Thanks for your help!</p>
<p><hr />
<strong>Edit:</strong> I'm using VB.Net 2.0, TestDriven.Net 2.14.2190 and NUnit 2.4.8.0</p>
|
[
{
"answer_id": 173693,
"author": "Andrew",
"author_id": 5662,
"author_profile": "https://Stackoverflow.com/users/5662",
"pm_score": 2,
"selected": false,
"text": "Trace.WriteLine() Trace Debug ------ Test started: Assembly: ClassLibrary1.dll ------\n\nInternal state of Class1: True\n\n1 passed, 0 failed, 0 skipped, took 0.61 seconds.\n Trace Assert()"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173641",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5662/"
] |
173,642
|
<p>I only want a list of files that have been added (not ones that have been modified) since a certain date. Is there an easy way to do this?</p>
<p><strong>Answer</strong>: Here's what ended up working for me, thanks guys!</p>
<blockquote>
<p>svn log -v -r{2008-10-1}:HEAD svn://path.to.repo/ | grep "^ A" | grep ".java" | sort -u</p>
</blockquote>
|
[
{
"answer_id": 173665,
"author": "Matthias Winkelmann",
"author_id": 4494,
"author_profile": "https://Stackoverflow.com/users/4494",
"pm_score": 4,
"selected": true,
"text": "svn log -v -r{2008-10-1}:HEAD | grep \"^ A\"\n"
},
{
"answer_id": 173669,
"author": "mmaibaum",
"author_id": 12213,
"author_profile": "https://Stackoverflow.com/users/12213",
"pm_score": 1,
"selected": false,
"text": "svn log -v -r {\"2008-01-01\"}:HEAD . | grep ' A ' | sort -u"
},
{
"answer_id": 18711027,
"author": "Harikrushna",
"author_id": 1587594,
"author_profile": "https://Stackoverflow.com/users/1587594",
"pm_score": 0,
"selected": false,
"text": "svn log -r '{2013-09-09}:HEAD'\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6583/"
] |
173,646
|
<p>Most often the cleanup rules (Preferences > Java > Code Style > Clean Up) in Eclipse work perfectly and create nice-looking code.</p>
<p>But sometimes, especially with comments and concatenated string snippets (like inline SQL queries), the cleanup just messes things up, and destroys my formatting.</p>
<p>Is there a way to say to Eclipse <em>"Don't touch this block of text! I have formatted it just the way I like, and you would make it just less readable"</em>?</p>
|
[
{
"answer_id": 175182,
"author": "srclontz",
"author_id": 4606,
"author_profile": "https://Stackoverflow.com/users/4606",
"pm_score": 2,
"selected": false,
"text": "public static final String SELECT_SOMETHING = \"SELECT\"\n + \"OBJECTID, THIS, THAT, THEOTHER, THING\"\n + \" FROM DBNAME.DBSCHEMA.TABLE_T\"\n + \" WHERE ID = ?\";\n public static final String SELECT_SOMETHING = \"SELECT OBJECTID, SOMETHING FROM DBNAME.DBSCHEMA.TABLE_T WHERE ID = ?\";\n"
},
{
"answer_id": 2932491,
"author": "MSzewczyk",
"author_id": 1082122,
"author_profile": "https://Stackoverflow.com/users/1082122",
"pm_score": 1,
"selected": false,
"text": "StringBuffer sql = new StringBuffer() //\n .append(\"SELECT whatever \\n\") //\n .append(\"FROM some_table\");\n"
},
{
"answer_id": 7096358,
"author": "Michael Piefel",
"author_id": 2621917,
"author_profile": "https://Stackoverflow.com/users/2621917",
"pm_score": 4,
"selected": true,
"text": "// @formatter:off\nStringBuilder sql = new StringBuilder()\n .append(\"SELECT whatever \\n\")\n .append(\"FROM some_table\");\n// @formatter:on\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2238/"
] |
173,652
|
<p>I have a WPF Window which has a among other controls hosts a Frame. In that frame I display different pages. Is there way to make a dialog modal to only a page? When I'm showing the dialog it should not be possible to click on any control on the page but it should be possible to click on a control on the same window that is not on the page.</p>
|
[
{
"answer_id": 173769,
"author": "Brad Leach",
"author_id": 708,
"author_profile": "https://Stackoverflow.com/users/708",
"pm_score": 6,
"selected": true,
"text": "<ControlTemplate TargetType=\"{x:Type local=DialogPresenter}\">\n <Grid>\n <ContentControl>\n <ContentPresenter />\n </ContentControl>\n <!-- The Rectangle is what simulates the modality -->\n <Rectangle x:Name=\"Overlay\" Visibility=\"Collapsed\" Opacity=\"0.4\" Fill=\"LightGrey\" />\n <Grid x:Name=\"Dialog\" Visibility=\"Collapsed\">\n <!-- The template for the dialog goes here (borders and such...) -->\n <ContentPresenter x:Name=\"PART_DialogView\" />\n </Grid>\n </Grid>\n <ControlTemplate.Triggers>\n <!-- Triggers to change the visibility of the PART_DialogView and Overlay -->\n </ControlTemplate.Triggers>\n</ControlTemplate>\n Show(Control view) Content DialogPresenter <controls:DialogPresenter x:Name=\"DialogPresenter\">\n <!-- Normal parent view content here -->\n <TextBlock>Hello World</TextBlock>\n <Button>Click Me!</Button>\n</controls:DialogPresenter>\n DialogPresenter"
},
{
"answer_id": 11277444,
"author": "Benjamin Gale",
"author_id": 577417,
"author_profile": "https://Stackoverflow.com/users/577417",
"pm_score": 2,
"selected": false,
"text": "FrameworkElement <c:ModalContentPresenter IsModal=\"{Binding DialogIsVisible}\">\n <TabControl Margin=\"5\">\n <Button Margin=\"55\"\n Padding=\"10\"\n Command=\"{Binding ShowModalContentCommand}\">\n This is the primary Content\n </Button>\n </TabItem>\n </TabControl>\n\n <c:ModalContentPresenter.ModalContent>\n <Button Margin=\"75\"\n Padding=\"50\"\n Command=\"{Binding HideModalContentCommand}\">\n This is the modal content\n </Button>\n </c:ModalContentPresenter.ModalContent>\n\n</c:ModalContentPresenter>\n IsModal"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173652",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/143/"
] |
173,663
|
<p><strong>Good day.</strong></p>
<p>I have a program thats launches an external application. That external app has a right click sub menu on it which I need to disable. Is it possible (without modifying the external app) to disable the right click? Maybe permission or group policies and etc.</p>
<p>Thanks.</p>
|
[
{
"answer_id": 173730,
"author": "Henry B",
"author_id": 6414,
"author_profile": "https://Stackoverflow.com/users/6414",
"pm_score": 1,
"selected": false,
"text": "WM_RBUTTONDOWN WM_RBUTTONUP"
},
{
"answer_id": 17992865,
"author": "GaneshKumar",
"author_id": 1667832,
"author_profile": "https://Stackoverflow.com/users/1667832",
"pm_score": 0,
"selected": false,
"text": " <script type=\"text/javascript\">\n $(function () {\n $(document).bind(\"contextmenu\", function (e) {\n e.preventDefault();\n });\n });\n\n</script>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
173,681
|
<p>Are the string literals we use inside functions automatic variables? Or are they allocated in heap which we have to free manually?</p>
<p>I've a situation like the code shown below wherein I'm assigning a string literal to a private field of the class (marked as ONE in the code) and retrieving it much later in my program and using it (marked as TWO). Am I assigning a variable in the stack to a field in ONE? Can the code be referencing to a dangling pointer which in this case worked because the program was small enough?</p>
<p>I've compiled and ran it, it worked fine but I'm having a strange crash in my actual program where I'm assigning string literals to fields of the class like this and I suspect the case I mentioned above.</p>
<pre><code>#include <iostream>
using namespace std;
class MemoryLeak
{
private:
char *s;
public:
MemoryLeak() {}
void store()
{
s = "Storing a string"; // ONE
}
char *retrieve()
{
return s;
}
};
int main()
{
MemoryLeak *obj = new MemoryLeak();
obj->store();
cout << obj->retrieve() << endl; // TWO
delete obj;
return 0;
}
</code></pre>
<p>Should I be declaring the variable "s" as a char array instead of a pointer? I'm planning to use std::string, but I'm just curious about this.</p>
<p>Any pointers or help is, as always, much appreciated :) Thanks.</p>
|
[
{
"answer_id": 173719,
"author": "Richard Corden",
"author_id": 11698,
"author_profile": "https://Stackoverflow.com/users/11698",
"pm_score": 3,
"selected": false,
"text": "char* const char * s std::string"
},
{
"answer_id": 173816,
"author": "Srikanth",
"author_id": 7205,
"author_profile": "https://Stackoverflow.com/users/7205",
"pm_score": 1,
"selected": false,
"text": "if (obj != NULL) delete obj;\n if (obj != NULL)\n{\n delete obj;\n obj = NULL;\n}\n"
},
{
"answer_id": 175010,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 0,
"selected": false,
"text": " /*\n * Should initialize s to NULL or a valid string in constructor */\n MemoryLeak()\n {\n store();\n }\n\n void store()\n {\n // This does not need to be freed because it is a string literal\n // generated by the compiler.\n s = \"Storing a string\"; // ONE\n\n // Note this is allowed for backward compatibility but the string is\n // really stored as a const char* and thus unmodifiable. If somebody\n // retrieves this C-String and tries to change any of the contents the\n // code could potentially crash as this is UNDEFINED Behavior.\n\n // The following does need to be free'd.\n // But given the type of s is char* this is more correct.\n s = strdup(\"Storing a string\");\n\n // This makes a copy of the string on the heap.\n // Because you allocated the memory it is modifiable by anybody\n // retrieving it but you also need to explicitly de-allocate it\n // with free()\n }\n std::auto_ptr<MemoryLeak> obj(new MemoryLeak());\n\nobj->store();\nstd::cout << obj->retrieve() << std::endl; // TWO\n\n// No need to delete When object goes out of scope it auto deletes the memory.\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7205/"
] |
173,687
|
<p>I haven't found an answer elsewhere and this doesn't appear to have been asked yet on SO.</p>
<p>When creating an event binding in wxPython, is it possible to pass additional arguments to the event? For example, this is the normal way:</p>
<pre><code>b = wx.Button(self, 10, "Default Button", (20, 20))
self.Bind(wx.EVT_BUTTON, self.OnClick, b)
def OnClick(self, event):
self.log.write("Click! (%d)\n" % event.GetId())
</code></pre>
<p>But is it possible to have another argument passed to the method? Such that the method can tell if more than one widget is calling it but still return the same value? </p>
<p>It would greatly reduce copy & pasting the same code but with different callers.</p>
|
[
{
"answer_id": 173694,
"author": "Florian Bösch",
"author_id": 19435,
"author_profile": "https://Stackoverflow.com/users/19435",
"pm_score": 6,
"selected": false,
"text": "b = wx.Button(self, 10, \"Default Button\", (20, 20))\n self.Bind(wx.EVT_BUTTON, lambda event: self.OnClick(event, 'somevalue'), b)\ndef OnClick(self, event, somearg):\n self.log.write(\"Click! (%d)\\n\" % event.GetId())\n class foo(whateverwxobject):\n def better_bind(self, type, instance, handler, *args, **kwargs):\n self.Bind(type, lambda event: handler(event, *args, **kwargs), instance)\n\n def __init__(self):\n self.better_bind(wx.EVT_BUTTON, b, self.OnClick, 'somevalue')\n"
},
{
"answer_id": 173826,
"author": "DzinX",
"author_id": 18745,
"author_profile": "https://Stackoverflow.com/users/18745",
"pm_score": 4,
"selected": false,
"text": "def getOnClick(self, additionalArgument):\n def OnClick(event):\n self.log.write(\"Click! (%d), arg: %s\\n\" \n % (event.GetId(), additionalArgument))\n return OnClick\n b = wx.Button(self, 10, \"Default Button\", (20, 20))\nb.Bind(wx.EVT_BUTTON, self.getOnClick('my additional data'))\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18676/"
] |
173,706
|
<p>I am having the problem that I cannot select a specific XML node which needs to be deleted. I have already tried to select the node by using the XPath which works fine for some XML files but I cannot figure out the correct XPath for a node in a more complex file.</p>
<p>Does anybody know a freeware tool which can load a XML file so that the user can select a specific node and receives the accurate XPath without having an enumeration in the path?</p>
<p><code>/root/anything[2]</code> <-- unfortunatly I cannot use such a statement because the number of the element might change. I need an expression that is based on an attribute.</p>
<p>In case that there is no freeware tool for this operation, does anybody know another way how I can select the needed node?</p>
<p><strong>XML Sample:</strong></p>
<p><strong>Root Node:</strong> SmsFormData </p>
<p><strong>Attributes:</strong> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" FormatVersion="1.0" xmlns="http://schemas.microsoft.com/SystemsManagementServer/2005/03/ConsoleFramework"</p>
<p><strong>Child node:</strong> Form</p>
<p><strong>Attributes:</strong> Id="some GUID" CustomData="Some data" FormType="some type" ForceRefresh="false"</p>
<p><strong>Child/Child node:</strong> Pages</p>
<p><strong>Child/Child/Child node:</strong> Page</p>
<p><strong>Attributes:</strong> VendorId="VendorName" Id="some GUID" Assembly="dll File name" Namespace="some Namespace" Type="some Type" HelpID=""></p>
<p>My xPath expression to select this specific page would now be:</p>
<p><strong>xPath =</strong> <code>/SmsFormData/Form/Pages/Page[@Id="some Guid"]</code></p>
<p>To do the selection I am using the following vbscript code:</p>
<pre><code>Set objDOM = CreateObject("Msxml2.DOMDocument.4.0")
objDOM.async = false
objDOM.load(file)
set objNode = objDOM.selectSingleNode(xPath)
</code></pre>
<p>The problem is now that the <code>objNode</code> object is empty. The node is not selected, but why?</p>
|
[
{
"answer_id": 173748,
"author": "mdb",
"author_id": 8562,
"author_profile": "https://Stackoverflow.com/users/8562",
"pm_score": 0,
"selected": false,
"text": "<root>\n <anything foo=\"bar\">value1</anything>\n <anything foo=\"qux\">value2</anything>\n</root>\n /root/anything[@foo=\"qux\"]\n objDOM.selectSingleNode(\"/root/anything[@foo=\"\"qux\"\"]/text()\").nodeValue\n"
},
{
"answer_id": 173812,
"author": "Marcus",
"author_id": 25428,
"author_profile": "https://Stackoverflow.com/users/25428",
"pm_score": 0,
"selected": false,
"text": "Set objDOM = CreateObject(\"Msxml2.DOMDocument.4.0\") \n\nobjDOM.async = false \nobjDOM.load(file) \n\nset objNode = objDOM.selectSingleNode(xPath) \n"
},
{
"answer_id": 173922,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 0,
"selected": false,
"text": "sNamespaces = \"xmlns:cf='http://schemas.microsoft.com/SystemsManagementServer/2005/03/ConsoleFramework'\"\nobjDOM.setProperty \"SelectionNamespaces\", sNamespaces\n xPath = \"/cf:SmsFormData/cf:Form/cf:Pages/cf:Page[@Id=\"\"some Guid\"\"]\"\n"
},
{
"answer_id": 173923,
"author": "Luke Bennett",
"author_id": 17602,
"author_profile": "https://Stackoverflow.com/users/17602",
"pm_score": 3,
"selected": true,
"text": "objDom.SetProperty \"SelectionNamespaces\", \"xmlns:cf=\"\"http://schemas.microsoft.com/SystemsManagementServer/2005/03/ConsoleFramework\"\"\"\n cf objDom.SelectSingleNode(\"/cf:SmsFormData/cf:Form/cf:Pages/cf:Page[@Id='Some Guid']\")\n"
},
{
"answer_id": 459465,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<LoginData>\n <GeneralData>\n <LoginMask>65537</LoginMask>\n </GeneralData>\n <UserData>\n <User>\n <Username>TEST0</Username>\n ...\n </User>\n <User>\n <Username>TEST1</Username>\n ...\n </User>\n </UserData>\n</LoginData>"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173706",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25428/"
] |
173,717
|
<p>What is the easiest way to copy the all the values from a column in a table to another column in the same table?</p>
|
[
{
"answer_id": 173720,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 4,
"selected": false,
"text": "UPDATE table SET field1 = field2\n"
},
{
"answer_id": 173722,
"author": "Panagiotis Korros",
"author_id": 19331,
"author_profile": "https://Stackoverflow.com/users/19331",
"pm_score": 7,
"selected": true,
"text": "UPDATE <tablename>\nSET <destination column name> = <source column name>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25438/"
] |
173,726
|
<p>I'm doing some research into databases and I'm looking at some limitations of relational DBs. </p>
<p>I'm getting that joins of large tables is very expensive, but I'm not completely sure why. What does the DBMS need to do to execute a join operation, where is the bottleneck?<br>
How can denormalization help to overcome this expense? How do other optimization techniques (indexing, for example) help?</p>
<p>Personal experiences are welcome! If you're going to post links to resources, please avoid Wikipedia. I know where to find that already.</p>
<p>In relation to this, I'm wondering about the denormalized approaches used by cloud service databases like BigTable and SimpleDB. See <a href="https://stackoverflow.com/questions/176131/pros-of-databases-like-bigtable-simpledb">this question</a>.</p>
|
[
{
"answer_id": 174047,
"author": "Peter Wone",
"author_id": 1715673,
"author_profile": "https://Stackoverflow.com/users/1715673",
"pm_score": 10,
"selected": true,
"text": "SELECT * FROM A,B JOINs JOINs"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173726",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5409/"
] |
173,727
|
<p>I would like to save data in cookies (user name, email address, etc...) but I don't the user to easily read it or modify it. I need to be able able to read the data back. How can I do that with php 5.2+?</p>
<p>It would be used for "welcome back bob" kind of feature. It is not a replacement for persistence or session storage.</p>
|
[
{
"answer_id": 173750,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 1,
"selected": false,
"text": "mcrypt"
},
{
"answer_id": 173764,
"author": "Shoan",
"author_id": 17404,
"author_profile": "https://Stackoverflow.com/users/17404",
"pm_score": 4,
"selected": true,
"text": "<?php\nclass MyProjCrypt {\n\n private $td;\n private $iv;\n private $ks;\n private $salt;\n private $encStr;\n private $decStr;\n\n\n /**\n * The constructor initializes the cryptography library\n * @param $salt string The encryption key\n * @return void\n */\n function __construct($salt) {\n $this->td = mcrypt_module_open('rijndael-256', '', 'ofb', ''); // algorithm\n $this->ks = mcrypt_enc_get_key_size($this->td); // key size needed for the algorithm\n $this->salt = substr(md5($salt), 0, $this->ks);\n }\n\n /**\n * Generates a hex string of $src\n * @param $src string String to be encrypted\n * @return void\n */\n function encrypt($src) {\n srand(( double) microtime() * 1000000); //for sake of MCRYPT_RAND\n $this->iv = mcrypt_create_iv($this->ks, MCRYPT_RAND); \n mcrypt_generic_init($this->td, $this->salt, $this->iv);\n $tmpStr = mcrypt_generic($this->td, $src);\n mcrypt_generic_deinit($this->td);\n mcrypt_module_close($this->td);\n\n //convert the encrypted binary string to hex\n //$this->iv is needed to decrypt the string later. It has a fixed length and can easily \n //be seperated out from the encrypted String\n $this->encStr = bin2hex($this->iv.$tmpStr);\n\n }\n\n /**\n * Decrypts a hex string \n * @param $src string String to be decrypted\n * @return void\n */\n function decrypt($src) {\n //convert the hex string to binary\n $corrected = preg_replace(\"[^0-9a-fA-F]\", \"\", $src);\n $binenc = pack(\"H\".strlen($corrected), $corrected);\n\n //retrieve the iv from the encrypted string\n $this->iv = substr($binenc, 0, $this->ks);\n\n //retrieve the encrypted string alone(minus iv)\n $binstr = substr($binenc, $this->ks);\n\n /* Initialize encryption module for decryption */\n mcrypt_generic_init($this->td, $this->salt, $this->iv);\n /* Decrypt encrypted string */\n $decrypted = mdecrypt_generic($this->td, $binstr);\n\n /* Terminate decryption handle and close module */\n mcrypt_generic_deinit($this->td);\n mcrypt_module_close($this->td);\n $this->decStr = trim($decrypted);\n\n }\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173727",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1771/"
] |
173,745
|
<p>I'm looking for a query which will return me an extra column at the end of my current query which is the count of all columns within the return set which contain a null column. For example:</p>
<pre><code>Col 1 - Col 2 - Col 3
A B 0
A NULL 1
NULL NULL 2
</code></pre>
<p>Is there a simple way to get this return set based on the row values rather than having to requery all the criteria which fetches the original rows?</p>
|
[
{
"answer_id": 173805,
"author": "pmg",
"author_id": 25324,
"author_profile": "https://Stackoverflow.com/users/25324",
"pm_score": 2,
"selected": false,
"text": "select Col1, Col2,\n case when Col1 is null then 1 else 0 end\n + case when Col2 is null then 1 else 0 end\n as Col3\nfrom (\n\nselect 'A' as Col1, 'B' as Col2\nunion select 'A', NULL\nunion select NULL, NULL\n\n) z\n Col1 Col2 Col3\nNULL NULL 2\nA NULL 1\nA B 0\n"
},
{
"answer_id": 173831,
"author": "kristof",
"author_id": 3241,
"author_profile": "https://Stackoverflow.com/users/3241",
"pm_score": 0,
"selected": false,
"text": "CREATE TABLE testTable(\n col1 nchar(10) NULL,\n col2 nchar(10) NULL,\n col3 AS (case when col1 IS NULL then (1) else (0) end+case when col2 IS NULL then (1) else (0) end)\n)\n"
},
{
"answer_id": 174048,
"author": "Mladen",
"author_id": 21404,
"author_profile": "https://Stackoverflow.com/users/21404",
"pm_score": 2,
"selected": false,
"text": "select count(*) - count(ColumnName) as NumberOfNulls from yourTable\n"
},
{
"answer_id": 174062,
"author": "David Aldridge",
"author_id": 6742,
"author_profile": "https://Stackoverflow.com/users/6742",
"pm_score": 2,
"selected": false,
"text": "select col1,\n col2,\n col3,\n ...\n NVL2(col1,0,1)\n +NVL2(col2,0,1)\n +NVL2(col3,0,1) coln\nfrom whatever\n"
},
{
"answer_id": 178674,
"author": "Thorsten",
"author_id": 25320,
"author_profile": "https://Stackoverflow.com/users/25320",
"pm_score": 1,
"selected": false,
"text": "select <key>, col1 as value From aTable\nUNION\nselect <key>, col2 as value From aTable\nUNION\n... and so on for the other columns to be summed.\n create view aView as (select as above).\n select key, count(*)\nfrom aView\nwhere value is null\nGroup By key\n"
},
{
"answer_id": 7539174,
"author": "Jasper Austin Alexander",
"author_id": 962633,
"author_profile": "https://Stackoverflow.com/users/962633",
"pm_score": 1,
"selected": false,
"text": "create table TEST\n(\n a VARCHAR2(10),\n b VARCHAR2(10),\n c VARCHAR2(10)\n);\n\ninsert into TEST (a, b, c)\nvalues ('jas', 'abhi', 'shail');\ninsert into TEST (a, b, c)\nvalues (null, 'abhi', 'shail');\ninsert into TEST (a, b, c)\nvalues ('jas', null, 'shail');\ninsert into TEST (a, b, c)\nvalues ('jas', 'abhi', null);\ninsert into TEST (a, b, c)\nvalues ('jas', 'abhi', 'abc|xyz');\ninsert into TEST (a, b, c)\nvalues ('jas', 'abhi', 'abc|xyz');\ninsert into TEST (a, b, c)\nvalues ('jas', 'abhi', 'abc|xyz');\ninsert into TEST (a, b, c)\nvalues (null, 'abhi', 'abc|xyz');\ncommit;\n\nselect sum(nvl2(a,null,1)),sum(nvl2(b,null,1)),sum(nvl2(c,null,1)) from test \nwhere a is null \nor b is null\nor c is null\norder by 1,2,3 \n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173745",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
173,757
|
<p>We run a medium-size site that gets a few hundred thousand pageviews a day. Up until last weekend we ran with a load usually below 0.2 on a virtual machine. The OS is Ubuntu.</p>
<p>When deploying the latest version of our application, we also did an apt-get dist-upgrade before deploying. After we had deployed we noticed that the load on the CPU had spiked dramatically (sometimes reaching 10 and stopping to respond to page requests). </p>
<p>We tried dumping a full minute of Xdebug profiling data from PHP, but looking through it revealed only a few somewhat slow parts, but nothing to explain the huge jump.</p>
<p>We are now pretty sure that nothing in the new version of our website is triggering the problem, but we have no way to be sure. We have rolled back a lot of the changes, but the problem still persists.</p>
<p>When look at processes, we see that single Apache processes use quite a bit of CPU over a longer period of time than strictly necessary. However, when using strace on the affected process, we never see anything but</p>
<pre><code>accept(3,
</code></pre>
<p>and it hangs for a while before receiving a new connection, so we can't actually see what is causing the problem.</p>
<p>The stack is PHP 5, Apache 2 (prefork), MySQL 5.1. Most things run through Memcached. We've tried APC and eAccelerator.</p>
<p>So, what should be our next step? Are there any profiling methods we overlooked/don't know about?</p>
|
[
{
"answer_id": 174994,
"author": "Jon Topper",
"author_id": 6945,
"author_profile": "https://Stackoverflow.com/users/6945",
"pm_score": 3,
"selected": false,
"text": "vmstat 1\n top\n echo \"show full processlist\" | mysql | grep -v Sleep\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1606/"
] |
173,786
|
<p>I have a UIScrollView that shows vertical data, but where the horizontal component is no wider than the screen of the iPhone. The problem is that the user is still able to drag horizontally, and basically expose blank sections of the UI. I have tried setting:</p>
<pre><code>scrollView.alwaysBounceHorizontal = NO;
scrollView.directionalLockEnabled = YES;
</code></pre>
<p>Which helps a little, but still doesn't stop the user from being able to drag horizontally. Surely there is a way to fix this easily?</p>
|
[
{
"answer_id": 174920,
"author": "Mike McMaster",
"author_id": 544,
"author_profile": "https://Stackoverflow.com/users/544",
"pm_score": 5,
"selected": true,
"text": "// Should scroll vertically but not horizontally\nUIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];\nscrollView.contentSize = CGSizeMake(320, 1000);\n"
},
{
"answer_id": 10949232,
"author": "Denis Kutlubaev",
"author_id": 751641,
"author_profile": "https://Stackoverflow.com/users/751641",
"pm_score": 0,
"selected": false,
"text": "- (void)webViewDidFinishLoad:(UIWebView *)webView {\n\n[webView.scrollView setContentSize: CGSizeMake(webView.frame.size.width, webView.scrollView.contentSize.height)];\n\n}\n"
},
{
"answer_id": 14412762,
"author": "n13",
"author_id": 129213,
"author_profile": "https://Stackoverflow.com/users/129213",
"pm_score": 2,
"selected": false,
"text": "scrollView.contentSize = CGSizeMake(scrollView.frame.size.width - scrollView.contentInset.left - scrollView.contentInset.right, height);\n"
},
{
"answer_id": 22750291,
"author": "Asnis Apps",
"author_id": 2926546,
"author_profile": "https://Stackoverflow.com/users/2926546",
"pm_score": 5,
"selected": false,
"text": "scrollView.bounces = NO;\n"
},
{
"answer_id": 38840638,
"author": "Addison",
"author_id": 1525759,
"author_profile": "https://Stackoverflow.com/users/1525759",
"pm_score": 1,
"selected": false,
"text": "false NO scrollView.horizontalScrollElasticity = false\n scrollView.horizontalScrollElasticity = NO\n"
},
{
"answer_id": 40536760,
"author": "Michael Katkov",
"author_id": 955321,
"author_profile": "https://Stackoverflow.com/users/955321",
"pm_score": 3,
"selected": false,
"text": "scrollView.alwaysBounceHorizontal = false\nscrollView.bounces = false\n"
},
{
"answer_id": 54071842,
"author": "Luan Si Ho",
"author_id": 7895927,
"author_profile": "https://Stackoverflow.com/users/7895927",
"pm_score": -1,
"selected": false,
"text": "collectionView.bounces = false"
},
{
"answer_id": 69990134,
"author": "xyzgentoo",
"author_id": 602024,
"author_profile": "https://Stackoverflow.com/users/602024",
"pm_score": 0,
"selected": false,
"text": "- (void)scrollViewDidScroll:(UIScrollView *)scrollView {\n if (scrollView.contentOffset.x < 0) {\n scrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);\n } else if (scrollView.contentOffset.x > scrollView.contentSize.width) {\n scrollView.contentOffset = CGPointMake(scrollView.contentSize.width, scrollView.contentOffset.y);\n }\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6044/"
] |
173,790
|
<p>If I safe an Array and reload it, is there a possibility to get the size if its unknown?
Thanks</p>
|
[
{
"answer_id": 173808,
"author": "Wouter Lievens",
"author_id": 7927,
"author_profile": "https://Stackoverflow.com/users/7927",
"pm_score": 2,
"selected": false,
"text": "int[] myArray = deserializeSomeArray();\nint size = myArray.length;\n"
},
{
"answer_id": 174077,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 0,
"selected": false,
"text": "MyType[] things = (MyType[])in.readObject();\nint len = things.length;\n private static final MyType[] NOTHING = new MyType[0];\n\nprivate transient MyType[] things = NOTHING;\n\nprivate void writeObject(ObjectOutputStream out) throws IOException {\n out.defaultWriteObject(); // Do not forget this call!\n for (MyType thing : things) {\n out.writeObject(thing);\n }\n}\nprivate void readObject(\n ObjectInputStream in\n) throws IOException, ClassNotFoundException {\n in.defaultReadObject(); // Do not forget this call!\n List<MyType> things = new ArrayList<MyType>();\n try {\n for (;;) {\n things.add((MyType)in.readObject();\n }\n } catch (OptionalDataException exc) {\n // Okay - end of custom data.\n }\n this.things = things.toArray(NOTHING);\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25128/"
] |
173,810
|
<p>A <code>TextBox</code> is set to <code>AutoPostback</code> as changing the value should cause a number of (display-only) fields to be recalculated and displayed.<br>
That works fine.</p>
<p>However, when the field is tabbed out of, the focus briefly moves on to the next field, then disappears when the page is redrawn so there is no focus anywhere. </p>
<p>I want the focus to be on the new field, not the textbox I've just changed.
Is there a way to work out which field had the focus and force it to have it again when the page is redrawn? </p>
|
[
{
"answer_id": 7875147,
"author": "Emanuele Greco",
"author_id": 497040,
"author_profile": "https://Stackoverflow.com/users/497040",
"pm_score": 1,
"selected": false,
"text": "<script>\nvar idSelected;\n $(\"input\").focusin(function () {\n idSelected = this.id;\n });\n</script>\n var idSelected var idSelected <script>\n$(document).ready(function () {\n if (idSelected != null) {\n $(\"#\" + idSelected).focus();\n idSelected = null;\n });\n});\n</script>\n Jquery.js <form id=\"form1\" runat=\"server\" enctype=\"multipart/form-data\" method=\"post\">\n <asp:ScriptManager runat=\"server\" >\n <Scripts>\n <asp:ScriptReference Path=\"~/Scripts/jquery.js\" ScriptMode=\"Auto\" />\n....\n <script type=\"text/javascript\">\n Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);\n\n function EndRequestHandler(sender, args)\n {\n MyScript(); \n } \n</script>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24096/"
] |
173,814
|
<p>How can ALTER be used to drop a column in a MySQL table if that column exists? </p>
<p>I know I can use <code>ALTER TABLE my_table DROP COLUMN my_column</code>, but that will throw an error if <code>my_column</code> does not exist. Is there alternative syntax for dropping the column conditionally?</p>
<p>I'm using MySQL version 4.0.18.</p>
|
[
{
"answer_id": 173820,
"author": "Matthias Winkelmann",
"author_id": 4494,
"author_profile": "https://Stackoverflow.com/users/4494",
"pm_score": 7,
"selected": true,
"text": "IF EXISTS DROP [COLUMN] [IF EXISTS] col_name \n ALTER TABLE my_table DROP IF EXISTS my_column;\n"
},
{
"answer_id": 2120452,
"author": "Chase Seibert",
"author_id": 7679,
"author_profile": "https://Stackoverflow.com/users/7679",
"pm_score": 6,
"selected": false,
"text": "drop procedure if exists schema_change;\n\ndelimiter ';;'\ncreate procedure schema_change() begin\n\n /* delete columns if they exist */\n if exists (select * from information_schema.columns where table_schema = schema() and table_name = 'table1' and column_name = 'column1') then\n alter table table1 drop column `column1`;\n end if;\n if exists (select * from information_schema.columns where table_schema = schema() and table_name = 'table1' and column_name = 'column2') then\n alter table table1 drop column `column2`;\n end if;\n\n /* add columns */\n alter table table1 add column `column1` varchar(255) NULL;\n alter table table1 add column `column2` varchar(255) NULL;\n\nend;;\n\ndelimiter ';'\ncall schema_change();\n\ndrop procedure if exists schema_change;\n"
},
{
"answer_id": 2155890,
"author": "DrHyde",
"author_id": 261131,
"author_profile": "https://Stackoverflow.com/users/261131",
"pm_score": 3,
"selected": false,
"text": "select * from information_schema.columns where table_schema in (select schema()) and table_name=...\n"
},
{
"answer_id": 6453654,
"author": "ajp",
"author_id": 22045,
"author_profile": "https://Stackoverflow.com/users/22045",
"pm_score": -1,
"selected": false,
"text": "x a a b"
},
{
"answer_id": 45505899,
"author": "Pradeep Puranik",
"author_id": 340131,
"author_profile": "https://Stackoverflow.com/users/340131",
"pm_score": 4,
"selected": false,
"text": "set @exist_Check := (\n select count(*) from information_schema.columns \n where TABLE_NAME='YOUR_TABLE' \n and COLUMN_NAME='YOUR_COLUMN' \n and TABLE_SCHEMA=database()\n) ;\nset @sqlstmt := if(@exist_Check>0,'alter table YOUR_TABLE drop column YOUR_COLUMN', 'select ''''') ;\nprepare stmt from @sqlstmt ;\nexecute stmt ;\n"
},
{
"answer_id": 49676339,
"author": "sp00m",
"author_id": 1225328,
"author_profile": "https://Stackoverflow.com/users/1225328",
"pm_score": 4,
"selected": false,
"text": "DROP COLUMN -- column_exists:\n\nDROP FUNCTION IF EXISTS column_exists;\n\nDELIMITER $$\nCREATE FUNCTION column_exists(\n tname VARCHAR(64),\n cname VARCHAR(64)\n)\n RETURNS BOOLEAN\n READS SQL DATA\n BEGIN\n RETURN 0 < (SELECT COUNT(*)\n FROM `INFORMATION_SCHEMA`.`COLUMNS`\n WHERE `TABLE_SCHEMA` = SCHEMA()\n AND `TABLE_NAME` = tname\n AND `COLUMN_NAME` = cname);\n END $$\nDELIMITER ;\n\n-- drop_column_if_exists:\n\nDROP PROCEDURE IF EXISTS drop_column_if_exists;\n\nDELIMITER $$\nCREATE PROCEDURE drop_column_if_exists(\n tname VARCHAR(64),\n cname VARCHAR(64)\n)\n BEGIN\n IF column_exists(tname, cname)\n THEN\n SET @drop_column_if_exists = CONCAT('ALTER TABLE `', tname, '` DROP COLUMN `', cname, '`');\n PREPARE drop_query FROM @drop_column_if_exists;\n EXECUTE drop_query;\n END IF;\n END $$\nDELIMITER ;\n CALL drop_column_if_exists('my_table', 'my_column');\n SELECT column_exists('my_table', 'my_column'); -- 1\nCALL drop_column_if_exists('my_table', 'my_column'); -- success\nSELECT column_exists('my_table', 'my_column'); -- 0\nCALL drop_column_if_exists('my_table', 'my_column'); -- success\nSELECT column_exists('my_table', 'my_column'); -- 0\n"
},
{
"answer_id": 59574226,
"author": "Shah Zain",
"author_id": 5196973,
"author_profile": "https://Stackoverflow.com/users/5196973",
"pm_score": 2,
"selected": false,
"text": " IF EXISTS (SELECT *\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE TABLE_NAME = 'TableName' AND COLUMN_NAME = 'ColumnName' \n AND TABLE_SCHEMA = SchemaName)\n BEGIN\n ALTER TABLE TableName DROP COLUMN ColumnName;\n END;\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7362/"
] |
173,821
|
<p>I want to output the function name each time it is called, I can easily copy and paste the function name, however I wondered if there was a shortcut that would do the job for me?</p>
<p>At the moment I am doing:</p>
<pre><code>SlideInfoHeader* lynxThreeFile::readSlideInfoHeader(QDataStream & in)
{
qDebug("lynxThreeFile::readSlideInfoHeader");
}
</code></pre>
<p>but what I want is something generic:</p>
<pre><code>SlideInfoHeader* lynxThreeFile::readSlideInfoHeader(QDataStream & in)
{
qDebug(this.className() + "::" + this.functionName());
}
</code></pre>
|
[
{
"answer_id": 173828,
"author": "Torbjörn Gyllebring",
"author_id": 21182,
"author_profile": "https://Stackoverflow.com/users/21182",
"pm_score": 6,
"selected": true,
"text": "__FUNCTION__"
},
{
"answer_id": 174369,
"author": "Matt Price",
"author_id": 852,
"author_profile": "https://Stackoverflow.com/users/852",
"pm_score": 3,
"selected": false,
"text": "__func__"
},
{
"answer_id": 175047,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 4,
"selected": false,
"text": "Q_FUNC_INFO <QGlobal>"
},
{
"answer_id": 175311,
"author": "Mark Kegel",
"author_id": 14788,
"author_profile": "https://Stackoverflow.com/users/14788",
"pm_score": 3,
"selected": false,
"text": "__PRETTY_FUNCTION__"
},
{
"answer_id": 217808,
"author": "Ronny Brendel",
"author_id": 14114,
"author_profile": "https://Stackoverflow.com/users/14114",
"pm_score": 3,
"selected": false,
"text": "__func__ __FUNCTION__ __PRETTY_FUNCTION__"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24459/"
] |
173,834
|
<p>Given an SQLConnection object how can you get a schema for a single table?</p>
<p>I seemed to be able to get the schema from a <code>DataSet</code> which I'd gotten from running a query, but all the schema info I could get from the connection seemed to be related to what tables were available and not the actual details on the tables.</p>
|
[
{
"answer_id": 173863,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": true,
"text": "Command.ExecuteReader(CommandBehavior.KeyInfo)\n"
},
{
"answer_id": 173871,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 3,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nusing System.Data;\nusing System.Data.SqlClient;\nusing System.Data.SqlTypes;\n\nnamespace ConsoleApp\n{\n class Program\n {\n static void Main(string[] args)\n {\n string query = \"SELECT * FROM t where 1=0\";\n string connectionString = \"initial catalog=test;data source=localhost;Trusted_Connection=Yes\";\n\n DataTable tblSchema;\n\n using (SqlConnection cnn = new SqlConnection(connectionString))\n {\n using (SqlCommand cmd = cnn.CreateCommand())\n {\n cmd.CommandText = query;\n cmd.CommandType = CommandType.Text;\n cnn.Open();\n using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.KeyInfo))\n {\n tblSchema = rdr.GetSchemaTable();\n }\n cnn.Close();\n }\n }\n int numColumns = tblSchema.Columns.Count;\n foreach (DataRow dr in tblSchema.Rows)\n {\n Console.WriteLine(\"{0}: {1}\", dr[\"ColumnName\"], dr[\"DataType\"]);\n }\n\n Console.ReadLine();\n }\n }\n}\n"
},
{
"answer_id": 173881,
"author": "KristoferA",
"author_id": 11241,
"author_profile": "https://Stackoverflow.com/users/11241",
"pm_score": 0,
"selected": false,
"text": "select so.name, sc.*\nfrom sys.objects as so\ninner join sys.columns as sc on sc.object_id = so.object_id\nwhere so.name='some_table'\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400/"
] |
173,835
|
<p>I am using Spry (<code>SpryData.js,xpath.js</code>)</p>
<pre><code> var ds1 = new Spry.Data.XMLDataSet("_db/db.xml", "bildiriler/bildiri",{useCache:false});
// load the xml tree
</code></pre>
<p>....</p>
<pre><code><!-- use it in a loop -
Sometimes the page use "ds1.loadData();" to refresh the data -->
<div spry:region="ds1" spry:repeatchildren="ds1">
<a href="#">{author}</a></div>
</code></pre>
<p>So how can I show a loader animation or "Loading text" while XML data is loading </p>
<p>(It takes a long time -about 2 sec from a slow CD-. My XML file is big 100KB )</p>
|
[
{
"answer_id": 174320,
"author": "Errico Malatesta",
"author_id": 24439,
"author_profile": "https://Stackoverflow.com/users/24439",
"pm_score": 0,
"selected": false,
"text": "<p spry:state =\"loading\"> Loading ( text or an image ) </p>\n"
},
{
"answer_id": 3351158,
"author": "loali",
"author_id": 404265,
"author_profile": "https://Stackoverflow.com/users/404265",
"pm_score": 0,
"selected": false,
"text": "<div align=\"center\" spry:region=\"dsmain\" spry:state=\"loading\" >\n<img src=\"../icon/Loader/1.gif\" />\n<br />please wait ...\n</div> \n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173835",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24439/"
] |
173,846
|
<p>I'm trying to have my Struts2 app redirect to a generated URL. In this case, I want the URL to use the current date, or a date I looked up in a database. So <code>/section/document</code> becomes <code>/section/document/2008-10-06</code></p>
<p>What's the best way to do this?</p>
|
[
{
"answer_id": 174100,
"author": "Sietse",
"author_id": 6400,
"author_profile": "https://Stackoverflow.com/users/6400",
"pm_score": 2,
"selected": false,
"text": "ServletRedirectResult doExecute() super.doExecute() public class AppendRedirectionResult extends ServletRedirectResult {\n private DateFormat df = new SimpleDateFormat(\"yyyy-MM-dd\");\n\n @Override\n protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {\n String date = df.format(new Date());\n String loc = \"/section/document/\"+date;\n super.doExecute(loc, invocation);\n }\n}\n"
},
{
"answer_id": 179251,
"author": "Johnny Wey",
"author_id": 25855,
"author_profile": "https://Stackoverflow.com/users/25855",
"pm_score": 7,
"selected": true,
"text": "<result name=\"redirect\" type=\"redirect\">${url}</result>\n private String url;\n\npublic String getUrl()\n{\n return url;\n}\n\npublic String execute()\n{\n [other stuff to setup your date]\n url = \"/section/document\" + date;\n return \"redirect\";\n}\n"
},
{
"answer_id": 696804,
"author": "Ivan Morales",
"author_id": 84573,
"author_profile": "https://Stackoverflow.com/users/84573",
"pm_score": 4,
"selected": false,
"text": "annotations @Result(location=\"${url}\", type=\"redirect\")\n"
},
{
"answer_id": 23708112,
"author": "hari",
"author_id": 3547935,
"author_profile": "https://Stackoverflow.com/users/3547935",
"pm_score": 2,
"selected": false,
"text": "ActionClass public class RedirecActionExample extends ActionSupport {\nHttpServletResponse response=(HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);\n\n url=\"http://localhost:8080/SpRoom-1.0-SNAPSHOT/\"+date;\n response.sendRedirect(url);\n return super.execute(); \n}\n"
},
{
"answer_id": 24891251,
"author": "tiwari.vikash",
"author_id": 1449506,
"author_profile": "https://Stackoverflow.com/users/1449506",
"pm_score": 1,
"selected": false,
"text": "@Result(\n name = \"resultName\",\n type = \"redirectAction\",\n params = { \"actionName\", \"XYZAction\" }\n)\n"
},
{
"answer_id": 40402314,
"author": "Aaron",
"author_id": 7659,
"author_profile": "https://Stackoverflow.com/users/7659",
"pm_score": 1,
"selected": false,
"text": " <global-results>\n <result name=\"redir\" type=\"redirect\">${#request.redirUrl}</result>\n </global-results>\n @Override\npublic String intercept(ActionInvocation ai) throws Exception\n{\n final ActionContext context = ai.getInvocationContext(); \n HttpServletRequest request = (HttpServletRequest)context.get(StrutsStatics.HTTP_REQUEST);\n request.setAttribute(\"redirUrl\", \"http://the.new.target.org\");\n return \"redir\";\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6400/"
] |
173,851
|
<p>I have a PHP script that needs to determine if it's been executed via the command-line or via HTTP, primarily for output-formatting purposes. What's the canonical way of doing this? I had thought it was to inspect <code>SERVER['argc']</code>, but it turns out this is populated, even when using the 'Apache 2.0 Handler' server API.</p>
|
[
{
"answer_id": 173856,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 3,
"selected": false,
"text": "$_SERVER['REMOTE_ADDR']\n"
},
{
"answer_id": 173887,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 9,
"selected": true,
"text": "php_sapi_name() if (php_sapi_name() == \"cli\") {\n // In cli-mode\n} else {\n // Not in cli-mode\n}\n PHP_SAPI php_sapi_name()"
},
{
"answer_id": 1235061,
"author": "Steve",
"author_id": 151283,
"author_profile": "https://Stackoverflow.com/users/151283",
"pm_score": 3,
"selected": false,
"text": "php_sapi"
},
{
"answer_id": 4392867,
"author": "Xeoncross",
"author_id": 99923,
"author_profile": "https://Stackoverflow.com/users/99923",
"pm_score": 5,
"selected": false,
"text": "define('CLI', PHP_SAPI === 'cli');\n <?php PHP_SAPI === 'cli' or die('not allowed');\n"
},
{
"answer_id": 12654906,
"author": "ya.teck",
"author_id": 272927,
"author_profile": "https://Stackoverflow.com/users/272927",
"pm_score": 4,
"selected": false,
"text": "function drupal_is_cli() {\n return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));\n}\n PHP_SAPI === 'cli'"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173851",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5058/"
] |
173,866
|
<p>I have a web page which contains a select box. When I open a jQuery Dialog it is displayed partly behind the select box.</p>
<p>How should I approach this problem? Should I hide the select box or does jQuery offer some kind of 'shim' solution. (I have Googled but didn't find anything)</p>
<p>Here is some code:</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<title>testJQuery</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
<link rel="stylesheet" href="theme/smooth/theme.css" type="text/css" media="screen" />
</head>
<body>
<a class="pop" href="nix">Click me</a>
<p/>
<select size="20">
<option>s jl fjlkdjfldjf l*s ldkjsdlfkjsdl fkdjlfks dfldkfjdfkjlsdkf jdksdjf sd</option>
<option>s jl fjlkdjfldjf l*s ldkjsdlfkjsdl fkdjlfks dfldkfjdfkjlsdkf jdksdjf sd</option>
<option>s jl fjlkdjfldjf l*s ldkjsdlfkjsdl fkdjlfks dfldkfjdfkjlsdkf jdksdjf sd</option>
<option>s jl fjlkdjfldjf l*s ldkjsdlfkjsdl fkdjlfks dfldkfjdfkjlsdkf jdksdjf sd</option>
<option>s jl fjlkdjfldjf l*s ldkjsdlfkjsdl fkdjlfks dfldkfjdfkjlsdkf jdksdjf sd</option>
</select>
<div id="xyz" class="flora hiddenAsset">
<div id="dialog" title="Edit Link">
<p>Enter the link details:</p>
<table width="80%" border="1">
<tr><td>URL</td><td><input id="url" style="width:100%" maxlength="200" value="{url}"/></td></tr>
<tr><td>Title</td><td><input id="title" style="width:100%" maxlength="200" value="{title}"/></td></tr>
<tr><td>Target</td><td><input id="target" size="20" maxlength="200" value="{target}"/></td></tr>
</table>
</div>
</div>
<script type="text/javascript" src="../script/firebug/firebug.js"></script>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript" src="jquery-ui-1.5.2.js"></script>
<script type="text/javascript" src="jqSOAPClient.js"></script>
<script type="text/javascript">
(function($){
$(document).ready(function(){
console.debug('ready');
$('.hiddenAsset').hide();
$('a.pop').bind('click', showDialog);
console.debug('ready - done');
});
var showDialog = function(){
console.debug('show');
$('#dialog').dialog({
modal: true,
overlay: {
backgroundColor: '#666',
opacity: '.3',
filter: 'alpha(opacity=30)'
},
width: '400px',
height: '300px',
buttons: {
Ok: function() {
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
}
});
console.debug('show-done');
return false;
};
})(jQuery);
</script>
</body>
</html>
</code></pre>
|
[
{
"answer_id": 173856,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 3,
"selected": false,
"text": "$_SERVER['REMOTE_ADDR']\n"
},
{
"answer_id": 173887,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 9,
"selected": true,
"text": "php_sapi_name() if (php_sapi_name() == \"cli\") {\n // In cli-mode\n} else {\n // Not in cli-mode\n}\n PHP_SAPI php_sapi_name()"
},
{
"answer_id": 1235061,
"author": "Steve",
"author_id": 151283,
"author_profile": "https://Stackoverflow.com/users/151283",
"pm_score": 3,
"selected": false,
"text": "php_sapi"
},
{
"answer_id": 4392867,
"author": "Xeoncross",
"author_id": 99923,
"author_profile": "https://Stackoverflow.com/users/99923",
"pm_score": 5,
"selected": false,
"text": "define('CLI', PHP_SAPI === 'cli');\n <?php PHP_SAPI === 'cli' or die('not allowed');\n"
},
{
"answer_id": 12654906,
"author": "ya.teck",
"author_id": 272927,
"author_profile": "https://Stackoverflow.com/users/272927",
"pm_score": 4,
"selected": false,
"text": "function drupal_is_cli() {\n return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));\n}\n PHP_SAPI === 'cli'"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173866",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11249/"
] |
173,868
|
<p>This is a question you can read everywhere on the web with various answers:</p>
<pre><code>$ext = end(explode('.', $filename));
$ext = substr(strrchr($filename, '.'), 1);
$ext = substr($filename, strrpos($filename, '.') + 1);
$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename);
$exts = split("[/\\.]", $filename);
$n = count($exts)-1;
$ext = $exts[$n];
</code></pre>
<p>etc.</p>
<p>However, there is always "the best way" and it should be on Stack Overflow.</p>
|
[
{
"answer_id": 173872,
"author": "Adam Wright",
"author_id": 1200,
"author_profile": "https://Stackoverflow.com/users/1200",
"pm_score": 8,
"selected": false,
"text": "pathinfo() $path_info = pathinfo('/foo/bar/baz.bill');\n\necho $path_info['extension']; // \"bill\"\n"
},
{
"answer_id": 173876,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 12,
"selected": true,
"text": "pathinfo() $ext = pathinfo($filename, PATHINFO_EXTENSION);\n pathinfo() setlocale(LC_ALL,'en_US.UTF-8');\n"
},
{
"answer_id": 174473,
"author": "Toxygene",
"author_id": 8428,
"author_profile": "https://Stackoverflow.com/users/8428",
"pm_score": 5,
"selected": false,
"text": "// Code assumes necessary extensions are installed and a successful file upload has already occurred\n\n// Create a FileInfo object\n$finfo = new FileInfo(null, '/path/to/magic/file');\n\n// Determine the MIME type of the uploaded file\nswitch ($finfo->file($_FILES['image']['tmp_name'], FILEINFO_MIME)) { \n case 'image/jpg':\n $im = imagecreatefromjpeg($_FILES['image']['tmp_name']);\n break;\n\n case 'image/png':\n $im = imagecreatefrompng($_FILES['image']['tmp_name']);\n break;\n\n case 'image/gif':\n $im = imagecreatefromgif($_FILES['image']['tmp_name']);\n break;\n}\n"
},
{
"answer_id": 11914810,
"author": "Anonymous",
"author_id": 1125062,
"author_profile": "https://Stackoverflow.com/users/1125062",
"pm_score": 5,
"selected": false,
"text": "array_pop(explode('.', $fname))\n $fname my_picture.jpg jpg"
},
{
"answer_id": 12932338,
"author": "hakre",
"author_id": 367456,
"author_profile": "https://Stackoverflow.com/users/367456",
"pm_score": 6,
"selected": false,
"text": "SplFileInfo $file = new SplFileInfo($path);\n$ext = $file->getExtension();\n $ext = (new SplFileInfo($path))->getExtension();\n"
},
{
"answer_id": 13183055,
"author": "Alix Axel",
"author_id": 89771,
"author_profile": "https://Stackoverflow.com/users/89771",
"pm_score": 4,
"selected": false,
"text": "pathinfo($path, PATHINFO_EXTENSION) $path = '/path/to/file.tar.gz';\n\necho ltrim(strstr($path, '.'), '.'); // tar.gz\necho pathinfo($path, PATHINFO_EXTENSION); // gz\n pathinfo"
},
{
"answer_id": 13604680,
"author": "AlexB",
"author_id": 1139150,
"author_profile": "https://Stackoverflow.com/users/1139150",
"pm_score": -1,
"selected": false,
"text": "str_replace('.', '', strrchr($file_name, '.'))\n"
},
{
"answer_id": 20398498,
"author": "Kurt Zhong",
"author_id": 480120,
"author_profile": "https://Stackoverflow.com/users/480120",
"pm_score": 3,
"selected": false,
"text": "substr($path, strrpos($path, '.') + 1);\n"
},
{
"answer_id": 25092925,
"author": "Subodh Ghulaxe",
"author_id": 1868660,
"author_profile": "https://Stackoverflow.com/users/1868660",
"pm_score": 4,
"selected": false,
"text": "<?php\n\n$info = new SplFileInfo('test.png');\nvar_dump($info->getExtension());\n\n$info = new SplFileInfo('test.tar.gz');\nvar_dump($info->getExtension());\n\n?>\n string(3) \"png\"\nstring(2) \"gz\"\n <?php\n\n$ext = pathinfo('test.png', PATHINFO_EXTENSION);\nvar_dump($ext);\n\n$ext = pathinfo('test.tar.gz', PATHINFO_EXTENSION);\nvar_dump($ext);\n\n?>\n string(3) \"png\"\nstring(2) \"gz\"\n"
},
{
"answer_id": 27961090,
"author": "Deepika Patel",
"author_id": 2756364,
"author_profile": "https://Stackoverflow.com/users/2756364",
"pm_score": 2,
"selected": false,
"text": "$ext = pathinfo($filename, PATHINFO_EXTENSION);\n"
},
{
"answer_id": 28054743,
"author": "Jonathan Ellis",
"author_id": 555485,
"author_profile": "https://Stackoverflow.com/users/555485",
"pm_score": 2,
"selected": false,
"text": "pathinfo() SplFileInfo # ? pathinfo() $url_components = parse_url($url); // First parse the URL\n$url_path = $url_components['path']; // Then get the path component\n$ext = pathinfo($url_path, PATHINFO_EXTENSION); // Then use pathinfo()\n"
},
{
"answer_id": 28731667,
"author": "G. I. Joe",
"author_id": 2986881,
"author_profile": "https://Stackoverflow.com/users/2986881",
"pm_score": 3,
"selected": false,
"text": "$ext = substr($filename, strrpos($filename, '.', -1), strlen($filename));\n"
},
{
"answer_id": 30207481,
"author": "Shahbaz",
"author_id": 1869193,
"author_profile": "https://Stackoverflow.com/users/1869193",
"pm_score": 3,
"selected": false,
"text": "$file_ext = pathinfo('your_file_name_here', PATHINFO_EXTENSION);\necho ($file_ext); // The output should be the extension of the file e.g., png, gif, or html\n"
},
{
"answer_id": 30454683,
"author": "version 2",
"author_id": 4152420,
"author_profile": "https://Stackoverflow.com/users/4152420",
"pm_score": 3,
"selected": false,
"text": "// Exploding the file based on the . operator\n$file_ext = explode('.', $filename);\n\n// Count taken (if more than one . exist; files like abc.fff.2013.pdf\n$file_ext_count = count($file_ext);\n\n// Minus 1 to make the offset correct\n$cnt = $file_ext_count - 1;\n\n// The variable will have a value pdf as per the sample file name mentioned above.\n$file_extension = $file_ext[$cnt];\n"
},
{
"answer_id": 31476046,
"author": "T.Todua",
"author_id": 2377343,
"author_profile": "https://Stackoverflow.com/users/2377343",
"pm_score": 7,
"selected": false,
"text": "http://example.com/myfolder/sympony.mp3?a=1&b=2#XYZ PATHINFO pathinfo($url)['dirname'] 'http://example.com/myfolder'\npathinfo($url)['basename'] 'sympony.mp3?a=1&b=2#XYZ' // <------- BAD !!\npathinfo($url)['extension'] 'mp3?a=1&b=2#XYZ' // <------- BAD !!\npathinfo($url)['filename'] 'sympony'\n parse_url($url)['scheme'] 'http'\nparse_url($url)['host'] 'example.com'\nparse_url($url)['path'] '/myfolder/sympony.mp3'\nparse_url($url)['query'] 'aa=1&bb=2'\nparse_url($url)['fragment'] 'XYZ'\n"
},
{
"answer_id": 37019281,
"author": "Samir Karmacharya",
"author_id": 5387175,
"author_profile": "https://Stackoverflow.com/users/5387175",
"pm_score": 2,
"selected": false,
"text": "<?php\n $files = glob(\"abc/*.*\"); // abc is the folder all files inside folder\n //print_r($files);\n //echo count($files);\n for($i=0; $i<count($files); $i++):\n $extension = pathinfo($files[$i], PATHINFO_EXTENSION);\n $ext[] = $extension;\n // Do operation for particular extension type\n if($extension=='html'){\n // Do operation\n }\n endfor;\n print_r($ext);\n?>\n"
},
{
"answer_id": 37410143,
"author": "smile 22121",
"author_id": 5790794,
"author_profile": "https://Stackoverflow.com/users/5790794",
"pm_score": 2,
"selected": false,
"text": " pathinfo(basename($_FILES[\"fileToUpload\"][\"name\"]), PATHINFO_EXTENSION)\n"
},
{
"answer_id": 37606085,
"author": "Arshid KV",
"author_id": 2513873,
"author_profile": "https://Stackoverflow.com/users/2513873",
"pm_score": 3,
"selected": false,
"text": "$path_parts = pathinfo('test.png');\n\necho $path_parts['extension'], \"\\n\";\necho $path_parts['dirname'], \"\\n\";\necho $path_parts['basename'], \"\\n\";\necho $path_parts['filename'], \"\\n\";\n"
},
{
"answer_id": 39413224,
"author": "Ray Foss",
"author_id": 370238,
"author_profile": "https://Stackoverflow.com/users/370238",
"pm_score": 1,
"selected": false,
"text": "/root/my.folder/my.css ltrim(strrchr($PATH, '.'),'.');\n"
},
{
"answer_id": 40078863,
"author": "Abbas",
"author_id": 2763330,
"author_profile": "https://Stackoverflow.com/users/2763330",
"pm_score": 2,
"selected": false,
"text": "substr($path, strrpos($path,'.')+1);"
},
{
"answer_id": 42184574,
"author": "pooya_sabramooz",
"author_id": 3619526,
"author_profile": "https://Stackoverflow.com/users/3619526",
"pm_score": 3,
"selected": false,
"text": "$info = new SplFileInfo('test.zip');\necho $info->getExtension(); // ----- Output -----> zip\n"
},
{
"answer_id": 51695722,
"author": "Dan Bray",
"author_id": 2452680,
"author_profile": "https://Stackoverflow.com/users/2452680",
"pm_score": 1,
"selected": false,
"text": "function getExt($path)\n{\n $basename = basename($path);\n return substr($basename, strlen(explode('.', $basename)[0]) + 1);\n}\n tar.gz"
},
{
"answer_id": 55399890,
"author": "Fred",
"author_id": 2421121,
"author_profile": "https://Stackoverflow.com/users/2421121",
"pm_score": 0,
"selected": false,
"text": "<?php\n\n$url = 'http://example.com/myfolder/sympony.mp3?a=1&b=2#XYZ';\n$tmp = @parse_url($url)['path'];\n$ext = pathinfo($tmp, PATHINFO_EXTENSION);\n\nvar_dump($ext);\n"
},
{
"answer_id": 55539659,
"author": "Tommy89",
"author_id": 5815685,
"author_profile": "https://Stackoverflow.com/users/5815685",
"pm_score": 2,
"selected": false,
"text": "$ext = explode('.', $filename); // Explode the string\n$my_ext = end($ext); // Get the last entry of the array\n\necho $my_ext;\n"
},
{
"answer_id": 57066213,
"author": "Anjani Barnwal",
"author_id": 7156889,
"author_profile": "https://Stackoverflow.com/users/7156889",
"pm_score": 2,
"selected": false,
"text": "ltrim(strstr($file_url, '.'), '.')\n"
},
{
"answer_id": 57126293,
"author": "Ali Han",
"author_id": 585626,
"author_profile": "https://Stackoverflow.com/users/585626",
"pm_score": 3,
"selected": false,
"text": "$path = \"/home/ali/public_html/wp-content/themes/chicken/css/base.min.css\";\n$name = pathinfo($path, PATHINFO_FILENAME);\n$ext = pathinfo($path, PATHINFO_EXTENSION);\nprintf('<hr> Name: %s <br> Extension: %s', $name, $ext);\n $url = \"//www.example.com/dir/file.bak.php?Something+is+wrong=hello\";\n$url = parse_url($url);\n$name = pathinfo($url['path'], PATHINFO_FILENAME);\n$ext = pathinfo($url['path'], PATHINFO_EXTENSION);\nprintf('<hr> Name: %s <br> Extension: %s', $name, $ext);\n Name: base.min\nExtension: css\n Name: file.bak\nExtension: php\n"
},
{
"answer_id": 57937519,
"author": "Sai Kiran Sangam",
"author_id": 12024442,
"author_profile": "https://Stackoverflow.com/users/12024442",
"pm_score": 2,
"selected": false,
"text": "$ext = preg_replace('/^.*\\.([^.]+)$/D', '$1', $fileName); $ext = substr($fileName, strrpos($fileName, '.') + 1);"
},
{
"answer_id": 61079134,
"author": "dkellner",
"author_id": 1892607,
"author_profile": "https://Stackoverflow.com/users/1892607",
"pm_score": 5,
"selected": false,
"text": "d:/some.thing/myfile /* 387 ns */ function method1($s) {return preg_replace(\"/.*\\./\",\"\",$s);} // edge case problem\n/* 769 ns */ function method2($s) {preg_match(\"/\\.([^\\.]+)$/\",$s,$a);return $a[1];}\n/* 67 ns */ function method3($s) {$n = strrpos($s,\".\"); if($n===false) return \"\";return substr($s,$n+1);}\n/* 175 ns */ function method4($s) {$a = explode(\".\",$s);$n = count($a); if($n==1) return \"\";return $a[$n-1];}\n/* 731 ns */ function method5($s) {return pathinfo($s, PATHINFO_EXTENSION);}\n/* 732 ns */ function method6($s) {return (new SplFileInfo($s))->getExtension();}\n\n// All measured on Linux; it will be vastly different on Windows\n SplFileInfo pathinfo explode() function fileExtension($name) {\n $n = strrpos($name, '.');\n return ($n === false) ? '' : substr($name, $n+1);\n}\n"
},
{
"answer_id": 65613057,
"author": "Ashok Chandrapal",
"author_id": 1642072,
"author_profile": "https://Stackoverflow.com/users/1642072",
"pm_score": 0,
"selected": false,
"text": "<?php\n\n$path = \"URL will be here\";\necho basename(parse_url($path)['path']);\n\n?>\n"
},
{
"answer_id": 71884623,
"author": "RafaSashi",
"author_id": 2456038,
"author_profile": "https://Stackoverflow.com/users/2456038",
"pm_score": 2,
"selected": false,
"text": "pathinfo(parse_url($url,PHP_URL_PATH),PATHINFO_EXTENSION);\n"
},
{
"answer_id": 73551735,
"author": "Brad",
"author_id": 4753391,
"author_profile": "https://Stackoverflow.com/users/4753391",
"pm_score": 3,
"selected": false,
"text": "pathinfo($file, PATHINFO_EXTENSION)\n if (stripos('/here/is/sOme.fiLe.PdF', '.pdf', -4) !== false )\n{\n //its a pdf file\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9951/"
] |
173,870
|
<p>I knew I should never have started using c++ io, the whole "type safety" argument is a red herring (does anyone <em>really</em> find that it's one of their most pressing problems?). Anyhow, I did, and discovered a strange difference between ifstreams and FILE*s and plain old file descriptors: ifstreams cannot read from a device. Can anyone think of a reason why?</p>
<pre><code>const char* path = "/dev/disk3";
char b;
// this works
FILE* f= fopen(path, "rb");
int i = fread(&b, 1, 1, f); // returns 1, success!
// this does not work
ifstream cf(path, ios::binary);
cf.read(&b, 1);
bool good = cf.good(); // returns false, failure.
</code></pre>
|
[
{
"answer_id": 174268,
"author": "Greg Rogers",
"author_id": 5963,
"author_profile": "https://Stackoverflow.com/users/5963",
"pm_score": 2,
"selected": false,
"text": "ios::in"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173870",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22147/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.