qid
int64 4
22.2M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
199,180
|
<p>The only thing I can get python omnicomplete to work with are system modules. I get nothing for help with modules in my site-packages or modules that I'm currently working on.</p>
|
[
{
"answer_id": 200227,
"author": "Simon Peverett",
"author_id": 6063,
"author_profile": "https://Stackoverflow.com/users/6063",
"pm_score": 0,
"selected": false,
"text": " set iskeyword+=.\n"
},
{
"answer_id": 201420,
"author": "Jeremy Cantrell",
"author_id": 18866,
"author_profile": "https://Stackoverflow.com/users/18866",
"pm_score": 3,
"selected": true,
"text": "myvar = 'test'\n\ndef myfunction(foo='test'):\n pass\n\nclass MyClass(object):\n pass\n"
},
{
"answer_id": 851255,
"author": "gotgenes",
"author_id": 38140,
"author_profile": "https://Stackoverflow.com/users/38140",
"pm_score": 2,
"selected": false,
"text": "PYTHONPATH"
},
{
"answer_id": 1104576,
"author": "RobM",
"author_id": 83100,
"author_profile": "https://Stackoverflow.com/users/83100",
"pm_score": 2,
"selected": false,
"text": ":python import {module-name}\n Traceback (most recent call last):\n File \"<string>\", line 1, in ?\n File \"modulename/__init__.py\", line 9\n class empty_paranthesis():\n ^\n SyntaxError: invalid syntax\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1367022/"
] |
199,182
|
<p>I'm working on a program that is form based but I have been asked to add some command line support, this works fine apart from the form flashes up and closes down when running from the command line. Is there anyway to hide the form whilst the command line is running? Some code does refer to controls so the gui would need to be accessible but not visible, is this workable?</p>
|
[
{
"answer_id": 199198,
"author": "benPearce",
"author_id": 4490,
"author_profile": "https://Stackoverflow.com/users/4490",
"pm_score": 2,
"selected": false,
"text": "main = new MainForm();\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
199,184
|
<p>How do I check if a number is a palindrome?</p>
<p>Any language. Any algorithm. (except the algorithm of making the number a string and then reversing the string).</p>
|
[
{
"answer_id": 199218,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 8,
"selected": false,
"text": "n = num;\nrev = 0;\nwhile (num > 0)\n{\n dig = num % 10;\n rev = rev * 10 + dig;\n num = num / 10;\n}\n"
},
{
"answer_id": 199248,
"author": "Mark Ransom",
"author_id": 5987,
"author_profile": "https://Stackoverflow.com/users/5987",
"pm_score": 5,
"selected": false,
"text": "def ReverseNumber(n, partial=0):\n if n == 0:\n return partial\n return ReverseNumber(n // 10, partial * 10 + n % 10)\n\ntrial = 123454321\nif ReverseNumber(trial) == trial:\n print(\"It's a Palindrome!\")\n"
},
{
"answer_id": 199253,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 4,
"selected": false,
"text": "int is_palindrome(unsigned long orig)\n{\n unsigned long reversed = 0, n = orig;\n\n while (n > 0)\n {\n reversed = reversed * 10 + n % 10;\n n /= 10;\n }\n\n return orig == reversed;\n}\n"
},
{
"answer_id": 199323,
"author": "Chris Vest",
"author_id": 13251,
"author_profile": "https://Stackoverflow.com/users/13251",
"pm_score": 2,
"selected": false,
"text": "(defn palindrome? [n]\n (let [len (count n)]\n (and\n (= (first n) (last n))\n (or (>= 1 (count n))\n (palindrome? (. n (substring 1 (dec len))))))))\n\n(defn begoners-palindrome []\n (loop [mx 0\n mxI 0\n mxJ 0\n i 999\n j 990]\n (if (> i 100)\n (let [product (* i j)]\n (if (and (> product mx) (palindrome? (str product)))\n (recur product i j\n (if (> j 100) i (dec i))\n (if (> j 100) (- j 11) 990))\n (recur mx mxI mxJ\n (if (> j 100) i (dec i))\n (if (> j 100) (- j 11) 990))))\n mx)))\n\n(time (prn (begoners-palindrome)))\n"
},
{
"answer_id": 200193,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 3,
"selected": false,
"text": "a = num;\nb = 0;\nif (a % 10 == 0)\n return a == 0;\ndo {\n b = 10 * b + a % 10;\n if (a == b)\n return true;\n a = a / 10;\n} while (a > b);\nreturn a == b;\n"
},
{
"answer_id": 1065046,
"author": "Mark Bolusmjak",
"author_id": 131227,
"author_profile": "https://Stackoverflow.com/users/131227",
"pm_score": 2,
"selected": false,
"text": "(define make-palindrome-tester\n (lambda (base)\n (lambda (n)\n (cond\n ((= 0 (modulo n base)) #f)\n (else\n (letrec\n ((Q (lambda (h t)\n (cond\n ((< h t) #f)\n ((= h t) #t)\n (else\n (let*\n ((h2 (quotient h base))\n (m (- h (* h2 base))))\n (cond\n ((= h2 t) #t)\n (else\n (Q h2 (+ (* base t) m))))))))))\n (Q n 0)))))))\n"
},
{
"answer_id": 6907621,
"author": "eku",
"author_id": 669366,
"author_profile": "https://Stackoverflow.com/users/669366",
"pm_score": 1,
"selected": false,
"text": "num=n\nlastDigit=0;\nrev=0;\nwhile (num>rev) {\n lastDigit=num%10;\n rev=rev*10+lastDigit;\n num /=2;\n}\nif (num==rev) print PALINDROME; exit(0);\nnum=num*10+lastDigit; // This line is required as a number with odd number of bits will necessary end up being smaller even if it is a palindrome\nif (num==rev) print PALINDROME\n"
},
{
"answer_id": 10451733,
"author": "Omu",
"author_id": 112100,
"author_profile": "https://Stackoverflow.com/users/112100",
"pm_score": 1,
"selected": false,
"text": "let reverseNumber n =\n let rec loop acc = function\n |0 -> acc\n |x -> loop (acc * 10 + x % 10) (x/10) \n loop 0 n\n\nlet isPalindrome = function\n | x when x = reverseNumber x -> true\n | _ -> false\n"
},
{
"answer_id": 11367380,
"author": "hughdbrown",
"author_id": 10293,
"author_profile": "https://Stackoverflow.com/users/10293",
"pm_score": 1,
"selected": false,
"text": "def is_palindrome(s):\n return all(s[i] == s[-(i + 1)] for i in range(len(s)//2))\n\ndef number_palindrome(n):\n return is_palindrome(str(n))\n"
},
{
"answer_id": 13333833,
"author": "Colonel Panic",
"author_id": 284795,
"author_profile": "https://Stackoverflow.com/users/284795",
"pm_score": 3,
"selected": false,
"text": "2**10-23"
},
{
"answer_id": 14639970,
"author": "Rock",
"author_id": 1021602,
"author_profile": "https://Stackoverflow.com/users/1021602",
"pm_score": 1,
"selected": false,
"text": "def palindrome(n):\n d = []\n while (n > 0):\n d.append(n % 10)\n n //= 10\n for i in range(len(d)/2):\n if (d[i] != d[-(i+1)]):\n return \"Fail.\"\n return \"Pass.\"\n"
},
{
"answer_id": 14846246,
"author": "vivek",
"author_id": 2067028,
"author_profile": "https://Stackoverflow.com/users/2067028",
"pm_score": 0,
"selected": false,
"text": "reverse = 0;\n remainder = 0;\n count = 0;\n while (number > reverse)\n {\n remainder = number % 10;\n reverse = reverse * 10 + remainder;\n number = number / 10;\n count++;\n }\n Console.WriteLine(count);\n if (reverse == number)\n {\n Console.WriteLine(\"Your number is a palindrome\");\n }\n else\n {\n number = number * 10 + remainder;\n if (reverse == number)\n Console.WriteLine(\"your number is a palindrome\");\n else\n Console.WriteLine(\"your number is not a palindrome\");\n }\n Console.ReadLine();\n}\n}\n"
},
{
"answer_id": 17384143,
"author": "lwm",
"author_id": 1573794,
"author_profile": "https://Stackoverflow.com/users/1573794",
"pm_score": 0,
"selected": false,
"text": "def isPalindromicNum(n):\n \"\"\"\n is 'n' a palindromic number?\n \"\"\"\n ns = list(str(n))\n for n in ns:\n if n != ns.pop():\n return False\n return True\n"
},
{
"answer_id": 17769514,
"author": "BLaaaaaa",
"author_id": 2603562,
"author_profile": "https://Stackoverflow.com/users/2603562",
"pm_score": 0,
"selected": false,
"text": " public class Numbers\n {\n public static void main(int givenNum)\n { \n int n= givenNum\n int rev=0;\n\n while(n>0)\n {\n //To extract the last digit\n int digit=n%10;\n\n //To store it in reverse\n rev=(rev*10)+digit;\n\n //To throw the last digit\n n=n/10;\n }\n\n //To check if a number is palindrome or not\n if(rev==givenNum)\n { \n System.out.println(givenNum+\"is a palindrome \");\n }\n else\n {\n System.out.pritnln(givenNum+\"is not a palindrome\");\n }\n }\n}\n"
},
{
"answer_id": 18480237,
"author": "Jiaji Li",
"author_id": 1021397,
"author_profile": "https://Stackoverflow.com/users/1021397",
"pm_score": 5,
"selected": false,
"text": "boolean isPalindrome(int x) {\n if (x < 0)\n return false;\n int div = 1;\n while (x / div >= 10) {\n div *= 10;\n }\n while (x != 0) {\n int l = x / div;\n int r = x % 10;\n if (l != r)\n return false;\n x = (x % div) / 10;\n div /= 100;\n }\n return true;\n}\n"
},
{
"answer_id": 18858222,
"author": "mario",
"author_id": 2789016,
"author_profile": "https://Stackoverflow.com/users/2789016",
"pm_score": 0,
"selected": false,
"text": "let isPalindrome (n:int) =\n let l1 = n.ToString() |> List.ofSeq |> List.rev\n let rec isPalindromeInt l1 l2 =\n match (l1,l2) with\n | (h1::rest1,h2::rest2) -> if (h1 = h2) then isPalindromeInt rest1 rest2 else false\n | _ -> true\n isPalindromeInt l1 (n.ToString() |> List.ofSeq)\n"
},
{
"answer_id": 19133400,
"author": "MarianG",
"author_id": 2837951,
"author_profile": "https://Stackoverflow.com/users/2837951",
"pm_score": 0,
"selected": false,
"text": "checkPalindrome(int number)\n{\n int lsd, msd,len;\n len = log10(number);\n while(number)\n {\n msd = (number/pow(10,len)); // \"most significant digit\"\n lsd = number%10; // \"least significant digit\"\n if(lsd==msd)\n {\n number/=10; // change of LSD\n number-=msd*pow(10,--len); // change of MSD, due to change of MSD\n len-=1; // due to change in LSD\n } else {return 1;}\n }\n return 0;\n}\n"
},
{
"answer_id": 20134388,
"author": "user1552891",
"author_id": 1552891,
"author_profile": "https://Stackoverflow.com/users/1552891",
"pm_score": 0,
"selected": false,
"text": "def isPalindrome(num):\n size = len(str(num))\n demoninator = 10**(size-1)\n return isPalindromeHelper(num, size, demoninator)\n\ndef isPalindromeHelper(num, size, demoninator):\n \"\"\"wrapper function, used in recursive\"\"\"\n if size <=1:\n return True\n else: \n if num/demoninator != num%10:\n return False\n # shrink the size, num and denominator\n num %= demoninator\n num /= 10\n size -= 2\n demoninator /=100\n return isPalindromeHelper(num, size, demoninator) \n"
},
{
"answer_id": 20743296,
"author": "Ziv Kesten",
"author_id": 2932628,
"author_profile": "https://Stackoverflow.com/users/2932628",
"pm_score": 0,
"selected": false,
"text": "int max =(int)(Math.random()*100001);\n\n int i;\n int num = max; //a var used in the tests\n int size; //the number of digits in the original number\n int opos = 0; // the oposite number\n int nsize = 1;\n\n System.out.println(max);\n\n for(i = 1; num>10; i++)\n {\n num = num/10;\n }\n\n System.out.println(\"this number has \"+i+\" digits\");\n\n size = i; //setting the digit number to a var for later use\n\n\n\n num = max;\n\n for(i=1;i<size;i++)\n {\n nsize *=10;\n }\n\n\n while(num>1)\n {\n opos += (num%10)*nsize;\n num/=10;\n nsize/=10;\n }\n\n System.out.println(\"and the number backwards is \"+opos);\n\n if (opos == max )\n {\n System.out.println(\"palindrome!!\");\n }\n else\n {\n System.out.println(\"aint no palindrome!\");\n }\n"
},
{
"answer_id": 23537470,
"author": "user3615696",
"author_id": 3615696,
"author_profile": "https://Stackoverflow.com/users/3615696",
"pm_score": 0,
"selected": false,
"text": "print('!* To Find Palindrome Number') \n\ndef Palindrome_Number():\n\n n = input('Enter Number to check for palindromee') \n m=n \n a = 0 \n\n while(m!=0): \n a = m % 10 + a * 10 \n m = m / 10 \n\n if( n == a): \n print('%d is a palindrome number' %n)\n else:\n print('%d is not a palindrome number' %n)\n"
},
{
"answer_id": 24017500,
"author": "sort_01out",
"author_id": 3502744,
"author_profile": "https://Stackoverflow.com/users/3502744",
"pm_score": 1,
"selected": false,
"text": "class CheckPalindrome{\npublic static void main(String str[]){\n int a=242, n=a, b=a, rev=0;\n while(n>0){\n a=n%10; n=n/10;rev=rev*10+a;\n System.out.println(a+\" \"+n+\" \"+rev); // to see the logic\n }\n if(rev==b) System.out.println(\"Palindrome\");\n else System.out.println(\"Not Palindrome\");\n }\n}\n"
},
{
"answer_id": 24721631,
"author": "VikramChopde",
"author_id": 3030685,
"author_profile": "https://Stackoverflow.com/users/3030685",
"pm_score": 2,
"selected": false,
"text": "template <typename bidirection_iter>\nbool palindrome(bidirection_iter first, bidirection_iter last)\n{\n while(first != last && first != --last)\n {\n if(::toupper(*first) != ::toupper(*last))\n return false;\n else\n first++;\n }\n return true;\n}\n"
},
{
"answer_id": 26058486,
"author": "Ranjan Manohar",
"author_id": 4083107,
"author_profile": "https://Stackoverflow.com/users/4083107",
"pm_score": 0,
"selected": false,
"text": "class Palindrome_Number{\n void display(int a){\n int count=0;\n int n=a;\n int n1=a;\n while(a>0){\n count++;\n a=a/10;\n }\n double b=0.0d;\n while(n>0){\n b+=(n%10)*(Math.pow(10,count-1));\n count--;\n n=n/10;\n }\n if(b==(double)n1){\n System.out.println(\"Palindrome number\");\n }\n else{\n System.out.println(\"Not a palindrome number\"); \n }\n }\n}\n"
},
{
"answer_id": 27952125,
"author": "Mr. Wonderful",
"author_id": 1538362,
"author_profile": "https://Stackoverflow.com/users/1538362",
"pm_score": 0,
"selected": false,
"text": "public bool IsPalindrome(int num)\n{\n string st = num.ToString();\n char[] arr = st.ToCharArray();\n int len = arr.Length;\n if (len <= 1)\n {\n return false;\n }\n for (int i = 0; i < arr.Length; i++)\n {\n if (arr[i] == arr[len - 1])\n {\n if (i >= len)\n {\n return true;\n }\n len--;\n }\n else\n {\n break;\n }\n }\n return false;\n}\n"
},
{
"answer_id": 28888553,
"author": "0x0",
"author_id": 419074,
"author_profile": "https://Stackoverflow.com/users/419074",
"pm_score": 1,
"selected": false,
"text": "O(n)"
},
{
"answer_id": 29125270,
"author": "user2343020",
"author_id": 2343020,
"author_profile": "https://Stackoverflow.com/users/2343020",
"pm_score": 1,
"selected": false,
"text": "def isPalindrome(number):\n return int(str(number)[::-1])==number\n"
},
{
"answer_id": 30280623,
"author": "NewCoder",
"author_id": 3674483,
"author_profile": "https://Stackoverflow.com/users/3674483",
"pm_score": 1,
"selected": false,
"text": "int reverse(int num)\n{\n assert(num >= 0); // for non-negative integers only.\n int rev = 0;\n while (num != 0)\n {\n rev = rev * 10 + num % 10;\n num /= 10;\n }\n return rev;\n}\n"
},
{
"answer_id": 31959409,
"author": "Thomas Modeneis",
"author_id": 2395283,
"author_profile": "https://Stackoverflow.com/users/2395283",
"pm_score": 2,
"selected": false,
"text": "package main\n\nimport \"fmt\"\n\nfunc main() {\n n := 123454321\n r := reverse(n)\n fmt.Println(r == n)\n}\n\nfunc reverse(n int) int {\n r := 0\n for {\n if n > 0 {\n r = r*10 + n%10\n n = n / 10\n } else {\n break\n }\n }\n return r\n}\n"
},
{
"answer_id": 32895098,
"author": "rassa45",
"author_id": 4871483,
"author_profile": "https://Stackoverflow.com/users/4871483",
"pm_score": 3,
"selected": false,
"text": "def reverse(n):\n newnum=0\n while n>0:\n newnum = newnum*10 + n % 10\n n//=10\n return newnum\n\ndef palindrome(n):\n return n == reverse(n)\n"
},
{
"answer_id": 33229672,
"author": "Flowers",
"author_id": 3082798,
"author_profile": "https://Stackoverflow.com/users/3082798",
"pm_score": 3,
"selected": false,
"text": "bool is_pal(int n) {\n if (n % 10 == 0) return 0;\n int r = 0;\n while (r < n) {\n r = 10 * r + n % 10;\n n /= 10;\n }\n return n == r || n == r / 10;\n}\n"
},
{
"answer_id": 33848890,
"author": "Jhutan Debnath",
"author_id": 4063455,
"author_profile": "https://Stackoverflow.com/users/4063455",
"pm_score": 0,
"selected": false,
"text": "num = int(raw_input())\nlist_num = list(str(num))\nif list_num[::-1] == list_num:\n print \"Its a palindrome\"\nelse:\n print \"Its not a palindrom\"\n"
},
{
"answer_id": 34643247,
"author": "hs2345",
"author_id": 3282123,
"author_profile": "https://Stackoverflow.com/users/3282123",
"pm_score": 0,
"selected": false,
"text": "import java.util.*;\n\npublic class Palin {\n\n public static void main(String[] args) {\n Random randInt = new Random();\n\n Scanner kbd = new Scanner(System.in);\n int t = kbd.nextInt(); //# of test cases;\n String[] arrPalin = new String[t]; //array of inputs;\n String[] nextPalin = new String[t];\n for (int i = 0; i < t; i++) {\n arrPalin[i] = String.valueOf(randInt.nextInt(2147483646) + 1);\n System.out.println(arrPalin[i]);\n }\n\n final long startTime = System.nanoTime();\n\n for (int i = 0; i < t; i++) {\n nextPalin[i] = (unmatcher(incrementer(switcher(match(arrPalin[i])))));\n }\n\n final long duration = System.nanoTime() - startTime;\n\n for (int i = 0; i < t; i++) {\n System.out.println(nextPalin[i]);\n }\n\n System.out.println(duration);\n\n }\n\n public static String match(String N) {\n int length = N.length();\n\n //Initialize a string with length of N\n char[] chars = new char[length];\n Arrays.fill(chars, '0');\n\n int count = 1;\n\n for (int i = 0; i < length; i++) {\n if ((i%2) == 0) { //at i = even.\n if (i == 0) {\n chars[i] = N.charAt(i);\n } else\n chars[i] = N.charAt(i/2);\n } else //at i = odd\n chars[i] = N.charAt(length - count);\n count++;\n }\n\n return String.valueOf(chars);\n }\n\n public static String switcher(String N) {\n int length = N.length();\n char[] chars = new char[length];\n Arrays.fill(chars, '0');\n\n for (int i = 0; i < length; i++) {\n if (i != 0) {\n if ((i % 2) == 0) {\n chars[i] = N.charAt(i);\n } else if ((i % 2) != 0) {\n chars[i] = N.charAt(i - 1);\n }\n }\n if (i == 0) {\n chars[0] = N.charAt(0);\n }\n }\n return String.valueOf(chars);\n }\n\n public static String incrementer(String N) {\n int length = N.length();\n char[] chars = new char[length];\n Arrays.fill(chars, '0');\n\n char[] newN = N.toCharArray();\n\n String returnVal;\n\n int numOne, numTwo;\n\n if ((length % 2) == 0) {\n numOne = N.charAt(length-1);\n numTwo = N.charAt(length-2);\n newN[length-1] = (char)(numOne+1);\n newN[length-2] = (char)(numTwo+1);\n returnVal = String.valueOf(newN);\n } else {\n numOne = N.charAt(length-1);\n newN[length-1] = (char)(numOne+1);\n returnVal = String.valueOf(newN);\n }\n return returnVal;\n }\n\n public static String unmatcher(String N) {\n int length = N.length();\n char[] chars = new char[length];\n Arrays.fill(chars, '0');\n char[] newN = N.toCharArray();\n\n for (int i = 0; i < length; i++) {\n if (((i % 2) == 0) && (i != 0)) { // for i > 0, even\n newN[i / 2] = N.charAt(i);\n } else if ((i % 2) == 0 && (i == 0)) { // for i = 0\n newN[0] = N.charAt(0);\n }\n }\n for (int i = (length/2); i < length; i++) {\n newN[i] = newN[Math.abs(i - (length - 1))];\n }\n\n return String.valueOf(newN);\n }\n\n\n}\n"
},
{
"answer_id": 34669500,
"author": "Pong Petrung",
"author_id": 5366710,
"author_profile": "https://Stackoverflow.com/users/5366710",
"pm_score": 0,
"selected": false,
"text": "public class PalindromePrime {\n private static int g ,n =0,i,m ; \n \n private javax.swing.JTextField jTextField;\n \n\n static String b =\"\";\n private static Scanner scanner = new Scanner( System.in ); \n public static void main(String [] args) throws IOException {\n System.out.print(\" Please Inter Data : \"); \n g = scanner.nextInt();\n \n System.out.print(\" Please Inter Data 2 : \"); \n m = scanner.nextInt(); \n \n count(g,m); \n } \n\n public static int count(int L, int R) {\n int resultNum = 0;\n \n for( i= L ; i<= R ;i++){\n int count= 0 ;\n for( n = i ; n >=1 ;n -- ){\n if(i%n==0){ \n count = count + 1 ;\n // System.out.println(\" Data : \\n \" +count ); \n } \n }\n if(count == 2)\n { \n //b = b +i + \"\" ;\n \n String ss= String .valueOf(i);\n // System.out.print(\"\\n\" +i );\n if(isPalindrome(i))\n {\n //0 System.out.println(\"Number : \" + i + \" is a palindrome\");\n \n //number2[b] = Integer.parseInt(number_ayy[b]);\n \n //String s = String .valueOf(i);\n //System.out.printf(\"123456\", s);\n resultNum++;\n }\n else{\n //*System.out.println(\"Number : \" + i + \" is Not a palindrome\");\n }\n //System.out.println(\" Data : \\n \" +ss.length() ); \n }\n // palindrome(i);\n }\n \n // System.out.print(\" Data : \"); \n // System.out.println(\" Data : \\n \" +b ); \n return resultNum;\n }\n \n @SuppressWarnings(\"unused\")\n public static boolean isPalindrome(int number ) {\n int p = number; // ประกาศ p เป็น int ให้เท่ากับ number ของ ตัวที่ มาจาก method \n int r = 0; //ประกาศ r เป็น int โดยให้มีค่าเรื่องต้นเท่ากับ 0 \n int w = 0 ;\n while (p != 0) { // เงื่อนไข While ถ้า p ไม่เท่ากับ 0 เช่น 2!= 0 จริง เข้า \n w = p % 10; // ประกาศตัว แปร W ให้ เท่ากับค่า p ที่มาจาก parramiter ให้ & mod กับ 10 คือ เช่น 2 % 10 = 2 ; w= 2 ; 3% 10 ; w =3\n r = r * 10 + w; // (ให้ R ที่มาจาก การประกาศค่ตัวแปร แล้ว * 10) + w จะมาจากค่า w = p % 10; ที่ mod ไว้ เช่น 0*10 + 2 = 2 \n p = p / 10; //แล้วใช้ p ที่จมาจากตัว paramiter แล้วมาหาร 10 เพราะถ้าไม่มี ก็จะสามารถพิมพ์ค่าออกมาได้ || ทำไงก็ได้ให้เป็น 0 และเอามาแทนค่ตัวต่อไป \n }\n\n // 1 วนวูปเช็คว่า (p != 0) หรือไม่ โดย p มาจาก p = number ที่รับมา \n // 2 r = (r * 10) + (p%10) ; \n \n //3 p = p /10 ; เพื่อเช็ค ว่าให้มันเป็น 0 เพื่อหลุด Loop \n if (number == r) {\n // for(int count = 0 ; count <i ;count ++){\n String s1 = String.valueOf(i); \n \n //countLines(s1);\n System.out.println(\"Number : \" + \"'\"+s1 +\"'\"+\" is a palindrome\");\n\n return true; //เรียก return ไป \n }\n return false;\n }\n \n public static int countLines(String str)\n {\n if (str == null || str.length() == 0)\n return 0;\n int lines = 1;\n int len = str.length();\n for( int pos = 0; pos < len; pos++) {\n char c = str.charAt(pos);\n if( c == '\\r' ) {\n System.out.println(\"Line 0 : \" + \"'\"+str );\n \n lines++;\n if ( pos+1 < len && str.charAt(pos+1) == '\\n' )\n \n System.out.println(\"Line : \" + \"'\"+str );\n \n pos++;\n } else if( c == '\\n' ) {\n lines++;\n \n System.out.println(\"Line 2 : \" + \"'\"+str );\n }\n }\n return lines;\n }\n \n public static int countLines1(String sd) throws IOException {\n LineNumberReader lineNumberReader = new LineNumberReader(new StringReader(sd));\n int count = 0 ;\n System.out.printf(\"Line : \" , count = count + 1 );\n lineNumberReader.skip(Long.MAX_VALUE);\n return lineNumberReader.getLineNumber();\n }\n}\n"
},
{
"answer_id": 35294336,
"author": "gadolf",
"author_id": 5889767,
"author_profile": "https://Stackoverflow.com/users/5889767",
"pm_score": 0,
"selected": false,
"text": "public static void main(String args[])\n{\n System.out.print(\"Enter a number: \");\n Scanner input = new Scanner(System.in);\n int num = input.nextInt();\n int number = num;\n int reversenum = 0;\n while (num != 0)\n {\n reversenum = reversenum * 10;\n reversenum = reversenum + num % 10;\n num = num / 10;\n }\n\n if (number == reversenum)\n System.out.println(\"The reverse number is \" + reversenum + \"\\nThen the number is palindrome.\");\n else\n System.out.println(\"The reverse number is \" + reversenum + \"\\nThen the number is not palindrome.\");\n\n}\n"
},
{
"answer_id": 35735839,
"author": "dre-hh",
"author_id": 1035375,
"author_profile": "https://Stackoverflow.com/users/1035375",
"pm_score": 2,
"selected": false,
"text": "def palindrome?(x, a=x, b=0)\n return x==b if a<1\n palindrome?(x, a/10, b*10 + a%10)\nend\n\npalindrome?(55655)\n"
},
{
"answer_id": 35989648,
"author": "Ankur Tewari",
"author_id": 6060901,
"author_profile": "https://Stackoverflow.com/users/6060901",
"pm_score": 0,
"selected": false,
"text": "static int pallindrome=41012;\nstatic String pallindromer=(Integer.toString(pallindrome));\nstatic int length=pallindromer.length();\n\npublic static void main(String[] args) {\n pallindrome(0);\n System.out.println(\"It's a pallindrome\");\n}\n\nstatic void pallindrome(int index){\n if(pallindromer.charAt(index)==pallindromer.charAt(length-(index+1))){\n if(index<length-1){\n pallindrome(++index);\n }\n }\n else{\n System.out.println(\"Not a pallindrome\");\n System.exit(0);\n }\n}\n"
},
{
"answer_id": 36189241,
"author": "Debosmit Ray",
"author_id": 1692706,
"author_profile": "https://Stackoverflow.com/users/1692706",
"pm_score": 3,
"selected": false,
"text": "(12321 % 10000)/10 = (2321)/10 = 232"
},
{
"answer_id": 38561398,
"author": "Pradip Das",
"author_id": 2230891,
"author_profile": "https://Stackoverflow.com/users/2230891",
"pm_score": -1,
"selected": false,
"text": "def isPalindrome(number):\n return True if str(number) == ''.join(reversed(str(number))) else False\n"
},
{
"answer_id": 39803062,
"author": "hafiz031",
"author_id": 6907424,
"author_profile": "https://Stackoverflow.com/users/6907424",
"pm_score": 0,
"selected": false,
"text": "#include<bits/stdc++.h>\nusing namespace std;\nvector<int>digits;\nstack<int>digitsRev;\nint d,number;\nbool isPal=1;//initially assuming the number is palindrome\nint main()\n{\n cin>>number;\n if(number<10)//if it is a single digit number than it is palindrome\n {\n cout<<\"PALINDROME\"<<endl;\n return 0;\n }\n //if the number is greater than or equal to 10\n while(1)\n {\n d=number%10;//taking each digit\n number=number/10;\n //vector and stack will pick the digits\n //in reverse order to each other\n digits.push_back(d);\n digitsRev.push(d);\n if(number==0)break;\n }\n int index=0;\n while(!digitsRev.empty())\n {\n //Checking each element of the vector and the stack\n //to see if there is any inequality.\n //And which is equivalent to check each digit of the main\n //number from both sides\n if(digitsRev.top()!=digits[index++])\n {\n cout<<\"NOT PALINDROME\"<<endl;\n isPal=0;\n break;\n }\n digitsRev.pop();\n }\n //If the digits are equal from both sides than the number is palindrome\n if(isPal==1)cout<<\"PALINDROME\"<<endl;\n}\n"
},
{
"answer_id": 40076395,
"author": "Abdou Amari",
"author_id": 4629358,
"author_profile": "https://Stackoverflow.com/users/4629358",
"pm_score": 0,
"selected": false,
"text": "private static boolean ispalidrome(long n) {\n return getrev(n, 0L) == n;\n }\n\n private static long getrev(long n, long initvalue) {\n if (n <= 0) {\n return initvalue;\n }\n initvalue = (initvalue * 10) + (n % 10);\n return getrev(n / 10, initvalue);\n }\n"
},
{
"answer_id": 41691705,
"author": "huseyin",
"author_id": 4253424,
"author_profile": "https://Stackoverflow.com/users/4253424",
"pm_score": 0,
"selected": false,
"text": "public static boolean isPalindrome(int x) {\n if (x < 0) return false;\n if (x < 10) return true;\n\n int numDigits = (int)(Math.log10(x)+1);\n int divider = (int) (Math.pow(10, numDigits - 1));\n for (int i = 0; i < numDigits / 2; i++) {\n if (x / divider != x % 10)\n return false;\n x = (x % divider) / 10;\n divider /= 100;\n }\n return true;\n }\n"
},
{
"answer_id": 41729999,
"author": "Shaun L",
"author_id": 6184474,
"author_profile": "https://Stackoverflow.com/users/6184474",
"pm_score": -1,
"selected": false,
"text": "// Checks if our string is palindromic.\nvar ourString = \"A Man, /.,.()^&*A Plan, A Canal__-Panama!\";\nisPalin(ourString);\n\nfunction isPalin(string) {\n// Make all lower case for case insensitivity and replace all spaces, underscores and non-words.\nstring = string.toLowerCase().replace(/\\s+/g, \"\").replace(/\\W/g,\"\").replace(/_/g,\"\");\nfor(i=0; i<=Math.floor(string.length/2-1); i++) {\n if(string[i] !== string[string.length-1-i]) {\n console.log(\"Your string is not palindromic!\");\n break;\n } else if(i === Math.floor(string.length/2-1)) {\n console.log(\"Your string is palindromic!\");\n }\n }\n}\n"
},
{
"answer_id": 41903244,
"author": "Panduka",
"author_id": 7310820,
"author_profile": "https://Stackoverflow.com/users/7310820",
"pm_score": -1,
"selected": false,
"text": " /*Palindrome number*/\n String sNumber = \"12321\";\n int l = sNumber.length(); // getting the length of sNumber. In this case its 5\n boolean flag = true;\n for (int i = 0; i <= l; ++i) {\n if (sNumber.charAt(i) != sNumber.charAt((l--) -1)) { //comparing the first and the last values of the string\n System.out.println(sNumber +\" is not a palindrome number\");\n flag = false;\n break;\n }\n //l--; // to reducing the length value by 1 \n }\n if (flag) {\n System.out.println(sNumber +\" is a palindrome number\");\n }\n"
},
{
"answer_id": 41909264,
"author": "P_P",
"author_id": 1673752,
"author_profile": "https://Stackoverflow.com/users/1673752",
"pm_score": -1,
"selected": false,
"text": "n = 332\nq = n / 10 = 33\nr = n - 10 * q = 2\nr > 0\nr != q\nn = q = 33\nn > r\nq = n / 10 = 3\nr -= q = 4294967295\nr *= 10 = 4294967286\nr += n = 23\nr != n\nr != q\nn = q = 3\nn > r ? No, so 332 isn't a palindromic number.\n"
},
{
"answer_id": 52864276,
"author": "Adnan Aftab",
"author_id": 718721,
"author_profile": "https://Stackoverflow.com/users/718721",
"pm_score": 0,
"selected": false,
"text": "func isPalindrom(_ input: Int) -> Bool {\n if input < 0 {\n return false\n }\n\n if input < 10 {\n return true\n }\n\n var num = input\n let length = Int(log10(Float(input))) + 1\n var i = length\n\n while i > 0 && num > 0 {\n\n let ithDigit = (input / Int(pow(10.0, Double(i) - 1.0)) ) % 10\n let r = Int(num % 10)\n\n if ithDigit != r {\n return false\n }\n\n num = num / 10\n i -= 1\n }\n\n return true\n }\n"
},
{
"answer_id": 55203523,
"author": "SuL",
"author_id": 8115833,
"author_profile": "https://Stackoverflow.com/users/8115833",
"pm_score": 0,
"selected": false,
"text": "public static boolean isPalindrome(int x) {\n int newX = x;\n int newNum = 0;\n boolean result = false;\n if (x >= 0) {\n while (newX >= 10) {\n newNum = newNum+newX % 10;\n newNum = newNum * 10;\n newX = newX / 10;\n }\n newNum += newX;\n\n if(newNum==x) {\n result = true;\n }\n else {\n result=false;\n }\n }\n\n else {\n\n result = false;\n }\n return result;\n }\n"
},
{
"answer_id": 55501410,
"author": "Chris Michael",
"author_id": 7246174,
"author_profile": "https://Stackoverflow.com/users/7246174",
"pm_score": -1,
"selected": false,
"text": " public static boolean isPal(String ss){\n StringBuilder stringBuilder = new StringBuilder(ss);\n stringBuilder.reverse();\n return ss.equals(stringBuilder.toString());\n }\n"
},
{
"answer_id": 66041536,
"author": "Yuvaraj Ram",
"author_id": 7174493,
"author_profile": "https://Stackoverflow.com/users/7174493",
"pm_score": 0,
"selected": false,
"text": "public boolean isPalindrome(int x) {\n if (isNegative(x))\n return false;\n\n boolean isPalindrome = reverseNumber(x) == x ? true : false;\n return isPalindrome;\n }\n\n private boolean isNegative(int x) {\n if (x < 0)\n return true;\n return false;\n }\n\n public int reverseNumber(int x) {\n\n int reverseNumber = 0;\n\n while (x > 0) {\n int remainder = x % 10;\n reverseNumber = reverseNumber * 10 + remainder;\n x = x / 10;\n }\n\n return reverseNumber;\n }\n"
},
{
"answer_id": 69873779,
"author": "Rauf",
"author_id": 5704551,
"author_profile": "https://Stackoverflow.com/users/5704551",
"pm_score": -1,
"selected": false,
"text": "var palindromCheck(nums) = () => {\n let str = x.toString()\n // + before str is quick syntax to cast String To Number.\n return nums === +str.split(\"\").reverse().join(\"\") \n}\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781/"
] |
199,219
|
<p>Im getting frustrated because of OpenDNS and other services (ie: roadrunner) that now always returns a ping even if you type any invalid url ie: lkjsdaflkjdsjf.com --- I had created software for my own use that would ping a url to verify if the site was up or not. This no longer works. Does anyone have any ideas about this?</p>
<p>Requirements:</p>
<ol>
<li>It should work with any valid web site, even ones i dont control</li>
<li>It should be able to run from any network that has internet access</li>
</ol>
<p>I would greatly appreciate to hear how others now handle this. I would like to add, im attempting to do this using System.Net in c#</p>
<p>Thank you greatly :-)</p>
<p>New addition: Looking for a solution that i can either buy and run on my windows machine, or program in c#. :-)</p>
<p><strong>Update:</strong></p>
<p>Thank you all very much for your answers. Ultimately i ended up creating a solution by doing this:</p>
<ol>
<li>Creating a simple webclient that downloaed the specified page from the url (may change to just headers or use this to notify of page changes)</li>
<li>Read in xml file that simply lists the full url to the site/pages to check</li>
<li>Created a windows service to host the solution so it would recover server restarts.</li>
<li>On error an email and text message is sent to defined list of recipients</li>
<li>Most values (interval, smtp, to, from, etc) are defined in the .config for easy change</li>
</ol>
<p>I will be taking some of your advice to add 'features' to this later, which includes:</p>
<ul>
<li>AJAX page for real-time monitoring. I will use WCF to connect to the existing windows service from the asp.net page</li>
<li>Download Headers only (with option for page change comparison)</li>
<li>make more configurable (ie: retries on failure before notification)</li>
</ul>
|
[
{
"answer_id": 199254,
"author": "IAmCodeMonkey",
"author_id": 27613,
"author_profile": "https://Stackoverflow.com/users/27613",
"pm_score": 3,
"selected": true,
"text": "<html>\n <head>\n <script language=\"javascript\" type=\"text/javascript\">\n <!--\n var ajax = new XMLHttpRequest();\n\n function pingSite() {\n ajax.onreadystatechange = stateChanged;\n ajax.open('GET', document.getElementById('siteToCheck').value, true);\n ajax.send(null);\n }\n\n function stateChanged() {\n if (ajax.readyState == 4) {\n if (ajax.status == 200) {\n document.getElementById('statusLabel').innerHTML = \"Success!\";\n }\n else {\n document.getElementById('statusLabel').innerHTML = \"Failure!\";\n }\n }\n }\n -->\n </script>\n </head>\n\n <body>\n Site To Check:<br />\n <input type=\"text\" id=\"siteToCheck\" /><input type=\"button\" onclick=\"javascript:pingSite()\" />\n\n <p>\n <span id=\"statusLabel\"></span>\n </p>\n </body>\n"
},
{
"answer_id": 199376,
"author": "jj33",
"author_id": 430,
"author_profile": "https://Stackoverflow.com/users/430",
"pm_score": 0,
"selected": false,
"text": "zone \"com\" { type delegation-only; };\nzone \"net\" { type delegation-only; };\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26685/"
] |
199,235
|
<p>I am using Oracle adapter from the BizTalk Adapter Pack (WCF based for BTS 2006 R2). In the configuration of the "solicit-response" send ports, I have used Oracle's username and password to connect to the database. </p>
<p>Now I would like to change that and use the SSO. So far I have created the Affiliate application and mapped the BTS Host Instance "user id" to the Oracle database user details.</p>
<p>When I run the application I am constantly getting the error: "Unable to redeem ticket, no ticket exists in the message".</p>
<p>reading through the BTS documentation I found the following at "ms-help://MS.BTS.2006/BTS06CoreDocs/html/c7bf755c-c37d-4b19-9817-a7f42e1e9656.htm":
In scenarios where an orchestration invokes the send adapter, the BizTalk Messaging Engine sends the message to the MessageBox database. The orchestration should ensure that both the <strong>SSOTicket</strong> context property and the <strong>Microsoft.BizTalk.XLANGs.BTXEngine.OriginatorSID</strong> context property of the message that contains the ticket are maintained. When the adapter receives this message from the MessageBox database, the adapter calls the RedeemTicket method with the encrypted ticket to retrieve the back-end credentials from the SSO store. The user designing the orchestration should specifically copy this property to the message.</p>
<p>But I receive a message through SQL integrated connection, that doesn't have the SSO Ticket.</p>
<p>Please help to resolve this issue?</p>
|
[
{
"answer_id": 2384200,
"author": "Sam",
"author_id": 47636,
"author_profile": "https://Stackoverflow.com/users/47636",
"pm_score": 2,
"selected": false,
"text": " public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)\n {\n ISSOTicket ssoTicket = new ISSOTicket();\n pInMsg.Context.Write(\"SSOTicket\", \"http://schemas.microsoft.com/BizTalk/2003/system-properties\", ssoTicket.IssueTicket(0));\n return pInMsg;\n }\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199235",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
199,238
|
<p>I'm writing a lightweight XML editor, and in cases where the user's input is not well formed, I would like to indicate to the user where the problem is, or at least where the first problem is. Does anyone know of an existing algorithm for this? If looking at code helps, if I could fill in the FindIndexOfInvalidXml method (or something like it), this would answer my question.</p>
<pre><code>using System;
namespace TempConsoleApp
{
class Program
{
static void Main(string[] args)
{
string text = "<?xml version=\"1.0\"?><tag1><tag2>Some text.</taagg2></tag1>";
int index = FindIndexOfInvalidXml(text);
Console.WriteLine(index);
}
private static int FindIndexOfInvalidXml(string theString)
{
int index = -1;
//Some logic
return index;
}
}
}
</code></pre>
|
[
{
"answer_id": 199332,
"author": "Pseudo Masochist",
"author_id": 8529,
"author_profile": "https://Stackoverflow.com/users/8529",
"pm_score": 4,
"selected": true,
"text": "string s = \"<?xml version=\\\"1.0\\\"?><tag1><tag2>Some text.</taagg2></tag1>\";\nSystem.Xml.XmlDocument doc = new System.Xml.XmlDocument();\n\ntry\n{\n doc.LoadXml(s);\n}\ncatch(System.Xml.XmlException ex)\n{\n MessageBox.Show(ex.LineNumber.ToString());\n MessageBox.Show(ex.LinePosition.ToString());\n}\n"
},
{
"answer_id": 199339,
"author": "Jared",
"author_id": 1980,
"author_profile": "https://Stackoverflow.com/users/1980",
"pm_score": 0,
"selected": false,
"text": "public bool isValidXml(string xml)\n{\n System.Xml.XmlDocument xDoc = null;\n bool valid = false;\n try\n {\n xDoc = new System.Xml.XmlDocument();\n xDoc.loadXml(xmlString);\n valid = true;\n }\n catch\n {\n // trap for errors\n }\n return valid;\n}\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199238",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27109/"
] |
199,241
|
<p>How can i generate bytecode (Byte[]) from a String at runtime, without using a "javac" process or something of this sort? is there a simple way of calling the compiler like that?</p>
<p>later addition:</p>
<p>I chose to <a href="https://stackoverflow.com/questions/200833/when-should-i-accept-an-answer">accept the solution that actually best fits <strong>my</strong> situation</a>. my application is a hobby-project still in design sketch phase, and it is the right time to consider inserting new technology. also, since the guy that's supposed to help me with BL is a JavaScript developer, the idea of using a JavaScript interpreter instead of a stub compiler+classLoader seems more appealing to me in this situation. other (unaccepted) answers of this question are informative and, as far as i can tell, answer my question very well, so thanks, but I'm going to try <a href="http://www.mozilla.org/rhino/" rel="nofollow noreferrer">Rhino</a> :)</p>
|
[
{
"answer_id": 199314,
"author": "William",
"author_id": 9193,
"author_profile": "https://Stackoverflow.com/users/9193",
"pm_score": 0,
"selected": false,
"text": "eval()"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11813/"
] |
199,252
|
<p>I'm considering the best way to design a permissions system for an "admin" web application. The application is likely to have many users, each of whom could be assigned a certain role; some of these users could be permitted to perform specific tasks outside the role.</p>
<p>I can think of two ways to design this: one, with a "permissions" table with a row for every user, and boolean columns, one for each task, that assign them permissions to perform those tasks. Like this:</p>
<pre>
User ID Manage Users Manage Products Manage Promotions Manage Orders
1 true true true true
2 false true true true
3 false false false true
</pre>
<p>Another way I thought of was to use a bit mask to store these user permissions. This would limit the number of tasks that could be managed to 31 for a 32-bit signed integer, but in practice we're unlikely to have more than 31 specific tasks that a user could perform. This way, the database schema would be simpler, and we wouldn't have to change the table structure every time we added a new task that would need access control. Like this: </p>
<pre>
User ID Permissions (8-bit mask), would be ints in table
1 00001111
2 00000111
3 00000001
</pre>
<p>What mechanisms have people here typically used, and why?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 199272,
"author": "Dimitry",
"author_id": 27073,
"author_profile": "https://Stackoverflow.com/users/27073",
"pm_score": 0,
"selected": false,
"text": "create table permissions (\n user_id INT NOT Null,\n permission VARCHAR(255) NOT NULL,\n value TINYINT(1) NULL\n)\nalter table `permissions` ADD PRIMARY KEY ( `user_id` , `permission` ) \n"
},
{
"answer_id": 199287,
"author": "stephenbayer",
"author_id": 18893,
"author_profile": "https://Stackoverflow.com/users/18893",
"pm_score": 5,
"selected": false,
"text": "UserID | Permission\n===================\n1 | 1 1 representing manage users\n1 | 2 2 being manger products\n2 | 3 \n"
},
{
"answer_id": 199450,
"author": "Chad Braun-Duin",
"author_id": 5458,
"author_profile": "https://Stackoverflow.com/users/5458",
"pm_score": 3,
"selected": false,
"text": "create table Users (\n id int identity not null,\n loginId varchar(30) not null,\n firstName varchar(50) not null,\n etc...\n)\n\ncreate table Roles (\n id int not null,\n name varchar(50) not null\n)\n\ncreate table UserRoles (\n userId int not null,\n roleId int not null\n)\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27649/"
] |
199,260
|
<p>Recently, someone asked about an <a href="https://stackoverflow.com/questions/198199/how-do-you-reverse-a-string-in-place-in-c-or-c">algorithm for reversing a string in place in C</a>. Most of the proposed solutions had troubles when dealing with non single-byte strings. So, I was wondering what could be a good algorithm for dealing specifically with utf-8 strings.</p>
<p>I came up with some code, which I'm posting as an answer, but I'd be glad to see other people's ideas or suggestions. I preferred to use actual code, so I've chosen C#, as it seems to be one of the most popular language in this site, but I don't mind if your code is in another language, as long as it could be reasonably understood by anyone who is familiar with an imperative language. And, as this is intended to see how such an algorithm could be implemented at a low-level (by low-level I just mean dealing with bytes), the idea is to avoid using libraries for the core code.</p>
<p><strong>Notes:</strong></p>
<p>I'm interested in the algorithm itself, its performance and how could it be optimized (I mean algorithm-level optimization, not replacing i++ with ++i and such; I'm not really interested in actual benchmarks either).</p>
<p>I don't mean to actually use it in production code or "reinventing the wheel". This is just out of curiosity and as an exercise.</p>
<p>I'm using C# byte arrays so I'm assuming you can get the length of the string without running though the string until you find a NUL.
That is, I'm not accounting for the complexity of finding the length of the string. But if you're using C, for instance, you could factor that out by using strlen() before calling the core code. </p>
<p><strong>Edit:</strong></p>
<p>As Mike F points out, my code (and other people's code posted here) is not dealing with composite characters. Some info about those <a href="http://www.unicode.org/faq/char_combmark.html" rel="nofollow noreferrer">here</a>. I'm not familiar with the concept, but if that means that there are "combining characters", i.e., characters / code points that are only valid in combination with other "base" characters / code points, a look-up table of such characters could be used to preserve the order of the "global" character ("base" + "combining" characters) when reversing.</p>
|
[
{
"answer_id": 199280,
"author": "Juan Pablo Califano",
"author_id": 24170,
"author_profile": "https://Stackoverflow.com/users/24170",
"pm_score": 3,
"selected": false,
"text": "class UTF8Utils {\n\n\n public static void Reverse(byte[] str) {\n int len = str.Length;\n int i = 0;\n int j = len - 1;\n\n // first, check if the string is \"synced\", i.e., it starts\n // with a valid leading character. Will check for illegal \n // sequences thru the whole string later.\n byte leadChar = str[0];\n\n // if it starts with 10xx xxx, it's a trailing char...\n // if it starts with 1111 10xx or 1111 110x \n // it's out of the 4 bytes range.\n // EDIT: added validation for 7 bytes seq and 0xff\n if( (leadChar & 0xc0) == 0x80 ||\n (leadChar & 0xfc) == 0xf8 ||\n (leadChar & 0xfe) == 0xfc ||\n (leadChar & 0xff) == 0xfe ||\n leadChar == 0xff) {\n\n throw new Exception(\"Illegal UTF-8 sequence\");\n\n }\n\n // reverse bytes in-place naïvely\n while(i < j) {\n byte tmp = str[i];\n str[i] = str[j];\n str[j] = tmp;\n i++;\n j--;\n }\n // now, run the string again to fix the multibyte sequences\n UTF8Utils.ReverseMbSequences(str);\n\n }\n\n private static void ReverseMbSequences(byte[] str) {\n int i = str.Length - 1;\n byte leadChar = 0;\n int nBytes = 0;\n\n // loop backwards thru the reversed buffer\n while(i >= 0) {\n // since the first byte in the unreversed buffer is assumed to be\n // the leading char of that byte, it seems safe to assume that the \n // last byte is now the leading char. (Given that the string is\n // not out of sync -- we checked that out already)\n leadChar = str[i];\n\n // check how many bytes this sequence takes and validate against\n // illegal sequences\n if(leadChar < 0x80) {\n nBytes = 1;\n } else if((leadChar & 0xe0) == 0xc0) {\n if((str[i-1] & 0xc0) != 0x80) {\n throw new Exception(\"Illegal UTF-8 sequence\");\n }\n nBytes = 2;\n } else if ((leadChar & 0xf0) == 0xe0) {\n if((str[i-1] & 0xc0) != 0x80 ||\n (str[i-2] & 0xc0) != 0x80 ) {\n throw new Exception(\"Illegal UTF-8 sequence\");\n }\n nBytes = 3;\n } else if ((leadChar & 0xf8) == 0xf0) {\n if((str[i-1] & 0xc0) != 0x80 ||\n (str[i-2] & 0xc0) != 0x80 ||\n (str[i-3] & 0xc0) != 0x80 ) {\n throw new Exception(\"Illegal UTF-8 sequence\");\n }\n nBytes = 4;\n } else {\n throw new Exception(\"Illegal UTF-8 sequence\");\n }\n\n // now, reverse the current sequence and then continue\n // whith the next one\n int back = i;\n int front = back - nBytes + 1;\n\n while(front < back) {\n byte tmp = str[front];\n str[front] = str[back];\n str[back] = tmp;\n front++;\n back--;\n }\n i -= nBytes;\n }\n }\n} \n"
},
{
"answer_id": 199394,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "void reverse( char *start, char *end )\n{\n while( start < end )\n {\n char c = *start;\n *start++ = *end;\n *end-- = c;\n }\n}\n\nchar *reverse_char( char *start )\n{\n char *end = start;\n while( (end[1] & 0xC0) == 0x80 ) end++;\n reverse( start, end );\n return( end+1 );\n}\n\nvoid reverse_string( char *string )\n{\n char *end = string;\n while( *end ) end = reverse_char( end );\n reverse( string, end-1 );\n}\n"
},
{
"answer_id": 199453,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 3,
"selected": false,
"text": "#include \"string.h\"\n\nvoid utf8rev(char *str)\n{\n /* this assumes that str is valid UTF-8 */\n char *scanl, *scanr, *scanr2, c;\n\n /* first reverse the string */\n for (scanl= str, scanr= str + strlen(str); scanl < scanr;)\n c= *scanl, *scanl++= *--scanr, *scanr= c;\n\n /* then scan all bytes and reverse each multibyte character */\n for (scanl= scanr= str; c= *scanr++;) {\n if ( (c & 0x80) == 0) // ASCII char\n scanl= scanr;\n else if ( (c & 0xc0) == 0xc0 ) { // start of multibyte\n scanr2= scanr;\n switch (scanr - scanl) {\n case 4: c= *scanl, *scanl++= *--scanr, *scanr= c; // fallthrough\n case 3: // fallthrough\n case 2: c= *scanl, *scanl++= *--scanr, *scanr= c;\n }\n scanr= scanl= scanr2;\n }\n }\n}\n\n// quick and dirty main for testing purposes\n#include \"stdio.h\"\n\nint main(int argc, char* argv[])\n{\n char buffer[256];\n buffer[sizeof(buffer)-1]= '\\0';\n\n while (--argc > 0) {\n strncpy(buffer, argv[argc], sizeof(buffer)-1); // don't overwrite final null\n printf(\"%s → \", buffer);\n utf8rev(buffer);\n printf(\"%s\\n\", buffer);\n }\n return 0;\n}\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24170/"
] |
199,266
|
<p>How can I make xargs execute the command exactly once for each line of input given?
It's default behavior is to chunk the lines and execute the command once, passing multiple lines to each instance. </p>
<blockquote>
<p>From <a href="http://en.wikipedia.org/wiki/Xargs" rel="noreferrer">http://en.wikipedia.org/wiki/Xargs</a>: </p>
<p>find /path -type f -print0 | xargs -0 rm</p>
<p>In this example, find feeds the input of xargs with a long list of file names. xargs then splits this list into sublists and calls rm once for every sublist. This is more efficient than this functionally equivalent version:</p>
<p>find /path -type f -exec rm '{}' \;</p>
</blockquote>
<p>I know that find has the "exec" flag. I am just quoting an illustrative example from another resource.</p>
|
[
{
"answer_id": 199270,
"author": "Draemon",
"author_id": 26334,
"author_profile": "https://Stackoverflow.com/users/26334",
"pm_score": 10,
"selected": true,
"text": "xargs -L 1\nxargs --max-lines=1 # synonym for the -L option\n"
},
{
"answer_id": 199293,
"author": "readonly",
"author_id": 4883,
"author_profile": "https://Stackoverflow.com/users/4883",
"pm_score": 2,
"selected": false,
"text": " -L max-lines\n Use at most max-lines nonblank input lines per command line. Trailing blanks cause an input line to be logically continued on the next input\n line. Implies -x.\n\n --max-lines[=max-lines], -l[max-lines]\n Synonym for the -L option. Unlike -L, the max-lines argument is optional. If max-args is not specified, it defaults to one. The -l option\n is deprecated since the POSIX standard specifies -L instead.\n\n --max-args=max-args, -n max-args\n Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded,\n unless the -x option is given, in which case xargs will exit.\n"
},
{
"answer_id": 199325,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 5,
"selected": false,
"text": "find"
},
{
"answer_id": 199396,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "find path -type f | xargs -L1 command \n"
},
{
"answer_id": 948716,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "/path"
},
{
"answer_id": 2646238,
"author": "sergiofbsilva",
"author_id": 317605,
"author_profile": "https://Stackoverflow.com/users/317605",
"pm_score": -1,
"selected": false,
"text": "find . -name 'build.xml' -exec ant -f {} clean-all \\;\n"
},
{
"answer_id": 13930396,
"author": "Richard",
"author_id": 1912470,
"author_profile": "https://Stackoverflow.com/users/1912470",
"pm_score": 4,
"selected": false,
"text": "find /path -type f | while read ln; do echo \"processing $ln\"; done\n"
},
{
"answer_id": 25319740,
"author": "Alex Riedler",
"author_id": 3943248,
"author_profile": "https://Stackoverflow.com/users/3943248",
"pm_score": 4,
"selected": false,
"text": "xargs -I '{}' rm '{}'\nxargs -i rm '{}'\n"
},
{
"answer_id": 28806991,
"author": "Tobia",
"author_id": 517371,
"author_profile": "https://Stackoverflow.com/users/517371",
"pm_score": 8,
"selected": false,
"text": "... | tr '\\n' '\\0' | xargs -0 -n1 ...\n"
},
{
"answer_id": 30104264,
"author": "Gray",
"author_id": 179850,
"author_profile": "https://Stackoverflow.com/users/179850",
"pm_score": 5,
"selected": false,
"text": "-L 1"
},
{
"answer_id": 35820260,
"author": "CrashNeb",
"author_id": 5844631,
"author_profile": "https://Stackoverflow.com/users/5844631",
"pm_score": 0,
"selected": false,
"text": "xargs"
},
{
"answer_id": 53754994,
"author": "Mohammad Karmi",
"author_id": 1865719,
"author_profile": "https://Stackoverflow.com/users/1865719",
"pm_score": 1,
"selected": false,
"text": "#touch \"file with space\"\n#touch \"file1\"\n#touch \"file2\"\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4883/"
] |
199,321
|
<p>What is the best way to write data to the text console at arbitrary locations on the screen and with custom fore/background colors?</p>
|
[
{
"answer_id": 22065166,
"author": "Igor Kostomin",
"author_id": 1119537,
"author_profile": "https://Stackoverflow.com/users/1119537",
"pm_score": 2,
"selected": false,
"text": "WriteConsoleOutput"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4435/"
] |
199,333
|
<p>I was writing a program in C++ to find all solutions of <em>a</em><sup><em>b</em></sup> = <em>c</em>, where <em>a</em>, <em>b</em> and <em>c</em> together use all the digits 0-9 exactly once. The program looped over values of <em>a</em> and <em>b</em>, and it ran a digit-counting routine each time on <em>a</em>, <em>b</em> and <em>a<sup>b</sup></em> to check if the digits condition was satisfied.</p>
<p>However, spurious solutions can be generated when <em>a</em><sup><em>b</em></sup> overflows the integer limit. I ended up checking for this using code like:</p>
<pre><code>unsigned long b, c, c_test;
...
c_test=c*b; // Possible overflow
if (c_test/b != c) {/* There has been an overflow*/}
else c=c_test; // No overflow
</code></pre>
<p>Is there a better way of testing for overflow? I know that some chips have an internal flag that is set when overflow occurs, but I've never seen it accessed through C or C++.</p>
<hr>
<p>Beware that <strong><em>signed</em> <code>int</code> overflow is undefined behaviour in C and C++</strong>, and thus you have to detect it without actually causing it. For signed int overflow before addition, see <em><a href="https://stackoverflow.com/questions/3944505/detecting-signed-overflow-in-c-c">Detecting signed overflow in C/C++</a></em>.</p>
|
[
{
"answer_id": 199354,
"author": "Andrew Edgecombe",
"author_id": 11694,
"author_profile": "https://Stackoverflow.com/users/11694",
"pm_score": 4,
"selected": false,
"text": "unsigned long"
},
{
"answer_id": 199355,
"author": "Nils Pipenbrinck",
"author_id": 15955,
"author_profile": "https://Stackoverflow.com/users/15955",
"pm_score": 4,
"selected": false,
"text": "-ftrapv"
},
{
"answer_id": 199363,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 6,
"selected": false,
"text": "if ( b > ULONG_MAX / a ) // a * b would overflow\n"
},
{
"answer_id": 199407,
"author": "Tarski",
"author_id": 27653,
"author_profile": "https://Stackoverflow.com/users/27653",
"pm_score": 2,
"selected": false,
"text": "jo"
},
{
"answer_id": 199455,
"author": "Head Geek",
"author_id": 12193,
"author_profile": "https://Stackoverflow.com/users/12193",
"pm_score": 7,
"selected": false,
"text": "bool addition_is_safe(uint32_t a, uint32_t b) {\n size_t a_bits=highestOneBitPosition(a), b_bits=highestOneBitPosition(b);\n return (a_bits<32 && b_bits<32);\n}\n"
},
{
"answer_id": 199668,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 5,
"selected": false,
"text": "uint8_t x, y; /* Give these values */\nconst uint16_t data16 = x + y;\nconst bool carry = (data16 > 0xFF);\nconst bool overflow = ((~(x ^ y)) & (x ^ data16) & 0x80);\n"
},
{
"answer_id": 202325,
"author": "Frank Szczerba",
"author_id": 8964,
"author_profile": "https://Stackoverflow.com/users/8964",
"pm_score": -1,
"selected": false,
"text": "uint64_t foo(uint64_t a, uint64_t b) {\n double dc;\n\n dc = pow(a, b);\n\n if (dc < UINT_MAX) {\n return (powu64(a, b));\n }\n else {\n // Overflow\n }\n}\n"
},
{
"answer_id": 528249,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "unsigned int r, a, b;\nr = a + b;\nif (r < a)\n{\n // Overflow\n}\n"
},
{
"answer_id": 1514309,
"author": "pmg",
"author_id": 25324,
"author_profile": "https://Stackoverflow.com/users/25324",
"pm_score": 8,
"selected": false,
"text": "#include <limits.h>\n\nint a = <something>;\nint x = <something>;\na += x; /* UB */\nif (a < 0) { /* Unreliable test */\n /* ... */\n}\n"
},
{
"answer_id": 2751206,
"author": "Dustin",
"author_id": 233239,
"author_profile": "https://Stackoverflow.com/users/233239",
"pm_score": -1,
"selected": false,
"text": "long lng;\nint n;\nfor (n = 0; n < 34; ++n)\n{\n lng = pow (2, n);\n printf (\"%li\\n\", lng);\n}\n"
},
{
"answer_id": 6472982,
"author": "DX-MON",
"author_id": 814674,
"author_profile": "https://Stackoverflow.com/users/814674",
"pm_score": 5,
"selected": false,
"text": "uint32_t x, y;\nuint32_t value = x + y;\nbool overflow = value < (x | y);\n"
},
{
"answer_id": 6822698,
"author": "A Fog",
"author_id": 862391,
"author_profile": "https://Stackoverflow.com/users/862391",
"pm_score": 6,
"selected": false,
"text": "-O2"
},
{
"answer_id": 12726956,
"author": "Willem Hengeveld",
"author_id": 1049677,
"author_profile": "https://Stackoverflow.com/users/1049677",
"pm_score": 3,
"selected": false,
"text": "CLANG ARITHMETIC UNDEFINED at <add.c, (9:11)> :\nOp: +, Reason : Signed Addition Overflow,\nBINARY OPERATION: left (int32): 2147483647 right (int32): 1\n"
},
{
"answer_id": 13764376,
"author": "Angel Sinigersky",
"author_id": 754396,
"author_profile": "https://Stackoverflow.com/users/754396",
"pm_score": 5,
"selected": false,
"text": "#include <cstddef>\n#if defined( _MSC_VER )\n#include <intrin.h>\n#endif\n\ninline size_t query_intel_x86_eflags(const size_t query_bit_mask)\n{\n #if defined( _MSC_VER )\n\n return __readeflags() & query_bit_mask;\n\n #elif defined( __GNUC__ )\n // This code will work only on 64-bit GNU-C machines.\n // Tested and does NOT work with Intel C++ 10.1!\n size_t eflags;\n __asm__ __volatile__(\n \"pushfq \\n\\t\"\n \"pop %%rax\\n\\t\"\n \"movq %%rax, %0\\n\\t\"\n :\"=r\"(eflags)\n :\n :\"%rax\"\n );\n return eflags & query_bit_mask;\n\n #else\n\n #pragma message(\"No inline assembly will work with this compiler!\")\n return 0;\n #endif\n}\n\nint main(int argc, char **argv)\n{\n int x = 1000000000;\n int y = 20000;\n int z = x * y;\n int f = query_intel_x86_eflags(0x801);\n printf(\"%X\\n\", f);\n}\n"
},
{
"answer_id": 14859480,
"author": "Steztric",
"author_id": 1069178,
"author_profile": "https://Stackoverflow.com/users/1069178",
"pm_score": 0,
"selected": false,
"text": "addition_is_safe"
},
{
"answer_id": 15330077,
"author": "hdante",
"author_id": 1797000,
"author_profile": "https://Stackoverflow.com/users/1797000",
"pm_score": 5,
"selected": false,
"text": " 9938.08^2 == 98765432\n 462.241^3 == 98765432\n 99.6899^4 == 98765432\n 39.7119^5 == 98765432\n 21.4998^6 == 98765432\n 13.8703^7 == 98765432\n 9.98448^8 == 98765432\n 7.73196^9 == 98765432\n 6.30174^10 == 98765432\n 5.33068^11 == 98765432\n 4.63679^12 == 98765432\n 4.12069^13 == 98765432\n 3.72429^14 == 98765432\n 3.41172^15 == 98765432\n 3.15982^16 == 98765432\n 2.95305^17 == 98765432\n 2.78064^18 == 98765432\n 2.63493^19 == 98765432\n 2.51033^20 == 98765432\n 2.40268^21 == 98765432\n 2.30883^22 == 98765432\n 2.22634^23 == 98765432\n 2.15332^24 == 98765432\n 2.08826^25 == 98765432\n 2.02995^26 == 98765432\n 1.97741^27 == 98765432\n"
},
{
"answer_id": 18062322,
"author": "Markus Demarmels",
"author_id": 2653743,
"author_profile": "https://Stackoverflow.com/users/2653743",
"pm_score": 3,
"selected": false,
"text": "#define overflowflag(isOverflow){ \\\nsize_t eflags; \\\nasm (\"pushfl ;\" \\\n \"pop %%eax\" \\\n : \"=a\" (eflags)); \\\nisOverflow = (eflags >> 11) & 1;}\n"
},
{
"answer_id": 19170906,
"author": "Spyros Panaoussis",
"author_id": 2844725,
"author_profile": "https://Stackoverflow.com/users/2844725",
"pm_score": -1,
"selected": false,
"text": "DWORD\nMy Addition(DWORD Value_A, DWORD Value_B)\n{\n ULARGE_INTEGER a, b;\n\n b.LowPart = Value_A; // A 32 bit value(up to 32 bit)\n b.HighPart = 0;\n a.LowPart = Value_B; // A 32 bit value(up to 32 bit)\n a.HighPart = 0;\n\n a.QuadPart += b.QuadPart;\n\n // If a.HighPart\n // Then a.HighPart contains the overflow (carry)\n\n return (a.LowPart + a.HighPart)\n\n // Any overflow is stored in a.HighPart (up to 32 bits)\n"
},
{
"answer_id": 20956705,
"author": "zneak",
"author_id": 251153,
"author_profile": "https://Stackoverflow.com/users/251153",
"pm_score": 8,
"selected": false,
"text": "<stdckdint.h>"
},
{
"answer_id": 21050394,
"author": "bartolo-otrit",
"author_id": 704244,
"author_profile": "https://Stackoverflow.com/users/704244",
"pm_score": 3,
"selected": false,
"text": "format ELF64\n\nsection '.text' executable\n\npublic u_mul\n\nu_mul:\n MOV eax, edi\n mul esi\n jnc u_mul_ret\n xor eax, eax\nu_mul_ret:\nret\n"
},
{
"answer_id": 24334290,
"author": "Scott Franco",
"author_id": 2352564,
"author_profile": "https://Stackoverflow.com/users/2352564",
"pm_score": -1,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\n\n#define MAX 100 \n\nint mltovf(int a, int b)\n{\n if (a && b) return abs(a) > MAX/abs(b);\n else return 0;\n}\n\nmain()\n{\n int a, b;\n\n for (a = 0; a <= MAX; a++)\n for (b = 0; b < MAX; b++) {\n\n if (mltovf(a, b) != (a*b > MAX)) \n printf(\"Bad calculation: a: %d b: %d\\n\", a, b);\n\n }\n}\n"
},
{
"answer_id": 28077168,
"author": "Tyler Durden",
"author_id": 1655700,
"author_profile": "https://Stackoverflow.com/users/1655700",
"pm_score": -1,
"selected": false,
"text": "... /* begin multiplication */\nunsigned multiplicand, multiplier, product, productHalf;\nint zeroesMultiplicand, zeroesMultiplier;\nzeroesMultiplicand = number_of_leading_zeroes( multiplicand );\nzeroesMultiplier = number_of_leading_zeroes( multiplier );\nif( zeroesMultiplicand + zeroesMultiplier <= 30 ) goto overflow;\nproductHalf = multiplicand * ( c >> 1 );\nif( (int)productHalf < 0 ) goto overflow;\nproduct = productHalf * 2;\nif( multiplier & 1 ){\n product += multiplicand;\n if( product < multiplicand ) goto overflow;\n}\n..../* continue code here where \"product\" is the correct product */\n....\noverflow: /* put overflow handling code here */\n\nint number_of_leading_zeroes( unsigned value ){\n int ctZeroes;\n if( value == 0 ) return 32;\n ctZeroes = 1;\n if( ( value >> 16 ) == 0 ){ ctZeroes += 16; value = value << 16; }\n if( ( value >> 24 ) == 0 ){ ctZeroes += 8; value = value << 8; }\n if( ( value >> 28 ) == 0 ){ ctZeroes += 4; value = value << 4; }\n if( ( value >> 30 ) == 0 ){ ctZeroes += 2; value = value << 2; }\n ctZeroes -= x >> 31;\n return ctZeroes;\n}\n"
},
{
"answer_id": 33788713,
"author": "Pauli Nieminen",
"author_id": 3945377,
"author_profile": "https://Stackoverflow.com/users/3945377",
"pm_score": 0,
"selected": false,
"text": "unsigned long checked_imul(unsigned long a, unsigned long b) {\n unsigned __int128 res = (unsigned __int128)a * b;\n if ((unsigned long)(res >> 64))\n printf(\"overflow in integer multiply\");\n return (unsigned long)res;\n}\n"
},
{
"answer_id": 49303966,
"author": "hsivonen",
"author_id": 18721,
"author_profile": "https://Stackoverflow.com/users/18721",
"pm_score": 1,
"selected": false,
"text": "mozilla::CheckedInt<T>"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23732/"
] |
199,336
|
<p>How would I print a spinning curser in a utility that runs in a terminal using standard C?</p>
<p>I'm looking for something that prints: \ | / - over and over in the same position on the screen?</p>
<p>Thanks </p>
|
[
{
"answer_id": 199344,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 6,
"selected": true,
"text": "\\b"
},
{
"answer_id": 199380,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 1,
"selected": false,
"text": "conio.h"
},
{
"answer_id": 199400,
"author": "Diego Zamboni",
"author_id": 5562,
"author_profile": "https://Stackoverflow.com/users/5562",
"pm_score": 4,
"selected": false,
"text": "#include <stdio.h>\n\nvoid advance_cursor() {\n static int pos=0;\n char cursor[4]={'/','-','\\\\','|'};\n printf(\"%c\\b\", cursor[pos]);\n fflush(stdout);\n pos = (pos+1) % 4;\n}\n\nint main(int argc, char **argv) {\n int i;\n for (i=0; i<100; i++) {\n advance_cursor();\n usleep(100000);\n }\n printf(\"\\n\");\n return 0;\n}\n"
},
{
"answer_id": 890760,
"author": "Miki Tebeka",
"author_id": 7650,
"author_profile": "https://Stackoverflow.com/users/7650",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n#include <unistd.h>\n\nvoid\nadvance_spinner() {\n static char bars[] = { '/', '-', '\\\\', '|' };\n static int nbars = sizeof(bars) / sizeof(char);\n static int pos = 0;\n\n printf(\"%c\\r\", bars[pos]);\n fflush(stdout);\n pos = (pos + 1) % nbars;\n}\n\nint\nmain() {\n while (1) {\n advance_spinner();\n usleep(300);\n }\n\n return 0;\n}\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3467/"
] |
199,348
|
<p>Is there a way (hacky will do) to allow a user to go back to a previous version of a <a href="http://en.wikipedia.org/wiki/ClickOnce" rel="noreferrer">ClickOnce</a> network deployed application?</p>
<p>I've looked in the docs and API and there seems to be no way. You <b>can</b> selectively choose if you would like to update, but once updated there is, seemingly, no way back.</p>
|
[
{
"answer_id": 1664121,
"author": "Jason Hornor",
"author_id": 201263,
"author_profile": "https://Stackoverflow.com/users/201263",
"pm_score": 7,
"selected": false,
"text": "[appName].application"
},
{
"answer_id": 11238554,
"author": "Hasani Blackwell",
"author_id": 79668,
"author_profile": "https://Stackoverflow.com/users/79668",
"pm_score": 0,
"selected": false,
"text": "using System;\nusing System.Deployment.Application;\nusing System.Reflection;\n\nnamespace ClickOnceAppRollback\n{\n static class Program\n {\n /// <summary>\n /// The main entry point for the application.\n /// </summary>\n static void Main()\n {\n string appId = string.Format(\"{0}#{1}, Version={2}, Culture={3}, PublicKeyToken={4}, processorArchitecture={5}/{6}, Version={7}, Culture={8}, PublicKeyToken={9}, processorArchitecture={10}, type={11}\",\n /*The URI location of the app*/@\"http://www.microsoft.com/coolapp.exe.application\",\n /*The application's assemblyIdentity name*/\"coolapp.app\",\n /*The application's assemblyIdentity version*/\"10.8.62.17109\",\n /*The application's assemblyIdentity language*/\"neutral\",\n /*The application's assemblyIdentity public Key Token*/\"0000000000000000\",\n /*The application's assemblyIdentity processor architecture*/\"msil\",\n /*The deployment's dependentAssembly name*/\"coolapp.exe\",\n /*The deployment's dependentAssembly version*/\"10.8.62.17109\",\n /*The deployment's dependentAssembly language*/\"neutral\",\n /*The deployment's dependentAssembly public Key Token*/\"0000000000000000\",\n /*The deployment's dependentAssembly processor architecture*/\"msil\",\n /*The deployment's dependentAssembly type*/\"win32\");\n\n var ctor = typeof(ApplicationDeployment).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(string) }, null);\n var appDeployment = ctor.Invoke(new object[] { appId });\n\n var subState = appDeployment.GetType().GetField(\"_subState\", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(appDeployment);\n var subStore = appDeployment.GetType().GetField(\"_subStore\", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(appDeployment);\n try\n {\n subStore.GetType().GetMethod(\"RollbackSubscription\").Invoke(subStore, new object[] { subState });\n }\n catch\n {\n subStore.GetType().GetMethod(\"UninstallSubscription\").Invoke(subStore, new object[] { subState });\n }\n }\n }\n}\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/460845/"
] |
199,390
|
<p>I have an application used by pretty tech-savey people and they want small island of programmability so I've used embedded Iron Python.</p>
<p>However, since IronPython 2.0 Eval() doesn't work any more. Specifically I can't both load modules and inject local variables.</p>
<p>There is a work around where I can still call Execute(), print out my answer and listen to StandardOut, but then it comes out as a string and I've lost the type.</p>
<p>Not a disaster for a long, but a huge pain for more complex objects.</p>
<p>Does anyone know how to get Eval() working again in 2.0 like it did in 1.x?</p>
<p>Cheers,
Jan</p>
|
[
{
"answer_id": 199406,
"author": "Curt Hagenlocher",
"author_id": 533,
"author_profile": "https://Stackoverflow.com/users/533",
"pm_score": 3,
"selected": true,
"text": "ScriptEngine engine = Python.CreateEngine();\nScriptSource source = engine.CreateScriptSourceFromString(\"2 + 5\", SourceCodeKind.Expression);\nint result = source.Execute<int>();\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/460845/"
] |
199,403
|
<p>I would like to load a BMP file, do some operations on it in memory, and output a new BMP file using C++ on Windows (Win32 native). I am aware of <a href="http://www.imagemagick.org/" rel="nofollow noreferrer">ImageMagick</a> and it's C++ binding <a href="http://www.imagemagick.org/Magick%2B%2B/" rel="nofollow noreferrer">Magick++</a>, but I think it's an overkill for this project since I am currently not interested in other file formats or platforms.</p>
<p>What would be the simplest way in terms of code setup to read and write BMP files? The answer may be "just use Magick++, it's the simplest."</p>
<p>Related Question: <a href="https://stackoverflow.com/questions/158756/what-is-the-best-image-manipulation-library">What is the best image manipulation library?</a></p>
|
[
{
"answer_id": 200113,
"author": "user27732",
"author_id": 27732,
"author_profile": "https://Stackoverflow.com/users/27732",
"pm_score": 2,
"selected": false,
"text": "#include <windows.h>\n"
},
{
"answer_id": 11961825,
"author": "Mike C",
"author_id": 800151,
"author_profile": "https://Stackoverflow.com/users/800151",
"pm_score": 2,
"selected": false,
"text": "CImage"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3827/"
] |
199,418
|
<p>I have a C++ library that provides various classes for managing data. I have the source code for the library.</p>
<p>I want to extend the C++ API to support C function calls so that the library can be used with C code and C++ code at the same time.</p>
<p>I'm using GNU tool chain (gcc, glibc, etc), so language and architecture support are not an issue.</p>
<p>Are there any reasons why this is <strong>technically</strong> not possible?</p>
<p>Are there any <strong>gotcha's</strong> that I need to watch out for?</p>
<p>Are there resources, example code and/or documentation available regarding this?</p>
<hr>
<p>Some other things that I have found out:</p>
<ol>
<li>Use the following to wrap your C++ headers that need to be used by C code.</li>
</ol>
<p></p>
<pre><code>#ifdef __cplusplus
extern "C" {
#endif
//
// Code goes here ...
//
#ifdef __cplusplus
} // extern "C"
#endif
</code></pre>
<ol start="2">
<li>Keep "real" C++ interfaces in separate header files that are not included by C. Think <a href="http://en.wikipedia.org/wiki/Private_class_data_pattern" rel="noreferrer">PIMPL principle</a> here. Using <code>#ifndef __cplusplus #error</code> stuff helps here to detect any craziness.</li>
<li>Careful of C++ identifiers as names in C code</li>
<li>Enums varying in size between C and C++ compilers. Probably not an issue if you're using GNU tool chain, but still, be careful.</li>
<li><p>For structs follow the following form so that C does not get confused.</p>
<pre><code>typedef struct X { ... } X
</code></pre></li>
<li><p>Then use pointers for passing around C++ objects, they just have to be declared in C as struct X where X is the C++ object.</p></li>
</ol>
<p>All of this is courtesy of a friend who's a wizard at C++.</p>
|
[
{
"answer_id": 199422,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 7,
"selected": true,
"text": "extern \"C\""
},
{
"answer_id": 199438,
"author": "David Nehme",
"author_id": 14167,
"author_profile": "https://Stackoverflow.com/users/14167",
"pm_score": 2,
"selected": false,
"text": "extern \"C\"\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199418",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3467/"
] |
199,426
|
<p>I am new to Java and am trying to run a program using Eclipse. But I have no idea how to get the command prompt running in with Eclipse...</p>
<p>I did some online research and couldn't get anything consolidated!</p>
<h3>Update:</h3>
<p>I'm not using an applet. It's a normal Java program trying to read a line from command prompt. I'm trying to do system programming.</p>
|
[
{
"answer_id": 199444,
"author": "Pablo Fernandez",
"author_id": 7595,
"author_profile": "https://Stackoverflow.com/users/7595",
"pm_score": 0,
"selected": false,
"text": "Try this:\n\n\nimport java.util.Scanner;\n\n public class ReadFromPrompt{\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n\n String line = in.nextLine(); \n\n }\n }\n"
},
{
"answer_id": 17036819,
"author": "Karthik Reddy",
"author_id": 1929603,
"author_profile": "https://Stackoverflow.com/users/1929603",
"pm_score": 0,
"selected": false,
"text": "Right Click on your project--->Run As--->Run Configurations...--->Select Arguments-->Enter the values---->Run\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21968/"
] |
199,428
|
<p>I Have one entity [Project] that contains a collection of other entities [Questions].</p>
<p>I have mapped the relation with a cascade attribute of "all-delete-orphan".</p>
<p>In my DB the relation is mapped with a project_id (FK) field on the questions table. this field cannot be null since I don't want a Question without a Project.</p>
<p>When I do <code>session.delete(project)</code> it throws an exception saying that <code>project_id</code> cant be <code>null</code>, but if I remove the <code>not-null</code> constraint to that field, the deletion works nice.</p>
<p>Anyone knows how to solve this?</p>
|
[
{
"answer_id": 199683,
"author": "abarax",
"author_id": 24390,
"author_profile": "https://Stackoverflow.com/users/24390",
"pm_score": 4,
"selected": false,
"text": "Parent p = (Parent) session.Load(typeof(Parent), pid);\n// Get one child out of the set\nIEnumerator childEnumerator = p.Children.GetEnumerator();\nchildEnumerator.MoveNext();\nChild c = (Child) childEnumerator.Current;\n\np.Children.Remove(c);\nc.Parent = null;\nsession.Flush();\n"
},
{
"answer_id": 73638227,
"author": "Klioda",
"author_id": 3544063,
"author_profile": "https://Stackoverflow.com/users/3544063",
"pm_score": 0,
"selected": false,
"text": "public class Project {\n\n @Id\n private long id;\n\n @OneToMany(mappedBy = \"project\", cascade = {CascadeType.REMOVE})\n public List<Question> questions;\n}\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7595/"
] |
199,468
|
<p>Why am I getting an out of memory exception?</p>
<p>So this dies in C# on the first time through:</p>
<p><strong>splitBitmaps.Add(neededImage.Clone(rectDimensions, neededImage.PixelFormat));</strong> </p>
<p>Where splitBitmaps is a List<BitMap> BUT this works in VB for at least 4 iterations:</p>
<p><strong>arlSplitBitmaps.Add(Image.Clone(rectDimensions, Image.PixelFormat))</strong></p>
<p>Where arlSplitBitmaps is a simple array list. (And yes I've tried arraylist in c#)</p>
<p>This is the fullsection:</p>
<pre><code>for (Int32 splitIndex = 0; splitIndex <= numberOfResultingImages - 1; splitIndex++)
{
Rectangle rectDimensions;
if (splitIndex < numberOfResultingImages - 1)
{
rectDimensions = new Rectangle(splitImageWidth * splitIndex, 0,
splitImageWidth, splitImageHeight);
}
else
{
rectDimensions = new Rectangle(splitImageWidth * splitIndex, 0,
sourceImageWidth - (splitImageWidth * splitIndex), splitImageHeight);
}
splitBitmaps.Add(neededImage.Clone(rectDimensions, neededImage.PixelFormat));
</code></pre>
<p>} </p>
<p>neededImage is a Bitmap by the way. </p>
<p>I can't find any useful answers on the intarweb, especially not why it works just fine in VB.</p>
<p><strong>Update:</strong></p>
<p>I actually found a reason (sort of) for this working but forgot to post it. It has to do with converting the image to a bitmap instead of just trying to clone the raw image if I remember.</p>
|
[
{
"answer_id": 29024741,
"author": "dellyjm",
"author_id": 1810774,
"author_profile": "https://Stackoverflow.com/users/1810774",
"pm_score": 2,
"selected": false,
"text": "int totalWidth = rect.Left + rect.Width; //think -the same as Right property\n\nint allowableWidth = localImage.Width - rect.Left;\nint finalWidth = 0;\n\nif (totalWidth > allowableWidth){\n finalWidth = allowableWidth;\n} else {\n finalWidth = totalWidth;\n}\n\nrect.Width = finalWidth;\n\nint totalHeight = rect.Top + rect.Height; //think same as Bottom property\nint allowableHeight = localImage.Height - rect.Top;\nint finalHeight = 0;\n\nif (totalHeight > allowableHeight){\n finalHeight = allowableHeight;\n} else {\n finalHeight = totalHeight;\n}\n\nrect.Height = finalHeight;\ncropped = ((Bitmap)localImage).Clone(rect, System.Drawing.Imaging.PixelFormat.DontCare);\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21691/"
] |
199,469
|
<p>I need to change the capitalization of a set of files in a subversion working copy, like so:</p>
<pre>
svn mv test.txt Test.txt
svn mv test2.txt Test2.txt
svn mv testn.txt Testn.txt
...
svn commit -m "caps"
</pre>
<p>How can I automate this process? Standard linux install tools available.</p>
|
[
{
"answer_id": 199510,
"author": "UnkwnTech",
"author_id": 115,
"author_profile": "https://Stackoverflow.com/users/115",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/python\nfrom os import rename, listdir\npath = \"/path/to/folder\"\ntry:\n dirList = listdir(path)\nexcept:\n print 'There was an error while trying to access the directory: '+path\nfor name in dirList:\n try:\n rename(path+'\\\\'+name, path+'\\\\'+name.upper())\n except:\n print 'Process failed for file: '+name\n"
},
{
"answer_id": 199520,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 1,
"selected": false,
"text": " #!/usr/bin/ruby \n # Upcase.rb \n ARGV.each{ |i|\n newname = i.gsub(/(^.|\\s.)/{ |x| x.upcase }\n `svn mv \"#{i}\" \"#{newname}\" `\n }\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27667/"
] |
199,470
|
<ul>
<li>What is the main difference between <code>int.Parse()</code> and <code>Convert.ToInt32()</code>?</li>
<li>Which one is to be preferred</li>
</ul>
|
[
{
"answer_id": 199482,
"author": "shahkalpesh",
"author_id": 23574,
"author_profile": "https://Stackoverflow.com/users/23574",
"pm_score": 7,
"selected": false,
"text": "Convert.ToInt32()"
},
{
"answer_id": 199484,
"author": "Dave Markle",
"author_id": 24995,
"author_profile": "https://Stackoverflow.com/users/24995",
"pm_score": 10,
"selected": true,
"text": "Int32.Parse()"
},
{
"answer_id": 199547,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 5,
"selected": false,
"text": "Int32.Parse()"
},
{
"answer_id": 201405,
"author": "Chris S",
"author_id": 21574,
"author_profile": "https://Stackoverflow.com/users/21574",
"pm_score": 8,
"selected": false,
"text": "public static int Parse(string s)\n{\n return System.Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);\n}\n"
},
{
"answer_id": 10528244,
"author": "shashi shekhar",
"author_id": 1386257,
"author_profile": "https://Stackoverflow.com/users/1386257",
"pm_score": 3,
"selected": false,
"text": "Convert.ToInt32\n"
},
{
"answer_id": 11789668,
"author": "Pradeep Kumar",
"author_id": 1573175,
"author_profile": "https://Stackoverflow.com/users/1573175",
"pm_score": 1,
"selected": false,
"text": "static void Main(string[] args)"
},
{
"answer_id": 19504682,
"author": "Dale K",
"author_id": 699377,
"author_profile": "https://Stackoverflow.com/users/699377",
"pm_score": 2,
"selected": false,
"text": "public static int ToInt32(char value)\n{\n return (int)value;\n} \n\nConvert.ToInt32('1'); // Returns 49\nint.Parse('1'); // Returns 1\n"
},
{
"answer_id": 30164744,
"author": "Sonu Rajpoot",
"author_id": 3600880,
"author_profile": "https://Stackoverflow.com/users/3600880",
"pm_score": 4,
"selected": false,
"text": "string s1 = \"1234\"; \nstring s2 = \"1234.65\"; \nstring s3 = null; \nstring s4 = \"123456789123456789123456789123456789123456789\"; \n\nresult = Int32.Parse(s1); //1234\nresult = Int32.Parse(s2); //FormatException\nresult = Int32.Parse(s3); //ArgumentNullException \nresult = Int32.Parse(s4); //OverflowException\n"
},
{
"answer_id": 35838093,
"author": "NITHIN RAJ T",
"author_id": 5077610,
"author_profile": "https://Stackoverflow.com/users/5077610",
"pm_score": 6,
"selected": false,
"text": "class Program\n{\n static void Main(string[] args)\n {\n string strInt = \"24532\";\n string strNull = null;\n string strWrongFrmt = \"5.87\";\n string strAboveRange = \"98765432123456\";\n int res;\n try\n {\n // int.Parse() - TEST\n res = int.Parse(strInt); // res = 24532\n res = int.Parse(strNull); // System.ArgumentNullException\n res = int.Parse(strWrongFrmt); // System.FormatException\n res = int.Parse(strAboveRange); // System.OverflowException\n\n // Convert.ToInt32(string s) - TEST\n res = Convert.ToInt32(strInt); // res = 24532\n res = Convert.ToInt32(strNull); // res = 0\n res = Convert.ToInt32(strWrongFrmt); // System.FormatException\n res = Convert.ToInt32(strAboveRange); //System.OverflowException\n\n // int.TryParse(string s, out res) - Test\n bool isParsed;\n isParsed = int.TryParse(strInt, out res); // isParsed = true, res = 24532\n isParsed = int.TryParse(strNull, out res); // isParsed = false, res = 0\n isParsed = int.TryParse(strWrongFrmt, out res); // isParsed = false, res = 0\n isParsed = int.TryParse(strAboveRange, out res); // isParsed = false, res = 0 \n }\n catch(Exception e)\n {\n Console.WriteLine(\"Check this.\\n\" + e.Message);\n }\n }\n"
},
{
"answer_id": 48800572,
"author": "Koala-Programmer",
"author_id": 3381508,
"author_profile": "https://Stackoverflow.com/users/3381508",
"pm_score": 2,
"selected": false,
"text": "int.Parse"
},
{
"answer_id": 55380480,
"author": "Sylwester Santorowski",
"author_id": 7523727,
"author_profile": "https://Stackoverflow.com/users/7523727",
"pm_score": 2,
"selected": false,
"text": "int i;\nbool b = int.TryParse( \"123-\",\n System.Globalization.NumberStyles.AllowTrailingSign,\n System.Globalization.CultureInfo.InvariantCulture,\n out i);\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14752/"
] |
199,483
|
<p>This is the constraint I have on the Customers table.</p>
<pre><code>ALTER TABLE Customers
ADD CONSTRAINT CN_CustomerPhone
CHECK (Phone LIKE '([0-9][0-9][0-9]) [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]')
</code></pre>
<p>Why does this fail?</p>
<pre><code>INSERT INTO Customers
(CustomerName, Address, City, State, Zip, Phone)
VALUES
('Some Name','An Address', 'City goes here', 'WI', 12345, '(800) 555-1212')
</code></pre>
<p>With this error message.</p>
<blockquote>
<p>Msg 547, Level 16, State 0, Line 1 The
INSERT statement conflicted with the
CHECK constraint "CN_CustomerPhoneNo".
The conflict occurred in database
"Accounting", table "dbo.Customers",
column 'Phone'. The statement has been
terminated.</p>
</blockquote>
<p>I'm sure I'm missing something really simple, but I can't find it.</p>
<p>I've tried simplifying the constraint to only 'Phone LIKE '[0-9]'' and inserting a single digit, but it still fails. WTF?</p>
|
[
{
"answer_id": 199500,
"author": "shahkalpesh",
"author_id": 23574,
"author_profile": "https://Stackoverflow.com/users/23574",
"pm_score": 4,
"selected": true,
"text": "\ncreate table #temp\n(phone varchar(15))\n\nALTER TABLE #temp\n ADD CONSTRAINT CN_CustomerPhone\n CHECK (Phone LIKE '([0-9][0-9][0-9]) [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]')\n\nINSERT INTO #temp\n(Phone)\nVALUES\n('(800) 555-1212')\n\nselect * from #temp\n\ndrop table #temp\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/100/"
] |
199,488
|
<p>For some reason I am having troubles with a DBI handle. Basically what happened was that I made a special connect function in a perl module and switched from doing:</p>
<pre><code>do 'foo.pl'
</code></pre>
<p>to</p>
<pre><code>use Foo;
</code></pre>
<p>and then I do</p>
<pre><code>$dbh = Foo->connect;
</code></pre>
<p>And now for some reason I keep getting the error:</p>
<blockquote>
<p>Can't locate object method "rollback" via package "Foo" at ../Foo.pm line 171.</p>
</blockquote>
<p>So the weird thing is that $dbh is definitely not a Foo, it's just defined in foo. Anyway, I haven't had any troubles with it up until now. Any ideas what's up?</p>
<p><strong>Edit</strong>: @Axeman: <code>connect</code> did not exist in the original. Before we just had a string that we used like this:</p>
<pre><code>do 'foo.pl';
$dbh = DBI->connect($DBConnectString);
</code></pre>
<p>and so <code>connect</code> is something like this</p>
<pre><code>sub connect {
my $dbh = DBI->connect('blah');
return $dbh;
}
</code></pre>
|
[
{
"answer_id": 199635,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 3,
"selected": true,
"text": "do 'foo.pl'"
},
{
"answer_id": 200016,
"author": "Frentos",
"author_id": 23978,
"author_profile": "https://Stackoverflow.com/users/23978",
"pm_score": 2,
"selected": false,
"text": "use Foo;\n...\n$dbh = Foo::connect();\n"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12448/"
] |
199,498
|
<p>I'm just getting started working with foreign keys for the first time and I'm wondering if there's a standard naming scheme to use for them?</p>
<p>Given these tables:</p>
<pre><code>task (id, userid, title)
note (id, taskid, userid, note);
user (id, name)
</code></pre>
<p>Where Tasks have Notes, Tasks are owned by Users, and Users author Notes.</p>
<p>How would the three foreign keys be named in this situation? Or alternatively, <em>does it even matter at all</em>?</p>
<p><em>Update</em>: This question is about foreign key names, not field names!</p>
|
[
{
"answer_id": 199504,
"author": "EvilTeach",
"author_id": 7734,
"author_profile": "https://Stackoverflow.com/users/7734",
"pm_score": 4,
"selected": false,
"text": "FK_TABLENAME_COLUMNNAME"
},
{
"answer_id": 199506,
"author": "Steve Moyer",
"author_id": 17008,
"author_profile": "https://Stackoverflow.com/users/17008",
"pm_score": 3,
"selected": false,
"text": "task (id, userid, title);\nnote (id, taskid, userid, note);\nuser (id, name);\n"
},
{
"answer_id": 199549,
"author": "Greg Beech",
"author_id": 13552,
"author_profile": "https://Stackoverflow.com/users/13552",
"pm_score": 9,
"selected": true,
"text": "FK_ForeignKeyTable_PrimaryKeyTable\n"
},
{
"answer_id": 200253,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 6,
"selected": false,
"text": "fk__ForeignKeyTable__PrimaryKeyTable \n"
},
{
"answer_id": 22673186,
"author": "Chad Kieffer",
"author_id": 437101,
"author_profile": "https://Stackoverflow.com/users/437101",
"pm_score": 0,
"selected": false,
"text": "fk_task_userid_user\nfk_note_userid_user\n"
},
{
"answer_id": 24729967,
"author": "bvj",
"author_id": 241296,
"author_profile": "https://Stackoverflow.com/users/241296",
"pm_score": 4,
"selected": false,
"text": "FK_ChildTable_ParentTable\n"
},
{
"answer_id": 35051349,
"author": "Cary Bondoc",
"author_id": 2947415,
"author_profile": "https://Stackoverflow.com/users/2947415",
"pm_score": 2,
"selected": false,
"text": "FK_ColumnNameOfForeignKey_TableNameOfReference_ColumnNameOfReference\n"
},
{
"answer_id": 35470097,
"author": "SSISPissesMeOff",
"author_id": 704906,
"author_profile": "https://Stackoverflow.com/users/704906",
"pm_score": 3,
"selected": false,
"text": "CONSTRAINT [FK_ChildTableName_ChildColName_ParentTableName_PrimaryKeyColName]\n"
},
{
"answer_id": 50710247,
"author": "coldserenity",
"author_id": 3112116,
"author_profile": "https://Stackoverflow.com/users/3112116",
"pm_score": -1,
"selected": false,
"text": "FK_4VPO_K4S2_A6M1_RQLEYLT1VQYV"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
199,499
|
<p>I'm creating a custom Java Struts tag that is for building and formatting an html select box in a standardised way (part of our usability guidelines).</p>
<p>Each select box has an additional/initial value which describes the requirement of the value returned by the select element, i.e.:</p>
<ul>
<li><i>Mandatory</i> - with the label "Please Select"
<li><i>Optional</i> - "None Selected"
<li><i>Select All</i> - "Select All"
</ul>
<p>The custom tag will have a property that controls which of these are to be used.</p>
<p>So the problem is, I need to think of a variable name that can adequately explain that is is holding one of these three values!<br>
I will be commenting the code in any case, but I'd prefer that co-workers didn't have to look up the source code to remember what the tag variable's purpose is.</p>
<p><strong>Edit:</strong> To put some context around this problem, the usability strategy that I'm implementing here is that if there are more than 5 items that can be selected, the options should appear as a select box. 5 or less items will appear as radio buttons.<br>
When radio buttons are being used, the mandatory label won't be displayed (form validation will complain if there's no value selected anyway). </p>
|
[
{
"answer_id": 199572,
"author": "Mike Spross",
"author_id": 17862,
"author_profile": "https://Stackoverflow.com/users/17862",
"pm_score": 4,
"selected": true,
"text": "requirementConstraint"
}
] |
2008/10/13
|
[
"https://Stackoverflow.com/questions/199499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6340/"
] |
199,508
|
<p>Is it possible to show other processes in progress on an Oracle database? Something like Sybases <code>sp_who</code></p>
|
[
{
"answer_id": 199523,
"author": "jim",
"author_id": 27628,
"author_profile": "https://Stackoverflow.com/users/27628",
"pm_score": 3,
"selected": false,
"text": "SELECT sid,\n opname,\n sofar,\n totalwork,\n units,\n elapsed_seconds,\n time_remaining\nFROM v$session_longops\nWHERE sofar != totalwork;\n"
},
{
"answer_id": 199567,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 8,
"selected": true,
"text": "SELECT sess.process, sess.status, sess.username, sess.schemaname, sql.sql_text\n FROM v$session sess,\n v$sql sql\n WHERE sql.sql_id(+) = sess.sql_id\n AND sess.type = 'USER'\n"
},
{
"answer_id": 24946439,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 3,
"selected": false,
"text": "select S.USERNAME, s.sid, s.osuser, t.sql_id, sql_text\nfrom v$sqltext_with_newlines t,V$SESSION s\nwhere t.address =s.sql_address\nand t.hash_value = s.sql_hash_value\nand s.status = 'ACTIVE'\nand s.username <> 'SYSTEM'\norder by s.sid,t.piece\n/\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199508",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14952/"
] |
199,518
|
<p>In WinXP (SP2) you can store mapped network passwords...</p>
<p>Start->Control Panel->User Accounts->Pick one then choose "Manage my network passwords" from Related Tasks.</p>
<p>I normally have about 25-30 servers mapped this way to a few different accounts/domains. The problem is that at some point during our policy updates they get wiped out and it's a real PITA to add them all back again.</p>
<p>Does anyone know how to add them programatically using some sort of script?</p>
<p>Just to clarify, the end goal is not to map drives, it's to actually create the entries in that section. This allows us to use Windows authentication for connecting to our servers (via Dameware, SSMS etc.).</p>
<p><strong>Addendum:</strong></p>
<p>Mark's CredWrite tip led me here...</p>
<p><a href="http://www.pinvoke.net/default.aspx/advapi32/CredWrite.html" rel="nofollow noreferrer">pinvoke.net -- CredWrite (advapi32)</a></p>
<p>Which in turn led me here...</p>
<p><a href="http://blogs.msdn.com/peerchan/pages/487834.aspx" rel="nofollow noreferrer">Peer Channel Blog -- Application Password Security</a></p>
<p>Both have proved very helpful.</p>
|
[
{
"answer_id": 199766,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 3,
"selected": true,
"text": "CRED_PERSIST_SESSION"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199518",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12842/"
] |
199,521
|
<p>I have a form with a "Clear" button.</p>
<p>When the user clicks "Clear", I want to clear the value of all the visible elements on the form. In the case of date controls, I want to reset them to the current date.</p>
<p>All of my controls are contained on a Panel.</p>
<p>Right now, I'm doing this with the below code. Is there an easier way than manually checking for each control type? This method seems excessively unwieldy.</p>
<p>To make matters worse, in order to recursively clear controls inside sub-containers (i.e., a group box within the panel) I have to repeat the whole monster with an overloaded "GroupBox" version.</p>
<p><em>Edit: Thanks to your suggestions, the below code is greatly simplified.</em></p>
<pre><code>Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'User clicks Clear, so clear all the controls within this panel
ClearAllControls(panMid, True) 'True indicates that yes, i want to recurse through sub-containers
End Sub
ClearAllControls(ByRef container As Panel, Optional Recurse As Boolean = True)
'Clear all of the controls within the container object
'If "Recurse" is true, then also clear controls within any sub-containers
Dim ctrl As Control
For Each ctrl In container.Controls
If (ctrl.GetType() Is GetType(TextBox)) Then
Dim txt As TextBox = CType(ctrl, TextBox)
txt.Text = ""
End If
If (ctrl.GetType() Is GetType(CheckBox)) Then
Dim chkbx As CheckBox = CType(ctrl, CheckBox)
chkbx.Checked = False
End If
If (ctrl.GetType() Is GetType(ComboBox)) Then
Dim cbobx As ComboBox = CType(ctrl, ComboBox)
cbobx.SelectedIndex = -1
End If
If (ctrl.GetType() Is GetType(DateTimePicker)) Then
Dim dtp As DateTimePicker = CType(ctrl, DateTimePicker)
dtp.Value = Now()
End If
If Recurse Then
If (ctrl.GetType() Is GetType(Panel)) Then
Dim pnl As Panel = CType(ctrl, Panel)
ClearAllControls(pnl, Recurse)
End If
If ctrl.GetType() Is GetType(GroupBox) Then
Dim grbx As GroupBox = CType(ctrl, GroupBox)
ClearAllControls(grbx, Recurse)
End If
End If
Next
End Sub
</code></pre>
<p>@Theraccoonbear: I like your suggestion, but when I change the declaration to this:</p>
<pre><code>Private Sub ClearAllControls(ByRef controls As ControlCollection, Optional ByVal Recurse As Boolean = True)
</code></pre>
<p>Then this line gives me "Unable to cast object of type 'ControlCollection' to type 'ControlCollection'.":</p>
<pre><code> ClearAllControls(panMid.Controls)
</code></pre>
|
[
{
"answer_id": 199553,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 5,
"selected": true,
"text": "Dim dtp as DateTimePicker = TryCast(ctrl, DateTimePicker)\nIf dtp IsNot Nothing then dtp.Value = Now()\n"
},
{
"answer_id": 199558,
"author": "rjrapson",
"author_id": 1616,
"author_profile": "https://Stackoverflow.com/users/1616",
"pm_score": 2,
"selected": false,
"text": "ClearAllControls(ByRef container As Control, Optional ByVal Recurse As Boolean = True)\n"
},
{
"answer_id": 1961621,
"author": "ShoushouLebanon",
"author_id": 238637,
"author_profile": "https://Stackoverflow.com/users/238637",
"pm_score": 1,
"selected": false,
"text": "For Each c In CONTAINER.Controls\n If TypeOf c Is TextBox Then\n c.Text = \"\"\n End If\nNext\n"
},
{
"answer_id": 12541586,
"author": "Sekhar Babu",
"author_id": 1690479,
"author_profile": "https://Stackoverflow.com/users/1690479",
"pm_score": 1,
"selected": false,
"text": "Private Sub ClearAll()\n Try\n For Each ctrl As Control In Me.Controls\n If ctrl.[GetType]().Name = \"Panel\" Then\n ClearControls(ctrl)\n End If\n\n If ctrl.[GetType]().Name = \"GroupBox\" Then\n ClearControls(ctrl)\n End If\n If ctrl.[GetType]().Name = \"ComboBox\" Then\n Dim tb As ComboBox = TryCast(ctrl, ComboBox)\n tb.SelectedText = \"\"\n End If\n\n\n If ctrl.[GetType]().Name = \"TabControl\" Then\n ClearControls(ctrl)\n End If\n\n If ctrl.[GetType]().Name = \"TextBox\" Then\n Dim tb As TextBox = TryCast(ctrl, TextBox)\n tb.Clear()\n End If\n\n If ctrl.[GetType]().Name = \"RadioButton\" Then\n Dim tb As RadioButton = TryCast(ctrl, RadioButton)\n tb.Checked = False\n End If\n\n If ctrl.[GetType]().Name = \"CheckBox\" Then\n Dim tb As CheckBox = TryCast(ctrl, CheckBox)\n tb.Checked = False\n End If\n\n If ctrl.[GetType]().Name = \"ComboBox\" Then\n Dim tb As ComboBox = TryCast(ctrl, ComboBox)\n tb.SelectedIndex = 0\n End If\n\n If ctrl.[GetType]().Name = \"RichTextBox\" Then\n Dim tb As RichTextBox = TryCast(ctrl, RichTextBox)\n tb.Clear()\n\n End If\n Next\n Catch ex As Exception\n MessageBox.Show(ex.Message, \"Error Message\", MessageBoxButtons.OK, MessageBoxIcon.Error)\n End Try\nEnd Sub\n\n\nPrivate Sub ClearControls(ByVal Type As Control)\n\n Try\n For Each ctrl As Control In Type.Controls\n\n If ctrl.[GetType]().Name = \"TextBox\" Then\n Dim tb As TextBox = TryCast(ctrl, TextBox)\n tb.Clear()\n End If\n\n If ctrl.[GetType]().Name = \"Panel\" Then\n ClearControls(ctrl)\n End If\n\n If ctrl.[GetType]().Name = \"GroupBox\" Then\n ClearControls(ctrl)\n End If\n\n If ctrl.[GetType]().Name = \"TabPage\" Then\n ClearControls(ctrl)\n End If\n\n If ctrl.[GetType]().Name = \"ComboBox\" Then\n Dim tb As ComboBox = TryCast(ctrl, ComboBox)\n tb.SelectedText = \"\"\n End If\n\n If ctrl.[GetType]().Name = \"RadioButton\" Then\n Dim tb As RadioButton = TryCast(ctrl, RadioButton)\n tb.Checked = False\n End If\n\n If ctrl.[GetType]().Name = \"CheckBox\" Then\n Dim tb As CheckBox = TryCast(ctrl, CheckBox)\n tb.Checked = False\n End If\n\n If ctrl.[GetType]().Name = \"RichTextBox\" Then\n Dim tb As RichTextBox = TryCast(ctrl, RichTextBox)\n tb.Clear()\n\n End If\n Next\n Catch ex As Exception\n MessageBox.Show(ex.Message, \"Error Message\", MessageBoxButtons.OK, MessageBoxIcon.Error)\n End Try\nEnd Sub\n"
},
{
"answer_id": 12985464,
"author": "Imran",
"author_id": 1760995,
"author_profile": "https://Stackoverflow.com/users/1760995",
"pm_score": 3,
"selected": false,
"text": "Private Sub GetControls()\n For Each GroupBoxCntrol As Control In Me.Controls\n If TypeOf GroupBoxCntrol Is GroupBox Then\n For Each cntrl As Control In GroupBoxCntrol.Controls\n 'do somethin here\n\n Next\n End If\n\n Next\nEnd Sub\n"
},
{
"answer_id": 14756578,
"author": "dmcgill50",
"author_id": 168617,
"author_profile": "https://Stackoverflow.com/users/168617",
"pm_score": 1,
"selected": false,
"text": "Private Sub ClearForm(ByVal ctrlParent As Control)\n Dim ctrl As Control\n For Each ctrl In ctrlParent.Controls\n If TypeOf ctrl Is TextBox Then\n ctrl.Text = \"\"\n End If\n ' If the control has children, \n ' recursively call this function\n If ctrl.HasChildren Then\n ClearForm(ctrl)\n End If\n Next\nEnd Sub\n"
},
{
"answer_id": 21934768,
"author": "ElektroStudios",
"author_id": 1248295,
"author_profile": "https://Stackoverflow.com/users/1248295",
"pm_score": 0,
"selected": false,
"text": "ControlIterator"
},
{
"answer_id": 29611813,
"author": "user3692282",
"author_id": 3692282,
"author_profile": "https://Stackoverflow.com/users/3692282",
"pm_score": 1,
"selected": false,
"text": "Public Sub raz(lst As Control.ControlCollection, Optional recursive As Boolean = True)\n For Each ctrl As Control In lst\n If TypeOf ctrl Is TextBox Then\n CType(ctrl, TextBox).Clear()\n End If\n\n If TypeOf ctrl Is MaskedTextBox Then\n CType(ctrl, MaskedTextBox).Clear()\n End If\n\n If TypeOf ctrl Is ComboBox Then\n CType(ctrl, ComboBox).SelectedIndex = -1\n End If\n\n If TypeOf ctrl Is DateTimePicker Then\n Dim dtp As DateTimePicker = CType(ctrl, DateTimePicker)\n dtp.CustomFormat = \" \"\n End If\n\n If TypeOf ctrl Is CheckedListBox Then\n Dim clbox As CheckedListBox = CType(ctrl, CheckedListBox)\n For i As Integer = 0 To clbox.Items.Count - 1\n clbox.SetItemChecked(i, False)\n Next\n End If\n\n If TypeOf ctrl Is RadioButton Then\n CType(ctrl, RadioButton).Checked = False\n\n End If\n\n If recursive Then\n If TypeOf ctrl Is GroupBox Then\n raz(CType(ctrl, GroupBox).Controls)\n End If\n End If\n Next\nEnd Sub\n"
},
{
"answer_id": 64253564,
"author": "user14410512",
"author_id": 14410512,
"author_profile": "https://Stackoverflow.com/users/14410512",
"pm_score": 0,
"selected": false,
"text": "GetAllButtons(Me)\n\nPublic Sub GetAllButtons(ByRef forms As Object)\n Dim list As New List(Of Button)\n Dim iIndx As Integer\n For Each c In forms.Controls\n For iIndx = 0 To forms.Controls.Count - 1\n If (TypeOf forms.Controls(iIndx) Is Button) Then\n list.Add(forms.Controls(iIndx))\n End If\n If (TypeOf forms.controls(iIndx) Is Panel) Then\n For Each cntrl As Control In forms.controls(iIndx).Controls\n If TypeOf cntrl Is Button Then\n list.Add(cntrl)\n End If\n Next\n End If\n Next\n Next\n\nButton(list.ToArray)\n\nEnd Sub\n\nPublic Sub Button(btn() As Button)\n For Each bt In btn\n Do Something with Buttons\n next\nEnd Sub\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/672/"
] |
199,527
|
<p><code>$0</code> is the variable for the top level Ruby program, but is there one for the current method?</p>
|
[
{
"answer_id": 199550,
"author": "Mark A. Nicolosi",
"author_id": 1103052,
"author_profile": "https://Stackoverflow.com/users/1103052",
"pm_score": 5,
"selected": false,
"text": "module Kernel\nprivate\n def this_method_name\n caller[0] =~ /`([^']*)'/ and $1\n end\nend\n\nclass Foo\n def test_method\n this_method_name\n end\nend\n\nputs Foo.new.test_method # => test_method\n"
},
{
"answer_id": 199560,
"author": "Mark A. Nicolosi",
"author_id": 1103052,
"author_profile": "https://Stackoverflow.com/users/1103052",
"pm_score": 10,
"selected": true,
"text": "class Foo\n def test_method\n __method__\n end\nend\n"
},
{
"answer_id": 20365877,
"author": "l3x",
"author_id": 1978383,
"author_profile": "https://Stackoverflow.com/users/1978383",
"pm_score": 4,
"selected": false,
"text": "__callee__"
},
{
"answer_id": 26887616,
"author": "Hetal Khunti",
"author_id": 4238841,
"author_profile": "https://Stackoverflow.com/users/4238841",
"pm_score": -1,
"selected": false,
"text": "params[:action] # it will return method's name\n"
},
{
"answer_id": 35634927,
"author": "Kelvin",
"author_id": 498594,
"author_profile": "https://Stackoverflow.com/users/498594",
"pm_score": 5,
"selected": false,
"text": "__method__"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/757/"
] |
199,528
|
<p>I know how to program Console application with parameters, example : myProgram.exe param1 param2.</p>
<p>My question is, how can I make my program works with |, example : echo "word" | myProgram.exe?</p>
|
[
{
"answer_id": 199534,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 7,
"selected": true,
"text": "Console.Read()"
},
{
"answer_id": 2151545,
"author": "Alex N",
"author_id": 207445,
"author_profile": "https://Stackoverflow.com/users/207445",
"pm_score": 1,
"selected": false,
"text": " while ((s = Console.ReadLine()) != null)\n"
},
{
"answer_id": 4074212,
"author": "CodeMiller",
"author_id": 425529,
"author_profile": "https://Stackoverflow.com/users/425529",
"pm_score": 4,
"selected": false,
"text": "public static void Main(String[] args)\n{\n\n String pipedText = \"\";\n bool isKeyAvailable;\n\n try\n {\n isKeyAvailable = System.Console.KeyAvailable;\n }\n catch (InvalidOperationException expected)\n {\n pipedText = System.Console.In.ReadToEnd();\n }\n\n //do something with pipedText or the args\n}\n"
},
{
"answer_id": 9712392,
"author": "Matthew Benedict",
"author_id": 498771,
"author_profile": "https://Stackoverflow.com/users/498771",
"pm_score": 2,
"selected": false,
"text": "static int Main(string[] args)\n{\n // if nothing is being piped in, then exit\n if (!IsPipedInput())\n return 0;\n\n while (Console.In.Peek() != -1)\n {\n string input = Console.In.ReadLine();\n Console.WriteLine(input);\n }\n\n return 0;\n}\n\nprivate static bool IsPipedInput()\n{\n try\n {\n bool isKey = Console.KeyAvailable;\n return false;\n }\n catch\n {\n return true;\n }\n}\n"
},
{
"answer_id": 21240198,
"author": "matt burns",
"author_id": 276093,
"author_profile": "https://Stackoverflow.com/users/276093",
"pm_score": 3,
"selected": false,
"text": "static void Main(string[] args)\n{\n Console.SetIn(new StreamReader(Console.OpenStandardInput(8192))); // This will allow input >256 chars\n while (Console.In.Peek() != -1)\n {\n string input = Console.In.ReadLine();\n Console.WriteLine(\"Data read was \" + input);\n }\n}\n"
},
{
"answer_id": 29047721,
"author": "gordy",
"author_id": 99691,
"author_profile": "https://Stackoverflow.com/users/99691",
"pm_score": 4,
"selected": false,
"text": "if (Console.IsInputRedirected)\n{\n using(stream s = Console.OpenStandardInput())\n {\n ...\n"
},
{
"answer_id": 46964766,
"author": "Si Zi",
"author_id": 1970498,
"author_profile": "https://Stackoverflow.com/users/1970498",
"pm_score": 2,
"selected": false,
"text": "public static void Main()\n{\n List<string> salesLines = new List<string>();\n Console.InputEncoding = Encoding.UTF8;\n using (StreamReader reader = new StreamReader(Console.OpenStandardInput(), Console.InputEncoding))\n {\n string stdin;\n do\n {\n StringBuilder stdinBuilder = new StringBuilder();\n stdin = reader.ReadLine();\n stdinBuilder.Append(stdin);\n var lineIn = stdin;\n if (stdinBuilder.ToString().Trim() != \"\")\n {\n salesLines.Add(stdinBuilder.ToString().Trim());\n }\n\n } while (stdin != null);\n\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199528",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13913/"
] |
199,564
|
<p>My professor wrote this shell script to time my program, and display the results. For some reason it just outputs 0s with my program. He provided the following files:</p>
<pre><code>timeit.csh
sequence
ecoli2500.txt
ecoli3000.txt
ecoli5000.txt
ecoli7000.txt
ecoli8000.txt
ecoli9000.txt
ecoli10000.txt
</code></pre>
<p>Here are the contents of sequence</p>
<pre><code>java EditDistance
</code></pre>
<p>The contents of timeit.csh are further below.</p>
<p>java EditDistance < ecoli2500.txt works as expected</p>
<p>In fact the program executes flawlessly with each of the above files other than sequence.</p>
<p>What I don't understand is why </p>
<pre><code>./timeit.csh sequence
</code></pre>
<p>produces all zeros</p>
<p>Here is timeit.csh... (further below is EditDistance.java):</p>
<pre><code>#!/bin/csh
#
# A Unix script to time programs.
#
# Command line: timeit sequence
# the array of programs from the commandline
set program = $argv[1]
# adjust as needed
set CPULIMIT = 120
limit cpu $CPULIMIT seconds
limit core 0
# input files
set input = ( stx1230.txt \
ecoli2500.txt \
ecoli3000.txt \
ecoli5000.txt \
ecoli7000.txt \
ecoli8000.txt \
ecoli9000.txt \
ecoli10000.txt)
# adjust as needed
set inputpath = `pwd`
# print header
printf "CPU limit = %d seconds\n\n" $CPULIMIT
printf "%-25s" "Data File"
foreach program ($argv)
printf "%16s" $program
end
printf "\n"
# print right number of = for table
@ i = 25 + 16 * $#argv
while ($i > 0)
printf "="
@ i = $i - 1
end
printf "\n"
# time it and print out row for each data file and column for each program
foreach datafile ($input)
printf "%-25s" $datafile
if (-f $inputpath/$datafile) then
foreach program ($argv)
# printing running time of program on datafile
# -p flag with time to ensure its output is measured in seconds and not minutes
nice /usr/bin/time -p $program < \
$inputpath/$datafile |& \
egrep '^user[ ]*[0-9]' | \
awk '{ if ($2 >= '$CPULIMIT') printf " CPU limit"; else printf("%16.2f", $2) }'
# egrep, awk commands extract second column of row corresponding to user time
end
else printf "could not open" $datafile
endif
printf "\n"
end
</code></pre>
<p>Here is EditDistance.java</p>
<pre><code>import java.util.*;
class EditDistance {
public static int min(int a, int b, int c) {
return Math.min(a,Math.min(b,c));
}
public static int distance(String one, String two) {
if (one.length()>two.length()) {
String temp1 = one;
String temp2 = two;
one = temp2;
two = temp1;
}
int[][] d = new int[one.length()+1][two.length()+1];
d[0][0] = 0;
int top, left, topleft, cost;
for (int i = 1; i <= one.length(); i++) {
d[0][i] = 2*i;
d[i][0] = 2*i;
}
for (int i = 1; i <= one.length(); i++) {
for (int j = 1; j <= two.length(); j++) {
if (one.charAt(i-1) == two.charAt(j-1))
cost = 0;
else
cost = 1;
top = d[i][j-1];
left = d[i-1][j];
topleft = d[i-1][j-1];
d[i][j] = min(top+2,left+2,topleft+cost);
}
}
return d[one.length()][two.length()];
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String one = scanner.next();
String two = scanner.next();
System.out.println(distance(one,two));
}
}
</code></pre>
<p>Any Ideas why things aren't working? I don't know much about shell scripts, but this section of the shell script:</p>
<pre><code>nice /usr/bin/time -p $program < \
$inputpath/$datafile |& \
egrep '^user[ ]*[0-9]' | \
awk '{ if ($2 >= '$CPULIMIT') printf " CPU limit"; else printf("%16.2f", $2) }'
</code></pre>
<p>confirms in my mind that my program should be expecting this command: </p>
<pre><code>java EditDistance < ecoli2500.txt
java EditDistance...etc. etc.
</code></pre>
<p>but the program works with those commands. I need to set up my program to respond correctly to the shell script. Maybe some of you can help. </p>
|
[
{
"answer_id": 202628,
"author": "objectivesea",
"author_id": 27763,
"author_profile": "https://Stackoverflow.com/users/27763",
"pm_score": 1,
"selected": false,
"text": " nice /usr/bin/time -p $program < \n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
199,597
|
<p>I have a table ("venues") that stores all the possible venues a volunteer can work, each volunteer is assigned to work one venue each.</p>
<p>I want to create a select drop down from the venues table.</p>
<p>Right now I can display the venue each volunteer is assigned, but I want it to display the drop down box, with the venue already selected in the list.</p>
<pre><code><form action="upd.php?id=7">
<select name="venue_id">
<?php //some sort of loop goes here
print '<option value="'.$row['venue_id'].'">'.$row['venue_name'].'</option>';
//end loop here ?>
</select>
<input type="submit" value="submit" name="submit">
</form>
</code></pre>
<p>For example, volunteer with the id of 7, is assigned to venue_id 4</p>
<pre><code><form action="upd.php?id=7">
<select name="venue_id">
<option value="1">Bagpipe Competition</option>
<option value="2">Band Assistance</option>
<option value="3">Beer/Wine Pouring</option>
<option value="4" selected>Brochure Distribution</option>
<option value="5">Childrens Area</option>
<option value="6">Cleanup</option>
<option value="7">Cultural Center Display</option>
<option value="8">Festival Merch</option>
</select>
<input type="submit" value="submit" name="submit">
</form>
Brochure Distribution option will already be selected when it displays the drop down list, because in the volunteers_2009 table, column venue_id is 4.
</code></pre>
<p>I know it will take a form of a for or while loop to pull the list of venues from the venues table</p>
<p>My query is:</p>
<pre><code>$query = "SELECT volunteers_2009.id, volunteers_2009.comments, volunteers_2009.choice1, volunteers_2009.choice2, volunteers_2009.choice3, volunteers_2009.lname, volunteers_2009.fname, volunteers_2009.venue_id, venues.venue_name FROM volunteers_2009 AS volunteers_2009 LEFT OUTER JOIN venues ON (volunteers_2009.venue_id = venues.id) ORDER by $order $sort";
</code></pre>
<p>How do I populate the select drop down box with the venues (<strong>volunteers_2009.venue_id</strong>, <strong>venues.id</strong>) from the venues table and have it pre-select the venue in the list?</p>
|
[
{
"answer_id": 199614,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": true,
"text": "$query = \"SELECT volunteers_2009.id, volunteers_2009.comments, volunteers_2009.choice1, volunteers_2009.choice2, volunteers_2009.choice3, volunteers_2009.lname, volunteers_2009.fname, volunteers_2009.venue_id, venues.venue_name FROM volunteers_2009 AS volunteers_2009 LEFT OUTER JOIN venues ON (volunteers_2009.venue_id = venues.id) ORDER by $order $sort\";\n\n$res = mysql_query($query);\necho \"<select name = 'venue'>\";\nwhile (($row = mysql_fetch_row($res)) != null)\n{\n echo \"<option value = '{$row['venue_id']}'\";\n if ($selected_venue_id == $row['venue_id'])\n echo \"selected = 'selected'\";\n echo \">{$row['venue_name']}</option>\";\n}\necho \"</select>\";\n"
},
{
"answer_id": 199742,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "function displayDropDown($items, $name, $label, $default='') {\n if (count($items)) {\n echo '<select name=\"' . $name . '\">';\n echo '<option value=\"\">' . $label . '</option>';\n echo '<option value=\"\">----------</option>';\n foreach($items as $item) {\n $selected = ($item['id'] == $default) ? ' selected=\"selected\" : '';\n echo <option value=\"' . $item['id'] . '\"' . $selected . '>' . $item['name'] . '</option>';\n }\n echo '</select>';\n } else {\n echo 'There are no venues';\n }\n}\n"
},
{
"answer_id": 5611885,
"author": "duc14s",
"author_id": 375277,
"author_profile": "https://Stackoverflow.com/users/375277",
"pm_score": 2,
"selected": false,
"text": " <?php \n $query = \"SELECT * from blogcategory\";\n //$res = mysql_query($query);\n $rows = $db->query($query);\n echo \"<select name = 'venue'>\";\n // while (($row = mysql_fetch_row($res)) != null)\n while ($record = $db->fetch_array($rows)) \n {\n echo \"<option value = '{$record['CategoryId']}'\";\n if ($CategoryId == $record['CategoryId'])\n echo \"selected = 'selected'\";\n echo \">{$record['CategoryName']}</option>\";\n }\n echo \"</select>\";\n ?>\n"
},
{
"answer_id": 46338462,
"author": "Risheekant Vishwakarma",
"author_id": 7995612,
"author_profile": "https://Stackoverflow.com/users/7995612",
"pm_score": -1,
"selected": false,
"text": "<!DOCTYPE html>\n<html>\n<head>\n <title>table binding</title>\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>\n\n</head>\n<body>\n <div id=\"mydiv\" style=\"width:100px;height:100px;background-color:yellow\">\n\n <select id=\"myselect\"></select>\n </div>\n\n</body>\n</html>\n\n\n<?php\ninclude('dbconnection.php');\n\n$sql = \"SHOW TABLES FROM $dbname\";\n$result = mysqli_query($conn,$sql);\n\nif (!$result) {\n echo \"DB Error, could not list tables\\n\";\n echo 'MySQL Error: ' . mysqli_error();\n exit;\n}\n\nwhile ($row = mysqli_fetch_row($result)) {\n echo \"<script>\n var z = document.createElement('option');\n z.setAttribute('value', '\".$row[0].\"');\n var t = document.createTextNode('\".$row[0].\"');\n z.appendChild(t);\n document.getElementById('myselect').appendChild(z);</script>\";\n\n}\n\n\n\n?>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199597",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26130/"
] |
199,603
|
<p>I want to be able to write a lambda/Proc in my Ruby code, serialize it so that I can write it to disk, and then execute the lambda later. Sort of like...</p>
<pre><code>x = 40
f = lambda { |y| x + y }
save_for_later(f)
</code></pre>
<p>Later, in a separate run of the Ruby interpreter, I want to be able to say...</p>
<pre><code>f = load_from_before
z = f.call(2)
z.should == 42
</code></pre>
<p>Marshal.dump does not work for Procs. I know Perl has <a href="http://search.cpan.org/~yves/Data-Dump-Streamer-2.08-40/lib/Data/Dump/Streamer.pm" rel="nofollow noreferrer">Data::Dump::Streamer</a>, and in Lisp this is trivial. But is there a way to do it in Ruby? In other words, what would be the implementation of <code>save<code>_</code>for<code>_</code>later</code>?</p>
<p><strong>Edit</strong>: <a href="https://stackoverflow.com/questions/199603/how-do-you-stringize-serialize-ruby-code/199803#199803">My answer below</a> is nice, but it does not close over free variables (like <code>x</code>) and serialize them along with the lambda. So in my example ...</p>
<pre><code>x = 40
s = save_for_later { |y| x + y }
# => "lambda { |y|\n (x + y)\n}"
</code></pre>
<p>... the string output does not include a definition for <code>x</code>. Is there a solution that takes this into account, perhaps by serializing the symbol table? Can you access that in Ruby?</p>
<p><strong>Edit 2</strong>: I updated my answer to incorporate serializing local variables. This seems acceptable.</p>
|
[
{
"answer_id": 199803,
"author": "Jonathan Tran",
"author_id": 12887,
"author_profile": "https://Stackoverflow.com/users/12887",
"pm_score": 5,
"selected": true,
"text": "def save_for_later(&block)\n return nil unless block_given?\n\n c = Class.new\n c.class_eval do\n define_method :serializable, &block\n end\n s = Ruby2Ruby.translate(c, :serializable)\n s.sub(/^def \\S+\\(([^\\)]*)\\)/, 'lambda { |\\1|').sub(/end$/, '}')\nend\n\nx = 40\ns = save_for_later { |y| x + y }\n# => \"lambda { |y|\\n (x + y)\\n}\"\ng = eval(s)\n# => #<Proc:0x4037bb2c@(eval):1>\ng.call(2) \n# => 42\n"
},
{
"answer_id": 6072624,
"author": "Jonathan Tran",
"author_id": 12887,
"author_profile": "https://Stackoverflow.com/users/12887",
"pm_score": 4,
"selected": false,
"text": "def save_for_later(&block)\n block.to_source\nend\n\nx = 40\ns = save_for_later {|y| x + y }\n# => \"proc { |y| (x + y) }\"\ng = eval(s)\n# => #<Proc:0x00000100e88450@(eval):1>\ng.call(2) \n# => 42\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12887/"
] |
199,606
|
<p>C++ is mostly a superset of C, but not always. In particular, while enumeration values in both C and C++ implicitly convert into int, the reverse isn't true: only in C do ints convert back into enumeration values. Thus, bitflags defined via enumeration declarations don't work correctly. Hence, this is OK in C, but not in C++:</p>
<pre><code>typedef enum Foo
{
Foo_First = 1<<0,
Foo_Second = 1<<1,
} Foo;
int main(void)
{
Foo x = Foo_First | Foo_Second; // error in C++
return 0;
}
</code></pre>
<p>How should this problem be handled efficiently and correctly, ideally without harming the debugger-friendly nature of using Foo as the variable type (it decomposes into the component bitflags in watches etc.)?</p>
<p>Consider also that there may be hundreds of such flag enumerations, and many thousands of use-points. Ideally some kind of efficient operator overloading would do the trick, but it really ought to be efficient; the application I have in mind is compute-bound and has a reputation of being fast.</p>
<p>Clarification: I'm translating a large (>300K) C program into C++, so I'm looking for an efficient translation in both run-time and developer-time. Simply inserting casts in all the appropriate locations could take weeks.</p>
|
[
{
"answer_id": 199618,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 4,
"selected": true,
"text": "Foo x = Foo(Foo_First | Foo_Second);\n"
},
{
"answer_id": 199619,
"author": "ejgottl",
"author_id": 9808,
"author_profile": "https://Stackoverflow.com/users/9808",
"pm_score": 0,
"selected": false,
"text": "Foo x = static_cast<Foo>(Foo_First | Foo_Second); // not an error in C++\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199606",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3712/"
] |
199,612
|
<p>So far I've figured out how to pass Unicode strings, bSTRs, to and from a Euphoria DLL using a Typelib. What I can't figure out, thus far, is how to create and pass back an array of BSTRs.</p>
<p>The code I have thus far (along with <code>include</code>s for EuCOM itself and parts of Win32lib):</p>
<pre><code>global function REALARR()
sequence seq
atom psa
atom var
seq = { "cat","cow","wolverine" }
psa = create_safearray( seq, VT_BSTR )
make_variant( var, VT_ARRAY + VT_BSTR, psa )
return var
end function
</code></pre>
<p>Part of the typelib is:</p>
<pre><code> [
helpstring("get an array of strings"),
entry("REALARR")
]
void __stdcall REALARR( [out,retval] VARIANT* res );
</code></pre>
<p>And the test code, in VB6 is:</p>
<pre><code>...
Dim v() as String
V = REALARR()
...
</code></pre>
<p>So far all I've managed to get is an error '0' from the DLL. Any ideas? Anyone?</p>
|
[
{
"answer_id": 211288,
"author": "bugmagnet",
"author_id": 426,
"author_profile": "https://Stackoverflow.com/users/426",
"pm_score": 0,
"selected": false,
"text": "global function REALARR() \n atom psa \n atom var \n atom bounds_ptr \n atom dim \n atom bstr \n object void \n\n dim = 1 \n bounds_ptr = allocate( 8 * dim ) -- now figure out which part is Extent and which is LBound \n poke4( bounds_ptr, { 3, 0 } ) -- assuming Extent and LBound in that order \n\n psa = c_func( SafeArrayCreate, { VT_BSTR, 1, bounds_ptr } ) \n\n bstr = alloc_bstr( \"cat\" ) \n poke4( bounds_ptr, 0 ) \n void = c_func( SafeArrayPutElement, {psa, bounds_ptr, bstr}) \n free_bstr( bstr ) \n\n bstr = alloc_bstr( \"cow\" ) \n poke4( bounds_ptr, 1 ) \n void = c_func( SafeArrayPutElement, {psa, bounds_ptr, bstr}) \n free_bstr( bstr ) \n\n bstr = alloc_bstr( \"wolverine\" ) \n poke4( bounds_ptr, 2 ) \n void = c_func( SafeArrayPutElement, {psa, bounds_ptr, bstr}) \n free_bstr( bstr ) \n\n make_variant( var, VT_ARRAY + VT_BSTR, psa ) \n return var \nend function \n"
},
{
"answer_id": 218867,
"author": "bugmagnet",
"author_id": 426,
"author_profile": "https://Stackoverflow.com/users/426",
"pm_score": 0,
"selected": false,
"text": "var"
},
{
"answer_id": 1675812,
"author": "Matt Lewis",
"author_id": 28987,
"author_profile": "https://Stackoverflow.com/users/28987",
"pm_score": 2,
"selected": true,
"text": "create_safearray()"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/426/"
] |
199,624
|
<p>What is the best method of performing an scp transfer via the Java programming language? It seems I may be able to perform this via JSSE, JSch or the bouncy castle java libraries. None of these solutions seem to have an easy answer.</p>
|
[
{
"answer_id": 14034420,
"author": "Will",
"author_id": 557117,
"author_profile": "https://Stackoverflow.com/users/557117",
"pm_score": 3,
"selected": false,
"text": "// create secure context\nSecureContext context = new SecureContext(\"userName\", \"localhost\");\n\n// set optional security configurations.\ncontext.setTrustAllHosts(true);\ncontext.setPrivateKeyFile(new File(\"private/key\"));\n\n// Console requires JDK 1.7\n// System.out.println(\"enter password:\");\n// context.setPassword(System.console().readPassword());\n\nJscp.exec(context, \n \"src/dir\",\n \"destination/path\",\n // regex ignore list \n Arrays.asList(\"logs/log[0-9]*.txt\",\n \"backups\") \n );\n"
},
{
"answer_id": 17642899,
"author": "boomz",
"author_id": 1521765,
"author_profile": "https://Stackoverflow.com/users/1521765",
"pm_score": 0,
"selected": false,
"text": "/jar"
},
{
"answer_id": 18683734,
"author": "faisalbhagat",
"author_id": 1851358,
"author_profile": "https://Stackoverflow.com/users/1851358",
"pm_score": 1,
"selected": false,
"text": "JSch jsch=new JSch();\n Session session=jsch.getSession(user, host, 22);\n session.setPassword(\"password\");\n\n\n Properties config = new Properties();\n config.put(\"StrictHostKeyChecking\",\"no\");\n session.setConfig(config);\n session.connect();\n\n boolean ptimestamp = true;\n\n // exec 'scp -t rfile' remotely\n String command=\"scp \" + (ptimestamp ? \"-p\" :\"\") +\" -t \"+rfile;\n Channel channel=session.openChannel(\"exec\");\n ((ChannelExec)channel).setCommand(command);\n\n // get I/O streams for remote scp\n OutputStream out=channel.getOutputStream();\n InputStream in=channel.getInputStream();\n\n channel.connect();\n\n if(checkAck(in)!=0){\n System.exit(0);\n }\n\n File _lfile = new File(lfile);\n\n if(ptimestamp){\n command=\"T \"+(_lfile.lastModified()/1000)+\" 0\";\n // The access time should be sent here,\n // but it is not accessible with JavaAPI ;-<\n command+=(\" \"+(_lfile.lastModified()/1000)+\" 0\\n\");\n out.write(command.getBytes()); out.flush();\n if(checkAck(in)!=0){\n System.exit(0);\n }\n }\n"
},
{
"answer_id": 19572066,
"author": "Daniel Kaplan",
"author_id": 61624,
"author_profile": "https://Stackoverflow.com/users/61624",
"pm_score": 2,
"selected": false,
"text": " uk.co.marcoratto.scp.SCP scp = new uk.co.marcoratto.scp.SCP(new uk.co.marcoratto.scp.listeners.SCPListenerPrintStream());\n scp.setUsername(\"root\");\n scp.setPassword(\"blah\");\n scp.setTrust(true);\n scp.setFromUri(file.getAbsolutePath());\n scp.setToUri(\"root@host:/path/on/remote\");\n scp.execute();\n"
},
{
"answer_id": 19576270,
"author": "Eduardo Dennis",
"author_id": 1754020,
"author_profile": "https://Stackoverflow.com/users/1754020",
"pm_score": 1,
"selected": false,
"text": "import com.jcraft.jsch.*;\n public void downloadFtp(String userName, String password, String host, int port, String path) {\n\n\n Session session = null;\n Channel channel = null;\n try {\n JSch ssh = new JSch();\n JSch.setConfig(\"StrictHostKeyChecking\", \"no\");\n session = ssh.getSession(userName, host, port);\n session.setPassword(password);\n session.connect();\n channel = session.openChannel(\"sftp\");\n channel.connect();\n ChannelSftp sftp = (ChannelSftp) channel;\n sftp.get(path, \"specify path to where you want the files to be output\");\n } catch (JSchException e) {\n System.out.println(userName);\n e.printStackTrace();\n\n\n } catch (SftpException e) {\n System.out.println(userName);\n e.printStackTrace();\n } finally {\n if (channel != null) {\n channel.disconnect();\n }\n if (session != null) {\n session.disconnect();\n }\n }\n\n }\n"
},
{
"answer_id": 21000228,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "// scp myfile.txt localhost:/tmp\nFile file = new File(\"myfile.txt\");\nScp res = WaySSH.scp()\n .file(file)\n .toHost(\"localhost\")\n .at(\"/tmp\")\n .send();\n"
},
{
"answer_id": 29458428,
"author": "Fernando Santos",
"author_id": 4750095,
"author_profile": "https://Stackoverflow.com/users/4750095",
"pm_score": 3,
"selected": false,
"text": "// This make scp copy of \n// one local file to remote dir\n\norg.apache.tools.ant.taskdefs.optional.ssh.Scp scp = new Scp();\nint portSSH = 22;\nString srvrSSH = \"ssh.your.domain\";\nString userSSH = \"anyuser\"; \nString pswdSSH = new String ( jPasswordField1.getPassword() );\nString localFile = \"C:\\\\localfile.txt\";\nString remoteDir = \"/uploads/\";\n\nscp.setPort( portSSH );\nscp.setLocalFile( localFile );\nscp.setTodir( userSSH + \":\" + pswdSSH + \"@\" + srvrSSH + \":\" + remoteDir );\nscp.setProject( new Project() );\nscp.setTrust( true );\nscp.execute();\n"
},
{
"answer_id": 48333790,
"author": "Burt",
"author_id": 2542004,
"author_profile": "https://Stackoverflow.com/users/2542004",
"pm_score": 0,
"selected": false,
"text": "scpFile(\"192.168.1.1\", \"root\",\"password\",\"/tmp/1\",\"/tmp\");\n\npublic void scpFile(String host, String username, String password, String src, String dest) throws Exception {\n\n String[] scpCmd = new String[]{\"expect\", \"-c\", String.format(\"spawn scp -r %s %s@%s:%s\\n\", src, username, host, dest) +\n \"expect \\\"?assword:\\\"\\n\" +\n String.format(\"send \\\"%s\\\\r\\\"\\n\", password) +\n \"expect eof\"};\n\n ProcessBuilder pb = new ProcessBuilder(scpCmd);\n System.out.println(\"Run shell command: \" + Arrays.toString(scpCmd));\n Process process = pb.start();\n int errCode = process.waitFor();\n System.out.println(\"Echo command executed, any errors? \" + (errCode == 0 ? \"No\" : \"Yes\"));\n System.out.println(\"Echo Output:\\n\" + output(process.getInputStream()));\n if(errCode != 0) throw new Exception();\n}\n"
},
{
"answer_id": 57133202,
"author": "Eng.Fouad",
"author_id": 597657,
"author_profile": "https://Stackoverflow.com/users/597657",
"pm_score": 2,
"selected": false,
"text": "ScpUploader.java"
},
{
"answer_id": 58705126,
"author": "Saikat",
"author_id": 1594823,
"author_profile": "https://Stackoverflow.com/users/1594823",
"pm_score": 1,
"selected": false,
"text": "<dependency>\n <groupId>org.apache.ant</groupId>\n <artifactId>ant-jsch</artifactId>\n <version>${ant-jsch.version}</version>\n</dependency>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4229/"
] |
199,627
|
<p>How would you go about converting a reasonably large (>300K), fairly mature C codebase to C++?</p>
<p>The kind of C I have in mind is split into files roughly corresponding to modules (i.e. less granular than a typical OO class-based decomposition), using internal linkage in lieu private functions and data, and external linkage for public functions and data. Global variables are used extensively for communication between the modules. There is a very extensive integration test suite available, but no unit (i.e. module) level tests.</p>
<p>I have in mind a general strategy:</p>
<ol>
<li>Compile everything in C++'s C subset and get that working.</li>
<li>Convert modules into huge classes, so that all the cross-references are scoped by a class name, but leaving all functions and data as static members, and get that working.</li>
<li>Convert huge classes into instances with appropriate constructors and initialized cross-references; replace static member accesses with indirect accesses as appropriate; and get that working.</li>
<li>Now, approach the project as an ill-factored OO application, and write unit tests where dependencies are tractable, and decompose into separate classes where they are not; the goal here would be to move from one working program to another at each transformation.</li>
</ol>
<p>Obviously, this would be quite a bit of work. Are there any case studies / war stories out there on this kind of translation? Alternative strategies? Other useful advice?</p>
<p>Note 1: the program is a compiler, and probably millions of other programs rely on its behaviour not changing, so wholesale rewriting is pretty much not an option.</p>
<p>Note 2: the source is nearly 20 years old, and has perhaps 30% code churn (lines modified + added / previous total lines) per year. It is heavily maintained and extended, in other words. Thus, one of the goals would be to increase mantainability.</p>
<p>[For the sake of the question, assume that translation into <strong>C++</strong> is mandatory, and that leaving it in C is <strong>not</strong> an option. The point of adding this condition is to weed out the "leave it in C" answers.]</p>
|
[
{
"answer_id": 199911,
"author": "Head Geek",
"author_id": 12193,
"author_profile": "https://Stackoverflow.com/users/12193",
"pm_score": 5,
"selected": true,
"text": "struct"
},
{
"answer_id": 1351659,
"author": "Paul Biggar",
"author_id": 104021,
"author_profile": "https://Stackoverflow.com/users/104021",
"pm_score": 2,
"selected": false,
"text": "-Wc++-compat"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199627",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3712/"
] |
199,629
|
<p>I am working with an existing code base made up of some COM interfaces written in C++ with a C# front end. There is some new functionality that needs to be added, so I'm having to modify the COM portions. In one particular case, I need to pass an array (allocated from C#) to the component to be filled.</p>
<p>What I would like to do is to be able to pass an array of int to the method from C#, something like:</p>
<pre><code>// desired C# signature
void GetFoo(int bufferSize, int[] buffer);
// desired usage
int[] blah = ...;
GetFoo(blah.Length, blah);
</code></pre>
<p>A couple of wrenches in the works:</p>
<ul>
<li>C++/CLI or Managed C++ can't be used (COM could be done away with in this case).</li>
<li>The C# side can't be compiled with /unsafe (using Marshal is allowed).</li>
</ul>
<p>The COM interface is only used (an will only ever be used) by the C# part, so I'm less concerned with interoperability with other COM consumers. Portability between 32 and 64 bit is also not a concern (everything is being compiled and run from a 32 bit machine, so code generators are converting pointers to integers). Eventually, it will be replaced by just C++/CLI, but that is a ways off.</p>
<hr />
<h2>My initial attempt</h2>
<p>is something similar to:</p>
<pre><code>HRESULT GetFoo([in] int bufferSize, [in, size_is(bufferSize)] int buffer[]);
</code></pre>
<p>And the output TLB definition is (seems reasonable):</p>
<pre><code>HRESULT _stdcall GetFoo([in] int bufferSize, [in] int* buffer);
</code></pre>
<p>Which is imported by C# as (not so reasonable):</p>
<pre><code>void GetFoo(int bufferSize, ref int buffer);
</code></pre>
<p>Which I <em>could</em> use with</p>
<pre><code>int[] b = ...;
fixed(int *bp = &b[0])
{
GetFoo(b.Length, ref *bp);
}
</code></pre>
<p>...except that I can't compile with /unsafe.</p>
<hr />
<h2>At the moment</h2>
<p>I am using:</p>
<pre><code>HRESULT GetFoo([in] int bufferSize, [in] INT_PTR buffer);
</code></pre>
<p>Which imports as:</p>
<pre><code>void GetFoo(int bufferSize, int buffer);
</code></pre>
<p>And I need use use it like:</p>
<pre><code>int[] b = ...;
GCHandle bPin = GCHandle.Alloc(b, GCHandleType.Pinned);
try
{
GetFoo(b.Length, (int)Marshal.UnsafeAddrOfPinnedArrayElement(b, 0));
}
finally
{
bPin.Free();
}
</code></pre>
<p>Which works..., but I'd like to find a cleaner way.</p>
<hr />
<h2>So, the question is</h2>
<p>Is there an IDL definition that is friendly to the C# import from TLB generator for this case? If not, what can be done on the C# side to make it a little safer?</p>
|
[
{
"answer_id": 199767,
"author": "Corey Ross",
"author_id": 5927,
"author_profile": "https://Stackoverflow.com/users/5927",
"pm_score": 1,
"selected": true,
"text": "HRESULT GetFoo([in] int bufferSize, [in, size_is(bufferSize)] int buffer[]);\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199629",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5927/"
] |
199,642
|
<p>I have a combo box on a WinForms app in which an item may be selected, but it is not mandatory. I therefore need an 'Empty' first item to indicate that no value has been set.</p>
<p>The combo box is bound to a DataTable being returned from a stored procedure (I offer no apologies for Hungarian notation on my UI controls :p ):</p>
<pre><code> DataTable hierarchies = _database.GetAvailableHierarchies(cmbDataDefinition.SelectedValue.ToString()).Copy();//Calls SP
cmbHierarchies.DataSource = hierarchies;
cmbHierarchies.ValueMember = "guid";
cmbHierarchies.DisplayMember = "ObjectLogicalName";
</code></pre>
<p>How can I insert such an empty item?</p>
<p>I do have access to change the SP, but I would really prefer not to 'pollute' it with UI logic.</p>
<p><strong>Update:</strong> It was the DataTable.NewRow() that I had blanked on, thanks. I have upmodded you all (all 3 answers so far anyway). I am trying to get the Iterator pattern working before I decide on an 'answer'</p>
<p><strong>Update:</strong> I think this edit puts me in Community Wiki land, I have decided not to specify a single answer, as they all have merit in context of their domains. Thanks for your collective input.</p>
|
[
{
"answer_id": 199695,
"author": "Jason Jackson",
"author_id": 13103,
"author_profile": "https://Stackoverflow.com/users/13103",
"pm_score": 3,
"selected": false,
"text": "DataTable hierarchies = _database.GetAvailableHierarchies(cmbDataDefinition.SelectedValue.ToString()).Copy();//Calls SP\ncmbHierarchies.DataSource = GetDisplayTable(hierarchies);\ncmbHierarchies.ValueMember = \"guid\";\ncmbHierarchies.DisplayMember = \"ObjectLogicalName\";\n\n...\n\nprivate IEnumerable GetDisplayTable(DataTable tbl)\n{\n yield return new { ObjectLogicalName = string.Empty, guid = Guid.Empty };\n\n foreach (DataRow row in tbl.Rows)\n yield return new { ObjectLogicalName = row[\"ObjectLogicalName\"].ToString(), guid = (Guid)row[\"guid\"] };\n}\n"
},
{
"answer_id": 199715,
"author": "Vivek",
"author_id": 7418,
"author_profile": "https://Stackoverflow.com/users/7418",
"pm_score": 6,
"selected": true,
"text": "DataTable"
},
{
"answer_id": 796705,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "cmbHierarchies.SelectedIndex = -1;\n"
},
{
"answer_id": 3986674,
"author": "Vincent De Smet",
"author_id": 138469,
"author_profile": "https://Stackoverflow.com/users/138469",
"pm_score": 1,
"selected": false,
"text": "private IEnumerable<KeyValuePair<object,object>> GetDisplayTable(DataTable dataTable, DataColumn ValueMember, string sep,params DataColumn[] DisplayMembers)\n{\n yield return new KeyValuePair<object,object>(\"<ALL>\",null);\n\n if (DisplayMembers.Length < 1)\n throw new ArgumentException(\"At least 1 DisplayMember column is required\");\n\n foreach (DataRow r in dataTable.Rows)\n {\n StringBuilder sbDisplayMember = new StringBuilder();\n foreach(DataColumn col in DisplayMembers)\n {\n if (sbDisplayMember.Length > 0) sbDisplayMember.Append(sep);\n sbDisplayMember.Append(r[col]);\n }\n yield return new KeyValuePair<object, object>(sbDisplayMember.ToString(), r[ValueMember]);\n }\n}\n"
},
{
"answer_id": 6292182,
"author": "Ray",
"author_id": 579788,
"author_profile": "https://Stackoverflow.com/users/579788",
"pm_score": 2,
"selected": false,
"text": " DataTable dt = new DataTable();\n dt.Rows.Add();\n dt.AcceptChanges();\n ...\n dt.Fill(\"your query\");\n"
},
{
"answer_id": 11237746,
"author": "Trevor",
"author_id": 1487411,
"author_profile": "https://Stackoverflow.com/users/1487411",
"pm_score": 0,
"selected": false,
"text": "private void Form1_Load(object sender, EventArgs e)\n{ \n this.TableAdapter.Fill(this.dsListOfCampaigns.EvolveCampaignTargetListMasterInfo);\n this.comboCampaignID.SelectedIndex = -1;\n}\n"
},
{
"answer_id": 15813287,
"author": "Sujith Radhakrishnan",
"author_id": 1788322,
"author_profile": "https://Stackoverflow.com/users/1788322",
"pm_score": 0,
"selected": false,
"text": "\n this.recieptDateTimePicker.SelectedIndex = -1;\n"
},
{
"answer_id": 18127379,
"author": "Zen",
"author_id": 2637667,
"author_profile": "https://Stackoverflow.com/users/2637667",
"pm_score": 0,
"selected": false,
"text": " DataTable hierarchies = new DataTable(); \n\n cmbHierarchies.BeginUpdate();\n cmbHierarchies.ValueMember = this.Value;\n cmbHierarchies.DisplayMember = this.Display;\n hierarchies = DataView.ToTable();\n cmbHierarchies.DataSource = table;\n cmbHierarchies.EndUpdate();\n\n //Add empty row\n DataRow row = table.NewRow();\n table.Rows.InsertAt(row, 0);\n cmbHierarchies.SelectedIndex = 0;\n"
},
{
"answer_id": 26455969,
"author": "joshman1019",
"author_id": 3602084,
"author_profile": "https://Stackoverflow.com/users/3602084",
"pm_score": 0,
"selected": false,
"text": " Attorney_List_CB.DataSource = DA_Attorney_List.BS.DataSource;\n Attorney_List_CB.DisplayMember = \"Attorney Name\";\n Attorney_List_CB.SelectedIndex = -1; \n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5302/"
] |
199,651
|
<p>I'm looking for a generic "Row Picker" for JQuery.</p>
<p>We've all seen the cool "Picker" tools like date pickers, color pickers, time pickers, etc, where you click in a text box and a little calendar or color palate or clock or something comes up. You select something (like a date) and the text box is then populated with a value.</p>
<p>I really need an all-purpose "row picker" where you can populate something (a table, divs, etc) with some rows of data (say a list of timezones). This would be linked to a text field and would pop up when the user clicks in the field.</p>
<p>They would click a row (say a timezone), and the timezone id would be passed back to the field.</p>
<p>Anyone know of anything that does this? </p>
<p>Thanks!</p>
|
[
{
"answer_id": 199710,
"author": "Duncan",
"author_id": 25035,
"author_profile": "https://Stackoverflow.com/users/25035",
"pm_score": 3,
"selected": true,
"text": "<script type=\"text/javascript\"> $(function() {\n $('table#data_table tr').click(function() {\n alert($(this).find('td.id').html());\n }); }); \n</script>\n\n\n<table border=\"0\" id=\"data_table\">\n<tr>\n<td class=\"id\">45</td><td>GMT</td>\n</tr>\n<tr>\n<td class=\"id\">47</td><td>CST</td>\n</tr>\n</table>\n"
},
{
"answer_id": 200368,
"author": "redsquare",
"author_id": 6440,
"author_profile": "https://Stackoverflow.com/users/6440",
"pm_score": 2,
"selected": false,
"text": "$('#someTable').click(function(e) {\n var target = $(e.target);\n\n});\n"
},
{
"answer_id": 2704734,
"author": "Matchu",
"author_id": 107415,
"author_profile": "https://Stackoverflow.com/users/107415",
"pm_score": 0,
"selected": false,
"text": "select"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27580/"
] |
199,661
|
<p>I've used bash, csh, and tcsh. But I asked <a href="http://web.archive.org/web/20151121164806/http://stackoverflow.com/questions/198723/whats-in-your-cshrc" rel="nofollow noreferrer">this question</a>, and Jonathan informed me that csh isn't to be trusted. So what Linux shell is good for development. and why?</p>
|
[
{
"answer_id": 199835,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 4,
"selected": false,
"text": "vim"
},
{
"answer_id": 596823,
"author": "Jon Ericson",
"author_id": 1438,
"author_profile": "https://Stackoverflow.com/users/1438",
"pm_score": 1,
"selected": false,
"text": "ksh"
},
{
"answer_id": 11316202,
"author": "J. M. Becker",
"author_id": 645957,
"author_profile": "https://Stackoverflow.com/users/645957",
"pm_score": 2,
"selected": false,
"text": "sh"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6688/"
] |
199,665
|
<p>I have a SOAP client in Ruby that I'm trying to get working with a Ruby SOAP server, to no avail. The client works fine over SSL with a Python SOAP server, but not with the Ruby version. Here's what the server looks like:</p>
<pre><code>require 'soap/rpc/standaloneServer'
require 'soap/rpc/driver'
require 'rubygems'
require 'httpclient'
def cert(filename)
OpenSSL::X509::Certificate.new(File.open("path to cert.cert") { |f|
f.read
})
end
def key(filename)
OpenSSL::PKey::RSA.new(File.open("path to rsaprivate.key") { |f|
f.read
})
end
class Server < SOAP::RPC::HTTPServer
~code snipped for readability~
end
server = Server.new(:BindAddress => HelperFunctions.local_ip, :Port => 1234, :SSLCertificate => cert("path to cert"), :SSLPrivateKey => key("path to rsa private key"))
new_thread = Thread.new { server.start }
</code></pre>
<p>I've trimmed some of the code out for readability's sake (e.g., I have some methods in there I expose) and it works fine with SSL off. But when the client tries to connect, it sees this:</p>
<pre><code>warning: peer certificate won't be verified in this SSL session
/usr/lib/ruby/1.8/net/http.rb:567: warning: using default DH parameters.
/usr/lib/ruby/1.8/net/http.rb:586:in `connect': unknown protocol (OpenSSL::SSL::SSLError)
</code></pre>
<p>I tried taking some advice from <a href="https://stackoverflow.com/questions/128660/how-can-i-make-rubys-soaprpcdriver-work-with-self-signed-certificates">this post</a> and now I see this message:</p>
<pre><code>/usr/lib/ruby/1.8/soap/httpconfigloader.rb:64:in `set_ssl_config': SSL not supported (NotImplementedError)
</code></pre>
<p>Any ideas on how to fix this would be greatly appreciated.</p>
|
[
{
"answer_id": 199817,
"author": "Chris Bunch",
"author_id": 422,
"author_profile": "https://Stackoverflow.com/users/422",
"pm_score": 3,
"selected": true,
"text": "require 'webrick/https'\n"
},
{
"answer_id": 765311,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "server = Server.new(:BindAddress => HelperFunctions.local_ip, :Port => 1234, :SSLEnable => true, :SSLCertificate => cert(\"path to cert\"), :SSLPrivateKey => key(\"path to rsa private key\"))\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/422/"
] |
199,677
|
<p>I am trying to help someone write a program that I thought would be easy, but of course it never is :)</p>
<p>I am trying to take a class roster (usually between 10-20 students) and effectivly uniquely pair off each classmate to another to make unique groups. Therefore in a class of 10 people, you can have 9 groups.</p>
<p>It needs to be able to handle odd number of students too, adding to my confusion.</p>
<p>I was looking at doing this in Java, but that is flexible. Any ideas on an algorithmic way to guarantee a)not infinite looping (ending with 2 people who have already been partners) and b) I am aiming for more efficent time than space, since class size will be small!</p>
<p>Thanks!</p>
|
[
{
"answer_id": 199894,
"author": "Moishe Lettvin",
"author_id": 23786,
"author_profile": "https://Stackoverflow.com/users/23786",
"pm_score": 1,
"selected": false,
"text": "// create all the edges\nfor i := 1 to number_of_students - 1\n for j := i + 1 to number_of_students\n edges.add(new Edge(i,j))\n\n// select all groups from the edges\nfor x := 1 to number_of_students - 1\n used_nodes.clear\n group.clear\n\n for y := 1 to number_of_students div 2\n do\n current_edge = edges.get_next\n while (current_edge.n1 not in used_nodes) and\n (current_edge.n2 not in used_nodes)\n\n used_nodes.add(current_edge.n1)\n used_nodes.add(current_edge.n2)\n\n group.add(current_edge)\n\n edges.remove(current_edge)\n\n groups.add(group)\n"
},
{
"answer_id": 200272,
"author": "Jude Allred",
"author_id": 1388,
"author_profile": "https://Stackoverflow.com/users/1388",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\n\nnamespace Pairing\n{\n class Program\n {\n static void Main(string[] args)\n {\n //switch these lines if you'd prefer a command line interface to a text file.\n var rgs = File.ReadAllLines(\"Roster.txt\");\n //var rgs = args;\n\n var setPairs = new HashSet<HashSet<string>>();\n for (var ixrgs = 0; ixrgs < rgs.Length - 1; ixrgs++)\n for (var ixrgsSubset = ixrgs + 1; ixrgsSubset < rgs.Length; ixrgsSubset++)\n setPairs.Add(new HashSet<string>(new string[] { rgs[ixrgs], rgs[ixrgsSubset] }));\n\n var setGroups = new HashSet<HashSet<HashSet<string>>>();\n var setUsedPairs = new HashSet<HashSet<string>>();\n while (setPairs.Count > 0)\n {\n var setPairsTmp = new HashSet<HashSet<string>>(setPairs);\n var setTmp = new HashSet<HashSet<string>>();\n var setUsedVariables = new HashSet<string>();\n\n while (setPairsTmp.Count > 0)\n {\n //give me the first element\n var pair = setPairsTmp.First<HashSet<string>>();\n //store it\n setTmp.Add(pair);\n //add it to our set of used variables\n setUsedVariables.UnionWith(pair);\n //remove it from our set of available pairs.\n setPairsTmp.RemoveWhere(set => set.Intersect<string> (setUsedVariables).Count<string>() != 0);\n\n //remove its implicated deadlocks from our set of available pairs\n //(this step is both gross, and key. Without it, failure potential arises.)\n var s1 = new HashSet<string>();\n var s2 = new HashSet<string>();\n //get the set of variables paired with the first:\n var rgPair = pair.ToArray<string>();\n foreach (var set in setUsedPairs)\n {\n if (set.Contains(rgPair[0]))\n s1.UnionWith(set);\n if(set.Contains(rgPair[1]))\n s2.UnionWith(set);\n }\n s1.IntersectWith(s2);\n //enumerate the pairs created by the deadlocking pairs, remove them from our available selections.\n var rgsTmp = s1.ToArray<string>();\n for (var ixrgs = 0; ixrgs < rgsTmp.Length - 1; ixrgs++)\n for (var ixrgsSubset = ixrgs + 1; ixrgsSubset < rgsTmp.Length; ixrgsSubset++)\n setPairsTmp.RemoveWhere(set => set.Contains(rgsTmp[ixrgs]) && set.Contains(rgsTmp[ixrgsSubset]));\n }\n setPairs.ExceptWith(setTmp);\n setGroups.Add(setTmp);\n setUsedPairs.UnionWith(setTmp);\n }\n //at this point, setGroups contains the set of unique group combinations.\n //the non-maximally sized groups indicate unique sets that could form provided that\n //all other students are in redundant sets.\n\n var enumerableGroups = setGroups.OrderByDescending<HashSet<HashSet<string>>, int>(set => set.Count);\n //Sanity Check:\n foreach (var group in enumerableGroups)\n {\n Console.Write(\"{\");\n foreach (var pair in group)\n Console.Write(string.Format(@\"[{0},{1}]\", pair.ToArray<string>()));\n Console.WriteLine(\"}\");\n }\n }\n }\n}\n"
},
{
"answer_id": 55336988,
"author": "silentbat",
"author_id": 3986697,
"author_profile": "https://Stackoverflow.com/users/3986697",
"pm_score": 0,
"selected": false,
"text": "from itertools import permutations\n\ndef my_sort(x):\n assert type(x) in (tuple, list)\n assert len(x)==10\n groups = x[0:2],x[2:4],x[4:6],x[6:8],x[8:10]\n groups = sorted([sorted(g) for g in groups], key=lambda k:k[0])\n return tuple(x for g in groups for x in g )\n\nS = set(my_sort(p) for p in permutations(list(range(10))))\n\n\"\"\"\nlen(S) == 945\nlist(sorted(S))[-3:] == [(0, 9, 1, 8, 2, 7, 3, 4, 5, 6), (0, 9, 1, 8, 2, 7, 3, 5, 4, 6), (0, 9, 1, 8, 2, 7, 3, 6, 4, 5)]\n\"\"\"\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
199,687
|
<p>At the moment I use the <a href="http://msdn.microsoft.com/en-us/library/ms646310.aspx" rel="nofollow noreferrer"><code>SendInput()</code></a> function but if you install a low level mouse hook the <code>LLMHF_INJECTED</code> is set indicating that the input was injected into the stream. Is there a way of sending mouse and keyboard input so that <code>LLMHF_INJECTED</code> is not set?</p>
|
[
{
"answer_id": 199894,
"author": "Moishe Lettvin",
"author_id": 23786,
"author_profile": "https://Stackoverflow.com/users/23786",
"pm_score": 1,
"selected": false,
"text": "// create all the edges\nfor i := 1 to number_of_students - 1\n for j := i + 1 to number_of_students\n edges.add(new Edge(i,j))\n\n// select all groups from the edges\nfor x := 1 to number_of_students - 1\n used_nodes.clear\n group.clear\n\n for y := 1 to number_of_students div 2\n do\n current_edge = edges.get_next\n while (current_edge.n1 not in used_nodes) and\n (current_edge.n2 not in used_nodes)\n\n used_nodes.add(current_edge.n1)\n used_nodes.add(current_edge.n2)\n\n group.add(current_edge)\n\n edges.remove(current_edge)\n\n groups.add(group)\n"
},
{
"answer_id": 200272,
"author": "Jude Allred",
"author_id": 1388,
"author_profile": "https://Stackoverflow.com/users/1388",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.IO;\n\nnamespace Pairing\n{\n class Program\n {\n static void Main(string[] args)\n {\n //switch these lines if you'd prefer a command line interface to a text file.\n var rgs = File.ReadAllLines(\"Roster.txt\");\n //var rgs = args;\n\n var setPairs = new HashSet<HashSet<string>>();\n for (var ixrgs = 0; ixrgs < rgs.Length - 1; ixrgs++)\n for (var ixrgsSubset = ixrgs + 1; ixrgsSubset < rgs.Length; ixrgsSubset++)\n setPairs.Add(new HashSet<string>(new string[] { rgs[ixrgs], rgs[ixrgsSubset] }));\n\n var setGroups = new HashSet<HashSet<HashSet<string>>>();\n var setUsedPairs = new HashSet<HashSet<string>>();\n while (setPairs.Count > 0)\n {\n var setPairsTmp = new HashSet<HashSet<string>>(setPairs);\n var setTmp = new HashSet<HashSet<string>>();\n var setUsedVariables = new HashSet<string>();\n\n while (setPairsTmp.Count > 0)\n {\n //give me the first element\n var pair = setPairsTmp.First<HashSet<string>>();\n //store it\n setTmp.Add(pair);\n //add it to our set of used variables\n setUsedVariables.UnionWith(pair);\n //remove it from our set of available pairs.\n setPairsTmp.RemoveWhere(set => set.Intersect<string> (setUsedVariables).Count<string>() != 0);\n\n //remove its implicated deadlocks from our set of available pairs\n //(this step is both gross, and key. Without it, failure potential arises.)\n var s1 = new HashSet<string>();\n var s2 = new HashSet<string>();\n //get the set of variables paired with the first:\n var rgPair = pair.ToArray<string>();\n foreach (var set in setUsedPairs)\n {\n if (set.Contains(rgPair[0]))\n s1.UnionWith(set);\n if(set.Contains(rgPair[1]))\n s2.UnionWith(set);\n }\n s1.IntersectWith(s2);\n //enumerate the pairs created by the deadlocking pairs, remove them from our available selections.\n var rgsTmp = s1.ToArray<string>();\n for (var ixrgs = 0; ixrgs < rgsTmp.Length - 1; ixrgs++)\n for (var ixrgsSubset = ixrgs + 1; ixrgsSubset < rgsTmp.Length; ixrgsSubset++)\n setPairsTmp.RemoveWhere(set => set.Contains(rgsTmp[ixrgs]) && set.Contains(rgsTmp[ixrgsSubset]));\n }\n setPairs.ExceptWith(setTmp);\n setGroups.Add(setTmp);\n setUsedPairs.UnionWith(setTmp);\n }\n //at this point, setGroups contains the set of unique group combinations.\n //the non-maximally sized groups indicate unique sets that could form provided that\n //all other students are in redundant sets.\n\n var enumerableGroups = setGroups.OrderByDescending<HashSet<HashSet<string>>, int>(set => set.Count);\n //Sanity Check:\n foreach (var group in enumerableGroups)\n {\n Console.Write(\"{\");\n foreach (var pair in group)\n Console.Write(string.Format(@\"[{0},{1}]\", pair.ToArray<string>()));\n Console.WriteLine(\"}\");\n }\n }\n }\n}\n"
},
{
"answer_id": 55336988,
"author": "silentbat",
"author_id": 3986697,
"author_profile": "https://Stackoverflow.com/users/3986697",
"pm_score": 0,
"selected": false,
"text": "from itertools import permutations\n\ndef my_sort(x):\n assert type(x) in (tuple, list)\n assert len(x)==10\n groups = x[0:2],x[2:4],x[4:6],x[6:8],x[8:10]\n groups = sorted([sorted(g) for g in groups], key=lambda k:k[0])\n return tuple(x for g in groups for x in g )\n\nS = set(my_sort(p) for p in permutations(list(range(10))))\n\n\"\"\"\nlen(S) == 945\nlist(sorted(S))[-3:] == [(0, 9, 1, 8, 2, 7, 3, 4, 5, 6), (0, 9, 1, 8, 2, 7, 3, 5, 4, 6), (0, 9, 1, 8, 2, 7, 3, 6, 4, 5)]\n\"\"\"\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
199,692
|
<p>I have only a basic knowledge of css, is it possible to inherit a property from one style into another style. So for instance I could inherit the font size specified in my default paragrah tag settings into my hyperlink tags.</p>
<p>The reason I want to do this is to make it easier to maintain multiple styles.</p>
|
[
{
"answer_id": 199714,
"author": "leek",
"author_id": 3765,
"author_profile": "https://Stackoverflow.com/users/3765",
"pm_score": 4,
"selected": true,
"text": "p, a {\n font-size: 1em;\n}\n"
},
{
"answer_id": 199719,
"author": "timmfin",
"author_id": 27488,
"author_profile": "https://Stackoverflow.com/users/27488",
"pm_score": 2,
"selected": false,
"text": "<p class=\"first all\">Some text</p>\n<p class=\"all\">More text</p>\n<p class=\"last all\">Yet more text</p>\n\np.all { font-weight: bold }\np.first { color: red; }\np.last { color: blue; }\n"
},
{
"answer_id": 199722,
"author": "Jonathan Arkell",
"author_id": 11052,
"author_profile": "https://Stackoverflow.com/users/11052",
"pm_score": 1,
"selected": false,
"text": "h1, h2, h3, h4, h5 h6 { font-weight: normal; border: 1px solid #ff0; }\nh1 { font-size: 300%; }\n... etc ...\n"
},
{
"answer_id": 199724,
"author": "Joe Basirico",
"author_id": 20795,
"author_profile": "https://Stackoverflow.com/users/20795",
"pm_score": 0,
"selected": false,
"text": "#EEE"
},
{
"answer_id": 201585,
"author": "Traingamer",
"author_id": 27609,
"author_profile": "https://Stackoverflow.com/users/27609",
"pm_score": 0,
"selected": false,
"text": "* {\nmargin: 0 10px;\npadding:0;\nfont-size: 1 em;\n}\np, a { font-size: 75%; }\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16989/"
] |
199,718
|
<p>Since Object Initializers are very similar to JSON, and now there are Anonymous Types in .NET. It would be cool to be able to take a string, such as JSON, and create an Anonymous Object that represents the JSON string.</p>
<p>Use Object Initializers to create an Anonymous Type:</p>
<pre><code>var person = new {
FirstName = "Chris",
LastName = "Johnson"
};
</code></pre>
<p>It would be awesome if you could pass in a string representation of the Object Initializer code (preferably something like JSON) to create an instance of an Anonymous Type with that data.</p>
<p>I don't know if it's possible, since C# isn't dynamic, and the compiler actually converts the Object Initializer an<a href="http://www.developer.com/net/csharp/article.php/3589916" rel="noreferrer">d Anonymous Type into strongly typed code that can run. This is explained in</a> this article.</p>
<p>Maybe functionality to take JSON and create a key/value Dictionary with it would work best.</p>
<p>I know you can serialize/deserializer an object to JSON in .NET, but what I'm look for is a way to create an object that is essentially loosely typed, similarly to how JavaScript works.</p>
<p>Does anyone know the best solution for doing this in .NET?</p>
<p>UPDATE: Too clarify the context of why I'm asking this... I was thinking of how C# could better support JSON at the language level (possibly) and I was trying to think of ways that it could be done today, for conceptual reasons. So, I thought I'd post it here to start a discussion.</p>
|
[
{
"answer_id": 199797,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 4,
"selected": true,
"text": " T deserialize<T>(string jsonStr, T obj) { /* ... */}\n\n var jsonString = \"{FirstName='Chris', LastName='Johnson, Other='unused'}\";\n var person = deserialize(jsonString, new {FirstName=\"\",LastName=\"\"});\n var x = person.FirstName; //strongly-typed\n"
},
{
"answer_id": 199923,
"author": "Chris Pietschmann",
"author_id": 7831,
"author_profile": "https://Stackoverflow.com/users/7831",
"pm_score": 2,
"selected": false,
"text": "var obj = ParseJsonToDictionary(\"{FirstName: \\\"Chris\\\", \\\"Address\\\":{Street:\\\"My Street\\\",Number:123}}\");\n\n// Access the Address.Number value\nobject streetNumber = ((Dictionary<string, object>)obj[\"Address\"])[\"Number\"];\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199718",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7831/"
] |
199,723
|
<p>I found a wonderful open source Java program that I'm translating into C#. The built-in translator in Visual Studio got me started and I've now spent about a month translating the rest manually line by line. I've completed over 15,000 lines of translation and the only thing that remains is trying to figure out how to convert their MemoryImageSource stuff into C#/.NET.</p>
<p>What's the .NET equivalent way of implementing this stuff? Is there a native .NET library already?</p>
|
[
{
"answer_id": 199750,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 3,
"selected": true,
"text": "System.Drawing."
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/356/"
] |
199,728
|
<p>How do I set gc.reflogExpire so that items will never expire?<br>
What other time interval formats does it accept?</p>
<p>The man page says that you can set it to "90 days or 3 months," but doesn't specify what format it expects.</p>
|
[
{
"answer_id": 199927,
"author": "Aristotle Pagaltzis",
"author_id": 9410,
"author_profile": "https://Stackoverflow.com/users/9410",
"pm_score": 3,
"selected": false,
"text": "git reflog"
},
{
"answer_id": 202947,
"author": "CB Bailey",
"author_id": 19563,
"author_profile": "https://Stackoverflow.com/users/19563",
"pm_score": 5,
"selected": true,
"text": "git config gc.reflogExpire \"never\"\n"
},
{
"answer_id": 72538799,
"author": "sunyunxian",
"author_id": 11235640,
"author_profile": "https://Stackoverflow.com/users/11235640",
"pm_score": 1,
"selected": false,
"text": "git reflog expire --expire=180"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199728",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4883/"
] |
199,731
|
<p>How do you track outbound links for your web site, since the request is logged on the destination server, not yours? </p>
|
[
{
"answer_id": 33357842,
"author": "Justin Tanner",
"author_id": 609,
"author_profile": "https://Stackoverflow.com/users/609",
"pm_score": 2,
"selected": false,
"text": "target=\"_blank\""
},
{
"answer_id": 73474345,
"author": "Steffen Wenzel",
"author_id": 204558,
"author_profile": "https://Stackoverflow.com/users/204558",
"pm_score": 0,
"selected": false,
"text": "Fetch"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8161/"
] |
199,747
|
<p>Is there a standard way to see how much stack space your app has and what the highest watermark for stack usage is during a run?</p>
<p>Also in the dreaded case of actual overflow what happens? </p>
<p>Does it crash, trigger an exception or signal? Is there a standard or is it different on all systems and compilers?</p>
<p>I'm looking specifically for Windows, Linux and Macintosh. </p>
|
[
{
"answer_id": 199809,
"author": "jussij",
"author_id": 14738,
"author_profile": "https://Stackoverflow.com/users/14738",
"pm_score": 4,
"selected": false,
"text": "#include <stdio.h>\n#include <windows.h>\n\nvoid StackOverFlow()\n{\n CONTEXT context;\n\n // we are interested control registers\n context.ContextFlags = CONTEXT_CONTROL;\n\n // get the details\n GetThreadContext(GetCurrentThread(), &context);\n\n // print the stack pointer\n printf(\"Esp: %X\\n\", context.Esp);\n\n // this will eventually overflow the stack\n StackOverFlow();\n}\n\nDWORD ExceptionFilter(EXCEPTION_POINTERS *pointers, DWORD dwException)\n{\n return EXCEPTION_EXECUTE_HANDLER;\n}\n\nvoid main()\n{\n CONTEXT context;\n\n // we are interested control registers\n context.ContextFlags = CONTEXT_CONTROL;\n\n // get the details\n GetThreadContext(GetCurrentThread(), &context);\n\n // print the stack pointer\n printf(\"Esp: %X\\n\", context.Esp);\n\n __try\n {\n // cause a stack overflow\n StackOverFlow();\n }\n __except(ExceptionFilter(GetExceptionInformation(), GetExceptionCode()))\n {\n printf(\"\\n****** ExceptionFilter fired ******\\n\");\n }\n}\n"
},
{
"answer_id": 199813,
"author": "Kknd",
"author_id": 18403,
"author_profile": "https://Stackoverflow.com/users/18403",
"pm_score": 3,
"selected": false,
"text": "call stack:\n-----------\nreturn address\ndummy\nchar b[10]\nchar a[20]\n"
},
{
"answer_id": 201352,
"author": "adl",
"author_id": 27835,
"author_profile": "https://Stackoverflow.com/users/27835",
"pm_score": 4,
"selected": false,
"text": "ulimit -s"
},
{
"answer_id": 380393,
"author": "deemok",
"author_id": 23713,
"author_profile": "https://Stackoverflow.com/users/23713",
"pm_score": 3,
"selected": false,
"text": "_NT_TIB"
},
{
"answer_id": 1581369,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile": "https://Stackoverflow.com/users/41661",
"pm_score": 3,
"selected": false,
"text": "stackoverflow_install_handler"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13676/"
] |
199,761
|
<p><sup><strong>Note:</strong> This question was asked at a time when C# did not yet support optional parameters (i.e. before C# 4).</sup></p>
<p>We're building a web API that's programmatically generated from a C# class. The class has method <code>GetFooBar(int a, int b)</code> and the API has a method <code>GetFooBar</code> taking query params like <code>&a=foo &b=bar</code>. </p>
<p>The classes needs to support optional parameters, which isn't supported in C# the language. What's the best approach?</p>
|
[
{
"answer_id": 199765,
"author": "Kalid",
"author_id": 109,
"author_profile": "https://Stackoverflow.com/users/109",
"pm_score": 6,
"selected": false,
"text": "using System.Runtime.InteropServices;\npublic void Foo(int a, int b, [Optional] int c)\n{\n ...\n}\n"
},
{
"answer_id": 199770,
"author": "stephenbayer",
"author_id": 18893,
"author_profile": "https://Stackoverflow.com/users/18893",
"pm_score": 6,
"selected": false,
"text": "void GetFooBar(int a) { int defaultBValue; GetFooBar(a, defaultBValue); }\nvoid GetFooBar(int a, int b)\n{\n // whatever here\n}\n"
},
{
"answer_id": 199779,
"author": "Tim Jarvis",
"author_id": 10387,
"author_profile": "https://Stackoverflow.com/users/10387",
"pm_score": 7,
"selected": false,
"text": "public void DoSomething(params object[] theObjects)\n{\n foreach(object o in theObjects)\n {\n // Something with the Objects…\n }\n}\n"
},
{
"answer_id": 199790,
"author": "Vivek",
"author_id": 7418,
"author_profile": "https://Stackoverflow.com/users/7418",
"pm_score": 3,
"selected": false,
"text": "public void Foo(int a, int b, int? c)\n{\n if(c.HasValue)\n {\n // do something with a,b and c\n }\n else\n {\n // do something with a and b only\n } \n}\n"
},
{
"answer_id": 200719,
"author": "Hugh Allen",
"author_id": 15069,
"author_profile": "https://Stackoverflow.com/users/15069",
"pm_score": 4,
"selected": false,
"text": "using System;\nusing System.Runtime.InteropServices;\nusing System.Reflection;\n\nnamespace ConsoleApplication1\n{\n class Class1\n {\n public static void sayHelloTo(\n [Optional,\n DefaultParameterValue(\"world\")] string whom)\n {\n Console.WriteLine(\"Hello \" + whom);\n }\n\n [STAThread]\n static void Main(string[] args)\n {\n MethodInfo mi = typeof(Class1).GetMethod(\"sayHelloTo\");\n mi.Invoke(null, new Object[] { Missing.Value });\n }\n }\n}\n"
},
{
"answer_id": 1746099,
"author": "Ron K",
"author_id": 212541,
"author_profile": "https://Stackoverflow.com/users/212541",
"pm_score": 0,
"selected": false,
"text": "[WebMethod]\npublic string Foo(string arg1, XmlNode optarg2)\n{\n string arg2 = \"\";\n if (optarg2 != null)\n {\n arg2 = optarg2.Value;\n }\n ... etc\n}\n"
},
{
"answer_id": 3343769,
"author": "Alex from Jitbit",
"author_id": 56621,
"author_profile": "https://Stackoverflow.com/users/56621",
"pm_score": 11,
"selected": true,
"text": "public void SomeMethod(int a, int b = 0)\n{\n //some code\n}\n"
},
{
"answer_id": 5076579,
"author": "kristi_io",
"author_id": 1646259,
"author_profile": "https://Stackoverflow.com/users/1646259",
"pm_score": 5,
"selected": false,
"text": "int MyMetod(int param1, int param2, int param3=10, int param4=20){....}\n"
},
{
"answer_id": 6100565,
"author": "baskinhu",
"author_id": 766403,
"author_profile": "https://Stackoverflow.com/users/766403",
"pm_score": 3,
"selected": false,
"text": "class myClass\n{\n public myClass(int myInt = 1, string myString =\n \"wow, this is cool: i can have a default string\")\n {\n // do something here if needed\n }\n}\n"
},
{
"answer_id": 27374682,
"author": "user2933082",
"author_id": 2933082,
"author_profile": "https://Stackoverflow.com/users/2933082",
"pm_score": 2,
"selected": false,
"text": "GetFooBar(int a)"
},
{
"answer_id": 29820290,
"author": "SteakOverflow",
"author_id": 802435,
"author_profile": "https://Stackoverflow.com/users/802435",
"pm_score": 5,
"selected": false,
"text": "public void PrintValues(int? a = null, int? b = null, float? c = null, string s = \"\")\n{\n if(a.HasValue)\n Console.Write(a);\n else\n Console.Write(\"-\");\n\n if(b.HasValue)\n Console.Write(b);\n else\n Console.Write(\"-\");\n\n if(c.HasValue)\n Console.Write(c);\n else\n Console.Write(\"-\");\n\n if(string.IsNullOrEmpty(s)) // Different check for strings\n Console.Write(s);\n else\n Console.Write(\"-\");\n}\n"
},
{
"answer_id": 30893531,
"author": "CodeArtist",
"author_id": 1843190,
"author_profile": "https://Stackoverflow.com/users/1843190",
"pm_score": 0,
"selected": false,
"text": "delegate"
},
{
"answer_id": 49442384,
"author": "Ankit Panwar",
"author_id": 2042974,
"author_profile": "https://Stackoverflow.com/users/2042974",
"pm_score": -1,
"selected": false,
"text": "public void YourMethod(int a=0, int b = 0)\n {\n //some code\n }"
},
{
"answer_id": 57903337,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": " private void GetVal(string sName, int sRoll)\n {\n if (sRoll > 0)\n {\n // do some work\n }\n }\n\n private void GetVal(string sName)\n {\n GetVal(\"testing\", 0);\n }\n"
},
{
"answer_id": 58060016,
"author": "Sharunas Bielskis",
"author_id": 4403269,
"author_profile": "https://Stackoverflow.com/users/4403269",
"pm_score": 0,
"selected": false,
"text": "namespace OptionalParameterWithOptionalAttribute\n{\n class Program\n {\n static void Main(string[] args)\n {\n //Calling the helper method Hello only with required parameters\n Hello(\"Vardenis\", \"Pavardenis\");\n //Calling the helper method Hello with required and optional parameters\n Hello(\"Vardenis\", \"Pavardenis\", \"Palanga\");\n }\n public static void Hello(string firstName, string secondName, \n [System.Runtime.InteropServices.OptionalAttribute] string fromCity)\n {\n string result = firstName + \" \" + secondName;\n if (fromCity != null)\n {\n result += \" from \" + fromCity;\n }\n Console.WriteLine(\"Hello \" + result);\n }\n\n }\n}\n"
},
{
"answer_id": 61372049,
"author": "Ryan",
"author_id": 13383975,
"author_profile": "https://Stackoverflow.com/users/13383975",
"pm_score": 1,
"selected": false,
"text": "Dictionary<string,Object>"
},
{
"answer_id": 63138018,
"author": "Sean Franklin",
"author_id": 10529399,
"author_profile": "https://Stackoverflow.com/users/10529399",
"pm_score": 1,
"selected": false,
"text": "public void OptionalParameters(int requerid, int optinal = default){}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/109/"
] |
199,769
|
<p>I'm on a Hardy Heron Ubuntu build, BTW.</p>
|
[
{
"answer_id": 201055,
"author": "pk.",
"author_id": 10615,
"author_profile": "https://Stackoverflow.com/users/10615",
"pm_score": 1,
"selected": false,
"text": "Enable the use of the mouse. Only works for certain terminals\n(xterm, MS-DOS, Win32 |win32-mouse|, qnx pterm, and Linux console\nwith gpm). For using the mouse in the GUI, see |gui-mouse|.\nThe mouse can be enabled for different modes:\n n Normal mode\n v Visual mode\n i Insert mode\n c Command-line mode\n h all previous modes when editing a help file\n a all previous modes\n r for |hit-enter| and |more-prompt| prompt\n A auto-select in Visual mode\nNormally you would enable the mouse in all four modes with: >\n :set mouse=a\nWhen the mouse is not enabled, the GUI will still use the mouse for\nmodeless selection. This doesn't move the text cursor.\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199769",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20273/"
] |
199,774
|
<p>I'm trying to get a postgres jdbc connection working in eclipse. It would be nice to use the Data Source Explorer, but for now I'm just trying to get a basic connection. What I have done so far is download the postgres JDBC connector. I then tried two different things. First, Preferences-> Data Management, I tried to add the postgres connector. Second, I added the jar to my project and tried to load the driver using Class.forName("org.postgresql.Driver"); but neither worked. Does anyone have any ideas?</p>
<p>Thanks,
Charlie</p>
|
[
{
"answer_id": 211512,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "org.postgresql.ds.PGSimpleDataSource"
},
{
"answer_id": 214750,
"author": "eflles",
"author_id": 26567,
"author_profile": "https://Stackoverflow.com/users/26567",
"pm_score": 4,
"selected": false,
"text": "Java build path"
},
{
"answer_id": 15044459,
"author": "jsina",
"author_id": 1734778,
"author_profile": "https://Stackoverflow.com/users/1734778",
"pm_score": 0,
"selected": false,
"text": " <property name=\"javax.persistence.jdbc.driver\" value=\"org.postgresql.Driver\"/>\n <property name=\"javax.persistence.jdbc.url\" value=\"jdbc:postgresql://localhost:5432/yourDataBaseName\"/>\n <property name=\"javax.persistence.jdbc.user\" value=\"postgres\"/>\n <property name=\"javax.persistence.jdbc.password\" value=\"yourPassword\"/>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199774",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27689/"
] |
199,792
|
<p>I can no longer use / at the windows xp command prompt, and it seems to have started after a botched cygwin installation, e.g. cd /windows won't work, but used to.</p>
<p>Can anyone think of how this might have happened?</p>
<p><strong>OOPS! It doesn't normally work in XP</strong>, though I had read that it does in Vista. I simplified my problem and it was wrong. <strong>The real problem is:</strong></p>
<p>I was using the cwrsync binaries (meant for cygwin use) that can be used at the command prompt in a way such as: </p>
<blockquote>
<p>ssh -i /keydir/keyfile user@server</p>
</blockquote>
<p>but after doing something (seems like it was installing cygwin), and even after reinstalling the cwrsync files, I can now only do:</p>
<blockquote>
<p>ssh -i \keydir\keyfile user@server, i.e. I have to use the windows convention when referring to local files.</p>
</blockquote>
<p>I posted this on the cwrsync forum, but it's not very active, so I was hoping someone might recognize what's going on here, I should maybe try the cygwin forum too.</p>
|
[
{
"answer_id": 200075,
"author": "Hugh Allen",
"author_id": 15069,
"author_profile": "https://Stackoverflow.com/users/15069",
"pm_score": 1,
"selected": false,
"text": "C:\\"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23119/"
] |
199,823
|
<p>I am looking out for some good practices on naming assemblies and versioning them. How often do you increment the major or minor versions?</p>
<p>In some cases, I have seen releases going straight from version 1.0 to 3.0. In other cases, it seems to be stuck at version 1.0.2.xxxx.</p>
<p>This will be for a shared assembly used in multiple projects across the company. Looking forward to some good inputs.</p>
|
[
{
"answer_id": 199844,
"author": "Scott Dorman",
"author_id": 1559,
"author_profile": "https://Stackoverflow.com/users/1559",
"pm_score": 3,
"selected": false,
"text": "CompanyName.Framework.Core \n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4337/"
] |
199,832
|
<p>Is there a way I can control columns from code. </p>
<p>I had a drop drop box with select : Daily and weekend and the gridview column with Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,sunday.
If the user selects Daily i want to show columns only from Monday to Friday.</p>
<p>It is possible to control from the code. Oh i am using this griview in my webpage and coding in done using C#. </p>
<p>help!</p>
|
[
{
"answer_id": 199946,
"author": "Pavel Chuchuva",
"author_id": 14131,
"author_profile": "https://Stackoverflow.com/users/14131",
"pm_score": 4,
"selected": true,
"text": "GridView1.Columns[5].Visible = false\nGridView1.Columns[6].Visible = false\n"
},
{
"answer_id": 199956,
"author": "Matt",
"author_id": 4154,
"author_profile": "https://Stackoverflow.com/users/4154",
"pm_score": 1,
"selected": false,
"text": "theGridview.Columns[0].Visible = false;\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199832",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14752/"
] |
199,847
|
<p>I have the following fields:</p>
<ul>
<li>Inventory control (16 byte record)
<ul>
<li>Product ID code (int – 4 bytes)</li>
<li>Quantity in stock (int – 4 bytes)</li>
<li>Price (double – 8 bytes)</li>
</ul></li>
</ul>
<p>How do I create a fixed length random access file using the above lengths? I tried some examples online, but I either get an EOF exception or random address values when I try to access them.</p>
<p>I tried some more examples and couldn't understand the concept very well. I'm trying a project with it and will try to explore more on it.</p>
<p>Here is some example data. There might be holes in the data where <code>No. in stock</code> could be <code>23 == 023</code>.</p>
<pre><code> Quantity
ID. No. In Stock Price
------- -------- ------
1001 476 $28.35
1002 240 $32.56
1003 517 $51.27
1004 284 $23.75
1005 165 $32.25
</code></pre>
<p>Thanks for the help.</p>
|
[
{
"answer_id": 199954,
"author": "Aaron Maenpaa",
"author_id": 2603,
"author_profile": "https://Stackoverflow.com/users/2603",
"pm_score": 4,
"selected": true,
"text": "package test;\n\nimport java.io.IOException;\nimport java.io.RandomAccessFile;\n\npublic class Raf {\n private static class Record{\n private final double price;\n private final int id;\n private final int stock;\n\n public Record(int id, int stock, double price){\n this.id = id;\n this.stock = stock;\n this.price = price;\n }\n\n public void pack(int n, int offset, byte[] array){\n array[offset + 0] = (byte)(n & 0xff);\n array[offset + 1] = (byte)((n >> 8) & 0xff);\n array[offset + 2] = (byte)((n >> 16) & 0xff);\n array[offset + 3] = (byte)((n >> 24) & 0xff);\n }\n\n public void pack(double n, int offset, byte[] array){\n long bytes = Double.doubleToRawLongBits(n);\n pack((int) (bytes & 0xffffffff), offset, array);\n pack((int) ((bytes >> 32) & 0xffffffff), offset + 4, array);\n }\n\n public byte[] getBytes() {\n byte[] record = new byte[16];\n pack(id, 0, record);\n pack(stock, 4, record);\n pack(price, 8, record);\n return record;\n }\n }\n\n private static final int RECORD_SIZE = 16;\n private static final int N_RECORDS = 1024;\n\n /**\n * @param args\n * @throws IOException \n */\n public static void main(String[] args) throws IOException {\n RandomAccessFile raf = new RandomAccessFile(args[0], \"rw\");\n try{\n raf.seek(RECORD_SIZE * N_RECORDS);\n\n raf.seek(0);\n\n raf.write(new Record(1001, 476, 28.35).getBytes());\n raf.write(new Record(1002, 240, 32.56).getBytes());\n } finally {\n raf.close();\n }\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21968/"
] |
199,866
|
<p>I am just starting out with Silverlight (2 RC0) and can’t seem to get the following to work. I want to create a simple image button user control.</p>
<p>My xaml for the user control is as follows:</p>
<pre><code> <Button>
<Button.Template>
<ControlTemplate>
<Image Source="{TemplateBinding ImageSource}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" />
</ControlTemplate>
</Button.Template>
</Button>
</code></pre>
<p>The code behind is as follows:</p>
<pre><code>public partial class ImageButtonUserControl : UserControl
{
public ImageButtonUserControl()
{
InitializeComponent();
}
public Image Source
{
get { return base.GetValue(SourceProperty) as Image; }
set { base.SetValue(SourceProperty, value); }
}
public static readonly DependencyProperty SourceProperty =
DependencyProperty.Register("SourceProperty", typeof(Image), typeof(ImageButtonUserControl),null);
}
</code></pre>
<p>I want to be able to dynamically create the ImageButtons and stuff them in a container like a WrapPanel:
Assume we have an image named “image” already:</p>
<pre><code>ImageButtonUserControl imageButton = new ImageButtonUserControl();
imageButton.Source = image;
this.thumbnailStackPanel.Children.Add(imageButton);
</code></pre>
<p>What do I need to do to get the image to display? I'm assuming I need to do something with DataContext, but I'm not quite sure what or where.</p>
<p>Thanks for any help</p>
|
[
{
"answer_id": 200013,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": 4,
"selected": true,
"text": " <ControlTemplate x:Key=\"btn_template\"> \n <Image Source=\"{TemplateBinding Content}\" /> \n </ControlTemplate>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199866",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67719/"
] |
199,876
|
<p>Is there a way to change the color of the background for a MDIParent windows in MFC (2005)?</p>
<p>I have tried intercepting ON_WM_CTLCOLOR AND ON_WM_ERASEBKGND but neither work. OnEraseBkgnd does work, but then it gets overwritten by the standard WM_CTL color.</p>
<p>Cheers</p>
|
[
{
"answer_id": 200780,
"author": "Aidan Ryan",
"author_id": 1042,
"author_profile": "https://Stackoverflow.com/users/1042",
"pm_score": 2,
"selected": false,
"text": "afx_msg BOOL OnEraseBkgnd(CDC* pDC);\nafx_msg void OnPaint(void);\nafx_msg void OnSize(UINT nType, int cx, int cy);\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199876",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1075/"
] |
199,879
|
<p>I have a div that contains several child elements, one of which is a flash movie.</p>
<p>When rolling over this div, I want it to change style to indicate it is rolled over. My problem is that the <code>mouseover</code> and <code>mouseout</code> events don't always trigger, especially if the user moves the mouse over the flash element too quickly.</p>
<p>Any suggestions for how I can ensure that a <code>mouseover</code> event always get triggered.</p>
<p>I can't add an event to the flash movie itself because it is proprietary code that I don't have the source for.</p>
<p>Also I can't cover the flash movie in a div/image because I need rollover and click events to occur within the flash itself.</p>
|
[
{
"answer_id": 200026,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 1,
"selected": false,
"text": "onmouseover"
},
{
"answer_id": 223568,
"author": "Claudio",
"author_id": 30122,
"author_profile": "https://Stackoverflow.com/users/30122",
"pm_score": 2,
"selected": false,
"text": "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia\n.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"800\" height=\"600\">\n <param name=\"movie\" value=\"movie.swf\">\n <param name=\"wmode\" value=\"opaque\">\n <embed src=\"movie.swf\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"800\" height=\"600\"></embed>\n</object>\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199879",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20851/"
] |
199,889
|
<p>I'm trying to do a domain lookup in vba with something like this:</p>
<pre><code>DLookup("island", "villages", "village = '" & txtVillage & "'")
</code></pre>
<p>This works fine until txtVillage is something like Dillon's Bay, when the apostrophe is taken to be a single quote, and I get a run-time error.</p>
<p>I've written a trivial function that escapes single quotes - it replaces "'" with "''". This seems to be something that comes up fairly often, but I can't find any reference to a built-in function that does the same. Have I missed something?</p>
|
[
{
"answer_id": 199900,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 2,
"selected": false,
"text": "'); DROP TABLE [YourTable]\n"
},
{
"answer_id": 199904,
"author": "inglesp",
"author_id": 10439,
"author_profile": "https://Stackoverflow.com/users/10439",
"pm_score": 0,
"selected": false,
"text": "Public Function EscapeQuotes(s As String) As String\n\n If s = \"\" Then\n EscapeQuotes = \"\"\n ElseIf Left(s, 1) = \"'\" Then\n EscapeQuotes = \"''\" & EscapeQuotes(Mid(s, 2))\n Else\n EscapeQuotes = Left(s, 1) & EscapeQuotes(Mid(s, 2))\n End If\n\nEnd Function\n"
},
{
"answer_id": 199913,
"author": "Matt",
"author_id": 4154,
"author_profile": "https://Stackoverflow.com/users/4154",
"pm_score": 6,
"selected": true,
"text": "DLookup(\"island\", \"villages\", \"village = '\" & Replace(txtVillage, \"'\", \"''\") & \"'\")\n"
},
{
"answer_id": 199916,
"author": "Rob Gray",
"author_id": 5691,
"author_profile": "https://Stackoverflow.com/users/5691",
"pm_score": 1,
"selected": false,
"text": "DLookup(\"island\", \"villages\", \"village = \" & chr$(34) & nonEscapedString & chr$(34))\n"
},
{
"answer_id": 200336,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 2,
"selected": false,
"text": "SELECT FIRST(island)\nFROM villages\nWHERE village = ?;\n"
},
{
"answer_id": 2331175,
"author": "niceboomer",
"author_id": 280855,
"author_profile": "https://Stackoverflow.com/users/280855",
"pm_score": 0,
"selected": false,
"text": "Replace(result, \"'\", \"''\", , , vbBinaryCompare)\n"
},
{
"answer_id": 15821856,
"author": "keith b",
"author_id": 2246805,
"author_profile": "https://Stackoverflow.com/users/2246805",
"pm_score": 0,
"selected": false,
"text": "DLookup(\"island\", \"villages\", \"village = '[\" & txtVillage & \"]'\")\n"
},
{
"answer_id": 17115002,
"author": "dubi",
"author_id": 2487209,
"author_profile": "https://Stackoverflow.com/users/2487209",
"pm_score": -1,
"selected": false,
"text": "Dim sSQL as String\nsSQL=\"SELECT * FROM tblTranslation WHERE fldEnglish='\" & myString & \"';\"\n"
},
{
"answer_id": 17170883,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "sSQL = \"SELECT * FROM tblTranslation WHERE fldEnglish=\"\"\" & myString & \"\"\";\"\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199889",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10439/"
] |
199,896
|
<p>As the title: How would I tell NHibernate, once and for all, that all table and column names are to be quoted in the SQL it generates?</p>
|
[
{
"answer_id": 2883057,
"author": "pvasek",
"author_id": 1185225,
"author_profile": "https://Stackoverflow.com/users/1185225",
"pm_score": 2,
"selected": false,
"text": "<property name=\"hbm2ddl.keywords\">auto-quote</property>\n"
},
{
"answer_id": 6339548,
"author": "Newbie",
"author_id": 49881,
"author_profile": "https://Stackoverflow.com/users/49881",
"pm_score": 3,
"selected": false,
"text": "SchemaMetadataUpdater.QuoteTableAndColumns(configuration);\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199896",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12349/"
] |
199,905
|
<p>Is it possible to add comments somehow, somewhere? </p>
<p>I don't pretend to be any sort of expert when using MySQL and certainly don't spend all day in it. More often than I would like I forget how I intend to use a column (usally the bit ones) and would be very excited if I could add a comment to remind me if 1 is good or bad, for example. </p>
<p>I'd be happy if it only showed up in something like 'show create table', but any obscure place within the table structures would be better and easier to find than the current post-it notes on my desk.</p>
|
[
{
"answer_id": 199920,
"author": "micahwittman",
"author_id": 11181,
"author_profile": "https://Stackoverflow.com/users/11181",
"pm_score": 5,
"selected": false,
"text": "table_option:\n {ENGINE|TYPE} [=] engine_name\n | AUTO_INCREMENT [=] value\n | AVG_ROW_LENGTH [=] value\n | [DEFAULT] CHARACTER SET [=] charset_name\n | CHECKSUM [=] {0 | 1}\n | [DEFAULT] COLLATE [=] collation_name\n | COMMENT [=] 'string'\n"
},
{
"answer_id": 199921,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 4,
"selected": false,
"text": "create table example (field1 char(3) comment 'first field') comment='example table'\n"
},
{
"answer_id": 200033,
"author": "Gary Richardson",
"author_id": 2506,
"author_profile": "https://Stackoverflow.com/users/2506",
"pm_score": 5,
"selected": false,
"text": "CREATE TABLE example (\n example_column INT COMMENT \"This is an example column\",\n another_column VARCHAR COMMENT \"One more column\"\n) TYPE=MYISAM COMMENT=\"This is a comment about table\";\n"
},
{
"answer_id": 21152921,
"author": "Brad Kent",
"author_id": 1371433,
"author_profile": "https://Stackoverflow.com/users/1371433",
"pm_score": 3,
"selected": false,
"text": "SHOW FULL COLUMNS FROM mytable"
},
{
"answer_id": 59830571,
"author": "Hebe",
"author_id": 7516009,
"author_profile": "https://Stackoverflow.com/users/7516009",
"pm_score": 2,
"selected": false,
"text": "CREATE TABLE `example` (\n`id` int(11) NOT NULL,\n`two` varchar(255) COMMENT \"comment text\",\nPRIMARY KEY (`id`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n"
},
{
"answer_id": 65336898,
"author": "Binh Ho",
"author_id": 9585130,
"author_profile": "https://Stackoverflow.com/users/9585130",
"pm_score": 0,
"selected": false,
"text": "CREATE TABLE `table_with_comment` (\n `id` int(11) NOT NULL,\n `column_a` varchar(255) DEFAULT NULL COMMENT 'comment comlumn text',\n PRIMARY KEY (`id`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='This is a table comment';\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1444/"
] |
199,918
|
<p>I have been trying to explain the difference between switch statements and pattern matching(F#) to a couple of people but I haven't really been able to explain it well..most of the time they just look at me and say "so why don't you just use if..then..else".</p>
<p>How would you explain it to them? </p>
<p>EDIT! Thanks everyone for the great answers, I really wish I could mark multiple right answers. </p>
|
[
{
"answer_id": 200277,
"author": "Bruno De Fraine",
"author_id": 6918,
"author_profile": "https://Stackoverflow.com/users/6918",
"pm_score": 5,
"selected": false,
"text": "type expr =\n | Int of int\n | Var of string\n | Add of expr * expr\n | Mul of expr * expr;;\n\nlet rec d(f, x) =\n match f with\n | Var y when x=y -> Int 1\n | Int _ | Var _ -> Int 0\n | Add(f, g) -> Add(d(f, x), d(g, x))\n | Mul(f, g) -> Add(Mul(f, d(g, x)), Mul(g, d(f, x)));;\n"
},
{
"answer_id": 4606114,
"author": "Yttrill",
"author_id": 518287,
"author_profile": "https://Stackoverflow.com/users/518287",
"pm_score": 3,
"selected": false,
"text": "(f * g) . (h * k) = (f . h * g . k) \n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6335/"
] |
199,936
|
<p>I am currently trying to program my first ajax interface using Rails.</p>
<p>The application currently shows a table populated with list items. The user has to approve or reject each of the list items. I currently have an edit link at the end of each row that shows a form in which I can approve the list item.</p>
<p>I am thinking on using a checkbox instead of the edit link. When the user clicks the checkbox I want to update the database with the status, user name and date/time without leaving this page.</p>
<ol>
<li>What steps should I follow? </li>
<li>Can I use a checkbox or am I
restricted to buttons?</li>
<li>What xxx_remote helper should I use?</li>
<li>How can I update the checkbox state with the results of the ajax call?</li>
</ol>
|
[
{
"answer_id": 200071,
"author": "Andrew",
"author_id": 17408,
"author_profile": "https://Stackoverflow.com/users/17408",
"pm_score": 4,
"selected": true,
"text": "...\n<tr id=\"item1\">\n <td>Accept or Reject</td>\n <td>\n link_to_remote 'accept', :action => :accept, :id => 1, :method => :post\n link_to_remote 'reject', :action => :reject, :id => 1, :method => :post\n </td>\n</tr>\n...\n"
},
{
"answer_id": 200588,
"author": "Tomek Melissa",
"author_id": 1928,
"author_profile": "https://Stackoverflow.com/users/1928",
"pm_score": 1,
"selected": false,
"text": "link_to_remote"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14755/"
] |
199,953
|
<p>I have 2 tables. One (domains) has domain ids, and domain names (dom_id, dom_url).</p>
<p>the other contains actual data, 2 of which columns require a TO and FROM domain names. So I have 2 columns rev_dom_from and rev_dom_for, both of which store the domain name id, from the domains table.</p>
<p>Simple.</p>
<p>Now I need to actually display both domain names on the webpage. I know how to display one or the other, via the LEFT JOIN domains ON reviews.rev_dom_for = domains.dom_url query, and then you echo out the dom_url, which would echo out the domain name in the rev_dom_for column.</p>
<p>But how would I make it echo out the 2nd domain name, in the dom_rev_from column?</p>
|
[
{
"answer_id": 199958,
"author": "Stephen Wrighton",
"author_id": 7516,
"author_profile": "https://Stackoverflow.com/users/7516",
"pm_score": 8,
"selected": true,
"text": "SELECT toD.dom_url AS ToURL, \n fromD.dom_url AS FromUrl, \n rvw.*\n\nFROM reviews AS rvw\n\nLEFT JOIN domain AS toD \n ON toD.Dom_ID = rvw.rev_dom_for\n\nLEFT JOIN domain AS fromD \n ON fromD.Dom_ID = rvw.rev_dom_from\n"
},
{
"answer_id": 200061,
"author": "delux247",
"author_id": 5569,
"author_profile": "https://Stackoverflow.com/users/5569",
"pm_score": 3,
"selected": false,
"text": "Domain Table\ndom_id | dom_url\n\nReview Table\nrev_id | rev_dom_from | rev_dom_for\n"
},
{
"answer_id": 14785621,
"author": "Ashekur Rahman molla Asik",
"author_id": 1672948,
"author_profile": "https://Stackoverflow.com/users/1672948",
"pm_score": -1,
"selected": false,
"text": "column11,column12,column13,column14\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199953",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
199,959
|
<p>In C# there is a method <code>SetApartmentState</code> in the class <code>Thread</code>.
How do I do the same thing in C++?</p>
|
[
{
"answer_id": 200034,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 4,
"selected": true,
"text": "CoInitializeEx()"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11238/"
] |
199,961
|
<p>How can I find out the folder where the windows service .exe file is installed dynamically?</p>
<pre><code>Path.GetFullPath(relativePath);
</code></pre>
<p>returns a path based on <code>C:\WINDOWS\system32</code> directory.</p>
<p>However, the <code>XmlDocument.Load(string filename)</code> method appears to be working against relative path inside the directory where the service .exe file is installed to.</p>
|
[
{
"answer_id": 199976,
"author": "Greg Dean",
"author_id": 1200558,
"author_profile": "https://Stackoverflow.com/users/1200558",
"pm_score": 7,
"selected": true,
"text": "System.Reflection.Assembly.GetEntryAssembly().Location\n"
},
{
"answer_id": 199991,
"author": "TheSoftwareJedi",
"author_id": 18941,
"author_profile": "https://Stackoverflow.com/users/18941",
"pm_score": -1,
"selected": false,
"text": "Environment.CurrentDirectory;\n"
},
{
"answer_id": 201177,
"author": "lowglider",
"author_id": 9602,
"author_profile": "https://Stackoverflow.com/users/9602",
"pm_score": 3,
"selected": false,
"text": "//CommandLine without the first and last two characters\n//Path.GetDirectory seems to have some difficulties with these (special chars maybe?)\nstring cmdLine = Environment.CommandLine.Remove(Environment.CommandLine.Length - 2, 2).Remove(0, 1);\nstring workDir = Path.GetDirectoryName(cmdLine); \n"
},
{
"answer_id": 201364,
"author": "Chris S",
"author_id": 21574,
"author_profile": "https://Stackoverflow.com/users/21574",
"pm_score": 3,
"selected": false,
"text": "string path = Assembly.GetExecutingAssembly().Location;\nFileInfo fileInfo = new FileInfo(path);\nstring dir = fileInfo.DirectoryName;\n"
},
{
"answer_id": 290308,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)\n"
},
{
"answer_id": 13129413,
"author": "Curtis Yallop",
"author_id": 854342,
"author_profile": "https://Stackoverflow.com/users/854342",
"pm_score": 6,
"selected": false,
"text": "AppDomain.CurrentDomain.BaseDirectory\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199961",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/437435/"
] |
199,966
|
<p>The <code>gcc -S</code> option will generate assembly code in AT&T syntax, is there a way to generate files in Intel syntax? Or is there a way to convert between the two?</p>
|
[
{
"answer_id": 200028,
"author": "Jason Dagit",
"author_id": 5113,
"author_profile": "https://Stackoverflow.com/users/5113",
"pm_score": 9,
"selected": true,
"text": "-masm=intel"
},
{
"answer_id": 5638826,
"author": "phoxis",
"author_id": 702361,
"author_profile": "https://Stackoverflow.com/users/702361",
"pm_score": 4,
"selected": false,
"text": "gcc -S -masm=intel test.c\n"
},
{
"answer_id": 10768776,
"author": "RizonBarns",
"author_id": 1419364,
"author_profile": "https://Stackoverflow.com/users/1419364",
"pm_score": 3,
"selected": false,
"text": "#include <conio.h>\n#include <stdio.h>\n#include <windows.h>\n\nint a = 0;\nint main(int argc, char *argv[]) {\n asm(\"mov eax, 0xFF\");\n asm(\"mov _a, eax\");\n printf(\"Result of a = %d\\n\", a);\n getch();\n return 0;\n };\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/199966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1841/"
] |
200,020
|
<p>In many symbolic math systems, such as Matlab or Mathematica, you can use a variable like <code>Ans</code> or <code>%</code> to retrieve the last computed value. Is there a similar facility in the Python shell?</p>
|
[
{
"answer_id": 200027,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 9,
"selected": true,
"text": ">>> 5+5\n10\n>>> _\n10\n>>> _ + 5\n15\n>>> _\n15\n"
},
{
"answer_id": 200045,
"author": "Peter Hoffmann",
"author_id": 720,
"author_profile": "https://Stackoverflow.com/users/720",
"pm_score": 7,
"selected": false,
"text": "In [1]: 10\nOut[1]: 10\n\nIn [2]: 32\nOut[2]: 32\n\nIn [3]: _\nOut[3]: 32\n\nIn [4]: _1\nOut[4]: 10\n\nIn [5]: _2\nOut[5]: 32\n\nIn [6]: _1 + _2\nOut[6]: 42\n\nIn [7]: _6\nOut[7]: 42\n"
},
{
"answer_id": 56060036,
"author": "Jan Kukacka",
"author_id": 2042751,
"author_profile": "https://Stackoverflow.com/users/2042751",
"pm_score": 4,
"selected": false,
"text": "_"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23845/"
] |
200,037
|
<p>I have developed an installer class which removes certain folders from the base dir.However,I also want to remove the entry of another application from add/remove programs through the inst class.Could anyone suggest the solution.</p>
<p>Regards,
Harsh Suman</p>
|
[
{
"answer_id": 18649680,
"author": "Kevin M",
"author_id": 1838481,
"author_profile": "https://Stackoverflow.com/users/1838481",
"pm_score": 1,
"selected": false,
"text": " public static void RemoveControlPanelProgram(string apllicationName)\n {\n string InstallerRegLoc = @\"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\";\n RegistryKey homeKey = (Registry.LocalMachine).OpenSubKey(InstallerRegLoc, true);\n RegistryKey appSubKey = homeKey.OpenSubKey(apllicationName);\n if (null != appSubKey)\n {\n homeKey.DeleteSubKey(apllicationName);\n }\n }\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200037",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,049
|
<p>I want to be able to capture my iPhone's screen as a video, but I'm not sure the best way to do this.</p>
<p>Can anyone help guide me on how to best do this <em>without jailbreak?</em></p>
|
[
{
"answer_id": 10104878,
"author": "Balan Prabhu",
"author_id": 1310087,
"author_profile": "https://Stackoverflow.com/users/1310087",
"pm_score": 2,
"selected": false,
"text": " -(void)playvideo\n{\n\n MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:outputURL ];\n [player.view setFrame:CGRectMake(0,0,320,480)];\n\n[player setMovieControlMode:MPMovieControlModeHidden]; \n\n[player setScalingMode:MPMovieScalingModeAspectFit];\n\n [player setBackgroundColor:[UIColor blackColor]];\n\n [player setFullscreen:YES animated:YES];\n\n[player play];\n\n[self addSubview:player.view];\n\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200049",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23294/"
] |
200,056
|
<p>I have access to an Oracle server that has some databases that I would like to access. However, the machine that I have access from has none of the oracle client software. Is there any alternative to oracle's client software the provides the functionality of something like MySQL's mysql or Postgres' psql? I'd like to be able to poke around a bit in the database before writing software against it.</p>
|
[
{
"answer_id": 200069,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 4,
"selected": true,
"text": "sqlplus"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/85/"
] |
200,066
|
<p>In C#, how do I get the name of the drive that the Operating System is installed on?</p>
|
[
{
"answer_id": 200068,
"author": "TheSoftwareJedi",
"author_id": 18941,
"author_profile": "https://Stackoverflow.com/users/18941",
"pm_score": 5,
"selected": false,
"text": "Path.GetPathRoot(Environment.SystemDirectory)\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,079
|
<p>Given the following inheritance tree, what would be the best way of implementing it in a way that works?</p>
<pre><code>abstract class Foo<T> : IEnumerable<T>
{
public abstract Bar CreateBar();
}
class Bar<T> : Foo<T>
{
// Bar's provide a proxy interface to Foo's and limit access nicely.
// The general public shouldn't be making these though, they have access
// via CreateBar()
protected Bar(Foo base)
{
// snip...
}
}
class Baz<T> : Foo<T>
{
public Bar CreateBar()
{
return new Bar(this);
}
}
</code></pre>
<p>This fails with: <code>'Bar.Bar()' is inaccessible due to its protection level</code>.</p>
<p>I don't want the constructor being public, only classes that inherit from <code>Foo</code> should be able to create <code>Bar</code>s. <code>Bar</code> is a specialised <code>Foo</code>, and any type of <code>Foo</code> should be able to create one. Public internal is an 'option' here, as the majority of the predefined extensions to <code>Foo</code> will be internal to the DLL, but I consider this a sloppy answer, since anyone who comes along later who wants to create their own type of <code>Foo</code> or <code>Baz</code> (which is likely to happen) will be stuck with a default <code>CreateBar()</code> implementation, which may or may not meet their needs.</p>
<p>Perhaps there is a way of refactoring this to make it work nicely? I'm banging my head on the wall trying to design this so it'll work though.</p>
<p><strong>Edit (More info):</strong></p>
<p>Slightly more concrete: Foo is implementing IEnumerable and long story short, Bar is providing the same interface, but to a limited subset of that enumerable object. All Foo's should be able to create subsets of themselves (ie. Bar) and return it. But I don't want to have everyone who ever wants to implement a Foo to have to worry about this, because Bar will do the proxying and worry about limiting the range, etc.</p>
|
[
{
"answer_id": 200129,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 1,
"selected": false,
"text": "abstract class Foo<T> : IEnumerable<T>\n{\n public abstract Bar<T> CreateBar();\n\n protected Bar<T> CreateBar(Foo<T> f) { return new FooBar(f); }\n\n private class FooBar : Bar<T> \n { public FooBar(Foo<T> f) : base(f) {} \n }\n}\n\nclass Bar<T> : Foo<T>\n{ protected Bar(Foo<T> @base) {}\n}\n\nclass Baz<T> : Foo<T>\n{\n public override Bar<T> CreateBar() \n {\n return CreateBar(this);\n }\n}\n"
},
{
"answer_id": 200164,
"author": "Robert Rossney",
"author_id": 19403,
"author_profile": "https://Stackoverflow.com/users/19403",
"pm_score": 1,
"selected": false,
"text": "public class Foo\n{\n protected static Bar CreateBarInstance()\n {\n return new Bar();\n }\n public virtual Bar CreateBar()\n {\n return CreateBarInstance();\n }\n}\n\npublic class Bar\n{\n internal Bar()\n {\n }\n}\n\npublic class Baz : Foo\n{\n public override Bar CreateBar()\n {\n Bar b = base.CreateBar();\n // manipulate the Bar in some fashion\n return b;\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
200,090
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/194465/how-to-parse-a-string-to-an-int-in-c">How to parse a string to an int in C++?</a> </p>
</blockquote>
<p>How do you convert a C++ string to an int?</p>
<p>Assume you are expecting the string to have actual numbers in it ("1", "345", "38944", for example).</p>
<p>Also, let's assume you don't have boost, and you really want to do it the C++ way, not the crufty old C way.</p>
|
[
{
"answer_id": 200095,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 5,
"selected": false,
"text": "std::string plop(\"123\");\nstd::stringstream str(plop);\nint x;\n\nstr >> x;\n\n/* Lets not forget to error checking */\nif (!str)\n{\n // The conversion failed.\n // Need to do something here.\n // Maybe throw an exception\n}\n"
},
{
"answer_id": 200108,
"author": "Randy Sugianto 'Yuku'",
"author_id": 11238,
"author_profile": "https://Stackoverflow.com/users/11238",
"pm_score": 6,
"selected": false,
"text": "#include <sstream>\n\n// st is input string\nint result;\nstringstream(st) >> result;\n"
},
{
"answer_id": 200110,
"author": "user27732",
"author_id": 27732,
"author_profile": "https://Stackoverflow.com/users/27732",
"pm_score": -1,
"selected": false,
"text": "StrToInt\n"
},
{
"answer_id": 200116,
"author": "ayaz",
"author_id": 23191,
"author_profile": "https://Stackoverflow.com/users/23191",
"pm_score": 2,
"selected": false,
"text": "#include <sstream>\nint main()\n{\n char* str = \"1234\";\n std::stringstream s_str( str );\n int i;\n s_str >> i;\n}\n"
},
{
"answer_id": 304018,
"author": "Ryan Ginstrom",
"author_id": 10658,
"author_profile": "https://Stackoverflow.com/users/10658",
"pm_score": 2,
"selected": false,
"text": "#include <boost/lexical_cast.hpp>\n\nint val = boost::lexical_cast<int>(strval) ;\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27729/"
] |
200,093
|
<p>What is the difference between UTF and UCS.</p>
<p>What are the best ways to represent not European character sets (using UTF) in C++ strings. I would like to know your recommendations for:</p>
<ul>
<li>Internal representation inside the code
<ul>
<li>For string manipulation at run-time</li>
<li>For using the string for display purposes.</li>
</ul></li>
<li>Best storage representation (<b>i.e.</b> In file)</li>
<li>Best on wire transport format (Transfer between application that may be on different architectures and have a different standard locale)</li>
</ul>
|
[
{
"answer_id": 200102,
"author": "Randy Sugianto 'Yuku'",
"author_id": 11238,
"author_profile": "https://Stackoverflow.com/users/11238",
"pm_score": 0,
"selected": false,
"text": "wchar_t"
},
{
"answer_id": 200103,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 2,
"selected": false,
"text": "wchar_t"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14065/"
] |
200,106
|
<p>Ok so ive got a swing app going using the "System" look and feel. Now, I want to change the background colour of the main panels to black. Too easy right?</p>
<pre><code>UIManager.put("Panel.background", Color.BLACK);
</code></pre>
<p>Well yeah, except now the controls in the app look stupid, because their 'shadows', for want of a better word, are graduated to fade towards the old system default colour(gross windows grey). So there are light grey 'corners' on all the controls, especially the tabs on JTabbedPane.
I know it can be fixed, because if you change the windowsXP theme to one with a different default application colour, the controls take on this changed colour and their shadows 'fade' towards it.</p>
<p>But I have no idea what UIManager key it is, or even if you can do it with UIManger.</p>
<p>I dont really want to change the L&F engine, because apart from this it looks good.</p>
|
[
{
"answer_id": 200130,
"author": "RodeoClown",
"author_id": 943,
"author_profile": "https://Stackoverflow.com/users/943",
"pm_score": 1,
"selected": false,
"text": "for (Object key: UIManager.getDefaults().keySet())\n{\n System.out.println(key);\n}\n"
},
{
"answer_id": 210058,
"author": "Rastislav Komara",
"author_id": 22068,
"author_profile": "https://Stackoverflow.com/users/22068",
"pm_score": 2,
"selected": false,
"text": "COMPONENT_NAME_WITHOUT_J + '.' + PROPERTY. \n"
},
{
"answer_id": 4048199,
"author": "Craigo",
"author_id": 418057,
"author_profile": "https://Stackoverflow.com/users/418057",
"pm_score": 1,
"selected": false,
"text": "setOpaque(false)"
},
{
"answer_id": 6053841,
"author": "gtiwari333",
"author_id": 607637,
"author_profile": "https://Stackoverflow.com/users/607637",
"pm_score": 1,
"selected": false,
"text": " import java.util.*;\n import javax.swing.UIManager;\n\n public class UIManager_All_Put_Options\n {\n public static void main (String[] args)\n {\n Hashtable properties = UIManager.getDefaults();\n Enumeration keys = properties.keys();\n\n while (keys.hasMoreElements()) {\n String key = (String) keys.nextElement();\n Object value = properties.get (key);\n System.out.printf(\"%-40s \\t %-200s \\n\", key,value);\n }\n }\n }\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16925/"
] |
200,140
|
<p>In my code, I want to view all data from a CSV in table form, but it only displays the last line. How about lines 1 and 2? Here's the data:</p>
<pre><code>1,HF6,08-Oct-08,34:22:13,df,jhj,fh,fh,ffgh,gh,g,rt,ffgsaf,asdf,dd,yoawa,DWP,tester,Pattern
2,hf35,08-Oct-08,34:12:13,dg,jh,fh,fgh,fgh,gh,gfh,re,fsaf,asdf,dd,yokogawa,DWP,DWP,Pattern
3,hf35,08-Oct-08,31:22:03,dg,jh,fh,fgh,gh,gh,gh,rte,ffgsaf,asdf,dfffd,yokogawa,DWP,DWP,ghh
</code></pre>
<p>Here's the code:</p>
<pre><code>#! /usr/bin/perl
print "Content-type:text/html\r\n\r\n";
use CGI qw(:standard);
use strict;
use warnings;
my $line;
my $file;
my ($f1,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$f10,$f11,$f12,$f13,$f14,$f15,$f16,$f17,$f18,$f19);
$file='MyFile.txt';
open(F,$file)||die("Could not open $file");
while ($line=<F>)
{
($f1,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$f10,$f11,$f12,$f13,$f14,$f15,$f16,$f17,$f18,$f19)= split ',',$line;
}
close(F);
print "<HTML>";
print "<head>";
print "<body bgcolor='#4682B4'>";
print "<title>FUSION SHIFT REPORT</title>";
print "<div align='left'>";
print "<TABLE CELLPADDING='1' CELLSPACING='1' BORDER='1' bordercolor=black width='100%'>";
print "<TR>";
print "<td width='12%'bgcolor='#00ff00'><font size='2'>RECORD No.</td>";
print "<td width='12%'bgcolor='#00ff00'><font size='2'>TESTER No.</td>";
print "<td width='12%'bgcolor='#00ff00'><font size='2'>DATE</td>";
print "<td width='13%'bgcolor='#00ff00'><font size='2'>TIME</td>";
print "<td width='11%'bgcolor='#00ff00'><font size='2'>DEVICE NAME</td>";
print "<td bgcolor='#00ff00'><font size='2'>TEST PROGRAM</td>";
print "<td bgcolor='#00ff00'><font size='2'>DEVICE FAMILY</td>";
print "<td width='13%'bgcolor='#00ff00'><font size='2'>SMSLOT</td>";
print "<td width='13%'bgcolor='#00ff00'><font size='2'>DIE LOT</td>";
print "<td width='12%'bgcolor='#00ff00'><font size='2'>LOADBOARD</td>";
print "<td width='12%'bgcolor='#00ff00'><font size='2'>TESTER </td>";
print "<td width='12%'bgcolor='#00ff00'><font size='2'>SERIAL NUMBER</td>";
print "<td width='13%'bgcolor='#00ff00'><font size='2'>TESTER CONFIG</td>";
print "<td width='11%'bgcolor='#00ff00'><font size='2'>SMSLOT</td>";
print "<td bgcolor='#00ff00'><font size='2'>PACKAGE</td>";
print "<td bgcolor='#00ff00'><font size='2'>SOCKET</td>";
print "<td width='13%'bgcolor='#00ff00'><font size='2'>ROOT CAUSE 1</td>";
print "<td width='13%'bgcolor='#00ff00'><font size='2'>ROOT CAUSE 2</td>";
print "<td width='13%'bgcolor='#00ff00'><font size='2'>ROOT CAUSE 3</td>";
print "</tr>";
print "<TR>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f1</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f2</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f3</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f4</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f5</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f6</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f7</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f8</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f9</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f10</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f11</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f12</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f13</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f14</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f15</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f16</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f17</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f18</TD>";
print "<TD bgcolor='#ADD8E6'><font size='2'>$f19</TD>";
print "</tr>";
print "</TABLE>";
print "</body>";
print "<html>";
</code></pre>
|
[
{
"answer_id": 200175,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "my $f;\nwhile ($line = <F>) {\n $f = $line;\n}\nprint $f;\n"
},
{
"answer_id": 200181,
"author": "Paul Dixon",
"author_id": 6521,
"author_profile": "https://Stackoverflow.com/users/6521",
"pm_score": 4,
"selected": false,
"text": "while ($line=<F>)\n{ \n print \"<tr>\";\n my @cells= split ',',$line;\n foreach my $cell (@cells)\n {\n print \"<td>$cell</td>\";\n }\n print \"</tr>\";\n}\n"
},
{
"answer_id": 201757,
"author": "tsee",
"author_id": 13164,
"author_profile": "https://Stackoverflow.com/users/13164",
"pm_score": 2,
"selected": false,
"text": "$f1"
},
{
"answer_id": 201762,
"author": "wfsp",
"author_id": 20438,
"author_profile": "https://Stackoverflow.com/users/20438",
"pm_score": 4,
"selected": true,
"text": "#!/usr/local/bin/perl\n\nuse strict;\nuse warnings;\n\nuse HTML::Template;\n\nmy @table;\nwhile (my $line = <DATA>){\n chomp $line;\n my @row = map{{cell => $_}} split(/,/, $line);\n push @table, {row => \\@row};\n}\n\nmy $tmpl = HTML::Template->new(scalarref => \\get_tmpl());\n$tmpl->param(table => \\@table);\nprint $tmpl->output;\n\nsub get_tmpl{\n return <<TMPL\n<html>\n<TMPL_LOOP table>\n<tr>\n<TMPL_LOOP row>\n<td><TMPL_VAR cell></td></TMPL_LOOP>\n</tr></TMPL_LOOP>\n</html>\nTMPL\n}\n\n__DATA__\n1,HF6,08-Oct-08,34:22:13,df,jhj,fh,fh,ffgh,gh,g,rt,ffgsaf,asdf,dd,yoawa,DWP,tester,Pattern\n2,hf35,08-Oct-08,34:12:13,dg,jh,fh,fgh,fgh,gh,gfh,re,fsaf,asdf,dd,yokogawa,DWP,DWP,Pattern\n3,hf35,08-Oct-08,31:22:03,dg,jh,fh,fgh,gh,gh,gh,rte,ffgsaf,asdf,dfffd,yokogawa,DWP,DWP,ghh\n"
},
{
"answer_id": 203455,
"author": "AmbroseChapel",
"author_id": 242241,
"author_profile": "https://Stackoverflow.com/users/242241",
"pm_score": 3,
"selected": false,
"text": "$f1,$f2,$f3,$f4\n"
},
{
"answer_id": 16794967,
"author": "Ashley Harris",
"author_id": 2429051,
"author_profile": "https://Stackoverflow.com/users/2429051",
"pm_score": 0,
"selected": false,
"text": "$content =~ s#\\n#</td></tr><tr><td>#g;\n$content =~ s#,#</td><td>#g;\n$content = \"<table><tr><td>$content</td></tr></table>\";\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,147
|
<p>I'm an absolute n00b into the java platform
I would like to know whether I need to change anything in my code to get the benefits of 64bit JRE ? </p>
<p>or is it something like when I initiate it with "java -d64" its gonna run in some turbo mode?</p>
<p>Your help is highly appreciated</p>
|
[
{
"answer_id": 21392637,
"author": "larsolsen",
"author_id": 3242291,
"author_profile": "https://Stackoverflow.com/users/3242291",
"pm_score": 0,
"selected": false,
"text": "public class Benchmark {\npublic static void main(String args[]) {\nlong time = System.currentTimeMillis();\nfor (int a = 1; a < 900000000; a++) {\n for (int b = 1; b < 20; b++) {\n }\n}\nlong time2 = System.currentTimeMillis() - time;\nSystem.out.println(\"\\nTime counter stopped: \" + time2);\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200147",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,150
|
<p>i am using the apache commons httpclient in a lotus notes java agent and it works fine. BUT when establishing a proxy connection the log will be spamed with the following line :</p>
<pre><code>[INFO] AuthChallengeProcessor - basic authentication scheme selected
</code></pre>
<p>Do you know how to disable the integrated loging or how to set a lower debug level ?
Its a "feature" from the httpclient itself, so code from my side is not needed :-)</p>
<p>Thanks.</p>
|
[
{
"answer_id": 200269,
"author": "JimmyTudeski",
"author_id": 27181,
"author_profile": "https://Stackoverflow.com/users/27181",
"pm_score": -1,
"selected": false,
"text": "client.getState().setProxyCredentials(\n new AuthScope(conParm.getProxyServer(), conParm.getProxyPort()),\n new UsernamePasswordCredentials(conParm.getProxyUser(), conParm.getProxyPw()));\n\n **ArrayList authPrefs = new ArrayList(2);\n authPrefs.add(AuthPolicy.DIGEST);\n authPrefs.add(AuthPolicy.BASIC);\n\n client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);\n client.getParams().setParameter(\"http.protocol.expect-continue\", new Boolean(true));**\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27181/"
] |
200,151
|
<p>Is it possible to search for an object by one of its properties in a Generic List?</p>
<pre><code>Public Class Customer
Private _id As Integer
Private _name As String
Public Property ID() As Integer
Get
Return _id
End Get
Set
_id = value
End Set
End Property
Public Property Name() As String
Get
Return _name
End Get
Set
_name = value
End Set
End Property
Public Sub New(id As Integer, name As String)
_id = id
_name = name
End Sub
End Class
</code></pre>
<p>Then loading and searching</p>
<pre><code>Dim list as new list(Of Customer)
list.Add(New Customer(1,"A")
list.Add(New Customer(2,"B")
</code></pre>
<p>How can I return customer object with id =1? Does this have to do with the "Predicate" in Generics?</p>
<p>Note: I am doing this in VB.NET.</p>
|
[
{
"answer_id": 200161,
"author": "Aleris",
"author_id": 20417,
"author_profile": "https://Stackoverflow.com/users/20417",
"pm_score": 0,
"selected": false,
"text": "Find"
},
{
"answer_id": 200165,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 6,
"selected": true,
"text": "list.Find(function(c) c.ID = 1)\n"
},
{
"answer_id": 200182,
"author": "Ozgur Ozcitak",
"author_id": 976,
"author_profile": "https://Stackoverflow.com/users/976",
"pm_score": 3,
"selected": false,
"text": "list.Add(New Customer(1, \"A\"))\nlist.Add(New Customer(2, \"B\"))\n\nPrivate Function HasID1(ByVal c As Customer) As Boolean\n Return (c.ID = 1)\nEnd Function\n\nDim customerWithID1 As Customer = list.Find(AddressOf HasID1)\n"
},
{
"answer_id": 200554,
"author": "chrissie1",
"author_id": 2936,
"author_profile": "https://Stackoverflow.com/users/2936",
"pm_score": 1,
"selected": false,
"text": "Dim list as new list(Of Customer)\n\nlist.Add(New Customer(1,\"A\")\n\nlist.Add(New Customer(2,\"B\")\n\nlist.contains(new customer(1,\"A\"))\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23667/"
] |
200,162
|
<p>The WebBrowser control has a property called "IsWebBrowserContextMenuEnabled" that disables all ability to right-click on a web page and see a context menu. This is very close to what I want (I don't want anyone to be able to right-click and print, hit back, hit properties, view source, etc).</p>
<p>The only problem is this also disables the context menu that appears in TextBoxes for copy/paste, etc.</p>
<p>To make this clearer, this is what I don't want:<br>
<a href="http://www.flickr.com/photos/24262860@N00/2941073716/" rel="nofollow noreferrer" title="badcontext by andersonimes, on Flickr"><img src="https://farm4.static.flickr.com/3047/2941073716_0c51ab4b3c_m.jpg" width="124" height="240" alt="badcontext" /></a></p>
<p>This is what I do want:<br>
<a href="http://www.flickr.com/photos/24262860@N00/2941073720/" rel="nofollow noreferrer" title="goodcontext by andersonimes, on Flickr"><img src="https://farm4.static.flickr.com/3024/2941073720_8aedaf9b06_o.png" width="104" height="144" alt="goodcontext" /></a></p>
<p>I would like to disable the main context menu, but allow the one that appears in TextBoxes. Anyone know how I would do that? The WebBrowser.Document.ContextMenuShowing event looks promising, but doesn't seem to properly identify the element the user is right-clicking on, either through the HtmlElementEventArgs parameter's "FromElement" and "ToElement" properties, nor is the sender anything but the HtmlDocument element.</p>
<p>Thanks in advance!</p>
|
[
{
"answer_id": 200194,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": true,
"text": " CopiedTxt = document.selection.createRange();\n CopiedTxt.execCommand(\"Copy\");\n"
},
{
"answer_id": 1723195,
"author": "Santosh Thakur",
"author_id": 209728,
"author_profile": "https://Stackoverflow.com/users/209728",
"pm_score": 0,
"selected": false,
"text": "//Start:\n\nfunction cutomizedcontextmenu(e)\n{\n var target = window.event ? window.event.srcElement : e ? e.target : null;\n if( navigator.userAgent.toLowerCase().indexOf(\"msie\") != -1 )\n {\n if (target.type != \"text\" && target.type != \"textarea\" && target.type != \"password\") \n {\n alert(message);\n return false;\n }\n return true;\n }\n else if( navigator.product == \"Gecko\" )\n {\n alert(message);\n return false;\n }\n} \n\ndocument.oncontextmenu = cutomizedcontextmenu;\n//End:\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200162",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3244/"
] |
200,163
|
<p>I am currently writing a little bootstrap code for a service that can be run in the console. It essentially boils down to calling the OnStart() method instead of using the ServiceBase to start and stop the service (because it doesn't run the application if it isn't installed as a service and makes debugging a nightmare).</p>
<p>Right now I am using Debugger.IsAttached to determine if I should use ServiceBase.Run or [service].OnStart, but I know that isn't the best idea because some times end users want to run the service in a console (to see the output etc. realtime).</p>
<p>Any ideas on how I could determine if the Windows service controller started 'me', or if the user started 'me' in the console? Apparantly <a href="http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/99c4594b-e6c9-424f-bfe1-c7261bba24d3/" rel="noreferrer" title="forum thread">Environment.IsUserInteractive</a> is not the answer. I thought about using commandline args, but that seems 'dirty'.</p>
<p>I could always see about a try-catch statement around ServiceBase.Run, but that seems dirty. Edit: Try catch doesn't work.</p>
<p>I have a solution: putting it up here for all the other interested stackers:</p>
<pre><code> public void Run()
{
if (Debugger.IsAttached || Environment.GetCommandLineArgs().Contains<string>("-console"))
{
RunAllServices();
}
else
{
try
{
string temp = Console.Title;
ServiceBase.Run((ServiceBase[])ComponentsToRun);
}
catch
{
RunAllServices();
}
}
} // void Run
private void RunAllServices()
{
foreach (ConsoleService component in ComponentsToRun)
{
component.Start();
}
WaitForCTRLC();
foreach (ConsoleService component in ComponentsToRun)
{
component.Stop();
}
}
</code></pre>
<p>EDIT: There was another question on StackOverflow where the guy had problems with the Environment.CurrentDirectory being "C:\Windows\System32" looks like that may be the answer. I will test today.</p>
|
[
{
"answer_id": 208073,
"author": "gyrolf",
"author_id": 23772,
"author_profile": "https://Stackoverflow.com/users/23772",
"pm_score": 4,
"selected": false,
"text": "Environment.UserInteractive"
},
{
"answer_id": 218954,
"author": "Kramii",
"author_id": 11514,
"author_profile": "https://Stackoverflow.com/users/11514",
"pm_score": 5,
"selected": true,
"text": "Public Class ExecutionContext\n ''' <summary>\n ''' Gets a value indicating whether the application is a windows service.\n ''' </summary>\n ''' <value>\n ''' <c>true</c> if this instance is service; otherwise, <c>false</c>.\n ''' </value>\n Public Shared ReadOnly Property IsService() As Boolean\n Get\n ' Determining whether or not the host application is a service is\n ' an expensive operation (it uses reflection), so we cache the\n ' result of the first call to this method so that we don't have to\n ' recalculate it every call.\n\n ' If we have not already determined whether or not the application\n ' is running as a service...\n If IsNothing(_isService) Then\n\n ' Get details of the host assembly.\n Dim entryAssembly As Reflection.Assembly = Reflection.Assembly.GetEntryAssembly\n\n ' Get the method that was called to enter the host assembly.\n Dim entryPoint As System.Reflection.MethodInfo = entryAssembly.EntryPoint\n\n ' If the base type of the host assembly inherits from the\n ' \"ServiceBase\" class, it must be a windows service. We store\n ' the result ready for the next caller of this method.\n _isService = (entryPoint.ReflectedType.BaseType.FullName = \"System.ServiceProcess.ServiceBase\")\n\n End If\n\n ' Return the cached result.\n Return CBool(_isService)\n End Get\n End Property\n\n Private Shared _isService As Nullable(Of Boolean) = Nothing\n#End Region\nEnd Class\n"
},
{
"answer_id": 2111492,
"author": "Rolf Kristensen",
"author_id": 193178,
"author_profile": "https://Stackoverflow.com/users/193178",
"pm_score": 3,
"selected": false,
"text": "static class Program\n{\n static void Main(string[] args)\n {\n if (Array.Exists(args, delegate(string arg) { return arg == \"/install\"; }))\n {\n System.Configuration.Install.TransactedInstaller ti = null;\n ti = new System.Configuration.Install.TransactedInstaller();\n ti.Installers.Add(new ProjectInstaller());\n ti.Context = new System.Configuration.Install.InstallContext(\"\", null);\n string path = System.Reflection.Assembly.GetExecutingAssembly().Location;\n ti.Context.Parameters[\"assemblypath\"] = path;\n ti.Install(new System.Collections.Hashtable());\n return;\n }\n\n if (Array.Exists(args, delegate(string arg) { return arg == \"/uninstall\"; }))\n {\n System.Configuration.Install.TransactedInstaller ti = null;\n ti = new System.Configuration.Install.TransactedInstaller();\n ti.Installers.Add(new ProjectInstaller());\n ti.Context = new System.Configuration.Install.InstallContext(\"\", null);\n string path = System.Reflection.Assembly.GetExecutingAssembly().Location;\n ti.Context.Parameters[\"assemblypath\"] = path;\n ti.Uninstall(null);\n return;\n }\n\n if (Array.Exists(args, delegate(string arg) { return arg == \"/service\"; }))\n {\n ServiceBase[] ServicesToRun;\n\n ServicesToRun = new ServiceBase[] { new MyService() };\n ServiceBase.Run(ServicesToRun);\n }\n else\n {\n Console.ReadKey();\n }\n }\n}\n"
},
{
"answer_id": 3165027,
"author": "rnr_never_dies",
"author_id": 381973,
"author_profile": "https://Stackoverflow.com/users/381973",
"pm_score": 5,
"selected": false,
"text": "var backend = new Backend();\n\nif (Environment.UserInteractive)\n{\n backend.OnStart();\n Application.EnableVisualStyles();\n Application.SetCompatibleTextRenderingDefault(false);\n Application.Run(new Fronend(backend));\n backend.OnStop();\n}\nelse\n{\n var ServicesToRun = new ServiceBase[] {backend};\n ServiceBase.Run(ServicesToRun);\n}\n"
},
{
"answer_id": 10004285,
"author": "shockwave121",
"author_id": 1311765,
"author_profile": "https://Stackoverflow.com/users/1311765",
"pm_score": 2,
"selected": false,
"text": "ServiceHost.Instance.RunningAsAService"
},
{
"answer_id": 25807557,
"author": "chksr",
"author_id": 1740663,
"author_profile": "https://Stackoverflow.com/users/1740663",
"pm_score": 0,
"selected": false,
"text": "enum enEnvironmentType\n {\n ENVTYPE_UNKNOWN,\n ENVTYPE_STANDARD,\n ENVTYPE_SERVICE_WITH_INTERACTION,\n ENVTYPE_SERVICE_WITHOUT_INTERACTION,\n ENVTYPE_IIS_ASP,\n };\n\nenEnvironmentType GetEnvironmentType(void)\n{\n HANDLE hProcessToken = NULL;\n DWORD groupLength = 300;\n PTOKEN_GROUPS groupInfo = NULL;\n\n SID_IDENTIFIER_AUTHORITY siaNt = SECURITY_NT_AUTHORITY;\n PSID pInteractiveSid = NULL;\n PSID pServiceSid = NULL;\n\n DWORD dwRet = NO_ERROR;\n DWORD ndx;\n\n BOOL m_isInteractive = FALSE;\n BOOL m_isService = FALSE;\n\n // open the token\n if (!::OpenProcessToken(::GetCurrentProcess(),TOKEN_QUERY,&hProcessToken))\n {\n dwRet = ::GetLastError();\n goto closedown;\n }\n\n // allocate a buffer of default size\n groupInfo = (PTOKEN_GROUPS)::LocalAlloc(0, groupLength);\n if (groupInfo == NULL)\n {\n dwRet = ::GetLastError();\n goto closedown;\n }\n\n // try to get the info\n if (!::GetTokenInformation(hProcessToken, TokenGroups,\n groupInfo, groupLength, &groupLength))\n {\n // if buffer was too small, allocate to proper size, otherwise error\n if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER)\n {\n dwRet = ::GetLastError();\n goto closedown;\n }\n\n ::LocalFree(groupInfo);\n\n groupInfo = (PTOKEN_GROUPS)::LocalAlloc(0, groupLength);\n if (groupInfo == NULL)\n {\n dwRet = ::GetLastError();\n goto closedown;\n }\n\n if (!GetTokenInformation(hProcessToken, TokenGroups,\n groupInfo, groupLength, &groupLength))\n {\n dwRet = ::GetLastError();\n goto closedown;\n }\n }\n\n //\n // We now know the groups associated with this token. We want\n // to look to see if the interactive group is active in the\n // token, and if so, we know that this is an interactive process.\n //\n // We also look for the \"service\" SID, and if it's present,\n // we know we're a service.\n //\n // The service SID will be present iff the service is running in a\n // user account (and was invoked by the service controller).\n //\n\n // create comparison sids\n if (!AllocateAndInitializeSid(&siaNt,\n 1,\n SECURITY_INTERACTIVE_RID,\n 0, 0, 0, 0, 0, 0, 0,\n &pInteractiveSid))\n {\n dwRet = ::GetLastError();\n goto closedown;\n }\n\n if (!AllocateAndInitializeSid(&siaNt,\n 1,\n SECURITY_SERVICE_RID,\n 0, 0, 0, 0, 0, 0, 0,\n &pServiceSid))\n {\n dwRet = ::GetLastError();\n goto closedown;\n }\n\n // try to match sids\n for (ndx = 0; ndx < groupInfo->GroupCount ; ndx += 1)\n {\n SID_AND_ATTRIBUTES sanda = groupInfo->Groups[ndx];\n PSID pSid = sanda.Sid;\n\n //\n // Check to see if the group we're looking at is one of\n // the two groups we're interested in.\n //\n\n if (::EqualSid(pSid, pInteractiveSid))\n {\n //\n // This process has the Interactive SID in its\n // token. This means that the process is running as\n // a console process\n //\n m_isInteractive = TRUE;\n m_isService = FALSE;\n break;\n }\n else if (::EqualSid(pSid, pServiceSid))\n {\n //\n // This process has the Service SID in its\n // token. This means that the process is running as\n // a service running in a user account ( not local system ).\n //\n m_isService = TRUE;\n m_isInteractive = FALSE;\n break;\n }\n }\n\n if ( !( m_isService || m_isInteractive ) )\n {\n //\n // Neither Interactive or Service was present in the current\n // users token, This implies that the process is running as\n // a service, most likely running as LocalSystem.\n //\n m_isService = TRUE;\n }\n\n\nclosedown:\n if ( pServiceSid )\n ::FreeSid( pServiceSid );\n\n if ( pInteractiveSid )\n ::FreeSid( pInteractiveSid );\n\n if ( groupInfo )\n ::LocalFree( groupInfo );\n\n if ( hProcessToken )\n ::CloseHandle( hProcessToken );\n\n if (dwRet == NO_ERROR)\n {\n if (m_isService)\n return(m_isInteractive ? ENVTYPE_SERVICE_WITH_INTERACTION : ENVTYPE_SERVICE_WITHOUT_INTERACTION);\n return(ENVTYPE_STANDARD);\n }\n else\n return(ENVTYPE_UNKNOWN);\n}\n"
},
{
"answer_id": 27935136,
"author": "Ben Voigt",
"author_id": 103167,
"author_profile": "https://Stackoverflow.com/users/103167",
"pm_score": 1,
"selected": false,
"text": "using System.Security.Principal;\n\nvar wi = WindowsIdentity.GetCurrent();\nvar wp = new WindowsPrincipal(wi);\nvar serviceSid = new SecurityIdentifier(WellKnownSidType.ServiceSid, null);\nvar localSystemSid = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null);\nvar interactiveSid = new SecurityIdentifier(WellKnownSidType.InteractiveSid, null);\n// maybe check LocalServiceSid, and NetworkServiceSid also\n\nbool isServiceRunningAsUser = wp.IsInRole(serviceSid);\nbool isSystem = wp.IsInRole(localSystemSid);\nbool isInteractive = wp.IsInRole(interactiveSid);\n\nbool isAnyService = isServiceRunningAsUser || isSystem || !isInteractive;\n"
},
{
"answer_id": 60174944,
"author": "Serge Ageyev",
"author_id": 8494004,
"author_profile": "https://Stackoverflow.com/users/8494004",
"pm_score": 0,
"selected": false,
"text": "C:\\windows\\system32"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200163",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24064/"
] |
200,178
|
<p>So what's the best way to create new tables in a Sqlite database in Rails 2. I have created the database using rake db:migrate command. So should I write individual sql scripts to create a database or use rake somehow. I don't need scaffolding.</p>
|
[
{
"answer_id": 200214,
"author": "hectorsq",
"author_id": 14755,
"author_profile": "https://Stackoverflow.com/users/14755",
"pm_score": 1,
"selected": false,
"text": "script/generate migration"
},
{
"answer_id": 200592,
"author": "robintw",
"author_id": 1912,
"author_profile": "https://Stackoverflow.com/users/1912",
"pm_score": 3,
"selected": true,
"text": "id"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1688440/"
] |
200,195
|
<p>I have a Stored procedure which schedules a job. This Job takes a lot of time to get completed (approx 30 to 40 min). I need to get to know the status of this Job.
Below details would help me</p>
<p>1) How to see the list of all jobs that have got scheduled for a future time and are yet to start</p>
<p>2) How to see the the list of jobs running and the time span from when they are running</p>
<p>3) How to see if the job has completed successfully or has stoped in between because of any error.</p>
|
[
{
"answer_id": 200280,
"author": "Tim C",
"author_id": 7585,
"author_profile": "https://Stackoverflow.com/users/7585",
"pm_score": 7,
"selected": true,
"text": "EXEC msdb.dbo.sp_help_job @Job_name = 'Your Job Name'\n"
},
{
"answer_id": 238001,
"author": "piers7",
"author_id": 26167,
"author_profile": "https://Stackoverflow.com/users/26167",
"pm_score": 5,
"selected": false,
"text": "SELECT\n job.Name, job.job_ID\n ,job.Originating_Server\n ,activity.run_requested_Date\n ,datediff(minute, activity.run_requested_Date, getdate()) AS Elapsed\nFROM\n msdb.dbo.sysjobs_view job \n INNER JOIN msdb.dbo.sysjobactivity activity\n ON (job.job_id = activity.job_id)\nWHERE\n run_Requested_date is not null \n AND stop_execution_date is null\n AND job.name like 'Your Job Prefix%'\n"
},
{
"answer_id": 8095633,
"author": "Yella",
"author_id": 1041898,
"author_profile": "https://Stackoverflow.com/users/1041898",
"pm_score": 2,
"selected": false,
"text": "select job.Name, job.job_ID, job.Originating_Server,activity.run_requested_Date,\ndatediff(minute, activity.run_requested_Date, getdate()) as Elapsed \nfrom msdb.dbo.sysjobs_view job \ninner join msdb.dbo.sysjobactivity activity on (job.job_id = activity.job_id) \nwhere run_Requested_date is not null \nand stop_execution_date is null \nand job.name like 'Your Job Prefix%'\n"
},
{
"answer_id": 9993535,
"author": "Pavel Metzenauer",
"author_id": 1310442,
"author_profile": "https://Stackoverflow.com/users/1310442",
"pm_score": 4,
"selected": false,
"text": "-- Microsoft SQL Server 2008 Standard Edition:\nIF EXISTS(SELECT 1 \n FROM msdb.dbo.sysjobs J \n JOIN msdb.dbo.sysjobactivity A \n ON A.job_id=J.job_id \n WHERE J.name=N'Your Job Name' \n AND A.run_requested_date IS NOT NULL \n AND A.stop_execution_date IS NULL\n )\n PRINT 'The job is running!'\nELSE\n PRINT 'The job is not running.'\n"
},
{
"answer_id": 18062236,
"author": "efesar",
"author_id": 1472771,
"author_profile": "https://Stackoverflow.com/users/1472771",
"pm_score": 7,
"selected": false,
"text": "SELECT\n job.name, \n job.job_id, \n job.originating_server, \n activity.run_requested_date, \n DATEDIFF( SECOND, activity.run_requested_date, GETDATE() ) as Elapsed\nFROM \n msdb.dbo.sysjobs_view job\nJOIN\n msdb.dbo.sysjobactivity activity\nON \n job.job_id = activity.job_id\nJOIN\n msdb.dbo.syssessions sess\nON\n sess.session_id = activity.session_id\nJOIN\n(\n SELECT\n MAX( agent_start_date ) AS max_agent_start_date\n FROM\n msdb.dbo.syssessions\n) sess_max\nON\n sess.agent_start_date = sess_max.max_agent_start_date\nWHERE \n run_requested_date IS NOT NULL AND stop_execution_date IS NULL\n"
},
{
"answer_id": 18107445,
"author": "user2661347",
"author_id": 2661347,
"author_profile": "https://Stackoverflow.com/users/2661347",
"pm_score": 0,
"selected": false,
"text": "/*-----------------------------------------------------------------------------------------------------------\n\n Document Title: usp_getJobStatus\n\n Purpose: Finds a Current Jobs Run Status \n Input Example: EXECUTE usp_getJobStatus 'MyJobName'\n\n-------------------------------------------------------------------------------------------------------------*/\n\n IF OBJECT_ID ( 'usp_getJobStatus','P' ) IS NOT NULL\n DROP PROCEDURE usp_getJobStatus;\n\n GO\n\n CREATE PROCEDURE usp_getJobStatus \n @JobName NVARCHAR (1000)\n\n AS\n\n IF OBJECT_ID('TempDB..#JobResults','U') IS NOT NULL DROP TABLE #JobResults\n CREATE TABLE #JobResults ( Job_ID UNIQUEIDENTIFIER NOT NULL, \n Last_Run_Date INT NOT NULL, \n Last_Run_Time INT NOT NULL, \n Next_Run_date INT NOT NULL, \n Next_Run_Time INT NOT NULL, \n Next_Run_Schedule_ID INT NOT NULL, \n Requested_to_Run INT NOT NULL,\n Request_Source INT NOT NULL, \n Request_Source_id SYSNAME \n COLLATE Database_Default NULL, \n Running INT NOT NULL,\n Current_Step INT NOT NULL, \n Current_Retry_Attempt INT NOT NULL, \n Job_State INT NOT NULL ) \n\n INSERT #JobResults \n EXECUTE master.dbo.xp_sqlagent_enum_jobs 1, '';\n\n SELECT job.name AS [Job_Name], \n ( SELECT MAX(CAST( STUFF(STUFF(CAST(jh.run_date AS VARCHAR),7,0,'-'),5,0,'-') + ' ' + \n STUFF(STUFF(REPLACE(STR(jh.run_time,6,0),' ','0'),5,0,':'),3,0,':') AS DATETIME))\n FROM msdb.dbo.sysjobs AS j \n INNER JOIN msdb.dbo.sysjobhistory AS jh \n ON jh.job_id = j.job_id AND jh.step_id = 0 \n WHERE j.[name] LIKE '%' + @JobName + '%' \n GROUP BY j.[name] ) AS [Last_Completed_DateTime], \n ( SELECT TOP 1 start_execution_date \n FROM msdb.dbo.sysjobactivity\n WHERE job_id = r.job_id\n ORDER BY start_execution_date DESC ) AS [Job_Start_DateTime],\n CASE \n WHEN r.running = 0 THEN\n CASE \n WHEN jobInfo.lASt_run_outcome = 0 THEN 'Failed'\n WHEN jobInfo.lASt_run_outcome = 1 THEN 'Success'\n WHEN jobInfo.lASt_run_outcome = 3 THEN 'Canceled'\n ELSE 'Unknown'\n END\n WHEN r.job_state = 0 THEN 'Success'\n WHEN r.job_state = 4 THEN 'Success'\n WHEN r.job_state = 5 THEN 'Success'\n WHEN r.job_state = 1 THEN 'In Progress'\n WHEN r.job_state = 2 THEN 'In Progress'\n WHEN r.job_state = 3 THEN 'In Progress'\n WHEN r.job_state = 7 THEN 'In Progress'\n ELSE 'Unknown' END AS [Run_Status_Description]\n FROM #JobResults AS r \n LEFT OUTER JOIN msdb.dbo.sysjobservers AS jobInfo \n ON r.job_id = jobInfo.job_id \n INNER JOIN msdb.dbo.sysjobs AS job \n ON r.job_id = job.job_id \n WHERE job.[enabled] = 1\n AND job.name LIKE '%' + @JobName + '%'\n"
},
{
"answer_id": 30898078,
"author": "Robert Sawyer",
"author_id": 5020747,
"author_profile": "https://Stackoverflow.com/users/5020747",
"pm_score": 1,
"selected": false,
"text": " delete activity\n from msdb.dbo.sysjobs_view job \n inner join msdb.dbo.sysjobactivity activity on job.job_id = activity.job_id \n where \n activity.run_Requested_date is not null \n and activity.stop_execution_date is null \n"
},
{
"answer_id": 36443374,
"author": "Gopakumar N.Kurup",
"author_id": 1310887,
"author_profile": "https://Stackoverflow.com/users/1310887",
"pm_score": 0,
"selected": false,
"text": ";WITH CTE_JobStatus\nAS (\n SELECT DISTINCT NAME AS [JobName]\n ,s.step_id\n ,s.step_name\n ,CASE \n WHEN [Enabled] = 1\n THEN 'Enabled'\n ELSE 'Disabled'\n END [JobStatus]\n ,CASE \n WHEN SJH.run_status = 0\n THEN 'Failed'\n WHEN SJH.run_status = 1\n THEN 'Succeeded'\n WHEN SJH.run_status = 2\n THEN 'Retry'\n WHEN SJH.run_status = 3\n THEN 'Cancelled'\n WHEN SJH.run_status = 4\n THEN 'In Progress'\n ELSE 'Unknown'\n END [JobOutcome]\n ,CONVERT(VARCHAR(8), sjh.run_date) [RunDate]\n ,CONVERT(VARCHAR(8), STUFF(STUFF(CONVERT(TIMESTAMP, RIGHT('000000' + CONVERT(VARCHAR(6), sjh.run_time), 6)), 3, 0, ':'), 6, 0, ':')) RunTime\n ,RANK() OVER (\n PARTITION BY s.step_name ORDER BY sjh.run_date DESC\n ,sjh.run_time DESC\n ) AS rn\n ,SJH.run_status\n FROM msdb..SYSJobs sj\n INNER JOIN msdb..SYSJobHistory sjh ON sj.job_id = sjh.job_id\n INNER JOIN msdb.dbo.sysjobsteps s ON sjh.job_id = s.job_id\n AND sjh.step_id = s.step_id\n WHERE (sj.NAME LIKE 'JOB NAME')\n AND sjh.run_date = CONVERT(CHAR, getdate(), 112)\n )\nSELECT *\nFROM CTE_JobStatus\nWHERE rn = 1\n AND run_status NOT IN (1,4)\n"
},
{
"answer_id": 39583379,
"author": "Tequila",
"author_id": 1073550,
"author_profile": "https://Stackoverflow.com/users/1073550",
"pm_score": 1,
"selected": false,
"text": "INSERT INTO #Job\nEXEC master.dbo.xp_sqlagent_enum_jobs 1,dbo\n"
},
{
"answer_id": 43212406,
"author": "LostFromTheStart",
"author_id": 7815515,
"author_profile": "https://Stackoverflow.com/users/7815515",
"pm_score": 2,
"selected": false,
"text": "SELECT sj.name\n FROM msdb..sysjobactivity aj\n JOIN msdb..sysjobs sj\n on sj.job_id = aj.job_id\n WHERE aj.stop_execution_date IS NULL -- job hasn't stopped running\n AND aj.start_execution_date IS NOT NULL -- job is currently running\n AND sj.name = '<your Job Name>'\n AND NOT EXISTS( -- make sure this is the most recent run\n select 1\n from msdb..sysjobactivity new\n where new.job_id = aj.job_id\n and new.start_execution_date > aj.start_execution_date ) )\nprint 'running'\n"
},
{
"answer_id": 43480369,
"author": "John Merager",
"author_id": 7885952,
"author_profile": "https://Stackoverflow.com/users/7885952",
"pm_score": 2,
"selected": false,
"text": "CREATE TABLE #list_running_SQL_jobs\n(\n job_id UNIQUEIDENTIFIER NOT NULL\n , last_run_date INT NOT NULL\n , last_run_time INT NOT NULL\n , next_run_date INT NOT NULL\n , next_run_time INT NOT NULL\n , next_run_schedule_id INT NOT NULL\n , requested_to_run INT NOT NULL\n , request_source INT NOT NULL\n , request_source_id sysname NULL\n , running INT NOT NULL\n , current_step INT NOT NULL\n , current_retry_attempt INT NOT NULL\n , job_state INT NOT NULL\n);\n\nDECLARE @sqluser NVARCHAR(128)\n , @is_sysadmin INT;\n\nSELECT @is_sysadmin = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0);\n\nDECLARE read_sysjobs_for_running CURSOR FOR\n SELECT DISTINCT SUSER_SNAME(owner_sid)FROM msdb.dbo.sysjobs;\nOPEN read_sysjobs_for_running;\nFETCH NEXT FROM read_sysjobs_for_running\nINTO @sqluser;\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n INSERT INTO #list_running_SQL_jobs\n EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @sqluser;\n FETCH NEXT FROM read_sysjobs_for_running\n INTO @sqluser;\nEND;\n\nCLOSE read_sysjobs_for_running;\nDEALLOCATE read_sysjobs_for_running;\n\nSELECT j.name\n , 'Enbld' = CASE j.enabled\n WHEN 0\n THEN 'no'\n ELSE 'YES'\n END\n , '#Min' = DATEDIFF(MINUTE, a.start_execution_date, ISNULL(a.stop_execution_date, GETDATE()))\n , 'Status' = CASE\n WHEN a.start_execution_date IS NOT NULL\n AND a.stop_execution_date IS NULL\n THEN 'Executing'\n WHEN h.run_status = 0\n THEN 'FAILED'\n WHEN h.run_status = 2\n THEN 'Retry'\n WHEN h.run_status = 3\n THEN 'Canceled'\n WHEN h.run_status = 4\n THEN 'InProg'\n WHEN h.run_status = 1\n THEN 'Success'\n ELSE 'Idle'\n END\n , r.current_step\n , spid = p.session_id\n , owner = ISNULL(SUSER_SNAME(j.owner_sid), 'S-' + CONVERT(NVARCHAR(12), CONVERT(BIGINT, UNICODE(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 1))) - CONVERT(BIGINT, 256) * CONVERT(BIGINT, UNICODE(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 1)) / 256)) + '-' + CONVERT(NVARCHAR(12), UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 4), 1)) / 256 + CONVERT(BIGINT, NULLIF(UNICODE(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 1)) / 256, 0)) - CONVERT(BIGINT, UNICODE(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 1)) / 256)) + ISNULL('-' + CONVERT(NVARCHAR(12), CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 5), 1))) + CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 6), 1))) * CONVERT(BIGINT, 65536) + CONVERT(BIGINT, NULLIF(SIGN(LEN(CONVERT(NVARCHAR(256), j.owner_sid)) - 6), -1)) * 0), '') + ISNULL('-' + CONVERT(NVARCHAR(12), CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 7), 1))) + CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 8), 1))) * CONVERT(BIGINT, 65536) + CONVERT(BIGINT, NULLIF(SIGN(LEN(CONVERT(NVARCHAR(256), j.owner_sid)) - 8), -1)) * 0), '') + ISNULL('-' + CONVERT(NVARCHAR(12), CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 9), 1))) + CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 10), 1))) * CONVERT(BIGINT, 65536) + CONVERT(BIGINT, NULLIF(SIGN(LEN(CONVERT(NVARCHAR(256), j.owner_sid)) - 10), -1)) * 0), '') + ISNULL('-' + CONVERT(NVARCHAR(12), CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 11), 1))) + CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 12), 1))) * CONVERT(BIGINT, 65536) + CONVERT(BIGINT, NULLIF(SIGN(LEN(CONVERT(NVARCHAR(256), j.owner_sid)) - 12), -1)) * 0), '') + ISNULL('-' + CONVERT(NVARCHAR(12), CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 13), 1))) + CONVERT(BIGINT, UNICODE(RIGHT(LEFT(CONVERT(NVARCHAR(256), j.owner_sid), 14), 1))) * CONVERT(BIGINT, 65536) + CONVERT(BIGINT, NULLIF(SIGN(LEN(CONVERT(NVARCHAR(256), j.owner_sid)) - 14), -1)) * 0), '')) --SHOW as NT SID when unresolved\n , a.start_execution_date\n , a.stop_execution_date\n , t.subsystem\n , t.step_name\nFROM msdb.dbo.sysjobs j\n LEFT OUTER JOIN (SELECT DISTINCT * FROM #list_running_SQL_jobs) r\n ON j.job_id = r.job_id\n LEFT OUTER JOIN msdb.dbo.sysjobactivity a\n ON j.job_id = a.job_id\n AND a.start_execution_date IS NOT NULL\n --AND a.stop_execution_date IS NULL\n AND NOT EXISTS\n (\n SELECT *\n FROM msdb.dbo.sysjobactivity at\n WHERE at.job_id = a.job_id\n AND at.start_execution_date > a.start_execution_date\n )\n LEFT OUTER JOIN sys.dm_exec_sessions p\n ON p.program_name LIKE 'SQLAgent%0x%'\n AND j.job_id = SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 7, 2) + SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 5, 2) + SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 3, 2) + SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 1, 2) + '-' + SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 11, 2) + SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 9, 2) + '-' + SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 15, 2) + SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 13, 2) + '-' + SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 17, 4) + '-' + SUBSTRING(SUBSTRING(p.program_name, CHARINDEX('0x', p.program_name) + 2, 32), 21, 12)\n LEFT OUTER JOIN msdb.dbo.sysjobhistory h\n ON j.job_id = h.job_id\n AND h.instance_id = a.job_history_id\n LEFT OUTER JOIN msdb.dbo.sysjobsteps t\n ON t.job_id = j.job_id\n AND t.step_id = r.current_step\nORDER BY 1;\n\nDROP TABLE #list_running_SQL_jobs;\n"
},
{
"answer_id": 62342227,
"author": "Venkataraman R",
"author_id": 634935,
"author_profile": "https://Stackoverflow.com/users/634935",
"pm_score": 1,
"selected": false,
"text": "SELECT sj.Name,\n CASE\n WHEN sja.start_execution_date IS NULL THEN 'Never ran'\n WHEN sja.start_execution_date IS NOT NULL AND sja.stop_execution_date IS NULL THEN 'Running'\n WHEN sja.start_execution_date IS NOT NULL AND sja.stop_execution_date IS NOT NULL THEN 'Not running'\n END AS 'RunStatus',\n CASE WHEN sja.start_execution_date IS NOT NULL AND sja.stop_execution_date IS NULL then js.StepCount else null end As TotalNumberOfSteps,\n CASE WHEN sja.start_execution_date IS NOT NULL AND sja.stop_execution_date IS NULL then ISNULL(sja.last_executed_step_id+1,js.StepCount) else null end as currentlyExecutingStep,\n CASE WHEN sja.start_execution_date IS NOT NULL AND sja.stop_execution_date IS NULL then datediff(minute, sja.run_requested_date, getdate()) ELSE NULL end as ElapsedTime\nFROM msdb.dbo.sysjobs sj\nJOIN msdb.dbo.sysjobactivity sja\nON sj.job_id = sja.job_id\nCROSS APPLY (SELECT COUNT(*) FROM msdb.dbo.sysjobsteps as js WHERE js.job_id = sj.job_id) as js(StepCount)\nWHERE session_id = (\n SELECT MAX(session_id) FROM msdb.dbo.sysjobactivity)\nORDER BY RunStatus desc\n"
},
{
"answer_id": 67421315,
"author": "Geoff Griswald",
"author_id": 11372842,
"author_profile": "https://Stackoverflow.com/users/11372842",
"pm_score": 2,
"selected": false,
"text": "-- ===================================================================================\n-- Function: \"IsJobAlreadyRunning\" | Author: Geoff Griswald | Created: 2021-05-06\n-- Description: Check if a SQL Agent Job is already Running - Return 1 if Yes, 0 if No\n-- ===================================================================================\nCREATE FUNCTION dbo.IsJobAlreadyRunning (@AgentJobName varchar(140))\nRETURNS bit\nAS\nBEGIN\nDECLARE @Result bit = 0\n IF EXISTS (SELECT job.name\n FROM msdb.dbo.sysjobs_view job\n INNER JOIN msdb.dbo.sysjobactivity activity ON job.job_id = activity.job_id\n INNER JOIN msdb.dbo.syssessions sess ON sess.session_id = activity.session_id\n INNER JOIN (SELECT MAX(agent_start_date) AS max_agent_start_date\n FROM msdb.dbo.syssessions) sess_max ON sess.agent_start_date = sess_max.max_agent_start_date\n WHERE run_requested_date IS NOT NULL \n AND stop_execution_date IS NULL\n AND job.name = @AgentJobName)\n SET @Result = 1\nRETURN @Result\nEND;\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200195",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20951/"
] |
200,200
|
<p>I need to use an alias in the WHERE clause, but It keeps telling me that its an unknown column. Is there any way to get around this issue? I need to select records that have a rating higher than x. Rating is calculated as the following alias:</p>
<pre><code>sum(reviews.rev_rating)/count(reviews.rev_id) as avg_rating
</code></pre>
|
[
{
"answer_id": 200203,
"author": "Paul Dixon",
"author_id": 6521,
"author_profile": "https://Stackoverflow.com/users/6521",
"pm_score": 9,
"selected": true,
"text": " HAVING avg_rating>5\n"
},
{
"answer_id": 200220,
"author": "Torbjörn Gyllebring",
"author_id": 21182,
"author_profile": "https://Stackoverflow.com/users/21182",
"pm_score": 5,
"selected": false,
"text": "select * from (\n -- your original query\n select .. sum(reviews.rev_rating)/count(reviews.rev_id) as avg_rating \n from ...) Foo\nwhere Foo.avg_rating ...\n"
},
{
"answer_id": 45014896,
"author": "Thorsten Kettner",
"author_id": 2270762,
"author_profile": "https://Stackoverflow.com/users/2270762",
"pm_score": 3,
"selected": false,
"text": "WHERE"
},
{
"answer_id": 57107188,
"author": "anson",
"author_id": 7532946,
"author_profile": "https://Stackoverflow.com/users/7532946",
"pm_score": 1,
"selected": false,
"text": "SELECT * FROM (SELECT customer_Id AS 'custId', gender, age FROM customer\n WHERE gender = 'F') AS c\nWHERE c.custId = 100;\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200200",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,205
|
<p>I'm experimenting with an updated build system at work; currently, I'm trying to find a good way to set compiler & flags depending on the target platform. </p>
<p>What I would like to do is something like</p>
<pre><code>switch $(PLATFORM)_$(BUILD_TYPE)
case "Linux_x86_release"
CFLAGS = -O3
case "Linux_x86_debug"
CFLAGS = -O0 -g
case "ARM_release"
CC = armcc
AR = armlink
CFLAGS = -O2 -fx
...
</code></pre>
<p>which is not supported by GNU Make. Now, my first thought was to just do</p>
<pre><code>-include $(PLATFORM)_$(BUILD_TYPE)
</code></pre>
<p>which is a pretty decent solution, however, it makes it hard to get an overview of what differs between files, not to mention that I'm looking forward to writing & maintaining a good 60-80 files, each containing a set of variable definitions.</p>
<p>Does anyone happen to know a better way to accomplish this? I.e. setting a set of flags and other options based on another variable?</p>
|
[
{
"answer_id": 200222,
"author": "Bruno De Fraine",
"author_id": 6918,
"author_profile": "https://Stackoverflow.com/users/6918",
"pm_score": 3,
"selected": false,
"text": "configure"
},
{
"answer_id": 200241,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 5,
"selected": false,
"text": "CFLAGS_Linux_x86_release = -O3\nCFLAGS_Linux_x86_debug = -O0 -g\n\n\nCFLAGS = ${CFLAGS_${PLATFORM}_${BUILD}}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15514/"
] |
200,213
|
<p>I've a small project that I want to share with a few others on a machine that we all have access to. I created a bare copy of the local repo with</p>
<pre><code>git clone --bare --no-hardlinks path/to/.git/ repoToShare.git
</code></pre>
<p>I then moved repoToShare.git to the server.</p>
<p>I can check it out with the following:</p>
<pre><code>git clone ssh://user@address/opt/gitroot/repoToShare.git/ test
</code></pre>
<p>I can then see everything in the local repo and make commits against that. When I try to push changes back to the remote server I get the following error.</p>
<pre><code>*** Project description file hasn't been set
error: hooks/update exited with error code 1
error: hook declined to update refs/heads/master
</code></pre>
<p>Any ideas?</p>
|
[
{
"answer_id": 509398,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": ".git"
},
{
"answer_id": 7122006,
"author": "rodrigomanhaes",
"author_id": 362945,
"author_profile": "https://Stackoverflow.com/users/362945",
"pm_score": 1,
"selected": false,
"text": "# check for no description\nprojectdesc=$(sed -e '1q' \"$GIT_DIR/description\")\nif [ -z \"$projectdesc\" -o \"$projectdesc\" = \"Unnamed repository; edit this file to name it for gitweb.\" ]; then\n echo \"*** Project description file hasn't been set\" >&2\n exit 1\nfi\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/85/"
] |
200,219
|
<p>I would like to develop Adobe Flex applications using Linux and a free environment. I'd prefer a free as in freedom alternative, but as in beer would work as well. ;-)</p>
<p>Are any of you developing Adobe Flex rich internet applications using such an environment? Or should I face the "facts" that Flex Builder is an essential tool for Flex development and that I'm more or less lost without it?</p>
|
[
{
"answer_id": 200684,
"author": "Yaba",
"author_id": 7524,
"author_profile": "https://Stackoverflow.com/users/7524",
"pm_score": 2,
"selected": false,
"text": "mvn package"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
200,225
|
<p>In a C++ project (i.e. no .NET) on Windows Mobile, I am looking for a way to easily communicate between two independently running applications. Application A would run a service, whereas application B would provide the user some functionality - for which B has to call some of A's functions. I would rather not go through implementing anything in COM. </p>
<p>In fact, I would prefer not to do any kind of serialization or similar (i.e. this would exclude using sockets/pipes/files), but rather have B pass all parameters and pointers over to A, just like if A were part of B. Also, apps C, D and E should be able to do the same with only one instance of A running.</p>
<p>I should add that B sometimes is supposed to return an array (or std::vector or std::map) to A where the size is not previously known. </p>
<p>Is this possible on Windows Mobile and possibly other platforms?</p>
|
[
{
"answer_id": 277209,
"author": "Johann Gerell",
"author_id": 6345,
"author_profile": "https://Stackoverflow.com/users/6345",
"pm_score": 0,
"selected": false,
"text": "CreateFile"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27101/"
] |
200,229
|
<p>Can Eclipse make parameters for generated methods (overwriting, implementing interface, etc.) final, and if so, how?</p>
<p>If I'm not mistaken, IntelliJ had an option for it. I could not find something similar in Eclipse.</p>
<p>I have become accustomed to making parameters final manually, but I am hoping for an automatic solution.</p>
|
[
{
"answer_id": 200275,
"author": "Guido",
"author_id": 12388,
"author_profile": "https://Stackoverflow.com/users/12388",
"pm_score": 5,
"selected": true,
"text": "Window > Preferences > Java > Editor > Templates or under Window > Preferences > Java > Code Style > Code Templates"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/706/"
] |
200,239
|
<p>I'm using the MIDP 2.0 (JSR 118) and I just noticed that there is no reader for strings in J2ME.</p>
<p>Does anyone know how you are supposed to read Strings from an <code>InputStream</code> or <code>InputStreamReader</code> in a platform independent way (i.e. between two java enabled cell phones of different models)?</p>
|
[
{
"answer_id": 200644,
"author": "tonys",
"author_id": 35439,
"author_profile": "https://Stackoverflow.com/users/35439",
"pm_score": 3,
"selected": true,
"text": "DataInputStream.readUTF()"
},
{
"answer_id": 261027,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "InputStreamReader.read(char[], int, int)"
},
{
"answer_id": 7822181,
"author": "Pedro Guillem",
"author_id": 1003257,
"author_profile": "https://Stackoverflow.com/users/1003257",
"pm_score": 2,
"selected": false,
"text": "BufferedReader"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3713/"
] |
200,247
|
<p>I don't understand it. </p>
<p>The ids of html elements in the master page are changed by the same id but with a prefix and it's breaking the css design.</p>
<p>In the master page I have:</p>
<pre><code><div id="container" runat="server">
<asp:ContentPlaceHolder ...
...
</code></pre>
<p>The above code is rendered</p>
<pre><code><div id="ctl00_ctloo_container">
...
</code></pre>
<p>And the CSS styles are gone obviously.</p>
<p>How do I stop it?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 200263,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 1,
"selected": false,
"text": "<asp:Whatever runat=\"server\" id=\"whatever\" CssClass=\"whateverClass\">\n"
},
{
"answer_id": 200300,
"author": "JacquesB",
"author_id": 7488,
"author_profile": "https://Stackoverflow.com/users/7488",
"pm_score": 3,
"selected": true,
"text": "<asp:ContentPlaceHolder />"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/460927/"
] |
200,257
|
<p>i've never created a shopping cart, or forum in php. aside from viewing and analyzing another persons project or viewing tutorials that display how to make such a project or how to being such a project. how would a person know how to design the database structure to create such a thing? im guessing its probbably through trial and error...</p>
|
[
{
"answer_id": 200262,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 4,
"selected": false,
"text": "students\n student_id\n student_name\n student_class\n student_grade\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27751/"
] |
200,286
|
<p>we had a heated discussion about a method name. </p>
<p>We have a class <code>User</code>. There is property called "Groups" on the user. It contains all groups that contain the user directly. That's ok. What we have problem with, is the name of the method that would recursively list all user's groups and their "parent" groups and return list of all groups, of which the user can be considered as member.</p>
<pre><code>User u = <get user>;
IList<UserGroup> groups = u.XYZ();
Console.WriteLine("User {0} is member of: ", u);
foreach(UserGroup g in groups)
Console.WriteLine("{0}", g);
</code></pre>
<p>My colleagues brought:</p>
<pre><code>u.GetAllGroups(); // what groups?
u.GetMemberOfGroups(); // doesn't make sense
u.GroupsIAmMemberOf(); // long
u.MemberOf(); // short, but the description is wrong
u.GetRolesForUser(); // we don't work with roles, so GetGroupsForUser ?
u.GetOccupiedGroups(); // is the meaning correct?
</code></pre>
<p>What name would you propose?</p>
|
[
{
"answer_id": 200288,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 1,
"selected": false,
"text": "u.GetGroupMembership()\n"
},
{
"answer_id": 200296,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 1,
"selected": false,
"text": "u.GetGroups()\n"
},
{
"answer_id": 200298,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 1,
"selected": true,
"text": " u.GroupMembership();\n"
},
{
"answer_id": 200304,
"author": "Panos",
"author_id": 8049,
"author_profile": "https://Stackoverflow.com/users/8049",
"pm_score": 1,
"selected": false,
"text": "u.Groups;\n"
},
{
"answer_id": 200383,
"author": "J c",
"author_id": 25837,
"author_profile": "https://Stackoverflow.com/users/25837",
"pm_score": 2,
"selected": false,
"text": "User u = <get user>;\nIList<UserGroup> groups = SecurityModel.Groups.getMembership(u);\n"
},
{
"answer_id": 253222,
"author": "Yarik",
"author_id": 31415,
"author_profile": "https://Stackoverflow.com/users/31415",
"pm_score": 1,
"selected": false,
"text": "if (the signature of the property Groups cannot be changed)\n{\n I think you are screwed\n and the best thing I can think of\n is another property named AllGroups\n // u.Groups and u.GetWhatever() look very inconsistently\n}\nelse\n{\n if (you are okay with using the term \"group\")\n {\n I would select one of these variants:\n {\n a pair of properties named ParentGroups and AncestorGroups\n }\n or\n { \n a parameterized method or property Groups(Level)\n where Level can be either PARENTS (default) or ANCESTORS\n }\n }\n else\n {\n I would consider replacing \"group\" with \"membership\"\n and then I would select one of these variants:\n {\n a pair of properties named DirectMemberships and AllMemberships\n }\n or\n { \n a parameterized method or property Memberships(Level)\n where Level can be either DIRECT_ONLY (default) or ALL\n }\n }\n}\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/75224/"
] |
200,292
|
<p>I'm producing a hex file to run on an ARM processor which I want to keep below 32K. It's currently a lot larger than that and I wondered if someone might have some advice on what's the best approach to slim it down?</p>
<p>Here's what I've done so far</p>
<ol>
<li>So I've run 'size' on it to determine how big the hex file is. </li>
<li>Then 'size' again to see how big each of the object files are that link to create the hex files. It seems the majority of the size comes from external libraries.</li>
<li>Then I used 'readelf' to see which functions take up the most memory. </li>
<li>I searched through the code to see if I could eliminate calls to those functions.</li>
</ol>
<p>Here's where I get stuck, there's some functions which I don't call directly (e.g. _vfprintf) and I can't find what calls it so I can remove the call (as I think I don't need it).</p>
<p>So what are the next steps?</p>
<p>Response to answers:</p>
<ul>
<li>As I can see there are functions being called which take up a lot of memory. I cannot however find what is calling it. </li>
<li>I want to omit those functions (if possible) but I can't find what's calling them! Could be called from any number of library functions I guess.</li>
<li>The linker is working as desired, I think, it only includes the relevant library files. How do you know if only the relevant functions are being included? Can you set a flag or something for that?</li>
<li>I'm using GCC</li>
</ul>
|
[
{
"answer_id": 200600,
"author": "Andrew Edgecombe",
"author_id": 11694,
"author_profile": "https://Stackoverflow.com/users/11694",
"pm_score": 5,
"selected": true,
"text": "strip"
},
{
"answer_id": 10340204,
"author": "Russ",
"author_id": 465838,
"author_profile": "https://Stackoverflow.com/users/465838",
"pm_score": 2,
"selected": false,
"text": "strip"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/76121/"
] |
200,305
|
<p>I want an <strong>simple IDE/editor for C</strong> in <strong>Linux</strong> to which I <strong>can add features easily</strong>. For example: I want to add a right click menu item and a related action for the editor. It should be easy to extent and add any desirable functionality. I tried eclipse CDT but its to much of learning(I mean knowing the eclipse plug-in architecture and the CDT extension points and stuff) to do for the small modification/s I want to do. </p>
<p>Thanks,
Sachin</p>
|
[
{
"answer_id": 201034,
"author": "Peter Miehle",
"author_id": 27800,
"author_profile": "https://Stackoverflow.com/users/27800",
"pm_score": 2,
"selected": false,
"text": ";; the indention-thing needs refining\n(defun pm-if ()\n \"generates if stub\"\n (interactive)\n (insert \"if () {\")\n (indent-according-to-mode)\n (newline)\n (indent-according-to-mode)\n (newline)\n (indent-according-to-mode)\n (insert \"} /* endif */\")\n (indent-according-to-mode)\n (newline)\n (indent-according-to-mode)\n (previous-line 3)\n (end-of-line)\n (goto-char (- (point) 3))\n)\n\n\n;; bind it to CTRL-c i\n(define-key Ctl-C-keymap \"i\" 'pm-if)\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200305",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2745562/"
] |
200,309
|
<p>How to create a table with a timestamp column that defaults to <code>DATETIME('now')</code>?</p>
<p>Like this:</p>
<pre><code>CREATE TABLE test (
id INTEGER PRIMARY KEY AUTOINCREMENT,
t TIMESTAMP DEFAULT DATETIME('now')
);
</code></pre>
<p>This gives an error.</p>
|
[
{
"answer_id": 200329,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 9,
"selected": true,
"text": "CURRENT_TIMESTAMP"
},
{
"answer_id": 228070,
"author": "rev",
"author_id": 30455,
"author_profile": "https://Stackoverflow.com/users/30455",
"pm_score": 7,
"selected": false,
"text": "CREATE TABLE whatever(\n ....\n timestamp DATE DEFAULT (datetime('now','localtime')),\n ...\n);\n"
},
{
"answer_id": 754051,
"author": "Adam Luter",
"author_id": 91361,
"author_profile": "https://Stackoverflow.com/users/91361",
"pm_score": 6,
"selected": false,
"text": "(DATETIME('now'))"
},
{
"answer_id": 20121683,
"author": "Nianliang",
"author_id": 790198,
"author_profile": "https://Stackoverflow.com/users/790198",
"pm_score": 4,
"selected": false,
"text": "CREATE TABLE test (\n id INTEGER PRIMARY KEY AUTOINCREMENT, \n t REAL DEFAULT (datetime('now', 'localtime'))\n);\n"
},
{
"answer_id": 26127039,
"author": "user272735",
"author_id": 272735,
"author_profile": "https://Stackoverflow.com/users/272735",
"pm_score": 5,
"selected": false,
"text": "created_at"
},
{
"answer_id": 56511045,
"author": "Bilbo",
"author_id": 585158,
"author_profile": "https://Stackoverflow.com/users/585158",
"pm_score": 2,
"selected": false,
"text": "Create Table Demo (\n idDemo Integer Not Null Primary Key AutoIncrement\n ,DemoValue Text Not Null Unique\n ,DatTimIns Integer(4) Not Null Default (strftime('%s', DateTime('Now', 'localtime'))) -- get Now/UTC, convert to local, convert to string/Unix Time, store as Integer(4)\n ,DatTimUpd Integer(4) Null\n);\n\nCreate Trigger trgDemoUpd After Update On Demo Begin\n Update Demo Set\n DatTimUpd = strftime('%s', DateTime('Now', 'localtime')) -- same as DatTimIns\n Where idDemo = new.idDemo;\nEnd;\n\nCreate View If Not Exists vewDemo As Select -- convert Unix-Times to DateTimes so not every single query needs to do so\n idDemo\n ,DemoValue\n ,DateTime(DatTimIns, 'unixepoch') As DatTimIns -- convert Integer(4) (treating it as Unix-Time)\n ,DateTime(DatTimUpd, 'unixepoch') As DatTimUpd -- to YYYY-MM-DD HH:MM:SS\nFrom Demo;\n\nInsert Into Demo (DemoValue) Values ('One'); -- activate the field Default\n-- WAIT a few seconds -- \nInsert Into Demo (DemoValue) Values ('Two'); -- same thing but with\nInsert Into Demo (DemoValue) Values ('Thr'); -- later time values\n\nUpdate Demo Set DemoValue = DemoValue || ' Upd' Where idDemo = 1; -- activate the Update-trigger\n\nSelect * From Demo; -- display raw audit values\nidDemo DemoValue DatTimIns DatTimUpd\n------ --------- ---------- ----------\n1 One Upd 1560024902 1560024944\n2 Two 1560024944\n3 Thr 1560024944\n\nSelect * From vewDemo; -- display automatic audit values\nidDemo DemoValue DatTimIns DatTimUpd\n------ --------- ------------------- -------------------\n1 One Upd 2019-06-08 20:15:02 2019-06-08 20:15:44\n2 Two 2019-06-08 20:15:44\n3 Thr 2019-06-08 20:15:44\n"
},
{
"answer_id": 66263567,
"author": "Jim Hunziker",
"author_id": 6160,
"author_profile": "https://Stackoverflow.com/users/6160",
"pm_score": 3,
"selected": false,
"text": "CREATE TABLE my_table (\n timestamp DATETIME DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))\n);\n"
}
] |
2008/10/14
|
[
"https://Stackoverflow.com/questions/200309",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13262/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.